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