add implementation for setMorphWeights

This commit is contained in:
Nick Fisher
2023-06-22 13:38:17 +08:00
parent 6ec9fc2988
commit 555d1199a2
9 changed files with 196 additions and 164 deletions

View File

@@ -264,9 +264,16 @@ class FilamentController {
_nativeLibrary.grab_end(_viewer);
}
void setMorphTargetWeights(FilamentEntity asset, List<double> weights) {
throw Exception("TODO");
// _nativeLibrary.set_morph_target_weights(_assetManager, asset, Float32List.fromList(weights));
void setMorphTargetWeights(
FilamentEntity asset, String meshName, List<double> weights) {
var weightPtr = calloc<Float>(weights.length);
for (int i = 0; i < weights.length; i++) {
weightPtr[i] = weights[i];
}
_nativeLibrary.set_morph_target_weights(_assetManager, asset,
meshName.toNativeUtf8().cast<Char>(), weightPtr, weights.length);
calloc.free(weightPtr);
}
List<String> getMorphTargetNames(FilamentEntity asset, String meshName) {
@@ -300,6 +307,7 @@ class FilamentController {
/// Each frame is [numWeights] in length, and each entry is the weight to be applied to the morph target located at that index in the mesh primitive at that frame.
///
void setMorphAnimation(FilamentEntity asset, MorphAnimation animation) async {
print("Setting morph animation");
var data = calloc<Float>(animation.data.length);
for (int i = 0; i < animation.data.length; i++) {
data.elementAt(i).value = animation.data[i];
@@ -393,8 +401,13 @@ class FilamentController {
_nativeLibrary.stop_animation(_assetManager, asset, animationIndex);
}
void setCamera(FilamentEntity asset, String name) async {
_nativeLibrary.set_camera(_viewer, asset, name.toNativeUtf8().cast<Char>());
void setCamera(FilamentEntity asset, String? name) async {
if (_nativeLibrary.set_camera(
_viewer, asset, name?.toNativeUtf8()?.cast<Char>() ?? nullptr) !=
1) {
throw Exception("Failed to set camera");
}
;
}
void setCameraFocalLength(double focalLength) async {

View File

@@ -618,6 +618,35 @@ class NativeLibrary {
void Function(ffi.Pointer<ffi.Void>, int, ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.Float>, int)>();
void set_morph_target_weights(
ffi.Pointer<ffi.Void> assetManager,
int asset,
ffi.Pointer<ffi.Char> entityName,
ffi.Pointer<ffi.Float> morphData,
int numWeights,
) {
return _set_morph_target_weights(
assetManager,
asset,
entityName,
morphData,
numWeights,
);
}
late final _set_morph_target_weightsPtr = _lookup<
ffi.NativeFunction<
ffi.Void Function(
ffi.Pointer<ffi.Void>,
EntityId,
ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.Float>,
ffi.Int)>>('set_morph_target_weights');
late final _set_morph_target_weights =
_set_morph_target_weightsPtr.asFunction<
void Function(ffi.Pointer<ffi.Void>, int, ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.Float>, int)>();
int set_morph_animation(
ffi.Pointer<ffi.Void> assetManager,
int asset,
@@ -1225,8 +1254,6 @@ class ResourceBuffer extends ffi.Struct {
}
class ResourceLoaderWrapper extends ffi.Struct {
external ffi.Pointer<ffi.Void> mOwner;
external LoadResource mLoadResource;
external FreeResource mFreeResource;
@@ -1234,6 +1261,8 @@ class ResourceLoaderWrapper extends ffi.Struct {
external LoadResourceFromOwner mLoadResourceFromOwner;
external FreeResourceFromOwner mFreeResourceFromOwner;
external ffi.Pointer<ffi.Void> mOwner;
}
typedef LoadResource = ffi.Pointer<