allow adding AnimationComponent/morph target animations to arbitrary entities

This commit is contained in:
Nick Fisher
2024-04-26 10:51:38 +08:00
parent 6fe436a5cc
commit f2efb0d7d1
2 changed files with 616 additions and 471 deletions

View File

@@ -30,10 +30,9 @@ namespace flutter_filament
using namespace filament;
using namespace filament::gltfio;
using namespace utils;
using std::vector;
using std::unique_ptr;
using std::string;
using std::unique_ptr;
using std::vector;
class SceneManager
{
@@ -44,7 +43,6 @@ namespace flutter_filament
const char *uberArchivePath);
~SceneManager();
EntityId loadGltf(const char *uri, const char *relativeResourcePath);
////
@@ -54,7 +52,7 @@ namespace flutter_filament
/// @return an Entity representing the FilamentAsset associated with the loaded FilamentAsset.
///
EntityId loadGlb(const char *uri, int numInstances);
EntityId loadGlbFromBuffer(const uint8_t* data, size_t length, int numInstances=1);
EntityId loadGlbFromBuffer(const uint8_t *data, size_t length, int numInstances = 1);
EntityId createInstance(EntityId entityId);
void remove(EntityId entity);
@@ -81,14 +79,13 @@ namespace flutter_filament
bool setMorphAnimationBuffer(
EntityId entityId,
const char *entityName,
const float *const morphData,
const int *const morphIndices,
int numMorphTargets,
int numFrames,
float frameLengthInMs);
void setMorphTargetWeights(EntityId entityId, const char *const entityName, const float *const weights, int count);
bool setMorphTargetWeights(EntityId entityId, const float *const weights, int count);
/// @brief Set the local transform for the bone at boneIndex/skinIndex in the given entity.
/// @param entityId the parent entity
@@ -97,7 +94,7 @@ namespace flutter_filament
/// @param boneName the name of the bone
/// @param transform the 4x4 matrix representing the local transform for the bone
/// @return true if the transform was successfully set, false otherwise
bool setBoneTransform(EntityId entityId, const char *entityName, int skinIndex, const char* boneName, math::mat4f transform);
bool setBoneTransform(EntityId entityId, const char *entityName, int skinIndex, const char *boneName, math::mat4f transform);
/// @brief Set frame data to animate the given bones/entities.
/// @param entity the parent entity
@@ -131,11 +128,11 @@ namespace flutter_filament
const char *entityName);
int getEntityCount(EntityId entity, bool renderableOnly);
void getEntities(EntityId entity, bool renderableOnly, EntityId *out);
const char* getEntityNameAt(EntityId entity, int index, bool renderableOnly);
const char *getEntityNameAt(EntityId entity, int index, bool renderableOnly);
void addCollisionComponent(EntityId entity, void (*onCollisionCallback)(const EntityId entityId1, const EntityId entityId2), bool affectsCollidingTransform);
void removeCollisionComponent(EntityId entityId);
void setParent(EntityId child, EntityId parent);
void addAnimationComponent(EntityId entity);
bool addAnimationComponent(EntityId entity);
/// @brief returns the number of instances of the FilamentAsset represented by the given entity.
/// @param entityId
@@ -144,24 +141,21 @@ namespace flutter_filament
/// @brief returns an array containing all instances of the FilamentAsset represented by the given entity.
/// @param entityId
void getInstances(EntityId entityId, EntityId* out);
void getInstances(EntityId entityId, EntityId *out);
///
/// Sets the draw priority for the given entity. See RenderableManager.h for more details.
///
void setPriority(EntityId entity, int priority);
/// @brief returns the gizmo entity, used to manipulate the global transform for entities
/// @param out a pointer to an array of three EntityId {x, y, z}
/// @return
///
void getGizmo(EntityId* out);
void getGizmo(EntityId *out);
friend class FilamentViewer;
private:
gltfio::AssetLoader *_assetLoader = nullptr;
const ResourceLoaderWrapper *const _resourceLoaderWrapper;
@@ -172,30 +166,30 @@ namespace flutter_filament
gltfio::TextureProvider *_stbDecoder = nullptr;
gltfio::TextureProvider *_ktxDecoder = nullptr;
std::mutex _mutex;
Material* _gizmoMaterial;
Material *_gizmoMaterial;
utils::NameComponentManager* _ncm;
utils::NameComponentManager *_ncm;
tsl::robin_map<
EntityId,
gltfio::FilamentInstance*> _instances;
tsl::robin_map<EntityId, gltfio::FilamentAsset*> _assets;
tsl::robin_map<EntityId, std::tuple<math::float3,bool,math::quatf,bool,float>> _transformUpdates;
gltfio::FilamentInstance *>
_instances;
tsl::robin_map<EntityId, gltfio::FilamentAsset *> _assets;
tsl::robin_map<EntityId, std::tuple<math::float3, bool, math::quatf, bool, float>> _transformUpdates;
AnimationComponentManager* _animationComponentManager = nullptr;
CollisionComponentManager* _collisionComponentManager = nullptr;
AnimationComponentManager *_animationComponentManager = nullptr;
CollisionComponentManager *_collisionComponentManager = nullptr;
gltfio::FilamentInstance* getInstanceByEntityId(EntityId entityId);
gltfio::FilamentAsset* getAssetByEntityId(EntityId entityId);
gltfio::FilamentInstance *getInstanceByEntityId(EntityId entityId);
gltfio::FilamentAsset *getAssetByEntityId(EntityId entityId);
utils::Entity findEntityByName(
const gltfio::FilamentInstance* instance,
const gltfio::FilamentInstance *instance,
const char *entityName);
EntityId addGizmo();
utils::Entity _gizmoX;
utils::Entity _gizmoY;
utils::Entity _gizmoZ;
};
}

File diff suppressed because it is too large Load Diff