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