diff --git a/thermion_dart/lib/src/filament/src/implementation/background_image.dart b/thermion_dart/lib/src/filament/src/implementation/background_image.dart index 2f3e84fb..1fe372a4 100644 --- a/thermion_dart/lib/src/filament/src/implementation/background_image.dart +++ b/thermion_dart/lib/src/filament/src/implementation/background_image.dart @@ -8,6 +8,7 @@ import 'package:thermion_dart/src/filament/src/implementation/ffi_texture.dart'; import 'package:thermion_dart/thermion_dart.dart'; class BackgroundImage extends ThermionAsset { + final ThermionAsset asset; ThermionEntity get entity => asset.entity; @@ -307,13 +308,11 @@ class BackgroundImage extends ThermionAsset { @override Future removeAnimationComponent() { - // TODO: implement removeAnimationComponent throw UnimplementedError(); } @override Future resetBones() { - // TODO: implement resetBones throw UnimplementedError(); } @@ -321,7 +320,6 @@ class BackgroundImage extends ThermionAsset { Future setBoneTransform( ThermionEntity entity, int boneIndex, Matrix4 transform, {int skinIndex = 0}) { - // TODO: implement setBoneTransform throw UnimplementedError(); } diff --git a/thermion_dart/lib/src/filament/src/implementation/ffi_asset.dart b/thermion_dart/lib/src/filament/src/implementation/ffi_asset.dart index 37e9049b..99c48e8e 100644 --- a/thermion_dart/lib/src/filament/src/implementation/ffi_asset.dart +++ b/thermion_dart/lib/src/filament/src/implementation/ffi_asset.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:animation_tools_dart/animation_tools_dart.dart'; import 'package:logging/logging.dart'; import 'package:thermion_dart/src/utils/src/matrix.dart'; @@ -7,6 +9,10 @@ import 'package:thermion_dart/thermion_dart.dart'; import 'package:vector_math/vector_math_64.dart' as v64; class FFIAsset extends ThermionAsset { + T getHandle() { + return asset as T; + } + /// /// /// @@ -190,11 +196,6 @@ class FFIAsset extends ThermionAsset { return result; } - /// - /// - /// - ThermionAsset? boundingBoxAsset; - /// /// /// @@ -226,143 +227,6 @@ class FFIAsset extends ThermionAsset { return boundingBox; } - /// - /// - /// - Future createBoundingBoxAsset() async { - if (boundingBoxAsset == null) { - final boundingBox = await SceneAsset_getBoundingBox(asset); - - final min = [ - boundingBox.centerX - boundingBox.halfExtentX, - boundingBox.centerY - boundingBox.halfExtentY, - boundingBox.centerZ - boundingBox.halfExtentZ - ]; - final max = [ - boundingBox.centerX + boundingBox.halfExtentX, - boundingBox.centerY + boundingBox.halfExtentY, - boundingBox.centerZ + boundingBox.halfExtentZ - ]; - - // Create vertices for the bounding box wireframe - // 8 vertices for a cube - final vertices = Float32List(8 * 3); - - // Bottom vertices - vertices[0] = min[0]; - vertices[1] = min[1]; - vertices[2] = min[2]; // v0 - vertices[3] = max[0]; - vertices[4] = min[1]; - vertices[5] = min[2]; // v1 - vertices[6] = max[0]; - vertices[7] = min[1]; - vertices[8] = max[2]; // v2 - vertices[9] = min[0]; - vertices[10] = min[1]; - vertices[11] = max[2]; // v3 - - // Top vertices - vertices[12] = min[0]; - vertices[13] = max[1]; - vertices[14] = min[2]; // v4 - vertices[15] = max[0]; - vertices[16] = max[1]; - vertices[17] = min[2]; // v5 - vertices[18] = max[0]; - vertices[19] = max[1]; - vertices[20] = max[2]; // v6 - vertices[21] = min[0]; - vertices[22] = max[1]; - vertices[23] = max[2]; // v7 - - // Indices for lines (24 indices for 12 lines) - final indices = Uint16List.fromList([ - // Bottom face - 0, 1, 1, 2, 2, 3, 3, 0, - // Top face - 4, 5, 5, 6, 6, 7, 7, 4, - // Vertical edges - 0, 4, 1, 5, 2, 6, 3, 7 - ]); - - // Create unlit material instance for the wireframe - final materialInstancePtr = - await withPointerCallback((cb) { - MaterialProvider_createMaterialInstanceRenderThread( - app.ubershaderMaterialProvider, - false, - true, - false, - false, - false, - false, - false, - false, - 0, - false, - false, - 0, - false, - 0, - 0, - false, - 0, - false, - 0, - false, - 0, - false, - false, - false, - 0, - 0, - 0, - false, - 0, - false, - 0, - false, - 0, - false, - 0, - false, - false, - false, - cb); - }); - - final material = FFIMaterialInstance(materialInstancePtr, app); - await material.setParameterFloat4( - "baseColorFactor", 1.0, 1.0, 0.0, 1.0); // Yellow wireframe - - // Create geometry for the bounding box - final geometry = Geometry( - vertices, - indices, - primitiveType: PrimitiveType.LINES, - ); - - boundingBoxAsset = await FilamentApp.instance!.createGeometry( - geometry, - animationManager, - materialInstances: [material], - keepData: false, - ) as FFIAsset; - - await boundingBoxAsset!.setCastShadows(false); - await boundingBoxAsset!.setReceiveShadows(false); - - TransformManager_setParent(Engine_getTransformManager(app.engine), - boundingBoxAsset!.entity, entity, false); - geometry.uvs?.free(); - geometry.normals?.free(); - geometry.vertices.free(); - geometry.indices.free(); - } - return boundingBoxAsset!; - } - /// /// /// diff --git a/thermion_dart/lib/src/filament/src/implementation/ffi_scene.dart b/thermion_dart/lib/src/filament/src/implementation/ffi_scene.dart index 88055f4c..192db811 100644 --- a/thermion_dart/lib/src/filament/src/implementation/ffi_scene.dart +++ b/thermion_dart/lib/src/filament/src/implementation/ffi_scene.dart @@ -14,8 +14,8 @@ class FFIScene extends Scene { FFIScene(this.scene); @override - Future add(covariant FFIAsset asset) async { - SceneAsset_addToScene(asset.asset, scene); + Future add(ThermionAsset asset) async { + SceneAsset_addToScene(asset.getHandle(), scene); } /// @@ -30,8 +30,8 @@ class FFIScene extends Scene { /// /// @override - Future remove(covariant FFIAsset asset) async { - SceneAsset_removeFromScene(asset.asset, scene); + Future remove(ThermionAsset asset) async { + SceneAsset_removeFromScene(asset.getHandle(), scene); } /// diff --git a/thermion_dart/lib/src/filament/src/interface/scene.dart b/thermion_dart/lib/src/filament/src/interface/scene.dart index 35319632..dd1939f9 100644 --- a/thermion_dart/lib/src/filament/src/interface/scene.dart +++ b/thermion_dart/lib/src/filament/src/interface/scene.dart @@ -15,7 +15,7 @@ abstract class Scene { /// Removes all renderable entities in [asset] from this scene. /// /// - Future remove(covariant ThermionAsset asset); + Future remove(ThermionAsset asset); /// Removes [entity] from this scene. ///