rename setLayerEnabled to setLayerVisibility, add setVisibilityLayer method
This commit is contained in:
@@ -55,6 +55,7 @@ namespace thermion_filament
|
||||
|
||||
enum LAYERS {
|
||||
DEFAULT_ASSETS = 0,
|
||||
BACKGROUND = 6,
|
||||
OVERLAY = 7,
|
||||
};
|
||||
|
||||
@@ -229,11 +230,8 @@ namespace thermion_filament
|
||||
|
||||
///
|
||||
/// Toggles the visibility of the given layer.
|
||||
/// Layer 0 - regular scene assets
|
||||
/// Layer 1 - unused
|
||||
/// Layer 2 - grid
|
||||
///
|
||||
void setLayerEnabled(int layer, bool enabled);
|
||||
void setLayerVisibility(SceneManager::LAYERS layer, bool enabled);
|
||||
|
||||
///
|
||||
/// Creates an entity with the specified geometry/material/normals and adds to the scene.
|
||||
@@ -284,6 +282,8 @@ namespace thermion_filament
|
||||
return _assetLoader->createInstance(asset);
|
||||
}
|
||||
|
||||
MaterialInstance* getMaterialInstanceAt(EntityId entityId, int materialIndex);
|
||||
|
||||
void setMaterialProperty(EntityId entity, int materialIndex, const char* property, float value);
|
||||
void setMaterialProperty(EntityId entity, int materialIndex, const char* property, int32_t value);
|
||||
void setMaterialProperty(EntityId entityId, int materialIndex, const char* property, filament::math::float4& value);
|
||||
@@ -298,6 +298,8 @@ namespace thermion_filament
|
||||
|
||||
MaterialInstance* createUnlitMaterialInstance();
|
||||
|
||||
void setVisibilityLayer(EntityId entityId, int layer);
|
||||
|
||||
private:
|
||||
gltfio::AssetLoader *_assetLoader = nullptr;
|
||||
const ResourceLoaderWrapperImpl *const _resourceLoaderWrapper;
|
||||
|
||||
@@ -269,11 +269,13 @@ extern "C"
|
||||
EMSCRIPTEN_KEEPALIVE void get_gizmo(void *const sceneManager, EntityId *out);
|
||||
EMSCRIPTEN_KEEPALIVE Aabb2 get_bounding_box(void *const sceneManager, EntityId entity);
|
||||
EMSCRIPTEN_KEEPALIVE void get_bounding_box_to_out(void *const sceneManager, EntityId entity, float *minX, float *minY, float *maxX, float *maxY);
|
||||
EMSCRIPTEN_KEEPALIVE void set_layer_enabled(void *const sceneManager, int layer, bool enabled);
|
||||
EMSCRIPTEN_KEEPALIVE void set_layer_visibility(void *const sceneManager, int layer, bool visible);
|
||||
EMSCRIPTEN_KEEPALIVE void set_visibility_layer(void *const sceneManager, EntityId entity, int layer);
|
||||
EMSCRIPTEN_KEEPALIVE void pick_gizmo(void *const sceneManager, int x, int y, void (*callback)(EntityId entityId, int x, int y));
|
||||
EMSCRIPTEN_KEEPALIVE void set_gizmo_visibility(void *const sceneManager, bool visible);
|
||||
EMSCRIPTEN_KEEPALIVE void set_stencil_highlight(void *const sceneManager, EntityId entity, float r, float g, float b);
|
||||
EMSCRIPTEN_KEEPALIVE void remove_stencil_highlight(void *const sceneManager, EntityId entity);
|
||||
EMSCRIPTEN_KEEPALIVE TMaterialInstance* get_material_instance_at(void *const sceneManager, EntityId entity, int materialIndex);
|
||||
EMSCRIPTEN_KEEPALIVE void set_material_property_float(void *const sceneManager, EntityId entity, int materialIndex, const char *property, float value);
|
||||
EMSCRIPTEN_KEEPALIVE void set_material_property_int(void *const sceneManager, EntityId entity, int materialIndex, const char *property, int value);
|
||||
EMSCRIPTEN_KEEPALIVE void set_material_property_float4(void *const sceneManager, EntityId entity, int materialIndex, const char *property, double4 value);
|
||||
|
||||
@@ -584,6 +584,7 @@ namespace thermion_filament
|
||||
.material(0, _imageMaterial->getDefaultInstance())
|
||||
.geometry(0, RenderableManager::PrimitiveType::TRIANGLES, _imageVb,
|
||||
_imageIb, 0, 3)
|
||||
.layerMask(0xFF, 1u << SceneManager::LAYERS::BACKGROUND)
|
||||
.culling(false)
|
||||
.build(*_engine, _imageEntity);
|
||||
_scene->addEntity(_imageEntity);
|
||||
@@ -969,7 +970,11 @@ namespace thermion_filament
|
||||
delete vec; },
|
||||
callbackData);
|
||||
_skybox =
|
||||
filament::Skybox::Builder().environment(_skyboxTexture).build(*_engine);
|
||||
filament::Skybox::Builder()
|
||||
.environment(_skyboxTexture)
|
||||
.build(*_engine);
|
||||
|
||||
_skybox->setLayerMask(0xFF, 1u << SceneManager::LAYERS::BACKGROUND);
|
||||
|
||||
_scene->setSkybox(_skybox);
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ namespace thermion_filament
|
||||
_scene->addEntity(_gridOverlay->grid());
|
||||
|
||||
_view->setLayerEnabled(SceneManager::LAYERS::DEFAULT_ASSETS, true);
|
||||
_view->setLayerEnabled(SceneManager::LAYERS::BACKGROUND, true); // skybox + image
|
||||
_view->setLayerEnabled(SceneManager::LAYERS::OVERLAY, false); // world grid + gizmo
|
||||
}
|
||||
|
||||
@@ -238,6 +239,17 @@ namespace thermion_filament
|
||||
return eid;
|
||||
}
|
||||
|
||||
void SceneManager::setVisibilityLayer(EntityId entityId, int layer) {
|
||||
auto& rm = _engine->getRenderableManager();
|
||||
auto renderable = rm.getInstance(utils::Entity::import(entityId));
|
||||
if(!renderable.isValid()) {
|
||||
Log("Warning: no renderable found");
|
||||
}
|
||||
|
||||
rm.setLayerMask(renderable, 0xFF, 1u << layer);
|
||||
|
||||
}
|
||||
|
||||
EntityId SceneManager::loadGlbFromBuffer(const uint8_t *data, size_t length, int numInstances, bool keepData, int priority, int layer)
|
||||
{
|
||||
|
||||
@@ -2393,7 +2405,7 @@ namespace thermion_filament
|
||||
return Aabb2{minX, minY, maxX, maxY};
|
||||
}
|
||||
|
||||
void SceneManager::setLayerEnabled(int layer, bool enabled)
|
||||
void SceneManager::setLayerVisibility(LAYERS layer, bool enabled)
|
||||
{
|
||||
_view->setLayerEnabled(layer, enabled);
|
||||
}
|
||||
@@ -2528,6 +2540,18 @@ EntityId SceneManager::createGeometry(
|
||||
return entityId;
|
||||
}
|
||||
|
||||
MaterialInstance* SceneManager::getMaterialInstanceAt(EntityId entityId, int materialIndex) {
|
||||
auto entity = Entity::import(entityId);
|
||||
const auto &rm = _engine->getRenderableManager();
|
||||
auto renderableInstance = rm.getInstance(entity);
|
||||
if (!renderableInstance.isValid())
|
||||
{
|
||||
Log("Error retrieving material instance: no renderable found for entity %d");
|
||||
return std::nullptr_t();
|
||||
}
|
||||
return rm.getMaterialInstanceAt(renderableInstance, materialIndex);
|
||||
}
|
||||
|
||||
void SceneManager::setMaterialProperty(EntityId entityId, int materialIndex, const char *property, float value)
|
||||
{
|
||||
auto entity = Entity::import(entityId);
|
||||
@@ -2620,7 +2644,6 @@ EntityId SceneManager::createGeometry(
|
||||
return;
|
||||
}
|
||||
auto materialInstance = rm.getMaterialInstanceAt(renderableInstance, materialIndex);
|
||||
|
||||
materialInstance->setDepthWrite(enabled);
|
||||
}
|
||||
|
||||
|
||||
@@ -927,9 +927,14 @@ extern "C"
|
||||
*maxY = box.maxY;
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void set_layer_enabled(void *const sceneManager, int layer, bool enabled)
|
||||
EMSCRIPTEN_KEEPALIVE void set_visibility_layer(void *const sceneManager, EntityId entity, int layer) {
|
||||
((SceneManager*)sceneManager)->setVisibilityLayer(entity, layer);
|
||||
}
|
||||
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void set_layer_visibility(void *const sceneManager, int layer, bool visible)
|
||||
{
|
||||
((SceneManager *)sceneManager)->setLayerEnabled(layer, enabled);
|
||||
((SceneManager *)sceneManager)->setLayerVisibility((SceneManager::LAYERS)layer, visible);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void thermion_flutter_free(void *ptr)
|
||||
@@ -962,9 +967,13 @@ extern "C"
|
||||
((SceneManager *)sceneManager)->setMaterialProperty(entity, materialIndex, property, value);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE TMaterialInstance* get_material_instance_at(void *const sceneManager, EntityId entity, int materialIndex) {
|
||||
auto instance = ((SceneManager *)sceneManager)->getMaterialInstanceAt(entity, materialIndex);
|
||||
return reinterpret_cast<TMaterialInstance*>(instance);
|
||||
}
|
||||
|
||||
EMSCRIPTEN_KEEPALIVE void set_material_property_int(void *const sceneManager, EntityId entity, int materialIndex, const char *property, int32_t value)
|
||||
{
|
||||
|
||||
((SceneManager *)sceneManager)->setMaterialProperty(entity, materialIndex, property, value);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user