add hide/reveal entity

This commit is contained in:
Nick Fisher
2023-07-03 22:54:27 +08:00
parent 4adf8bbf80
commit 313fb9bebf
9 changed files with 288 additions and 137 deletions

View File

@@ -64,6 +64,8 @@ namespace polyvox {
void setMorphTargetWeights(const char* const entityName, float *weights, int count);
void loadTexture(EntityId entity, const char* resourcePath, int renderableIndex);
void setAnimationFrame(EntityId entity, int animationIndex, int animationFrame);
bool hide(EntityId entity, const char* meshName);
bool reveal(EntityId entity, const char* meshName);
private:
AssetLoader* _assetLoader = nullptr;

View File

@@ -97,6 +97,8 @@ void set_camera_rotation(void *viewer, float rads, float x, float y, float z);
void set_camera_model_matrix(void *viewer, const float *const matrix);
void set_camera_focal_length(void *viewer, float focalLength);
void set_camera_focus_distance(void *viewer, float focusDistance);
int hide_mesh(void* assetManager, EntityId asset, const char* meshName);
int reveal_mesh(void* assetManager, EntityId asset, const char* meshName);
void ios_dummy();
#endif

View File

@@ -150,20 +150,7 @@ EntityId AssetManager::loadGlb(const char *uri, bool unlit) {
_gltfResourceLoader->loadResources(asset);
// const Entity *entities = asset->getEntities();
// RenderableManager &rm = _engine->getRenderableManager();
// MaterialKey config;
// auto mi_new = _materialProvider->createMaterialInstance(&config, nullptr);
// for (int i = 0; i < asset->getEntityCount(); i++) {
// auto entityInstance = rm.getInstance(entities[i]);
// auto mi = rm.getMaterialInstanceAt(entityInstance, 0);
// // auto m = mi->getMaterial();
// // auto shading = m->getShading();
// // Log("Shading %d", shading);
// }
const Entity *entities = asset->getEntities();
auto lights = asset->getLightEntities();
_scene->addEntities(lights, asset->getLightEntityCount());
@@ -185,10 +172,46 @@ EntityId AssetManager::loadGlb(const char *uri, bool unlit) {
_entityIdLookup.emplace(eid, _assets.size());
_assets.push_back(sceneAsset);
return eid;
}
bool AssetManager::hide(EntityId entityId, const char* meshName) {
auto asset = getAssetByEntityId(entityId);
if(!asset) {
return false;
}
auto entity = findEntityByName(asset, meshName);
if(entity.isNull()) {
Log("Mesh %s could not be found", meshName);
return false;
}
_scene->remove(entity);
return true;
}
bool AssetManager::reveal(EntityId entityId, const char* meshName) {
auto asset = getAssetByEntityId(entityId);
if(!asset) {
Log("No asset found under entity ID");
return false;
}
auto entity = findEntityByName(asset, meshName);
RenderableManager &rm = _engine->getRenderableManager();
if(entity.isNull()) {
Log("Mesh %s could not be found", meshName);
return false;
}
_scene->addEntity(entity);
return true;
}
void AssetManager::destroyAll() {
for (auto& asset : _assets) {
_scene->removeEntities(asset.mAsset->getEntities(),

View File

@@ -568,6 +568,22 @@ extern "C" {
// fut.wait();
}
FLUTTER_PLUGIN_EXPORT int hide_mesh(void* assetManager, EntityId asset, const char* meshName) {
//std::packaged_task<void()> lambda([=]() mutable {
return ((AssetManager*)assetManager)->hide(asset, meshName);
//});
// auto fut = _tp->add_task(lambda);
// fut.wait();
}
FLUTTER_PLUGIN_EXPORT int reveal_mesh(void* assetManager, EntityId asset, const char* meshName) {
//std::packaged_task<void()> lambda([=]() mutable {
return ((AssetManager*)assetManager)->reveal(asset, meshName);
//});
// auto fut = _tp->add_task(lambda);
// fut.wait();
}
FLUTTER_PLUGIN_EXPORT void ios_dummy() {
Log("Dummy called");
}