9#ifdef WITH_IO_WAVEFRONT_OBJ
49 {
DAG_EVAL_RENDER,
"DAG_EVAL_RENDER", 0,
"Render",
"Export objects as they appear in render"},
54 "Export objects as they appear in the viewport"},
55 {0,
nullptr, 0,
nullptr,
nullptr}};
64 {0,
nullptr, 0,
nullptr,
nullptr}};
71 "Create new materials with unique names for each OBJ file"},
76 "Use existing materials with same name instead of creating new ones"},
77 {0,
nullptr, 0,
nullptr,
nullptr}};
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");
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");
110 export_params.export_selected_objects =
RNA_boolean_get(op->ptr,
"export_selected_objects");
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");
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");
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");
126 export_params.reports = op->reports;
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");
146 layout.use_property_split_set(
true);
147 layout.use_property_decorate_set(
false);
169 col.prop(ptr,
"export_curves_as_nurbs",
UI_ITEM_NONE,
IFACE_(
"Curves as NURBS"), ICON_NONE);
172 ptr,
"export_triangulated_mesh",
UI_ITEM_NONE,
IFACE_(
"Triangulated Mesh"), 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);
188 ptr,
"smooth_group_bitflags",
UI_ITEM_NONE,
IFACE_(
"Smooth Group Bitflags"), ICON_NONE);
194 panel.header->prop(ptr,
"export_materials",
UI_ITEM_NONE,
"", ICON_NONE);
195 panel.header->label(
IFACE_(
"Materials"), ICON_NONE);
200 col.prop(ptr,
"export_pbr_extensions",
UI_ITEM_NONE,
IFACE_(
"PBR Extensions"), ICON_NONE);
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);
220 ui_obj_export_settings(
C, *op->layout, op->ptr);
230 bool changed =
false;
243 if (start == INT_MIN) {
244 start = scene->r.sfra;
266 ot->
name =
"Export Wavefront OBJ";
267 ot->description =
"Save the scene to a Wavefront OBJ file";
268 ot->idname =
"WM_OT_obj_export";
270 ot->invoke = wm_obj_export_invoke;
271 ot->exec = wm_obj_export_exec;
273 ot->ui = wm_obj_export_draw;
274 ot->check = wm_obj_export_check;
291 "Export multiple frames instead of the current frame only");
298 "The first frame to be exported",
307 "The last frame to be exported",
323 "Value by which to enlarge or shrink the objects with respect to the world's origin",
328 ot->srna,
"apply_modifiers",
true,
"Apply Modifiers",
"Apply modifiers to exported meshes");
333 "Apply object transforms to exported vertices");
336 io_obj_export_evaluation_mode,
339 "Determines properties like object visibility, modifiers etc., where they differ "
340 "for Render and Viewport");
342 "export_selected_objects",
344 "Export Selected Objects",
345 "Export only selected objects instead of all supported objects");
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");
358 "Export MTL library. There must be a Principled-BSDF node for image textures to "
359 "be exported to the MTL file");
361 "export_pbr_extensions",
363 "Export Materials with PBR Extensions",
364 "Export MTL library using PBR extensions (roughness, metallic, sheen, "
365 "coat, anisotropy, transmission)");
371 "Method used to reference paths");
374 "export_triangulated_mesh",
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");
381 "export_curves_as_nurbs",
383 "Export Curves as NURBS",
384 "Export curves in parametric form instead of exporting as mesh");
387 "export_object_groups",
389 "Export Object Groups",
390 "Append mesh name to object name, separated by a '_'");
392 "export_material_groups",
394 "Export Material Groups",
395 "Generate an OBJ group for each part of a geometry using a different material");
398 "export_vertex_groups",
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");
404 "export_smooth_groups",
406 "Export Smooth Groups",
407 "Generate smooth groups identifiers for each group of smooth faces, as "
408 "unique integer values by default");
411 "smooth_group_bitflags",
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");
419 prop =
RNA_def_string(ot->srna,
"filter_glob",
"*.obj;*.mtl", 0,
"Extension Filter",
"");
430 import_params.clamp_size =
RNA_float_get(op->ptr,
"clamp_size");
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] = {};
440 import_params.collection_separator = separator[0];
442 import_params.clear_selection =
true;
446 import_params.reports = op->reports;
450 if (paths.is_empty()) {
454 for (
const auto &path : paths) {
455 STRNCPY(import_params.filepath, path.c_str());
458 import_params.clear_selection =
false;
472 layout.use_property_split_set(
true);
473 layout.use_property_decorate_set(
false);
478 col.prop(ptr,
"clamp_size",
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);
501 ui_obj_import_settings(
C, *op->layout, op->ptr);
508 ot->
name =
"Import Wavefront OBJ";
509 ot->description =
"Load a Wavefront OBJ scene";
510 ot->idname =
"WM_OT_obj_import";
514 ot->exec = wm_obj_import_exec;
516 ot->ui = wm_obj_import_draw;
534 "Value by which to enlarge or shrink the objects with respect to the world's origin",
543 "Clamp Bounding Box",
544 "Resize the objects to keep bounding box under this value. Value 0 disables clamping",
556 "Import each OBJ 'o' as a separate object");
561 "Import each OBJ 'g' as a separate object");
563 "import_vertex_groups",
566 "Import OBJ groups as vertex groups");
572 "Ensure the data is valid "
573 "(when disabled, data may be imported which causes crashes displaying or editing)");
575 "close_spline_loops",
577 "Detect Cyclic Curves",
578 "Join curve endpoints if overlapping control points are detected "
579 "(if disabled, no curves will be cyclic)");
582 "collection_separator",
586 "Character used to separate objects name into hierarchical structure");
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");
597 prop =
RNA_def_string(ot->srna,
"filter_glob",
"*.obj;*.mtl", 0,
"Extension Filter",
"");
604 auto fh = std::make_unique<bke::FileHandlerType>();
#define STRNCPY_UTF8(dst, src)
#define BLT_I18NCONTEXT_EDITOR_FILEBROWSER
void file_handler_add(std::unique_ptr< FileHandlerType > file_handler)
bool poll_file_object_drop(const bContext *C, bke::FileHandlerType *)
Vector< std::string > paths_from_operator_properties(PointerRNA *ptr)
wmOperatorStatus filesel_drop_import_invoke(bContext *C, wmOperator *op, const wmEvent *)
void obj_file_handler_add()
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)
void ED_fileselect_ensure_default_filepath(bContext *C, wmOperator *op, const char *extension)
bool BKE_reports_contain(ReportList *reports, eReportType level)
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)
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)
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)
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)
@ PATH_REFERENCE_RELATIVE
@ PATH_REFERENCE_ABSOLUTE
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)