pass through instance owner to FFIAsset so instances can be created on instances

This commit is contained in:
Nick Fisher
2025-06-24 21:31:10 +08:00
parent bec34e5b0b
commit ed21eec66e
2 changed files with 10 additions and 11 deletions

View File

@@ -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<FFIAsset> createInstance(
{covariant List<MaterialInstance>? 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);
}
///

View File

@@ -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");