From b7bd8d813fd92d25eceedc7b1f23894c12bba6f9 Mon Sep 17 00:00:00 2001 From: Gaia Clary Date: Sun, 2 Jun 2019 19:06:14 +0200 Subject: feature collada: Allow export/import of skeletal animations as curves --- source/blender/collada/ArmatureImporter.cpp | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'source/blender/collada/ArmatureImporter.cpp') diff --git a/source/blender/collada/ArmatureImporter.cpp b/source/blender/collada/ArmatureImporter.cpp index de66c6ebdb2..9bafc58a658 100644 --- a/source/blender/collada/ArmatureImporter.cpp +++ b/source/blender/collada/ArmatureImporter.cpp @@ -659,6 +659,11 @@ Object *ArmatureImporter::create_armature_bones(Main *bmain, SkinInfo &skin) ED_armature_from_edit(bmain, armature); ED_armature_edit_free(armature); + for (ri = root_joints.begin(); ri != root_joints.end(); ri++) { + COLLADAFW::Node *node = *ri; + set_bone_transformation_type(node, ob_arm); + } + ED_armature_to_edit(armature); if (this->import_settings->find_chains) { connect_bone_chains(armature, (Bone *)armature->bonebase.first, UNLIMITED_CHAIN_MAX); @@ -673,6 +678,20 @@ Object *ArmatureImporter::create_armature_bones(Main *bmain, SkinInfo &skin) return ob_arm; } +void ArmatureImporter::set_bone_transformation_type(const COLLADAFW::Node *node, Object *ob_arm) +{ + bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm->pose, bc_get_joint_name(node)); + if (pchan) { + pchan->rotmode = (node_is_decomposed(node)) ? ROT_MODE_EUL : ROT_MODE_QUAT; + } + + COLLADAFW::NodePointerArray childnodes = node->getChildNodes(); + for (int index = 0; index < childnodes.getCount(); index++) { + node = childnodes[index]; + set_bone_transformation_type(node, ob_arm); + } +} + void ArmatureImporter::set_pose(Object *ob_arm, COLLADAFW::Node *root_node, const char *parentname, @@ -684,9 +703,12 @@ void ArmatureImporter::set_pose(Object *ob_arm, /* object-space */ get_node_mat(obmat, root_node, NULL, NULL); + bool is_decomposed = node_is_decomposed(root_node); // if (*edbone) bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm->pose, bone_name); + pchan->rotmode = (is_decomposed) ? ROT_MODE_EUL : ROT_MODE_QUAT; + // else fprintf ( "", /* get world-space */ @@ -716,6 +738,19 @@ void ArmatureImporter::set_pose(Object *ob_arm, } } +bool ArmatureImporter::node_is_decomposed(const COLLADAFW::Node *node) +{ + const COLLADAFW::TransformationPointerArray &nodeTransforms = node->getTransformations(); + for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) { + COLLADAFW::Transformation *transform = nodeTransforms[i]; + COLLADAFW::Transformation::TransformationType tm_type = transform->getTransformationType(); + if (tm_type == COLLADAFW::Transformation::MATRIX) { + return false; + } + } + return true; +} + /** * root - if this joint is the top joint in hierarchy, if a joint * is a child of a node (not joint), root should be true since -- cgit v1.2.3