mirror of https://github.com/AxioDL/metaforce.git
MP2/3 RigInverter
This commit is contained in:
parent
6d13a4b257
commit
68c1ac8978
|
@ -56,7 +56,7 @@ RigInverter<CINFType>::Bone::Bone(const CINFType& cinf, const typename CINFType:
|
|||
}
|
||||
}
|
||||
m_tail /= float(actualChildren);
|
||||
if (m_tail.magSquared() < 0.001f)
|
||||
if ((m_tail - boneOrigin).magSquared() < 0.001f)
|
||||
m_tail = naturalTail;
|
||||
|
||||
if (isLCTR)
|
||||
|
@ -65,8 +65,8 @@ RigInverter<CINFType>::Bone::Bone(const CINFType& cinf, const typename CINFType:
|
|||
else if (parentIdx != -1)
|
||||
{
|
||||
/* Extrapolate by delta with parent */
|
||||
m_tail = zeus::CVector3f(origBone.origin) + m_parentDelta;
|
||||
if (m_tail.magSquared() < 0.001f)
|
||||
m_tail = boneOrigin + m_parentDelta;
|
||||
if (m_parentDelta.magSquared() < 0.001f)
|
||||
m_tail = naturalTail;
|
||||
|
||||
float deltaMag = m_parentDelta.magnitude();
|
||||
|
|
|
@ -46,8 +46,6 @@ void ANIM::IANIM::sendANIMToBlender(hecl::BlenderConnection::PyOutStream& os, co
|
|||
"crv.keyframe_points[-1].interpolation = 'LINEAR'\n"
|
||||
"\n";
|
||||
|
||||
if (bone.first == 3)
|
||||
printf("");
|
||||
ANIMOutStream ao = os.beginANIMCurve();
|
||||
|
||||
{
|
||||
|
|
|
@ -100,7 +100,6 @@ struct CINF : BigDNA
|
|||
os.format("bone = arm.edit_bones.new('%s')\n"
|
||||
"bone.head = (%f,%f,%f)\n"
|
||||
"bone.tail = (%f,%f,%f)\n"
|
||||
"#bone.tail[1] += 0.5\n"
|
||||
"bone.use_inherit_scale = False\n"
|
||||
"arm_bone_table[%u] = bone\n", getBoneNameFromId(bone.m_origBone.id)->c_str(),
|
||||
bone.m_origBone.origin.vec[0], bone.m_origBone.origin.vec[1], bone.m_origBone.origin.vec[2],
|
||||
|
|
|
@ -12,6 +12,10 @@ void ANIM::IANIM::sendANIMToBlender(hecl::BlenderConnection::PyOutStream& os, co
|
|||
os.format("act.hecl_fps = round(%f)\n", (1.0f / mainInterval));
|
||||
|
||||
auto kit = chanKeys.begin();
|
||||
|
||||
std::vector<zeus::CQuaternion> fixedRotKeys;
|
||||
std::vector<zeus::CVector3f> fixedTransKeys;
|
||||
|
||||
for (const std::pair<atUint32, std::tuple<bool,bool,bool>>& bone : bones)
|
||||
{
|
||||
const std::string* bName = rig.getCINF().getBoneNameFromId(bone.first);
|
||||
|
@ -54,24 +58,50 @@ void ANIM::IANIM::sendANIMToBlender(hecl::BlenderConnection::PyOutStream& os, co
|
|||
if (std::get<0>(bone.second))
|
||||
{
|
||||
const std::vector<DNAANIM::Value>& rotKeys = *kit++;
|
||||
fixedRotKeys.clear();
|
||||
fixedRotKeys.resize(rotKeys.size());
|
||||
|
||||
for (int c=0 ; c<4 ; ++c)
|
||||
{
|
||||
size_t idx = 0;
|
||||
for (const DNAANIM::Value& val : rotKeys)
|
||||
fixedRotKeys[idx++][c] = val.v4.vec[c];
|
||||
}
|
||||
|
||||
for (zeus::CQuaternion& rot : fixedRotKeys)
|
||||
rot = rig.invertRotation(bone.first, rot);
|
||||
|
||||
for (int c=0 ; c<4 ; ++c)
|
||||
{
|
||||
auto frameit = frames.begin();
|
||||
ao.changeCurve(ANIMOutStream::CurveType::Rotate, c, rotKeys.size());
|
||||
for (const DNAANIM::Value& val : rotKeys)
|
||||
ao.write(*frameit++, val.v4.vec[c]);
|
||||
for (const zeus::CQuaternion& val : fixedRotKeys)
|
||||
ao.write(*frameit++, val[c]);
|
||||
}
|
||||
}
|
||||
|
||||
if (std::get<1>(bone.second))
|
||||
{
|
||||
const std::vector<DNAANIM::Value>& transKeys = *kit++;
|
||||
fixedTransKeys.clear();
|
||||
fixedTransKeys.resize(transKeys.size());
|
||||
|
||||
for (int c=0 ; c<3 ; ++c)
|
||||
{
|
||||
size_t idx = 0;
|
||||
for (const DNAANIM::Value& val : transKeys)
|
||||
fixedTransKeys[idx++][c] = val.v3.vec[c];
|
||||
}
|
||||
|
||||
for (zeus::CVector3f& t : fixedTransKeys)
|
||||
t = rig.invertPosition(bone.first, t, true);
|
||||
|
||||
for (int c=0 ; c<3 ; ++c)
|
||||
{
|
||||
auto frameit = frames.begin();
|
||||
ao.changeCurve(ANIMOutStream::CurveType::Translate, c, transKeys.size());
|
||||
for (const DNAANIM::Value& val : transKeys)
|
||||
ao.write(*frameit++, val.v3.vec[c]);
|
||||
ao.changeCurve(ANIMOutStream::CurveType::Translate, c, fixedTransKeys.size());
|
||||
for (const zeus::CVector3f& val : fixedTransKeys)
|
||||
ao.write(*frameit++, val[c]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "BlenderConnection.hpp"
|
||||
#include "../DNACommon/DNACommon.hpp"
|
||||
#include "../DNACommon/RigInverter.hpp"
|
||||
|
||||
namespace DataSpec
|
||||
{
|
||||
|
@ -86,6 +87,8 @@ struct CINF : BigDNA
|
|||
|
||||
void sendCINFToBlender(hecl::BlenderConnection::PyOutStream& os, const UniqueID32& cinfId) const
|
||||
{
|
||||
DNAANIM::RigInverter<CINF> inverter(*this);
|
||||
|
||||
os.format("arm = bpy.data.armatures.new('CINF_%08X')\n"
|
||||
"arm_obj = bpy.data.objects.new(arm.name, arm)\n"
|
||||
"bpy.context.scene.objects.link(arm_obj)\n"
|
||||
|
@ -94,14 +97,15 @@ struct CINF : BigDNA
|
|||
"arm_bone_table = {}\n",
|
||||
cinfId.toUint32());
|
||||
|
||||
for (const Bone& bone : bones)
|
||||
for (const DNAANIM::RigInverter<CINF>::Bone& bone : inverter.getBones())
|
||||
os.format("bone = arm.edit_bones.new('%s')\n"
|
||||
"bone.head = (%f,%f,%f)\n"
|
||||
"bone.tail = bone.head\n"
|
||||
"bone.tail[1] += 0.5\n"
|
||||
"bone.tail = (%f,%f,%f)\n"
|
||||
"bone.use_inherit_scale = False\n"
|
||||
"arm_bone_table[%u] = bone\n", getBoneNameFromId(bone.id)->c_str(),
|
||||
bone.origin.vec[0], bone.origin.vec[1], bone.origin.vec[2], bone.id);
|
||||
"arm_bone_table[%u] = bone\n", getBoneNameFromId(bone.m_origBone.id)->c_str(),
|
||||
bone.m_origBone.origin.vec[0], bone.m_origBone.origin.vec[1], bone.m_origBone.origin.vec[2],
|
||||
bone.m_tail[0], bone.m_tail[1], bone.m_tail[2],
|
||||
bone.m_origBone.id);
|
||||
|
||||
for (const Bone& bone : bones)
|
||||
if (bone.parentId != 97)
|
||||
|
|
|
@ -16,6 +16,10 @@ void ANIM::IANIM::sendANIMToBlender(hecl::BlenderConnection::PyOutStream& os, co
|
|||
1.0f / mainInterval, additive ? "True" : "False");
|
||||
|
||||
auto kit = chanKeys.begin() + 1;
|
||||
|
||||
std::vector<zeus::CQuaternion> fixedRotKeys;
|
||||
std::vector<zeus::CVector3f> fixedTransKeys;
|
||||
|
||||
for (const std::pair<atUint32, std::tuple<bool,bool,bool>>& bone : bones)
|
||||
{
|
||||
const std::string* bName = rig.getCINF().getBoneNameFromId(bone.first);
|
||||
|
@ -68,24 +72,50 @@ void ANIM::IANIM::sendANIMToBlender(hecl::BlenderConnection::PyOutStream& os, co
|
|||
if (std::get<0>(bone.second))
|
||||
{
|
||||
const std::vector<DNAANIM::Value>& rotKeys = *kit++;
|
||||
fixedRotKeys.clear();
|
||||
fixedRotKeys.resize(rotKeys.size());
|
||||
|
||||
for (int c=0 ; c<4 ; ++c)
|
||||
{
|
||||
size_t idx = 0;
|
||||
for (const DNAANIM::Value& val : rotKeys)
|
||||
fixedRotKeys[idx++][c] = val.v4.vec[c];
|
||||
}
|
||||
|
||||
for (zeus::CQuaternion& rot : fixedRotKeys)
|
||||
rot = rig.invertRotation(bone.first, rot);
|
||||
|
||||
for (int c=0 ; c<4 ; ++c)
|
||||
{
|
||||
auto frameit = frames.begin();
|
||||
ao.changeCurve(ANIMOutStream::CurveType::Rotate, c, rotKeys.size());
|
||||
for (const DNAANIM::Value& val : rotKeys)
|
||||
ao.write(*frameit++, val.v4.vec[c]);
|
||||
for (const zeus::CQuaternion& val : fixedRotKeys)
|
||||
ao.write(*frameit++, val[c]);
|
||||
}
|
||||
}
|
||||
|
||||
if (std::get<1>(bone.second))
|
||||
{
|
||||
const std::vector<DNAANIM::Value>& transKeys = *kit++;
|
||||
fixedTransKeys.clear();
|
||||
fixedTransKeys.resize(transKeys.size());
|
||||
|
||||
for (int c=0 ; c<3 ; ++c)
|
||||
{
|
||||
size_t idx = 0;
|
||||
for (const DNAANIM::Value& val : transKeys)
|
||||
fixedTransKeys[idx++][c] = val.v3.vec[c];
|
||||
}
|
||||
|
||||
for (zeus::CVector3f& t : fixedTransKeys)
|
||||
t = rig.invertPosition(bone.first, t, !additive);
|
||||
|
||||
for (int c=0 ; c<3 ; ++c)
|
||||
{
|
||||
auto frameit = frames.begin();
|
||||
ao.changeCurve(ANIMOutStream::CurveType::Translate, c, transKeys.size());
|
||||
for (const DNAANIM::Value& val : transKeys)
|
||||
ao.write(*frameit++, val.v3.vec[c]);
|
||||
ao.changeCurve(ANIMOutStream::CurveType::Translate, c, fixedTransKeys.size());
|
||||
for (const zeus::CVector3f& val : fixedTransKeys)
|
||||
ao.write(*frameit++, val[c]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@ struct CINF : DNAMP2::CINF
|
|||
Delete expl;
|
||||
void sendCINFToBlender(hecl::BlenderConnection::PyOutStream& os, const UniqueID64& cinfId) const
|
||||
{
|
||||
DNAANIM::RigInverter<CINF> inverter(*this);
|
||||
|
||||
os.format("arm = bpy.data.armatures.new('CINF_%016" PRIX64 "')\n"
|
||||
"arm_obj = bpy.data.objects.new(arm.name, arm)\n"
|
||||
"bpy.context.scene.objects.link(arm_obj)\n"
|
||||
|
@ -23,14 +25,15 @@ struct CINF : DNAMP2::CINF
|
|||
"arm_bone_table = {}\n",
|
||||
cinfId.toUint64());
|
||||
|
||||
for (const Bone& bone : bones)
|
||||
for (const DNAANIM::RigInverter<CINF>::Bone& bone : inverter.getBones())
|
||||
os.format("bone = arm.edit_bones.new('%s')\n"
|
||||
"bone.head = (%f,%f,%f)\n"
|
||||
"bone.tail = bone.head\n"
|
||||
"bone.tail[1] += 0.5\n"
|
||||
"bone.tail = (%f,%f,%f)\n"
|
||||
"bone.use_inherit_scale = False\n"
|
||||
"arm_bone_table[%u] = bone\n", getBoneNameFromId(bone.id)->c_str(),
|
||||
bone.origin.vec[0], bone.origin.vec[1], bone.origin.vec[2], bone.id);
|
||||
"arm_bone_table[%u] = bone\n", getBoneNameFromId(bone.m_origBone.id)->c_str(),
|
||||
bone.m_origBone.origin.vec[0], bone.m_origBone.origin.vec[1], bone.m_origBone.origin.vec[2],
|
||||
bone.m_tail[0], bone.m_tail[1], bone.m_tail[2],
|
||||
bone.m_origBone.id);
|
||||
|
||||
if (bones.size())
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue