From 01b164cdaec5518fb48ec8d1a383047dae44015c Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Wed, 7 Nov 2018 22:48:24 +0800 Subject: [PATCH] Fit control bones in pose canvas Add scale factor to make all the bones fit in the canvas of pose editor --- src/animalposer.cpp | 2 ++ src/animalrigger.cpp | 7 +------ src/posedocument.cpp | 25 +++++++++++++------------ src/posedocument.h | 1 + 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/animalposer.cpp b/src/animalposer.cpp index 94e78c76..53fbfbb4 100644 --- a/src/animalposer.cpp +++ b/src/animalposer.cpp @@ -166,6 +166,8 @@ void AnimalPoser::resolveChainRotation(const std::vector &limbBoneNames const float &c = targetBeginBoneLength; double cosC = (a*a + b*b - c*c) / (2.0*a*b); angleBetweenDistanceAndMiddleBones = qRadiansToDegrees(acos(cosC)); + if (std::isnan(angleBetweenDistanceAndMiddleBones) || std::isinf(angleBetweenDistanceAndMiddleBones)) + angleBetweenDistanceAndMiddleBones = 0; } QVector3D targetMiddleBoneStartPosition; diff --git a/src/animalrigger.cpp b/src/animalrigger.cpp index ab219496..993739a2 100644 --- a/src/animalrigger.cpp +++ b/src/animalrigger.cpp @@ -406,12 +406,7 @@ bool AnimalRigger::rig() tailPosition = findExtremPointFrom(spineBoneVertices, spineNode.position); } - QVector3D spineBoneHeadPosition = averagePosition(spineBoneVertices); - if (isMainBodyVerticalAligned) { - spineBoneHeadPosition.setY(spineNode.coord); - } else { - spineBoneHeadPosition.setZ(spineNode.coord); - } + QVector3D spineBoneHeadPosition = spineNode.position; QString spineName = namingSpine(spineGenerateOrder); diff --git a/src/posedocument.cpp b/src/posedocument.cpp index 4302e410..ea963627 100644 --- a/src/posedocument.cpp +++ b/src/posedocument.cpp @@ -6,6 +6,7 @@ const float PoseDocument::m_nodeRadius = 0.01; const float PoseDocument::m_groundPlaneHalfThickness = 0.01 / 4; const bool PoseDocument::m_hideRootAndVirtual = true; +const float PoseDocument::m_outcomeScaleFactor = 0.5; bool PoseDocument::hasPastableNodesInClipboard() const { @@ -198,9 +199,9 @@ void PoseDocument::updateRigBones(const std::vector *rigBones, const node.partId = m_bonesPartId; node.id = QUuid::createUuid(); node.setRadius(m_nodeRadius); - node.x = bone.headPosition.x() + 0.5; - node.y = -bone.headPosition.y() + 0.5; - node.z = -bone.headPosition.z() + 1; + node.x = fromOutcomeX(bone.headPosition.x()); + node.y = fromOutcomeY(bone.headPosition.y()); + node.z = fromOutcomeZ(bone.headPosition.z()); nodeMap[node.id] = node; newAddedNodeIds.insert(node.id); boneIndexToHeadNodeIdMap[edgePair.first] = node.id; @@ -217,9 +218,9 @@ void PoseDocument::updateRigBones(const std::vector *rigBones, const node.partId = m_bonesPartId; node.id = QUuid::createUuid(); node.setRadius(m_nodeRadius); - node.x = bone.headPosition.x() + 0.5; - node.y = -bone.headPosition.y() + 0.5; - node.z = -bone.headPosition.z() + 1; + node.x = fromOutcomeX(bone.headPosition.x()); + node.y = fromOutcomeY(bone.headPosition.y()); + node.z = fromOutcomeZ(bone.headPosition.z()); nodeMap[node.id] = node; newAddedNodeIds.insert(node.id); boneIndexToHeadNodeIdMap[edgePair.second] = node.id; @@ -423,31 +424,31 @@ void PoseDocument::toParameters(std::map> &p float PoseDocument::fromOutcomeX(float x) { - return x + 0.5; + return x * m_outcomeScaleFactor + 0.5; } float PoseDocument::toOutcomeX(float x) { - return x - 0.5; + return (x - 0.5) / m_outcomeScaleFactor; } float PoseDocument::fromOutcomeY(float y) { - return -y + 0.5; + return -y * m_outcomeScaleFactor + 0.5; } float PoseDocument::toOutcomeY(float y) { - return 0.5 - y; + return (0.5 - y) / m_outcomeScaleFactor; } float PoseDocument::fromOutcomeZ(float z) { - return -z + 1; + return -z * m_outcomeScaleFactor + 1; } float PoseDocument::toOutcomeZ(float z) { - return 1.0 - z; + return (1.0 - z) / m_outcomeScaleFactor; } diff --git a/src/posedocument.h b/src/posedocument.h index af9b7bb4..08f3dce7 100644 --- a/src/posedocument.h +++ b/src/posedocument.h @@ -53,6 +53,7 @@ public: static const float m_nodeRadius; static const float m_groundPlaneHalfThickness; static const bool m_hideRootAndVirtual; + static const float m_outcomeScaleFactor; private: std::map> m_boneNameToIdsMap;