use boneName instead of boneIndex for setBoneTransform

This commit is contained in:
Nick Fisher
2023-11-18 00:28:31 +08:00
parent 572a945025
commit 0c698d16e3
8 changed files with 45 additions and 39 deletions

View File

@@ -27,6 +27,9 @@ class MorphAnimationData {
Iterable<double> getData(String morphName) sync* {
int index = morphTargets.indexOf(morphName);
if (index == -1) {
throw Exception("No data for morph $morphName");
}
for (int i = 0; i < numFrames; i++) {
yield data[(i * numMorphTargets) + index];
}

View File

@@ -280,7 +280,7 @@ abstract class FilamentController {
/// Sets the local joint transform for the bone at the given index in [entity] for the mesh under [meshName].
///
Future setBoneTransform(
FilamentEntity entity, String meshName, int boneIndex, Matrix4 data);
FilamentEntity entity, String meshName, String boneName, Matrix4 data);
///
/// Removes/destroys the specified entity from the scene.

View File

@@ -1161,16 +1161,20 @@ class FilamentControllerFFI extends FilamentController {
}
@override
Future setBoneTransform(FilamentEntity entity, String meshName, int boneIndex,
Matrix4 data) async {
Future setBoneTransform(FilamentEntity entity, String meshName,
String boneName, Matrix4 data) async {
var ptr = calloc<Float>(16);
for (int i = 0; i < 16; i++) {
ptr.elementAt(i).value = data.storage[i];
}
set_bone_transform(_assetManager!, entity,
meshName.toNativeUtf8().cast<Char>(), ptr, boneIndex);
var meshNamePtr = meshName.toNativeUtf8(allocator: calloc).cast<Char>();
var boneNamePtr = boneName.toNativeUtf8(allocator: calloc).cast<Char>();
set_bone_transform(_assetManager!, entity, meshNamePtr, ptr, boneNamePtr);
calloc.free(ptr);
calloc.free(meshNamePtr);
calloc.free(boneNamePtr);
}
}

View File

@@ -387,15 +387,19 @@ external void add_bone_animation(
);
@ffi.Native<
ffi.Bool Function(ffi.Pointer<ffi.Void>, EntityId,
ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Float>, ffi.Int)>(
ffi.Bool Function(
ffi.Pointer<ffi.Void>,
EntityId,
ffi.Pointer<ffi.Char>,
ffi.Pointer<ffi.Float>,
ffi.Pointer<ffi.Char>)>(
symbol: 'set_bone_transform', assetId: 'flutter_filament_plugin')
external bool set_bone_transform(
ffi.Pointer<ffi.Void> assetManager,
int asset,
ffi.Pointer<ffi.Char> entityName,
ffi.Pointer<ffi.Float> transform,
int boneIndex,
ffi.Pointer<ffi.Char> boneName,
);
@ffi.Native<
@@ -1049,30 +1053,6 @@ external bool set_morph_animation_ffi(
double frameLengthInMs,
);
@ffi.Native<
ffi.Void Function(
ffi.Pointer<ffi.Void>,
EntityId,
ffi.Pointer<ffi.Float>,
ffi.Int,
ffi.Int,
ffi.Pointer<ffi.Pointer<ffi.Char>>,
ffi.Pointer<ffi.Pointer<ffi.Char>>,
ffi.Int,
ffi.Float)>(
symbol: 'set_bone_animation_ffi', assetId: 'flutter_filament_plugin')
external void set_bone_animation_ffi(
ffi.Pointer<ffi.Void> assetManager,
int asset,
ffi.Pointer<ffi.Float> frameData,
int numFrames,
int numBones,
ffi.Pointer<ffi.Pointer<ffi.Char>> boneNames,
ffi.Pointer<ffi.Pointer<ffi.Char>> meshName,
int numMeshTargets,
double frameLengthInMs,
);
@ffi.Native<
ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId, ffi.Int, ffi.Bool,
ffi.Bool, ffi.Bool, ffi.Float)>(