added the hook to put the copy of the mutated bind poses into tthe skeleton

This commit is contained in:
amantley 2018-11-14 17:02:25 -08:00
parent a8d7b0503d
commit 8256c652fc
6 changed files with 47 additions and 14 deletions

View file

@ -27,21 +27,32 @@ AnimSkeleton::AnimSkeleton(const HFMModel& hfmModel) {
for (int i = 0; i < (int)hfmModel.meshes.size(); i++) {
const HFMMesh& mesh = hfmModel.meshes.at(i);
for (int j = 0; j < mesh.clusters.size(); j++) {
std::vector<HFMCluster> dummyClustersList;
for (int j = 0; j < mesh.clusters.size(); j++) {
std::vector<glm::mat4> bindMatrices;
// cast into a non-const reference, so we can mutate the FBXCluster
HFMCluster& cluster = const_cast<HFMCluster&>(mesh.clusters.at(j));
HFMCluster localCluster;
localCluster.jointIndex = cluster.jointIndex;
localCluster.inverseBindMatrix = cluster.inverseBindMatrix;
localCluster.inverseBindTransform.evalFromRawMatrix(localCluster.inverseBindMatrix);
//dummyClustersList.push_back(localCluster);
// AJT: mutate bind pose! this allows us to oreint the skeleton back into the authored orientaiton before
// rendering, with no runtime overhead.
if (hfmModel.jointRotationOffsets.contains(cluster.jointIndex)) {
AnimPose localOffset(hfmModel.jointRotationOffsets[cluster.jointIndex], glm::vec3());
if ((hfmModel.clusterBindMatrixOriginalValues.size() > i) && (hfmModel.clusterBindMatrixOriginalValues[i].size() > j)) {
cluster.inverseBindMatrix = (glm::mat4)localOffset.inverse() * hfmModel.clusterBindMatrixOriginalValues[i][j];
localCluster.inverseBindMatrix = (glm::mat4)localOffset.inverse() * hfmModel.clusterBindMatrixOriginalValues[i][j];
//cluster.inverseBindMatrix = (glm::mat4)localOffset.inverse() * hfmModel.clusterBindMatrixOriginalValues[i][j];
}
cluster.inverseBindTransform.evalFromRawMatrix(cluster.inverseBindMatrix);
//cluster.inverseBindTransform.evalFromRawMatrix(cluster.inverseBindMatrix);
localCluster.inverseBindTransform.evalFromRawMatrix(localCluster.inverseBindMatrix);
}
dummyClustersList.push_back(localCluster);
}
_clusterBindMatrixOriginalValues.push_back(dummyClustersList);
}
}

View file

@ -63,6 +63,7 @@ public:
void dump(const AnimPoseVec& poses) const;
std::vector<int> lookUpJointIndices(const std::vector<QString>& jointNames) const;
std::vector<std::vector<HFMCluster>> _clusterBindMatrixOriginalValues;
protected:
void buildSkeletonFromJoints(const std::vector<HFMJoint>& joints, const QMap<int, glm::quat> jointOffsets);
@ -77,6 +78,7 @@ protected:
std::vector<int> _nonMirroredIndices;
std::vector<int> _mirrorMap;
QHash<QString, int> _jointIndicesByName;
// std::vector<std::vector<glm::mat4>> _clusterBindMatrixOriginalValues;
// no copies
AnimSkeleton(const AnimSkeleton&) = delete;

View file

@ -2029,7 +2029,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString&
}
// create a backup copy of the bindposes,
// these are needed when we recompute the bindpose offsets on reset.
// these are needed when we recompute the bindpose offsets in the AnimSkeleton constructor on mySkeleton->reset()
for (int i = 0; i < (int)hfmModel.meshes.size(); i++) {
const HFMMesh& mesh = hfmModel.meshes.at(i);
vector<glm::mat4> meshBindMatrices;

View file

@ -112,6 +112,7 @@ void CauterizedModel::updateClusterMatrices() {
const HFMModel& hfmModel = getHFMModel();
for (int i = 0; i < (int)_meshStates.size(); i++) {
qCDebug(renderutils) << "mesh states size " << _meshStates.size() << " mesh size " << hfmModel.meshes.size();
Model::MeshState& state = _meshStates[i];
const HFMMesh& mesh = hfmModel.meshes.at(i);
for (int j = 0; j < mesh.clusters.size(); j++) {
@ -120,12 +121,20 @@ void CauterizedModel::updateClusterMatrices() {
auto jointPose = _rig.getJointPose(cluster.jointIndex);
Transform jointTransform(jointPose.rot(), jointPose.scale(), jointPose.trans());
Transform clusterTransform;
Transform::mult(clusterTransform, jointTransform, cluster.inverseBindTransform);
Transform clusterTransform2;
//Transform::mult(clusterTransform, jointTransform, cluster.inverseBindTransform);
Transform::mult(clusterTransform, jointTransform, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindTransform);
Transform::mult(clusterTransform2, jointTransform, cluster.inverseBindTransform);
//qCDebug(renderutils) << "the animskel matrix i " << i << " j " << j << _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindTransform;
qCDebug(renderutils) << "the mesh state cluster matrix " << state.clusterMatrices[j];
//qCDebug(renderutils) << "cluster transform old way " << clusterTransform2;
//qCDebug(renderutils) << "cluster transform new way " << clusterTransform;
state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(clusterTransform);
state.clusterDualQuaternions[j].setCauterizationParameters(0.0f, jointPose.trans());
} else {
auto jointMatrix = _rig.getJointTransform(cluster.jointIndex);
glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]);
//glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]);
glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindMatrix, state.clusterMatrices[j]);
}
}
}
@ -157,7 +166,8 @@ void CauterizedModel::updateClusterMatrices() {
} else {
Transform jointTransform(cauterizePose.rot(), cauterizePose.scale(), cauterizePose.trans());
Transform clusterTransform;
Transform::mult(clusterTransform, jointTransform, cluster.inverseBindTransform);
//Transform::mult(clusterTransform, jointTransform, cluster.inverseBindTransform);
Transform::mult(clusterTransform, jointTransform, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindTransform);
state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(clusterTransform);
state.clusterDualQuaternions[j].setCauterizationParameters(1.0f, cauterizePose.trans());
}
@ -166,7 +176,8 @@ void CauterizedModel::updateClusterMatrices() {
// not cauterized so just copy the value from the non-cauterized version.
state.clusterMatrices[j] = _meshStates[i].clusterMatrices[j];
} else {
glm_mat4u_mul(cauterizeMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]);
// glm_mat4u_mul(cauterizeMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]);
glm_mat4u_mul(cauterizeMatrix, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindMatrix, state.clusterMatrices[j]);
}
}
}
@ -231,6 +242,8 @@ void CauterizedModel::updateRenderItems() {
if (useDualQuaternionSkinning) {
data.updateClusterBuffer(meshState.clusterDualQuaternions,
cauterizedMeshState.clusterDualQuaternions);
//qCDebug(renderutils) << "mesh cluster transform " << meshState.clusterDualQuaternions[0];
//qCDebug(renderutils) << "cauterized mesh cluster transform " << cauterizedMeshState.clusterDualQuaternions[0];
} else {
data.updateClusterBuffer(meshState.clusterMatrices,
cauterizedMeshState.clusterMatrices);

View file

@ -237,6 +237,10 @@ void Model::updateRenderItems() {
bool invalidatePayloadShapeKey = self->shouldInvalidatePayloadShapeKey(meshIndex);
bool useDualQuaternionSkinning = self->getUseDualQuaternionSkinning();
if (useDualQuaternionSkinning) {
qCDebug(renderutils) << "use dual quats value " << useDualQuaternionSkinning;
}
transaction.updateItem<ModelMeshPartPayload>(itemID, [modelTransform, meshState, useDualQuaternionSkinning,
invalidatePayloadShapeKey, isWireframe, renderItemKeyGlobalFlags](ModelMeshPartPayload& data) {
if (useDualQuaternionSkinning) {
@ -1425,11 +1429,13 @@ void Model::updateClusterMatrices() {
auto jointPose = _rig.getJointPose(cluster.jointIndex);
Transform jointTransform(jointPose.rot(), jointPose.scale(), jointPose.trans());
Transform clusterTransform;
Transform::mult(clusterTransform, jointTransform, cluster.inverseBindTransform);
Transform::mult(clusterTransform, jointTransform, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindTransform);
//Transform::mult(clusterTransform, jointTransform, cluster.inverseBindTransform);
state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(clusterTransform);
} else {
auto jointMatrix = _rig.getJointTransform(cluster.jointIndex);
glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]);
glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindMatrix, state.clusterMatrices[j]);
// glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]);
}
}
}

View file

@ -61,7 +61,8 @@ void SoftAttachmentModel::updateClusterMatrices() {
}
glm::mat4 m;
glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, m);
//glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, m);
glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindMatrix, m);
state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(m);
} else {
glm::mat4 jointMatrix;
@ -70,8 +71,8 @@ void SoftAttachmentModel::updateClusterMatrices() {
} else {
jointMatrix = _rig.getJointTransform(cluster.jointIndex);
}
glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]);
//glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]);
glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindMatrix, state.clusterMatrices[j]);
}
}
}