add setBoneTransform method
This commit is contained in:
@@ -279,6 +279,12 @@ abstract class FilamentController {
|
||||
///
|
||||
Future setBoneAnimation(FilamentEntity entity, BoneAnimationData animation);
|
||||
|
||||
///
|
||||
/// 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);
|
||||
|
||||
///
|
||||
/// Removes/destroys the specified entity from the scene.
|
||||
/// [entity] will no longer be a valid handle after this method is called; ensure you immediately discard all references once this method is complete.
|
||||
|
||||
@@ -1160,4 +1160,18 @@ class FilamentControllerFFI extends FilamentController {
|
||||
|
||||
return frustum;
|
||||
}
|
||||
|
||||
@override
|
||||
Future setBoneTransform(FilamentEntity entity, String meshName, int boneIndex,
|
||||
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);
|
||||
|
||||
calloc.free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,6 +388,18 @@ external void set_bone_animation(
|
||||
double frameLengthInMs,
|
||||
);
|
||||
|
||||
@ffi.Native<
|
||||
ffi.Bool Function(ffi.Pointer<ffi.Void>, EntityId,
|
||||
ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Float>, ffi.Int)>(
|
||||
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.Native<
|
||||
ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId, ffi.Int, ffi.Bool,
|
||||
ffi.Bool, ffi.Bool, ffi.Float)>(
|
||||
|
||||
@@ -139,18 +139,18 @@ class _SizedFilamentWidgetState extends State<_SizedFilamentWidget> {
|
||||
);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
||||
try {
|
||||
widget.controller.setDimensions(_rect, MediaQuery.of(context).devicePixelRatio);
|
||||
try {
|
||||
widget.controller
|
||||
.setDimensions(_rect, MediaQuery.of(context).devicePixelRatio);
|
||||
} catch (err) {
|
||||
dev.log("Fatal error : $err");
|
||||
_error = err.toString();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
||||
Timer? _resizeTimer;
|
||||
bool _resizing = false;
|
||||
|
||||
@@ -162,26 +162,29 @@ class _SizedFilamentWidgetState extends State<_SizedFilamentWidget> {
|
||||
// any subsequent widget resizes will cancel the timer and replace with a new one.
|
||||
// debug mode does need a longer timeout.
|
||||
_resizeTimer?.cancel();
|
||||
_resizeTimer = Timer(Duration(milliseconds: (kReleaseMode || Platform.isWindows) ? 10 : 100), () async {
|
||||
await widget.controller
|
||||
.setDimensions(_rect, MediaQuery.of(context).devicePixelRatio);
|
||||
_resizeTimer = Timer(
|
||||
Duration(milliseconds: (kReleaseMode || Platform.isWindows) ? 10 : 100),
|
||||
() async {
|
||||
try {
|
||||
|
||||
while(_resizing) {
|
||||
while (_resizing) {
|
||||
await Future.delayed(const Duration(milliseconds: 20));
|
||||
}
|
||||
_resizing = true;
|
||||
await widget.controller.setDimensions(_rect, MediaQuery.of(context).devicePixelRatio);
|
||||
await widget.controller
|
||||
.setDimensions(_rect, MediaQuery.of(context).devicePixelRatio);
|
||||
await widget.controller.resize();
|
||||
_resizeTimer = null;
|
||||
setState(() {});
|
||||
} catch (err) {
|
||||
dev.log("Error resizing FilamentWidget: $err");
|
||||
} finally {
|
||||
} finally {
|
||||
_resizing = false;
|
||||
completer.complete();
|
||||
}
|
||||
});
|
||||
return completer.future;
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user