mirror of
https://github.com/lubosz/overte.git
synced 2025-04-18 04:18:17 +02:00
optimizations for debug rendering of AnimSkeleton
This commit is contained in:
parent
b8bae7cc3f
commit
d1fdbe32d2
3 changed files with 22 additions and 11 deletions
|
@ -12,6 +12,14 @@
|
|||
|
||||
AnimSkeleton::AnimSkeleton(const std::vector<FBXJoint>& joints) {
|
||||
_joints = joints;
|
||||
|
||||
// build a cache of bind poses
|
||||
_bindPoses.reserve(joints.size());
|
||||
for (size_t i = 0; i < joints.size(); i++) {
|
||||
_bindPoses.push_back(AnimPose(extractScale(_joints[i].bindTransform),
|
||||
glm::quat_cast(_joints[i].bindTransform),
|
||||
extractTranslation(_joints[i].bindTransform)));
|
||||
}
|
||||
}
|
||||
|
||||
int AnimSkeleton::nameToJointIndex(const QString& jointName) const {
|
||||
|
@ -28,11 +36,7 @@ int AnimSkeleton::getNumJoints() const {
|
|||
}
|
||||
|
||||
AnimPose AnimSkeleton::getBindPose(int jointIndex) const {
|
||||
// TODO: perhaps cache these, it's expensive to de-compose the matrix
|
||||
// on every call.
|
||||
return AnimPose(extractScale(_joints[jointIndex].bindTransform),
|
||||
glm::quat_cast(_joints[jointIndex].bindTransform),
|
||||
extractTranslation(_joints[jointIndex].bindTransform));
|
||||
return _bindPoses[jointIndex];
|
||||
}
|
||||
|
||||
int AnimSkeleton::getParentIndex(int jointIndex) const {
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
|
||||
protected:
|
||||
std::vector<FBXJoint> _joints;
|
||||
std::vector<AnimPose> _bindPoses;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -187,30 +187,36 @@ void AnimDebugDraw::update() {
|
|||
for (int i = 0; i < skeleton->getNumJoints(); i++) {
|
||||
AnimPose pose = skeleton->getBindPose(i);
|
||||
|
||||
v->pos = xform.transform(pose.trans);
|
||||
glm::vec3 base = xform.transform(pose.trans);
|
||||
|
||||
// x-axis
|
||||
v->pos = base;
|
||||
v->rgba = red;
|
||||
v++;
|
||||
v->pos = xform.transform(pose.trans + pose.rot * glm::vec3(pose.scale.x, 0.0f, 0.0f));
|
||||
v->pos = base + pose.rot * glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
v->rgba = red;
|
||||
v++;
|
||||
|
||||
// y-axis
|
||||
v->pos = xform.transform(pose.trans);
|
||||
v->rgba = green;
|
||||
v++;
|
||||
v->pos = xform.transform(pose.trans + pose.rot * glm::vec3(0.0f, pose.scale.y, 0.0f));
|
||||
v->pos = base + pose.rot * glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
v->rgba = green;
|
||||
v++;
|
||||
|
||||
v->pos = xform.transform(pose.trans);
|
||||
// z-axis
|
||||
v->pos = base;
|
||||
v->rgba = blue;
|
||||
v++;
|
||||
v->pos = xform.transform(pose.trans + pose.rot * glm::vec3(0.0f, 0.0f, pose.scale.z));
|
||||
v->pos = base + pose.rot * glm::vec3(0.0f, 0.0f, 1.0f);
|
||||
v->rgba = blue;
|
||||
v++;
|
||||
|
||||
// line to parent.
|
||||
if (skeleton->getParentIndex(i) >= 0) {
|
||||
AnimPose parentPose = skeleton->getBindPose(skeleton->getParentIndex(i));
|
||||
v->pos = xform.transform(pose.trans);
|
||||
v->pos = base;
|
||||
v->rgba = gray;
|
||||
v++;
|
||||
v->pos = xform.transform(parentPose.trans);
|
||||
|
|
Loading…
Reference in a new issue