mirror of
https://github.com/overte-org/overte.git
synced 2025-04-24 20:34:20 +02:00
in the process of changing the rotation application to being absolute joints not local
This commit is contained in:
parent
6b4620b4a1
commit
8735b409ab
4 changed files with 48 additions and 56 deletions
|
@ -2037,9 +2037,7 @@ controller::Pose MyAvatar::getControllerPoseInSensorFrame(controller::Action act
|
|||
|
||||
controller::Pose MyAvatar::getControllerPoseInWorldFrame(controller::Action action) const {
|
||||
auto pose = getControllerPoseInSensorFrame(action);
|
||||
qCDebug(interfaceapp) << "avatar sensor orientation " << pose.getRotation();
|
||||
if (pose.valid) {
|
||||
qCDebug(interfaceapp) << "sensor to world matrix orientation " << extractRotation(getSensorToWorldMatrix());
|
||||
return pose.transform(getSensorToWorldMatrix());
|
||||
} else {
|
||||
return controller::Pose(); // invalid pose
|
||||
|
@ -2049,7 +2047,6 @@ controller::Pose MyAvatar::getControllerPoseInWorldFrame(controller::Action acti
|
|||
controller::Pose MyAvatar::getControllerPoseInAvatarFrame(controller::Action action) const {
|
||||
auto pose = getControllerPoseInWorldFrame(action);
|
||||
if (pose.valid) {
|
||||
qCDebug(interfaceapp) << "avatar world orientation " << getWorldOrientation();
|
||||
glm::mat4 invAvatarMatrix = glm::inverse(createMatFromQuatAndPos(getWorldOrientation(), getWorldPosition()));
|
||||
return pose.transform(invAvatarMatrix);
|
||||
} else {
|
||||
|
|
|
@ -119,21 +119,7 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
|
|||
// input action is the highest priority source for head orientation.
|
||||
auto avatarHeadPose = myAvatar->getControllerPoseInAvatarFrame(controller::Action::HEAD);
|
||||
if (avatarHeadPose.isValid()) {
|
||||
AnimPose previousHeadPose;
|
||||
bool headUnfuckedWith = _rig.getAbsoluteJointPoseInRigFrame(_rig.indexOfJoint("Head"), previousHeadPose);
|
||||
if (headUnfuckedWith) {
|
||||
qCDebug(interfaceapp) << "unset head position " << previousHeadPose.trans();
|
||||
qCDebug(interfaceapp) << "unset head rotation " << previousHeadPose.rot();
|
||||
}
|
||||
qCDebug(interfaceapp) << "neck joint offset " << jointOffsetMap[62];
|
||||
qCDebug(interfaceapp) << "head joint avatar frame " << avatarHeadPose.getRotation();
|
||||
AnimPose jointOffsetNeck(jointOffsetMap[62], glm::vec3());
|
||||
AnimPose jointOffsetSpine2(jointOffsetMap[13], glm::vec3());
|
||||
AnimPose testPose(glm::quat(0.7071f, 0.0f, 0.0f, 0.7071f), glm::vec3());
|
||||
AnimPose pose(avatarHeadPose.getRotation(), avatarHeadPose.getTranslation());
|
||||
AnimPose newHeadRot = (avatarToRigPose * pose) * testPose;
|
||||
AnimPose newHeadRot2(newHeadRot.rot(), avatarHeadPose.getTranslation());
|
||||
AnimPose identityPose(glm::quat(1.0f,0.0f,0.0f,0.0f), glm::vec3(0.0f,0.57f,0.0f));
|
||||
params.primaryControllerPoses[Rig::PrimaryControllerType_Head] = avatarToRigPose * pose;
|
||||
params.primaryControllerFlags[Rig::PrimaryControllerType_Head] = (uint8_t)Rig::ControllerFlags::Enabled;
|
||||
} else {
|
||||
|
@ -244,7 +230,7 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
|
|||
params.primaryControllerFlags[Rig::PrimaryControllerType_Hips] = (uint8_t)Rig::ControllerFlags::Enabled | (uint8_t)Rig::ControllerFlags::Estimated;
|
||||
|
||||
// set spine2 if we have hand controllers
|
||||
qCDebug(interfaceapp) << "spine 2 joint offset " << jointOffsetMap[13];
|
||||
//qCDebug(interfaceapp) << "spine 2 joint offset " << jointOffsetMap[13];
|
||||
if (myAvatar->getControllerPoseInAvatarFrame(controller::Action::RIGHT_HAND).isValid() &&
|
||||
myAvatar->getControllerPoseInAvatarFrame(controller::Action::LEFT_HAND).isValid() &&
|
||||
!(params.primaryControllerFlags[Rig::PrimaryControllerType_Spine2] & (uint8_t)Rig::ControllerFlags::Enabled)) {
|
||||
|
@ -255,6 +241,7 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
|
|||
bool spine2Exists = _rig.getAbsoluteJointPoseInRigFrame(_rig.indexOfJoint("Spine2"), currentSpine2Pose);
|
||||
bool headExists = _rig.getAbsoluteJointPoseInRigFrame(_rig.indexOfJoint("Head"), currentHeadPose);
|
||||
bool hipsExists = _rig.getAbsoluteJointPoseInRigFrame(_rig.indexOfJoint("Hips"), currentHipsPose);
|
||||
|
||||
if (spine2Exists && headExists && hipsExists) {
|
||||
|
||||
AnimPose rigSpaceYaw(myAvatar->getSpine2RotationRigSpace());
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <GLMHelpers.h>
|
||||
|
||||
#include "AnimationLogging.h"
|
||||
static bool notBound = true;
|
||||
|
||||
AnimSkeleton::AnimSkeleton(const FBXGeometry& fbxGeometry, const QMap<int, glm::quat> jointOffsets) {
|
||||
|
||||
|
@ -22,48 +23,46 @@ AnimSkeleton::AnimSkeleton(const FBXGeometry& fbxGeometry, const QMap<int, glm::
|
|||
// convert to std::vector of joints
|
||||
std::vector<FBXJoint> joints;
|
||||
joints.reserve(fbxGeometry.joints.size());
|
||||
//_avatarTPoseOffsets.reserve(_jointsSize);
|
||||
for (auto& joint : fbxGeometry.joints) {
|
||||
joints.push_back(joint);
|
||||
//_avatarTPoseOffsets.push_back(AnimPose(glm::quat(), glm::vec3()));
|
||||
}
|
||||
|
||||
buildSkeletonFromJoints(joints, jointOffsets);
|
||||
// add offsets for spine2 and the neck
|
||||
// _avatarTPoseOffsets[nameToJointIndex("Spine2")] = AnimPose(glm::quat(-0.707107f, 0.0f, 0.0f, 0.707107f), glm::vec3());
|
||||
// _avatarTPoseOffsets[nameToJointIndex("Neck")] = AnimPose(glm::quat(0.0f, 0.707107f, 0.0f, 0.707107f), glm::vec3());
|
||||
|
||||
for (int i = 0; i < (int)fbxGeometry.meshes.size(); i++) {
|
||||
const FBXMesh& mesh = fbxGeometry.meshes.at(i);
|
||||
for (int j = 0; j < mesh.clusters.size(); j++) {
|
||||
|
||||
|
||||
// cast into a non-const reference, so we can mutate the FBXCluster
|
||||
FBXCluster& cluster = const_cast<FBXCluster&>(mesh.clusters.at(j));
|
||||
if (notBound) {
|
||||
notBound = false;
|
||||
for (int i = 0; i < (int)fbxGeometry.meshes.size(); i++) {
|
||||
const FBXMesh& mesh = fbxGeometry.meshes.at(i);
|
||||
for (int j = 0; j < mesh.clusters.size(); j++) {
|
||||
|
||||
// AJT: mutate bind pose! this allows us to oreint the skeleton back into the authored orientaiton before
|
||||
// rendering, with no runtime overhead.
|
||||
// this works if clusters match joints one for one.
|
||||
|
||||
if (cluster.jointIndex == 62) {
|
||||
qCDebug(animation) << "Neck";
|
||||
qCDebug(animation) << "found a joint offset to add " << cluster.jointIndex << " " << jointOffsets[cluster.jointIndex] << " cluster " << cluster.jointIndex;
|
||||
AnimPose localOffset(jointOffsets[cluster.jointIndex], glm::vec3());
|
||||
cluster.inverseBindMatrix = (glm::mat4)localOffset.inverse() * cluster.inverseBindMatrix;
|
||||
cluster.inverseBindTransform.evalFromRawMatrix(cluster.inverseBindMatrix);
|
||||
}
|
||||
if (cluster.jointIndex == 13) {
|
||||
qCDebug(animation) << "Spine2";
|
||||
qCDebug(animation) << "found a joint offset to add " << cluster.jointIndex << " " << jointOffsets[cluster.jointIndex] << " cluster " << cluster.jointIndex;
|
||||
AnimPose localOffset(jointOffsets[cluster.jointIndex], glm::vec3());
|
||||
cluster.inverseBindMatrix = (glm::mat4)localOffset.inverse() * cluster.inverseBindMatrix;
|
||||
cluster.inverseBindTransform.evalFromRawMatrix(cluster.inverseBindMatrix);
|
||||
}
|
||||
|
||||
// cast into a non-const reference, so we can mutate the FBXCluster
|
||||
FBXCluster& cluster = const_cast<FBXCluster&>(mesh.clusters.at(j));
|
||||
|
||||
// AJT: mutate bind pose! this allows us to oreint the skeleton back into the authored orientaiton before
|
||||
// rendering, with no runtime overhead.
|
||||
// this works if clusters match joints one for one.
|
||||
|
||||
if (cluster.jointIndex == 62) {
|
||||
qCDebug(animation) << "Neck";
|
||||
qCDebug(animation) << "found a joint offset to add " << cluster.jointIndex << " " << jointOffsets[cluster.jointIndex] << " cluster " << cluster.jointIndex;
|
||||
AnimPose localOffset(jointOffsets[cluster.jointIndex], glm::vec3());
|
||||
cluster.inverseBindMatrix = (glm::mat4)localOffset.inverse() * cluster.inverseBindMatrix;
|
||||
cluster.inverseBindTransform.evalFromRawMatrix(cluster.inverseBindMatrix);
|
||||
}
|
||||
if (cluster.jointIndex == 13) {
|
||||
qCDebug(animation) << "Spine2";
|
||||
qCDebug(animation) << "found a joint offset to add " << cluster.jointIndex << " " << jointOffsets[cluster.jointIndex] << " cluster " << cluster.jointIndex;
|
||||
AnimPose localOffset(jointOffsets[cluster.jointIndex], glm::vec3());
|
||||
cluster.inverseBindMatrix = (glm::mat4)localOffset.inverse() * cluster.inverseBindMatrix;
|
||||
cluster.inverseBindTransform.evalFromRawMatrix(cluster.inverseBindMatrix);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
AnimSkeleton::AnimSkeleton(const std::vector<FBXJoint>& joints, const QMap<int, glm::quat> jointOffsets) {
|
||||
|
@ -232,6 +231,12 @@ void AnimSkeleton::buildSkeletonFromJoints(const std::vector<FBXJoint>& joints,
|
|||
qCDebug(animation) << "relative default pose for joint " << i << " " << relDefaultPose.trans() << " " << relDefaultPose.rot();
|
||||
|
||||
int parentIndex = getParentIndex(i);
|
||||
AnimPose newAbsPose;
|
||||
if (parentIndex >= 0) {
|
||||
newAbsPose = _absoluteDefaultPoses[parentIndex] * AnimPose(relDefaultPose.rot(),glm::vec3());
|
||||
} else {
|
||||
newAbsPose = relDefaultPose;
|
||||
}
|
||||
|
||||
// putting the pipeline code is
|
||||
// remember the inverse bind pose already has the offset added into it. the total effect is offset^-1 * relDefPose * offset.
|
||||
|
@ -242,20 +247,21 @@ void AnimSkeleton::buildSkeletonFromJoints(const std::vector<FBXJoint>& joints,
|
|||
if (jointOffsets.contains(i)) {
|
||||
//QString parentIndex = getJointName(parentIndex);
|
||||
AnimPose localOffset(jointOffsets[i], glm::vec3());
|
||||
relDefaultPose = relDefaultPose * localOffset;
|
||||
newAbsPose = newAbsPose * localOffset;
|
||||
}
|
||||
if ((parentIndex >= 0) && jointOffsets.contains(parentIndex)) {
|
||||
AnimPose localParentOffset(jointOffsets[parentIndex], glm::vec3());
|
||||
relDefaultPose = localParentOffset.inverse() * AnimPose(glm::quat(), relDefaultPose.trans()) * localParentOffset * AnimPose(relDefaultPose.rot(), glm::vec3());
|
||||
newAbsPose = localParentOffset.inverse() * AnimPose(glm::quat(), relDefaultPose.trans()) * localParentOffset * AnimPose(newAbsPose.rot(), glm::vec3());
|
||||
}
|
||||
|
||||
_relativeDefaultPoses.push_back(relDefaultPose);
|
||||
|
||||
if (parentIndex >= 0) {
|
||||
_absoluteDefaultPoses.push_back(_absoluteDefaultPoses[parentIndex] * relDefaultPose);
|
||||
} else {
|
||||
_absoluteDefaultPoses.push_back(relDefaultPose);
|
||||
relDefaultPose = _absoluteDefaultPoses[parentIndex].inverse() * newAbsPose;
|
||||
}
|
||||
_relativeDefaultPoses.push_back(relDefaultPose);
|
||||
|
||||
|
||||
_absoluteDefaultPoses.push_back(newAbsPose);
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0; i < _jointsSize; i++) {
|
||||
|
|
|
@ -2084,6 +2084,8 @@ void Rig::setJointRotationOffsets(const QMap<QString, glm::quat>& offsets) {
|
|||
_jointRotationOffsets.insert(spine2Id, glm::quat(0.5f, 0.5f, 0.5f, -0.5f));
|
||||
}
|
||||
qCDebug(animation) << "set the neck and spine2 offsets " << spine2Id << " " << neckId;
|
||||
glm::quat testRot(glm::vec3(0.000018095f, -4.74360667058f, -89.9994155926f));
|
||||
qCDebug(animation) << "test rot from euler" << testRot;
|
||||
}
|
||||
|
||||
const QMap<int, glm::quat>& Rig::getJointRotationOffsets() const {
|
||||
|
|
Loading…
Reference in a new issue