Collada Importer: Separated finding bone chains and fixing leaf bone orientations into 2 functions and added a separated import option
This commit is contained in:
@@ -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)
|
* 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
|
* 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 */
|
/* armature has no bones */
|
||||||
if (bone == NULL)
|
if (bone == NULL)
|
||||||
@@ -220,8 +220,9 @@ void ArmatureImporter::fix_bone_orientation(bArmature *armature, Bone *bone)
|
|||||||
float leaf_length = (leaf_bone_length == FLT_MAX) ? 1.0 : leaf_bone_length;
|
float leaf_length = (leaf_bone_length == FLT_MAX) ? 1.0 : leaf_bone_length;
|
||||||
|
|
||||||
EditBone *ebone = get_edit_bone(armature, bone->name);
|
EditBone *ebone = get_edit_bone(armature, bone->name);
|
||||||
|
|
||||||
float vec[3];
|
float vec[3];
|
||||||
|
|
||||||
|
if (this->import_settings->fix_orientation) {
|
||||||
if (ebone->parent != NULL) {
|
if (ebone->parent != NULL) {
|
||||||
EditBone *parent = ebone->parent;
|
EditBone *parent = ebone->parent;
|
||||||
sub_v3_v3v3(vec, ebone->head, parent->tail);
|
sub_v3_v3v3(vec, ebone->head, parent->tail);
|
||||||
@@ -234,13 +235,18 @@ void ArmatureImporter::fix_bone_orientation(bArmature *armature, Bone *bone)
|
|||||||
vec[2] = 0.1f;
|
vec[2] = 0.1f;
|
||||||
sub_v3_v3v3(vec, ebone->tail, ebone->head);
|
sub_v3_v3v3(vec, ebone->tail, ebone->head);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sub_v3_v3v3(vec, ebone->tail, ebone->head);
|
||||||
|
}
|
||||||
|
|
||||||
normalize_v3_v3(vec, vec);
|
normalize_v3_v3(vec, vec);
|
||||||
mul_v3_fl(vec, leaf_length);
|
mul_v3_fl(vec, leaf_length);
|
||||||
add_v3_v3v3(ebone->tail, ebone->head, vec);
|
add_v3_v3v3(ebone->tail, ebone->head, vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
|
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);
|
ED_armature_to_edit(armature);
|
||||||
|
|
||||||
connect_bone_chains(armature, (Bone *)armature->bonebase.first, UNLIMITED_CHAIN_MAX);
|
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
|
// exit armature edit mode
|
||||||
unskinned_armature_map[(*ri)->getUniqueId()] = ob_arm;
|
unskinned_armature_map[(*ri)->getUniqueId()] = ob_arm;
|
||||||
@@ -584,7 +590,7 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin)
|
|||||||
ED_armature_to_edit(armature);
|
ED_armature_to_edit(armature);
|
||||||
|
|
||||||
connect_bone_chains(armature, (Bone *)armature->bonebase.first, UNLIMITED_CHAIN_MAX);
|
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
|
// exit armature edit mode
|
||||||
ED_armature_from_edit(armature);
|
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
|
* 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()
|
* and ArmatureImporter::connect_bone_chains()
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ private:
|
|||||||
BoneExtended &add_bone_extended(EditBone *bone, COLLADAFW::Node * node);
|
BoneExtended &add_bone_extended(EditBone *bone, COLLADAFW::Node * node);
|
||||||
void clear_extended_boneset();
|
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 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]);
|
void set_pose( Object *ob_arm, COLLADAFW::Node *root_node, const char *parentname, float parent_mat[4][4]);
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ struct ImportSettings {
|
|||||||
public:
|
public:
|
||||||
bool import_units;
|
bool import_units;
|
||||||
bool find_chains;
|
bool find_chains;
|
||||||
|
bool fix_orientation;
|
||||||
int min_chain_length;
|
int min_chain_length;
|
||||||
char *filepath;
|
char *filepath;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -46,14 +46,15 @@ int collada_import(bContext *C,
|
|||||||
const char *filepath,
|
const char *filepath,
|
||||||
int import_units,
|
int import_units,
|
||||||
int find_chains,
|
int find_chains,
|
||||||
|
int fix_orientation,
|
||||||
int min_chain_length)
|
int min_chain_length)
|
||||||
{
|
{
|
||||||
|
|
||||||
ImportSettings import_settings;
|
ImportSettings import_settings;
|
||||||
import_settings.filepath = (char *)filepath;
|
import_settings.filepath = (char *)filepath;
|
||||||
|
|
||||||
import_settings.import_units = import_units != 0;
|
import_settings.import_units = import_units != 0;
|
||||||
import_settings.find_chains = find_chains != 0;
|
import_settings.find_chains = find_chains != 0;
|
||||||
|
import_settings.fix_orientation = fix_orientation != 0;
|
||||||
import_settings.min_chain_length = min_chain_length;
|
import_settings.min_chain_length = min_chain_length;
|
||||||
|
|
||||||
DocumentImporter imp(C, &import_settings);
|
DocumentImporter imp(C, &import_settings);
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ int collada_import(struct bContext *C,
|
|||||||
const char *filepath,
|
const char *filepath,
|
||||||
int import_units,
|
int import_units,
|
||||||
int find_chains,
|
int find_chains,
|
||||||
|
int fix_orientation,
|
||||||
int min_chain_length);
|
int min_chain_length);
|
||||||
|
|
||||||
int collada_export(struct Scene *sce,
|
int collada_export(struct Scene *sce,
|
||||||
|
|||||||
@@ -366,6 +366,7 @@ static int wm_collada_import_exec(bContext *C, wmOperator *op)
|
|||||||
char filename[FILE_MAX];
|
char filename[FILE_MAX];
|
||||||
int import_units;
|
int import_units;
|
||||||
int find_chains;
|
int find_chains;
|
||||||
|
int fix_orientation;
|
||||||
int min_chain_length;
|
int min_chain_length;
|
||||||
|
|
||||||
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
|
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 */
|
/* Options panel */
|
||||||
import_units = RNA_boolean_get(op->ptr, "import_units");
|
import_units = RNA_boolean_get(op->ptr, "import_units");
|
||||||
find_chains = RNA_boolean_get(op->ptr, "find_chains");
|
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");
|
min_chain_length = RNA_int_get(op->ptr, "min_chain_length");
|
||||||
|
|
||||||
RNA_string_get(op->ptr, "filepath", filename);
|
RNA_string_get(op->ptr, "filepath", filename);
|
||||||
if (collada_import(C, filename,
|
if (collada_import(C, filename,
|
||||||
import_units,
|
import_units,
|
||||||
find_chains,
|
find_chains,
|
||||||
|
fix_orientation,
|
||||||
min_chain_length)) {
|
min_chain_length)) {
|
||||||
return OPERATOR_FINISHED;
|
return OPERATOR_FINISHED;
|
||||||
}
|
}
|
||||||
@@ -407,12 +410,14 @@ static void uiCollada_importSettings(uiLayout *layout, PointerRNA *imfptr)
|
|||||||
row = uiLayoutRow(box, false);
|
row = uiLayoutRow(box, false);
|
||||||
uiItemL(row, IFACE_("Armature Options:"), ICON_MESH_DATA);
|
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);
|
row = uiLayoutRow(box, false);
|
||||||
uiItemR(row, imfptr, "find_chains", 0, NULL, ICON_NONE);
|
uiItemR(row, imfptr, "find_chains", 0, NULL, ICON_NONE);
|
||||||
|
|
||||||
row = uiLayoutRow(box, false);
|
row = uiLayoutRow(box, false);
|
||||||
uiItemR(row, imfptr, "min_chain_length", 0, NULL, ICON_NONE);
|
uiItemR(row, imfptr, "min_chain_length", 0, NULL, ICON_NONE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wm_collada_import_draw(bContext *UNUSED(C), wmOperator *op)
|
static void wm_collada_import_draw(bContext *UNUSED(C), wmOperator *op)
|
||||||
@@ -445,6 +450,10 @@ void WM_OT_collada_import(wmOperatorType *ot)
|
|||||||
"If disabled match import to Blender's current Unit settings, "
|
"If disabled match import to Blender's current Unit settings, "
|
||||||
"otherwise use the settings from the Imported scene");
|
"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,
|
RNA_def_boolean(ot->srna,
|
||||||
"find_chains", 0, "Find Bone Chains",
|
"find_chains", 0, "Find Bone Chains",
|
||||||
"Find best matching Bone Chains and ensure bones in chain are connected");
|
"Find best matching Bone Chains and ensure bones in chain are connected");
|
||||||
|
|||||||
Reference in New Issue
Block a user