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 5d1ed541..ff1cc6c7 100644 --- a/thermion_dart/lib/src/filament/src/implementation/ffi_asset.dart +++ b/thermion_dart/lib/src/filament/src/implementation/ffi_asset.dart @@ -31,12 +31,10 @@ class FFIAsset extends ThermionAsset { /// /// /// - FFIAsset? _highlight; + bool get isInstance => instanceOwner != null; + final FFIAsset? instanceOwner; + - /// - /// - /// - final bool isInstance; /// /// @@ -51,7 +49,7 @@ class FFIAsset extends ThermionAsset { /// /// FFIAsset(this.asset, this.app, this.animationManager, - {this.isInstance = false, this.keepData = false}) { + {this.instanceOwner = null, this.keepData = false}) { entity = SceneAsset_getEntity(asset); } @@ -134,9 +132,8 @@ class FFIAsset extends ThermionAsset { @override Future createInstance( {covariant List? materialInstances = null}) async { - if(!isInstance) { - throw Exception( - "createInstance cannot be called on an instance. Make sure you are all calling the method on the original asset"); + if(isInstance) { + return instanceOwner!.createInstance(materialInstances: materialInstances); } if (!keepData) { throw Exception( @@ -171,7 +168,7 @@ class FFIAsset extends ThermionAsset { if (created == nullptr) { throw Exception("Failed to create instance"); } - return FFIAsset(created, app, animationManager, isInstance: true, keepData: keepData); + return FFIAsset(created, app, animationManager, instanceOwner: this, keepData: keepData); } /// diff --git a/thermion_dart/test/instancing_tests.dart b/thermion_dart/test/instancing_tests.dart index 7f64d6fe..071ca990 100644 --- a/thermion_dart/test/instancing_tests.dart +++ b/thermion_dart/test/instancing_tests.dart @@ -77,7 +77,9 @@ void main() async { var asset = await viewer.loadGltf( "file://${testHelper.testDir}/assets/cube.glb", addToScene: false, - numInstances: 2, keepData: true); + numInstances: 2, + keepData: true + ); var defaultInstance = await asset.getInstance(0); await viewer.addToScene(defaultInstance); await testHelper.capture(viewer.view, "gltf_without_instance");