From ca35b310eb843b9249ce745cbd853fdea197e79e Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Fri, 17 May 2024 14:43:47 +0800 Subject: [PATCH] mandate passing childEntity to morph target functions --- .../dart_filament/filament_viewer_impl.dart | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/dart_filament/lib/dart_filament/filament_viewer_impl.dart b/dart_filament/lib/dart_filament/filament_viewer_impl.dart index 6eaeb8a5..d2430219 100644 --- a/dart_filament/lib/dart_filament/filament_viewer_impl.dart +++ b/dart_filament/lib/dart_filament/filament_viewer_impl.dart @@ -98,8 +98,8 @@ class FilamentViewer extends AbstractFilamentViewer { Future _initialize() async { final uberarchivePtr = - uberArchivePath?.toNativeUtf8(allocator:allocator).cast() ?? nullptr; - + uberArchivePath?.toNativeUtf8(allocator: allocator).cast() ?? + nullptr; var viewer = await withVoidPointerCallback( (Pointer)>> callback) { create_filament_viewer_ffi(_sharedContext, _driver, uberarchivePtr, @@ -107,8 +107,6 @@ class FilamentViewer extends AbstractFilamentViewer { }); _viewer = Pointer.fromAddress(viewer); allocator.free(uberarchivePtr); - print("Set viewer to $_viewer"); - print("Created viewer ${_viewer!.address}"); if (_viewer!.address == 0) { throw Exception("Failed to create viewer. Check logs for details"); } @@ -156,7 +154,7 @@ class FilamentViewer extends AbstractFilamentViewer { @override Future setBackgroundImage(String path, {bool fillHeight = false}) async { - final pathPtr = path.toNativeUtf8(allocator:allocator).cast(); + final pathPtr = path.toNativeUtf8(allocator: allocator).cast(); await withVoidCallback((cb) { set_background_image_ffi(_viewer!, pathPtr, fillHeight, cb); }); @@ -177,9 +175,8 @@ class FilamentViewer extends AbstractFilamentViewer { @override Future loadSkybox(String skyboxPath) async { - final pathPtr = skyboxPath.toNativeUtf8(allocator: allocator).cast(); - + await withVoidCallback((cb) { load_skybox_ffi(_viewer!, pathPtr, cb); }); @@ -189,7 +186,8 @@ class FilamentViewer extends AbstractFilamentViewer { @override Future loadIbl(String lightingPath, {double intensity = 30000}) async { - final pathPtr = lightingPath.toNativeUtf8(allocator:allocator).cast(); + final pathPtr = + lightingPath.toNativeUtf8(allocator: allocator).cast(); load_ibl_ffi(_viewer!, pathPtr, intensity); } @@ -290,7 +288,7 @@ class FilamentViewer extends AbstractFilamentViewer { if (unlit) { throw Exception("Not yet implemented"); } - final pathPtr = path.toNativeUtf8(allocator:allocator).cast(); + final pathPtr = path.toNativeUtf8(allocator: allocator).cast(); var entity = await withIntCallback((callback) => load_glb_ffi(_sceneManager!, pathPtr, numInstances, callback)); 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"); // } - final pathPtr = path.toNativeUtf8(allocator:allocator).cast(); + final pathPtr = path.toNativeUtf8(allocator: allocator).cast(); final relativeResourcePathPtr = - relativeResourcePath.toNativeUtf8(allocator:allocator).cast(); + relativeResourcePath.toNativeUtf8(allocator: allocator).cast(); var entity = await withIntCallback((callback) => load_gltf_ffi( _sceneManager!, pathPtr, relativeResourcePathPtr, callback)); allocator.free(pathPtr); @@ -382,20 +380,18 @@ class FilamentViewer extends AbstractFilamentViewer { @override Future> getMorphTargetNames( - FilamentEntity entity, String meshName) async { + FilamentEntity entity, FilamentEntity childEntity) async { var names = []; - var meshNamePtr = meshName.toNativeUtf8(allocator:allocator).cast(); var count = await withIntCallback((callback) => get_morph_target_name_count_ffi( - _sceneManager!, entity, meshNamePtr, callback)); + _sceneManager!, entity, childEntity, callback)); var outPtr = allocator(255); 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().toDartString()); } allocator.free(outPtr); - allocator.free(meshNamePtr); return names.cast(); } @@ -437,8 +433,12 @@ class FilamentViewer extends AbstractFilamentViewer { Future setMorphAnimationData( FilamentEntity entity, MorphAnimationData animation, {List? targetMeshNames}) async { + print("setting in actual viewer with $entity"); var meshNames = await getChildEntityNames(entity, renderableOnly: true); + + print("MESH NAMES ${meshNames}"); 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), // either from each other, or from those specified in [animation]. @@ -453,7 +453,7 @@ class FilamentViewer extends AbstractFilamentViewer { if (targetMeshNames?.contains(meshName) == false) { continue; } - var meshMorphTargets = await getMorphTargetNames(entity, meshName); + var meshMorphTargets = await getMorphTargetNames(entity, meshEntity); var intersection = animation.morphTargets .toSet() @@ -568,8 +568,9 @@ class FilamentViewer extends AbstractFilamentViewer { @override Future clearEntities() async { - await withVoidCallback( - (callback) => clear_entities_ffi(_viewer!, callback)); + await withVoidCallback((callback) { + clear_entities_ffi(_viewer!, callback); + }); _scene.clearEntities(); } @@ -647,7 +648,8 @@ class FilamentViewer extends AbstractFilamentViewer { @override Future setCamera(FilamentEntity entity, String? name) async { - var cameraNamePtr = name?.toNativeUtf8(allocator:allocator).cast() ?? nullptr; + var cameraNamePtr = + name?.toNativeUtf8(allocator: allocator).cast() ?? nullptr; var result = set_camera(_viewer!, entity, cameraNamePtr); allocator.free(cameraNamePtr); if (!result) { @@ -746,7 +748,7 @@ class FilamentViewer extends AbstractFilamentViewer { @override Future setMaterialColor(FilamentEntity entity, String meshName, int materialIndex, double r, double g, double b, double a) async { - var meshNamePtr = meshName.toNativeUtf8(allocator:allocator).cast(); + var meshNamePtr = meshName.toNativeUtf8(allocator: allocator).cast(); var result = set_material_color( _sceneManager!, entity, meshNamePtr, materialIndex, r, g, b, a); allocator.free(meshNamePtr); @@ -808,14 +810,16 @@ class FilamentViewer extends AbstractFilamentViewer { @override Future hide(FilamentEntity entity, String? meshName) async { - final meshNamePtr = meshName?.toNativeUtf8(allocator:allocator).cast() ?? nullptr; + final meshNamePtr = + meshName?.toNativeUtf8(allocator: allocator).cast() ?? nullptr; if (hide_mesh(_sceneManager!, entity, meshNamePtr) != 1) {} allocator.free(meshNamePtr); } @override Future reveal(FilamentEntity entity, String? meshName) async { - final meshNamePtr = meshName?.toNativeUtf8(allocator:allocator).cast() ?? nullptr; + final meshNamePtr = + meshName?.toNativeUtf8(allocator: allocator).cast() ?? nullptr; final result = reveal_mesh(_sceneManager!, entity, meshNamePtr) == 1; allocator.free(meshNamePtr); if (!result) { @@ -1134,7 +1138,7 @@ class FilamentViewer extends AbstractFilamentViewer { Future setPriority(FilamentEntity entityId, int priority) async { set_priority(_sceneManager!, entityId, priority); } - + @override AbstractGizmo? get gizmo => null; }