Blender V4.3
io_collada.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8#ifdef WITH_COLLADA
9# include "DNA_space_types.h"
10
11# include "BLT_translation.hh"
12
13# include "BLI_blenlib.h"
14# include "BLI_string.h"
15# include "BLI_utildefines.h"
16
17# include "BKE_context.hh"
18# include "BKE_file_handler.hh"
19# include "BKE_report.hh"
20
21# include "DEG_depsgraph.hh"
22
23# include "ED_fileselect.hh"
24# include "ED_object.hh"
25# include "ED_outliner.hh"
26
27# include "RNA_access.hh"
28# include "RNA_define.hh"
29
30# include "UI_interface.hh"
31# include "UI_resources.hh"
32
33# include "WM_api.hh"
34# include "WM_types.hh"
35
36# include "collada.h"
37
38# include "io_collada.hh"
39# include "io_utils.hh"
40
41static int wm_collada_export_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
42{
44
46
48}
49
50static int wm_collada_export_exec(bContext *C, wmOperator *op)
51{
52 char filepath[FILE_MAX];
53 int apply_modifiers;
54 int global_forward;
55 int global_up;
56 int apply_global_orientation;
57 int export_mesh_type;
58 int selected;
59 int include_children;
60 int include_armatures;
61 int include_shapekeys;
62 int deform_bones_only;
63
64 int include_animations;
65 int include_all_actions;
66 int sampling_rate;
67 int keep_smooth_curves;
68 int keep_keyframes;
69 int keep_flat_curves;
70
71 int export_animation_type;
72 int use_texture_copies;
73 int active_uv_only;
74
75 int triangulate;
76 int use_object_instantiation;
77 int use_blender_profile;
78 int sort_by_name;
79 int export_object_transformation_type;
80 int export_animation_transformation_type;
81
82 int open_sim;
83 int limit_precision;
84 int keep_bind_info;
85
86 int export_count;
87 int sample_animations;
88
89 if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) {
90 BKE_report(op->reports, RPT_ERROR, "No filepath given");
91 return OPERATOR_CANCELLED;
92 }
93
94 RNA_string_get(op->ptr, "filepath", filepath);
95 BLI_path_extension_ensure(filepath, sizeof(filepath), ".dae");
96
97 /* Avoid File write exceptions in Collada */
98 if (!BLI_exists(filepath)) {
100 if (!BLI_file_touch(filepath)) {
101 BKE_report(op->reports, RPT_ERROR, "Can't create export file");
102 fprintf(stdout, "Collada export: Can not create: %s\n", filepath);
103 return OPERATOR_CANCELLED;
104 }
105 }
106 else if (!BLI_file_is_writable(filepath)) {
107 BKE_report(op->reports, RPT_ERROR, "Can't overwrite export file");
108 fprintf(stdout, "Collada export: Can not modify: %s\n", filepath);
109 return OPERATOR_CANCELLED;
110 }
111
112 /* Now the exporter can create and write the export file */
113
114 /* Options panel */
115 apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers");
116 export_mesh_type = RNA_enum_get(op->ptr, "export_mesh_type_selection");
117 global_forward = RNA_enum_get(op->ptr, "export_global_forward_selection");
118 global_up = RNA_enum_get(op->ptr, "export_global_up_selection");
119 apply_global_orientation = RNA_boolean_get(op->ptr, "apply_global_orientation");
120
121 selected = RNA_boolean_get(op->ptr, "selected");
122 include_children = RNA_boolean_get(op->ptr, "include_children");
123 include_armatures = RNA_boolean_get(op->ptr, "include_armatures");
124 include_shapekeys = RNA_boolean_get(op->ptr, "include_shapekeys");
125
126 include_animations = RNA_boolean_get(op->ptr, "include_animations");
127 include_all_actions = RNA_boolean_get(op->ptr, "include_all_actions");
128 export_animation_type = RNA_enum_get(op->ptr, "export_animation_type_selection");
129 sample_animations = (export_animation_type == BC_ANIMATION_EXPORT_SAMPLES);
130 sampling_rate = (sample_animations) ? RNA_int_get(op->ptr, "sampling_rate") : 0;
131 keep_smooth_curves = RNA_boolean_get(op->ptr, "keep_smooth_curves");
132 keep_keyframes = RNA_boolean_get(op->ptr, "keep_keyframes");
133 keep_flat_curves = RNA_boolean_get(op->ptr, "keep_flat_curves");
134
135 deform_bones_only = RNA_boolean_get(op->ptr, "deform_bones_only");
136
137 use_texture_copies = RNA_boolean_get(op->ptr, "use_texture_copies");
138 active_uv_only = RNA_boolean_get(op->ptr, "active_uv_only");
139
140 triangulate = RNA_boolean_get(op->ptr, "triangulate");
141 use_object_instantiation = RNA_boolean_get(op->ptr, "use_object_instantiation");
142 use_blender_profile = RNA_boolean_get(op->ptr, "use_blender_profile");
143 sort_by_name = RNA_boolean_get(op->ptr, "sort_by_name");
144
145 export_object_transformation_type = RNA_enum_get(op->ptr,
146 "export_object_transformation_type_selection");
147 export_animation_transformation_type = RNA_enum_get(
148 op->ptr, "export_animation_transformation_type_selection");
149
150 open_sim = RNA_boolean_get(op->ptr, "open_sim");
151 limit_precision = RNA_boolean_get(op->ptr, "limit_precision");
152 keep_bind_info = RNA_boolean_get(op->ptr, "keep_bind_info");
153
154 Main *bmain = CTX_data_main(C);
155
156 /* get editmode results */
158
159 // Scene *scene = CTX_data_scene(C);
160
161 ExportSettings export_settings{};
162
163 export_settings.filepath = filepath;
164
165 export_settings.apply_modifiers = apply_modifiers != 0;
166 export_settings.global_forward = BC_global_forward_axis(global_forward);
167 export_settings.global_up = BC_global_up_axis(global_up);
168 export_settings.apply_global_orientation = apply_global_orientation != 0;
169
170 export_settings.export_mesh_type = BC_export_mesh_type(export_mesh_type);
171 export_settings.selected = selected != 0;
172 export_settings.include_children = include_children != 0;
173 export_settings.include_armatures = include_armatures != 0;
174 export_settings.include_shapekeys = include_shapekeys != 0;
175 export_settings.deform_bones_only = deform_bones_only != 0;
176 export_settings.include_animations = include_animations != 0;
177 export_settings.include_all_actions = include_all_actions != 0;
178 export_settings.sampling_rate = sampling_rate;
179 export_settings.keep_keyframes = keep_keyframes != 0 || sampling_rate < 1;
180 export_settings.keep_flat_curves = keep_flat_curves != 0;
181
182 export_settings.active_uv_only = active_uv_only != 0;
183 export_settings.export_animation_type = BC_export_animation_type(export_animation_type);
184 export_settings.use_texture_copies = use_texture_copies != 0;
185
186 export_settings.triangulate = triangulate != 0;
187 export_settings.use_object_instantiation = use_object_instantiation != 0;
188 export_settings.use_blender_profile = use_blender_profile != 0;
189 export_settings.sort_by_name = sort_by_name != 0;
190 export_settings.object_transformation_type = BC_export_transformation_type(
191 export_object_transformation_type);
192 export_settings.animation_transformation_type = BC_export_transformation_type(
193 export_animation_transformation_type);
194 export_settings.keep_smooth_curves = keep_smooth_curves != 0;
195
196 if (export_animation_type != BC_ANIMATION_EXPORT_SAMPLES) {
197 /* When curves are exported then we can not export as matrix. */
198 export_settings.animation_transformation_type = BC_TRANSFORMATION_TYPE_DECOMPOSED;
199 }
200
201 if (export_settings.animation_transformation_type != BC_TRANSFORMATION_TYPE_DECOMPOSED) {
202 /* Can not export smooth curves when Matrix export is enabled. */
203 export_settings.keep_smooth_curves = false;
204 }
205
206 if (include_animations) {
207 export_settings.object_transformation_type = export_settings.animation_transformation_type;
208 }
209
210 export_settings.open_sim = open_sim != 0;
211 export_settings.limit_precision = limit_precision != 0;
212 export_settings.keep_bind_info = keep_bind_info != 0;
213
214 export_count = collada_export(C, &export_settings);
215
216 if (export_count == 0) {
217 BKE_report(op->reports, RPT_WARNING, "No objects selected -- Created empty export file");
218 return OPERATOR_CANCELLED;
219 }
220 if (export_count < 0) {
221 BKE_report(op->reports, RPT_WARNING, "Error during export (see Console)");
222 return OPERATOR_CANCELLED;
223 }
224
225 char buff[100];
226 SNPRINTF(buff, "Exported %d Objects", export_count);
227 BKE_report(op->reports, RPT_INFO, buff);
228 return OPERATOR_FINISHED;
229}
230
231static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
232{
233 uiLayout *box, *row, *col, *sub;
234 bool include_animations = RNA_boolean_get(imfptr, "include_animations");
235 int ui_section = RNA_enum_get(imfptr, "prop_bc_export_ui_section");
236
238 RNA_enum_get(imfptr, "export_animation_type_selection"));
239
240 BC_export_transformation_type animation_transformation_type = BC_export_transformation_type(
241 RNA_enum_get(imfptr, "export_animation_transformation_type_selection"));
242
243 bool sampling = animation_type == BC_ANIMATION_EXPORT_SAMPLES;
244
245 /* Export Options: */
246 row = uiLayoutRow(layout, false);
247 uiItemR(row, imfptr, "prop_bc_export_ui_section", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
248
249 uiLayoutSetPropSep(layout, true);
250 uiLayoutSetPropDecorate(layout, false);
251
252 if (ui_section == BC_UI_SECTION_MAIN) {
253 /* Export data options. */
254 box = uiLayoutBox(layout);
255 col = uiLayoutColumn(box, false);
256 uiItemR(col, imfptr, "selected", UI_ITEM_NONE, nullptr, ICON_NONE);
257 sub = uiLayoutColumn(col, false);
258 uiLayoutSetEnabled(sub, RNA_boolean_get(imfptr, "selected"));
259 uiItemR(sub, imfptr, "include_children", UI_ITEM_NONE, nullptr, ICON_NONE);
260 uiItemR(sub, imfptr, "include_armatures", UI_ITEM_NONE, nullptr, ICON_NONE);
261 uiItemR(sub, imfptr, "include_shapekeys", UI_ITEM_NONE, nullptr, ICON_NONE);
262
263 box = uiLayoutBox(layout);
264 row = uiLayoutRow(box, false);
265 uiItemL(row, IFACE_("Global Orientation"), ICON_ORIENTATION_GLOBAL);
266
267 uiItemR(box, imfptr, "apply_global_orientation", UI_ITEM_NONE, IFACE_("Apply"), ICON_NONE);
268 uiItemR(box,
269 imfptr,
270 "export_global_forward_selection",
272 IFACE_("Forward Axis"),
273 ICON_NONE);
274 uiItemR(box, imfptr, "export_global_up_selection", UI_ITEM_NONE, IFACE_("Up Axis"), ICON_NONE);
275
276 /* Texture options */
277 box = uiLayoutBox(layout);
278 uiItemL(box, IFACE_("Texture Options"), ICON_TEXTURE_DATA);
279
280 col = uiLayoutColumn(box, false);
281 uiItemR(col, imfptr, "use_texture_copies", UI_ITEM_NONE, nullptr, ICON_NONE);
282 row = uiLayoutRowWithHeading(col, true, IFACE_("UV"));
283 uiItemR(row, imfptr, "active_uv_only", UI_ITEM_NONE, IFACE_("Only Selected Map"), ICON_NONE);
284 }
285 else if (ui_section == BC_UI_SECTION_GEOMETRY) {
286 box = uiLayoutBox(layout);
287 uiItemL(box, IFACE_("Export Data Options"), ICON_MESH_DATA);
288
289 col = uiLayoutColumn(box, false);
290
291 uiItemR(col, imfptr, "triangulate", UI_ITEM_NONE, nullptr, ICON_NONE);
292
293 row = uiLayoutRowWithHeading(col, true, IFACE_("Apply Modifiers"));
294 uiItemR(row, imfptr, "apply_modifiers", UI_ITEM_NONE, "", ICON_NONE);
295 sub = uiLayoutColumn(row, false);
296 uiLayoutSetActive(sub, RNA_boolean_get(imfptr, "apply_modifiers"));
297 uiItemR(sub, imfptr, "export_mesh_type_selection", UI_ITEM_NONE, "", ICON_NONE);
298
299 if (RNA_boolean_get(imfptr, "include_animations")) {
300 uiItemR(col,
301 imfptr,
302 "export_animation_transformation_type_selection",
304 nullptr,
305 ICON_NONE);
306 }
307 else {
308 uiItemR(col,
309 imfptr,
310 "export_object_transformation_type_selection",
312 nullptr,
313 ICON_NONE);
314 }
315 }
316 else if (ui_section == BC_UI_SECTION_ARMATURE) {
317 /* Armature options */
318 box = uiLayoutBox(layout);
319 uiItemL(box, IFACE_("Armature Options"), ICON_ARMATURE_DATA);
320
321 col = uiLayoutColumn(box, false);
322 uiItemR(col, imfptr, "deform_bones_only", UI_ITEM_NONE, nullptr, ICON_NONE);
323 uiItemR(col, imfptr, "open_sim", UI_ITEM_NONE, nullptr, ICON_NONE);
324 }
325 else if (ui_section == BC_UI_SECTION_ANIMATION) {
326 /* Animation options. */
327 box = uiLayoutBox(layout);
328 uiItemR(box, imfptr, "include_animations", UI_ITEM_NONE, nullptr, ICON_NONE);
329
330 col = uiLayoutColumn(box, false);
331 row = uiLayoutRow(col, false);
332 uiLayoutSetActive(row, include_animations);
333 uiItemR(row, imfptr, "export_animation_type_selection", UI_ITEM_R_EXPAND, nullptr, ICON_NONE);
334
335 uiLayoutSetActive(row, include_animations && animation_type == BC_ANIMATION_EXPORT_SAMPLES);
336 if (RNA_boolean_get(imfptr, "include_animations")) {
337 uiItemR(box,
338 imfptr,
339 "export_animation_transformation_type_selection",
341 nullptr,
342 ICON_NONE);
343 }
344 else {
345 uiItemR(box,
346 imfptr,
347 "export_object_transformation_type_selection",
349 nullptr,
350 ICON_NONE);
351 }
352
353 row = uiLayoutColumn(col, false);
355 include_animations &&
356 (animation_transformation_type == BC_TRANSFORMATION_TYPE_DECOMPOSED ||
357 animation_type == BC_ANIMATION_EXPORT_KEYS));
358 uiItemR(row, imfptr, "keep_smooth_curves", UI_ITEM_NONE, nullptr, ICON_NONE);
359
360 sub = uiLayoutColumn(col, false);
361 uiLayoutSetActive(sub, sampling && include_animations);
362 uiItemR(sub, imfptr, "sampling_rate", UI_ITEM_NONE, nullptr, ICON_NONE);
363 uiItemR(sub, imfptr, "keep_keyframes", UI_ITEM_NONE, nullptr, ICON_NONE);
364
365 sub = uiLayoutColumn(col, false);
366 uiLayoutSetActive(sub, include_animations);
367 uiItemR(sub, imfptr, "keep_flat_curves", UI_ITEM_NONE, nullptr, ICON_NONE);
368 uiItemR(sub, imfptr, "include_all_actions", UI_ITEM_NONE, nullptr, ICON_NONE);
369 }
370 else if (ui_section == BC_UI_SECTION_COLLADA) {
371 /* Collada options: */
372 box = uiLayoutBox(layout);
373 row = uiLayoutRow(box, false);
374 uiItemL(row, IFACE_("Collada Options"), ICON_MODIFIER);
375
376 col = uiLayoutColumn(box, false);
377 uiItemR(col, imfptr, "use_object_instantiation", UI_ITEM_NONE, nullptr, ICON_NONE);
378 uiItemR(col, imfptr, "use_blender_profile", UI_ITEM_NONE, nullptr, ICON_NONE);
379 uiItemR(col, imfptr, "sort_by_name", UI_ITEM_NONE, nullptr, ICON_NONE);
380 uiItemR(col, imfptr, "keep_bind_info", UI_ITEM_NONE, nullptr, ICON_NONE);
381 uiItemR(col, imfptr, "limit_precision", UI_ITEM_NONE, nullptr, ICON_NONE);
382 }
383}
384
385static void wm_collada_export_draw(bContext * /*C*/, wmOperator *op)
386{
387 uiCollada_exportSettings(op->layout, op->ptr);
388}
389
390static bool wm_collada_export_check(bContext * /*C*/, wmOperator *op)
391{
392 char filepath[FILE_MAX];
393 RNA_string_get(op->ptr, "filepath", filepath);
394
395 if (!BLI_path_extension_check(filepath, ".dae")) {
396 BLI_path_extension_ensure(filepath, FILE_MAX, ".dae");
397 RNA_string_set(op->ptr, "filepath", filepath);
398 return true;
399 }
400
401 return false;
402}
403
405{
406 static const EnumPropertyItem prop_bc_export_mesh_type[] = {
407 {BC_MESH_TYPE_VIEW, "view", 0, "Viewport", "Apply modifier's viewport settings"},
408 {BC_MESH_TYPE_RENDER, "render", 0, "Render", "Apply modifier's render settings"},
409 {0, nullptr, 0, nullptr, nullptr},
410 };
411
412 static const EnumPropertyItem prop_bc_export_global_forward[] = {
413 {BC_GLOBAL_FORWARD_X, "X", 0, "X", "Global Forward is positive X Axis"},
414 {BC_GLOBAL_FORWARD_Y, "Y", 0, "Y", "Global Forward is positive Y Axis"},
415 {BC_GLOBAL_FORWARD_Z, "Z", 0, "Z", "Global Forward is positive Z Axis"},
416 {BC_GLOBAL_FORWARD_MINUS_X, "-X", 0, "-X", "Global Forward is negative X Axis"},
417 {BC_GLOBAL_FORWARD_MINUS_Y, "-Y", 0, "-Y", "Global Forward is negative Y Axis"},
418 {BC_GLOBAL_FORWARD_MINUS_Z, "-Z", 0, "-Z", "Global Forward is negative Z Axis"},
419 {0, nullptr, 0, nullptr, nullptr},
420 };
421
422 static const EnumPropertyItem prop_bc_export_global_up[] = {
423 {BC_GLOBAL_UP_X, "X", 0, "X", "Global UP is positive X Axis"},
424 {BC_GLOBAL_UP_Y, "Y", 0, "Y", "Global UP is positive Y Axis"},
425 {BC_GLOBAL_UP_Z, "Z", 0, "Z", "Global UP is positive Z Axis"},
426 {BC_GLOBAL_UP_MINUS_X, "-X", 0, "-X", "Global UP is negative X Axis"},
427 {BC_GLOBAL_UP_MINUS_Y, "-Y", 0, "-Y", "Global UP is negative Y Axis"},
428 {BC_GLOBAL_UP_MINUS_Z, "-Z", 0, "-Z", "Global UP is negative Z Axis"},
429 {0, nullptr, 0, nullptr, nullptr},
430 };
431
432 static const EnumPropertyItem prop_bc_export_transformation_type[] = {
434 "matrix",
435 0,
436 "Matrix",
437 "Use <matrix> representation for exported transformations"},
439 "decomposed",
440 0,
441 "Decomposed",
442 "Use <rotate>, <translate> and <scale> representation for exported transformations"},
443 {0, nullptr, 0, nullptr, nullptr}};
444
445 static const EnumPropertyItem prop_bc_export_animation_type[] = {
447 "sample",
448 0,
449 "Samples",
450 "Export Sampled points guided by sampling rate"},
452 "keys",
453 0,
454 "Curves",
455 "Export Curves (note: guided by curve keys)"},
456 {0, nullptr, 0, nullptr, nullptr}};
457
458 static const EnumPropertyItem prop_bc_export_ui_section[] = {
459 {BC_UI_SECTION_MAIN, "main", 0, "Main", "Data export section"},
460 {BC_UI_SECTION_GEOMETRY, "geometry", 0, "Geom", "Geometry export section"},
461 {BC_UI_SECTION_ARMATURE, "armature", 0, "Arm", "Armature export section"},
462 {BC_UI_SECTION_ANIMATION, "animation", 0, "Anim", "Animation export section"},
463 {BC_UI_SECTION_COLLADA, "collada", 0, "Extra", "Collada export section"},
464 {0, nullptr, 0, nullptr, nullptr}};
465
466 ot->name = "Export COLLADA (Legacy)";
467 ot->description = "Save a Collada file";
468 ot->idname = "WM_OT_collada_export";
469
470 ot->invoke = wm_collada_export_invoke;
471 ot->exec = wm_collada_export_exec;
473 ot->check = wm_collada_export_check;
474
476
477 ot->ui = wm_collada_export_draw;
478
482 FILE_SAVE,
486
487 PropertyRNA *prop = RNA_def_string(ot->srna, "filter_glob", "*.dae", 0, "", "");
489
491 "prop_bc_export_ui_section",
492 prop_bc_export_ui_section,
493 0,
494 "Export Section",
495 "Only for User Interface organization");
496
498 "apply_modifiers",
499 false,
500 "Apply Modifiers",
501 "Apply modifiers to exported mesh (non destructive)");
502
504 "export_mesh_type",
505 0,
506 INT_MIN,
507 INT_MAX,
508 "Resolution",
509 "Modifier resolution for export",
510 INT_MIN,
511 INT_MAX);
512
514 "export_mesh_type_selection",
515 prop_bc_export_mesh_type,
516 0,
517 "Resolution",
518 "Modifier resolution for export");
519
521 "export_global_forward_selection",
522 prop_bc_export_global_forward,
524 "Global Forward Axis",
525 "Global Forward axis for export");
526
528 "export_global_up_selection",
529 prop_bc_export_global_up,
531 "Global Up Axis",
532 "Global Up axis for export");
533
535 "apply_global_orientation",
536 false,
537 "Apply Global Orientation",
538 "Rotate all root objects to match the global orientation settings "
539 "otherwise set the global orientation per Collada asset");
540
541 RNA_def_boolean(ot->srna, "selected", false, "Selection Only", "Export only selected elements");
542
544 "include_children",
545 false,
546 "Include Children",
547 "Export all children of selected objects (even if not selected)");
548
550 "include_armatures",
551 false,
552 "Include Armatures",
553 "Export related armatures (even if not selected)");
554
556 "include_shapekeys",
557 false,
558 "Include Shape Keys",
559 "Export all Shape Keys from Mesh Objects");
560
562 "deform_bones_only",
563 false,
564 "Deform Bones Only",
565 "Only export deforming bones with armatures");
566
568 ot->srna,
569 "include_animations",
570 true,
571 "Include Animations",
572 "Export animations if available (exporting animations will enforce the decomposition of "
573 "node transforms into <translation> <rotation> and <scale> components)");
574
576 "include_all_actions",
577 true,
578 "Include all Actions",
579 "Export also unassigned actions (this allows you to export entire animation "
580 "libraries for your character(s))");
581
583 "export_animation_type_selection",
584 prop_bc_export_animation_type,
585 0,
586 "Key Type",
587 "Type for exported animations (use sample keys or Curve keys)");
588
590 "sampling_rate",
591 1,
592 1,
593 INT_MAX,
594 "Sampling Rate",
595 "The distance between 2 keyframes (1 to key every frame)",
596 1,
597 INT_MAX);
598
600 "keep_smooth_curves",
601 false,
602 "Keep Smooth curves",
603 "Export also the curve handles (if available) (this does only work when the "
604 "inverse parent matrix "
605 "is the unity matrix, otherwise you may end up with odd results)");
606
608 "keep_keyframes",
609 false,
610 "Keep Keyframes",
611 "Use existing keyframes as additional sample points (this helps when you want "
612 "to keep manual tweaks)");
613
615 "keep_flat_curves",
616 false,
617 "All Keyed Curves",
618 "Export also curves which have only one key or are totally flat");
619
621 "active_uv_only",
622 false,
623 "Only Selected UV Map",
624 "Export only the selected UV Map");
625
627 "use_texture_copies",
628 true,
629 "Copy",
630 "Copy textures to same folder where the .dae file is exported");
631
633 "triangulate",
634 true,
635 "Triangulate",
636 "Export polygons (quads and n-gons) as triangles");
637
639 "use_object_instantiation",
640 true,
641 "Use Object Instances",
642 "Instantiate multiple Objects from same Data");
643
645 ot->srna,
646 "use_blender_profile",
647 true,
648 "Use Blender Profile",
649 "Export additional Blender specific information (for material, shaders, bones, etc.)");
650
652 ot->srna, "sort_by_name", false, "Sort by Object name", "Sort exported data by Object name");
653
655 "export_object_transformation_type",
656 0,
657 INT_MIN,
658 INT_MAX,
659 "Transform",
660 "Object Transformation type for translation, scale and rotation",
661 INT_MIN,
662 INT_MAX);
663
665 "export_object_transformation_type_selection",
666 prop_bc_export_transformation_type,
667 0,
668 "Transform",
669 "Object Transformation type for translation, scale and rotation");
670
672 "export_animation_transformation_type",
673 0,
674 INT_MIN,
675 INT_MAX,
676 "Transform",
677 "Transformation type for translation, scale and rotation. "
678 "Note: The Animation transformation type in the Anim Tab "
679 "is always equal to the Object transformation type in the Geom tab",
680 INT_MIN,
681 INT_MAX);
682
684 "export_animation_transformation_type_selection",
685 prop_bc_export_transformation_type,
686 0,
687 "Transform",
688 "Transformation type for translation, scale and rotation. "
689 "Note: The Animation transformation type in the Anim Tab "
690 "is always equal to the Object transformation type in the Geom tab");
691
693 ot->srna,
694 "open_sim",
695 false,
696 "Export to SL/OpenSim",
697 "Compatibility mode for Second Life, OpenSimulator and other compatible online worlds");
698
700 "limit_precision",
701 false,
702 "Limit Precision",
703 "Reduce the precision of the exported data to 6 digits");
704
706 ot->srna,
707 "keep_bind_info",
708 false,
709 "Keep Bind Info",
710 "Store Bindpose information in custom bone properties for later use during Collada export");
711}
712
713static int wm_collada_import_exec(bContext *C, wmOperator *op)
714{
715 char filepath[FILE_MAX];
716 int import_units;
717 int find_chains;
718 int auto_connect;
719 int fix_orientation;
720 int min_chain_length;
721
722 int keep_bind_info;
723 int custom_normals;
724 ImportSettings import_settings{};
725
726 if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) {
727 BKE_report(op->reports, RPT_ERROR, "No filepath given");
728 return OPERATOR_CANCELLED;
729 }
730
731 /* Options panel */
732 import_units = RNA_boolean_get(op->ptr, "import_units");
733 custom_normals = RNA_boolean_get(op->ptr, "custom_normals");
734 find_chains = RNA_boolean_get(op->ptr, "find_chains");
735 auto_connect = RNA_boolean_get(op->ptr, "auto_connect");
736 fix_orientation = RNA_boolean_get(op->ptr, "fix_orientation");
737
738 keep_bind_info = RNA_boolean_get(op->ptr, "keep_bind_info");
739
740 min_chain_length = RNA_int_get(op->ptr, "min_chain_length");
741
742 RNA_string_get(op->ptr, "filepath", filepath);
743
744 import_settings.filepath = filepath;
745 import_settings.import_units = import_units != 0;
746 import_settings.custom_normals = custom_normals != 0;
747 import_settings.auto_connect = auto_connect != 0;
748 import_settings.find_chains = find_chains != 0;
749 import_settings.fix_orientation = fix_orientation != 0;
750 import_settings.min_chain_length = min_chain_length;
751 import_settings.keep_bind_info = keep_bind_info != 0;
752
753 if (collada_import(C, &import_settings)) {
755 Scene *scene = CTX_data_scene(C);
760 return OPERATOR_FINISHED;
761 }
762
763 BKE_report(op->reports, RPT_ERROR, "Parsing errors in Document (see Blender Console)");
764 return OPERATOR_CANCELLED;
765}
766
767static void wm_collada_import_settings(uiLayout *layout, PointerRNA *imfptr)
768{
769 uiLayout *box, *col;
770
771 uiLayoutSetPropSep(layout, true);
772 uiLayoutSetPropDecorate(layout, false);
773
774 /* Import Options: */
775 box = uiLayoutBox(layout);
776 uiItemL(box, IFACE_("Import Data Options"), ICON_MESH_DATA);
777
778 uiItemR(box, imfptr, "import_units", UI_ITEM_NONE, nullptr, ICON_NONE);
779 uiItemR(box, imfptr, "custom_normals", UI_ITEM_NONE, nullptr, ICON_NONE);
780
781 box = uiLayoutBox(layout);
782 uiItemL(box, IFACE_("Armature Options"), ICON_ARMATURE_DATA);
783
784 col = uiLayoutColumn(box, false);
785 uiItemR(col, imfptr, "fix_orientation", UI_ITEM_NONE, nullptr, ICON_NONE);
786 uiItemR(col, imfptr, "find_chains", UI_ITEM_NONE, nullptr, ICON_NONE);
787 uiItemR(col, imfptr, "auto_connect", UI_ITEM_NONE, nullptr, ICON_NONE);
788 uiItemR(col, imfptr, "min_chain_length", UI_ITEM_NONE, nullptr, ICON_NONE);
789
790 box = uiLayoutBox(layout);
791
792 uiItemR(box, imfptr, "keep_bind_info", UI_ITEM_NONE, nullptr, ICON_NONE);
793}
794
795static void wm_collada_import_draw(bContext * /*C*/, wmOperator *op)
796{
797 wm_collada_import_settings(op->layout, op->ptr);
798}
799
801{
802 ot->name = "Import COLLADA (Legacy)";
803 ot->description = "Load a Collada file";
804 ot->idname = "WM_OT_collada_import";
806
808 ot->exec = wm_collada_import_exec;
810
811 ot->ui = wm_collada_import_draw;
812
820
821 PropertyRNA *prop = RNA_def_string(ot->srna, "filter_glob", "*.dae", 0, "", "");
823
825 "import_units",
826 false,
827 "Import Units",
828 "If disabled match import to Blender's current Unit settings, "
829 "otherwise use the settings from the Imported scene");
830
832 "custom_normals",
833 true,
834 "Custom Normals",
835 "Import custom normals, if available (otherwise Blender will compute them)");
836
838 "fix_orientation",
839 false,
840 "Fix Leaf Bones",
841 "Fix Orientation of Leaf Bones (Collada does only support Joints)");
842
844 "find_chains",
845 false,
846 "Find Bone Chains",
847 "Find best matching Bone Chains and ensure bones in chain are connected");
848
850 "auto_connect",
851 false,
852 "Auto Connect",
853 "Set use_connect for parent bones which have exactly one child bone");
854
856 "min_chain_length",
857 0,
858 0,
859 INT_MAX,
860 "Minimum Chain Length",
861 "When searching Bone Chains disregard chains of length below this value",
862 0,
863 INT_MAX);
864
866 ot->srna,
867 "keep_bind_info",
868 false,
869 "Keep Bind Info",
870 "Store Bindpose information in custom bone properties for later use during Collada export");
871}
872
873namespace blender::ed::io {
875{
876 auto fh = std::make_unique<blender::bke::FileHandlerType>();
877 STRNCPY(fh->idname, "IO_FH_collada");
878 STRNCPY(fh->import_operator, "WM_OT_collada_import");
879 STRNCPY(fh->label, "Collada");
880 STRNCPY(fh->file_extensions_str, ".dae");
881 fh->poll_drop = poll_file_object_drop;
882 bke::file_handler_add(std::move(fh));
883}
884} // namespace blender::ed::io
885
886#endif
Scene * CTX_data_scene(const bContext *C)
Object * CTX_data_edit_object(const bContext *C)
Main * CTX_data_main(const bContext *C)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:125
bool BLI_file_touch(const char *filepath) ATTR_NONNULL(1)
Definition fileops_c.cc:316
int BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:350
bool BLI_file_is_writable(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition fileops_c.cc:291
bool BLI_file_ensure_parent_dir_exists(const char *filepath) ATTR_NONNULL(1)
Definition fileops_c.cc:429
#define FILE_MAX
bool BLI_path_extension_check(const char *path, const char *ext) ATTR_NONNULL(1
bool BLI_path_extension_ensure(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
#define STRNCPY(dst, src)
Definition BLI_string.h:593
#define SNPRINTF(dst, format,...)
Definition BLI_string.h:597
#define IFACE_(msgid)
static const BC_global_forward_axis BC_DEFAULT_FORWARD
static const BC_global_up_axis BC_DEFAULT_UP
BC_global_up_axis
@ BC_GLOBAL_UP_X
@ BC_GLOBAL_UP_MINUS_Y
@ BC_GLOBAL_UP_MINUS_Z
@ BC_GLOBAL_UP_Y
@ BC_GLOBAL_UP_MINUS_X
@ BC_GLOBAL_UP_Z
BC_global_forward_axis
@ BC_GLOBAL_FORWARD_Z
@ BC_GLOBAL_FORWARD_X
@ BC_GLOBAL_FORWARD_MINUS_Z
@ BC_GLOBAL_FORWARD_Y
@ BC_GLOBAL_FORWARD_MINUS_Y
@ BC_GLOBAL_FORWARD_MINUS_X
void DEG_id_tag_update(ID *id, unsigned int flags)
@ ID_RECALC_BASE_FLAGS
Definition DNA_ID.h:1071
@ FILE_SORT_DEFAULT
@ FILE_BLENDER
@ FILE_TYPE_COLLADA
@ FILE_TYPE_FOLDER
@ FILE_DEFAULTDISPLAY
@ OPERATOR_RUNNING_MODAL
void ED_fileselect_ensure_default_filepath(bContext *C, wmOperator *op, const char *extension)
Definition filesel.cc:1466
void ED_outliner_select_sync_from_object_tag(bContext *C)
BC_export_animation_type
@ BC_ANIMATION_EXPORT_KEYS
@ BC_ANIMATION_EXPORT_SAMPLES
BC_export_mesh_type
@ 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.hh:239
void uiLayoutSetActive(uiLayout *layout, bool active)
uiLayout * uiLayoutBox(uiLayout *layout)
void uiLayoutSetEnabled(uiLayout *layout, bool enabled)
void uiItemL(uiLayout *layout, const char *name, int icon)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
uiLayout * uiLayoutRowWithHeading(uiLayout *layout, bool align, const char *heading)
#define UI_ITEM_NONE
void uiLayoutSetPropDecorate(uiLayout *layout, bool is_sep)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_EXPAND
@ WM_FILESEL_SHOW_PROPS
Definition WM_api.hh:939
@ WM_FILESEL_FILEPATH
Definition WM_api.hh:936
@ FILE_OPENFILE
Definition WM_api.hh:945
@ FILE_SAVE
Definition WM_api.hh:946
@ OPTYPE_PRESET
Definition WM_types.hh:175
@ OPTYPE_UNDO
Definition WM_types.hh:162
#define ND_OB_ACTIVE
Definition WM_types.hh:407
#define ND_OB_SELECT
Definition WM_types.hh:409
#define NC_SCENE
Definition WM_types.hh:345
#define ND_LAYER_CONTENT
Definition WM_types.hh:420
int collada_import(bContext *C, ImportSettings *import_settings)
Definition collada.cpp:50
int collada_export(bContext *C, ExportSettings *export_settings)
Definition collada.cpp:60
uint col
void WM_OT_collada_import(wmOperatorType *ot)
void WM_OT_collada_export(wmOperatorType *ot)
void file_handler_add(std::unique_ptr< FileHandlerType > file_handler)
bool poll_file_object_drop(const bContext *C, blender::bke::FileHandlerType *)
Definition io_utils.cc:57
void collada_file_handler_add()
int filesel_drop_import_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition io_utils.cc:25
bool editmode_load(Main *bmain, Object *obedit)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
bool RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, bool use_ghost)
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
int RNA_int_get(PointerRNA *ptr, const char *name)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
const char * name
Definition WM_types.hh:990
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
bool(* check)(bContext *C, wmOperator *op)
Definition WM_types.hh:1014
int(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1022
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
void(* ui)(bContext *C, wmOperator *op)
Definition WM_types.hh:1053
StructRNA * srna
Definition WM_types.hh:1080
struct ReportList * reports
struct uiLayout * layout
struct PointerRNA * ptr
void WM_event_add_fileselect(bContext *C, wmOperator *op)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition wm_files.cc:4125
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)