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