From 1346482d23f167fa57049128384246397fda8d27 Mon Sep 17 00:00:00 2001 From: Gaia Clary Date: Thu, 26 May 2016 18:22:36 +0200 Subject: moved is_leaf_bone() to collada utils for reuse in exporter and importer --- source/blender/collada/ArmatureExporter.cpp | 12 +----- source/blender/collada/ArmatureImporter.cpp | 63 ++++++++++++++--------------- source/blender/collada/ArmatureImporter.h | 2 + source/blender/collada/collada_utils.cpp | 12 ++++++ source/blender/collada/collada_utils.h | 2 +- 5 files changed, 47 insertions(+), 44 deletions(-) (limited to 'source/blender/collada') diff --git a/source/blender/collada/ArmatureExporter.cpp b/source/blender/collada/ArmatureExporter.cpp index cf02293886c..47a0ffda3c6 100644 --- a/source/blender/collada/ArmatureExporter.cpp +++ b/source/blender/collada/ArmatureExporter.cpp @@ -150,16 +150,6 @@ std::string ArmatureExporter::get_joint_sid(Bone *bone, Object *ob_arm) return get_joint_id(bone, ob_arm); } -static bool is_leaf_bone(Bone *bone) -{ - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { - if (child->flag & BONE_CONNECTED) { - return false; - } - } - return true; -} - // parent_mat is armature-space void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene *sce, SceneExporter *se, @@ -185,7 +175,7 @@ void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene *sce, } } - if (is_leaf_bone(bone)) + if (bc_is_leaf_bone(bone)) { node.addExtraTechniqueParameter("blender", "tip_x", bone->arm_tail[0] - bone->arm_head[0]); node.addExtraTechniqueParameter("blender", "tip_y", bone->arm_tail[1] - bone->arm_head[1]); diff --git a/source/blender/collada/ArmatureImporter.cpp b/source/blender/collada/ArmatureImporter.cpp index df60b213d16..4c318cd97cc 100644 --- a/source/blender/collada/ArmatureImporter.cpp +++ b/source/blender/collada/ArmatureImporter.cpp @@ -210,18 +210,6 @@ int ArmatureImporter::create_bone(SkinInfo *skin, COLLADAFW::Node *node, EditBon return chain_length + 1; } -/* - * A bone is a leaf when it has no children or all children are not connected. - */ -static bool is_leaf_bone(Bone *bone) -{ - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { - if (child->flag & BONE_CONNECTED) - return false; - } - return true; -} - /** * Collada only knows Joints, hence bones at the end of a bone chain * don't have a defined length. This function guesses reasonable @@ -233,35 +221,39 @@ void ArmatureImporter::fix_leaf_bones(bArmature *armature, Bone *bone) if (bone == NULL) return; - if (is_leaf_bone(bone)) { - /* Collada only knows Joints, Here we guess a reasonable leaf bone length */ - float leaf_length = (leaf_bone_length == FLT_MAX) ? 1.0 : leaf_bone_length; + if (bc_is_leaf_bone(bone)) { - EditBone *ebone = get_edit_bone(armature, bone->name); - float vec[3]; + BoneExtended *be = extended_bones[bone->name]; + if (be == NULL || !be->has_custom_tail()) { - if (ebone->parent != NULL) { - EditBone *parent = ebone->parent; - sub_v3_v3v3(vec, ebone->head, parent->head); - if (len_squared_v3(vec) < MINIMUM_BONE_LENGTH) - { - sub_v3_v3v3(vec, parent->tail, parent->head); + /* Collada only knows Joints, Here we guess a reasonable leaf bone length */ + float leaf_length = (leaf_bone_length == FLT_MAX) ? 1.0 : leaf_bone_length; + + EditBone *ebone = get_edit_bone(armature, bone->name); + float vec[3]; + + if (ebone->parent != NULL) { + EditBone *parent = ebone->parent; + sub_v3_v3v3(vec, ebone->head, parent->head); + if (len_squared_v3(vec) < MINIMUM_BONE_LENGTH) + { + sub_v3_v3v3(vec, parent->tail, parent->head); + } + } + else { + vec[2] = 0.1f; + sub_v3_v3v3(vec, ebone->tail, ebone->head); } - } - else { - vec[2] = 0.1f; - sub_v3_v3v3(vec, ebone->tail, ebone->head); - } - normalize_v3_v3(vec, vec); - mul_v3_fl(vec, leaf_length); - add_v3_v3v3(ebone->tail, ebone->head, vec); + normalize_v3_v3(vec, vec); + mul_v3_fl(vec, leaf_length); + add_v3_v3v3(ebone->tail, ebone->head, vec); + } } for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { fix_leaf_bones(armature, child); } - } void ArmatureImporter::fix_parent_connect(bArmature *armature, Bone *bone) @@ -949,6 +941,7 @@ BoneExtended::BoneExtended(EditBone *aBone) this->tail[1] = 0.5f; this->tail[2] = 0.0f; this->use_connect = -1; + this->has_tail = false; } char *BoneExtended::get_name() @@ -986,6 +979,12 @@ void BoneExtended::set_tail(float vec[]) this->tail[0] = vec[0]; this->tail[1] = vec[1]; this->tail[2] = vec[2]; + this->has_tail = true; +} + +bool BoneExtended::has_custom_tail() +{ + return this->has_tail; } float *BoneExtended::get_tail() diff --git a/source/blender/collada/ArmatureImporter.h b/source/blender/collada/ArmatureImporter.h index 407fa83f84b..4cef3d4fb38 100644 --- a/source/blender/collada/ArmatureImporter.h +++ b/source/blender/collada/ArmatureImporter.h @@ -67,6 +67,7 @@ private: bool is_leaf; float tail[3]; bool use_connect; + bool has_tail; public: @@ -83,6 +84,7 @@ public: void set_tail(float *vec); float *get_tail(); + bool has_custom_tail(); void set_use_connect(int use_connect); int get_use_connect(); diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp index f8feed8145c..30cf404cc3d 100644 --- a/source/blender/collada/collada_utils.cpp +++ b/source/blender/collada/collada_utils.cpp @@ -366,3 +366,15 @@ void bc_triangulate_mesh(Mesh *me) BM_mesh_bm_to_me(bm, me, &bm_to_me_params); BM_mesh_free(bm); } + +/* +* A bone is a leaf when it has no children or all children are not connected. +*/ +bool bc_is_leaf_bone(Bone *bone) +{ + for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { + if (child->flag & BONE_CONNECTED) + return false; + } + return true; +} diff --git a/source/blender/collada/collada_utils.h b/source/blender/collada/collada_utils.h index 4bc2f55cf33..7f8e93736b5 100644 --- a/source/blender/collada/collada_utils.h +++ b/source/blender/collada/collada_utils.h @@ -87,7 +87,7 @@ extern void bc_match_scale(Object *ob, UnitConverter &bc_unit, bool scale_to_sce extern void bc_match_scale(std::vector *objects_done, UnitConverter &unit_converter, bool scale_to_scene); extern void bc_triangulate_mesh(Mesh *me); - +extern bool bc_is_leaf_bone(Bone *bone); class BCPolygonNormalsIndices { -- cgit v1.2.3