restructure render loop to correct timings and expose FFI methods for setBoneTransform/setMorphWeights
This commit is contained in:
@@ -485,4 +485,11 @@ abstract class FilamentController {
|
||||
double orbitSpeedX = 0.01,
|
||||
double orbitSpeedY = 0.01,
|
||||
double zoomSpeed = 0.01});
|
||||
|
||||
///
|
||||
/// Finds the child entity named [childName] associated with the given parent.
|
||||
/// Usually, [parent] will be the return value from [loadGlb]/[loadGltf] and [childName] will be the name of a node/mesh.
|
||||
///
|
||||
Future<FilamentEntity> getChildEntity(
|
||||
FilamentEntity parent, String childName);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,9 @@ class FilamentControllerFFI extends FilamentController {
|
||||
|
||||
@override
|
||||
Future setFrameRate(int framerate) async {
|
||||
set_frame_interval_ffi(1.0 / framerate);
|
||||
final interval = 1000.0 / framerate;
|
||||
set_frame_interval_ffi(interval);
|
||||
dev.log("Set frame interval to $interval");
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -596,7 +598,7 @@ class FilamentControllerFFI extends FilamentController {
|
||||
weightsPtr.elementAt(i).value = weights[i];
|
||||
}
|
||||
var meshNamePtr = meshName.toNativeUtf8(allocator: calloc).cast<Char>();
|
||||
set_morph_target_weights(
|
||||
set_morph_target_weights_ffi(
|
||||
_assetManager!, entity, meshNamePtr, weightsPtr, weights.length);
|
||||
calloc.free(weightsPtr);
|
||||
calloc.free(meshNamePtr);
|
||||
@@ -1178,7 +1180,7 @@ class FilamentControllerFFI extends FilamentController {
|
||||
var meshNamePtr = meshName.toNativeUtf8(allocator: calloc).cast<Char>();
|
||||
var boneNamePtr = boneName.toNativeUtf8(allocator: calloc).cast<Char>();
|
||||
|
||||
var result = set_bone_transform(
|
||||
var result = set_bone_transform_ffi(
|
||||
_assetManager!, entity, meshNamePtr, ptr, boneNamePtr);
|
||||
|
||||
calloc.free(ptr);
|
||||
@@ -1188,4 +1190,21 @@ class FilamentControllerFFI extends FilamentController {
|
||||
throw Exception("Failed to set bone transform. See logs for details");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<FilamentEntity> getChildEntity(
|
||||
FilamentEntity parent, String childName) async {
|
||||
var childNamePtr = childName.toNativeUtf8(allocator: calloc).cast<Char>();
|
||||
try {
|
||||
var childEntity =
|
||||
find_child_entity_by_name(_assetManager!, parent, childNamePtr);
|
||||
if (childEntity == _FILAMENT_ASSET_ERROR) {
|
||||
throw Exception(
|
||||
"Could not find child ${childName} under the specified entity");
|
||||
}
|
||||
return childEntity;
|
||||
} finally {
|
||||
calloc.free(childNamePtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -736,6 +736,16 @@ external ffi.Pointer<ffi.Char> get_name_for_entity(
|
||||
int entityId,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
EntityId Function(
|
||||
ffi.Pointer<ffi.Void>, EntityId, ffi.Pointer<ffi.Char>)>(
|
||||
symbol: 'find_child_entity_by_name', assetId: 'flutter_filament_plugin')
|
||||
external int find_child_entity_by_name(
|
||||
ffi.Pointer<ffi.Void> assetManager,
|
||||
int parent,
|
||||
ffi.Pointer<ffi.Char> name,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Void Function()>(
|
||||
symbol: 'ios_dummy', assetId: 'flutter_filament_plugin')
|
||||
external void ios_dummy();
|
||||
@@ -1092,6 +1102,34 @@ external int get_morph_target_name_count_ffi(
|
||||
ffi.Pointer<ffi.Char> meshName,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId,
|
||||
ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Float>, ffi.Int)>(
|
||||
symbol: 'set_morph_target_weights_ffi', assetId: 'flutter_filament_plugin')
|
||||
external void set_morph_target_weights_ffi(
|
||||
ffi.Pointer<ffi.Void> assetManager,
|
||||
int asset,
|
||||
ffi.Pointer<ffi.Char> entityName,
|
||||
ffi.Pointer<ffi.Float> morphData,
|
||||
int numWeights,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Bool Function(
|
||||
ffi.Pointer<ffi.Void>,
|
||||
EntityId,
|
||||
ffi.Pointer<ffi.Char>,
|
||||
ffi.Pointer<ffi.Float>,
|
||||
ffi.Pointer<ffi.Char>)>(
|
||||
symbol: 'set_bone_transform_ffi', assetId: 'flutter_filament_plugin')
|
||||
external bool set_bone_transform_ffi(
|
||||
ffi.Pointer<ffi.Void> assetManager,
|
||||
int asset,
|
||||
ffi.Pointer<ffi.Char> entityName,
|
||||
ffi.Pointer<ffi.Float> transform,
|
||||
ffi.Pointer<ffi.Char> boneName,
|
||||
);
|
||||
|
||||
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>, ffi.Bool)>(
|
||||
symbol: 'set_post_processing_ffi', assetId: 'flutter_filament_plugin')
|
||||
external void set_post_processing_ffi(
|
||||
|
||||
Reference in New Issue
Block a user