Blender V5.3
io_usd.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#ifdef WITH_USD
10# include "DNA_modifier_types.h"
11# include "DNA_space_types.h"
12
13# include "BKE_context.hh"
14# include "BKE_file_handler.hh"
15# include "BKE_report.hh"
16
17# include "BLI_path_utils.hh"
18# include "BLI_string_utf8.hh"
19
20# include "BLT_translation.hh"
21
22# include "ED_fileselect.hh"
23# include "ED_object.hh"
24
25# include "MEM_guardedalloc.h"
26
27# include "RNA_access.hh"
28# include "RNA_define.hh"
29# include "RNA_enum_types.hh"
30
31# include "UI_interface.hh"
32# include "UI_interface_layout.hh"
33# include "UI_resources.hh"
34
35# include "WM_api.hh"
36# include "WM_types.hh"
37
38# include "DEG_depsgraph.hh"
39
40# include "IO_orientation.hh"
41# include "io_usd.hh"
42# include "io_utils.hh"
43# include "usd.hh"
44
45# include <string>
46# include <utility>
47
48namespace blender {
49
50using namespace io::usd;
51
52const EnumPropertyItem rna_enum_usd_export_evaluation_mode_items[] = {
54 "RENDER",
55 0,
56 "Render",
57 "Use Render settings for object visibility, modifier settings, etc"},
59 "VIEWPORT",
60 0,
61 "Viewport",
62 "Use Viewport settings for object visibility, modifier settings, etc"},
63 {0, nullptr, 0, nullptr, nullptr},
64};
65
66const EnumPropertyItem rna_enum_usd_mtl_name_collision_mode_items[] = {
67 {int(MtlNameCollisionMode::MakeUnique),
68 "MAKE_UNIQUE",
69 0,
70 "Make Unique",
71 "Import each USD material as a unique Blender material"},
72 {int(MtlNameCollisionMode::ReferenceExisting),
73 "REFERENCE_EXISTING",
74 0,
75 "Reference Existing",
76 "If a material with the same name already exists, reference that instead of importing"},
77 {0, nullptr, 0, nullptr, nullptr},
78};
79
80const EnumPropertyItem rna_enum_usd_property_import_mode_items[] = {
81 {int(PropertyImportMode::None), "NONE", 0, "None", "Do not import USD custom attributes"},
82 {int(PropertyImportMode::User),
83 "USER",
84 0,
85 "User",
86 "Import USD attributes in the 'userProperties' namespace as Blender custom "
87 "properties. The namespace will be stripped from the property names"},
88 {int(PropertyImportMode::All),
89 "ALL",
90 0,
91 "All Custom",
92 "Import all USD custom attributes as Blender custom properties. "
93 "Namespaces will be retained in the property names"},
94 {0, nullptr, 0, nullptr, nullptr},
95};
96
97const EnumPropertyItem rna_enum_usd_tex_import_mode_items[] = {
98 {int(TexImportMode::None), "IMPORT_NONE", 0, "None", "Don't import textures"},
99 {int(TexImportMode::Pack), "IMPORT_PACK", 0, "Packed", "Import textures as packed data"},
100 {int(TexImportMode::Copy), "IMPORT_COPY", 0, "Copy", "Copy files to textures directory"},
101 {0, nullptr, 0, nullptr, nullptr},
102};
103
104const EnumPropertyItem rna_enum_usd_tex_name_collision_mode_items[] = {
105 {int(TexNameCollisionMode::UseExisting),
106 "USE_EXISTING",
107 0,
108 "Use Existing",
109 "If a file with the same name already exists, use that instead of copying"},
110 {int(TexNameCollisionMode::Overwrite),
111 "OVERWRITE",
112 0,
113 "Overwrite",
114 "Overwrite existing files"},
115 {0, nullptr, 0, nullptr, nullptr},
116};
117
118const EnumPropertyItem rna_enum_usd_export_subdiv_mode_items[] = {
119 {int(SubdivExportMode::Ignore),
120 "IGNORE",
121 0,
122 "Ignore",
123 "Scheme = None. Export base mesh without subdivision"},
124 {int(SubdivExportMode::Tessellate),
125 "TESSELLATE",
126 0,
127 "Tessellate",
128 "Scheme = None. Export subdivided mesh"},
129 {int(SubdivExportMode::Match),
130 "BEST_MATCH",
131 0,
132 "Best Match",
133 "Scheme = Catmull-Clark, when possible. "
134 "Reverts to exporting the subdivided mesh for the Simple subdivision type"},
135 {0, nullptr, 0, nullptr, nullptr},
136};
137
138const EnumPropertyItem rna_enum_usd_xform_op_mode_items[] = {
139 {int(XformOpMode::TRS),
140 "TRS",
141 0,
142 "Translate, Rotate, Scale",
143 "Export with translate, rotate, and scale Xform operators"},
144 {int(XformOpMode::TOS),
145 "TOS",
146 0,
147 "Translate, Orient, Scale",
148 "Export with translate, orient quaternion, and scale Xform operators"},
149 {int(XformOpMode::MAT), "MAT", 0, "Matrix", "Export matrix operator"},
150 {0, nullptr, 0, nullptr, nullptr},
151};
152
153const EnumPropertyItem rna_enum_usdz_downscale_size[] = {
154 {int(TextureDownscaleSize::Keep), "KEEP", 0, "Keep", "Keep all current texture sizes"},
155 {int(TextureDownscaleSize::Size256), "256", 0, "256", "Resize to a maximum of 256 pixels"},
156 {int(TextureDownscaleSize::Size512), "512", 0, "512", "Resize to a maximum of 512 pixels"},
157 {int(TextureDownscaleSize::Size1024), "1024", 0, "1024", "Resize to a maximum of 1024 pixels"},
158 {int(TextureDownscaleSize::Size2048), "2048", 0, "2048", "Resize to a maximum of 2048 pixels"},
159 {int(TextureDownscaleSize::Size4096), "4096", 0, "4096", "Resize to a maximum of 4096 pixels"},
160 {int(TextureDownscaleSize::Custom), "CUSTOM", 0, "Custom", "Specify a custom size"},
161 {0, nullptr, 0, nullptr, nullptr},
162};
163
164const EnumPropertyItem rna_enum_usd_tex_export_mode_items[] = {
165 {int(TexExportMode::Keep), "KEEP", 0, "Keep", "Use original location of textures"},
166 {int(TexExportMode::Preserve),
167 "PRESERVE",
168 0,
169 "Preserve",
170 "Preserve file paths of textures from already imported USD files.\n"
171 "Export remaining textures to a 'textures' folder next to the USD file"},
172 {int(TexExportMode::NewPath),
173 "NEW",
174 0,
175 "New Path",
176 "Export textures to a 'textures' folder next to the USD file"},
177 {0, nullptr, 0, nullptr, nullptr}};
178
179const EnumPropertyItem rna_enum_usd_mtl_purpose_items[] = {
180 {int(MtlPurpose::All),
181 "MTL_ALL_PURPOSE",
182 0,
183 "All Purpose",
184 "Attempt to import 'allPurpose' materials."},
185 {int(MtlPurpose::Preview),
186 "MTL_PREVIEW",
187 0,
188 "Preview",
189 "Attempt to import 'preview' materials. "
190 "Load 'allPurpose' materials as a fallback"},
191 {int(MtlPurpose::Full),
192 "MTL_FULL",
193 0,
194 "Full",
195 "Attempt to import 'full' materials. "
196 "Load 'allPurpose' or 'preview' materials, in that order, as a fallback"},
197 {0, nullptr, 0, nullptr, nullptr},
198};
199
200const EnumPropertyItem rna_enum_usd_convert_scene_units_items[] = {
201 {int(SceneUnits::Meters), "METERS", 0, "Meters", "Scene meters per unit to 1.0"},
202 {int(SceneUnits::Kilometers),
203 "KILOMETERS",
204 0,
205 "Kilometers",
206 "Scene meters per unit to 1000.0"},
207 {int(SceneUnits::Centimeters),
208 "CENTIMETERS",
209 0,
210 "Centimeters",
211 "Scene meters per unit to 0.01"},
212 {int(SceneUnits::Millimeters),
213 "MILLIMETERS",
214 0,
215 "Millimeters",
216 "Scene meters per unit to 0.001"},
217 {int(SceneUnits::Inches), "INCHES", 0, "Inches", "Scene meters per unit to 0.0254"},
218 {int(SceneUnits::Feet), "FEET", 0, "Feet", "Scene meters per unit to 0.3048"},
219 {int(SceneUnits::Yards), "YARDS", 0, "Yards", "Scene meters per unit to 0.9144"},
220 {int(SceneUnits::Custom),
221 "CUSTOM",
222 0,
223 "Custom",
224 "Specify a custom scene meters per unit value"},
225 {0, nullptr, 0, nullptr, nullptr},
226};
227
228/* Stored in the wmOperator's customdata field to indicate it should run as a background job.
229 * This is set when the operator is invoked, and not set when it is only executed. */
230struct USDOperatorOptions {
231 bool as_background_job;
232};
233
234static void free_operator_customdata(wmOperator *op)
235{
236 if (op->customdata) {
237 USDOperatorOptions *options = static_cast<USDOperatorOptions *>(op->customdata);
238 MEM_delete(options);
239 op->customdata = nullptr;
240 }
241}
242
243/* Ensure that the prim_path is not set to
244 * the absolute root path '/'. */
245static void process_prim_path(std::string &prim_path)
246{
247 if (prim_path.empty()) {
248 return;
249 }
250
251 /* The absolute root "/" path indicates a no-op, so clear the string. */
252 if (prim_path == "/") {
253 prim_path.clear();
254 }
255 /* If a prim path doesn't start with a "/" it is invalid when creating the prim. */
256 else if (prim_path[0] != '/') {
257 prim_path.insert(0, 1, '/');
258 }
259}
260
261static wmOperatorStatus wm_usd_export_invoke(bContext *C,
262 wmOperator *op,
263 const wmEvent * /*event*/)
264{
265 USDOperatorOptions *options = MEM_new_zeroed<USDOperatorOptions>("USDOperatorOptions");
266 options->as_background_job = true;
267 op->customdata = options;
268
270
272
274}
275
276static wmOperatorStatus wm_usd_export_exec(bContext *C, wmOperator *op)
277{
278 if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) {
279 BKE_report(op->reports, RPT_ERROR, "No filepath given");
280 free_operator_customdata(op);
281 return OPERATOR_CANCELLED;
282 }
283
284 const USDOperatorOptions *options = static_cast<USDOperatorOptions *>(op->customdata);
285 const bool as_background_job = (options != nullptr && options->as_background_job);
286 free_operator_customdata(op);
287
288 char filepath[FILE_MAX];
289 RNA_string_get(op->ptr, "filepath", filepath);
290
291 const TexExportMode textures_mode = TexExportMode(RNA_enum_get(op->ptr, "export_textures_mode"));
292 bool export_textures = false;
293 bool use_original_paths = false;
294
295 switch (textures_mode) {
296 case TexExportMode::Preserve:
297 export_textures = false;
298 use_original_paths = true;
299 break;
300 case TexExportMode::NewPath:
301 export_textures = true;
302 use_original_paths = false;
303 break;
304 case TexExportMode::Keep:
305 export_textures = false;
306 use_original_paths = false;
307 break;
308 default:
310 break;
311 }
312
313 USDExportParams params;
314 params.export_animation = RNA_boolean_get(op->ptr, "export_animation");
315 params.incremental_frames = RNA_int_get(op->ptr, "incremental_frames");
316 params.selected_objects_only = RNA_boolean_get(op->ptr, "selected_objects_only");
317
318 params.export_meshes = RNA_boolean_get(op->ptr, "export_meshes");
319 params.export_lights = RNA_boolean_get(op->ptr, "export_lights");
320 params.convert_world_material = params.export_lights &&
321 RNA_boolean_get(op->ptr, "convert_world_material");
322 params.export_cameras = RNA_boolean_get(op->ptr, "export_cameras");
323 params.export_curves = RNA_boolean_get(op->ptr, "export_curves");
324 params.export_points = RNA_boolean_get(op->ptr, "export_points");
325 params.export_volumes = RNA_boolean_get(op->ptr, "export_volumes");
326 params.export_hair = RNA_boolean_get(op->ptr, "export_hair");
327 params.export_uvmaps = RNA_boolean_get(op->ptr, "export_uvmaps");
328 params.rename_uvmaps = RNA_boolean_get(op->ptr, "rename_uvmaps");
329 params.export_normals = RNA_boolean_get(op->ptr, "export_normals");
330 params.export_mesh_colors = RNA_boolean_get(op->ptr, "export_mesh_colors");
331 params.export_materials = RNA_boolean_get(op->ptr, "export_materials");
332
333 params.export_armatures = RNA_boolean_get(op->ptr, "export_armatures");
334 params.export_shapekeys = RNA_boolean_get(op->ptr, "export_shapekeys");
335 params.only_deform_bones = RNA_boolean_get(op->ptr, "only_deform_bones");
336
337 params.use_instancing = RNA_boolean_get(op->ptr, "use_instancing");
338 params.export_custom_properties = RNA_boolean_get(op->ptr, "export_custom_properties");
339 params.author_blender_name = RNA_boolean_get(op->ptr, "author_blender_name");
340 params.allow_unicode = RNA_boolean_get(op->ptr, "allow_unicode");
341
342 params.export_subdiv = SubdivExportMode(RNA_enum_get(op->ptr, "export_subdivision"));
343 params.evaluation_mode = eEvaluationMode(RNA_enum_get(op->ptr, "evaluation_mode"));
344
345 params.generate_preview_surface = RNA_boolean_get(op->ptr, "generate_preview_surface");
346 params.generate_materialx_network = RNA_boolean_get(op->ptr, "generate_materialx_network");
347 params.overwrite_textures = RNA_boolean_get(op->ptr, "overwrite_textures");
348 params.relative_paths = RNA_boolean_get(op->ptr, "relative_paths");
349 params.export_textures = export_textures;
350 params.use_original_paths = use_original_paths;
351
352 params.triangulate_meshes = RNA_boolean_get(op->ptr, "triangulate_meshes");
353 params.quad_method = RNA_enum_get(op->ptr, "quad_method");
354 params.ngon_method = RNA_enum_get(op->ptr, "ngon_method");
355
356 params.convert_orientation = RNA_boolean_get(op->ptr, "convert_orientation");
357 params.forward_axis = eIOAxis(RNA_enum_get(op->ptr, "export_global_forward_selection"));
358 params.up_axis = eIOAxis(RNA_enum_get(op->ptr, "export_global_up_selection"));
359 params.xform_op_mode = XformOpMode(RNA_enum_get(op->ptr, "xform_op_mode"));
360
361 params.usdz_downscale_size = TextureDownscaleSize(RNA_enum_get(op->ptr, "usdz_downscale_size"));
362 params.usdz_downscale_custom_size = RNA_int_get(op->ptr, "usdz_downscale_custom_size");
363 params.convert_scene_units = SceneUnits(RNA_enum_get(op->ptr, "convert_scene_units"));
364 params.custom_meters_per_unit = RNA_float_get(op->ptr, "meters_per_unit");
365
366 params.merge_parent_xform = RNA_boolean_get(op->ptr, "merge_parent_xform");
367
368 params.root_prim_path = RNA_string_get(op->ptr, "root_prim_path");
369 process_prim_path(params.root_prim_path);
370
371 RNA_string_get(op->ptr, "custom_properties_namespace", params.custom_properties_namespace);
372 RNA_string_get(op->ptr, "collection", params.collection);
373
374 params.accessibility_label = RNA_string_get(op->ptr, "accessibility_label");
375 params.accessibility_description = RNA_string_get(op->ptr, "accessibility_description");
376
377 bool ok = USD_export(C, filepath, &params, as_background_job, op->reports);
378
379 return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
380}
381
382static void wm_usd_export_draw(bContext *C, wmOperator *op)
383{
384 ui::Layout &layout = *op->layout;
385 PointerRNA *ptr = op->ptr;
386
387 layout.use_property_split_set(true);
388 layout.use_property_decorate_set(false);
389
390 if (ui::Layout *panel = layout.panel(C, "USD_export_general", false, IFACE_("General"))) {
391 ui::Layout *col = &panel->column(false);
392 col->prop(ptr, "root_prim_path", UI_ITEM_NONE, std::nullopt, ICON_NONE);
393
394 ui::Layout *sub = &col->column(true, IFACE_("Include"));
395 if (CTX_wm_space_file(C)) {
396 sub->prop(ptr, "selected_objects_only", UI_ITEM_NONE, std::nullopt, ICON_NONE);
397 }
398 sub->prop(ptr, "export_animation", UI_ITEM_NONE, std::nullopt, ICON_NONE);
399 if (RNA_boolean_get(ptr, "export_animation")) {
400 sub->prop(ptr, "incremental_frames", UI_ITEM_NONE, std::nullopt, ICON_NONE);
401 }
402
403 sub = &col->column(true, IFACE_("Blender Data"));
404 sub->prop(ptr, "export_custom_properties", UI_ITEM_NONE, std::nullopt, ICON_NONE);
405 ui::Layout *props_col = &sub->column(true);
406 props_col->prop(ptr, "custom_properties_namespace", UI_ITEM_NONE, std::nullopt, ICON_NONE);
407 props_col->prop(ptr, "author_blender_name", UI_ITEM_NONE, std::nullopt, ICON_NONE);
408 props_col->active_set(RNA_boolean_get(op->ptr, "export_custom_properties"));
409 sub->prop(ptr, "allow_unicode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
410
411 sub = &col->column(true, IFACE_("File References"));
412 sub->prop(ptr, "relative_paths", UI_ITEM_NONE, std::nullopt, ICON_NONE);
413
414 col = &panel->column(false);
415 col->prop(ptr, "convert_orientation", UI_ITEM_NONE, std::nullopt, ICON_NONE);
416 if (RNA_boolean_get(ptr, "convert_orientation")) {
417 col->prop(ptr, "export_global_forward_selection", UI_ITEM_NONE, std::nullopt, ICON_NONE);
418 col->prop(ptr, "export_global_up_selection", UI_ITEM_NONE, std::nullopt, ICON_NONE);
419 }
420
421 col->prop(ptr, "convert_scene_units", UI_ITEM_NONE, std::nullopt, ICON_NONE);
422 if (SceneUnits(RNA_enum_get(ptr, "convert_scene_units")) == SceneUnits::Custom) {
423 col->prop(ptr, "meters_per_unit", UI_ITEM_NONE, std::nullopt, ICON_NONE);
424 }
425
426 col->prop(ptr, "xform_op_mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
427
428 col = &panel->column(false);
429 col->prop(ptr, "evaluation_mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
430 }
431
432 if (ui::Layout *panel = layout.panel(C, "USD_export_types", false, IFACE_("Object Types"))) {
433 ui::Layout &col = panel->column(false);
434 col.prop(ptr, "export_meshes", UI_ITEM_NONE, std::nullopt, ICON_NONE);
435 col.prop(ptr, "export_lights", UI_ITEM_NONE, std::nullopt, ICON_NONE);
436
437 ui::Layout &row = col.row(true);
438 row.prop(ptr, "convert_world_material", UI_ITEM_NONE, std::nullopt, ICON_NONE);
439 const bool export_lights = RNA_boolean_get(ptr, "export_lights");
440 row.active_set(export_lights);
441
442 col.prop(ptr, "export_cameras", UI_ITEM_NONE, std::nullopt, ICON_NONE);
443 col.prop(ptr, "export_curves", UI_ITEM_NONE, std::nullopt, ICON_NONE);
444 col.prop(ptr, "export_points", UI_ITEM_NONE, std::nullopt, ICON_NONE);
445 col.prop(ptr, "export_volumes", UI_ITEM_NONE, std::nullopt, ICON_NONE);
446 col.prop(ptr, "export_hair", UI_ITEM_NONE, std::nullopt, ICON_NONE);
447 }
448
449 if (ui::Layout *panel = layout.panel(C, "USD_export_geometry", false, IFACE_("Geometry"))) {
450 ui::Layout &col = panel->column(false);
451 col.prop(ptr, "export_uvmaps", UI_ITEM_NONE, std::nullopt, ICON_NONE);
452 col.prop(ptr, "rename_uvmaps", UI_ITEM_NONE, std::nullopt, ICON_NONE);
453 col.prop(ptr, "export_normals", UI_ITEM_NONE, std::nullopt, ICON_NONE);
454
455 col.prop(ptr, "merge_parent_xform", UI_ITEM_NONE, std::nullopt, ICON_NONE);
456 col.prop(ptr, "triangulate_meshes", UI_ITEM_NONE, std::nullopt, ICON_NONE);
457 if (RNA_boolean_get(ptr, "triangulate_meshes")) {
458 col.prop(ptr, "quad_method", UI_ITEM_NONE, IFACE_("Method Quads"), ICON_NONE);
459 col.prop(ptr, "ngon_method", UI_ITEM_NONE, IFACE_("Polygons"), ICON_NONE);
460 }
461
462 col.prop(ptr, "export_subdivision", UI_ITEM_NONE, std::nullopt, ICON_NONE);
463 }
464
465 if (ui::Layout *panel = layout.panel(C, "USD_export_rigging", true, IFACE_("Rigging"))) {
466 ui::Layout &col = panel->column(false);
467
468 col.prop(ptr, "export_shapekeys", UI_ITEM_NONE, std::nullopt, ICON_NONE);
469 col.prop(ptr, "export_armatures", UI_ITEM_NONE, std::nullopt, ICON_NONE);
470
471 ui::Layout &row = col.row(true);
472 row.prop(ptr, "only_deform_bones", UI_ITEM_NONE, std::nullopt, ICON_NONE);
473 row.active_set(RNA_boolean_get(ptr, "export_armatures"));
474 }
475
476 {
477 ui::PanelLayout panel = layout.panel(C, "USD_export_materials", true);
478 panel.header->use_property_split_set(false);
479 panel.header->prop(ptr, "export_materials", UI_ITEM_NONE, "", ICON_NONE);
480 panel.header->label(IFACE_("Materials"), ICON_NONE);
481 if (panel.body) {
482 const bool export_materials = RNA_boolean_get(ptr, "export_materials");
483 panel.body->active_set(export_materials);
484
485 ui::Layout *col = &panel.body->column(false);
486 col->prop(ptr, "generate_preview_surface", UI_ITEM_NONE, std::nullopt, ICON_NONE);
487 col->prop(ptr, "generate_materialx_network", UI_ITEM_NONE, std::nullopt, ICON_NONE);
488
489 col = &panel.body->column(true);
490 col->use_property_split_set(true);
491 col->prop(ptr, "export_textures_mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
492
493 const TexExportMode textures_mode = TexExportMode(
494 RNA_enum_get(op->ptr, "export_textures_mode"));
495
496 ui::Layout &sub_col = col->column(true);
497 sub_col.use_property_split_set(true);
498 sub_col.enabled_set(textures_mode == TexExportMode::NewPath);
499 sub_col.prop(ptr, "overwrite_textures", UI_ITEM_NONE, std::nullopt, ICON_NONE);
500 sub_col.prop(ptr, "usdz_downscale_size", UI_ITEM_NONE, std::nullopt, ICON_NONE);
501 if (TextureDownscaleSize(RNA_enum_get(ptr, "usdz_downscale_size")) ==
502 TextureDownscaleSize::Custom)
503 {
504 sub_col.prop(ptr, "usdz_downscale_custom_size", UI_ITEM_NONE, std::nullopt, ICON_NONE);
505 }
506 }
507 }
508
509 if (ui::Layout *panel = layout.panel(
510 C, "USD_export_accessibility", true, IFACE_("Accessibility")))
511 {
512 ui::Layout &col = panel->column(false);
513 col.prop(ptr, "accessibility_label", UI_ITEM_NONE, std::nullopt, ICON_NONE);
514 col.prop(ptr, "accessibility_description", UI_ITEM_NONE, std::nullopt, ICON_NONE);
515 }
516
517 if (ui::Layout *panel = layout.panel(C, "USD_export_experimental", true, IFACE_("Experimental")))
518 {
519 ui::Layout &col = panel->column(false);
520 col.prop(ptr, "use_instancing", UI_ITEM_NONE, std::nullopt, ICON_NONE);
521 }
522}
523
524static void wm_usd_export_cancel(bContext * /*C*/, wmOperator *op)
525{
526 free_operator_customdata(op);
527}
528
529static bool wm_usd_export_check(bContext * /*C*/, wmOperator *op)
530{
531 char filepath[FILE_MAX];
532 RNA_string_get(op->ptr, "filepath", filepath);
533
534 if (!BLI_path_extension_check_n(filepath, ".usd", ".usda", ".usdc", ".usdz", nullptr)) {
535 BLI_path_extension_ensure(filepath, FILE_MAX, ".usdc");
536 RNA_string_set(op->ptr, "filepath", filepath);
537 return true;
538 }
539
540 return false;
541}
542
543static void forward_axis_update(Main * /*main*/, Scene * /*scene*/, PointerRNA *ptr)
544{
545 int forward = RNA_enum_get(ptr, "export_global_forward_selection");
546 int up = RNA_enum_get(ptr, "export_global_up_selection");
547 if ((forward % 3) == (up % 3)) {
548 RNA_enum_set(ptr, "export_global_up_selection", (up + 1) % 6);
549 }
550}
551
552static void up_axis_update(Main * /*main*/, Scene * /*scene*/, PointerRNA *ptr)
553{
554 int forward = RNA_enum_get(ptr, "export_global_forward_selection");
555 int up = RNA_enum_get(ptr, "export_global_up_selection");
556 if ((forward % 3) == (up % 3)) {
557 RNA_enum_set(ptr, "export_global_forward_selection", (forward + 1) % 6);
558 }
559}
560
562{
563 ot->name = "Export USD";
564 ot->description = "Export current scene in a USD archive";
565 ot->idname = "WM_OT_usd_export";
566
567 ot->invoke = wm_usd_export_invoke;
568 ot->exec = wm_usd_export_exec;
569 ot->poll = WM_operator_winactive;
570 ot->ui = wm_usd_export_draw;
571 ot->cancel = wm_usd_export_cancel;
572 ot->check = wm_usd_export_check;
573
574 ot->flag = OPTYPE_REGISTER | OPTYPE_PRESET; /* No UNDO possible. */
575
579 FILE_SAVE,
583
584 PropertyRNA *prop = RNA_def_string(ot->srna, "filter_glob", "*.usd", 0, "", "");
586
587 RNA_def_boolean(ot->srna,
588 "selected_objects_only",
589 false,
590 "Selection Only",
591 "Only export selected objects. Unselected parents of selected objects are "
592 "exported as empty transform");
593
594 prop = RNA_def_string(ot->srna, "collection", nullptr, MAX_ID_NAME - 2, "Collection", nullptr);
596
598 ot->srna,
599 "export_animation",
600 false,
601 "Animation",
602 "Export all frames in the render frame range, rather than only the current frame");
603 RNA_def_int(ot->srna,
604 "incremental_frames",
605 0,
606 0,
607 INT_MAX,
608 "Incremental Save",
609 "Incrementally save after the specified number of frames to reduce peak memory "
610 "usage. Incremental saves can result in longer export times and potential issues "
611 "with some file synchronization services. Zero disables incremental save",
612 0,
613 INT_MAX);
614
616 ot->srna, "export_hair", false, "Hair", "Export hair particle systems as USD curves");
618 ot->srna, "export_uvmaps", true, "UV Maps", "Include all mesh UV maps in the export");
619 RNA_def_boolean(ot->srna,
620 "rename_uvmaps",
621 true,
622 "Rename UV Maps",
623 "Rename active render UV map to \"st\" to match USD conventions");
624 RNA_def_boolean(ot->srna,
625 "export_mesh_colors",
626 true,
627 "Color Attributes",
628 "Include mesh color attributes in the export");
629 RNA_def_boolean(ot->srna,
630 "export_normals",
631 true,
632 "Normals",
633 "Include normals of exported meshes in the export");
634 RNA_def_boolean(ot->srna,
635 "export_materials",
636 true,
637 "Materials",
638 "Export viewport settings of materials as USD preview materials, and export "
639 "material assignments as geometry subsets");
640
641 RNA_def_enum(ot->srna,
642 "export_subdivision",
643 rna_enum_usd_export_subdiv_mode_items,
644 int(SubdivExportMode::Match),
645 "Subdivision",
646 "Choose how subdivision modifiers will be mapped to the USD subdivision scheme "
647 "during export");
648
649 RNA_def_boolean(ot->srna,
650 "export_armatures",
651 true,
652 "Armatures",
653 "Export armatures and meshes with armature modifiers as USD skeletons and "
654 "skinned meshes");
655
656 RNA_def_boolean(ot->srna,
657 "only_deform_bones",
658 false,
659 "Only Deform Bones",
660 "Only export deform bones and their parents");
661
663 ot->srna, "export_shapekeys", true, "Shape Keys", "Export shape keys as USD blend shapes");
664
665 RNA_def_boolean(ot->srna,
666 "use_instancing",
667 false,
668 "Instancing",
669 "Export instanced objects as references in USD rather than real objects");
670
671 RNA_def_enum(ot->srna,
672 "evaluation_mode",
673 rna_enum_usd_export_evaluation_mode_items,
675 "Use Settings for",
676 "Determines visibility of objects, modifier settings, and other areas where there "
677 "are different settings for viewport and rendering");
678
679 RNA_def_boolean(ot->srna,
680 "generate_preview_surface",
681 true,
682 "USD Preview Surface Network",
683 "Generate an approximate USD Preview Surface shader "
684 "representation of a Principled BSDF node network");
685
686 RNA_def_boolean(ot->srna,
687 "generate_materialx_network",
688 false,
689 "MaterialX Network",
690 "Generate a MaterialX network representation of the materials");
691
693 ot->srna,
694 "convert_orientation",
695 false,
696 "Convert Orientation",
697 "Convert orientation axis to a different convention to match other applications");
698
699 prop = RNA_def_enum(ot->srna,
700 "export_global_forward_selection",
703 "Forward Axis",
704 "");
705 RNA_def_property_update_runtime(prop, forward_axis_update);
706
707 prop = RNA_def_enum(
708 ot->srna, "export_global_up_selection", io_transform_axis, IO_AXIS_Y, "Up Axis", "");
709 RNA_def_property_update_runtime(prop, up_axis_update);
710
711 RNA_def_enum(ot->srna,
712 "export_textures_mode",
713 rna_enum_usd_tex_export_mode_items,
714 int(TexExportMode::NewPath),
715 "Export Textures",
716 "Texture export method");
717
718 RNA_def_boolean(ot->srna,
719 "overwrite_textures",
720 false,
721 "Overwrite Textures",
722 "Overwrite existing files when exporting textures");
723
724 RNA_def_boolean(ot->srna,
725 "relative_paths",
726 true,
727 "Relative Paths",
728 "Use relative paths to reference external files (i.e. textures, volumes) in "
729 "USD, otherwise use absolute paths");
730
731 RNA_def_enum(ot->srna,
732 "xform_op_mode",
733 rna_enum_usd_xform_op_mode_items,
734 int(XformOpMode::TRS),
735 "Xform Ops",
736 "The type of transform operators to write");
737
738 RNA_def_string(ot->srna,
739 "root_prim_path",
740 "/root",
741 0,
742 "Root Prim",
743 "If set, add a transform primitive with the given path to the stage "
744 "as the parent of all exported data");
745
746 RNA_def_boolean(ot->srna,
747 "export_custom_properties",
748 true,
749 "Custom Properties",
750 "Export custom properties as USD attributes");
751
752 RNA_def_string(ot->srna,
753 "custom_properties_namespace",
754 "userProperties",
756 "Namespace",
757 "If set, add the given namespace as a prefix to exported custom property names. "
758 "This only applies to property names that do not already have a prefix "
759 "(e.g., it would apply to name 'bar' but not 'foo:bar') and does not apply "
760 "to blender object and data names which are always exported in the "
761 "'userProperties:blender' namespace");
762
763 prop = RNA_def_string(ot->srna,
764 "accessibility_label",
765 nullptr,
766 0,
767 "Label",
768 "Set the accessibility label for the exported stage's default prim");
770
771 prop = RNA_def_string(ot->srna,
772 "accessibility_description",
773 nullptr,
774 0,
775 "Description",
776 "Set the accessibility description for the exported stage's default prim");
778
779 RNA_def_boolean(ot->srna,
780 "author_blender_name",
781 true,
782 "Blender Names",
783 "Author USD custom attributes containing the original Blender object and "
784 "object data names");
785
787 ot->srna,
788 "convert_world_material",
789 true,
790 "World Dome Light",
791 "Convert the world material to a USD dome light. "
792 "Currently works for simple materials, consisting of an environment texture "
793 "connected to a background shader, with an optional vector multiply of the texture color");
794
796 ot->srna,
797 "allow_unicode",
798 true,
799 "Allow Unicode",
800 "Preserve UTF-8 encoded characters when writing USD prim and property names "
801 "(requires software utilizing USD 24.03 or greater when opening the resulting files)");
802
803 RNA_def_boolean(ot->srna, "export_meshes", true, "Meshes", "Export all meshes");
804
805 RNA_def_boolean(ot->srna, "export_lights", true, "Lights", "Export all lights");
806
807 RNA_def_boolean(ot->srna, "export_cameras", true, "Cameras", "Export all cameras");
808
809 RNA_def_boolean(ot->srna, "export_curves", true, "Curves", "Export all curves");
810
811 RNA_def_boolean(ot->srna, "export_points", true, "Point Clouds", "Export all point clouds");
812
813 RNA_def_boolean(ot->srna, "export_volumes", true, "Volumes", "Export all volumes");
814
815 RNA_def_boolean(ot->srna,
816 "triangulate_meshes",
817 false,
818 "Triangulate Meshes",
819 "Triangulate meshes during export");
820
821 RNA_def_enum(ot->srna,
822 "quad_method",
825 "Quad Method",
826 "Method for splitting the quads into triangles");
827
828 RNA_def_enum(ot->srna,
829 "ngon_method",
832 "N-gon Method",
833 "Method for splitting the n-gons into triangles");
834
835 RNA_def_enum(ot->srna,
836 "usdz_downscale_size",
837 rna_enum_usdz_downscale_size,
839 "USDZ Texture Downsampling",
840 "Choose a maximum size for all exported textures");
841
842 RNA_def_int(ot->srna,
843 "usdz_downscale_custom_size",
844 128,
845 64,
846 16384,
847 "USDZ Custom Downscale Size",
848 "Custom size for downscaling exported textures",
849 128,
850 8192);
851
852 RNA_def_boolean(ot->srna,
853 "merge_parent_xform",
854 false,
855 "Merge parent Xform",
856 "Merge USD primitives with their Xform parent if possible. USD does not allow "
857 "nested UsdGeomGprims, intermediary Xform prims will be defined to keep the USD "
858 "file valid when encountering object hierarchies.");
859
860 RNA_def_enum(ot->srna,
861 "convert_scene_units",
862 rna_enum_usd_convert_scene_units_items,
863 int(SceneUnits::Meters),
864 "Units",
865 "Set the USD Stage meters per unit to the chosen measurement, or a custom value");
866
867 RNA_def_float(ot->srna,
868 "meters_per_unit",
869 1.0f,
870 0.0001f,
871 1000.0f,
872 "Meters Per Unit",
873 "Custom value for meters per unit in the USD Stage",
874 0.0001f,
875 1000.0f);
876}
877
878/* ====== USD Import ====== */
879
880static wmOperatorStatus wm_usd_import_invoke(bContext *C, wmOperator *op, const wmEvent *event)
881{
882 USDOperatorOptions *options = MEM_new_zeroed<USDOperatorOptions>("USDOperatorOptions");
883 options->as_background_job = true;
884 op->customdata = options;
885
886 return ed::io::filesel_drop_import_invoke(C, op, event);
887}
888
889static wmOperatorStatus wm_usd_import_exec(bContext *C, wmOperator *op)
890{
891 if (!RNA_struct_property_is_set_ex(op->ptr, "filepath", false)) {
892 BKE_report(op->reports, RPT_ERROR, "No filepath given");
893 free_operator_customdata(op);
894 return OPERATOR_CANCELLED;
895 }
896
897 const USDOperatorOptions *options = static_cast<USDOperatorOptions *>(op->customdata);
898 const bool as_background_job = (options != nullptr && options->as_background_job);
899 free_operator_customdata(op);
900
901 char filepath[FILE_MAX];
902 RNA_string_get(op->ptr, "filepath", filepath);
903
904 const bool read_mesh_uvs = RNA_boolean_get(op->ptr, "read_mesh_uvs");
905 const bool read_mesh_colors = RNA_boolean_get(op->ptr, "read_mesh_colors");
906 const bool read_mesh_attributes = RNA_boolean_get(op->ptr, "read_mesh_attributes");
907
909 if (read_mesh_uvs) {
910 mesh_read_flag |= MOD_MESHSEQ_READ_UV;
911 }
912 if (read_mesh_colors) {
913 mesh_read_flag |= MOD_MESHSEQ_READ_COLOR;
914 }
915 if (read_mesh_attributes) {
916 mesh_read_flag |= MOD_MESHSEQ_READ_ATTRIBUTES;
917 }
918
919 USDImportParams params{};
920 params.scale = RNA_float_get(op->ptr, "scale");
921 params.light_intensity_scale = RNA_float_get(op->ptr, "light_intensity_scale");
922 params.apply_unit_conversion_scale = RNA_boolean_get(op->ptr, "apply_unit_conversion_scale");
923
924 params.mesh_read_flag = mesh_read_flag;
925 params.set_frame_range = RNA_boolean_get(op->ptr, "set_frame_range");
926
927 /* TODO(makowalski): Add support for sequences. */
928 params.is_sequence = false;
929 params.sequence_len = 1;
930 params.offset = 0;
931 params.relative_path = RNA_boolean_get(op->ptr, "relative_path");
932
933 params.import_visible_only = RNA_boolean_get(op->ptr, "import_visible_only");
934 params.import_defined_only = RNA_boolean_get(op->ptr, "import_defined_only");
935
936 params.import_cameras = RNA_boolean_get(op->ptr, "import_cameras");
937 params.import_curves = RNA_boolean_get(op->ptr, "import_curves");
938 params.import_lights = RNA_boolean_get(op->ptr, "import_lights");
939 params.create_world_material = params.import_lights &&
940 RNA_boolean_get(op->ptr, "create_world_material");
941 params.import_materials = RNA_boolean_get(op->ptr, "import_materials");
942 params.import_all_materials = RNA_boolean_get(op->ptr, "import_all_materials");
943 params.import_meshes = RNA_boolean_get(op->ptr, "import_meshes");
944 params.import_points = RNA_boolean_get(op->ptr, "import_points");
945 params.import_subdivision = RNA_boolean_get(op->ptr, "import_subdivision");
946 params.import_volumes = RNA_boolean_get(op->ptr, "import_volumes");
947
948 params.create_collection = RNA_boolean_get(op->ptr, "create_collection");
949 params.support_scene_instancing = RNA_boolean_get(op->ptr, "support_scene_instancing");
950
951 params.import_shapes = RNA_boolean_get(op->ptr, "import_shapes");
952 params.import_skeletons = RNA_boolean_get(op->ptr, "import_skeletons");
953 params.import_blendshapes = RNA_boolean_get(op->ptr, "import_blendshapes");
954
955 params.validate_meshes = RNA_boolean_get(op->ptr, "validate_meshes");
956 params.merge_parent_xform = RNA_boolean_get(op->ptr, "merge_parent_xform");
957
958 params.import_guide = RNA_boolean_get(op->ptr, "import_guide");
959 params.import_proxy = RNA_boolean_get(op->ptr, "import_proxy");
960 params.import_render = RNA_boolean_get(op->ptr, "import_render");
961
962 params.import_usd_preview = RNA_boolean_get(op->ptr, "import_usd_preview");
963 params.set_material_blend = RNA_boolean_get(op->ptr, "set_material_blend");
964 params.mtl_purpose = MtlPurpose(RNA_enum_get(op->ptr, "mtl_purpose"));
965 params.mtl_name_collision_mode = MtlNameCollisionMode(
966 RNA_enum_get(op->ptr, "mtl_name_collision_mode"));
967 params.import_textures_mode = TexImportMode(RNA_enum_get(op->ptr, "import_textures_mode"));
968 params.tex_name_collision_mode = TexNameCollisionMode(
969 RNA_enum_get(op->ptr, "tex_name_collision_mode"));
970
971 params.property_import_mode = PropertyImportMode(RNA_enum_get(op->ptr, "property_import_mode"));
972
973 params.prim_path_mask = RNA_string_get(op->ptr, "prim_path_mask");
974
975 RNA_string_get(op->ptr, "import_textures_dir", params.import_textures_dir);
976
977 /* Switch out of edit mode to avoid being stuck in it (#54326). */
978 const Object *obedit = CTX_data_edit_object(C);
979 if (obedit) {
981 }
982
983 const bool ok = USD_import(C, filepath, &params, as_background_job, op->reports);
984
985 return as_background_job || ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
986}
987
988static void wm_usd_import_cancel(bContext * /*C*/, wmOperator *op)
989{
990 free_operator_customdata(op);
991}
992
993static void wm_usd_import_draw(bContext *C, wmOperator *op)
994{
995 ui::Layout &layout = *op->layout;
996 PointerRNA *ptr = op->ptr;
997
998 layout.use_property_split_set(true);
999 layout.use_property_decorate_set(false);
1000
1001 if (ui::Layout *panel = layout.panel(C, "USD_import_general", false, IFACE_("General"))) {
1002 ui::Layout *col = &panel->column(false);
1003
1004 col->prop(ptr, "prim_path_mask", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1005
1006 ui::Layout &sub = col->column(true, IFACE_("Include"));
1007 sub.prop(ptr, "import_visible_only", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1008 sub.prop(ptr, "import_defined_only", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1009
1010 col = &panel->column(false);
1011 col->prop(ptr, "set_frame_range", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1012 col->prop(ptr, "create_collection", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1013 col->prop(ptr, "relative_path", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1014
1015 col->prop(ptr, "apply_unit_conversion_scale", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1016 col->prop(ptr, "scale", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1017 col->prop(ptr, "light_intensity_scale", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1018 col->prop(ptr, "property_import_mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1019 }
1020
1021 if (ui::Layout *panel = layout.panel(C, "USD_import_types", false, IFACE_("Object Types"))) {
1022 ui::Layout &obj_col = panel->column(false);
1023 obj_col.prop(ptr, "import_cameras", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1024 obj_col.prop(ptr, "import_curves", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1025 obj_col.prop(ptr, "import_lights", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1026
1027 ui::Layout &row = obj_col.row(true);
1028 row.prop(ptr, "create_world_material", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1029 const bool import_lights = RNA_boolean_get(ptr, "import_lights");
1030 row.active_set(import_lights);
1031
1032 obj_col.prop(ptr, "import_materials", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1033 obj_col.prop(ptr, "import_meshes", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1034 obj_col.prop(ptr, "import_volumes", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1035 obj_col.prop(ptr, "import_points", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1036 obj_col.prop(ptr, "import_shapes", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1037
1038 ui::Layout &disp_col = panel->column(true, IFACE_("Display Purpose"));
1039 disp_col.prop(ptr, "import_render", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1040 disp_col.prop(ptr, "import_proxy", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1041 disp_col.prop(ptr, "import_guide", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1042
1043 ui::Layout &mtl_col = panel->column(true, IFACE_("Material Purpose"));
1044 mtl_col.prop(ptr, "mtl_purpose", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1045 }
1046
1047 if (ui::Layout *panel = layout.panel(C, "USD_import_geometry", true, IFACE_("Geometry"))) {
1048 ui::Layout *col = &panel->column(false);
1049 col->prop(ptr, "read_mesh_uvs", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1050 col->prop(ptr, "read_mesh_colors", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1051 col->prop(ptr, "read_mesh_attributes", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1052 col->prop(ptr, "import_subdivision", UI_ITEM_NONE, IFACE_("Subdivision"), ICON_NONE);
1053
1054 col = &panel->column(false);
1055 col->prop(ptr, "validate_meshes", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1056 col->prop(ptr, "merge_parent_xform", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1057 }
1058
1059 if (ui::Layout *panel = layout.panel(C, "USD_import_rigging", true, IFACE_("Rigging"))) {
1060 ui::Layout &col = panel->column(false);
1061 col.prop(ptr, "import_blendshapes", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1062 col.prop(ptr, "import_skeletons", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1063 }
1064
1065 if (ui::Layout *panel = layout.panel(C, "USD_import_material", true, IFACE_("Materials"))) {
1066 ui::Layout &col = panel->column(false);
1067
1068 col.prop(ptr, "import_all_materials", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1069 col.prop(ptr, "import_usd_preview", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1070 col.enabled_set(RNA_boolean_get(ptr, "import_materials"));
1071
1072 ui::Layout &row = col.row(true);
1073 row.prop(ptr, "set_material_blend", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1074 row.enabled_set(RNA_boolean_get(ptr, "import_usd_preview"));
1075 col.prop(ptr, "mtl_name_collision_mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1076 }
1077
1078 if (ui::Layout *panel = layout.panel(C, "USD_import_texture", true, IFACE_("Textures"))) {
1079 ui::Layout &col = panel->column(false);
1080
1081 col.prop(ptr, "import_textures_mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1082 const bool copy_textures = TexImportMode(RNA_enum_get(op->ptr, "import_textures_mode")) ==
1083 TexImportMode::Copy;
1084
1085 ui::Layout *row = &col.row(true);
1086 row->prop(ptr, "import_textures_dir", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1087 row->enabled_set(copy_textures);
1088 row = &col.row(true);
1089 row->prop(ptr, "tex_name_collision_mode", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1090 row->enabled_set(copy_textures);
1091 col.enabled_set(RNA_boolean_get(ptr, "import_materials"));
1092 }
1093
1094 if (ui::Layout *panel = layout.panel(
1095 C, "USD_import_instancing", true, IFACE_("Particles and Instancing")))
1096 {
1097 ui::Layout &col = panel->column(false);
1098 col.prop(ptr, "support_scene_instancing", UI_ITEM_NONE, std::nullopt, ICON_NONE);
1099 }
1100}
1101
1103{
1104 ot->name = "Import USD";
1105 ot->description = "Import USD stage into current scene";
1106 ot->idname = "WM_OT_usd_import";
1107
1108 ot->invoke = wm_usd_import_invoke;
1109 ot->exec = wm_usd_import_exec;
1110 ot->cancel = wm_usd_import_cancel;
1111 ot->poll = WM_operator_winactive;
1112 ot->ui = wm_usd_import_draw;
1113
1114 ot->flag = OPTYPE_UNDO | OPTYPE_PRESET;
1115
1123
1124 PropertyRNA *prop = RNA_def_string(ot->srna, "filter_glob", "*.usd", 0, "", "");
1126
1128 ot->srna,
1129 "scale",
1130 1.0f,
1131 0.0001f,
1132 1000.0f,
1133 "Scale",
1134 "Value by which to enlarge or shrink the objects with respect to the world's origin",
1135 0.0001f,
1136 1000.0f);
1137
1138 RNA_def_boolean(ot->srna,
1139 "set_frame_range",
1140 true,
1141 "Set Frame Range",
1142 "Update the scene's start and end frame to match those of the USD archive");
1143
1144 RNA_def_boolean(ot->srna, "import_cameras", true, "Cameras", "");
1145 RNA_def_boolean(ot->srna, "import_curves", true, "Curves", "");
1146 RNA_def_boolean(ot->srna, "import_lights", true, "Lights", "");
1147 RNA_def_boolean(ot->srna, "import_materials", true, "Materials", "");
1148 RNA_def_boolean(ot->srna, "import_meshes", true, "Meshes", "");
1149 RNA_def_boolean(ot->srna, "import_volumes", true, "Volumes", "");
1150 RNA_def_boolean(ot->srna, "import_shapes", true, "USD Shapes", "");
1151 RNA_def_boolean(ot->srna, "import_skeletons", true, "Armatures", "");
1152 RNA_def_boolean(ot->srna, "import_blendshapes", true, "Shape Keys", "");
1153 RNA_def_boolean(ot->srna, "import_points", true, "Point Clouds", "");
1154
1155 RNA_def_boolean(ot->srna,
1156 "import_subdivision",
1157 false,
1158 "Import Subdivision Scheme",
1159 "Create subdivision surface modifiers based on the USD "
1160 "SubdivisionScheme attribute");
1161
1162 RNA_def_boolean(ot->srna,
1163 "support_scene_instancing",
1164 true,
1165 "Scene Instancing",
1166 "Import USD scene graph instances as collection instances");
1167
1168 RNA_def_boolean(ot->srna,
1169 "import_visible_only",
1170 true,
1171 "Visible Primitives Only",
1172 "Do not import invisible USD primitives. "
1173 "Only applies to primitives with a non-animated visibility attribute. "
1174 "Primitives with animated visibility will always be imported");
1175
1176 RNA_def_boolean(ot->srna,
1177 "create_collection",
1178 false,
1179 "Create Collection",
1180 "Add all imported objects to a new collection");
1181
1182 RNA_def_boolean(ot->srna, "read_mesh_uvs", true, "UV Coordinates", "Read mesh UV coordinates");
1183
1185 ot->srna, "read_mesh_colors", true, "Color Attributes", "Read mesh color attributes");
1186
1187 RNA_def_boolean(ot->srna,
1188 "read_mesh_attributes",
1189 true,
1190 "Mesh Attributes",
1191 "Read USD Primvars as mesh attributes");
1192
1193 RNA_def_string(ot->srna,
1194 "prim_path_mask",
1195 nullptr,
1196 0,
1197 "Path Mask",
1198 "Import only the primitive at the given path and its descendants. "
1199 "Multiple paths may be specified in a list delimited by commas or semicolons");
1200
1201 RNA_def_boolean(ot->srna, "import_guide", false, "Guide", "Import guide geometry");
1202
1203 RNA_def_boolean(ot->srna, "import_proxy", false, "Proxy", "Import proxy geometry");
1204
1205 RNA_def_boolean(ot->srna, "import_render", true, "Render", "Import final render geometry");
1206
1207 RNA_def_boolean(ot->srna,
1208 "import_all_materials",
1209 false,
1210 "Import All Materials",
1211 "Also import materials that are not used by any geometry. "
1212 "Note that when this option is false, materials referenced "
1213 "by geometry will still be imported");
1214
1215 RNA_def_boolean(ot->srna,
1216 "import_usd_preview",
1217 true,
1218 "Import USD Preview",
1219 "Convert UsdPreviewSurface shaders to Principled BSDF shader networks");
1220
1221 RNA_def_boolean(ot->srna,
1222 "set_material_blend",
1223 true,
1224 "Set Material Blend",
1225 "If the Import USD Preview option is enabled, "
1226 "the material blend method will automatically be set based on the "
1227 "shader's opacity and opacityThreshold inputs");
1228
1229 RNA_def_float(ot->srna,
1230 "light_intensity_scale",
1231 1.0f,
1232 0.0001f,
1233 10000.0f,
1234 "Light Intensity Scale",
1235 "Scale for the intensity of imported lights",
1236 0.0001f,
1237 1000.0f);
1238
1239 RNA_def_enum(ot->srna,
1240 "mtl_purpose",
1241 rna_enum_usd_mtl_purpose_items,
1242 int(MtlPurpose::Full),
1243 "Material Purpose",
1244 "Attempt to import materials with the given purpose. "
1245 "If no material with this purpose is bound to the primitive, "
1246 "fall back on loading any other bound material");
1247
1249 ot->srna,
1250 "mtl_name_collision_mode",
1251 rna_enum_usd_mtl_name_collision_mode_items,
1252 int(MtlNameCollisionMode::MakeUnique),
1253 "Material Name Collision",
1254 "Behavior when the name of an imported material conflicts with an existing material");
1255
1256 RNA_def_enum(ot->srna,
1257 "import_textures_mode",
1258 rna_enum_usd_tex_import_mode_items,
1259 int(TexImportMode::Pack),
1260 "Import Textures",
1261 "Behavior when importing textures from a USDZ archive");
1262
1263 RNA_def_string(ot->srna,
1264 "import_textures_dir",
1265 "//textures/",
1267 "Textures Directory",
1268 "Path to the directory where imported textures will be copied");
1269
1271 ot->srna,
1272 "tex_name_collision_mode",
1273 rna_enum_usd_tex_name_collision_mode_items,
1274 int(TexNameCollisionMode::UseExisting),
1275 "File Name Collision",
1276 "Behavior when the name of an imported texture file conflicts with an existing file");
1277
1278 RNA_def_enum(ot->srna,
1279 "property_import_mode",
1280 rna_enum_usd_property_import_mode_items,
1281 int(PropertyImportMode::All),
1282 "Custom Properties",
1283 "Behavior when importing USD attributes as Blender custom properties");
1284
1286 ot->srna,
1287 "validate_meshes",
1288 false,
1289 "Validate Meshes",
1290 "Ensure the data is valid "
1291 "(when disabled, data may be imported which causes crashes displaying or editing)");
1292
1293 RNA_def_boolean(ot->srna,
1294 "create_world_material",
1295 true,
1296 "World Dome Light",
1297 "Convert the first discovered USD dome light to a world background shader");
1298
1299 RNA_def_boolean(ot->srna,
1300 "import_defined_only",
1301 true,
1302 "Defined Primitives Only",
1303 "Import only defined USD primitives. When disabled this allows importing USD "
1304 "primitives which are not defined, such as those with an override specifier");
1305
1306 RNA_def_boolean(ot->srna,
1307 "merge_parent_xform",
1308 true,
1309 "Merge parent Xform",
1310 "Allow USD primitives to merge with their Xform parent "
1311 "if they are the only child in the hierarchy");
1312
1314 ot->srna,
1315 "apply_unit_conversion_scale",
1316 true,
1317 "Apply Unit Conversion Scale",
1318 "Scale the scene objects by the USD stage's meters per unit value. "
1319 "This scaling is applied in addition to the value specified in the Scale option");
1320}
1321
1322namespace ed::io {
1324{
1325 auto fh = std::make_unique<bke::FileHandlerType>();
1326 STRNCPY_UTF8(fh->idname, "IO_FH_usd");
1327 STRNCPY_UTF8(fh->import_operator, "WM_OT_usd_import");
1328 STRNCPY_UTF8(fh->export_operator, "WM_OT_usd_export");
1329 STRNCPY_UTF8(fh->label, "Universal Scene Description");
1330 STRNCPY_UTF8(fh->file_extensions_str, ".usd;.usda;.usdc;.usdz");
1331 fh->poll_drop = poll_file_object_drop;
1332 bke::file_handler_add(std::move(fh));
1333}
1334} // namespace ed::io
1335} // namespace blender
1336
1337#endif /* WITH_USD */
#define FILE_MAX
#define FILE_MAXDIR
#define STRNCPY_UTF8(dst, src)
#define IFACE_(msgid)
#define MAX_ID_NAME
Definition DNA_ID.h:367
#define MAX_IDPROP_NAME
Definition DNA_ID.h:174
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define BLI_assert_unreachable()
CCL_NAMESPACE_BEGIN struct Options options
#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
wmOperatorStatus filesel_drop_import_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition io_utils.cc:30
void usd_file_handler_add()
bool mode_set(bContext *C, eObjectMode mode)
bool USD_import(bContext *C, const char *filepath, const USDImportParams *params, bool as_background_job, ReportList *reports)
bool USD_export(const bContext *C, const char *filepath, const USDExportParams *params, bool as_background_job, ReportList *reports)
BMesh Iterators.
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 RNA_string_set(PointerRNA *ptr, const char *name, const char *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 RNA_enum_set(PointerRNA *ptr, const char *name, int value)
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 WM_OT_usd_export(wmOperatorType *ot)
bool BLI_path_extension_ensure(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
const EnumPropertyItem rna_enum_modifier_triangulate_quad_method_items[]
@ WM_FILESEL_RELPATH
Definition WM_api.hh:1329
@ WM_FILESEL_SHOW_PROPS
Definition WM_api.hh:1335
@ WM_FILESEL_FILEPATH
Definition WM_api.hh:1332
Object * CTX_data_edit_object(const bContext *C)
void ED_fileselect_ensure_default_filepath(bContext *C, wmOperator *op, const char *extension)
Definition filesel.cc:1515
@ DAG_EVAL_VIEWPORT
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
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)
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
@ MOD_TRIANGULATE_QUAD_SHORTEDGE
void RNA_def_property_update_runtime(PropertyRNA *prop, RNAPropertyUpdateFunc func)
SpaceFile * CTX_wm_space_file(const bContext *C)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_PRESET
Definition WM_types.hh:203
std::string RNA_string_get(PointerRNA *ptr, const char *name)
const EnumPropertyItem rna_enum_modifier_triangulate_ngon_method_items[]
void WM_OT_usd_import(wmOperatorType *ot)
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[]
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)
bool BLI_path_extension_check_n(const char *path,...) ATTR_NONNULL(1) ATTR_SENTINEL(0)
float RNA_float_get(PointerRNA *ptr, const char *name)
void WM_event_add_fileselect(bContext *C, wmOperator *op)
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)
Layout & row(bool align)