Added new option for storing bindpose matrix, see T50412
authorGaia Clary <gaia.clary@machinimatrix.org>
Wed, 22 Mar 2017 23:07:05 +0000 (00:07 +0100)
committerGaia Clary <gaia.clary@machinimatrix.org>
Thu, 23 Mar 2017 13:14:22 +0000 (14:14 +0100)
source/blender/collada/ArmatureImporter.cpp
source/blender/collada/ExportSettings.h
source/blender/collada/ImportSettings.h
source/blender/collada/collada.cpp
source/blender/collada/collada.h
source/blender/editors/io/io_collada.c
source/blender/makesrna/intern/rna_scene_api.c

index 398c4a2c106797d21cd59a574d53969862a87d3f..2e4a7dfebc739fa44db45ffabdf12b4b487840c7 100644 (file)
@@ -93,6 +93,7 @@ int ArmatureImporter::create_bone(SkinInfo *skin, COLLADAFW::Node *node, EditBon
 {
        float mat[4][4];
        float joint_inv_bind_mat[4][4];
+       float joint_bind_mat[4][4];
        int chain_length = 0;
 
        //Checking if bone is already made.
@@ -116,7 +117,7 @@ int ArmatureImporter::create_bone(SkinInfo *skin, COLLADAFW::Node *node, EditBon
 
                        // get original world-space matrix
                        invert_m4_m4(mat, joint_inv_bind_mat);
-
+                       copy_m4_m4(joint_bind_mat, mat);
                        // And make local to armature
                        Object *ob_arm = skin->BKE_armature_from_object();
                        if (ob_arm) {
@@ -165,6 +166,14 @@ int ArmatureImporter::create_bone(SkinInfo *skin, COLLADAFW::Node *node, EditBon
                bone->roll = angle;
        }
        copy_v3_v3(bone->head, mat[3]);
+
+       if (bone_is_skinned)
+       {
+               float rest_mat[4][4];
+               get_node_mat(rest_mat, node, NULL, NULL, NULL);
+               bc_create_bindpose_properties(this->import_settings, bone, joint_bind_mat, rest_mat);
+       }
+
        add_v3_v3v3(bone->tail, bone->head, tail); //tail must be non zero
 
        /* find smallest bone length in armature (used later for leaf bone length) */
@@ -266,7 +275,6 @@ void ArmatureImporter::fix_parent_connect(bArmature *armature, Bone *bone)
 
 }
 
-
 void ArmatureImporter::connect_bone_chains(bArmature *armature, Bone *parentbone, int clip)
 {
        BoneExtensionMap &extended_bones = bone_extension_manager.getExtensionMap(armature);
@@ -302,7 +310,6 @@ void ArmatureImporter::connect_bone_chains(bArmature *armature, Bone *parentbone
                EditBone *pebone = bc_get_edit_bone(armature, parentbone->name);
                EditBone *cebone = bc_get_edit_bone(armature, dominant_child->get_name());
                if (pebone && !(cebone->flag & BONE_CONNECTED)) {
-
                        float vec[3];
                        sub_v3_v3v3(vec, cebone->head, pebone->head);
 
index 9451cac9dae2d410d26094028e81079acf26789e..03e380dc19896b72074a0bdd1f30b9a52f7815c9 100644 (file)
@@ -51,7 +51,9 @@ public:
        bool use_blender_profile;
        bool sort_by_name;
        BC_export_transformation_type export_transformation_type;
+
        bool open_sim;
+       bool keep_bind_info;
 
        char *filepath;
        LinkNode *export_set;
index 2c52d73e756e4fe203b34586bdac7682975877ef..4a2d4e8046a44108549f1ebf075334bab12ba987 100644 (file)
@@ -37,6 +37,7 @@ public:
        bool fix_orientation;
        int  min_chain_length;
        char *filepath;
+       bool keep_bind_info;
 };
 
 #endif
index fe8b1d2320a798e6d8f2a30f24719cf48aa7ceba..c0784ca8eb506a32e3e2515768553c224ac31b9f 100644 (file)
@@ -48,7 +48,8 @@ int collada_import(bContext *C,
                                   int find_chains,
                                   int auto_connect,
                                   int fix_orientation,
-                                  int min_chain_length)
+                                  int min_chain_length,
+                                  int keep_bind_info)
 {
 
        ImportSettings import_settings;
@@ -58,6 +59,7 @@ int collada_import(bContext *C,
        import_settings.find_chains      = find_chains != 0;
        import_settings.fix_orientation  = fix_orientation != 0;
        import_settings.min_chain_length = min_chain_length;
+       import_settings.keep_bind_info = keep_bind_info;
 
        DocumentImporter imp(C, &import_settings);
        if (imp.import()) return 1;
@@ -87,7 +89,9 @@ int collada_export(Scene *sce,
                                   int use_blender_profile,
                                   int sort_by_name,
                                   BC_export_transformation_type export_transformation_type,
-                   int open_sim)
+                                  int open_sim,
+
+                                  int keep_bind_info)
 {
        ExportSettings export_settings;
 
@@ -113,6 +117,7 @@ int collada_export(Scene *sce,
        export_settings.export_transformation_type = export_transformation_type;
        export_settings.open_sim                   = open_sim != 0;
 
+       export_settings.keep_bind_info = keep_bind_info;
 
        int includeFilter = OB_REL_NONE;
        if (export_settings.include_armatures) includeFilter |= OB_REL_MOD_ARMATURE;
index a441660858485da8cc6774a4fb0e7cd393f70cb5..09acc4a064ba5b6a4017531670df73e8e2d26163 100644 (file)
@@ -58,7 +58,9 @@ int collada_import(struct bContext *C,
                                   int find_chains,
                                   int auto_connect,
                                   int fix_orientation,
-                                  int min_chain_length);
+                                  int min_chain_length,
+
+                                  int keep_bind_info);
 
 int collada_export(struct Scene *sce,
                    const char *filepath,
@@ -81,9 +83,9 @@ int collada_export(struct Scene *sce,
                    int use_blender_profile,
                    int sort_by_name,
                    BC_export_transformation_type export_transformation_type,
-                   int open_sim);
-
 
+                                  int open_sim,
+                                  int keep_bind_info);
 
 #ifdef __cplusplus
 }
index 0e185cd93a7105e7000a26b26442a8159030807d..9b12aa6d475c965e742c4c39689ac431c78cb8ce 100644 (file)
@@ -97,7 +97,9 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
        int use_blender_profile;
        int sort_by_name;
        int export_transformation_type;
+
        int open_sim;
+       int keep_bind_info;
 
        int export_count;
 
@@ -148,6 +150,8 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
        export_transformation_type = RNA_enum_get(op->ptr,    "export_transformation_type_selection");
        open_sim                   = RNA_boolean_get(op->ptr, "open_sim");
 
+       keep_bind_info = RNA_boolean_get(op->ptr, "keep_bind_info");
+
        /* get editmode results */
        ED_object_editmode_load(CTX_data_edit_object(C));
 
@@ -172,7 +176,10 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
                use_blender_profile,
                sort_by_name,
                export_transformation_type,
-               open_sim);
+
+               open_sim,
+               keep_bind_info
+       );
 
        if (export_count == 0) {
                BKE_report(op->reports, RPT_WARNING, "No objects selected -- Created empty export file");
@@ -269,6 +276,8 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
 
        row = uiLayoutRow(box, false);
        uiItemR(row, imfptr, "sort_by_name", 0, NULL, ICON_NONE);
+       row = uiLayoutRow(box, false);
+       uiItemR(row, imfptr, "keep_bind_info", 0, NULL, ICON_NONE);
 
 }
 
@@ -386,6 +395,10 @@ void WM_OT_collada_export(wmOperatorType *ot)
 
        RNA_def_boolean(func, "open_sim", 0, "Export to SL/OpenSim",
                        "Compatibility mode for SL, OpenSim and other compatible online worlds");
+
+       RNA_def_boolean(func, "keep_bind_info", 0,
+               "Keep Bind Info", "Store Bindpose information in custom bone properties for later use during Collada export");
+
 }
 
 
@@ -397,7 +410,9 @@ static int wm_collada_import_exec(bContext *C, wmOperator *op)
        int find_chains;
        int auto_connect;
        int fix_orientation;
-       int  min_chain_length;
+       int min_chain_length;
+
+       int keep_bind_info;
 
        if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
                BKE_report(op->reports, RPT_ERROR, "No filename given");
@@ -409,6 +424,9 @@ static int wm_collada_import_exec(bContext *C, wmOperator *op)
        find_chains      = RNA_boolean_get(op->ptr, "find_chains");
        auto_connect     = RNA_boolean_get(op->ptr, "auto_connect");
        fix_orientation  = RNA_boolean_get(op->ptr, "fix_orientation");
+
+       keep_bind_info = RNA_boolean_get(op->ptr, "keep_bind_info");
+
        min_chain_length = RNA_int_get(op->ptr, "min_chain_length");
 
        RNA_string_get(op->ptr, "filepath", filename);
@@ -418,7 +436,8 @@ static int wm_collada_import_exec(bContext *C, wmOperator *op)
                find_chains,
                auto_connect,
                fix_orientation,
-               min_chain_length))
+               min_chain_length,
+                       keep_bind_info) )
        {
                return OPERATOR_FINISHED;
        }
