Blender V5.3
io_obj.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#ifdef WITH_IO_WAVEFRONT_OBJ
10
11# include "DNA_space_types.h"
12
13# include "BKE_context.hh"
14# include "BKE_file_handler.hh"
15# include "BKE_main.hh"
16# include "BKE_report.hh"
17
18# include "BLI_path_utils.hh"
19# include "BLI_string.hh"
20# include "BLI_string_utf8.hh"
21
22# include "BLT_translation.hh"
23
24# include "ED_fileselect.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_interface_layout.hh"
32# include "UI_resources.hh"
33
34# include "WM_api.hh"
35# include "WM_types.hh"
36
37# include "DEG_depsgraph.hh"
38
39# include "IO_orientation.hh"
40# include "IO_path_util_types.hh"
41# include "IO_wavefront_obj.hh"
42
43# include "io_obj.hh"
44# include "io_utils.hh"
45
46namespace blender {
47
48static const EnumPropertyItem io_obj_export_evaluation_mode[] = {
49 {DAG_EVAL_RENDER, "DAG_EVAL_RENDER", 0, "Render", "Export objects as they appear in render"},
51 "DAG_EVAL_VIEWPORT",
52 0,
53 "Viewport",
54 "Export objects as they appear in the viewport"},
55 {0, nullptr, 0, nullptr, nullptr}};
56
57static const EnumPropertyItem io_obj_path_mode[] = {
58 {PATH_REFERENCE_AUTO, "AUTO", 0, "Auto", "Use relative paths with subdirectories only"},
59 {PATH_REFERENCE_ABSOLUTE, "ABSOLUTE", 0, "Absolute", "Always write absolute paths"},
60 {PATH_REFERENCE_RELATIVE, "RELATIVE", 0, "Relative", "Write relative paths where possible"},
61 {PATH_REFERENCE_MATCH, "MATCH", 0, "Match", "Match absolute/relative setting with input path"},
62 {PATH_REFERENCE_STRIP, "STRIP", 0, "Strip", "Write filename only"},
63 {PATH_REFERENCE_COPY, "COPY", 0, "Copy", "Copy the file to the destination path"},
64 {0, nullptr, 0, nullptr, nullptr}};
65
66static const EnumPropertyItem io_obj_mtl_name_collision_mode[] = {
68 "MAKE_UNIQUE",
69 0,
70 "Make Unique",
71 "Create new materials with unique names for each OBJ file"},
73 "REFERENCE_EXISTING",
74 0,
75 "Reference Existing",
76 "Use existing materials with same name instead of creating new ones"},
77 {0, nullptr, 0, nullptr, nullptr}};
78
79static wmOperatorStatus wm_obj_export_invoke(bContext *C,
80 wmOperator *op,
81 const wmEvent * /*event*/)
82{
84
87}
88
89static wmOperatorStatus wm_obj_export_exec(bContext *C, wmOperator *op)
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 OBJExportParams export_params;
96 export_params.file_base_for_tests[0] = '\0';
97 RNA_string_get(op->ptr, "filepath", export_params.filepath);
98 export_params.blen_filepath = CTX_data_main(C)->filepath;
99 export_params.export_animation = RNA_boolean_get(op->ptr, "export_animation");
100 export_params.start_frame = RNA_int_get(op->ptr, "start_frame");
101 export_params.end_frame = RNA_int_get(op->ptr, "end_frame");
102
103 export_params.forward_axis = eIOAxis(RNA_enum_get(op->ptr, "forward_axis"));
104 export_params.up_axis = eIOAxis(RNA_enum_get(op->ptr, "up_axis"));
105 export_params.global_scale = RNA_float_get(op->ptr, "global_scale");
106 export_params.apply_modifiers = RNA_boolean_get(op->ptr, "apply_modifiers");
107 export_params.apply_transform = RNA_boolean_get(op->ptr, "apply_transform");
108 export_params.export_eval_mode = eEvaluationMode(RNA_enum_get(op->ptr, "export_eval_mode"));
109
110 export_params.export_selected_objects = RNA_boolean_get(op->ptr, "export_selected_objects");
111 export_params.export_uv = RNA_boolean_get(op->ptr, "export_uv");
112 export_params.export_normals = RNA_boolean_get(op->ptr, "export_normals");
113 export_params.export_colors = RNA_boolean_get(op->ptr, "export_colors");
114 export_params.export_materials = RNA_boolean_get(op->ptr, "export_materials");
115 export_params.path_mode = ePathReferenceMode(RNA_enum_get(op->ptr, "path_mode"));
116 export_params.export_triangulated_mesh = RNA_boolean_get(op->ptr, "export_triangulated_mesh");
117 export_params.export_curves_as_nurbs = RNA_boolean_get(op->ptr, "export_curves_as_nurbs");
118 export_params.export_pbr_extensions = RNA_boolean_get(op->ptr, "export_pbr_extensions");
119
120 export_params.export_object_groups = RNA_boolean_get(op->ptr, "export_object_groups");
121 export_params.export_material_groups = RNA_boolean_get(op->ptr, "export_material_groups");
122 export_params.export_vertex_groups = RNA_boolean_get(op->ptr, "export_vertex_groups");
123 export_params.export_smooth_groups = RNA_boolean_get(op->ptr, "export_smooth_groups");
124 export_params.smooth_groups_bitflags = RNA_boolean_get(op->ptr, "smooth_group_bitflags");
125
126 export_params.reports = op->reports;
127
128 RNA_string_get(op->ptr, "collection", export_params.collection);
129
130 OBJ_export(C, &export_params);
131
132 if (BKE_reports_contain(op->reports, RPT_ERROR)) {
133 return OPERATOR_CANCELLED;
134 }
135
136 BKE_report(op->reports, RPT_INFO, "File exported successfully");
137 return OPERATOR_FINISHED;
138}
139
140static void ui_obj_export_settings(const bContext *C, ui::Layout &layout, PointerRNA *ptr)
141{
142 const bool export_animation = RNA_boolean_get(ptr, "export_animation");
143 const bool export_smooth_groups = RNA_boolean_get(ptr, "export_smooth_groups");
144 const bool export_materials = RNA_boolean_get(ptr, "export_materials");
145
146 layout.use_property_split_set(true);
147 layout.use_property_decorate_set(false);
148
149 /* Object General options. */
150 if (ui::Layout *panel = layout.panel(C, "OBJ_export_general", false, IFACE_("General"))) {
151 ui::Layout &col = panel->column(false);
152
153 if (CTX_wm_space_file(C)) {
154 ui::Layout &sub = col.column(false, IFACE_("Include"));
155 sub.prop(ptr, "export_selected_objects", UI_ITEM_NONE, IFACE_("Selection Only"), ICON_NONE);
156 }
157
158 col.prop(ptr, "global_scale", UI_ITEM_NONE, std::nullopt, ICON_NONE);
159 col.prop(ptr, "forward_axis", UI_ITEM_NONE, IFACE_("Forward Axis"), ICON_NONE);
160 col.prop(ptr, "up_axis", UI_ITEM_NONE, IFACE_("Up Axis"), ICON_NONE);
161 }
162
163 /* Geometry options. */
164 if (ui::Layout *panel = layout.panel(C, "OBJ_export_geometry", false, IFACE_("Geometry"))) {
165 ui::Layout &col = panel->column(false);
166 col.prop(ptr, "export_uv", UI_ITEM_NONE, IFACE_("UV Coordinates"), ICON_NONE);
167 col.prop(ptr, "export_normals", UI_ITEM_NONE, IFACE_("Normals"), ICON_NONE);
168 col.prop(ptr, "export_colors", UI_ITEM_NONE, IFACE_("Colors"), ICON_NONE);
169 col.prop(ptr, "export_curves_as_nurbs", UI_ITEM_NONE, IFACE_("Curves as NURBS"), ICON_NONE);
170
171 col.prop(
172 ptr, "export_triangulated_mesh", UI_ITEM_NONE, IFACE_("Triangulated Mesh"), ICON_NONE);
173 col.prop(ptr, "apply_modifiers", UI_ITEM_NONE, IFACE_("Apply Modifiers"), ICON_NONE);
174 col.prop(ptr, "apply_transform", UI_ITEM_NONE, IFACE_("Apply Transform"), ICON_NONE);
175 col.prop(ptr, "export_eval_mode", UI_ITEM_NONE, IFACE_("Properties"), ICON_NONE);
176 }
177
178 /* Grouping options. */
179 if (ui::Layout *panel = layout.panel(C, "OBJ_export_grouping", false, IFACE_("Grouping"))) {
180 ui::Layout &col = panel->column(false);
181 col.prop(ptr, "export_object_groups", UI_ITEM_NONE, IFACE_("Object Groups"), ICON_NONE);
182 col.prop(ptr, "export_material_groups", UI_ITEM_NONE, IFACE_("Material Groups"), ICON_NONE);
183 col.prop(ptr, "export_vertex_groups", UI_ITEM_NONE, IFACE_("Vertex Groups"), ICON_NONE);
184 col.prop(ptr, "export_smooth_groups", UI_ITEM_NONE, IFACE_("Smooth Groups"), ICON_NONE);
185 ui::Layout &sub = col.column(false);
186 sub.enabled_set(export_smooth_groups);
187 sub.prop(
188 ptr, "smooth_group_bitflags", UI_ITEM_NONE, IFACE_("Smooth Group Bitflags"), ICON_NONE);
189 }
190
191 /* Material options. */
192 ui::PanelLayout panel = layout.panel(C, "OBJ_export_materials", false);
193 panel.header->use_property_split_set(false);
194 panel.header->prop(ptr, "export_materials", UI_ITEM_NONE, "", ICON_NONE);
195 panel.header->label(IFACE_("Materials"), ICON_NONE);
196 if (panel.body) {
197 ui::Layout &col = panel.body->column(false);
198 col.enabled_set(export_materials);
199
200 col.prop(ptr, "export_pbr_extensions", UI_ITEM_NONE, IFACE_("PBR Extensions"), ICON_NONE);
201 col.prop(ptr, "path_mode", UI_ITEM_NONE, IFACE_("Path Mode"), ICON_NONE);
202 }
203
204 /* Animation options. */
205 panel = layout.panel(C, "OBJ_export_animation", true);
206 panel.header->use_property_split_set(false);
207 panel.header->prop(ptr, "export_animation", UI_ITEM_NONE, "", ICON_NONE);
208 panel.header->label(IFACE_("Animation"), ICON_NONE);
209 if (panel.body) {
210 ui::Layout &col = panel.body->column(false);
211 col.enabled_set(export_animation);
212
213 col.prop(ptr, "start_frame", UI_ITEM_NONE, IFACE_("Frame Start"), ICON_NONE);
214 col.prop(ptr, "end_frame", UI_ITEM_NONE, IFACE_("End"), ICON_NONE);
215 }
216}
217
218static void wm_obj_export_draw(bContext *C, wmOperator *op)
219{
220 ui_obj_export_settings(C, *op->layout, op->ptr);
221}
222
226static bool wm_obj_export_check(bContext *C, wmOperator *op)
227{
228 char filepath[FILE_MAX];
229 Scene *scene = CTX_data_scene(C);
230 bool changed = false;
231 RNA_string_get(op->ptr, "filepath", filepath);
232
233 if (!BLI_path_extension_check(filepath, ".obj")) {
234 BLI_path_extension_ensure(filepath, FILE_MAX, ".obj");
235 RNA_string_set(op->ptr, "filepath", filepath);
236 changed = true;
237 }
238
239 {
240 int start = RNA_int_get(op->ptr, "start_frame");
241 int end = RNA_int_get(op->ptr, "end_frame");
242 /* Set the defaults. */
243 if (start == INT_MIN) {
244 start = scene->r.sfra;
245 changed = true;
246 }
247 if (end == INT_MAX) {
248 end = scene->r.efra;
249 changed = true;
250 }
251 /* Fix user errors. */
252 if (end < start) {
253 end = start;
254 changed = true;
255 }
256 RNA_int_set(op->ptr, "start_frame", start);
257 RNA_int_set(op->ptr, "end_frame", end);
258 }
259 return changed;
260}
261
263{
264 PropertyRNA *prop;
265
266 ot->name = "Export Wavefront OBJ";
267 ot->description = "Save the scene to a Wavefront OBJ file";
268 ot->idname = "WM_OT_obj_export";
269
270 ot->invoke = wm_obj_export_invoke;
271 ot->exec = wm_obj_export_exec;
272 ot->poll = WM_operator_winactive;
273 ot->ui = wm_obj_export_draw;
274 ot->check = wm_obj_export_check;
275
276 ot->flag = OPTYPE_PRESET;
277
281 FILE_SAVE,
285
286 /* Animation options. */
287 RNA_def_boolean(ot->srna,
288 "export_animation",
289 false,
290 "Export Animation",
291 "Export multiple frames instead of the current frame only");
292 RNA_def_int(ot->srna,
293 "start_frame",
294 INT_MIN, /* wm_obj_export_check uses this to set scene->r.sfra. */
295 INT_MIN,
296 INT_MAX,
297 "Start Frame",
298 "The first frame to be exported",
299 INT_MIN,
300 INT_MAX);
301 RNA_def_int(ot->srna,
302 "end_frame",
303 INT_MAX, /* wm_obj_export_check uses this to set scene->r.efra. */
304 INT_MIN,
305 INT_MAX,
306 "End Frame",
307 "The last frame to be exported",
308 INT_MIN,
309 INT_MAX);
310 /* Object transform options. */
311 prop = RNA_def_enum(
312 ot->srna, "forward_axis", io_transform_axis, IO_AXIS_NEGATIVE_Z, "Forward Axis", "");
314 prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Y, "Up Axis", "");
317 ot->srna,
318 "global_scale",
319 1.0f,
320 0.0001f,
321 10000.0f,
322 "Scale",
323 "Value by which to enlarge or shrink the objects with respect to the world's origin",
324 0.0001f,
325 10000.0f);
326 /* File Writer options. */
328 ot->srna, "apply_modifiers", true, "Apply Modifiers", "Apply modifiers to exported meshes");
329 RNA_def_boolean(ot->srna,
330 "apply_transform",
331 true,
332 "Apply Transform",
333 "Apply object transforms to exported vertices");
334 RNA_def_enum(ot->srna,
335 "export_eval_mode",
336 io_obj_export_evaluation_mode,
338 "Object Properties",
339 "Determines properties like object visibility, modifiers etc., where they differ "
340 "for Render and Viewport");
341 RNA_def_boolean(ot->srna,
342 "export_selected_objects",
343 false,
344 "Export Selected Objects",
345 "Export only selected objects instead of all supported objects");
346 RNA_def_boolean(ot->srna, "export_uv", true, "Export UVs", "");
347 RNA_def_boolean(ot->srna,
348 "export_normals",
349 true,
350 "Export Normals",
351 "Export per-face normals if the face is flat-shaded, per-face-corner "
352 "normals if smooth-shaded");
353 RNA_def_boolean(ot->srna, "export_colors", false, "Export Colors", "Export per-vertex colors");
354 RNA_def_boolean(ot->srna,
355 "export_materials",
356 true,
357 "Export Materials",
358 "Export MTL library. There must be a Principled-BSDF node for image textures to "
359 "be exported to the MTL file");
360 RNA_def_boolean(ot->srna,
361 "export_pbr_extensions",
362 false,
363 "Export Materials with PBR Extensions",
364 "Export MTL library using PBR extensions (roughness, metallic, sheen, "
365 "coat, anisotropy, transmission)");
366 prop = RNA_def_enum(ot->srna,
367 "path_mode",
368 io_obj_path_mode,
370 "Path Mode",
371 "Method used to reference paths");
373 RNA_def_boolean(ot->srna,
374 "export_triangulated_mesh",
375 false,
376 "Export Triangulated Mesh",
377 "All ngons with four or more vertices will be triangulated. Meshes in "
378 "the scene will not be affected. Behaves like Triangulate Modifier with "
379 "ngon-method: \"Beauty\", quad-method: \"Shortest Diagonal\", min vertices: 4");
380 RNA_def_boolean(ot->srna,
381 "export_curves_as_nurbs",
382 false,
383 "Export Curves as NURBS",
384 "Export curves in parametric form instead of exporting as mesh");
385
386 RNA_def_boolean(ot->srna,
387 "export_object_groups",
388 false,
389 "Export Object Groups",
390 "Append mesh name to object name, separated by a '_'");
391 RNA_def_boolean(ot->srna,
392 "export_material_groups",
393 false,
394 "Export Material Groups",
395 "Generate an OBJ group for each part of a geometry using a different material");
397 ot->srna,
398 "export_vertex_groups",
399 false,
400 "Export Vertex Groups",
401 "Export the name of the vertex group of a face. It is approximated "
402 "by choosing the vertex group with the most members among the vertices of a face");
403 RNA_def_boolean(ot->srna,
404 "export_smooth_groups",
405 false,
406 "Export Smooth Groups",
407 "Generate smooth groups identifiers for each group of smooth faces, as "
408 "unique integer values by default");
410 ot->srna,
411 "smooth_group_bitflags",
412 false,
413 "Bitflags Smooth Groups",
414 "If exporting smoothgroups, generate 'bitflags' values for the groups, instead of "
415 "unique integer values. The same bitflag value can be re-used for different groups of "
416 "smooth faces, as long as they have no common sharp edges or vertices");
417
418 /* Only show `.obj` or `.mtl` files by default. */
419 prop = RNA_def_string(ot->srna, "filter_glob", "*.obj;*.mtl", 0, "Extension Filter", "");
421
422 prop = RNA_def_string(ot->srna, "collection", nullptr, MAX_ID_NAME - 2, "Collection", nullptr);
424}
425
426static wmOperatorStatus wm_obj_import_exec(bContext *C, wmOperator *op)
427{
428 OBJImportParams import_params;
429 import_params.global_scale = RNA_float_get(op->ptr, "global_scale");
430 import_params.clamp_size = RNA_float_get(op->ptr, "clamp_size");
431 import_params.forward_axis = eIOAxis(RNA_enum_get(op->ptr, "forward_axis"));
432 import_params.up_axis = eIOAxis(RNA_enum_get(op->ptr, "up_axis"));
433 import_params.use_split_objects = RNA_boolean_get(op->ptr, "use_split_objects");
434 import_params.use_split_groups = RNA_boolean_get(op->ptr, "use_split_groups");
435 import_params.import_vertex_groups = RNA_boolean_get(op->ptr, "import_vertex_groups");
436 import_params.validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes");
437 import_params.close_spline_loops = RNA_boolean_get(op->ptr, "close_spline_loops");
438 char separator[2] = {};
439 RNA_string_get(op->ptr, "collection_separator", separator);
440 import_params.collection_separator = separator[0];
441 import_params.relative_paths = ((U.flag & USER_RELPATHS) != 0);
442 import_params.clear_selection = true;
443 import_params.mtl_name_collision_mode = eOBJMtlNameCollisionMode(
444 RNA_enum_get(op->ptr, "mtl_name_collision_mode"));
445
446 import_params.reports = op->reports;
447
448 const auto paths = ed::io::paths_from_operator_properties(op->ptr);
449
450 if (paths.is_empty()) {
451 BKE_report(op->reports, RPT_ERROR, "No filepath given");
452 return OPERATOR_CANCELLED;
453 }
454 for (const auto &path : paths) {
455 STRNCPY(import_params.filepath, path.c_str());
456 OBJ_import(C, &import_params);
457 /* Only first import clears selection. */
458 import_params.clear_selection = false;
459 };
460
461 Scene *scene = CTX_data_scene(C);
466
467 return OPERATOR_FINISHED;
468}
469
470static void ui_obj_import_settings(const bContext *C, ui::Layout &layout, PointerRNA *ptr)
471{
472 layout.use_property_split_set(true);
473 layout.use_property_decorate_set(false);
474
475 if (ui::Layout *panel = layout.panel(C, "OBJ_import_general", false, IFACE_("General"))) {
476 ui::Layout &col = panel->column(false);
477 col.prop(ptr, "global_scale", UI_ITEM_NONE, std::nullopt, ICON_NONE);
478 col.prop(ptr, "clamp_size", UI_ITEM_NONE, std::nullopt, ICON_NONE);
479 col.prop(ptr, "forward_axis", UI_ITEM_NONE, IFACE_("Forward Axis"), ICON_NONE);
480 col.prop(ptr, "up_axis", UI_ITEM_NONE, IFACE_("Up Axis"), ICON_NONE);
481 }
482
483 if (ui::Layout *panel = layout.panel(C, "OBJ_import_options", false, IFACE_("Options"))) {
484 ui::Layout &col = panel->column(false);
485 col.prop(ptr, "use_split_objects", UI_ITEM_NONE, std::nullopt, ICON_NONE);
486 col.prop(ptr, "use_split_groups", UI_ITEM_NONE, std::nullopt, ICON_NONE);
487 col.prop(ptr, "import_vertex_groups", UI_ITEM_NONE, std::nullopt, ICON_NONE);
488 col.prop(ptr, "validate_meshes", UI_ITEM_NONE, std::nullopt, ICON_NONE);
489 col.prop(ptr, "close_spline_loops", UI_ITEM_NONE, std::nullopt, ICON_NONE);
490 col.prop(ptr, "collection_separator", UI_ITEM_NONE, std::nullopt, ICON_NONE);
491 }
492
493 if (ui::Layout *panel = layout.panel(C, "OBJ_import_materials", false, IFACE_("Materials"))) {
494 ui::Layout &col = panel->column(false);
495 col.prop(ptr, "mtl_name_collision_mode", UI_ITEM_NONE, IFACE_("Name Collision"), ICON_NONE);
496 }
497}
498
499static void wm_obj_import_draw(bContext *C, wmOperator *op)
500{
501 ui_obj_import_settings(C, *op->layout, op->ptr);
502}
503
505{
506 PropertyRNA *prop;
507
508 ot->name = "Import Wavefront OBJ";
509 ot->description = "Load a Wavefront OBJ scene";
510 ot->idname = "WM_OT_obj_import";
511 ot->flag = OPTYPE_UNDO | OPTYPE_PRESET;
512
514 ot->exec = wm_obj_import_exec;
515 ot->poll = WM_operator_winactive;
516 ot->ui = wm_obj_import_draw;
517
526
528 ot->srna,
529 "global_scale",
530 1.0f,
531 0.0001f,
532 10000.0f,
533 "Scale",
534 "Value by which to enlarge or shrink the objects with respect to the world's origin",
535 0.0001f,
536 10000.0f);
538 ot->srna,
539 "clamp_size",
540 0.0f,
541 0.0f,
542 1000.0f,
543 "Clamp Bounding Box",
544 "Resize the objects to keep bounding box under this value. Value 0 disables clamping",
545 0.0f,
546 1000.0f);
547 prop = RNA_def_enum(
548 ot->srna, "forward_axis", io_transform_axis, IO_AXIS_NEGATIVE_Z, "Forward Axis", "");
550 prop = RNA_def_enum(ot->srna, "up_axis", io_transform_axis, IO_AXIS_Y, "Up Axis", "");
552 RNA_def_boolean(ot->srna,
553 "use_split_objects",
554 true,
555 "Split By Object",
556 "Import each OBJ 'o' as a separate object");
557 RNA_def_boolean(ot->srna,
558 "use_split_groups",
559 false,
560 "Split By Group",
561 "Import each OBJ 'g' as a separate object");
562 RNA_def_boolean(ot->srna,
563 "import_vertex_groups",
564 false,
565 "Vertex Groups",
566 "Import OBJ groups as vertex groups");
568 ot->srna,
569 "validate_meshes",
570 true,
571 "Validate Meshes",
572 "Ensure the data is valid "
573 "(when disabled, data may be imported which causes crashes displaying or editing)");
574 RNA_def_boolean(ot->srna,
575 "close_spline_loops",
576 true,
577 "Detect Cyclic Curves",
578 "Join curve endpoints if overlapping control points are detected "
579 "(if disabled, no curves will be cyclic)");
580
581 RNA_def_string(ot->srna,
582 "collection_separator",
583 nullptr,
584 2,
585 "Path Separator",
586 "Character used to separate objects name into hierarchical structure");
587
588 /* Material options */
589 RNA_def_enum(ot->srna,
590 "mtl_name_collision_mode",
591 io_obj_mtl_name_collision_mode,
593 "Material Name Collision",
594 "How to handle naming collisions when importing materials");
595
596 /* Only show `.obj` or `.mtl` files by default. */
597 prop = RNA_def_string(ot->srna, "filter_glob", "*.obj;*.mtl", 0, "Extension Filter", "");
599}
600
601namespace ed::io {
603{
604 auto fh = std::make_unique<bke::FileHandlerType>();
605 STRNCPY_UTF8(fh->idname, "IO_FH_obj");
606 STRNCPY_UTF8(fh->import_operator, "WM_OT_obj_import");
607 STRNCPY_UTF8(fh->export_operator, "WM_OT_obj_export");
608 STRNCPY_UTF8(fh->label, "Wavefront OBJ");
609 STRNCPY_UTF8(fh->file_extensions_str, ".obj");
610 fh->poll_drop = poll_file_object_drop;
611 bke::file_handler_add(std::move(fh));
612}
613} // namespace ed::io
614} // namespace blender
615
616#endif /* WITH_IO_WAVEFRONT_OBJ */
#define FILE_MAX
#define STRNCPY_UTF8(dst, src)
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_EDITOR_FILEBROWSER
#define MAX_ID_NAME
Definition DNA_ID.h:367
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define ND_OB_ACTIVE
Definition WM_types.hh:459
#define ND_OB_SELECT
Definition WM_types.hh:461
#define NC_SCENE
Definition WM_types.hh:391
#define ND_LAYER_CONTENT
Definition WM_types.hh:472
#define INT_MAX
void file_handler_add(std::unique_ptr< FileHandlerType > file_handler)
bool poll_file_object_drop(const bContext *C, bke::FileHandlerType *)
Definition io_utils.cc:62
Vector< std::string > paths_from_operator_properties(PointerRNA *ptr)
Definition io_utils.cc:79
wmOperatorStatus filesel_drop_import_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition io_utils.cc:30
void obj_file_handler_add()
BMesh Iterators.
UserDef U
Definition blender.cc:58
void io_ui_forward_axis_update(Main *, Scene *, PointerRNA *ptr)
char * STRNCPY(char(&dst)[N], const char *src)
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)
void OBJ_export(bContext *C, const OBJExportParams *export_params)
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
bool RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, bool use_ghost)
int RNA_int_get(PointerRNA *ptr, const char *name)
void WM_OT_obj_export(wmOperatorType *ot)
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)
void ED_outliner_select_sync_from_object_tag(bContext *C)
void WM_OT_obj_import(wmOperatorType *ot)
bool BLI_path_extension_ensure(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
@ WM_FILESEL_DIRECTORY
Definition WM_api.hh:1330
@ WM_FILESEL_SHOW_PROPS
Definition WM_api.hh:1335
@ WM_FILESEL_FILES
Definition WM_api.hh:1333
@ WM_FILESEL_FILEPATH
Definition WM_api.hh:1332
void ED_fileselect_ensure_default_filepath(bContext *C, wmOperator *op, const char *extension)
Definition filesel.cc:1515
bool BKE_reports_contain(ReportList *reports, eReportType level)
Definition report.cc:394
@ DAG_EVAL_VIEWPORT
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
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)
@ FILE_SAVE
Definition WM_api.hh:1342
@ FILE_OPENFILE
Definition WM_api.hh:1341
bool WM_operator_winactive(bContext *C)
Main * CTX_data_main(const bContext *C)
bool BLI_path_extension_check(const char *path, const char *ext) ATTR_NONNULL(1
void OBJ_import(bContext *C, const OBJImportParams *import_params)
@ PROP_HIDDEN
Definition RNA_types.hh:408
void RNA_def_property_update_runtime(PropertyRNA *prop, RNAPropertyUpdateFunc func)
@ OBJ_MTL_NAME_COLLISION_REFERENCE_EXISTING
@ OBJ_MTL_NAME_COLLISION_MAKE_UNIQUE
SpaceFile * CTX_wm_space_file(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_PRESET
Definition WM_types.hh:203
std::string RNA_string_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
const EnumPropertyItem io_transform_axis[]
void io_ui_up_axis_update(Main *, Scene *, PointerRNA *ptr)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
float RNA_float_get(PointerRNA *ptr, const char *name)
void WM_event_add_fileselect(bContext *C, wmOperator *op)
char filepath[1024]
Definition BKE_main.hh:267
char file_base_for_tests[FILE_MAX]
void enabled_set(bool enabled)
void use_property_split_set(bool is_sep)
PanelLayout panel(const bContext *C, StringRef idname, bool default_closed)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
Layout & column(bool align)