support collisions & restructure transforms to only update once per frame

This commit is contained in:
Nick Fisher
2024-02-13 13:31:18 +08:00
parent 6561af6825
commit 1638599078
8 changed files with 144 additions and 85 deletions

View File

@@ -538,4 +538,11 @@ abstract class FilamentController {
Future<EntityTransformController> control(FilamentEntity entity,
{double? translationSpeed, String? forwardAnimation});
///
/// Make [collidableEntity] collidable.
/// At the moment, this is only relevant when controlling a different entity's transform.
/// If there is a collision between the controlled entity and [collidableEntity], the transform will not be updated.
///
Future addCollisionComponent(FilamentEntity collidableEntity);
}

View File

@@ -1358,4 +1358,13 @@ class FilamentControllerFFI extends FilamentController {
_keyboardListener = HardwareKeyboardListener(transformController);
return transformController;
}
@override
Future addCollisionComponent(FilamentEntity entity) async {
if (_assetManager == null) {
throw Exception("AssetManager must be non-null");
}
add_collision_component(_assetManager!, entity);
}
}

View File

@@ -828,6 +828,13 @@ external void flutter_filament_free(
ffi.Pointer<ffi.Void> ptr,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId)>(
symbol: 'add_collision_component', assetId: 'flutter_filament_plugin')
external void add_collision_component(
ffi.Pointer<ffi.Void> assetManager,
int entityId,
);
@ffi.Native<
ffi.Pointer<ffi.Void> Function(
ffi.Pointer<ffi.Void>,