pass callback to native pick() and remove pick_ffi

This commit is contained in:
Nick Fisher
2024-03-09 11:17:25 +08:00
parent 6e9a02b5b5
commit 13fa60e8de
5 changed files with 6 additions and 8 deletions

View File

@@ -125,7 +125,7 @@ namespace flutter_filament
void scrollBegin(); void scrollBegin();
void scrollUpdate(float x, float y, float delta); void scrollUpdate(float x, float y, float delta);
void scrollEnd(); void scrollEnd();
void pick(uint32_t x, uint32_t y, EntityId *entityId); void pick(uint32_t x, uint32_t y, void (*callback)(EntityId entityId, int x, int y));
EntityId addLight(LightManager::Type t, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows); EntityId addLight(LightManager::Type t, float colour, float intensity, float posX, float posY, float posZ, float dirX, float dirY, float dirZ, bool shadows);
void removeLight(EntityId entityId); void removeLight(EntityId entityId);

View File

@@ -184,7 +184,7 @@ extern "C"
FLUTTER_PLUGIN_EXPORT int reveal_mesh(void *sceneManager, EntityId asset, const char *meshName); FLUTTER_PLUGIN_EXPORT int reveal_mesh(void *sceneManager, EntityId asset, const char *meshName);
FLUTTER_PLUGIN_EXPORT void set_post_processing(void *const viewer, bool enabled); FLUTTER_PLUGIN_EXPORT void set_post_processing(void *const viewer, bool enabled);
FLUTTER_PLUGIN_EXPORT void set_antialiasing(void *const viewer, bool msaa, bool fxaa, bool taa); FLUTTER_PLUGIN_EXPORT void set_antialiasing(void *const viewer, bool msaa, bool fxaa, bool taa);
FLUTTER_PLUGIN_EXPORT void pick(void *const viewer, int x, int y, EntityId *entityId); FLUTTER_PLUGIN_EXPORT void pick(void *const viewer, int x, int y, void (*callback)(EntityId entityId, int x, int y));
FLUTTER_PLUGIN_EXPORT const char *get_name_for_entity(void *const sceneManager, const EntityId entityId); FLUTTER_PLUGIN_EXPORT const char *get_name_for_entity(void *const sceneManager, const EntityId entityId);
FLUTTER_PLUGIN_EXPORT EntityId find_child_entity_by_name(void *const sceneManager, const EntityId parent, const char* name); FLUTTER_PLUGIN_EXPORT EntityId find_child_entity_by_name(void *const sceneManager, const EntityId parent, const char* name);
FLUTTER_PLUGIN_EXPORT int get_entity_count(void *const sceneManager, const EntityId target, bool renderableOnly); FLUTTER_PLUGIN_EXPORT int get_entity_count(void *const sceneManager, const EntityId target, bool renderableOnly);

View File

@@ -113,7 +113,6 @@ extern "C"
float frameLengthInMs, float frameLengthInMs,
bool isModelSpace); bool isModelSpace);
FLUTTER_PLUGIN_EXPORT void set_post_processing_ffi(void *const viewer, bool enabled); FLUTTER_PLUGIN_EXPORT void set_post_processing_ffi(void *const viewer, bool enabled);
FLUTTER_PLUGIN_EXPORT void pick_ffi(void *const viewer, int x, int y, EntityId *entityId);
FLUTTER_PLUGIN_EXPORT void reset_to_rest_pose_ffi(void *const sceneManager, EntityId entityId); FLUTTER_PLUGIN_EXPORT void reset_to_rest_pose_ffi(void *const sceneManager, EntityId entityId);
FLUTTER_PLUGIN_EXPORT void ios_dummy_ffi(); FLUTTER_PLUGIN_EXPORT void ios_dummy_ffi();
FLUTTER_PLUGIN_EXPORT void create_geometry_ffi(void *const viewer, float *vertices, int numVertices, uint16_t *indices, int numIndices, const char *materialPath, void (*callback)(EntityId)); FLUTTER_PLUGIN_EXPORT void create_geometry_ffi(void *const viewer, float *vertices, int numVertices, uint16_t *indices, int numIndices, const char *materialPath, void (*callback)(EntityId));

View File

@@ -1442,12 +1442,11 @@ namespace flutter_filament
_manipulator = nullptr; _manipulator = nullptr;
} }
void FilamentViewer::pick(uint32_t x, uint32_t y, EntityId *entityId) void FilamentViewer::pick(uint32_t x, uint32_t y, void (*callback)(EntityId entityId, int x, int y))
{ {
_view->pick(x, y, [=](filament::View::PickingQueryResult const &result) _view->pick(x, y, [=](filament::View::PickingQueryResult const &result)
{ {
callback(Entity::smuggle(result.renderable), x, y);
*entityId = Entity::smuggle(result.renderable);
}); });
} }

View File

@@ -548,9 +548,9 @@ extern "C"
return ((SceneManager *)sceneManager)->reveal(asset, meshName); return ((SceneManager *)sceneManager)->reveal(asset, meshName);
} }
FLUTTER_PLUGIN_EXPORT void pick(void *const viewer, int x, int y, EntityId *entityId) FLUTTER_PLUGIN_EXPORT void pick(void *const viewer, int x, int y, void (*callback)(EntityId entityId, int x, int y))
{ {
((FilamentViewer *)viewer)->pick(static_cast<uint32_t>(x), static_cast<uint32_t>(y), static_cast<int32_t *>(entityId)); ((FilamentViewer *)viewer)->pick(static_cast<uint32_t>(x), static_cast<uint32_t>(y), callback);
} }
FLUTTER_PLUGIN_EXPORT const char *get_name_for_entity(void *const sceneManager, const EntityId entityId) FLUTTER_PLUGIN_EXPORT const char *get_name_for_entity(void *const sceneManager, const EntityId entityId)