Collada: Added export Option 'sort by object name' to fix an issue with Second Life...
authorGaia Clary <gaia.clary@machinimatrix.org>
Thu, 14 Jun 2012 10:38:39 +0000 (10:38 +0000)
committerGaia Clary <gaia.clary@machinimatrix.org>
Thu, 14 Jun 2012 10:38:39 +0000 (10:38 +0000)
source/blender/collada/ExportSettings.h
source/blender/collada/collada.cpp
source/blender/collada/collada.h
source/blender/collada/collada_utils.cpp
source/blender/collada/collada_utils.h
source/blender/makesrna/intern/rna_scene_api.c
source/blender/windowmanager/intern/wm_operators.c

index 97ea687385630df6d1d21b2343c5db456edd17a4..e856eefab9926954c0ef2cf7c9adad4436ac61c7 100644 (file)
@@ -39,6 +39,7 @@ struct ExportSettings
  bool include_armatures;
  bool include_children;
  bool use_object_instantiation;
+ bool sort_by_name;
  bool second_life;
  char *filepath;
  LinkNode *export_set;
index bc03bdc970c429347676f5ab8e1c76a8a53b81b9..9a4fd44b9e95b28789e67e99acea39417581bae2 100644 (file)
@@ -59,6 +59,7 @@ int collada_export(
     int include_children,
 
     int use_object_instantiation,
+       int sort_by_name,
     int second_life)
 {
        ExportSettings export_settings;
@@ -79,6 +80,7 @@ int collada_export(
        export_settings.include_children         = include_children != 0;
        export_settings.second_life              = second_life != 0;
        export_settings.use_object_instantiation = use_object_instantiation != 0;
+       export_settings.sort_by_name             = sort_by_name != 0;
        export_settings.filepath                 = (char *)filepath;
 
        int includeFilter = OB_REL_NONE;
@@ -88,6 +90,9 @@ int collada_export(
        eObjectSet objectSet = (export_settings.selected) ? OB_SET_SELECTED : OB_SET_ALL;
        export_settings.export_set = BKE_object_relational_superset(sce, objectSet, (eObRelationTypes)includeFilter);
 
+       if (export_settings.sort_by_name)
+               bc_bubble_sort_by_Object_name(export_settings.export_set);
+
        DocumentExporter exporter(&export_settings);
        exporter.exportCurrentScene(sce);
 
index da2179ca13534ac84cc52deca7ccfbbc4d105fd0..8daf2b65fe23da3a368f1ea1b6c4faafc90190b6 100644 (file)
@@ -47,6 +47,7 @@ extern "C" {
                int include_children,
 
                int use_object_instantiation,
+               int sort_by_name,
                int second_life);
 
 
index f481de994a34d3f520259016ac969e8e78231530..3d9aa8e542d6182d7b867ceca94717cf70808c52 100644 (file)
@@ -226,3 +226,31 @@ void bc_remove_mark(Object *ob)
 {
        ob->id.flag &= ~LIB_DOIT;
 }
+
+// Use bubble sort algorithm for sorting the export set
+void bc_bubble_sort_by_Object_name(LinkNode *export_set)
+{
+       int i, j; // loop indices
+       bool unsorted = true;
+
+       LinkNode *current;
+       int set_size = BLI_linklist_length(export_set);
+       for(i = 0; (i < set_size) && unsorted; i++) {
+               unsorted = false;
+               
+               for (current=export_set; current->next; current = current->next) {
+                       Object *a = (Object *)current->link;
+                       Object *b = (Object *)current->next->link;
+
+                       std::string str_a (a->id.name);
+                       std::string str_b (b->id.name);
+
+                       if (str_a.compare(str_b) > 0) {
+                               current->link       = b;
+                               current->next->link = a;
+                               unsorted = true;
+                       }
+                       
+               }
+       }
+}
\ No newline at end of file
index 71365ffb8d0d0345d05d9541f204116655d87e12..139a2cb93bd6ee1f2fe6165e2ca9aacce6677131 100644 (file)
@@ -71,4 +71,6 @@ extern void bc_remove_mark(Object *ob);
 extern char *bc_CustomData_get_layer_name(const CustomData *data, int type, int n);
 extern char *bc_CustomData_get_active_layer_name(const CustomData *data, int type);
 
+extern void bc_bubble_sort_by_Object_name(LinkNode *export_set);
+
 #endif
index 76fe5a656b690e95153c7d81b5b72619d30c0252..76366efe0d100bffae098a6cb4f6027548c02f93 100644 (file)
@@ -93,11 +93,12 @@ static void rna_Scene_collada_export(
     int include_armatures,
     int include_children,
     int use_object_instantiation,
+       int sort_by_name,
     int second_life)
 {
        collada_export(scene, filepath, selected, apply_modifiers, 
                       include_armatures, include_children,
-                      use_object_instantiation, second_life);
+                      use_object_instantiation, sort_by_name, second_life);
 }
 
 #endif
@@ -130,6 +131,7 @@ void RNA_api_scene(StructRNA *srna)
        parm = RNA_def_boolean(func, "include_armatures", 0, "Include Armatures", "Include armature(s) used by the exported objects");
        parm = RNA_def_boolean(func, "include_children", 0, "Include Children", "Include all children even if not selected");
        parm = RNA_def_boolean(func, "use_object_instantiation", 1, "Use Object Instantiation", "Instantiate multiple Objects from same Data");
+       parm = RNA_def_boolean(func, "sort_by_name", 0, "Sort by Object name", "Sort exported data by Object name");
        parm = RNA_def_boolean(func, "second_life", 0, "Export for Second Life", "Compatibility mode for Second Life");
        RNA_def_function_ui_description(func, "Export to collada file");
 #endif
index e16a7befdd56b04acf76ef875b94a08d1f0888d2..b4bec014b9cfffac05a0b9d3ea4ad11842446e54 100644 (file)
@@ -2167,6 +2167,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
        int apply_modifiers;
        int include_children;
        int use_object_instantiation;
+       int sort_by_name;
        
        if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
                BKE_report(op->reports, RPT_ERROR, "No filename given");
@@ -2182,6 +2183,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
        include_armatures        = RNA_boolean_get(op->ptr, "include_armatures");
        include_children         = RNA_boolean_get(op->ptr, "include_children");
        use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation");
+       sort_by_name             = RNA_boolean_get(op->ptr, "sort_by_name");
        second_life              = RNA_boolean_get(op->ptr, "second_life");
 
        /* get editmode results */
@@ -2195,6 +2197,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
                include_armatures,
                include_children,
                use_object_instantiation,
+                       sort_by_name,
                second_life)) {
                return OPERATOR_FINISHED;
        }
@@ -2232,6 +2235,9 @@ static void WM_OT_collada_export(wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "use_object_instantiation", 1, "Use Object Instantiation",
                        "Instantiate multiple Objects from same Data");
 
+       RNA_def_boolean(ot->srna, "sort_by_name", 0, "Sort by Object name",
+                       "Sort exported data by Object name");
+
        RNA_def_boolean(ot->srna, "second_life", 0, "Export for Second Life",
                        "Compatibility mode for Second Life");
 }