载入中...
搜索中...
未找到
AnimSkeleton.cpp
浏览该文件的文档.
3
4#include "common/Exception.h"
5
6namespace eve::animation {
7
8void AnimSkeleton::requireBone(int boneIndex) const {
9 if (boneIndex < 0 || boneIndex >= getBoneCount()) {
10 throw Exception("AnimSkeleton: invalid bone index %d", boneIndex);
11 }
12}
13
14int AnimSkeleton::addBone(const std::string &name, int parentIndex) {
15 if (parentIndex < -1 || parentIndex >= getBoneCount()) {
16 throw Exception("AnimSkeleton.addBone: invalid parent index %d", parentIndex);
17 }
18 if (name.empty()) {
19 throw Exception("AnimSkeleton.addBone: name must not be empty");
20 }
21 if (findBone(name) >= 0) {
22 throw Exception("AnimSkeleton.addBone: duplicate bone name '%s'", name.c_str());
23 }
24 Bone b;
25 b.name = name;
26 b.parent = parentIndex;
28 bones_.push_back(b);
29 return static_cast<int>(bones_.size()) - 1;
30}
31
32std::string AnimSkeleton::getBoneName(int boneIndex) const {
33 requireBone(boneIndex);
34 return bones_[static_cast<size_t>(boneIndex)].name;
35}
36
37int AnimSkeleton::findBone(const std::string &name) const {
38 for (int i = 0; i < getBoneCount(); ++i) {
39 if (bones_[static_cast<size_t>(i)].name == name) return i;
40 }
41 return -1;
42}
43
44int AnimSkeleton::getParent(int boneIndex) const {
45 requireBone(boneIndex);
46 return bones_[static_cast<size_t>(boneIndex)].parent;
47}
48
49void AnimSkeleton::setBindPosition(int boneIndex, float x, float y, float z) {
50 requireBone(boneIndex);
51 auto &t = bones_[static_cast<size_t>(boneIndex)].bind;
52 t.px = x;
53 t.py = y;
54 t.pz = z;
55}
56
57void AnimSkeleton::setBindRotation(int boneIndex, float x, float y, float z, float w) {
58 requireBone(boneIndex);
59 auto &t = bones_[static_cast<size_t>(boneIndex)].bind;
60 t.qx = x;
61 t.qy = y;
62 t.qz = z;
63 t.qw = w;
64 t.normalizeRotation();
65}
66
67void AnimSkeleton::setBindScale(int boneIndex, float x, float y, float z) {
68 requireBone(boneIndex);
69 auto &t = bones_[static_cast<size_t>(boneIndex)].bind;
70 t.sx = x;
71 t.sy = y;
72 t.sz = z;
73}
74
75void AnimSkeleton::setBoneLodLimit(int boneIndex, int highestLod) {
76 requireBone(boneIndex);
77 if (highestLod < 0) throw Exception("AnimSkeleton.setBoneLodLimit: highestLod must be >= 0");
78 bones_[static_cast<size_t>(boneIndex)].lodLimit = highestLod;
79}
80
81int AnimSkeleton::getBoneLodLimit(int boneIndex) const {
82 requireBone(boneIndex);
83 return bones_[static_cast<size_t>(boneIndex)].lodLimit;
84}
85
86float AnimSkeleton::getBindPositionX(int boneIndex) const {
87 requireBone(boneIndex);
88 return bones_[static_cast<size_t>(boneIndex)].bind.px;
89}
90float AnimSkeleton::getBindPositionY(int boneIndex) const {
91 requireBone(boneIndex);
92 return bones_[static_cast<size_t>(boneIndex)].bind.py;
93}
94float AnimSkeleton::getBindPositionZ(int boneIndex) const {
95 requireBone(boneIndex);
96 return bones_[static_cast<size_t>(boneIndex)].bind.pz;
97}
98float AnimSkeleton::getBindRotationX(int boneIndex) const {
99 requireBone(boneIndex);
100 return bones_[static_cast<size_t>(boneIndex)].bind.qx;
101}
102float AnimSkeleton::getBindRotationY(int boneIndex) const {
103 requireBone(boneIndex);
104 return bones_[static_cast<size_t>(boneIndex)].bind.qy;
105}
106float AnimSkeleton::getBindRotationZ(int boneIndex) const {
107 requireBone(boneIndex);
108 return bones_[static_cast<size_t>(boneIndex)].bind.qz;
109}
110float AnimSkeleton::getBindRotationW(int boneIndex) const {
111 requireBone(boneIndex);
112 return bones_[static_cast<size_t>(boneIndex)].bind.qw;
113}
114float AnimSkeleton::getBindScaleX(int boneIndex) const {
115 requireBone(boneIndex);
116 return bones_[static_cast<size_t>(boneIndex)].bind.sx;
117}
118float AnimSkeleton::getBindScaleY(int boneIndex) const {
119 requireBone(boneIndex);
120 return bones_[static_cast<size_t>(boneIndex)].bind.sy;
121}
122float AnimSkeleton::getBindScaleZ(int boneIndex) const {
123 requireBone(boneIndex);
124 return bones_[static_cast<size_t>(boneIndex)].bind.sz;
125}
126
127const TransformTRS &AnimSkeleton::bindLocal(int boneIndex) const {
128 requireBone(boneIndex);
129 return bones_[static_cast<size_t>(boneIndex)].bind;
130}
131
133 if (!pose) throw Exception("AnimSkeleton.applyBindPose: pose is null");
134 pose->resize(getBoneCount());
135 for (int i = 0; i < getBoneCount(); ++i) {
136 pose->local(i) = bones_[static_cast<size_t>(i)].bind;
137 }
138}
139
140} // namespace eve::animation
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
eve::EntitySpatialPose pose
std::int32_t parent
std::string name
MeleePoint3 b
Definition MeleeHit.cpp:41
float t
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
Evaluated local (and optional world) pose for an AnimSkeleton. Script type: AnimPose.
Definition AnimPose.h:17
float getBindPositionY(int boneIndex) const
Returns the bind position y.
float getBindScaleX(int boneIndex) const
Returns the bind scale x.
int getBoneCount() const
Returns the bone count.
int getParent(int boneIndex) const
Returns the parent.
void setBindPosition(int boneIndex, float x, float y, float z)
Sets the bind position.
float getBindPositionZ(int boneIndex) const
Returns the bind position z.
float getBindRotationW(int boneIndex) const
Returns the bind rotation w.
float getBindScaleY(int boneIndex) const
Returns the bind scale y.
float getBindRotationY(int boneIndex) const
Returns the bind rotation y.
float getBindScaleZ(int boneIndex) const
Returns the bind scale z.
float getBindPositionX(int boneIndex) const
Returns the bind position x.
const TransformTRS & bindLocal(int boneIndex) const
Binds local.
float getBindRotationZ(int boneIndex) const
Returns the bind rotation z.
float getBindRotationX(int boneIndex) const
Returns the bind rotation x.
int getBoneLodLimit(int boneIndex) const
Highest LOD at which the bone is sampled; defaults to all LODs.
std::string getBoneName(int boneIndex) const
Returns the bone name.
void setBoneLodLimit(int boneIndex, int highestLod)
Set the highest animation LOD at which this bone is sampled (0 = full-detail only)....
int findBone(const std::string &name) const
Finds bone.
void setBindScale(int boneIndex, float x, float y, float z)
Sets the bind scale.
void setBindRotation(int boneIndex, float x, float y, float z, float w)
Sets the bind rotation.
void applyBindPose(class AnimPose *pose) const
Fill pose locals with bind pose.
int addBone(const std::string &name, int parentIndex=-1)
Append a bone. parentIndex = -1 for root.
Local TRS used by skeletal animation (quaternion xyzw).
Definition AnimMath.h:9
static TransformTRS identity()
Identity.
Definition AnimMath.h:15