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