allow setting material property by name

This commit is contained in:
Nick Fisher
2024-09-13 15:27:46 +08:00
parent 6ef8d19e94
commit ad205679cb
2 changed files with 44 additions and 0 deletions

View File

@@ -593,9 +593,23 @@ abstract class ThermionViewer {
///
/// Sets the `baseColorFactor` property for the material at index [materialIndex] in [entity] under node [meshName] to [color].
///
@Deprecated("Use setMaterialPropertyFloat4 instead")
Future setMaterialColor(ThermionEntity entity, String meshName,
int materialIndex, double r, double g, double b, double a);
///
/// Sets the material property [propertyName] under material [materialIndex] for [entity] to [value].
/// [entity] must have a Renderable attached.
///
Future setMaterialPropertyFloat4(ThermionEntity entity, String propertyName,
int materialIndex, double f1, double f2, double f3, double f4);
///
/// Sets the material property [propertyName] under material [materialIndex] for [entity] to [value].
/// [entity] must have a Renderable attached.
///
Future setMaterialPropertyFloat(ThermionEntity entity, String propertyName, int materialIndex, double value);
///
/// Scale [entity] to fit within the unit cube.
///
@@ -867,4 +881,5 @@ abstract class ThermionViewer {
/// Removes the outline around [entity]. Noop if there was no highlight.
///
Future removeStencilHighlight(ThermionEntity entity);
}

View File

@@ -1943,4 +1943,33 @@ class ThermionViewerFFI extends ThermionViewer {
Future removeStencilHighlight(ThermionEntity entity) async {
remove_stencil_highlight(_sceneManager!, entity);
}
///
/// Sets the material property [propertyName] under material [materialIndex] for [entity] to [value].
/// [entity] must have a Renderable attached.
///
Future setMaterialPropertyFloat(ThermionEntity entity, String propertyName,
int materialIndex, double value) async {
final ptr = propertyName.toNativeUtf8(allocator: allocator);
set_material_property_float(
_sceneManager!, entity, materialIndex, ptr.cast<Char>(), value);
allocator.free(ptr);
}
///
/// Sets the material property [propertyName] under material [materialIndex] for [entity] to {f1,f2,f3,f4}.
/// [entity] must have a Renderable attached.
///
Future setMaterialPropertyFloat4(ThermionEntity entity, String propertyName,
int materialIndex, double f1, double f2, double f3, double f4) async {
final ptr = propertyName.toNativeUtf8(allocator: allocator);
var struct = Struct.create<float4>();
struct.x = f1;
struct.y = f2;
struct.z = f3;
struct.w = f3;
set_material_property_float4(_sceneManager!, entity, materialIndex,
ptr.cast<Char>(), struct);
allocator.free(ptr);
}
}