2016-04-26 00:47:48 +00:00
|
|
|
#include "CINF.hpp"
|
2017-12-29 08:08:12 +00:00
|
|
|
#include "hecl/Blender/Connection.hpp"
|
2016-04-26 00:47:48 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace DataSpec::DNAMP2 {
|
2016-04-26 00:47:48 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
atUint32 CINF::getInternalBoneIdxFromId(atUint32 id) const {
|
|
|
|
atUint32 idx = 0;
|
|
|
|
for (const Bone& b : bones) {
|
|
|
|
if (b.id == id)
|
|
|
|
return idx;
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
return -1;
|
2016-04-26 00:47:48 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
atUint32 CINF::getBoneIdxFromId(atUint32 id) const {
|
|
|
|
atUint32 idx = 0;
|
|
|
|
for (atUint32 bid : boneIds) {
|
|
|
|
if (bid == id)
|
|
|
|
return idx;
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
return 0;
|
2016-04-26 00:47:48 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const std::string* CINF::getBoneNameFromId(atUint32 id) const {
|
|
|
|
for (const Name& name : names)
|
|
|
|
if (id == name.boneId)
|
|
|
|
return &name.name;
|
|
|
|
return nullptr;
|
2016-04-26 00:47:48 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CINF::sendVertexGroupsToBlender(hecl::blender::PyOutStream& os) const {
|
|
|
|
for (atUint32 bid : boneIds) {
|
|
|
|
for (const Name& name : names) {
|
|
|
|
if (name.boneId == bid) {
|
2019-07-20 04:27:21 +00:00
|
|
|
os.format(fmt("obj.vertex_groups.new(name='{}')\n"), name.name);
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-04-26 00:47:48 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-04-26 00:47:48 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CINF::sendCINFToBlender(hecl::blender::PyOutStream& os, const UniqueID32& cinfId) const {
|
|
|
|
DNAANIM::RigInverter<CINF> inverter(*this);
|
2016-04-26 00:47:48 +00:00
|
|
|
|
2019-07-20 04:27:21 +00:00
|
|
|
os.format(fmt(
|
|
|
|
"arm = bpy.data.armatures.new('CINF_{}')\n"
|
2018-12-08 05:30:43 +00:00
|
|
|
"arm_obj = bpy.data.objects.new(arm.name, arm)\n"
|
2019-05-08 03:50:21 +00:00
|
|
|
"bpy.context.scene.collection.objects.link(arm_obj)\n"
|
|
|
|
"bpy.context.view_layer.objects.active = arm_obj\n"
|
2018-12-08 05:30:43 +00:00
|
|
|
"bpy.ops.object.mode_set(mode='EDIT')\n"
|
2019-07-20 04:27:21 +00:00
|
|
|
"arm_bone_table = {{}}\n"),
|
|
|
|
cinfId);
|
2016-04-26 00:47:48 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const DNAANIM::RigInverter<CINF>::Bone& bone : inverter.getBones()) {
|
|
|
|
zeus::simd_floats originF(bone.m_origBone.origin.simd);
|
|
|
|
zeus::simd_floats tailF(bone.m_tail.mSimd);
|
2019-07-20 04:27:21 +00:00
|
|
|
os.format(fmt(
|
|
|
|
"bone = arm.edit_bones.new('{}')\n"
|
|
|
|
"bone.head = ({},{},{})\n"
|
|
|
|
"bone.tail = ({},{},{})\n"
|
2018-12-08 05:30:43 +00:00
|
|
|
"bone.use_inherit_scale = False\n"
|
2019-07-20 04:27:21 +00:00
|
|
|
"arm_bone_table[{}] = bone\n"),
|
|
|
|
*getBoneNameFromId(bone.m_origBone.id), originF[0], originF[1], originF[2], tailF[0], tailF[1],
|
2018-12-08 05:30:43 +00:00
|
|
|
tailF[2], bone.m_origBone.id);
|
|
|
|
}
|
2016-04-26 00:47:48 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const Bone& bone : bones)
|
|
|
|
if (bone.parentId != 97)
|
2019-07-20 04:27:21 +00:00
|
|
|
os.format(fmt("arm_bone_table[{}].parent = arm_bone_table[{}]\n"), bone.id, bone.parentId);
|
2016-04-26 00:47:48 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
os << "bpy.ops.object.mode_set(mode='OBJECT')\n";
|
2016-04-26 00:47:48 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const DNAANIM::RigInverter<CINF>::Bone& bone : inverter.getBones())
|
2019-07-20 04:27:21 +00:00
|
|
|
os.format(fmt("arm_obj.pose.bones['{}'].rotation_mode = 'QUATERNION'\n"),
|
|
|
|
*getBoneNameFromId(bone.m_origBone.id));
|
2016-04-26 00:47:48 +00:00
|
|
|
}
|
|
|
|
|
2019-07-20 04:27:21 +00:00
|
|
|
std::string CINF::GetCINFArmatureName(const UniqueID32& cinfId) { return fmt::format(fmt("CINF_{}"), cinfId); }
|
2016-04-26 00:47:48 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace DataSpec::DNAMP2
|