allow creating more glTF instances than pre-allocated
This commit is contained in:
@@ -63,12 +63,12 @@ namespace thermion
|
|||||||
{
|
{
|
||||||
auto instanceNumber = _instances.size();
|
auto instanceNumber = _instances.size();
|
||||||
|
|
||||||
if (instanceNumber > _asset->getAssetInstanceCount() - 1)
|
if (instanceNumber >= _asset->getAssetInstanceCount() - 1)
|
||||||
{
|
{
|
||||||
Log("glTF asset was created with %d instances reserved, and %d instances have been used. Increase the number of instances pre-allocated when the asset is loaded.",
|
TRACE("Warning: %d/%d pre-allocated instances already consumed. You may wish to pre-allocate a larger number.",
|
||||||
_asset->getAssetInstanceCount(), _instances.size()
|
_asset->getAssetInstanceCount(), _instances.size()
|
||||||
);
|
);
|
||||||
return std::nullptr_t();
|
_assetLoader->createInstance(_asset);
|
||||||
}
|
}
|
||||||
TRACE("Creating instance %d", instanceNumber);
|
TRACE("Creating instance %d", instanceNumber);
|
||||||
auto instance = _asset->getAssetInstances()[instanceNumber];
|
auto instance = _asset->getAssetInstances()[instanceNumber];
|
||||||
|
|||||||
@@ -64,15 +64,8 @@ void main() async {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('create gltf instance', () async {
|
test('create pre-allocated gltf instance', () async {
|
||||||
await testHelper.withViewer((viewer) async {
|
await testHelper.withViewer((viewer) async {
|
||||||
await viewer
|
|
||||||
.loadIbl("file://${testHelper.testDir}/assets/default_env_ibl.ktx");
|
|
||||||
await viewer.loadSkybox(
|
|
||||||
"file://${testHelper.testDir}/assets/default_env_skybox.ktx");
|
|
||||||
await viewer.setPostProcessing(true);
|
|
||||||
await viewer.setAntiAliasing(false, true, false);
|
|
||||||
|
|
||||||
// Loading a glTF asset always creates a single instance behind the scenes,
|
// Loading a glTF asset always creates a single instance behind the scenes,
|
||||||
// but the entities exposed by the asset are used to manipulate all
|
// but the entities exposed by the asset are used to manipulate all
|
||||||
// instances as a group, not the singular "default" instance.
|
// instances as a group, not the singular "default" instance.
|
||||||
@@ -88,7 +81,7 @@ void main() async {
|
|||||||
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");
|
||||||
|
|
||||||
var instance = await asset.createInstance();
|
var instance = await asset.createInstance();
|
||||||
await instance.setTransform(Matrix4.translation(Vector3(1, 0, 0)));
|
await instance.setTransform(Matrix4.translation(Vector3(1, 0, 0)));
|
||||||
await testHelper.capture(viewer.view, "gltf_instance_created");
|
await testHelper.capture(viewer.view, "gltf_instance_created");
|
||||||
@@ -96,7 +89,16 @@ void main() async {
|
|||||||
await testHelper.capture(viewer.view, "gltf_instance_add_to_scene");
|
await testHelper.capture(viewer.view, "gltf_instance_add_to_scene");
|
||||||
await viewer.removeFromScene(instance);
|
await viewer.removeFromScene(instance);
|
||||||
await testHelper.capture(viewer.view, "gltf_instance_remove_from_scene");
|
await testHelper.capture(viewer.view, "gltf_instance_remove_from_scene");
|
||||||
});
|
|
||||||
|
// above, we pre-allocated two instances and have used all of them
|
||||||
|
// calling createInstance now will still create another instance, but will be slower than allocating.
|
||||||
|
var instance2 = await asset.createInstance();
|
||||||
|
await instance2.setTransform(Matrix4.translation(Vector3(-1, 0, 0)));
|
||||||
|
await viewer.addToScene(instance2);
|
||||||
|
await testHelper.capture(viewer.view, "gltf_instance2_add_to_scene");
|
||||||
|
|
||||||
|
|
||||||
|
}, addSkybox: true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('physics simulation with 100 instances', () async {
|
test('physics simulation with 100 instances', () async {
|
||||||
|
|||||||
Reference in New Issue
Block a user