add inUse flag to assist with recycling gltf instances
This commit is contained in:
@@ -140,6 +140,8 @@ namespace thermion
|
|||||||
return _instance->getBoundingBox();
|
return _instance->getBoundingBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool inUse = true;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
filament::Engine *_engine;
|
filament::Engine *_engine;
|
||||||
utils::NameComponentManager *_ncm;
|
utils::NameComponentManager *_ncm;
|
||||||
|
|||||||
@@ -53,25 +53,37 @@ namespace thermion
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GltfSceneAsset::destroyInstance(SceneAsset *asset) {
|
void GltfSceneAsset::destroyInstance(SceneAsset *asset) {
|
||||||
auto it = std::remove_if(_instances.begin(), _instances.end(), [=](auto &sceneAsset)
|
for(auto& instance : _instances) {
|
||||||
{ return sceneAsset.get() == asset; });
|
if(instance.get() == asset) {
|
||||||
_instances.erase(it, _instances.end());
|
instance->inUse = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
SceneAsset *GltfSceneAsset::createInstance(MaterialInstance **materialInstances, size_t materialInstanceCount)
|
SceneAsset *GltfSceneAsset::createInstance(MaterialInstance **materialInstances, size_t materialInstanceCount)
|
||||||
{
|
{
|
||||||
auto instanceNumber = _instances.size();
|
|
||||||
|
|
||||||
if (instanceNumber >= _asset->getAssetInstanceCount() - 1)
|
// first, see if we can recycled any "unused" instances.
|
||||||
|
for(auto &instance : _instances) {
|
||||||
|
if(!instance->inUse) {
|
||||||
|
instance->inUse = true;
|
||||||
|
return instance.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_instances.size() == _asset->getAssetInstanceCount())
|
||||||
{
|
{
|
||||||
TRACE("Warning: %d/%d pre-allocated instances already consumed. You may wish to pre-allocate a larger number.",
|
TRACE("Warning: %d pre-allocated instances already consumed. A new instance will be allocated internally, but in future you may wish to pre-allocate a larger number.",
|
||||||
_asset->getAssetInstanceCount(), _instances.size()
|
_asset->getAssetInstanceCount()
|
||||||
);
|
);
|
||||||
_assetLoader->createInstance(_asset);
|
_assetLoader->createInstance(_asset);
|
||||||
|
} else {
|
||||||
|
TRACE("Returning pre-allocated instance at index %d", _instances.size());
|
||||||
}
|
}
|
||||||
TRACE("Creating instance %d", instanceNumber);
|
|
||||||
auto instance = _asset->getAssetInstances()[instanceNumber];
|
auto instance = _asset->getAssetInstances()[_instances.size()];
|
||||||
|
|
||||||
instance->recomputeBoundingBoxes();
|
instance->recomputeBoundingBoxes();
|
||||||
auto bb = instance->getBoundingBox();
|
auto bb = instance->getBoundingBox();
|
||||||
|
|||||||
Reference in New Issue
Block a user