add method for setting material color

This commit is contained in:
Nick Fisher
2023-08-19 13:52:57 +08:00
parent ed72c16724
commit 042439a72b
7 changed files with 823 additions and 754 deletions

View File

@@ -218,6 +218,9 @@ class _ExampleWidgetState extends State<ExampleWidget> {
.build();
_filamentController.setMorphAnimationData(_cube!, animation);
}, "animate morph weights #3 and #4"),
_item(() {
_filamentController.setMaterialColor(_cube!, "Cone", 0, Colors.purple);
}, "set cone material color to purple")
];
if (_animations != null) {
children.addAll(_animations!.map((a) => _item(() {

View File

@@ -615,7 +615,18 @@ public class SwiftPolyvoxFilamentPlugin: NSObject, FlutterPlugin, FlutterTexture
case "setCameraFocusDistance":
set_camera_focus_distance(viewer, call.arguments as! Float)
result(true)
case "setMaterialColor":
guard let args = call.arguments as? [Any], args.count == 5,
let assetManager = args[0] as? Int64,
let asset = args[1] as? EntityId,
let meshName = args[2] as? String,
let materialIndex = args[3] as? Int32,
let color = args[4] as? [Double] else {
result(FlutterError(code: "INVALID_ARGUMENTS", message: "Expected correct arguments for setMaterialColor", details: nil))
return
}
set_material_color(unsafeBitCast(assetManager, to:UnsafeMutableRawPointer.self), asset, meshName, materialIndex, Float(color[0]), Float(color[1]), Float(color[2]), Float(color[3]))
result(true)
case "hideMesh":
guard let args = call.arguments as? [Any], args.count == 3,

View File

@@ -40,6 +40,7 @@ namespace polyvox {
const utils::Entity* getLightEntities(EntityId e) const noexcept;
size_t getLightEntityCount(EntityId e) const noexcept;
void updateAnimations();
bool setMaterialColor(EntityId e, const char* meshName, int materialInstance, const float r, const float g, const float b, const float a);
bool setMorphAnimationBuffer(
EntityId entityId,

View File

@@ -82,6 +82,7 @@ void remove_asset(const void* const viewer, EntityId asset);
void clear_assets(const void* const viewer);
void load_texture(void* assetManager, EntityId asset, const char *assetPath, int renderableIndex);
void set_texture(void* assetManager, EntityId asset);
bool set_material_color(void* assetManager, EntityId asset, const char* meshName, int materialIndex, const float r, const float g, const float b, const float a);
void transform_to_unit_cube(void* assetManager, EntityId asset);
void set_position(void* assetManager, EntityId asset, float x, float y, float z);
void set_rotation(void* assetManager, EntityId asset, float rads, float x, float y, float z);

File diff suppressed because it is too large Load Diff

View File

@@ -337,6 +337,10 @@ extern "C" {
// ((AssetManager*)assetManager)->setTexture();
}
bool set_material_color(void* assetManager, EntityId asset, const char* meshName, int materialIndex, const float r, const float g, const float b, const float a) {
return ((AssetManager*)assetManager)->setMaterialColor(asset, meshName, materialIndex, r, g, b, a);
}
FLUTTER_PLUGIN_EXPORT void transform_to_unit_cube(void* assetManager, EntityId asset) {
((AssetManager*)assetManager)->transformToUnitCube(asset);
}

View File

@@ -260,13 +260,12 @@ class FilamentController {
///
void setMorphAnimationData(
FilamentEntity asset, MorphAnimationData animation) async {
print("SETTING animation with ${animation.data}");
await _channel.invokeMethod("setMorphAnimation", [
_assetManager,
asset,
animation.meshName,
animation.data,
animation.morphIndices,
animation.animatedMorphIndices,
animation.numMorphTargets,
animation.numFrames,
animation.frameLengthInMs
@@ -402,6 +401,22 @@ class FilamentController {
await _channel.invokeMethod("setTexture", [_assetManager, asset]);
}
void setMaterialColor(FilamentEntity asset, String meshName,
int materialIndex, Color color) async {
await _channel.invokeMethod("setMaterialColor", [
_assetManager,
asset,
meshName,
materialIndex,
[
color.red.toDouble() / 255.0,
color.green.toDouble() / 255.0,
color.blue.toDouble() / 255.0,
color.alpha.toDouble() / 255.0
]
]);
}
void transformToUnitCube(FilamentEntity asset) async {
await _channel.invokeMethod("transformToUnitCube", [_assetManager, asset]);
}