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