载入中...
搜索中...
未找到
MotionDatabase.h
浏览该文件的文档.
1#pragma once
2
4
5#include <string>
6#include <vector>
7
8namespace eve::animation {
9
10class AnimClip;
11class AnimSkeleton;
12
23public:
24 explicit MotionDatabase(AnimSkeleton *skeleton);
25 ~MotionDatabase() = default;
26
27 MotionDatabase(const MotionDatabase &) = delete;
29
30 AnimSkeleton *getSkeleton() const { return skeleton_; }
31
33 void addFeatureBone(int boneIndex);
34 void addFeatureBoneByName(const std::string &name);
35
40 void setRootBone(int boneIndex);
41 int getRootBone() const { return rootBone_; }
42 void setRootBoneByName(const std::string &name);
43
44 void addClip(AnimClip *clip);
45 int getClipCount() const { return static_cast<int>(clips_.size()); }
46
48 void bake();
49 bool isBaked() const { return baked_; }
50
51 int getFrameCount() const { return static_cast<int>(frames_.size()); }
52 int getFeatureSize() const { return featureSize_; }
53
54 float getFrameTime(int frameIndex) const;
55 int getFrameClipIndex(int frameIndex) const;
56 AnimClip *getClip(int clipIndex) const;
57
58 int getFeatureBoneCount() const { return static_cast<int>(featureBones_.size()); }
59 int getFeatureBone(int index) const;
60
62 void getFeature(int frameIndex, float *out, int outCount) const;
63
64 struct Frame {
65 int clipIndex = 0;
66 float time = 0.f;
67 std::vector<float> feature;
68 // Cached root for trajectory reconstruction helpers.
69 float rootX = 0.f, rootZ = 0.f, rootYaw = 0.f;
70 float velX = 0.f, velZ = 0.f;
71 };
72
73 const Frame &frameAt(int index) const;
74
75private:
76 void requireBaked() const;
77 void computeFeatureSize();
78 void extractFeature(AnimClip *clip, float time, float dtSample, std::vector<float> &out,
79 float &rootX, float &rootZ, float &rootYaw, float &velX,
80 float &velZ) const;
81 static float yawFromQuat(float x, float y, float z, float w);
82
83 AnimSkeleton *skeleton_ = nullptr;
84 std::vector<AnimClip *> clips_;
85 std::vector<int> featureBones_;
86 std::vector<Frame> frames_;
87 int featureSize_ = 0;
88 int rootBone_ = 0;
89 bool baked_ = false;
90 mutable AnimPose scratchPose_;
91};
92
93} // namespace eve::animation
int y
Definition Grass.cpp:135
int z
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
int w
const char * name
Definition RockMesh.cpp:21
Keyframed skeletal animation clip (local TRS tracks per bone). Script type: AnimClip.
Definition AnimClip.h:17
Evaluated local (and optional world) pose for an AnimSkeleton. Script type: AnimPose.
Definition AnimPose.h:15
3D bone hierarchy + bind-pose local TRS for skeletal animation. Independent of ik::Skeleton3D (FABRIK...
Baked motion-matching feature database from one or more AnimClips. Feature layout per frame: [0....
void setRootBoneByName(const std::string &name)
MotionDatabase(const MotionDatabase &)=delete
AnimSkeleton * getSkeleton() const
void getFeature(int frameIndex, float *out, int outCount) const
Copy feature vector into out[0..featureSize).
void addFeatureBone(int boneIndex)
Include bone world position in pose features (by index).
float getFrameTime(int frameIndex) const
AnimClip * getClip(int clipIndex) const
const Frame & frameAt(int index) const
MotionDatabase & operator=(const MotionDatabase &)=delete
void addFeatureBoneByName(const std::string &name)
void bake()
Bake all clips into searchable frames. Call after addClip / feature bones.
int getFeatureBone(int index) const
void setRootBone(int boneIndex)
Bone used for trajectory / velocity features (default 0). Mixamo clips typically want hips (mixamorig...
int getFrameClipIndex(int frameIndex) const