2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-09 21:07:42 +00:00

Migration to new ANIM extract

This commit is contained in:
Jack Andersen
2016-04-06 17:40:25 -10:00
parent cd8b6b6ed4
commit 9ee8840b54
29 changed files with 691 additions and 427 deletions

View File

@@ -3,6 +3,7 @@
#include "BlenderConnection.hpp"
#include "../DNACommon/DNACommon.hpp"
#include "../DNACommon/RigInverter.hpp"
namespace DataSpec
{
@@ -36,6 +37,18 @@ struct CINF : BigDNA
};
Vector<Name, DNA_COUNT(nameCount)> names;
atUint32 getInternalBoneIdxFromId(atUint32 id) const
{
atUint32 idx = 0;
for (const Bone& b : bones)
{
if (b.id == id)
return idx;
++idx;
}
return -1;
}
atUint32 getBoneIdxFromId(atUint32 id) const
{
atUint32 idx = 0;
@@ -73,6 +86,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"
@@ -81,14 +96,16 @@ 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.tail[1] += 0.5\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 != 2)
@@ -96,6 +113,49 @@ struct CINF : BigDNA
os << "bpy.ops.object.mode_set(mode='OBJECT')\n";
}
CINF() = default;
using Armature = hecl::BlenderConnection::DataStream::Actor::Armature;
int RecursiveAddArmatureBone(const Armature& armature, const Armature::Bone* bone, int parent, int& curId)
{
bones.emplace_back();
names.emplace_back();
Bone& boneOut = bones.back();
Name& nameOut = names.back();
nameOut.name = bone->name;
nameOut.boneId = curId;
boneOut.id = curId++;
boneOut.parentId = parent;
boneOut.origin = bone->origin;
boneOut.linkedCount = bone->children.size();
boneOut.linked.reserve(boneOut.linkedCount);
const Armature::Bone* child;
for (size_t i=0 ; (child = armature.getChild(bone, i)) ; ++i)
boneOut.linked.push_back(RecursiveAddArmatureBone(armature, child, boneOut.id, curId));
return boneOut.id;
}
CINF(const Armature& armature)
{
bones.reserve(armature.bones.size());
names.reserve(armature.bones.size());
const Armature::Bone* bone = armature.getRoot();
int curId = 3;
if (bone)
RecursiveAddArmatureBone(armature, bone, 2, curId);
boneCount = bones.size();
nameCount = names.size();
boneIdCount = boneCount;
boneIds.reserve(boneIdCount);
for (auto it=bones.crbegin() ; it != bones.crend() ; ++it)
boneIds.push_back(it->id);
}
};
}