Fix inconsistent result between pose editor preview and motion generation

Each bone's head and tail positions are been kept in the pose parameters, that means there are repeated info and we can resolve the bone's head position from parent's tail position if there isn't any positions info been kept for one bone.
master
Jeremy Hu 2018-11-08 16:01:25 +08:00
parent f0379740ca
commit a551995235
3 changed files with 13 additions and 3 deletions

View File

@ -188,8 +188,10 @@ const JointNodeTree &MotionsGenerator::poseJointNodeTree(const QUuid &poseId)
if (findResult != m_poseJointNodeTreeMap.end())
return findResult->second;
const auto &parameters = m_poses[poseId];
m_poser->reset();
m_poser->parameters() = m_poses[poseId];
m_poser->parameters() = parameters;
m_poser->commit();
auto insertResult = m_poseJointNodeTreeMap.insert({poseId, m_poser->resultJointNodeTree()});
return insertResult.first->second;

View File

@ -132,11 +132,16 @@ void PoseDocument::fromParameters(const std::vector<RiggerBone> *rigBones,
if (findXResult != map.end() ||
findYResult != map.end() ||
findZResult != map.end()) {
bone.tailPosition = {
QVector3D toPosition = {
valueOfKeyInMapOrEmpty(map, "toX").toFloat(),
valueOfKeyInMapOrEmpty(map, "toY").toFloat(),
valueOfKeyInMapOrEmpty(map, "toZ").toFloat()
};
bone.tailPosition = toPosition;
for (const auto &child: bone.children) {
auto &childBone = bones[child];
childBone.headPosition = toPosition;
}
}
}
}
@ -405,7 +410,6 @@ void PoseDocument::toParameters(std::map<QString, std::map<QString, QString>> &p
boneParameter["translateY"] = QString::number(translateY);
}
for (const auto &item: m_boneNameToIdsMap) {
auto &boneParameter = parameters[item.first];
const auto &boneNodeIdPair = item.second;
auto findFirstNode = nodeMap.find(boneNodeIdPair.first);
if (findFirstNode == nodeMap.end())
@ -413,6 +417,7 @@ void PoseDocument::toParameters(std::map<QString, std::map<QString, QString>> &p
auto findSecondNode = nodeMap.find(boneNodeIdPair.second);
if (findSecondNode == nodeMap.end())
continue;
auto &boneParameter = parameters[item.first];
boneParameter["fromX"] = QString::number(toOutcomeX(findFirstNode->second.x));
boneParameter["fromY"] = QString::number(toOutcomeY(findFirstNode->second.y));
boneParameter["fromZ"] = QString::number(toOutcomeZ(findFirstNode->second.z));

View File

@ -222,6 +222,9 @@ void PoseEditWidget::updatePreview()
if (nullptr == poser)
return;
m_parameters.clear();
m_poseDocument->toParameters(m_parameters);
poser->parameters() = m_parameters;
poser->commit();
m_posePreviewManager->postUpdate(*poser, m_document->currentRiggedOutcome(), *rigWeights);