allow adding AnimationComponent/morph target animations to arbitrary entities

This commit is contained in:
Nick Fisher
2024-04-26 10:53:16 +08:00
parent 4b348f62eb
commit fc4bb19569

View File

@@ -76,7 +76,8 @@ extern "C"
((FilamentViewer *)viewer)->loadIbl(iblPath, intensity); ((FilamentViewer *)viewer)->loadIbl(iblPath, intensity);
} }
FLUTTER_PLUGIN_EXPORT void rotate_ibl(const void *const viewer, float* rotationMatrix) { FLUTTER_PLUGIN_EXPORT void rotate_ibl(const void *const viewer, float *rotationMatrix)
{
math::mat3f matrix(rotationMatrix[0], rotationMatrix[1], math::mat3f matrix(rotationMatrix[0], rotationMatrix[1],
rotationMatrix[2], rotationMatrix[2],
rotationMatrix[3], rotationMatrix[3],
@@ -124,15 +125,18 @@ extern "C"
return ((SceneManager *)sceneManager)->loadGlbFromBuffer((const uint8_t *)data, length); return ((SceneManager *)sceneManager)->loadGlbFromBuffer((const uint8_t *)data, length);
} }
FLUTTER_PLUGIN_EXPORT EntityId create_instance(void *sceneManager, EntityId entityId) { FLUTTER_PLUGIN_EXPORT EntityId create_instance(void *sceneManager, EntityId entityId)
{
return ((SceneManager *)sceneManager)->createInstance(entityId); return ((SceneManager *)sceneManager)->createInstance(entityId);
} }
FLUTTER_PLUGIN_EXPORT int get_instance_count(void *sceneManager, EntityId entityId) { FLUTTER_PLUGIN_EXPORT int get_instance_count(void *sceneManager, EntityId entityId)
{
return ((SceneManager *)sceneManager)->getInstanceCount(entityId); return ((SceneManager *)sceneManager)->getInstanceCount(entityId);
} }
FLUTTER_PLUGIN_EXPORT void get_instances(void *sceneManager, EntityId entityId, EntityId *out) { FLUTTER_PLUGIN_EXPORT void get_instances(void *sceneManager, EntityId entityId, EntityId *out)
{
return ((SceneManager *)sceneManager)->getInstances(entityId, out); return ((SceneManager *)sceneManager)->getInstances(entityId, out);
} }
@@ -146,7 +150,6 @@ extern "C"
return ((FilamentViewer *)viewer)->setMainCamera(); return ((FilamentViewer *)viewer)->setMainCamera();
} }
FLUTTER_PLUGIN_EXPORT EntityId get_main_camera(const void *const viewer) FLUTTER_PLUGIN_EXPORT EntityId get_main_camera(const void *const viewer)
{ {
return ((FilamentViewer *)viewer)->getMainCamera(); return ((FilamentViewer *)viewer)->getMainCamera();
@@ -204,11 +207,13 @@ extern "C"
((FilamentViewer *)viewer)->setCameraCulling(near, far); ((FilamentViewer *)viewer)->setCameraCulling(near, far);
} }
double get_camera_culling_near(const void *const viewer) { double get_camera_culling_near(const void *const viewer)
{
return ((FilamentViewer *)viewer)->getCameraCullingNear(); return ((FilamentViewer *)viewer)->getCameraCullingNear();
} }
double get_camera_culling_far(const void *const viewer) { double get_camera_culling_far(const void *const viewer)
{
return ((FilamentViewer *)viewer)->getCameraCullingFar(); return ((FilamentViewer *)viewer)->getCameraCullingFar();
} }
@@ -351,21 +356,18 @@ extern "C"
// ((SceneManager*)sceneManager)->setMorphTargetWeights(asset, entityName, weights, count); // ((SceneManager*)sceneManager)->setMorphTargetWeights(asset, entityName, weights, count);
} }
FLUTTER_PLUGIN_EXPORT void set_morph_target_weights( FLUTTER_PLUGIN_EXPORT bool set_morph_target_weights(
void *sceneManager, void *sceneManager,
EntityId asset, EntityId asset,
const char *const entityName,
const float *const weights, const float *const weights,
const int numWeights) const int numWeights)
{ {
return ((SceneManager *)sceneManager)->setMorphTargetWeights(asset, weights, numWeights);
return ((SceneManager *)sceneManager)->setMorphTargetWeights(asset, entityName, weights, numWeights);
} }
bool set_morph_animation( bool set_morph_animation(
void *sceneManager, void *sceneManager,
EntityId asset, EntityId asset,
const char *const entityName,
const float *const morphData, const float *const morphData,
const int *const morphIndices, const int *const morphIndices,
int numMorphTargets, int numMorphTargets,
@@ -373,10 +375,11 @@ extern "C"
float frameLengthInMs) float frameLengthInMs)
{ {
return ((SceneManager *)sceneManager)->setMorphAnimationBuffer(asset, entityName, morphData, morphIndices, numMorphTargets, numFrames, frameLengthInMs); return ((SceneManager *)sceneManager)->setMorphAnimationBuffer(asset, morphData, morphIndices, numMorphTargets, numFrames, frameLengthInMs);
} }
FLUTTER_PLUGIN_EXPORT void reset_to_rest_pose(void *sceneManager, EntityId entityId) { FLUTTER_PLUGIN_EXPORT void reset_to_rest_pose(void *sceneManager, EntityId entityId)
{
((SceneManager *)sceneManager)->resetBones(entityId); ((SceneManager *)sceneManager)->resetBones(entityId);
} }
@@ -399,11 +402,11 @@ extern "C"
((FilamentViewer *)viewer)->setPostProcessing(enabled); ((FilamentViewer *)viewer)->setPostProcessing(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)
{
((FilamentViewer *)viewer)->setAntiAliasing(msaa, fxaa, taa); ((FilamentViewer *)viewer)->setAntiAliasing(msaa, fxaa, taa);
} }
FLUTTER_PLUGIN_EXPORT bool set_bone_transform( FLUTTER_PLUGIN_EXPORT bool set_bone_transform(
void *sceneManager, void *sceneManager,
EntityId entityId, EntityId entityId,
@@ -477,13 +480,13 @@ extern "C"
FLUTTER_PLUGIN_EXPORT int get_morph_target_name_count(void *sceneManager, EntityId asset, const char *meshName) FLUTTER_PLUGIN_EXPORT int get_morph_target_name_count(void *sceneManager, EntityId asset, const char *meshName)
{ {
std::unique_ptr<std::vector<std::string>> names = ((SceneManager *)sceneManager)->getMorphTargetNames(asset, meshName); auto names = ((SceneManager *)sceneManager)->getMorphTargetNames(asset, meshName);
return (int)names->size(); return (int)names->size();
} }
FLUTTER_PLUGIN_EXPORT void get_morph_target_name(void *sceneManager, EntityId asset, const char *meshName, char *const outPtr, int index) FLUTTER_PLUGIN_EXPORT void get_morph_target_name(void *sceneManager, EntityId asset, const char *meshName, char *const outPtr, int index)
{ {
std::unique_ptr<std::vector<std::string>> names = ((SceneManager *)sceneManager)->getMorphTargetNames(asset, meshName); auto names = ((SceneManager *)sceneManager)->getMorphTargetNames(asset, meshName);
std::string name = names->at(index); std::string name = names->at(index);
strcpy(outPtr, name.c_str()); strcpy(outPtr, name.c_str());
} }
@@ -558,24 +561,28 @@ extern "C"
return ((SceneManager *)sceneManager)->getNameForEntity(entityId); return ((SceneManager *)sceneManager)->getNameForEntity(entityId);
} }
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)
{
return ((SceneManager *)sceneManager)->getEntityCount(target, renderableOnly); return ((SceneManager *)sceneManager)->getEntityCount(target, renderableOnly);
} }
FLUTTER_PLUGIN_EXPORT void get_entities(void *const sceneManager, const EntityId target, bool renderableOnly, EntityId* out) { FLUTTER_PLUGIN_EXPORT void get_entities(void *const sceneManager, const EntityId target, bool renderableOnly, EntityId *out)
{
((SceneManager *)sceneManager)->getEntities(target, renderableOnly, out); ((SceneManager *)sceneManager)->getEntities(target, renderableOnly, out);
} }
FLUTTER_PLUGIN_EXPORT const char* get_entity_name_at(void *const sceneManager, const EntityId target, int index, bool renderableOnly) { FLUTTER_PLUGIN_EXPORT const char *get_entity_name_at(void *const sceneManager, const EntityId target, int index, bool renderableOnly)
{
return ((SceneManager *)sceneManager)->getEntityNameAt(target, index, renderableOnly); return ((SceneManager *)sceneManager)->getEntityNameAt(target, index, renderableOnly);
} }
FLUTTER_PLUGIN_EXPORT void set_recording(void *const viewer, bool recording)
FLUTTER_PLUGIN_EXPORT void set_recording(void *const viewer, bool recording) { {
((FilamentViewer *)viewer)->setRecording(recording); ((FilamentViewer *)viewer)->setRecording(recording);
} }
FLUTTER_PLUGIN_EXPORT void set_recording_output_directory(void *const viewer, const char* outputDirectory) { FLUTTER_PLUGIN_EXPORT void set_recording_output_directory(void *const viewer, const char *outputDirectory)
{
((FilamentViewer *)viewer)->setRecordingOutputDirectory(outputDirectory); ((FilamentViewer *)viewer)->setRecordingOutputDirectory(outputDirectory);
} }
@@ -589,48 +596,49 @@ extern "C"
free(ptr); free(ptr);
} }
FLUTTER_PLUGIN_EXPORT void add_collision_component(void *const sceneManager, EntityId entityId, void (*onCollisionCallback)(const EntityId entityId1, const EntityId entityId2), bool affectsCollidingTransform) { FLUTTER_PLUGIN_EXPORT void add_collision_component(void *const sceneManager, EntityId entityId, void (*onCollisionCallback)(const EntityId entityId1, const EntityId entityId2), bool affectsCollidingTransform)
{
((SceneManager *)sceneManager)->addCollisionComponent(entityId, onCollisionCallback, affectsCollidingTransform); ((SceneManager *)sceneManager)->addCollisionComponent(entityId, onCollisionCallback, affectsCollidingTransform);
} }
FLUTTER_PLUGIN_EXPORT void remove_collision_component(void *const sceneManager, EntityId entityId) { FLUTTER_PLUGIN_EXPORT void remove_collision_component(void *const sceneManager, EntityId entityId)
{
((SceneManager *)sceneManager)->removeCollisionComponent(entityId); ((SceneManager *)sceneManager)->removeCollisionComponent(entityId);
} }
FLUTTER_PLUGIN_EXPORT void add_animation_component(void *const sceneManager, EntityId entityId) { FLUTTER_PLUGIN_EXPORT bool add_animation_component(void *const sceneManager, EntityId entityId)
((SceneManager*)sceneManager)->addAnimationComponent(entityId); {
return ((SceneManager *)sceneManager)->addAnimationComponent(entityId);
} }
FLUTTER_PLUGIN_EXPORT EntityId create_geometry(void *const viewer, float* vertices, int numVertices, uint16_t* indices, int numIndices, int primitiveType, const char* materialPath) { FLUTTER_PLUGIN_EXPORT EntityId create_geometry(void *const viewer, float *vertices, int numVertices, uint16_t *indices, int numIndices, int primitiveType, const char *materialPath)
return ((FilamentViewer*)viewer)->createGeometry( {
vertices, return ((FilamentViewer *)viewer)->createGeometry(vertices, (uint32_t)numVertices, indices, numIndices, (filament::RenderableManager::PrimitiveType)primitiveType, materialPath);
(uint32_t)numVertices,
indices,
numIndices,
(filament::RenderableManager::PrimitiveType)primitiveType,
materialPath
);
} }
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)
{
auto entity = ((SceneManager *)sceneManager)->findChildEntityByName(parent, name); auto entity = ((SceneManager *)sceneManager)->findChildEntityByName(parent, name);
return utils::Entity::smuggle(entity); return utils::Entity::smuggle(entity);
} }
FLUTTER_PLUGIN_EXPORT void set_parent(void *const sceneManager, EntityId child, EntityId parent) { FLUTTER_PLUGIN_EXPORT void set_parent(void *const sceneManager, EntityId child, EntityId parent)
{
((SceneManager *)sceneManager)->setParent(child, parent); ((SceneManager *)sceneManager)->setParent(child, parent);
} }
FLUTTER_PLUGIN_EXPORT void test_collisions(void *const sceneManager, EntityId entity) { FLUTTER_PLUGIN_EXPORT void test_collisions(void *const sceneManager, EntityId entity)
{
((SceneManager *)sceneManager)->testCollisions(entity); ((SceneManager *)sceneManager)->testCollisions(entity);
} }
FLUTTER_PLUGIN_EXPORT void set_priority(void *const sceneManager, EntityId entity, int priority) { FLUTTER_PLUGIN_EXPORT void set_priority(void *const sceneManager, EntityId entity, int priority)
{
((SceneManager *)sceneManager)->setPriority(entity, priority); ((SceneManager *)sceneManager)->setPriority(entity, priority);
} }
FLUTTER_PLUGIN_EXPORT void get_gizmo(void *const sceneManager, EntityId* out) { FLUTTER_PLUGIN_EXPORT void get_gizmo(void *const sceneManager, EntityId *out)
{
return ((SceneManager *)sceneManager)->getGizmo(out); return ((SceneManager *)sceneManager)->getGizmo(out);
} }
} }