Add MeshDeformation utility for generic meshes vertices morphing (eg. via Blend Shapes or Cloth)

This commit is contained in:
Wojtek Figat
2023-07-03 09:49:23 +02:00
parent 60181a29a3
commit 99ee0b1bfe
26 changed files with 600 additions and 368 deletions

View File

@@ -17,7 +17,7 @@ class FLAXENGINE_API AnimatedModel : public ModelInstanceActor
{
DECLARE_SCENE_OBJECT(AnimatedModel);
friend class AnimationsSystem;
public:
/// <summary>
/// Describes the animation graph updates frequency for the animated model.
/// </summary>
@@ -55,16 +55,27 @@ public:
};
private:
struct BlendShapeMesh
{
uint16 LODIndex;
uint16 MeshIndex;
uint32 Usages;
};
GeometryDrawStateData _drawState;
SkinnedMeshDrawData _skinningData;
AnimationUpdateMode _actualMode;
uint32 _counter;
Real _lastMinDstSqr;
uint64 _lastUpdateFrame;
BlendShapesInstance _blendShapes;
mutable MeshDeformation* _deformation = nullptr;
ScriptingObjectReference<AnimatedModel> _masterPose;
Array<Pair<String, float>> _blendShapeWeights;
Array<BlendShapeMesh> _blendShapeMeshes;
public:
~AnimatedModel();
/// <summary>
/// The skinned model asset used for rendering.
/// </summary>
@@ -291,7 +302,7 @@ public:
API_FUNCTION() void SetBlendShapeWeight(const StringView& name, float value);
/// <summary>
/// Clears the weights of the blend shapes (disabled any used blend shapes).
/// Clears the weights of the blend shapes (disables any used blend shapes).
/// </summary>
API_FUNCTION() void ClearBlendShapeWeights();
@@ -346,9 +357,9 @@ public:
private:
void ApplyRootMotion(const Transform& rootMotionDelta);
void SyncParameters();
void RunBlendShapeDeformer(const MeshBase* mesh, struct MeshDeformationData& deformation);
void Update();
void UpdateBounds();
void UpdateSockets();
void OnAnimationUpdated_Async();
void OnAnimationUpdated_Sync();
@@ -375,6 +386,8 @@ public:
bool IntersectsEntry(int32 entryIndex, const Ray& ray, Real& distance, Vector3& normal) override;
bool IntersectsEntry(const Ray& ray, Real& distance, Vector3& normal, int32& entryIndex) override;
bool GetMeshData(const MeshReference& mesh, MeshBufferType type, BytesContainer& result, int32& count) const override;
void UpdateBounds() override;
MeshDeformation* GetMeshDeformation() const override;
void OnDeleteObject() override;
protected:
@@ -384,6 +397,5 @@ protected:
void OnEnable() override;
void OnDisable() override;
void OnActiveInTreeChanged() override;
void OnTransformChanged() override;
void WaitForModelLoad() override;
};