mirror of https://github.com/AxioDL/metaforce.git
Initial working RigInverter
This commit is contained in:
parent
84541e1ed7
commit
0ff9794f94
|
@ -87,16 +87,18 @@ RigInverter<CINFType>::RigInverter(const CINFType& cinf,
|
|||
for (const typename CINFType::Bone& b : cinf.bones)
|
||||
{
|
||||
m_bones.emplace_back(cinf, b);
|
||||
|
||||
const std::string* name = cinf.getBoneNameFromId(b.id);
|
||||
if (name)
|
||||
{
|
||||
auto search = matrices.find(*name);
|
||||
if (search != matrices.cend())
|
||||
{
|
||||
m_bones.back().m_inverter = zeus::CMatrix3f(search->second[0],
|
||||
search->second[1],
|
||||
search->second[2]);
|
||||
m_bones.back().m_restorer = m_bones.back().m_inverter.transposed();
|
||||
zeus::CMatrix3f boneMtx(search->second[0],
|
||||
search->second[1],
|
||||
search->second[2]);
|
||||
m_bones.back().m_inverter = boneMtx.transposed();
|
||||
m_bones.back().m_restorer = boneMtx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,17 +106,17 @@ RigInverter<CINFType>::RigInverter(const CINFType& cinf,
|
|||
|
||||
template <class CINFType>
|
||||
zeus::CQuaternion
|
||||
RigInverter<CINFType>::transformRotation(atUint32 boneId, const zeus::CQuaternion& origRot) const
|
||||
RigInverter<CINFType>::invertRotation(atUint32 boneId, const zeus::CQuaternion& origRot) const
|
||||
{
|
||||
for (const Bone& b : m_bones)
|
||||
if (b.m_origBone.id == boneId)
|
||||
return b.m_inverter * zeus::CMatrix3f(origRot) * b.m_restorer;
|
||||
return b.m_restorer * zeus::CMatrix3f(origRot) * b.m_inverter;
|
||||
return origRot;
|
||||
}
|
||||
|
||||
template <class CINFType>
|
||||
zeus::CVector3f
|
||||
RigInverter<CINFType>::transformPosition(atUint32 boneId, const zeus::CVector3f& origPos, bool subDelta) const
|
||||
RigInverter<CINFType>::invertPosition(atUint32 boneId, const zeus::CVector3f& origPos, bool subDelta) const
|
||||
{
|
||||
for (const Bone& b : m_bones)
|
||||
if (b.m_origBone.id == boneId)
|
||||
|
@ -122,7 +124,32 @@ RigInverter<CINFType>::transformPosition(atUint32 boneId, const zeus::CVector3f&
|
|||
zeus::CVector3f localPos = origPos;
|
||||
if (subDelta)
|
||||
localPos -= b.m_parentDelta;
|
||||
return zeus::CQuaternion::rotate(b.m_inverter, localPos);
|
||||
return b.m_inverter * localPos;
|
||||
}
|
||||
return origPos;
|
||||
}
|
||||
|
||||
template <class CINFType>
|
||||
zeus::CQuaternion
|
||||
RigInverter<CINFType>::restoreRotation(atUint32 boneId, const zeus::CQuaternion& origRot) const
|
||||
{
|
||||
for (const Bone& b : m_bones)
|
||||
if (b.m_origBone.id == boneId)
|
||||
return b.m_inverter * zeus::CMatrix3f(origRot) * b.m_restorer;
|
||||
return origRot;
|
||||
}
|
||||
|
||||
template <class CINFType>
|
||||
zeus::CVector3f
|
||||
RigInverter<CINFType>::restorePosition(atUint32 boneId, const zeus::CVector3f& origPos, bool subDelta) const
|
||||
{
|
||||
for (const Bone& b : m_bones)
|
||||
if (b.m_origBone.id == boneId)
|
||||
{
|
||||
zeus::CVector3f localPos = b.m_restorer * origPos;
|
||||
if (subDelta)
|
||||
localPos += b.m_parentDelta;
|
||||
return localPos;
|
||||
}
|
||||
return origPos;
|
||||
}
|
||||
|
|
|
@ -36,8 +36,12 @@ public:
|
|||
hecl::BlenderConnection::DataStream::Matrix3f>& matrices);
|
||||
const CINFType& getCINF() const {return m_cinf;}
|
||||
const std::vector<Bone>& getBones() const {return m_bones;}
|
||||
zeus::CQuaternion transformRotation(atUint32 boneId, const zeus::CQuaternion& origRot) const;
|
||||
zeus::CVector3f transformPosition(atUint32 boneId, const zeus::CVector3f& origPos, bool subDelta) const;
|
||||
|
||||
zeus::CQuaternion invertRotation(atUint32 boneId, const zeus::CQuaternion& origRot) const;
|
||||
zeus::CVector3f invertPosition(atUint32 boneId, const zeus::CVector3f& origPos, bool subDelta) const;
|
||||
|
||||
zeus::CQuaternion restoreRotation(atUint32 boneId, const zeus::CQuaternion& origRot) const;
|
||||
zeus::CVector3f restorePosition(atUint32 boneId, const zeus::CVector3f& origPos, bool subDelta) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -34,10 +34,7 @@ void ANIM::IANIM::sendANIMToBlender(hecl::BlenderConnection::PyOutStream& os, co
|
|||
"\n";
|
||||
|
||||
if (bone.second)
|
||||
os << "#bone_trans_head = (0.0,0.0,0.0)\n"
|
||||
"#if arm_obj.data.bones[bone_string].parent is not None:\n"
|
||||
"# bone_trans_head = Vector(arm_obj.data.bones[bone_string].head_local) - Vector(arm_obj.data.bones[bone_string].parent.head_local)\n"
|
||||
"transCurves = []\n"
|
||||
os << "transCurves = []\n"
|
||||
"transCurves.append(act.fcurves.new('pose.bones[\"'+bone_string+'\"].location', index=0, action_group=bone_string))\n"
|
||||
"transCurves.append(act.fcurves.new('pose.bones[\"'+bone_string+'\"].location', index=1, action_group=bone_string))\n"
|
||||
"transCurves.append(act.fcurves.new('pose.bones[\"'+bone_string+'\"].location', index=2, action_group=bone_string))\n"
|
||||
|
@ -66,7 +63,7 @@ void ANIM::IANIM::sendANIMToBlender(hecl::BlenderConnection::PyOutStream& os, co
|
|||
}
|
||||
|
||||
for (zeus::CQuaternion& rot : fixedRotKeys)
|
||||
rot = rig.transformRotation(bone.first, rot);
|
||||
rot = rig.invertRotation(bone.first, rot);
|
||||
|
||||
for (int c=0 ; c<4 ; ++c)
|
||||
{
|
||||
|
@ -91,7 +88,7 @@ void ANIM::IANIM::sendANIMToBlender(hecl::BlenderConnection::PyOutStream& os, co
|
|||
}
|
||||
|
||||
for (zeus::CVector3f& t : fixedTransKeys)
|
||||
t = rig.transformPosition(bone.first, t, true);
|
||||
t = rig.invertPosition(bone.first, t, true);
|
||||
|
||||
for (int c=0 ; c<3 ; ++c)
|
||||
{
|
||||
|
|
|
@ -31,10 +31,7 @@ void ANIM::IANIM::sendANIMToBlender(hecl::BlenderConnection::PyOutStream& os, co
|
|||
"\n";
|
||||
|
||||
if (std::get<1>(bone.second))
|
||||
os << "#bone_trans_head = (0.0,0.0,0.0)\n"
|
||||
"#if arm_obj.data.bones[bone_string].parent is not None:\n"
|
||||
"# bone_trans_head = Vector(arm_obj.data.bones[bone_string].head_local) - Vector(arm_obj.data.bones[bone_string].parent.head_local)\n"
|
||||
"transCurves = []\n"
|
||||
os << "transCurves = []\n"
|
||||
"transCurves.append(act.fcurves.new('pose.bones[\"'+bone_string+'\"].location', index=0, action_group=bone_string))\n"
|
||||
"transCurves.append(act.fcurves.new('pose.bones[\"'+bone_string+'\"].location', index=1, action_group=bone_string))\n"
|
||||
"transCurves.append(act.fcurves.new('pose.bones[\"'+bone_string+'\"].location', index=2, action_group=bone_string))\n"
|
||||
|
|
|
@ -44,12 +44,6 @@ void ANIM::IANIM::sendANIMToBlender(hecl::BlenderConnection::PyOutStream& os, co
|
|||
|
||||
if (std::get<1>(bone.second))
|
||||
{
|
||||
if (!additive)
|
||||
os << "#bone_trans_head = (0.0,0.0,0.0)\n"
|
||||
"#if arm_obj.data.bones[bone_string].parent is not None:\n"
|
||||
"# bone_trans_head = Vector(arm_obj.data.bones[bone_string].head_local) - Vector(arm_obj.data.bones[bone_string].parent.head_local)\n";
|
||||
else
|
||||
os << "#bone_trans_head = (0.0,0.0,0.0)\n";
|
||||
os << "transCurves = []\n"
|
||||
"transCurves.append(act.fcurves.new('pose.bones[\"'+bone_string+'\"].location', index=0, action_group=bone_string))\n"
|
||||
"transCurves.append(act.fcurves.new('pose.bones[\"'+bone_string+'\"].location', index=1, action_group=bone_string))\n"
|
||||
|
|
2
hecl
2
hecl
|
@ -1 +1 @@
|
|||
Subproject commit 76788ee293a8e25131e6fae118b9337f70b8f371
|
||||
Subproject commit 50f43c48616e47408fc6e24c86c41156cc350a77
|
Loading…
Reference in New Issue