void Flow::updateAbsolutePoses(const AnimPoseVec& relativePoses, AnimPoseVec& absolutePoses) { for (auto &joint : _flowJointData) { int index = joint.second.getIndex(); int parentIndex = joint.second.getParentIndex(); if (index >= 0 && index < (int)relativePoses.size() && parentIndex >= 0 && parentIndex < (int)absolutePoses.size()) { absolutePoses[index] = absolutePoses[parentIndex] * relativePoses[index]; } } }
AnimPose AnimSkeleton::getAbsolutePose(int jointIndex, const AnimPoseVec& poses) const { if (jointIndex < 0 || jointIndex >= (int)poses.size() || jointIndex >= (int)_joints.size()) { return AnimPose::identity; } else { return getAbsolutePose(_joints[jointIndex].parentIndex, poses) * poses[jointIndex]; } }
AnimPose AnimSkeleton::getAbsolutePose(int jointIndex, const AnimPoseVec& relativePoses) const { if (jointIndex < 0 || jointIndex >= (int)relativePoses.size() || jointIndex >= _jointsSize) { return AnimPose::identity; } else { return getAbsolutePose(_joints[jointIndex].parentIndex, relativePoses) * relativePoses[jointIndex]; } }
bool Flow::getJointTranslation(const AnimPoseVec& relativePoses, int jointIndex, glm::vec3& translation) const { if (jointIndex >= 0 && jointIndex < (int)relativePoses.size()) { translation = relativePoses[jointIndex].trans(); return true; } else { return false; } }
bool Flow::getJointRotation(const AnimPoseVec& relativePoses, int jointIndex, glm::quat& rotation) const { if (jointIndex >= 0 && jointIndex < (int)relativePoses.size()) { rotation = relativePoses[jointIndex].rot(); return true; } else { return false; } }
bool Flow::getJointRotationInWorldFrame(const AnimPoseVec& absolutePoses, int jointIndex, glm::quat& result, const glm::quat& rotation) const { if (jointIndex >= 0 && jointIndex < (int)absolutePoses.size()) { result = rotation * absolutePoses[jointIndex].rot(); return true; } else { return false; } }
void AnimSkeleton::convertRelativePosesToAbsolute(AnimPoseVec& poses) const { // poses start off relative and leave in absolute frame for (int i = 0; i < (int)poses.size() && i < (int)_joints.size(); ++i) { int parentIndex = _joints[i].parentIndex; if (parentIndex != -1) { poses[i] = poses[parentIndex] * poses[i]; } } }
void AnimSkeleton::convertAbsolutePosesToRelative(AnimPoseVec& poses) const { // poses start off absolute and leave in relative frame int lastIndex = std::min((int)poses.size(), _jointsSize); for (int i = lastIndex - 1; i >= 0; --i) { int parentIndex = _joints[i].parentIndex; if (parentIndex != -1) { poses[i] = poses[parentIndex].inverse() * poses[i]; } } }
void Flow::setJoints(AnimPoseVec& relativePoses, const std::vector<bool>& overrideFlags) { for (auto &thread : _jointThreads) { auto &joints = thread._joints; for (int jointIndex : joints) { auto &joint = _flowJointData[jointIndex]; if (jointIndex >= 0 && jointIndex < (int)relativePoses.size() && !overrideFlags[jointIndex]) { relativePoses[jointIndex].rot() = joint.getSettings()._active ? joint.getCurrentRotation() : joint.getInitialRotation(); } } } }
bool Flow::getJointPositionInWorldFrame(const AnimPoseVec& absolutePoses, int jointIndex, glm::vec3& position, glm::vec3 translation, glm::quat rotation) const { if (jointIndex >= 0 && jointIndex < (int)absolutePoses.size()) { glm::vec3 poseSetTrans = absolutePoses[jointIndex].trans(); position = (rotation * poseSetTrans) + translation; if (!isNaN(position)) { return true; } else { position = glm::vec3(0.0f); } } return false; }
void AnimSkeleton::mirrorAbsolutePoses(AnimPoseVec& poses) const { AnimPoseVec temp = poses; for (int i = 0; i < (int)poses.size(); i++) { poses[_mirrorMap[i]] = temp[i].mirror(); } }