mandate passing childEntity to morph target functions

This commit is contained in:
Nick Fisher
2024-05-17 14:43:47 +08:00
parent b465553f04
commit ca35b310eb

View File

@@ -98,8 +98,8 @@ class FilamentViewer extends AbstractFilamentViewer {
Future _initialize() async { Future _initialize() async {
final uberarchivePtr = final uberarchivePtr =
uberArchivePath?.toNativeUtf8(allocator:allocator).cast<Char>() ?? nullptr; uberArchivePath?.toNativeUtf8(allocator: allocator).cast<Char>() ??
nullptr;
var viewer = await withVoidPointerCallback( var viewer = await withVoidPointerCallback(
(Pointer<NativeFunction<Void Function(Pointer<Void>)>> callback) { (Pointer<NativeFunction<Void Function(Pointer<Void>)>> callback) {
create_filament_viewer_ffi(_sharedContext, _driver, uberarchivePtr, create_filament_viewer_ffi(_sharedContext, _driver, uberarchivePtr,
@@ -107,8 +107,6 @@ class FilamentViewer extends AbstractFilamentViewer {
}); });
_viewer = Pointer.fromAddress(viewer); _viewer = Pointer.fromAddress(viewer);
allocator.free(uberarchivePtr); allocator.free(uberarchivePtr);
print("Set viewer to $_viewer");
print("Created viewer ${_viewer!.address}");
if (_viewer!.address == 0) { if (_viewer!.address == 0) {
throw Exception("Failed to create viewer. Check logs for details"); throw Exception("Failed to create viewer. Check logs for details");
} }
@@ -156,7 +154,7 @@ class FilamentViewer extends AbstractFilamentViewer {
@override @override
Future setBackgroundImage(String path, {bool fillHeight = false}) async { Future setBackgroundImage(String path, {bool fillHeight = false}) async {
final pathPtr = path.toNativeUtf8(allocator:allocator).cast<Char>(); final pathPtr = path.toNativeUtf8(allocator: allocator).cast<Char>();
await withVoidCallback((cb) { await withVoidCallback((cb) {
set_background_image_ffi(_viewer!, pathPtr, fillHeight, cb); set_background_image_ffi(_viewer!, pathPtr, fillHeight, cb);
}); });
@@ -177,9 +175,8 @@ class FilamentViewer extends AbstractFilamentViewer {
@override @override
Future loadSkybox(String skyboxPath) async { Future loadSkybox(String skyboxPath) async {
final pathPtr = skyboxPath.toNativeUtf8(allocator: allocator).cast<Char>(); final pathPtr = skyboxPath.toNativeUtf8(allocator: allocator).cast<Char>();
await withVoidCallback((cb) { await withVoidCallback((cb) {
load_skybox_ffi(_viewer!, pathPtr, cb); load_skybox_ffi(_viewer!, pathPtr, cb);
}); });
@@ -189,7 +186,8 @@ class FilamentViewer extends AbstractFilamentViewer {
@override @override
Future loadIbl(String lightingPath, {double intensity = 30000}) async { Future loadIbl(String lightingPath, {double intensity = 30000}) async {
final pathPtr = lightingPath.toNativeUtf8(allocator:allocator).cast<Char>(); final pathPtr =
lightingPath.toNativeUtf8(allocator: allocator).cast<Char>();
load_ibl_ffi(_viewer!, pathPtr, intensity); load_ibl_ffi(_viewer!, pathPtr, intensity);
} }
@@ -290,7 +288,7 @@ class FilamentViewer extends AbstractFilamentViewer {
if (unlit) { if (unlit) {
throw Exception("Not yet implemented"); throw Exception("Not yet implemented");
} }
final pathPtr = path.toNativeUtf8(allocator:allocator).cast<Char>(); final pathPtr = path.toNativeUtf8(allocator: allocator).cast<Char>();
var entity = await withIntCallback((callback) => var entity = await withIntCallback((callback) =>
load_glb_ffi(_sceneManager!, pathPtr, numInstances, callback)); load_glb_ffi(_sceneManager!, pathPtr, numInstances, callback));
allocator.free(pathPtr); allocator.free(pathPtr);
@@ -310,9 +308,9 @@ class FilamentViewer extends AbstractFilamentViewer {
// "loadGltf has a race condition on Windows which is likely to crash your program. If you really want to try, pass force=true to loadGltf"); // "loadGltf has a race condition on Windows which is likely to crash your program. If you really want to try, pass force=true to loadGltf");
// } // }
final pathPtr = path.toNativeUtf8(allocator:allocator).cast<Char>(); final pathPtr = path.toNativeUtf8(allocator: allocator).cast<Char>();
final relativeResourcePathPtr = final relativeResourcePathPtr =
relativeResourcePath.toNativeUtf8(allocator:allocator).cast<Char>(); relativeResourcePath.toNativeUtf8(allocator: allocator).cast<Char>();
var entity = await withIntCallback((callback) => load_gltf_ffi( var entity = await withIntCallback((callback) => load_gltf_ffi(
_sceneManager!, pathPtr, relativeResourcePathPtr, callback)); _sceneManager!, pathPtr, relativeResourcePathPtr, callback));
allocator.free(pathPtr); allocator.free(pathPtr);
@@ -382,20 +380,18 @@ class FilamentViewer extends AbstractFilamentViewer {
@override @override
Future<List<String>> getMorphTargetNames( Future<List<String>> getMorphTargetNames(
FilamentEntity entity, String meshName) async { FilamentEntity entity, FilamentEntity childEntity) async {
var names = <String>[]; var names = <String>[];
var meshNamePtr = meshName.toNativeUtf8(allocator:allocator).cast<Char>();
var count = await withIntCallback((callback) => var count = await withIntCallback((callback) =>
get_morph_target_name_count_ffi( get_morph_target_name_count_ffi(
_sceneManager!, entity, meshNamePtr, callback)); _sceneManager!, entity, childEntity, callback));
var outPtr = allocator<Char>(255); var outPtr = allocator<Char>(255);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
get_morph_target_name(_sceneManager!, entity, meshNamePtr, outPtr, i); get_morph_target_name(_sceneManager!, entity, childEntity, outPtr, i);
names.add(outPtr.cast<Utf8>().toDartString()); names.add(outPtr.cast<Utf8>().toDartString());
} }
allocator.free(outPtr); allocator.free(outPtr);
allocator.free(meshNamePtr);
return names.cast<String>(); return names.cast<String>();
} }
@@ -437,8 +433,12 @@ class FilamentViewer extends AbstractFilamentViewer {
Future setMorphAnimationData( Future setMorphAnimationData(
FilamentEntity entity, MorphAnimationData animation, FilamentEntity entity, MorphAnimationData animation,
{List<String>? targetMeshNames}) async { {List<String>? targetMeshNames}) async {
print("setting in actual viewer with $entity");
var meshNames = await getChildEntityNames(entity, renderableOnly: true); var meshNames = await getChildEntityNames(entity, renderableOnly: true);
print("MESH NAMES ${meshNames}");
var meshEntities = await getChildEntities(entity, true); var meshEntities = await getChildEntities(entity, true);
print("MESH ENTITIES ${meshEntities}");
// Entities are not guaranteed to have the same morph targets (or share the same order), // Entities are not guaranteed to have the same morph targets (or share the same order),
// either from each other, or from those specified in [animation]. // either from each other, or from those specified in [animation].
@@ -453,7 +453,7 @@ class FilamentViewer extends AbstractFilamentViewer {
if (targetMeshNames?.contains(meshName) == false) { if (targetMeshNames?.contains(meshName) == false) {
continue; continue;
} }
var meshMorphTargets = await getMorphTargetNames(entity, meshName); var meshMorphTargets = await getMorphTargetNames(entity, meshEntity);
var intersection = animation.morphTargets var intersection = animation.morphTargets
.toSet() .toSet()
@@ -568,8 +568,9 @@ class FilamentViewer extends AbstractFilamentViewer {
@override @override
Future clearEntities() async { Future clearEntities() async {
await withVoidCallback( await withVoidCallback((callback) {
(callback) => clear_entities_ffi(_viewer!, callback)); clear_entities_ffi(_viewer!, callback);
});
_scene.clearEntities(); _scene.clearEntities();
} }
@@ -647,7 +648,8 @@ class FilamentViewer extends AbstractFilamentViewer {
@override @override
Future setCamera(FilamentEntity entity, String? name) async { Future setCamera(FilamentEntity entity, String? name) async {
var cameraNamePtr = name?.toNativeUtf8(allocator:allocator).cast<Char>() ?? nullptr; var cameraNamePtr =
name?.toNativeUtf8(allocator: allocator).cast<Char>() ?? nullptr;
var result = set_camera(_viewer!, entity, cameraNamePtr); var result = set_camera(_viewer!, entity, cameraNamePtr);
allocator.free(cameraNamePtr); allocator.free(cameraNamePtr);
if (!result) { if (!result) {
@@ -746,7 +748,7 @@ class FilamentViewer extends AbstractFilamentViewer {
@override @override
Future setMaterialColor(FilamentEntity entity, String meshName, Future setMaterialColor(FilamentEntity entity, String meshName,
int materialIndex, double r, double g, double b, double a) async { int materialIndex, double r, double g, double b, double a) async {
var meshNamePtr = meshName.toNativeUtf8(allocator:allocator).cast<Char>(); var meshNamePtr = meshName.toNativeUtf8(allocator: allocator).cast<Char>();
var result = set_material_color( var result = set_material_color(
_sceneManager!, entity, meshNamePtr, materialIndex, r, g, b, a); _sceneManager!, entity, meshNamePtr, materialIndex, r, g, b, a);
allocator.free(meshNamePtr); allocator.free(meshNamePtr);
@@ -808,14 +810,16 @@ class FilamentViewer extends AbstractFilamentViewer {
@override @override
Future hide(FilamentEntity entity, String? meshName) async { Future hide(FilamentEntity entity, String? meshName) async {
final meshNamePtr = meshName?.toNativeUtf8(allocator:allocator).cast<Char>() ?? nullptr; final meshNamePtr =
meshName?.toNativeUtf8(allocator: allocator).cast<Char>() ?? nullptr;
if (hide_mesh(_sceneManager!, entity, meshNamePtr) != 1) {} if (hide_mesh(_sceneManager!, entity, meshNamePtr) != 1) {}
allocator.free(meshNamePtr); allocator.free(meshNamePtr);
} }
@override @override
Future reveal(FilamentEntity entity, String? meshName) async { Future reveal(FilamentEntity entity, String? meshName) async {
final meshNamePtr = meshName?.toNativeUtf8(allocator:allocator).cast<Char>() ?? nullptr; final meshNamePtr =
meshName?.toNativeUtf8(allocator: allocator).cast<Char>() ?? nullptr;
final result = reveal_mesh(_sceneManager!, entity, meshNamePtr) == 1; final result = reveal_mesh(_sceneManager!, entity, meshNamePtr) == 1;
allocator.free(meshNamePtr); allocator.free(meshNamePtr);
if (!result) { if (!result) {
@@ -1134,7 +1138,7 @@ class FilamentViewer extends AbstractFilamentViewer {
Future setPriority(FilamentEntity entityId, int priority) async { Future setPriority(FilamentEntity entityId, int priority) async {
set_priority(_sceneManager!, entityId, priority); set_priority(_sceneManager!, entityId, priority);
} }
@override @override
AbstractGizmo? get gizmo => null; AbstractGizmo? get gizmo => null;
} }