From a551995235b5c63cfe8d425a96ecaf5133c619ad Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Thu, 8 Nov 2018 16:01:25 +0800 Subject: [PATCH] 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. --- src/motionsgenerator.cpp | 4 +++- src/posedocument.cpp | 9 +++++++-- src/poseeditwidget.cpp | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/motionsgenerator.cpp b/src/motionsgenerator.cpp index 04d1ca57..7d83a6cf 100644 --- a/src/motionsgenerator.cpp +++ b/src/motionsgenerator.cpp @@ -188,8 +188,10 @@ const JointNodeTree &MotionsGenerator::poseJointNodeTree(const QUuid &poseId) if (findResult != m_poseJointNodeTreeMap.end()) return findResult->second; + const auto ¶meters = 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; diff --git a/src/posedocument.cpp b/src/posedocument.cpp index 9e605ccb..2bf33740 100644 --- a/src/posedocument.cpp +++ b/src/posedocument.cpp @@ -132,11 +132,16 @@ void PoseDocument::fromParameters(const std::vector *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> &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> &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)); diff --git a/src/poseeditwidget.cpp b/src/poseeditwidget.cpp index 029389af..908703dd 100644 --- a/src/poseeditwidget.cpp +++ b/src/poseeditwidget.cpp @@ -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);