mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 21:03:27 +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 {
|
controller::Pose MyAvatar::getControllerPoseInWorldFrame(controller::Action action) const {
|
||||||
auto pose = getControllerPoseInSensorFrame(action);
|
auto pose = getControllerPoseInSensorFrame(action);
|
||||||
qCDebug(interfaceapp) << "avatar sensor orientation " << pose.getRotation();
|
|
||||||
if (pose.valid) {
|
if (pose.valid) {
|
||||||
qCDebug(interfaceapp) << "sensor to world matrix orientation " << extractRotation(getSensorToWorldMatrix());
|
|
||||||
return pose.transform(getSensorToWorldMatrix());
|
return pose.transform(getSensorToWorldMatrix());
|
||||||
} else {
|
} else {
|
||||||
return controller::Pose(); // invalid pose
|
return controller::Pose(); // invalid pose
|
||||||
|
@ -2049,7 +2047,6 @@ controller::Pose MyAvatar::getControllerPoseInWorldFrame(controller::Action acti
|
||||||
controller::Pose MyAvatar::getControllerPoseInAvatarFrame(controller::Action action) const {
|
controller::Pose MyAvatar::getControllerPoseInAvatarFrame(controller::Action action) const {
|
||||||
auto pose = getControllerPoseInWorldFrame(action);
|
auto pose = getControllerPoseInWorldFrame(action);
|
||||||
if (pose.valid) {
|
if (pose.valid) {
|
||||||
qCDebug(interfaceapp) << "avatar world orientation " << getWorldOrientation();
|
|
||||||
glm::mat4 invAvatarMatrix = glm::inverse(createMatFromQuatAndPos(getWorldOrientation(), getWorldPosition()));
|
glm::mat4 invAvatarMatrix = glm::inverse(createMatFromQuatAndPos(getWorldOrientation(), getWorldPosition()));
|
||||||
return pose.transform(invAvatarMatrix);
|
return pose.transform(invAvatarMatrix);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -119,21 +119,7 @@ void MySkeletonModel::updateRig(float deltaTime, glm::mat4 parentTransform) {
|
||||||
// input action is the highest priority source for head orientation.
|
// input action is the highest priority source for head orientation.
|
||||||
auto avatarHeadPose = myAvatar->getControllerPoseInAvatarFrame(controller::Action::HEAD);
|
auto avatarHeadPose = myAvatar->getControllerPoseInAvatarFrame(controller::Action::HEAD);
|
||||||
if (avatarHeadPose.isValid()) {
|
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 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.primaryControllerPoses[Rig::PrimaryControllerType_Head] = avatarToRigPose * pose;
|
||||||
params.primaryControllerFlags[Rig::PrimaryControllerType_Head] = (uint8_t)Rig::ControllerFlags::Enabled;
|
params.primaryControllerFlags[Rig::PrimaryControllerType_Head] = (uint8_t)Rig::ControllerFlags::Enabled;
|
||||||
} else {
|
} 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;
|
params.primaryControllerFlags[Rig::PrimaryControllerType_Hips] = (uint8_t)Rig::ControllerFlags::Enabled | (uint8_t)Rig::ControllerFlags::Estimated;
|
||||||
|
|
||||||
// set spine2 if we have hand controllers
|
// 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() &&
|
if (myAvatar->getControllerPoseInAvatarFrame(controller::Action::RIGHT_HAND).isValid() &&
|
||||||
myAvatar->getControllerPoseInAvatarFrame(controller::Action::LEFT_HAND).isValid() &&
|
myAvatar->getControllerPoseInAvatarFrame(controller::Action::LEFT_HAND).isValid() &&
|
||||||
!(params.primaryControllerFlags[Rig::PrimaryControllerType_Spine2] & (uint8_t)Rig::ControllerFlags::Enabled)) {
|
!(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 spine2Exists = _rig.getAbsoluteJointPoseInRigFrame(_rig.indexOfJoint("Spine2"), currentSpine2Pose);
|
||||||
bool headExists = _rig.getAbsoluteJointPoseInRigFrame(_rig.indexOfJoint("Head"), currentHeadPose);
|
bool headExists = _rig.getAbsoluteJointPoseInRigFrame(_rig.indexOfJoint("Head"), currentHeadPose);
|
||||||
bool hipsExists = _rig.getAbsoluteJointPoseInRigFrame(_rig.indexOfJoint("Hips"), currentHipsPose);
|
bool hipsExists = _rig.getAbsoluteJointPoseInRigFrame(_rig.indexOfJoint("Hips"), currentHipsPose);
|
||||||
|
|
||||||
if (spine2Exists && headExists && hipsExists) {
|
if (spine2Exists && headExists && hipsExists) {
|
||||||
|
|
||||||
AnimPose rigSpaceYaw(myAvatar->getSpine2RotationRigSpace());
|
AnimPose rigSpaceYaw(myAvatar->getSpine2RotationRigSpace());
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include <GLMHelpers.h>
|
#include <GLMHelpers.h>
|
||||||
|
|
||||||
#include "AnimationLogging.h"
|
#include "AnimationLogging.h"
|
||||||
|
static bool notBound = true;
|
||||||
|
|
||||||
AnimSkeleton::AnimSkeleton(const FBXGeometry& fbxGeometry, const QMap<int, glm::quat> jointOffsets) {
|
AnimSkeleton::AnimSkeleton(const FBXGeometry& fbxGeometry, const QMap<int, glm::quat> jointOffsets) {
|
||||||
|
|
||||||
|
@ -22,47 +23,45 @@ AnimSkeleton::AnimSkeleton(const FBXGeometry& fbxGeometry, const QMap<int, glm::
|
||||||
// convert to std::vector of joints
|
// convert to std::vector of joints
|
||||||
std::vector<FBXJoint> joints;
|
std::vector<FBXJoint> joints;
|
||||||
joints.reserve(fbxGeometry.joints.size());
|
joints.reserve(fbxGeometry.joints.size());
|
||||||
//_avatarTPoseOffsets.reserve(_jointsSize);
|
|
||||||
for (auto& joint : fbxGeometry.joints) {
|
for (auto& joint : fbxGeometry.joints) {
|
||||||
joints.push_back(joint);
|
joints.push_back(joint);
|
||||||
//_avatarTPoseOffsets.push_back(AnimPose(glm::quat(), glm::vec3()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buildSkeletonFromJoints(joints, jointOffsets);
|
buildSkeletonFromJoints(joints, jointOffsets);
|
||||||
// add offsets for spine2 and the neck
|
// add offsets for spine2 and the neck
|
||||||
// _avatarTPoseOffsets[nameToJointIndex("Spine2")] = AnimPose(glm::quat(-0.707107f, 0.0f, 0.0f, 0.707107f), glm::vec3());
|
if (notBound) {
|
||||||
// _avatarTPoseOffsets[nameToJointIndex("Neck")] = AnimPose(glm::quat(0.0f, 0.707107f, 0.0f, 0.707107f), glm::vec3());
|
notBound = false;
|
||||||
|
for (int i = 0; i < (int)fbxGeometry.meshes.size(); i++) {
|
||||||
for (int i = 0; i < (int)fbxGeometry.meshes.size(); i++) {
|
const FBXMesh& mesh = fbxGeometry.meshes.at(i);
|
||||||
const FBXMesh& mesh = fbxGeometry.meshes.at(i);
|
for (int j = 0; j < mesh.clusters.size(); j++) {
|
||||||
for (int j = 0; j < mesh.clusters.size(); j++) {
|
|
||||||
|
|
||||||
|
|
||||||
// cast into a non-const reference, so we can mutate the FBXCluster
|
// cast into a non-const reference, so we can mutate the FBXCluster
|
||||||
FBXCluster& cluster = const_cast<FBXCluster&>(mesh.clusters.at(j));
|
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
|
// AJT: mutate bind pose! this allows us to oreint the skeleton back into the authored orientaiton before
|
||||||
// rendering, with no runtime overhead.
|
// rendering, with no runtime overhead.
|
||||||
// this works if clusters match joints one for one.
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,6 +231,12 @@ void AnimSkeleton::buildSkeletonFromJoints(const std::vector<FBXJoint>& joints,
|
||||||
qCDebug(animation) << "relative default pose for joint " << i << " " << relDefaultPose.trans() << " " << relDefaultPose.rot();
|
qCDebug(animation) << "relative default pose for joint " << i << " " << relDefaultPose.trans() << " " << relDefaultPose.rot();
|
||||||
|
|
||||||
int parentIndex = getParentIndex(i);
|
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
|
// 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.
|
// 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)) {
|
if (jointOffsets.contains(i)) {
|
||||||
//QString parentIndex = getJointName(parentIndex);
|
//QString parentIndex = getJointName(parentIndex);
|
||||||
AnimPose localOffset(jointOffsets[i], glm::vec3());
|
AnimPose localOffset(jointOffsets[i], glm::vec3());
|
||||||
relDefaultPose = relDefaultPose * localOffset;
|
newAbsPose = newAbsPose * localOffset;
|
||||||
}
|
}
|
||||||
if ((parentIndex >= 0) && jointOffsets.contains(parentIndex)) {
|
if ((parentIndex >= 0) && jointOffsets.contains(parentIndex)) {
|
||||||
AnimPose localParentOffset(jointOffsets[parentIndex], glm::vec3());
|
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) {
|
if (parentIndex >= 0) {
|
||||||
_absoluteDefaultPoses.push_back(_absoluteDefaultPoses[parentIndex] * relDefaultPose);
|
relDefaultPose = _absoluteDefaultPoses[parentIndex].inverse() * newAbsPose;
|
||||||
} else {
|
|
||||||
_absoluteDefaultPoses.push_back(relDefaultPose);
|
|
||||||
}
|
}
|
||||||
|
_relativeDefaultPoses.push_back(relDefaultPose);
|
||||||
|
|
||||||
|
|
||||||
|
_absoluteDefaultPoses.push_back(newAbsPose);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < _jointsSize; i++) {
|
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));
|
_jointRotationOffsets.insert(spine2Id, glm::quat(0.5f, 0.5f, 0.5f, -0.5f));
|
||||||
}
|
}
|
||||||
qCDebug(animation) << "set the neck and spine2 offsets " << spine2Id << " " << neckId;
|
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 {
|
const QMap<int, glm::quat>& Rig::getJointRotationOffsets() const {
|
||||||
|
|
Loading…
Reference in a new issue