@@ -455,6 +474,13 @@ static void uiCollada_importSettings(uiLayout *layout, PointerRNA *imfptr)
 
        row = uiLayoutRow(box, false);
        uiItemR(row, imfptr, "min_chain_length", 0, NULL, ICON_NONE);
+
+       box = uiLayoutBox(layout);
+       row = uiLayoutRow(box, false);
+
+       row = uiLayoutRow(box, false);
+       uiItemR(row, imfptr, "keep_bind_info", 0, NULL, ICON_NONE);
+
 }
 
 static void wm_collada_import_draw(bContext *UNUSED(C), wmOperator *op)
@@ -510,5 +536,9 @@ void WM_OT_collada_import(wmOperatorType *ot)
                0,
                INT_MAX);
 
+       RNA_def_boolean(ot->srna, 
+               "keep_bind_info", 0, "Keep Bind Info", 
+               "Store Bindpose information in custom bone properties for later use during Collada export");
+
 }
 #endif
index d4d8e23fdf575cf77ffafd20b40fdd9532520366..d1ecd912773db20e7bd91898b197ea2ca0257bc2 100644 (file)
@@ -284,32 +284,34 @@ static void rna_Scene_collada_export(
         int use_blender_profile,
         int sort_by_name,
         int export_transformation_type,
-        int open_sim)
+        int open_sim,
+        int keep_bind_info)
 {
-    collada_export(scene,
-        filepath,
-
-        apply_modifiers,
-        export_mesh_type,
-
-        selected,
-        include_children,
-        include_armatures,
-        include_shapekeys,
-        deform_bones_only,
-
-        active_uv_only,
-        include_uv_textures,
-        include_material_textures,
-        use_texture_copies,
-
-        triangulate,
-        use_object_instantiation,
-        use_blender_profile,
-        sort_by_name,
-
-        export_transformation_type,
-        open_sim);
+       collada_export(scene,
+               filepath,
+
+               apply_modifiers,
+               export_mesh_type,
+
+               selected,
+               include_children,
+               include_armatures,
+               include_shapekeys,
+               deform_bones_only,
+
+               active_uv_only,
+               include_uv_textures,
+               include_material_textures,
+               use_texture_copies,
+
+               triangulate,
+               use_object_instantiation,
+               use_blender_profile,
+               sort_by_name,
+
+               export_transformation_type,
+               open_sim,
+               keep_bind_info);
 }
 
 #endif
@@ -396,7 +398,6 @@ void RNA_api_scene(StructRNA *srna)
        RNA_def_boolean(func, "deform_bones_only", 0, "Deform Bones only",
                "Only export deforming bones with armatures");
 
-
        RNA_def_boolean(func, "active_uv_only", 0, "Only Selected UV Map",
                "Export only the selected UV Map");
 
@@ -409,7 +410,6 @@ void RNA_api_scene(StructRNA *srna)
        RNA_def_boolean(func, "use_texture_copies", 1, "Copy",
                "Copy textures to same folder where the .dae file is exported");
 
-
        RNA_def_boolean(func, "triangulate", 1, "Triangulate",
                "Export Polygons (Quads & NGons) as Triangles");
 
@@ -427,6 +427,10 @@ void RNA_api_scene(StructRNA *srna)
 
        RNA_def_boolean(func, "open_sim", 0, "Export to SL/OpenSim",
                "Compatibility mode for SL, OpenSim and other compatible online worlds");
+
+    RNA_def_boolean(func, "keep_bind_info", 0,
+               "Keep Bind Info", "Store Bindpose information in custom bone properties for later use during Collada export");
+
 #endif
 
 #ifdef WITH_ALEMBIC