From ca37657dbd4bcd6ca9aa2e905343ca9f6b0762d4 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Mon, 25 Apr 2016 14:47:48 -1000 Subject: [PATCH] SLERP PoseBone exporting for supported blender builds --- DataSpec/DNACommon/RigInverter.cpp | 10 ++-- DataSpec/DNAMP1/ANIM.cpp | 6 -- DataSpec/DNAMP1/CINF.cpp | 8 ++- DataSpec/DNAMP2/ANIM.cpp | 6 -- DataSpec/DNAMP2/CINF.cpp | 96 ++++++++++++++++++++++++++++++ DataSpec/DNAMP2/CINF.hpp | 86 ++------------------------ DataSpec/DNAMP2/CMakeLists.txt | 1 + DataSpec/DNAMP3/ANIM.cpp | 6 -- DataSpec/DNAMP3/CINF.cpp | 53 +++++++++++++++++ DataSpec/DNAMP3/CINF.hpp | 39 +----------- DataSpec/DNAMP3/CMakeLists.txt | 1 + hecl | 2 +- 12 files changed, 173 insertions(+), 141 deletions(-) create mode 100644 DataSpec/DNAMP2/CINF.cpp create mode 100644 DataSpec/DNAMP3/CINF.cpp diff --git a/DataSpec/DNACommon/RigInverter.cpp b/DataSpec/DNACommon/RigInverter.cpp index 8ad1874e9..5a22bbd3a 100644 --- a/DataSpec/DNACommon/RigInverter.cpp +++ b/DataSpec/DNACommon/RigInverter.cpp @@ -65,11 +65,13 @@ RigInverter::Bone::Bone(const CINFType& cinf, const typename CINFType: { /* Extrapolate by delta with parent */ m_tail = boneOrigin + m_parentDelta; - if (m_parentDelta.magSquared() < 0.001f) - m_tail = naturalTail; - float deltaMag = m_parentDelta.magnitude(); - if (deltaMag > 0.5f) + if (deltaMag < 0.001f) + { + deltaMag = 0.5f; + m_tail = naturalTail; + } + else if (deltaMag > 0.5f) { /* Extreme bones capped to +0.5 value */ deltaMag = 0.5f; diff --git a/DataSpec/DNAMP1/ANIM.cpp b/DataSpec/DNAMP1/ANIM.cpp index 139716c5d..c15545d13 100644 --- a/DataSpec/DNAMP1/ANIM.cpp +++ b/DataSpec/DNAMP1/ANIM.cpp @@ -40,12 +40,6 @@ void ANIM::IANIM::sendANIMToBlender(hecl::BlenderConnection::PyOutStream& os, co "transCurves.append(act.fcurves.new('pose.bones[\"'+bone_string+'\"].location', index=2, action_group=bone_string))\n" "\n"; - os << "crv = act.fcurves.new('pose.bones[\"'+bone_string+'\"].rotation_mode', action_group=bone_string)\n" - "crv.keyframe_points.add()\n" - "crv.keyframe_points[-1].co = (0, 0)\n" - "crv.keyframe_points[-1].interpolation = 'LINEAR'\n" - "\n"; - ANIMOutStream ao = os.beginANIMCurve(); { diff --git a/DataSpec/DNAMP1/CINF.cpp b/DataSpec/DNAMP1/CINF.cpp index 20ea78754..7fb08282c 100644 --- a/DataSpec/DNAMP1/CINF.cpp +++ b/DataSpec/DNAMP1/CINF.cpp @@ -69,7 +69,8 @@ void CINF::sendCINFToBlender(hecl::BlenderConnection::PyOutStream& os, const Uni "bone.head = (%f,%f,%f)\n" "bone.tail = (%f,%f,%f)\n" "bone.use_inherit_scale = False\n" - "arm_bone_table[%u] = bone\n", getBoneNameFromId(bone.m_origBone.id)->c_str(), + "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); @@ -79,6 +80,11 @@ void CINF::sendCINFToBlender(hecl::BlenderConnection::PyOutStream& os, const Uni os.format("arm_bone_table[%u].parent = arm_bone_table[%u]\n", bone.id, bone.parentId); os << "bpy.ops.object.mode_set(mode='OBJECT')\n"; + + const char* rotMode = os.getConnection().hasSLERP() ? "QUATERNION_SLERP" : "QUATERNION"; + for (const DNAANIM::RigInverter::Bone& bone : inverter.getBones()) + os.format("arm_obj.pose.bones['%s'].rotation_mode = '%s'\n", + getBoneNameFromId(bone.m_origBone.id)->c_str(), rotMode); } std::string CINF::GetCINFArmatureName(const UniqueID32& cinfId) diff --git a/DataSpec/DNAMP2/ANIM.cpp b/DataSpec/DNAMP2/ANIM.cpp index a9816c29c..bafa40381 100644 --- a/DataSpec/DNAMP2/ANIM.cpp +++ b/DataSpec/DNAMP2/ANIM.cpp @@ -48,12 +48,6 @@ void ANIM::IANIM::sendANIMToBlender(hecl::BlenderConnection::PyOutStream& os, co "scaleCurves.append(act.fcurves.new('pose.bones[\"'+bone_string+'\"].scale', index=2, action_group=bone_string))\n" "\n"; - os << "crv = act.fcurves.new('pose.bones[\"'+bone_string+'\"].rotation_mode', action_group=bone_string)\n" - "crv.keyframe_points.add()\n" - "crv.keyframe_points[-1].co = (0, 0)\n" - "crv.keyframe_points[-1].interpolation = 'LINEAR'\n" - "\n"; - ANIMOutStream ao = os.beginANIMCurve(); if (std::get<0>(bone.second)) { diff --git a/DataSpec/DNAMP2/CINF.cpp b/DataSpec/DNAMP2/CINF.cpp new file mode 100644 index 000000000..c944c0308 --- /dev/null +++ b/DataSpec/DNAMP2/CINF.cpp @@ -0,0 +1,96 @@ +#include "CINF.hpp" + +namespace DataSpec +{ +namespace DNAMP2 +{ + +atUint32 CINF::getInternalBoneIdxFromId(atUint32 id) const +{ + atUint32 idx = 0; + for (const Bone& b : bones) + { + if (b.id == id) + return idx; + ++idx; + } + return -1; +} + +atUint32 CINF::getBoneIdxFromId(atUint32 id) const +{ + atUint32 idx = 0; + for (atUint32 bid : boneIds) + { + if (bid == id) + return idx; + ++idx; + } + return 0; +} + +const std::string* CINF::getBoneNameFromId(atUint32 id) const +{ + for (const Name& name : names) + if (id == name.boneId) + return &name.name; + return nullptr; +} + +void CINF::sendVertexGroupsToBlender(hecl::BlenderConnection::PyOutStream& os) const +{ + for (atUint32 bid : boneIds) + { + for (const Name& name : names) + { + if (name.boneId == bid) + { + os.format("obj.vertex_groups.new('%s')\n", name.name.c_str()); + break; + } + } + } +} + +void CINF::sendCINFToBlender(hecl::BlenderConnection::PyOutStream& os, const UniqueID32& cinfId) const +{ + DNAANIM::RigInverter 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" + "bpy.context.scene.objects.active = arm_obj\n" + "bpy.ops.object.mode_set(mode='EDIT')\n" + "arm_bone_table = {}\n", + cinfId.toUint32()); + + for (const DNAANIM::RigInverter::Bone& bone : inverter.getBones()) + os.format("bone = arm.edit_bones.new('%s')\n" + "bone.head = (%f,%f,%f)\n" + "bone.tail = (%f,%f,%f)\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], + 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) + os.format("arm_bone_table[%u].parent = arm_bone_table[%u]\n", bone.id, bone.parentId); + + os << "bpy.ops.object.mode_set(mode='OBJECT')\n"; + + const char* rotMode = os.getConnection().hasSLERP() ? "QUATERNION_SLERP" : "QUATERNION"; + for (const DNAANIM::RigInverter::Bone& bone : inverter.getBones()) + os.format("arm_obj.pose.bones['%s'].rotation_mode = '%s'\n", + getBoneNameFromId(bone.m_origBone.id)->c_str(), rotMode); +} + +std::string CINF::GetCINFArmatureName(const UniqueID32& cinfId) +{ + return hecl::Format("CINF_%08X", cinfId.toUint32()); +} + +} +} diff --git a/DataSpec/DNAMP2/CINF.hpp b/DataSpec/DNAMP2/CINF.hpp index 905927116..307f1ec81 100644 --- a/DataSpec/DNAMP2/CINF.hpp +++ b/DataSpec/DNAMP2/CINF.hpp @@ -38,86 +38,12 @@ struct CINF : BigDNA }; Vector 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; - for (atUint32 bid : boneIds) - { - if (bid == id) - return idx; - ++idx; - } - return 0; - } - - const std::string* getBoneNameFromId(atUint32 id) const - { - for (const Name& name : names) - if (id == name.boneId) - return &name.name; - return nullptr; - } - - void sendVertexGroupsToBlender(hecl::BlenderConnection::PyOutStream& os) const - { - for (atUint32 bid : boneIds) - { - for (const Name& name : names) - { - if (name.boneId == bid) - { - os.format("obj.vertex_groups.new('%s')\n", name.name.c_str()); - break; - } - } - } - } - - void sendCINFToBlender(hecl::BlenderConnection::PyOutStream& os, const UniqueID32& cinfId) const - { - DNAANIM::RigInverter 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" - "bpy.context.scene.objects.active = arm_obj\n" - "bpy.ops.object.mode_set(mode='EDIT')\n" - "arm_bone_table = {}\n", - cinfId.toUint32()); - - for (const DNAANIM::RigInverter::Bone& bone : inverter.getBones()) - os.format("bone = arm.edit_bones.new('%s')\n" - "bone.head = (%f,%f,%f)\n" - "bone.tail = (%f,%f,%f)\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], - 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) - os.format("arm_bone_table[%u].parent = arm_bone_table[%u]\n", bone.id, bone.parentId); - - os << "bpy.ops.object.mode_set(mode='OBJECT')\n"; - } - - static std::string GetCINFArmatureName(const UniqueID32& cinfId) - { - return hecl::Format("CINF_%08X", cinfId.toUint32()); - } + atUint32 getInternalBoneIdxFromId(atUint32 id) const; + atUint32 getBoneIdxFromId(atUint32 id) const; + const std::string* getBoneNameFromId(atUint32 id) const; + void sendVertexGroupsToBlender(hecl::BlenderConnection::PyOutStream& os) const; + void sendCINFToBlender(hecl::BlenderConnection::PyOutStream& os, const UniqueID32& cinfId) const; + static std::string GetCINFArmatureName(const UniqueID32& cinfId); }; } diff --git a/DataSpec/DNAMP2/CMakeLists.txt b/DataSpec/DNAMP2/CMakeLists.txt index 7c1e4b45c..e236c2be8 100644 --- a/DataSpec/DNAMP2/CMakeLists.txt +++ b/DataSpec/DNAMP2/CMakeLists.txt @@ -12,6 +12,7 @@ add_library(DNAMP2 DNAMP2.hpp DNAMP2.cpp ${liblist} ANIM.cpp + CINF.cpp ANCS.cpp CMDL.hpp MREA.cpp diff --git a/DataSpec/DNAMP3/ANIM.cpp b/DataSpec/DNAMP3/ANIM.cpp index 6098458ed..eadc90226 100644 --- a/DataSpec/DNAMP3/ANIM.cpp +++ b/DataSpec/DNAMP3/ANIM.cpp @@ -62,12 +62,6 @@ void ANIM::IANIM::sendANIMToBlender(hecl::BlenderConnection::PyOutStream& os, co "scaleCurves.append(act.fcurves.new('pose.bones[\"'+bone_string+'\"].scale', index=2, action_group=bone_string))\n" "\n"; - os << "crv = act.fcurves.new('pose.bones[\"'+bone_string+'\"].rotation_mode', action_group=bone_string)\n" - "crv.keyframe_points.add()\n" - "crv.keyframe_points[-1].co = (0, 0)\n" - "crv.keyframe_points[-1].interpolation = 'LINEAR'\n" - "\n"; - ANIMOutStream ao = os.beginANIMCurve(); if (std::get<0>(bone.second)) { diff --git a/DataSpec/DNAMP3/CINF.cpp b/DataSpec/DNAMP3/CINF.cpp new file mode 100644 index 000000000..df39ed7c2 --- /dev/null +++ b/DataSpec/DNAMP3/CINF.cpp @@ -0,0 +1,53 @@ +#include "CINF.hpp" + +namespace DataSpec +{ +namespace DNAMP3 +{ + +void CINF::sendCINFToBlender(hecl::BlenderConnection::PyOutStream& os, const UniqueID64& cinfId) const +{ + DNAANIM::RigInverter 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" + "bpy.context.scene.objects.active = arm_obj\n" + "bpy.ops.object.mode_set(mode='EDIT')\n" + "arm_bone_table = {}\n", + cinfId.toUint64()); + + for (const DNAANIM::RigInverter::Bone& bone : inverter.getBones()) + os.format("bone = arm.edit_bones.new('%s')\n" + "bone.head = (%f,%f,%f)\n" + "bone.tail = (%f,%f,%f)\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], + bone.m_tail[0], bone.m_tail[1], bone.m_tail[2], + bone.m_origBone.id); + + if (bones.size()) + { + atUint32 nullId = bones[0].parentId; + for (const Bone& bone : bones) + if (bone.parentId != nullId) + os.format("arm_bone_table[%u].parent = arm_bone_table[%u]\n", bone.id, bone.parentId); + } + + os << "bpy.ops.object.mode_set(mode='OBJECT')\n"; + + const char* rotMode = os.getConnection().hasSLERP() ? "QUATERNION_SLERP" : "QUATERNION"; + for (const DNAANIM::RigInverter::Bone& bone : inverter.getBones()) + os.format("arm_obj.pose.bones['%s'].rotation_mode = '%s'\n", + getBoneNameFromId(bone.m_origBone.id)->c_str(), rotMode); +} + +std::string CINF::GetCINFArmatureName(const UniqueID64& cinfId) +{ + return hecl::Format("CINF_%016" PRIX64, cinfId.toUint64()); +} + +} +} diff --git a/DataSpec/DNAMP3/CINF.hpp b/DataSpec/DNAMP3/CINF.hpp index 4bc726070..77cc54355 100644 --- a/DataSpec/DNAMP3/CINF.hpp +++ b/DataSpec/DNAMP3/CINF.hpp @@ -13,43 +13,8 @@ namespace DNAMP3 struct CINF : DNAMP2::CINF { Delete expl; - void sendCINFToBlender(hecl::BlenderConnection::PyOutStream& os, const UniqueID64& cinfId) const - { - DNAANIM::RigInverter 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" - "bpy.context.scene.objects.active = arm_obj\n" - "bpy.ops.object.mode_set(mode='EDIT')\n" - "arm_bone_table = {}\n", - cinfId.toUint64()); - - for (const DNAANIM::RigInverter::Bone& bone : inverter.getBones()) - os.format("bone = arm.edit_bones.new('%s')\n" - "bone.head = (%f,%f,%f)\n" - "bone.tail = (%f,%f,%f)\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], - bone.m_tail[0], bone.m_tail[1], bone.m_tail[2], - bone.m_origBone.id); - - if (bones.size()) - { - atUint32 nullId = bones[0].parentId; - for (const Bone& bone : bones) - if (bone.parentId != nullId) - os.format("arm_bone_table[%u].parent = arm_bone_table[%u]\n", bone.id, bone.parentId); - } - - os << "bpy.ops.object.mode_set(mode='OBJECT')\n"; - } - - static std::string GetCINFArmatureName(const UniqueID64& cinfId) - { - return hecl::Format("CINF_%016" PRIX64, cinfId.toUint64()); - } + void sendCINFToBlender(hecl::BlenderConnection::PyOutStream& os, const UniqueID64& cinfId) const; + static std::string GetCINFArmatureName(const UniqueID64& cinfId); }; } diff --git a/DataSpec/DNAMP3/CMakeLists.txt b/DataSpec/DNAMP3/CMakeLists.txt index f106778b1..531091fdf 100644 --- a/DataSpec/DNAMP3/CMakeLists.txt +++ b/DataSpec/DNAMP3/CMakeLists.txt @@ -12,6 +12,7 @@ add_library(DNAMP3 ${liblist} PAK.cpp ANIM.cpp + CINF.cpp CHAR.cpp CMDL.hpp CMDLMaterials.cpp diff --git a/hecl b/hecl index 675d00d08..fdc5d61b4 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 675d00d08a2713006dd64622ff61ae849f71c06f +Subproject commit fdc5d61b4e091a8c5eefa625ea9b21d59977f633