expose removeCollisionComponent

This commit is contained in:
Nick Fisher
2024-03-05 10:30:42 +08:00
parent 32fe5d9083
commit 39fa9387e6
5 changed files with 35 additions and 12 deletions

View File

@@ -194,6 +194,7 @@ extern "C"
FLUTTER_PLUGIN_EXPORT void ios_dummy();
FLUTTER_PLUGIN_EXPORT void flutter_filament_free(void *ptr);
FLUTTER_PLUGIN_EXPORT void add_collision_component(void *const sceneManager, EntityId entityId, void (*callback)(const EntityId entityId1, const EntityId entityId2), bool affectsCollidingTransform);
FLUTTER_PLUGIN_EXPORT void remove_collision_component(void *const sceneManager, EntityId entityId);
FLUTTER_PLUGIN_EXPORT void add_animation_component(void *const sceneManager, EntityId entityId);
FLUTTER_PLUGIN_EXPORT EntityId create_geometry(void *const viewer, float* vertices, int numVertices, uint16_t* indices, int numIndices, const char* materialPath);

View File

@@ -589,6 +589,10 @@ extern "C"
((SceneManager*)sceneManager)->addCollisionComponent(entityId, onCollisionCallback, affectsCollidingTransform);
}
FLUTTER_PLUGIN_EXPORT void remove_collision_component(void *const sceneManager, EntityId entityId) {
((SceneManager*)sceneManager)->removeCollisionComponent(entityId);
}
FLUTTER_PLUGIN_EXPORT void add_animation_component(void *const sceneManager, EntityId entityId) {
((SceneManager*)sceneManager)->addAnimationComponent(entityId);
}

View File

@@ -626,15 +626,18 @@ abstract class FilamentController {
Future addAnimationComponent(FilamentEntity entity);
///
/// Makes [collidableEntity] collidable with
/// (a) any entity whose transform is being controlled (via [control]) or
/// (b) any entity that has been marked as non-transformable but collidable (via [markNonTransformableCollidable])
/// These are differentiated because a collision will affect the transform for controlled entities
/// (e.g. if a controlled entity collides with a wall, we ignore the control update to the transform so it doesn't go through the wall)
/// Makes [entity] collidable.
/// This allows you to call [testCollisions] with any other entity ("entity B") to see if [entity] has collided with entity B. The callback will be invoked if so.
/// Alternatively, if [affectsTransform] is true and this entity collides with another entity, any queued position updates to the latter entity will be ignored.
///
Future addCollisionComponent(FilamentEntity collidableEntity,
Future addCollisionComponent(FilamentEntity entity,
{void Function(int entityId1, int entityId2)? callback,
bool affectsCollingTransform = false});
bool affectsTransform = false});
///
/// Removes the collision component from [entity], meaning this will no longer be tested when [testCollisions] or [queuePositionUpdate] is called with another entity.
///
Future removeCollisionComponent(FilamentEntity entity);
///
/// Creates a (renderable) entity with the specified geometry and adds to the scene.

View File

@@ -1485,10 +1485,12 @@ class FilamentControllerFFI extends FilamentController {
return transformController;
}
final _collisions = <FilamentEntity, NativeCallable>{};
@override
Future addCollisionComponent(FilamentEntity collidableEntity,
Future addCollisionComponent(FilamentEntity entity,
{void Function(int entityId1, int entityId2)? callback,
bool affectsCollingTransform = false}) async {
bool affectsTransform = false}) async {
if (_sceneManager == null) {
throw Exception("SceneManager must be non-null");
}
@@ -1497,14 +1499,20 @@ class FilamentControllerFFI extends FilamentController {
if (callback != null) {
var ptr = NativeCallable<
Void Function(Int32 entityId1, Int32 entityId2)>.listener(callback);
add_collision_component(_sceneManager!, collidableEntity,
ptr.nativeFunction, affectsCollingTransform);
add_collision_component(
_sceneManager!, entity, ptr.nativeFunction, affectsTransform);
_collisions[entity] = ptr;
} else {
add_collision_component(
_sceneManager!, collidableEntity, nullptr, affectsCollingTransform);
_sceneManager!, entity, nullptr, affectsTransform);
}
}
@override
Future removeCollisionComponent(FilamentEntity entity) async {
remove_collision_component(_sceneManager!, entity);
}
@override
Future addAnimationComponent(FilamentEntity entity) async {
add_animation_component(_sceneManager!, entity);

View File

@@ -931,6 +931,13 @@ external void add_collision_component(
bool affectsCollidingTransform,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId)>(
symbol: 'remove_collision_component', assetId: 'flutter_filament_plugin')
external void remove_collision_component(
ffi.Pointer<ffi.Void> sceneManager,
int entityId,
);
@ffi.Native<ffi.Void Function(ffi.Pointer<ffi.Void>, EntityId)>(
symbol: 'add_animation_component', assetId: 'flutter_filament_plugin')
external void add_animation_component(