pass through instance owner to FFIAsset so instances can be created on instances
This commit is contained in:
@@ -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,
|
FFIAsset(this.asset, this.app, this.animationManager,
|
||||||
{this.isInstance = false, this.keepData = false}) {
|
{this.instanceOwner = null, this.keepData = false}) {
|
||||||
entity = SceneAsset_getEntity(asset);
|
entity = SceneAsset_getEntity(asset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,9 +132,8 @@ class FFIAsset extends ThermionAsset {
|
|||||||
@override
|
@override
|
||||||
Future<FFIAsset> createInstance(
|
Future<FFIAsset> createInstance(
|
||||||
{covariant List<MaterialInstance>? materialInstances = null}) async {
|
{covariant List<MaterialInstance>? materialInstances = null}) async {
|
||||||
if(!isInstance) {
|
if(isInstance) {
|
||||||
throw Exception(
|
return instanceOwner!.createInstance(materialInstances: materialInstances);
|
||||||
"createInstance cannot be called on an instance. Make sure you are all calling the method on the original asset");
|
|
||||||
}
|
}
|
||||||
if (!keepData) {
|
if (!keepData) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
@@ -171,7 +168,7 @@ class FFIAsset extends ThermionAsset {
|
|||||||
if (created == nullptr) {
|
if (created == nullptr) {
|
||||||
throw Exception("Failed to create instance");
|
throw Exception("Failed to create instance");
|
||||||
}
|
}
|
||||||
return FFIAsset(created, app, animationManager, isInstance: true, keepData: keepData);
|
return FFIAsset(created, app, animationManager, instanceOwner: this, keepData: keepData);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -77,7 +77,9 @@ void main() async {
|
|||||||
var asset = await viewer.loadGltf(
|
var asset = await viewer.loadGltf(
|
||||||
"file://${testHelper.testDir}/assets/cube.glb",
|
"file://${testHelper.testDir}/assets/cube.glb",
|
||||||
addToScene: false,
|
addToScene: false,
|
||||||
numInstances: 2, keepData: true);
|
numInstances: 2,
|
||||||
|
keepData: true
|
||||||
|
);
|
||||||
var defaultInstance = await asset.getInstance(0);
|
var defaultInstance = await asset.getInstance(0);
|
||||||
await viewer.addToScene(defaultInstance);
|
await viewer.addToScene(defaultInstance);
|
||||||
await testHelper.capture(viewer.view, "gltf_without_instance");
|
await testHelper.capture(viewer.view, "gltf_without_instance");
|
||||||
|
|||||||
Reference in New Issue
Block a user