Collada exporter update
[blender.git] / source / blender / editors / io / io_collada.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup collada
22  */
23 #ifdef WITH_COLLADA
24 #  include "DNA_space_types.h"
25
26 #  include "BLT_translation.h"
27
28 #  include "BLI_blenlib.h"
29 #  include "BLI_utildefines.h"
30
31 #  include "BKE_context.h"
32 #  include "BKE_global.h"
33 #  include "BKE_main.h"
34 #  include "BKE_object.h"
35 #  include "BKE_report.h"
36
37 #  include "DEG_depsgraph.h"
38
39 #  include "ED_screen.h"
40 #  include "ED_object.h"
41
42 #  include "RNA_access.h"
43 #  include "RNA_define.h"
44
45 #  include "UI_interface.h"
46 #  include "UI_resources.h"
47
48 #  include "WM_api.h"
49 #  include "WM_types.h"
50
51 #  include "../../collada/collada.h"
52
53 #  include "io_collada.h"
54
55 static int wm_collada_export_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
56 {
57   Main *bmain = CTX_data_main(C);
58
59   if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
60     char filepath[FILE_MAX];
61     const char *blendfile_path = BKE_main_blendfile_path(bmain);
62
63     if (blendfile_path[0] == '\0') {
64       BLI_strncpy(filepath, "untitled", sizeof(filepath));
65     }
66     else {
67       BLI_strncpy(filepath, blendfile_path, sizeof(filepath));
68     }
69
70     BLI_path_extension_replace(filepath, sizeof(filepath), ".dae");
71     RNA_string_set(op->ptr, "filepath", filepath);
72   }
73
74   WM_event_add_fileselect(C, op);
75
76   return OPERATOR_RUNNING_MODAL;
77 }
78
79 /* function used for WM_OT_save_mainfile too */
80 static int wm_collada_export_exec(bContext *C, wmOperator *op)
81 {
82   char filepath[FILE_MAX];
83   int apply_modifiers;
84   int global_forward;
85   int global_up;
86   int apply_global_orientation;
87   int export_mesh_type;
88   int selected;
89   int include_children;
90   int include_armatures;
91   int include_shapekeys;
92   int deform_bones_only;
93
94   int include_animations;
95   int include_all_actions;
96   int sampling_rate;
97   int keep_smooth_curves;
98   int keep_keyframes;
99   int keep_flat_curves;
100
101   int export_animation_type;
102   int use_texture_copies;
103   int active_uv_only;
104
105   int triangulate;
106   int use_object_instantiation;
107   int use_blender_profile;
108   int sort_by_name;
109   int export_transformation_type;
110
111   int open_sim;
112   int limit_precision;
113   int keep_bind_info;
114
115   int export_count;
116   int sample_animations;
117
118   if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
119     BKE_report(op->reports, RPT_ERROR, "No filename given");
120     return OPERATOR_CANCELLED;
121   }
122
123   RNA_string_get(op->ptr, "filepath", filepath);
124   BLI_path_extension_ensure(filepath, sizeof(filepath), ".dae");
125
126   /* Avoid File write exceptions in Collada */
127   if (!BLI_exists(filepath)) {
128     BLI_make_existing_file(filepath);
129     if (!BLI_file_touch(filepath)) {
130       BKE_report(op->reports, RPT_ERROR, "Can't create export file");
131       fprintf(stdout, "Collada export: Can not create: %s\n", filepath);
132       return OPERATOR_CANCELLED;
133     }
134   }
135   else if (!BLI_file_is_writable(filepath)) {
136     BKE_report(op->reports, RPT_ERROR, "Can't overwrite export file");
137     fprintf(stdout, "Collada export: Can not modify: %s\n", filepath);
138     return OPERATOR_CANCELLED;
139   }
140
141   /* Now the exporter can create and write the export file */
142
143   /* Options panel */
144   apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers");
145   export_mesh_type = RNA_enum_get(op->ptr, "export_mesh_type_selection");
146   global_forward = RNA_enum_get(op->ptr, "export_global_forward_selection");
147   global_up = RNA_enum_get(op->ptr, "export_global_up_selection");
148   apply_global_orientation = RNA_boolean_get(op->ptr, "apply_global_orientation");
149
150   selected = RNA_boolean_get(op->ptr, "selected");
151   include_children = RNA_boolean_get(op->ptr, "include_children");
152   include_armatures = RNA_boolean_get(op->ptr, "include_armatures");
153   include_shapekeys = RNA_boolean_get(op->ptr, "include_shapekeys");
154
155   include_animations = RNA_boolean_get(op->ptr, "include_animations");
156   include_all_actions = RNA_boolean_get(op->ptr, "include_all_actions");
157   export_animation_type = RNA_enum_get(op->ptr, "export_animation_type_selection");
158   sample_animations = (export_animation_type == BC_ANIMATION_EXPORT_SAMPLES);
159   sampling_rate = (sample_animations) ? RNA_int_get(op->ptr, "sampling_rate") : 0;
160   keep_smooth_curves = RNA_boolean_get(op->ptr, "keep_smooth_curves");
161   keep_keyframes = RNA_boolean_get(op->ptr, "keep_keyframes");
162   keep_flat_curves = RNA_boolean_get(op->ptr, "keep_flat_curves");
163
164   deform_bones_only = RNA_boolean_get(op->ptr, "deform_bones_only");
165
166   use_texture_copies = RNA_boolean_get(op->ptr, "use_texture_copies");
167   active_uv_only = RNA_boolean_get(op->ptr, "active_uv_only");
168
169   triangulate = RNA_boolean_get(op->ptr, "triangulate");
170   use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation");
171   use_blender_profile = RNA_boolean_get(op->ptr, "use_blender_profile");
172   sort_by_name = RNA_boolean_get(op->ptr, "sort_by_name");
173   export_transformation_type = RNA_enum_get(op->ptr, "export_transformation_type_selection");
174   open_sim = RNA_boolean_get(op->ptr, "open_sim");
175
176   limit_precision = RNA_boolean_get(op->ptr, "limit_precision");
177   keep_bind_info = RNA_boolean_get(op->ptr, "keep_bind_info");
178
179   Main *bmain = CTX_data_main(C);
180
181   /* get editmode results */
182   ED_object_editmode_load(bmain, CTX_data_edit_object(C));
183
184   // Scene *scene = CTX_data_scene(C);
185
186   ExportSettings export_settings;
187
188   export_settings.filepath = filepath;
189
190   export_settings.apply_modifiers = apply_modifiers != 0;
191   export_settings.global_forward = global_forward;
192   export_settings.global_up = global_up;
193   export_settings.apply_global_orientation = apply_global_orientation != 0;
194
195   export_settings.export_mesh_type = export_mesh_type;
196   export_settings.export_mesh_type = export_mesh_type;
197   export_settings.selected = selected != 0;
198   export_settings.include_children = include_children != 0;
199   export_settings.include_armatures = include_armatures != 0;
200   export_settings.include_shapekeys = include_shapekeys != 0;
201   export_settings.deform_bones_only = deform_bones_only != 0;
202   export_settings.include_animations = include_animations != 0;
203   export_settings.include_all_actions = include_all_actions != 0;
204   export_settings.sampling_rate = sampling_rate;
205   export_settings.keep_keyframes = keep_keyframes != 0 || sampling_rate < 1;
206   export_settings.keep_flat_curves = keep_flat_curves != 0;
207
208   export_settings.active_uv_only = active_uv_only != 0;
209   export_settings.export_animation_type = export_animation_type;
210   export_settings.use_texture_copies = use_texture_copies != 0;
211
212   export_settings.triangulate = triangulate != 0;
213   export_settings.use_object_instantiation = use_object_instantiation != 0;
214   export_settings.use_blender_profile = use_blender_profile != 0;
215   export_settings.sort_by_name = sort_by_name != 0;
216
217   if (export_animation_type == BC_ANIMATION_EXPORT_SAMPLES) {
218     export_settings.export_transformation_type = export_transformation_type;
219   }
220   else {
221     // When curves are exported then we can not export as matrix
222     export_settings.export_transformation_type = BC_TRANSFORMATION_TYPE_TRANSROTLOC;
223   }
224
225   if (export_settings.export_transformation_type == BC_TRANSFORMATION_TYPE_TRANSROTLOC) {
226     export_settings.keep_smooth_curves = keep_smooth_curves != 0;
227   }
228   else {
229     // Can not export smooth curves when Matrix export is enabled.
230     export_settings.keep_smooth_curves = false;
231   }
232
233   export_settings.open_sim = open_sim != 0;
234   export_settings.limit_precision = limit_precision != 0;
235   export_settings.keep_bind_info = keep_bind_info != 0;
236
237   int includeFilter = OB_REL_NONE;
238   if (export_settings.include_armatures) {
239     includeFilter |= OB_REL_MOD_ARMATURE;
240   }
241   if (export_settings.include_children) {
242     includeFilter |= OB_REL_CHILDREN_RECURSIVE;
243   }
244
245   export_count = collada_export(C, &export_settings);
246
247   if (export_count == 0) {
248     BKE_report(op->reports, RPT_WARNING, "No objects selected -- Created empty export file");
249     return OPERATOR_CANCELLED;
250   }
251   else if (export_count < 0) {
252     BKE_report(op->reports, RPT_WARNING, "Error during export (see Console)");
253     return OPERATOR_CANCELLED;
254   }
255   else {
256     char buff[100];
257     sprintf(buff, "Exported %d Objects", export_count);
258     BKE_report(op->reports, RPT_INFO, buff);
259     return OPERATOR_FINISHED;
260   }
261 }
262
263 static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
264 {
265   uiLayout *bbox, *box, *row, *col, *split;
266   bool include_animations = RNA_boolean_get(imfptr, "include_animations");
267   int ui_section = RNA_enum_get(imfptr, "prop_bc_export_ui_section");
268
269   BC_export_animation_type animation_type = RNA_enum_get(imfptr,
270                                                          "export_animation_type_selection");
271   BC_export_transformation_type transformation_type = RNA_enum_get(
272       imfptr, "export_transformation_type_selection");
273
274   bool sampling = animation_type == BC_ANIMATION_EXPORT_SAMPLES;
275
276   /* Export Options: */
277   box = uiLayoutBox(layout);
278
279   row = uiLayoutRow(box, false);
280   uiItemR(row, imfptr, "prop_bc_export_ui_section", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
281
282   if (ui_section == BC_UI_SECTION_MAIN) {
283     /* =================== */
284     /* Export Data options */
285     /* =================== */
286
287     bbox = uiLayoutBox(layout);
288     row = uiLayoutRow(bbox, false);
289     uiItemL(row, IFACE_("Global Orientation:"), ICON_ORIENTATION_GLOBAL);
290     row = uiLayoutRow(bbox, false);
291     uiItemR(row, imfptr, "export_global_forward_selection", 0, "", ICON_NONE);
292
293     row = uiLayoutRow(bbox, false);
294     uiItemR(row, imfptr, "export_global_up_selection", 0, "", ICON_NONE);
295
296     row = uiLayoutRow(bbox, false);
297     uiItemR(row, imfptr, "apply_global_orientation", 0, NULL, ICON_NONE);
298
299     row = uiLayoutRow(box, false);
300     uiItemR(row, imfptr, "selected", 0, NULL, ICON_NONE);
301
302     row = uiLayoutRow(box, false);
303     uiItemR(row, imfptr, "include_children", 0, NULL, ICON_NONE);
304     uiLayoutSetEnabled(row, RNA_boolean_get(imfptr, "selected"));
305
306     row = uiLayoutRow(box, false);
307     uiItemR(row, imfptr, "include_armatures", 0, NULL, ICON_NONE);
308     uiLayoutSetEnabled(row, RNA_boolean_get(imfptr, "selected"));
309
310     row = uiLayoutRow(box, false);
311     uiItemR(row, imfptr, "include_shapekeys", 0, NULL, ICON_NONE);
312     uiLayoutSetEnabled(row, RNA_boolean_get(imfptr, "selected"));
313
314     row = uiLayoutRow(box, false);
315
316     /* Texture options */
317     box = uiLayoutBox(layout);
318     row = uiLayoutRow(box, false);
319     uiItemL(row, IFACE_("Texture Options:"), ICON_TEXTURE_DATA);
320
321     row = uiLayoutRow(box, false);
322     uiItemR(row, imfptr, "active_uv_only", 0, NULL, ICON_NONE);
323
324     row = uiLayoutRow(box, false);
325     uiItemR(row, imfptr, "use_texture_copies", 1, NULL, ICON_NONE);
326   }
327   else if (ui_section == BC_UI_SECTION_GEOMETRY) {
328     row = uiLayoutRow(box, false);
329     uiItemL(row, IFACE_("Export Data Options:"), ICON_MESH_DATA);
330
331     row = uiLayoutRow(box, false);
332     split = uiLayoutSplit(row, 0.6f, UI_LAYOUT_ALIGN_RIGHT);
333     col = uiLayoutColumn(split, false);
334     uiItemR(col, imfptr, "apply_modifiers", 0, NULL, ICON_NONE);
335     col = uiLayoutColumn(split, false);
336     uiItemR(col, imfptr, "export_mesh_type_selection", 0, "", ICON_NONE);
337     uiLayoutSetEnabled(col, RNA_boolean_get(imfptr, "apply_modifiers"));
338     row = uiLayoutRow(box, false);
339     uiItemR(row, imfptr, "triangulate", 1, NULL, ICON_NONE);
340   }
341   else if (ui_section == BC_UI_SECTION_ARMATURE) {
342     /* Armature options */
343     box = uiLayoutBox(layout);
344     row = uiLayoutRow(box, false);
345     uiItemL(row, IFACE_("Armature Options:"), ICON_ARMATURE_DATA);
346
347     row = uiLayoutRow(box, false);
348     uiItemR(row, imfptr, "deform_bones_only", 0, NULL, ICON_NONE);
349
350     row = uiLayoutRow(box, false);
351     uiItemR(row, imfptr, "open_sim", 0, NULL, ICON_NONE);
352   }
353   else if (ui_section == BC_UI_SECTION_ANIMATION) {
354
355     /* ====================== */
356     /* Animation Data options */
357     /* ====================== */
358
359     row = uiLayoutRow(box, false);
360     uiItemR(row, imfptr, "include_animations", 0, NULL, ICON_NONE);
361
362     row = uiLayoutRow(box, false);
363     uiItemR(row, imfptr, "export_animation_type_selection", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
364
365     row = uiLayoutRow(box, false);
366     split = uiLayoutSplit(row, 0.6f, UI_LAYOUT_ALIGN_RIGHT);
367     uiItemL(split, IFACE_("Transformation Type"), ICON_NONE);
368     uiItemR(split, imfptr, "export_transformation_type_selection", 0, "", ICON_NONE);
369     uiLayoutSetEnabled(row, animation_type == BC_ANIMATION_EXPORT_SAMPLES);
370
371     row = uiLayoutColumn(box, false);
372     uiItemR(row, imfptr, "keep_smooth_curves", 0, NULL, ICON_NONE);
373     uiLayoutSetEnabled(row,
374                        include_animations &&
375                            (transformation_type == BC_TRANSFORMATION_TYPE_TRANSROTLOC ||
376                             animation_type == BC_ANIMATION_EXPORT_KEYS));
377
378     row = uiLayoutColumn(box, false);
379     uiItemR(row, imfptr, "sampling_rate", 0, NULL, ICON_NONE);
380     uiLayoutSetEnabled(row, sampling && include_animations);
381
382     row = uiLayoutColumn(box, false);
383     uiItemR(row, imfptr, "keep_keyframes", 0, NULL, ICON_NONE);
384     uiLayoutSetEnabled(row, sampling && include_animations);
385
386     row = uiLayoutColumn(box, false);
387     uiItemR(row, imfptr, "keep_flat_curves", 0, NULL, ICON_NONE);
388
389     row = uiLayoutRow(box, false);
390     uiItemR(row, imfptr, "include_all_actions", 0, NULL, ICON_NONE);
391     uiLayoutSetEnabled(row, include_animations);
392   }
393   else if (ui_section == BC_UI_SECTION_COLLADA) {
394     /* Collada options: */
395     box = uiLayoutBox(layout);
396     row = uiLayoutRow(box, false);
397     uiItemL(row, IFACE_("Collada Options:"), ICON_MODIFIER);
398
399     row = uiLayoutRow(box, false);
400     uiItemR(row, imfptr, "use_object_instantiation", 1, NULL, ICON_NONE);
401     row = uiLayoutRow(box, false);
402     uiItemR(row, imfptr, "use_blender_profile", 1, NULL, ICON_NONE);
403
404     row = uiLayoutRow(box, false);
405     uiItemR(row, imfptr, "sort_by_name", 0, NULL, ICON_NONE);
406
407     row = uiLayoutRow(box, false);
408     uiItemR(row, imfptr, "keep_bind_info", 0, NULL, ICON_NONE);
409
410     row = uiLayoutRow(box, false);
411     uiItemR(row, imfptr, "limit_precision", 0, NULL, ICON_NONE);
412   }
413 }
414
415 static void wm_collada_export_draw(bContext *UNUSED(C), wmOperator *op)
416 {
417   PointerRNA ptr;
418
419   RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
420   uiCollada_exportSettings(op->layout, &ptr);
421 }
422
423 static bool wm_collada_export_check(bContext *UNUSED(C), wmOperator *op)
424 {
425   char filepath[FILE_MAX];
426   RNA_string_get(op->ptr, "filepath", filepath);
427
428   if (!BLI_path_extension_check(filepath, ".dae")) {
429     BLI_path_extension_ensure(filepath, FILE_MAX, ".dae");
430     RNA_string_set(op->ptr, "filepath", filepath);
431     return true;
432   }
433
434   return false;
435 }
436
437 void WM_OT_collada_export(wmOperatorType *ot)
438 {
439   struct StructRNA *func = ot->srna;
440
441   static const EnumPropertyItem prop_bc_export_mesh_type[] = {
442       {BC_MESH_TYPE_VIEW, "view", 0, "View", "Apply modifier's view settings"},
443       {BC_MESH_TYPE_RENDER, "render", 0, "Render", "Apply modifier's render settings"},
444       {0, NULL, 0, NULL, NULL},
445   };
446
447   static const EnumPropertyItem prop_bc_export_global_forward[] = {
448       {BC_GLOBAL_FORWARD_X, "X", 0, "X Forward", "Global Forward is positive X Axis"},
449       {BC_GLOBAL_FORWARD_Y, "Y", 0, "Y Forward", "Global Forward is positive Y Axis"},
450       {BC_GLOBAL_FORWARD_Z, "Z", 0, "Z Forward", "Global Forward is positive Z Axis"},
451       {BC_GLOBAL_FORWARD_MINUS_X, "-X", 0, "-X Forward", "Global Forward is negative X Axis"},
452       {BC_GLOBAL_FORWARD_MINUS_Y, "-Y", 0, "-Y Forward", "Global Forward is negative Y Axis"},
453       {BC_GLOBAL_FORWARD_MINUS_Z, "-Z", 0, "-Z Forward", "Global Forward is negative Z Axis"},
454       {0, NULL, 0, NULL, NULL},
455   };
456
457   static const EnumPropertyItem prop_bc_export_global_up[] = {
458       {BC_GLOBAL_UP_X, "X", 0, "X Up", "Global UP is positive X Axis"},
459       {BC_GLOBAL_UP_Y, "Y", 0, "Y Up", "Global UP is positive Y Axis"},
460       {BC_GLOBAL_UP_Z, "Z", 0, "Z Up", "Global UP is positive Z Axis"},
461       {BC_GLOBAL_UP_MINUS_X, "-X", 0, "-X Up", "Global UP is negative X Axis"},
462       {BC_GLOBAL_UP_MINUS_Y, "-Y", 0, "-Y Up", "Global UP is negative Y Axis"},
463       {BC_GLOBAL_UP_MINUS_Z, "-Z", 0, "-Z Up", "Global UP is negative Z Axis"},
464       {0, NULL, 0, NULL, NULL},
465   };
466
467   static const EnumPropertyItem prop_bc_export_transformation_type[] = {
468       {BC_TRANSFORMATION_TYPE_MATRIX,
469        "matrix",
470        0,
471        "Matrix",
472        "Use <matrix> to specify transformations"},
473       {BC_TRANSFORMATION_TYPE_TRANSROTLOC,
474        "transrotloc",
475        0,
476        "TransRotLoc",
477        "Use <translate>, <rotate>, <scale> to specify transformations"},
478       {0, NULL, 0, NULL, NULL}};
479
480   static const EnumPropertyItem prop_bc_export_animation_type[] = {
481       {BC_ANIMATION_EXPORT_SAMPLES,
482        "sample",
483        0,
484        "Samples",
485        "Export Sampled points guided by sampling rate"},
486       {BC_ANIMATION_EXPORT_KEYS,
487        "keys",
488        0,
489        "Curves",
490        "Export Curves (note: guided by curve keys)"},
491       {0, NULL, 0, NULL, NULL}};
492
493   static const EnumPropertyItem prop_bc_export_ui_section[] = {
494       {BC_UI_SECTION_MAIN, "main", 0, "Main", "Data Export Section"},
495       {BC_UI_SECTION_GEOMETRY, "geometry", 0, "Geom", "Geometry Export Section"},
496       {BC_UI_SECTION_ARMATURE, "armature", 0, "Arm", "Armature Export Section"},
497       {BC_UI_SECTION_ANIMATION, "animation", 0, "Anim", "Animation Export Section"},
498       {BC_UI_SECTION_COLLADA, "collada", 0, "Extra", "Collada Export Section"},
499       {0, NULL, 0, NULL, NULL}};
500
501   ot->name = "Export COLLADA";
502   ot->description = "Save a Collada file";
503   ot->idname = "WM_OT_collada_export";
504
505   ot->invoke = wm_collada_export_invoke;
506   ot->exec = wm_collada_export_exec;
507   ot->poll = WM_operator_winactive;
508   ot->check = wm_collada_export_check;
509
510   ot->flag |= OPTYPE_PRESET;
511
512   ot->ui = wm_collada_export_draw;
513
514   WM_operator_properties_filesel(ot,
515                                  FILE_TYPE_FOLDER | FILE_TYPE_COLLADA,
516                                  FILE_BLENDER,
517                                  FILE_SAVE,
518                                  WM_FILESEL_FILEPATH,
519                                  FILE_DEFAULTDISPLAY,
520                                  FILE_SORT_ALPHA);
521
522   RNA_def_enum(func,
523                "prop_bc_export_ui_section",
524                prop_bc_export_ui_section,
525                0,
526                "Export Section",
527                "Only for User Interface organization");
528
529   RNA_def_boolean(func,
530                   "apply_modifiers",
531                   0,
532                   "Apply Modifiers",
533                   "Apply modifiers to exported mesh (non destructive))");
534
535   RNA_def_int(func,
536               "export_mesh_type",
537               0,
538               INT_MIN,
539               INT_MAX,
540               "Resolution",
541               "Modifier resolution for export",
542               INT_MIN,
543               INT_MAX);
544
545   RNA_def_enum(func,
546                "export_mesh_type_selection",
547                prop_bc_export_mesh_type,
548                0,
549                "Resolution",
550                "Modifier resolution for export");
551
552   RNA_def_enum(func,
553                "export_global_forward_selection",
554                prop_bc_export_global_forward,
555                BC_DEFAULT_FORWARD,
556                "Global Forward Axis",
557                "Global Forward axis for export");
558
559   RNA_def_enum(func,
560                "export_global_up_selection",
561                prop_bc_export_global_up,
562                BC_DEFAULT_UP,
563                "Global Up Axis",
564                "Global Up axis for export");
565
566   RNA_def_boolean(func, "", false, "Selection Only", "Export only selected elements");
567
568   RNA_def_boolean(func,
569                   "apply_global_orientation",
570                   false,
571                   "Apply Global Orientation",
572                   "enabled: Rotate all root objects to match the global orientation "
573                   "settings.\ndisabled: set global orientation in Collada assets");
574
575   RNA_def_boolean(func, "selected", false, "Selection Only", "Export only selected elements");
576
577   RNA_def_boolean(func,
578                   "include_children",
579                   false,
580                   "Include Children",
581                   "Export all children of selected objects (even if not selected)");
582
583   RNA_def_boolean(func,
584                   "include_armatures",
585                   false,
586                   "Include Armatures",
587                   "Export related armatures (even if not selected)");
588
589   RNA_def_boolean(func,
590                   "include_shapekeys",
591                   false,
592                   "Include Shape Keys",
593                   "Export all Shape Keys from Mesh Objects");
594
595   RNA_def_boolean(func,
596                   "deform_bones_only",
597                   false,
598                   "Deform Bones only",
599                   "Only export deforming bones with armatures");
600
601   RNA_def_boolean(
602       func,
603       "include_animations",
604       true,
605       "Include Animations",
606       "Export animations if available (exporting animations will enforce the decomposition of "
607       "node transforms into  <translation> <rotation> and <scale> components)");
608
609   RNA_def_boolean(func,
610                   "include_all_actions",
611                   true,
612                   "Include all Actions",
613                   "Export also unassigned actions (this allows you to export entire animation "
614                   "libraries for your character(s))");
615
616   RNA_def_enum(func,
617                "export_animation_type_selection",
618                prop_bc_export_animation_type,
619                0,
620                "Key Type",
621                "Type for exported animations (use sample keys or Curve keys)");
622
623   RNA_def_int(func,
624               "sampling_rate",
625               1,
626               1,
627               INT_MAX,
628               "Sampling Rate",
629               "The distance between 2 keyframes (1 to key every frame)",
630               1,
631               INT_MAX);
632
633   RNA_def_boolean(func,
634                   "keep_smooth_curves",
635                   0,
636                   "Keep Smooth curves",
637                   "Export also the curve handles (if available) (this does only work when the "
638                   "inverse parent matrix "
639                   "is the unity matrix, otherwise you may end up with odd results)");
640
641   RNA_def_boolean(func,
642                   "keep_keyframes",
643                   0,
644                   "Keep Keyframes",
645                   "Use existing keyframes as additional sample points (this helps when you want "
646                   "to keep manual tweaks)");
647
648   RNA_def_boolean(func,
649                   "keep_flat_curves",
650                   0,
651                   "All keyed curves",
652                   "Export also curves which have only one key or are totally flat");
653
654   RNA_def_boolean(
655       func, "active_uv_only", 0, "Only Selected UV Map", "Export only the selected UV Map");
656
657   RNA_def_boolean(func,
658                   "use_texture_copies",
659                   1,
660                   "Copy",
661                   "Copy textures to same folder where the .dae file is exported");
662
663   RNA_def_boolean(
664       func, "triangulate", 1, "Triangulate", "Export Polygons (Quads & NGons) as Triangles");
665
666   RNA_def_boolean(func,
667                   "use_object_instantiation",
668                   1,
669                   "Use Object Instances",
670                   "Instantiate multiple Objects from same Data");
671
672   RNA_def_boolean(
673       func,
674       "use_blender_profile",
675       1,
676       "Use Blender Profile",
677       "Export additional Blender specific information (for material, shaders, bones, etc.)");
678
679   RNA_def_boolean(
680       func, "sort_by_name", 0, "Sort by Object name", "Sort exported data by Object name");
681
682   RNA_def_int(func,
683               "export_transformation_type",
684               0,
685               INT_MIN,
686               INT_MAX,
687               "Transform",
688               "Transformation type for translation, scale and rotation",
689               INT_MIN,
690               INT_MAX);
691
692   RNA_def_enum(func,
693                "export_transformation_type_selection",
694                prop_bc_export_transformation_type,
695                0,
696                "Transform",
697                "Transformation type for translation, scale and rotation");
698
699   RNA_def_boolean(func,
700                   "open_sim",
701                   0,
702                   "Export to SL/OpenSim",
703                   "Compatibility mode for SL, OpenSim and other compatible online worlds");
704
705   RNA_def_boolean(func,
706                   "limit_precision",
707                   0,
708                   "Limit Precision",
709                   "Reduce the precision of the exported data to 6 digits");
710
711   RNA_def_boolean(
712       func,
713       "keep_bind_info",
714       0,
715       "Keep Bind Info",
716       "Store Bindpose information in custom bone properties for later use during Collada export");
717 }
718
719 /* function used for WM_OT_save_mainfile too */
720 static int wm_collada_import_exec(bContext *C, wmOperator *op)
721 {
722   char filename[FILE_MAX];
723   int import_units;
724   int find_chains;
725   int auto_connect;
726   int fix_orientation;
727   int min_chain_length;
728
729   int keep_bind_info;
730   ImportSettings import_settings;
731
732   if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
733     BKE_report(op->reports, RPT_ERROR, "No filename given");
734     return OPERATOR_CANCELLED;
735   }
736
737   /* Options panel */
738   import_units = RNA_boolean_get(op->ptr, "import_units");
739   find_chains = RNA_boolean_get(op->ptr, "find_chains");
740   auto_connect = RNA_boolean_get(op->ptr, "auto_connect");
741   fix_orientation = RNA_boolean_get(op->ptr, "fix_orientation");
742
743   keep_bind_info = RNA_boolean_get(op->ptr, "keep_bind_info");
744
745   min_chain_length = RNA_int_get(op->ptr, "min_chain_length");
746
747   RNA_string_get(op->ptr, "filepath", filename);
748
749   import_settings.filepath = filename;
750   import_settings.import_units = import_units != 0;
751   import_settings.auto_connect = auto_connect != 0;
752   import_settings.find_chains = find_chains != 0;
753   import_settings.fix_orientation = fix_orientation != 0;
754   import_settings.min_chain_length = min_chain_length;
755   import_settings.keep_bind_info = keep_bind_info != 0;
756
757   if (collada_import(C, &import_settings)) {
758     DEG_id_tag_update(&CTX_data_scene(C)->id, ID_RECALC_BASE_FLAGS);
759     return OPERATOR_FINISHED;
760   }
761   else {
762     BKE_report(op->reports, RPT_ERROR, "Parsing errors in Document (see Blender Console)");
763     return OPERATOR_CANCELLED;
764   }
765 }
766
767 static void uiCollada_importSettings(uiLayout *layout, PointerRNA *imfptr)
768 {
769   uiLayout *box, *row;
770
771   /* Import Options: */
772   box = uiLayoutBox(layout);
773   row = uiLayoutRow(box, false);
774   uiItemL(row, IFACE_("Import Data Options:"), ICON_MESH_DATA);
775
776   row = uiLayoutRow(box, false);
777   uiItemR(row, imfptr, "import_units", 0, NULL, ICON_NONE);
778
779   box = uiLayoutBox(layout);
780   row = uiLayoutRow(box, false);
781   uiItemL(row, IFACE_("Armature Options:"), ICON_MESH_DATA);
782
783   row = uiLayoutRow(box, false);
784   uiItemR(row, imfptr, "fix_orientation", 0, NULL, ICON_NONE);
785
786   row = uiLayoutRow(box, false);
787   uiItemR(row, imfptr, "find_chains", 0, NULL, ICON_NONE);
788
789   row = uiLayoutRow(box, false);
790   uiItemR(row, imfptr, "auto_connect", 0, NULL, ICON_NONE);
791
792   row = uiLayoutRow(box, false);
793   uiItemR(row, imfptr, "min_chain_length", 0, NULL, ICON_NONE);
794
795   box = uiLayoutBox(layout);
796   row = uiLayoutRow(box, false);
797
798   row = uiLayoutRow(box, false);
799   uiItemR(row, imfptr, "keep_bind_info", 0, NULL, ICON_NONE);
800 }
801
802 static void wm_collada_import_draw(bContext *UNUSED(C), wmOperator *op)
803 {
804   PointerRNA ptr;
805
806   RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
807   uiCollada_importSettings(op->layout, &ptr);
808 }
809
810 void WM_OT_collada_import(wmOperatorType *ot)
811 {
812   ot->name = "Import COLLADA";
813   ot->description = "Load a Collada file";
814   ot->idname = "WM_OT_collada_import";
815
816   ot->invoke = WM_operator_filesel;
817   ot->exec = wm_collada_import_exec;
818   ot->poll = WM_operator_winactive;
819
820   // ot->flag |= OPTYPE_PRESET;
821
822   ot->ui = wm_collada_import_draw;
823
824   WM_operator_properties_filesel(ot,
825                                  FILE_TYPE_FOLDER | FILE_TYPE_COLLADA,
826                                  FILE_BLENDER,
827                                  FILE_OPENFILE,
828                                  WM_FILESEL_FILEPATH,
829                                  FILE_DEFAULTDISPLAY,
830                                  FILE_SORT_ALPHA);
831
832   RNA_def_boolean(ot->srna,
833                   "import_units",
834                   0,
835                   "Import Units",
836                   "If disabled match import to Blender's current Unit settings, "
837                   "otherwise use the settings from the Imported scene");
838
839   RNA_def_boolean(ot->srna,
840                   "fix_orientation",
841                   0,
842                   "Fix Leaf Bones",
843                   "Fix Orientation of Leaf Bones (Collada does only support Joints)");
844
845   RNA_def_boolean(ot->srna,
846                   "find_chains",
847                   0,
848                   "Find Bone Chains",
849                   "Find best matching Bone Chains and ensure bones in chain are connected");
850
851   RNA_def_boolean(ot->srna,
852                   "auto_connect",
853                   0,
854                   "Auto Connect",
855                   "Set use_connect for parent bones which have exactly one child bone");
856
857   RNA_def_int(ot->srna,
858               "min_chain_length",
859               0,
860               0,
861               INT_MAX,
862               "Minimum Chain Length",
863               "When searching Bone Chains disregard chains of length below this value",
864               0,
865               INT_MAX);
866
867   RNA_def_boolean(
868       ot->srna,
869       "keep_bind_info",
870       0,
871       "Keep Bind Info",
872       "Store Bindpose information in custom bone properties for later use during Collada export");
873 }
874 #endif