Collada: Added export Option 'sort by object name' to fix an issue with Second Life import
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ extern "C" {
|
||||
int include_children,
|
||||
|
||||
int use_object_instantiation,
|
||||
int sort_by_name,
|
||||
int second_life);
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user