mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 09:28:46 +02:00
added getter for the orginal cluster bind matrix values in AnimSkeleton
This commit is contained in:
parent
80ebde1036
commit
c8cd65c3bd
6 changed files with 32 additions and 30 deletions
|
@ -25,6 +25,8 @@ AnimSkeleton::AnimSkeleton(const HFMModel& hfmModel) {
|
||||||
}
|
}
|
||||||
buildSkeletonFromJoints(joints, hfmModel.jointRotationOffsets);
|
buildSkeletonFromJoints(joints, hfmModel.jointRotationOffsets);
|
||||||
|
|
||||||
|
// we make a copy of the inverseBindMatrices in order to prevent mutating the model bind pose
|
||||||
|
// when we are dealing with a joint offset in the model
|
||||||
for (int i = 0; i < (int)hfmModel.meshes.size(); i++) {
|
for (int i = 0; i < (int)hfmModel.meshes.size(); i++) {
|
||||||
const HFMMesh& mesh = hfmModel.meshes.at(i);
|
const HFMMesh& mesh = hfmModel.meshes.at(i);
|
||||||
std::vector<HFMCluster> dummyClustersList;
|
std::vector<HFMCluster> dummyClustersList;
|
||||||
|
@ -39,12 +41,11 @@ AnimSkeleton::AnimSkeleton(const HFMModel& hfmModel) {
|
||||||
localCluster.inverseBindMatrix = cluster.inverseBindMatrix;
|
localCluster.inverseBindMatrix = cluster.inverseBindMatrix;
|
||||||
localCluster.inverseBindTransform.evalFromRawMatrix(localCluster.inverseBindMatrix);
|
localCluster.inverseBindTransform.evalFromRawMatrix(localCluster.inverseBindMatrix);
|
||||||
|
|
||||||
// we make a copy of the inversebindMatrices in order to prevent mutating the model bind pose
|
// if we have a joint offset in the fst file then multiply its inverse by the
|
||||||
|
// model cluster inverse bind matrix
|
||||||
if (hfmModel.jointRotationOffsets.contains(cluster.jointIndex)) {
|
if (hfmModel.jointRotationOffsets.contains(cluster.jointIndex)) {
|
||||||
AnimPose localOffset(hfmModel.jointRotationOffsets[cluster.jointIndex], glm::vec3());
|
AnimPose localOffset(hfmModel.jointRotationOffsets[cluster.jointIndex], glm::vec3());
|
||||||
if ((hfmModel.clusterBindMatrixOriginalValues.size() > i) && (hfmModel.clusterBindMatrixOriginalValues[i].size() > j)) {
|
localCluster.inverseBindMatrix = (glm::mat4)localOffset.inverse() * cluster.inverseBindMatrix;
|
||||||
localCluster.inverseBindMatrix = (glm::mat4)localOffset.inverse() * hfmModel.clusterBindMatrixOriginalValues[i][j];
|
|
||||||
}
|
|
||||||
localCluster.inverseBindTransform.evalFromRawMatrix(localCluster.inverseBindMatrix);
|
localCluster.inverseBindTransform.evalFromRawMatrix(localCluster.inverseBindMatrix);
|
||||||
}
|
}
|
||||||
dummyClustersList.push_back(localCluster);
|
dummyClustersList.push_back(localCluster);
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
void dump(const AnimPoseVec& poses) const;
|
void dump(const AnimPoseVec& poses) const;
|
||||||
|
|
||||||
std::vector<int> lookUpJointIndices(const std::vector<QString>& jointNames) const;
|
std::vector<int> lookUpJointIndices(const std::vector<QString>& jointNames) const;
|
||||||
std::vector<std::vector<HFMCluster>> _clusterBindMatrixOriginalValues;
|
const HFMCluster getClusterBindMatricesOriginalValues(const int meshIndex, const int clusterIndex) const { return _clusterBindMatrixOriginalValues[meshIndex][clusterIndex]; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void buildSkeletonFromJoints(const std::vector<HFMJoint>& joints, const QMap<int, glm::quat> jointOffsets);
|
void buildSkeletonFromJoints(const std::vector<HFMJoint>& joints, const QMap<int, glm::quat> jointOffsets);
|
||||||
|
@ -78,6 +78,7 @@ protected:
|
||||||
std::vector<int> _nonMirroredIndices;
|
std::vector<int> _nonMirroredIndices;
|
||||||
std::vector<int> _mirrorMap;
|
std::vector<int> _mirrorMap;
|
||||||
QHash<QString, int> _jointIndicesByName;
|
QHash<QString, int> _jointIndicesByName;
|
||||||
|
std::vector<std::vector<HFMCluster>> _clusterBindMatrixOriginalValues;
|
||||||
|
|
||||||
// no copies
|
// no copies
|
||||||
AnimSkeleton(const AnimSkeleton&) = delete;
|
AnimSkeleton(const AnimSkeleton&) = delete;
|
||||||
|
|
|
@ -349,7 +349,6 @@ public:
|
||||||
Extents meshExtents;
|
Extents meshExtents;
|
||||||
|
|
||||||
QVector<HFMAnimationFrame> animationFrames;
|
QVector<HFMAnimationFrame> animationFrames;
|
||||||
std::vector<std::vector<glm::mat4>> clusterBindMatrixOriginalValues;
|
|
||||||
|
|
||||||
int getJointIndex(const QString& name) const { return jointIndices.value(name) - 1; }
|
int getJointIndex(const QString& name) const { return jointIndices.value(name) - 1; }
|
||||||
QStringList getJointNames() const;
|
QStringList getJointNames() const;
|
||||||
|
|
|
@ -114,18 +114,22 @@ void CauterizedModel::updateClusterMatrices() {
|
||||||
for (int i = 0; i < (int)_meshStates.size(); i++) {
|
for (int i = 0; i < (int)_meshStates.size(); i++) {
|
||||||
Model::MeshState& state = _meshStates[i];
|
Model::MeshState& state = _meshStates[i];
|
||||||
const HFMMesh& mesh = hfmModel.meshes.at(i);
|
const HFMMesh& mesh = hfmModel.meshes.at(i);
|
||||||
|
int meshIndex = i;
|
||||||
|
|
||||||
for (int j = 0; j < mesh.clusters.size(); j++) {
|
for (int j = 0; j < mesh.clusters.size(); j++) {
|
||||||
const HFMCluster& cluster = mesh.clusters.at(j);
|
const HFMCluster& cluster = mesh.clusters.at(j);
|
||||||
|
int clusterIndex = j;
|
||||||
|
|
||||||
if (_useDualQuaternionSkinning) {
|
if (_useDualQuaternionSkinning) {
|
||||||
auto jointPose = _rig.getJointPose(cluster.jointIndex);
|
auto jointPose = _rig.getJointPose(cluster.jointIndex);
|
||||||
Transform jointTransform(jointPose.rot(), jointPose.scale(), jointPose.trans());
|
Transform jointTransform(jointPose.rot(), jointPose.scale(), jointPose.trans());
|
||||||
Transform clusterTransform;
|
Transform clusterTransform;
|
||||||
Transform::mult(clusterTransform, jointTransform, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindTransform);
|
Transform::mult(clusterTransform, jointTransform, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindTransform);
|
||||||
state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(clusterTransform);
|
state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(clusterTransform);
|
||||||
state.clusterDualQuaternions[j].setCauterizationParameters(0.0f, jointPose.trans());
|
state.clusterDualQuaternions[j].setCauterizationParameters(0.0f, jointPose.trans());
|
||||||
} else {
|
} else {
|
||||||
auto jointMatrix = _rig.getJointTransform(cluster.jointIndex);
|
auto jointMatrix = _rig.getJointTransform(cluster.jointIndex);
|
||||||
glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindMatrix, state.clusterMatrices[j]);
|
glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindMatrix, state.clusterMatrices[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,9 +150,11 @@ void CauterizedModel::updateClusterMatrices() {
|
||||||
for (int i = 0; i < _cauterizeMeshStates.size(); i++) {
|
for (int i = 0; i < _cauterizeMeshStates.size(); i++) {
|
||||||
Model::MeshState& state = _cauterizeMeshStates[i];
|
Model::MeshState& state = _cauterizeMeshStates[i];
|
||||||
const HFMMesh& mesh = hfmModel.meshes.at(i);
|
const HFMMesh& mesh = hfmModel.meshes.at(i);
|
||||||
|
int meshIndex = i;
|
||||||
|
|
||||||
for (int j = 0; j < mesh.clusters.size(); j++) {
|
for (int j = 0; j < mesh.clusters.size(); j++) {
|
||||||
const HFMCluster& cluster = mesh.clusters.at(j);
|
const HFMCluster& cluster = mesh.clusters.at(j);
|
||||||
|
int clusterIndex = j;
|
||||||
|
|
||||||
if (_useDualQuaternionSkinning) {
|
if (_useDualQuaternionSkinning) {
|
||||||
if (_cauterizeBoneSet.find(cluster.jointIndex) == _cauterizeBoneSet.end()) {
|
if (_cauterizeBoneSet.find(cluster.jointIndex) == _cauterizeBoneSet.end()) {
|
||||||
|
@ -157,7 +163,7 @@ void CauterizedModel::updateClusterMatrices() {
|
||||||
} else {
|
} else {
|
||||||
Transform jointTransform(cauterizePose.rot(), cauterizePose.scale(), cauterizePose.trans());
|
Transform jointTransform(cauterizePose.rot(), cauterizePose.scale(), cauterizePose.trans());
|
||||||
Transform clusterTransform;
|
Transform clusterTransform;
|
||||||
Transform::mult(clusterTransform, jointTransform, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindTransform);
|
Transform::mult(clusterTransform, jointTransform, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindTransform);
|
||||||
state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(clusterTransform);
|
state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(clusterTransform);
|
||||||
state.clusterDualQuaternions[j].setCauterizationParameters(1.0f, cauterizePose.trans());
|
state.clusterDualQuaternions[j].setCauterizationParameters(1.0f, cauterizePose.trans());
|
||||||
}
|
}
|
||||||
|
@ -166,7 +172,7 @@ void CauterizedModel::updateClusterMatrices() {
|
||||||
// not cauterized so just copy the value from the non-cauterized version.
|
// not cauterized so just copy the value from the non-cauterized version.
|
||||||
state.clusterMatrices[j] = _meshStates[i].clusterMatrices[j];
|
state.clusterMatrices[j] = _meshStates[i].clusterMatrices[j];
|
||||||
} else {
|
} else {
|
||||||
glm_mat4u_mul(cauterizeMatrix, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindMatrix, state.clusterMatrices[j]);
|
glm_mat4u_mul(cauterizeMatrix, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindMatrix, state.clusterMatrices[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1418,20 +1418,21 @@ void Model::updateClusterMatrices() {
|
||||||
const HFMModel& hfmModel = getHFMModel();
|
const HFMModel& hfmModel = getHFMModel();
|
||||||
for (int i = 0; i < (int) _meshStates.size(); i++) {
|
for (int i = 0; i < (int) _meshStates.size(); i++) {
|
||||||
MeshState& state = _meshStates[i];
|
MeshState& state = _meshStates[i];
|
||||||
|
int meshIndex = i;
|
||||||
const HFMMesh& mesh = hfmModel.meshes.at(i);
|
const HFMMesh& mesh = hfmModel.meshes.at(i);
|
||||||
for (int j = 0; j < mesh.clusters.size(); j++) {
|
for (int j = 0; j < mesh.clusters.size(); j++) {
|
||||||
const HFMCluster& cluster = mesh.clusters.at(j);
|
const HFMCluster& cluster = mesh.clusters.at(j);
|
||||||
|
int clusterIndex = j;
|
||||||
|
|
||||||
if (_useDualQuaternionSkinning) {
|
if (_useDualQuaternionSkinning) {
|
||||||
auto jointPose = _rig.getJointPose(cluster.jointIndex);
|
auto jointPose = _rig.getJointPose(cluster.jointIndex);
|
||||||
Transform jointTransform(jointPose.rot(), jointPose.scale(), jointPose.trans());
|
Transform jointTransform(jointPose.rot(), jointPose.scale(), jointPose.trans());
|
||||||
Transform clusterTransform;
|
Transform clusterTransform;
|
||||||
Transform::mult(clusterTransform, jointTransform, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindTransform);
|
Transform::mult(clusterTransform, jointTransform, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindTransform);
|
||||||
//Transform::mult(clusterTransform, jointTransform, cluster.inverseBindTransform);
|
|
||||||
state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(clusterTransform);
|
state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(clusterTransform);
|
||||||
} else {
|
} else {
|
||||||
auto jointMatrix = _rig.getJointTransform(cluster.jointIndex);
|
auto jointMatrix = _rig.getJointTransform(cluster.jointIndex);
|
||||||
glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindMatrix, state.clusterMatrices[j]);
|
glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindMatrix, state.clusterMatrices[j]);
|
||||||
// glm_mat4u_mul(jointMatrix, cluster.inverseBindMatrix, state.clusterMatrices[j]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,31 +46,25 @@ void SoftAttachmentModel::updateClusterMatrices() {
|
||||||
for (int i = 0; i < (int) _meshStates.size(); i++) {
|
for (int i = 0; i < (int) _meshStates.size(); i++) {
|
||||||
MeshState& state = _meshStates[i];
|
MeshState& state = _meshStates[i];
|
||||||
const HFMMesh& mesh = hfmModel.meshes.at(i);
|
const HFMMesh& mesh = hfmModel.meshes.at(i);
|
||||||
|
int meshIndex = i;
|
||||||
for (int j = 0; j < mesh.clusters.size(); j++) {
|
for (int j = 0; j < mesh.clusters.size(); j++) {
|
||||||
const HFMCluster& cluster = mesh.clusters.at(j);
|
const HFMCluster& cluster = mesh.clusters.at(j);
|
||||||
|
|
||||||
|
int clusterIndex = j;
|
||||||
// TODO: cache these look-ups as an optimization
|
// TODO: cache these look-ups as an optimization
|
||||||
int jointIndexOverride = getJointIndexOverride(cluster.jointIndex);
|
int jointIndexOverride = getJointIndexOverride(cluster.jointIndex);
|
||||||
|
glm::mat4 jointMatrix;
|
||||||
|
if (jointIndexOverride >= 0 && jointIndexOverride < _rigOverride.getJointStateCount()) {
|
||||||
|
jointMatrix = _rigOverride.getJointTransform(jointIndexOverride);
|
||||||
|
} else {
|
||||||
|
jointMatrix = _rig.getJointTransform(cluster.jointIndex);
|
||||||
|
}
|
||||||
if (_useDualQuaternionSkinning) {
|
if (_useDualQuaternionSkinning) {
|
||||||
glm::mat4 jointMatrix;
|
|
||||||
if (jointIndexOverride >= 0 && jointIndexOverride < _rigOverride.getJointStateCount()) {
|
|
||||||
jointMatrix = _rigOverride.getJointTransform(jointIndexOverride);
|
|
||||||
} else {
|
|
||||||
jointMatrix = _rig.getJointTransform(cluster.jointIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::mat4 m;
|
glm::mat4 m;
|
||||||
glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindMatrix, m);
|
glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindMatrix, m);
|
||||||
state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(m);
|
state.clusterDualQuaternions[j] = Model::TransformDualQuaternion(m);
|
||||||
} else {
|
} else {
|
||||||
glm::mat4 jointMatrix;
|
glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->getClusterBindMatricesOriginalValues(meshIndex, clusterIndex).inverseBindMatrix, state.clusterMatrices[j]);
|
||||||
if (jointIndexOverride >= 0 && jointIndexOverride < _rigOverride.getJointStateCount()) {
|
|
||||||
jointMatrix = _rigOverride.getJointTransform(jointIndexOverride);
|
|
||||||
} else {
|
|
||||||
jointMatrix = _rig.getJointTransform(cluster.jointIndex);
|
|
||||||
}
|
|
||||||
glm_mat4u_mul(jointMatrix, _rig.getAnimSkeleton()->_clusterBindMatrixOriginalValues[i][j].inverseBindMatrix, state.clusterMatrices[j]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue