Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaia Clary <gaia.clary@machinimatrix.org>2016-05-26 19:22:36 +0300
committerGaia Clary <gaia.clary@machinimatrix.org>2016-05-26 19:22:36 +0300
commit1346482d23f167fa57049128384246397fda8d27 (patch)
tree89addd5cd73c1edd47cde5022ce8724421998964 /source/blender/collada
parent29aa13cfa284182ee47818a477a3b8b7297a12c8 (diff)
moved is_leaf_bone() to collada utils for reuse in exporter and importer
Diffstat (limited to 'source/blender/collada')
-rw-r--r--source/blender/collada/ArmatureExporter.cpp12
-rw-r--r--source/blender/collada/ArmatureImporter.cpp63
-rw-r--r--source/blender/collada/ArmatureImporter.h2
-rw-r--r--source/blender/collada/collada_utils.cpp12
-rw-r--r--source/blender/collada/collada_utils.h2
5 files changed, 47 insertions, 44 deletions
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<Object *> *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
{