allow setting material property by name

This commit is contained in:
Nick Fisher
2024-09-13 15:20:45 +08:00
parent 2eb7cc286b
commit f18f04734d
4 changed files with 60 additions and 0 deletions

View File

@@ -2460,6 +2460,41 @@ void SceneManager::queueRelativePositionUpdateWorldAxis(EntityId entity, float v
) {
return createGeometryWithNormals(vertices, numVertices, nullptr, 0, indices, numIndices, primitiveType, materialPath, keepData);
}
void SceneManager::setMaterialProperty(EntityId entityId, int materialIndex, const char* property, float value) {
auto entity = Entity::import(entityId);
const auto& rm = _engine->getRenderableManager();
auto renderableInstance = rm.getInstance(entity);
if(!renderableInstance.isValid()) {
Log("ERROR");
return;
}
auto materialInstance = rm.getMaterialInstanceAt(renderableInstance, materialIndex);
if(!materialInstance->getMaterial()->hasParameter(property)) {
Log("Parameter %s not found", property);
return;
}
materialInstance->setParameter(property, value);
}
void SceneManager::setMaterialProperty(EntityId entityId, int materialIndex, const char* property, filament::math::float4 value) {
auto entity = Entity::import(entityId);
const auto& rm = _engine->getRenderableManager();
auto renderableInstance = rm.getInstance(entity);
if(!renderableInstance.isValid()) {
Log("ERROR");
return;
}
auto materialInstance = rm.getMaterialInstanceAt(renderableInstance, materialIndex);
if(!materialInstance->getMaterial()->hasParameter(property)) {
Log("Parameter %s not found", property);
return;
}
materialInstance->setParameter(property, value);
}
} // namespace thermion_filament