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>2014-12-01 22:31:42 +0300
committerGaia Clary <gaia.clary@machinimatrix.org>2014-12-01 22:31:59 +0300
commite35b4bac0a2c537cd076c0ba92d443bc4e576da9 (patch)
tree95537089a74978febe15778765bd05dd4cfa87ec
parent670f5deda62b35e8ed6e91f732052da775eb09f3 (diff)
Collada Importer: Separated finding bone chains and fixing leaf bone orientations into 2 functions and added a separated import option
-rw-r--r--source/blender/collada/ArmatureImporter.cpp32
-rw-r--r--source/blender/collada/ArmatureImporter.h2
-rw-r--r--source/blender/collada/ImportSettings.h1
-rw-r--r--source/blender/collada/collada.cpp9
-rw-r--r--source/blender/collada/collada.h1
-rw-r--r--source/blender/editors/io/io_collada.c11
6 files changed, 37 insertions, 19 deletions
diff --git a/source/blender/collada/ArmatureImporter.cpp b/source/blender/collada/ArmatureImporter.cpp
index db24bf6d0cf..bdfb7021370 100644
--- a/source/blender/collada/ArmatureImporter.cpp
+++ b/source/blender/collada/ArmatureImporter.cpp
@@ -208,7 +208,7 @@ int ArmatureImporter::create_bone(SkinInfo *skin, COLLADAFW::Node *node, EditBon
* tail locations for the affected bones (nodes which don't have any connected child)
* Hint: The extended_bones set gets populated in ArmatureImporter::create_bone
**/
-void ArmatureImporter::fix_bone_orientation(bArmature *armature, Bone *bone)
+void ArmatureImporter::fix_leaf_bones(bArmature *armature, Bone *bone)
{
/* armature has no bones */
if (bone == NULL)
@@ -220,27 +220,33 @@ void ArmatureImporter::fix_bone_orientation(bArmature *armature, Bone *bone)
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->tail);
- if (len_squared_v3(vec) < MINIMUM_BONE_LENGTH)
- {
- sub_v3_v3v3(vec, parent->tail, parent->head);
+
+ if (this->import_settings->fix_orientation) {
+ if (ebone->parent != NULL) {
+ EditBone *parent = ebone->parent;
+ sub_v3_v3v3(vec, ebone->head, parent->tail);
+ 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);
}
for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
- fix_bone_orientation(armature, child);
+ fix_leaf_bones(armature, child);
}
}
@@ -447,7 +453,7 @@ void ArmatureImporter::create_armature_bones( )
ED_armature_to_edit(armature);
connect_bone_chains(armature, (Bone *)armature->bonebase.first, UNLIMITED_CHAIN_MAX);
- fix_bone_orientation(armature, (Bone *)armature->bonebase.first);
+ fix_leaf_bones(armature, (Bone *)armature->bonebase.first);
// exit armature edit mode
unskinned_armature_map[(*ri)->getUniqueId()] = ob_arm;
@@ -584,7 +590,7 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin)
ED_armature_to_edit(armature);
connect_bone_chains(armature, (Bone *)armature->bonebase.first, UNLIMITED_CHAIN_MAX);
- fix_bone_orientation(armature, (Bone *)armature->bonebase.first);
+ fix_leaf_bones(armature, (Bone *)armature->bonebase.first);
// exit armature edit mode
ED_armature_from_edit(armature);
@@ -886,7 +892,7 @@ bool ArmatureImporter::get_joint_bind_mat(float m[4][4], COLLADAFW::Node *joint)
/**
* BoneExtended is a helper class needed for the Bone chain finder
- * See ArmatureImporter::fix_bone_orientation()
+ * See ArmatureImporter::fix_leaf_bones()
* and ArmatureImporter::connect_bone_chains()
**/
diff --git a/source/blender/collada/ArmatureImporter.h b/source/blender/collada/ArmatureImporter.h
index e09906e6c92..732fda80ff1 100644
--- a/source/blender/collada/ArmatureImporter.h
+++ b/source/blender/collada/ArmatureImporter.h
@@ -130,7 +130,7 @@ private:
BoneExtended &add_bone_extended(EditBone *bone, COLLADAFW::Node * node);
void clear_extended_boneset();
- void fix_bone_orientation(bArmature *armature, Bone *bone);
+ void fix_leaf_bones(bArmature *armature, Bone *bone);
void connect_bone_chains(bArmature *armature, Bone *bone, const int max_chain_length);
void set_pose( Object *ob_arm, COLLADAFW::Node *root_node, const char *parentname, float parent_mat[4][4]);
diff --git a/source/blender/collada/ImportSettings.h b/source/blender/collada/ImportSettings.h
index f2185b13c50..51a13da7724 100644
--- a/source/blender/collada/ImportSettings.h
+++ b/source/blender/collada/ImportSettings.h
@@ -33,6 +33,7 @@ struct ImportSettings {
public:
bool import_units;
bool find_chains;
+ bool fix_orientation;
int min_chain_length;
char *filepath;
};
diff --git a/source/blender/collada/collada.cpp b/source/blender/collada/collada.cpp
index 826d634b8f1..f1d5f1a208a 100644
--- a/source/blender/collada/collada.cpp
+++ b/source/blender/collada/collada.cpp
@@ -46,14 +46,15 @@ int collada_import(bContext *C,
const char *filepath,
int import_units,
int find_chains,
+ int fix_orientation,
int min_chain_length)
{
ImportSettings import_settings;
- import_settings.filepath = (char *)filepath;
-
- import_settings.import_units = import_units != 0;
- import_settings.find_chains = find_chains != 0;
+ import_settings.filepath = (char *)filepath;
+ import_settings.import_units = import_units != 0;
+ import_settings.find_chains = find_chains != 0;
+ import_settings.fix_orientation = fix_orientation != 0;
import_settings.min_chain_length = min_chain_length;
DocumentImporter imp(C, &import_settings);
diff --git a/source/blender/collada/collada.h b/source/blender/collada/collada.h
index 0a2713b1db5..6819a62fdf0 100644
--- a/source/blender/collada/collada.h
+++ b/source/blender/collada/collada.h
@@ -57,6 +57,7 @@ int collada_import(struct bContext *C,
const char *filepath,
int import_units,
int find_chains,
+ int fix_orientation,
int min_chain_length);
int collada_export(struct Scene *sce,
diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c
index b45f3ccde2a..b4b892963fa 100644
--- a/source/blender/editors/io/io_collada.c
+++ b/source/blender/editors/io/io_collada.c
@@ -366,6 +366,7 @@ static int wm_collada_import_exec(bContext *C, wmOperator *op)
char filename[FILE_MAX];
int import_units;
int find_chains;
+ int fix_orientation;
int min_chain_length;
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
@@ -376,12 +377,14 @@ static int wm_collada_import_exec(bContext *C, wmOperator *op)
/* Options panel */
import_units = RNA_boolean_get(op->ptr, "import_units");
find_chains = RNA_boolean_get(op->ptr, "find_chains");
+ fix_orientation = RNA_boolean_get(op->ptr, "fix_orientation");
min_chain_length = RNA_int_get(op->ptr, "min_chain_length");
RNA_string_get(op->ptr, "filepath", filename);
if (collada_import(C, filename,
import_units,
find_chains,
+ fix_orientation,
min_chain_length)) {
return OPERATOR_FINISHED;
}
@@ -408,11 +411,13 @@ static void uiCollada_importSettings(uiLayout *layout, PointerRNA *imfptr)
uiItemL(row, IFACE_("Armature Options:"), ICON_MESH_DATA);
row = uiLayoutRow(box, false);
+ uiItemR(row, imfptr, "fix_orientation", 0, NULL, ICON_NONE);
+
+ row = uiLayoutRow(box, false);
uiItemR(row, imfptr, "find_chains", 0, NULL, ICON_NONE);
row = uiLayoutRow(box, false);
uiItemR(row, imfptr, "min_chain_length", 0, NULL, ICON_NONE);
-
}
static void wm_collada_import_draw(bContext *UNUSED(C), wmOperator *op)
@@ -446,6 +451,10 @@ void WM_OT_collada_import(wmOperatorType *ot)
"otherwise use the settings from the Imported scene");
RNA_def_boolean(ot->srna,
+ "fix_orientation", 0, "Fix Leaf Bones",
+ "Fix Orientation of Leaf Bones (Collada does only support Joints)");
+
+ RNA_def_boolean(ot->srna,
"find_chains", 0, "Find Bone Chains",
"Find best matching Bone Chains and ensure bones in chain are connected");