mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 12:37:51 +02:00
Make sure joint names are unique
This commit is contained in:
parent
2ef1c6458a
commit
260ee59585
1 changed files with 23 additions and 8 deletions
|
@ -64,6 +64,9 @@ void PrepareJointsTask::run(const baker::BakeContextPointer& context, const Inpu
|
||||||
const auto& jointsIn = input.get0();
|
const auto& jointsIn = input.get0();
|
||||||
auto& jointsOut = output.edit0();
|
auto& jointsOut = output.edit0();
|
||||||
|
|
||||||
|
const QString APPEND_DUPLICATE_JOINT = "_joint";
|
||||||
|
const QString APPEND_DUPLICATE_MESH = "_mesh";
|
||||||
|
|
||||||
if (_passthrough) {
|
if (_passthrough) {
|
||||||
jointsOut = jointsIn;
|
jointsOut = jointsIn;
|
||||||
} else {
|
} else {
|
||||||
|
@ -87,17 +90,29 @@ void PrepareJointsTask::run(const baker::BakeContextPointer& context, const Inpu
|
||||||
|
|
||||||
// Make sure that joint name is unique
|
// Make sure that joint name is unique
|
||||||
if (jointIndices.contains(jointOut.name)) {
|
if (jointIndices.contains(jointOut.name)) {
|
||||||
// The joint name is duplicated. Most likely a mesh joint.
|
int duplicatedJointIndex = jointIndices.find(jointOut.name).value();
|
||||||
auto duplicatedJointData = jointIndices.find(jointOut.name);
|
|
||||||
int duplicatedJointIndex = duplicatedJointData.value();
|
|
||||||
auto& duplicatedJoint = jointsOut[duplicatedJointIndex];
|
auto& duplicatedJoint = jointsOut[duplicatedJointIndex];
|
||||||
|
bool areBothJoints = jointOut.isSkeletonJoint && duplicatedJoint.isSkeletonJoint;
|
||||||
QString existJointName = jointOut.name;
|
QString existJointName = jointOut.name;
|
||||||
qCDebug(model_baker) << "Joint already exist. Renaming joint: " << existJointName;
|
QString appendName;
|
||||||
// One of the joints could be a mesh joint. Locate it and change its name.
|
if (areBothJoints) {
|
||||||
if (!jointOut.isSkeletonJoint) {
|
appendName = APPEND_DUPLICATE_JOINT;
|
||||||
jointOut.name = existJointName + "_mesh";
|
qCWarning(model_baker) << "Duplicated skeleton joints found: " << existJointName;
|
||||||
} else {
|
} else {
|
||||||
duplicatedJoint.name = existJointName + "_mesh";
|
appendName = APPEND_DUPLICATE_MESH;
|
||||||
|
qCDebug(model_baker) << "Duplicated joints found. Renaming the mesh joint: " << existJointName;
|
||||||
|
}
|
||||||
|
QString newName = existJointName + appendName;
|
||||||
|
// Make sure the new name is unique
|
||||||
|
int duplicateIndex = 0;
|
||||||
|
while (jointIndices.contains(newName)) {
|
||||||
|
newName = existJointName + appendName + QString::number(++duplicateIndex);
|
||||||
|
}
|
||||||
|
// Find and rename the mesh joint
|
||||||
|
if (!jointOut.isSkeletonJoint) {
|
||||||
|
jointOut.name = newName;
|
||||||
|
} else {
|
||||||
|
duplicatedJoint.name = newName;
|
||||||
jointIndices.remove(jointOut.name);
|
jointIndices.remove(jointOut.name);
|
||||||
jointIndices.insert(duplicatedJoint.name, duplicatedJointIndex);
|
jointIndices.insert(duplicatedJoint.name, duplicatedJointIndex);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue