internal: pass NameComponentManager to GltfSceneAsset, used for finding child entities by name
This commit is contained in:
@@ -11,6 +11,9 @@
|
|||||||
#include <gltfio/FilamentAsset.h>
|
#include <gltfio/FilamentAsset.h>
|
||||||
#include <gltfio/MaterialProvider.h>
|
#include <gltfio/MaterialProvider.h>
|
||||||
|
|
||||||
|
#include <utils/NameComponentManager.h>
|
||||||
|
|
||||||
|
|
||||||
#include "scene/GltfSceneAssetInstance.hpp"
|
#include "scene/GltfSceneAssetInstance.hpp"
|
||||||
#include "components/AnimationComponentManager.hpp"
|
#include "components/AnimationComponentManager.hpp"
|
||||||
#include "components/CollisionComponentManager.hpp"
|
#include "components/CollisionComponentManager.hpp"
|
||||||
@@ -29,11 +32,13 @@ namespace thermion
|
|||||||
gltfio::FilamentAsset *asset,
|
gltfio::FilamentAsset *asset,
|
||||||
gltfio::AssetLoader *assetLoader,
|
gltfio::AssetLoader *assetLoader,
|
||||||
Engine *engine,
|
Engine *engine,
|
||||||
|
utils::NameComponentManager* ncm,
|
||||||
MaterialInstance **materialInstances = nullptr,
|
MaterialInstance **materialInstances = nullptr,
|
||||||
size_t materialInstanceCount = 0,
|
size_t materialInstanceCount = 0,
|
||||||
int instanceIndex = -1) : _asset(asset),
|
int instanceIndex = -1) : _asset(asset),
|
||||||
_assetLoader(assetLoader),
|
_assetLoader(assetLoader),
|
||||||
_engine(engine),
|
_engine(engine),
|
||||||
|
_ncm(ncm),
|
||||||
_materialInstances(materialInstances),
|
_materialInstances(materialInstances),
|
||||||
_materialInstanceCount(materialInstanceCount)
|
_materialInstanceCount(materialInstanceCount)
|
||||||
{
|
{
|
||||||
@@ -150,6 +155,7 @@ namespace thermion
|
|||||||
}
|
}
|
||||||
|
|
||||||
Entity findEntityByName(const char* name) override {
|
Entity findEntityByName(const char* name) override {
|
||||||
|
TRACE("Searching for entity with name %s", name);
|
||||||
Entity entities[1];
|
Entity entities[1];
|
||||||
auto found = _asset->getEntitiesByName(name, entities, 1);
|
auto found = _asset->getEntitiesByName(name, entities, 1);
|
||||||
return entities[0];
|
return entities[0];
|
||||||
@@ -159,6 +165,7 @@ namespace thermion
|
|||||||
gltfio::FilamentAsset *_asset;
|
gltfio::FilamentAsset *_asset;
|
||||||
gltfio::AssetLoader *_assetLoader;
|
gltfio::AssetLoader *_assetLoader;
|
||||||
Engine *_engine;
|
Engine *_engine;
|
||||||
|
utils::NameComponentManager *_ncm;
|
||||||
MaterialInstance **_materialInstances = nullptr;
|
MaterialInstance **_materialInstances = nullptr;
|
||||||
size_t _materialInstanceCount = 0;
|
size_t _materialInstanceCount = 0;
|
||||||
std::vector<std::unique_ptr<GltfSceneAssetInstance>> _instances;
|
std::vector<std::unique_ptr<GltfSceneAssetInstance>> _instances;
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
#include <gltfio/FilamentInstance.h>
|
#include <gltfio/FilamentInstance.h>
|
||||||
#include <gltfio/MaterialProvider.h>
|
#include <gltfio/MaterialProvider.h>
|
||||||
|
|
||||||
|
#include <utils/NameComponentManager.h>
|
||||||
|
|
||||||
#include "scene/SceneAsset.hpp"
|
#include "scene/SceneAsset.hpp"
|
||||||
|
|
||||||
namespace thermion
|
namespace thermion
|
||||||
@@ -24,9 +26,11 @@ namespace thermion
|
|||||||
GltfSceneAssetInstance(
|
GltfSceneAssetInstance(
|
||||||
gltfio::FilamentInstance *instance,
|
gltfio::FilamentInstance *instance,
|
||||||
Engine *engine,
|
Engine *engine,
|
||||||
|
utils::NameComponentManager* ncm,
|
||||||
MaterialInstance **materialInstances = nullptr,
|
MaterialInstance **materialInstances = nullptr,
|
||||||
size_t materialInstanceCount = 0,
|
size_t materialInstanceCount = 0,
|
||||||
int instanceIndex = -1) : _instance(instance),
|
int instanceIndex = -1) : _ncm(ncm),
|
||||||
|
_instance(instance),
|
||||||
_materialInstances(materialInstances),
|
_materialInstances(materialInstances),
|
||||||
_materialInstanceCount(materialInstanceCount)
|
_materialInstanceCount(materialInstanceCount)
|
||||||
{
|
{
|
||||||
@@ -102,7 +106,22 @@ namespace thermion
|
|||||||
}
|
}
|
||||||
|
|
||||||
Entity findEntityByName(const char* name) override {
|
Entity findEntityByName(const char* name) override {
|
||||||
return Entity(); // not currently implemented
|
|
||||||
|
TRACE("Searching for entity with name %s", name);
|
||||||
|
|
||||||
|
for(int i = 0; i < getChildEntityCount(); i++) {
|
||||||
|
auto entity = getChildEntities()[i];
|
||||||
|
auto nameInstance = _ncm->getInstance(entity);
|
||||||
|
auto entityName = _ncm->getName(nameInstance);
|
||||||
|
|
||||||
|
if (strcmp(entityName, name) == 0) {
|
||||||
|
TRACE("Found entity name : %s", entityName);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
TRACE("Skipping entity : %s", entityName);
|
||||||
|
|
||||||
|
}
|
||||||
|
return Entity();
|
||||||
}
|
}
|
||||||
|
|
||||||
SceneAsset *getInstanceByEntity(utils::Entity entity) override {
|
SceneAsset *getInstanceByEntity(utils::Entity entity) override {
|
||||||
@@ -139,6 +158,7 @@ namespace thermion
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
filament::Engine *_engine;
|
filament::Engine *_engine;
|
||||||
|
utils::NameComponentManager *_ncm;
|
||||||
gltfio::FilamentInstance *_instance;
|
gltfio::FilamentInstance *_instance;
|
||||||
MaterialInstance **_materialInstances = nullptr;
|
MaterialInstance **_materialInstances = nullptr;
|
||||||
size_t _materialInstanceCount = 0;
|
size_t _materialInstanceCount = 0;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace thermion
|
|||||||
Log("No instances available for reuse. When loading the asset, you must pre-allocate the number of instances you wish to make available for use. Try increasing this number.");
|
Log("No instances available for reuse. When loading the asset, you must pre-allocate the number of instances you wish to make available for use. Try increasing this number.");
|
||||||
return std::nullptr_t();
|
return std::nullptr_t();
|
||||||
}
|
}
|
||||||
Log("Creating instance %d", instanceNumber);
|
TRACE("Creating instance %d", instanceNumber);
|
||||||
auto instance = _asset->getAssetInstances()[instanceNumber];
|
auto instance = _asset->getAssetInstances()[instanceNumber];
|
||||||
instance->recomputeBoundingBoxes();
|
instance->recomputeBoundingBoxes();
|
||||||
instance->getAnimator()->updateBoneMatrices();
|
instance->getAnimator()->updateBoneMatrices();
|
||||||
@@ -49,6 +49,7 @@ namespace thermion
|
|||||||
std::unique_ptr<GltfSceneAssetInstance> sceneAssetInstance = std::make_unique<GltfSceneAssetInstance>(
|
std::unique_ptr<GltfSceneAssetInstance> sceneAssetInstance = std::make_unique<GltfSceneAssetInstance>(
|
||||||
instance,
|
instance,
|
||||||
_engine,
|
_engine,
|
||||||
|
_ncm,
|
||||||
materialInstances,
|
materialInstances,
|
||||||
materialInstanceCount
|
materialInstanceCount
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -285,7 +285,9 @@ namespace thermion
|
|||||||
auto sceneAsset = std::make_unique<GltfSceneAsset>(
|
auto sceneAsset = std::make_unique<GltfSceneAsset>(
|
||||||
asset,
|
asset,
|
||||||
_assetLoader,
|
_assetLoader,
|
||||||
_engine);
|
_engine,
|
||||||
|
_ncm
|
||||||
|
);
|
||||||
auto filamentInstance = asset->getInstance();
|
auto filamentInstance = asset->getInstance();
|
||||||
size_t entityCount = filamentInstance->getEntityCount();
|
size_t entityCount = filamentInstance->getEntityCount();
|
||||||
|
|
||||||
@@ -372,7 +374,9 @@ namespace thermion
|
|||||||
auto sceneAsset = std::make_unique<GltfSceneAsset>(
|
auto sceneAsset = std::make_unique<GltfSceneAsset>(
|
||||||
asset,
|
asset,
|
||||||
_assetLoader,
|
_assetLoader,
|
||||||
_engine);
|
_engine,
|
||||||
|
_ncm
|
||||||
|
);
|
||||||
|
|
||||||
auto sceneAssetInstance = sceneAsset->createInstance();
|
auto sceneAssetInstance = sceneAsset->createInstance();
|
||||||
if(addToScene) {
|
if(addToScene) {
|
||||||
|
|||||||
Reference in New Issue
Block a user