56 "Use Render settings for object visibility, modifier settings, etc"},
61 "Use Viewport settings for object visibility, modifier settings, etc"},
62 {0,
nullptr, 0,
nullptr,
nullptr},
70 "Import each USD material as a unique Blender material"},
75 "If a material with the same name already exists, reference that instead of importing"},
76 {0,
nullptr, 0,
nullptr,
nullptr},
85 "Import USD attributes in the 'userProperties' namespace as Blender custom "
86 "properties. The namespace will be stripped from the property names"},
91 "Import all USD custom attributes as Blender custom properties. "
92 "Namespaces will be retained in the property names"},
93 {0,
nullptr, 0,
nullptr,
nullptr},
100 {0,
nullptr, 0,
nullptr,
nullptr},
108 "If a file with the same name already exists, use that instead of copying"},
110 {0,
nullptr, 0,
nullptr,
nullptr},
118 "Scheme = None. Export base mesh without subdivision"},
123 "Scheme = None. Export subdivided mesh"},
128 "Scheme = Catmull-Clark, when possible. "
129 "Reverts to exporting the subdivided mesh for the Simple subdivision type"},
130 {0,
nullptr, 0,
nullptr,
nullptr},
137 "Translate, Rotate, Scale",
138 "Export with translate, rotate, and scale Xform operators"},
142 "Translate, Orient, Scale",
143 "Export with translate, orient quaternion, and scale Xform operators"},
145 {0,
nullptr, 0,
nullptr,
nullptr},
156 {0,
nullptr, 0,
nullptr,
nullptr},
165 "Preserve file paths of textures from already imported USD files."
166 "Export remaining textures to a 'textures' folder next to the USD file"},
171 "Export textures to a 'textures' folder next to the USD file"},
172 {0,
nullptr, 0,
nullptr,
nullptr}};
179 "Attempt to import 'allPurpose' materials."},
184 "Attempt to import 'preview' materials. "
185 "Load 'allPurpose' materials as a fallback"},
190 "Attempt to import 'full' materials. "
191 "Load 'allPurpose' or 'preview' materials, in that order, as a fallback"},
197struct eUSDOperatorOptions {
198 bool as_background_job;
203static void process_prim_path(
char *prim_path)
205 if (prim_path ==
nullptr || prim_path[0] ==
'\0') {
211 if (prim_path[0] ==
'/' && prim_path[1] ==
'\0') {
217 if (prim_path[0] !=
'/') {
218 const std::string prim_path_copy = std::string(prim_path);
225 eUSDOperatorOptions *
options = MEM_cnew<eUSDOperatorOptions>(
"eUSDOperatorOptions");
226 options->as_background_job =
true;
246 eUSDOperatorOptions *
options =
static_cast<eUSDOperatorOptions *
>(op->
customdata);
247 const bool as_background_job = (
options !=
nullptr &&
options->as_background_job);
272 const bool generate_preview_surface =
RNA_boolean_get(op->
ptr,
"generate_preview_surface");
273 const bool generate_materialx_network =
RNA_boolean_get(op->
ptr,
"generate_materialx_network");
281 const bool export_custom_properties =
RNA_boolean_get(op->
ptr,
"export_custom_properties");
290 const int global_forward =
RNA_enum_get(op->
ptr,
"export_global_forward_selection");
291 const int global_up =
RNA_enum_get(op->
ptr,
"export_global_up_selection");
293 const bool convert_world_material =
RNA_boolean_get(op->
ptr,
"convert_world_material");
300 const int usdz_downscale_custom_size =
RNA_int_get(op->
ptr,
"usdz_downscale_custom_size");
302# if PXR_VERSION >= 2403
305 const bool allow_unicode =
false;
315 bool use_original_paths =
false;
317 if (!export_textures) {
318 switch (textures_mode) {
319 case eUSDTexExportMode::USD_TEX_EXPORT_PRESERVE:
320 export_textures =
false;
321 use_original_paths =
true;
323 case eUSDTexExportMode::USD_TEX_EXPORT_NEW_PATH:
324 export_textures =
true;
325 use_original_paths =
false;
328 use_original_paths =
false;
334 process_prim_path(root_prim_path);
337 RNA_string_get(op->
ptr,
"custom_properties_namespace", custom_properties_namespace);
340 params.export_animation = export_animation;
341 params.selected_objects_only = selected_objects_only;
342 params.visible_objects_only = visible_objects_only;
344 params.export_meshes = export_meshes;
345 params.export_lights = export_lights;
346 params.export_cameras = export_cameras;
347 params.export_curves = export_curves;
348 params.export_points = export_points;
349 params.export_volumes = export_volumes;
350 params.export_hair = export_hair;
351 params.export_uvmaps = export_uvmaps;
352 params.rename_uvmaps = rename_uvmaps;
353 params.export_normals = export_normals;
354 params.export_mesh_colors = export_mesh_colors;
355 params.export_materials = export_materials;
357 params.export_armatures = export_armatures;
358 params.export_shapekeys = export_shapekeys;
359 params.only_deform_bones = only_deform_bones;
361 params.convert_world_material = convert_world_material;
363 params.use_instancing = use_instancing;
364 params.export_custom_properties = export_custom_properties;
365 params.author_blender_name = author_blender_name;
366 params.allow_unicode = allow_unicode;
368 params.export_subdiv = export_subdiv;
371 params.generate_preview_surface = generate_preview_surface;
372 params.generate_materialx_network = generate_materialx_network;
373 params.export_textures = export_textures;
374 params.overwrite_textures = overwrite_textures;
375 params.relative_paths = relative_paths;
376 params.use_original_paths = use_original_paths;
378 params.triangulate_meshes = triangulate_meshes;
379 params.quad_method = quad_method;
380 params.ngon_method = ngon_method;
382 params.convert_orientation = convert_orientation;
385 params.xform_op_mode = xform_op_mode;
387 params.usdz_downscale_size = usdz_downscale_size;
388 params.usdz_downscale_custom_size = usdz_downscale_custom_size;
391 STRNCPY(
params.custom_properties_namespace, custom_properties_namespace);
424# if PXR_VERSION >= 2403
444 C, layout,
"USD_export_types",
false,
IFACE_(
"Object Types")))
510 if (
RNA_enum_get(
ptr,
"usdz_downscale_size") == USD_TEXTURE_SIZE_CUSTOM) {
517 C, layout,
"USD_export_experimental",
true,
IFACE_(
"Experimental")))
524static void free_operator_customdata(
wmOperator *op)
534 free_operator_customdata(op);
555 if ((forward % 3) == (up % 3)) {
564 if ((forward % 3) == (up % 3)) {
565 RNA_enum_set(
ptr,
"export_global_forward_selection", (forward + 1) % 6);
576 ot->
exec = wm_usd_export_exec;
578 ot->
ui = wm_usd_export_draw;
580 ot->
check = wm_usd_export_check;
596 "selected_objects_only",
599 "Only export selected objects. Unselected parents of selected objects are "
600 "exported as empty transform");
603 "visible_objects_only",
606 "Only export visible objects. Invisible parents of exported objects are "
607 "exported as empty transforms");
617 "Export all frames in the render frame range, rather than only the current frame");
619 ot->
srna,
"export_hair",
false,
"Hair",
"Export hair particle systems as USD curves");
621 ot->
srna,
"export_uvmaps",
true,
"UV Maps",
"Include all mesh UV maps in the export");
626 "Rename active render UV map to \"st\" to match USD conventions");
628 "export_mesh_colors",
631 "Include mesh color attributes in the export");
636 "Include normals of exported meshes in the export");
641 "Export viewport settings of materials as USD preview materials, and export "
642 "material assignments as geometry subsets");
645 "export_subdivision",
646 rna_enum_usd_export_subdiv_mode_items,
647 USD_SUBDIV_BEST_MATCH,
649 "Choose how subdivision modifiers will be mapped to the USD subdivision scheme "
656 "Export armatures and meshes with armature modifiers as USD skeletons and "
663 "Only export deform bones and their parents");
666 ot->
srna,
"export_shapekeys",
true,
"Shape Keys",
"Export shape keys as USD blend shapes");
672 "Export instanced objects as references in USD rather than real objects");
676 rna_enum_usd_export_evaluation_mode_items,
679 "Determines visibility of objects, modifier settings, and other areas where there "
680 "are different settings for viewport and rendering");
683 "generate_preview_surface",
685 "USD Preview Surface Network",
686 "Generate an approximate USD Preview Surface shader "
687 "representation of a Principled BSDF node network");
690 "generate_materialx_network",
693 "Generate a MaterialX network representation of the materials");
697 "convert_orientation",
699 "Convert Orientation",
700 "Convert orientation axis to a different convention to match other applications");
703 "export_global_forward_selection",
718 "If exporting materials, export textures referenced by material nodes "
719 "to a 'textures' directory in the same directory as the USD file");
722 "export_textures_mode",
723 rna_enum_usd_tex_export_mode_items,
724 USD_TEX_EXPORT_NEW_PATH,
726 "Texture export method");
729 "overwrite_textures",
731 "Overwrite Textures",
732 "Overwrite existing files when exporting textures");
738 "Use relative paths to reference external files (i.e. textures, volumes) in "
739 "USD, otherwise use absolute paths");
743 rna_enum_usd_xform_op_mode_items,
746 "The type of transform operators to write");
753 "If set, add a transform primitive with the given path to the stage "
754 "as the parent of all exported data");
757 "export_custom_properties",
760 "Export custom properties as USD attributes");
763 "custom_properties_namespace",
767 "If set, add the given namespace as a prefix to exported custom property names. "
768 "This only applies to property names that do not already have a prefix "
769 "(e.g., it would apply to name 'bar' but not 'foo:bar') and does not apply "
770 "to blender object and data names which are always exported in the "
771 "'userProperties:blender' namespace");
774 "author_blender_name",
777 "Author USD custom attributes containing the original Blender object and "
778 "object data names");
782 "convert_world_material",
784 "Convert World Material",
785 "Convert the world material to a USD dome light. "
786 "Currently works for simple materials, consisting of an environment texture "
787 "connected to a background shader, with an optional vector multiply of the texture color");
789# if PXR_VERSION >= 2403
795 "Preserve UTF-8 encoded characters when writing USD prim and property names "
796 "(requires software utilizing USD 24.03 or greater when opening the resulting files)");
812 "triangulate_meshes",
814 "Triangulate Meshes",
815 "Triangulate meshes during export");
822 "Method for splitting the quads into triangles");
829 "Method for splitting the n-gons into triangles");
832 "usdz_downscale_size",
833 prop_usdz_downscale_size,
835 "USDZ Texture Downsampling",
836 "Choose a maximum size for all exported textures");
839 "usdz_downscale_custom_size",
843 "USDZ Custom Downscale Size",
844 "Custom size for downscaling exported textures",
853 eUSDOperatorOptions *
options = MEM_cnew<eUSDOperatorOptions>(
"eUSDOperatorOptions");
854 options->as_background_job =
true;
870 eUSDOperatorOptions *
options =
static_cast<eUSDOperatorOptions *
>(op->
customdata);
871 const bool as_background_job = (
options !=
nullptr &&
options->as_background_job);
886 if (read_mesh_colors) {
889 if (read_mesh_attributes) {
906 const bool support_scene_instancing =
RNA_boolean_get(op->
ptr,
"support_scene_instancing");
925 const float light_intensity_scale =
RNA_float_get(op->
ptr,
"light_intensity_scale");
939 const bool is_sequence =
false;
941 int sequence_len = 1;
953 params.prim_path_mask = prim_path_mask;
955 params.light_intensity_scale = light_intensity_scale;
957 params.mesh_read_flag = mesh_read_flag;
959 params.is_sequence = is_sequence;
960 params.sequence_len = sequence_len;
963 params.import_visible_only = import_visible_only;
964 params.import_defined_only = import_defined_only;
966 params.import_cameras = import_cameras;
967 params.import_curves = import_curves;
968 params.import_lights = import_lights;
969 params.import_materials = import_materials;
970 params.import_all_materials = import_all_materials;
971 params.import_meshes = import_meshes;
972 params.import_points = import_points;
973 params.import_subdiv = import_subdiv;
974 params.import_volumes = import_volumes;
976 params.create_collection = create_collection;
977 params.create_world_material = create_world_material;
978 params.support_scene_instancing = support_scene_instancing;
980 params.import_shapes = import_shapes;
981 params.import_skeletons = import_skeletons;
984 params.validate_meshes = validate_meshes;
986 params.import_guide = import_guide;
987 params.import_proxy = import_proxy;
988 params.import_render = import_render;
990 params.import_usd_preview = import_usd_preview;
991 params.set_material_blend = set_material_blend;
992 params.mtl_purpose = mtl_purpose;
993 params.mtl_name_collision_mode = mtl_name_collision_mode;
994 params.import_textures_mode = import_textures_mode;
995 params.tex_name_collision_mode = tex_name_collision_mode;
997 params.attr_import_mode = attr_import_mode;
1014 free_operator_customdata(op);
1045 C, layout,
"USD_import_types",
false,
IFACE_(
"Object Types")))
1115 C, layout,
"USD_import_instancing",
true,
IFACE_(
"Particles and Instancing")))
1129 ot->
exec = wm_usd_import_exec;
1132 ot->
ui = wm_usd_import_draw;
1154 "Value by which to enlarge or shrink the objects with respect to the world's origin",
1162 "Update the scene's start and end frame to match those of the USD archive");
1178 "Import Subdivision Scheme",
1179 "Create subdivision surface modifiers based on the USD "
1180 "SubdivisionScheme attribute");
1183 "support_scene_instancing",
1186 "Import USD scene graph instances as collection instances");
1189 "import_visible_only",
1191 "Visible Primitives Only",
1192 "Do not import invisible USD primitives. "
1193 "Only applies to primitives with a non-animated visibility attribute. "
1194 "Primitives with animated visibility will always be imported");
1197 "create_collection",
1199 "Create Collection",
1200 "Add all imported objects to a new collection");
1205 ot->
srna,
"read_mesh_colors",
true,
"Color Attributes",
"Read mesh color attributes");
1208 "read_mesh_attributes",
1211 "Read USD Primvars as mesh attributes");
1218 "Import only the primitive at the given path and its descendants. "
1219 "Multiple paths may be specified in a list delimited by commas or semicolons");
1228 "import_all_materials",
1230 "Import All Materials",
1231 "Also import materials that are not used by any geometry. "
1232 "Note that when this option is false, materials referenced "
1233 "by geometry will still be imported");
1236 "import_usd_preview",
1238 "Import USD Preview",
1239 "Convert UsdPreviewSurface shaders to Principled BSDF shader networks");
1242 "set_material_blend",
1244 "Set Material Blend",
1245 "If the Import USD Preview option is enabled, "
1246 "the material blend method will automatically be set based on the "
1247 "shader's opacity and opacityThreshold inputs");
1250 "light_intensity_scale",
1254 "Light Intensity Scale",
1255 "Scale for the intensity of imported lights",
1261 rna_enum_usd_mtl_purpose_items,
1262 USD_MTL_PURPOSE_FULL,
1264 "Attempt to import materials with the given purpose. "
1265 "If no material with this purpose is bound to the primitive, "
1266 "fall back on loading any other bound material");
1270 "mtl_name_collision_mode",
1271 rna_enum_usd_mtl_name_collision_mode_items,
1272 USD_MTL_NAME_COLLISION_MAKE_UNIQUE,
1273 "Material Name Collision",
1274 "Behavior when the name of an imported material conflicts with an existing material");
1277 "import_textures_mode",
1278 rna_enum_usd_tex_import_mode_items,
1279 USD_TEX_IMPORT_PACK,
1281 "Behavior when importing textures from a USDZ archive");
1284 "import_textures_dir",
1287 "Textures Directory",
1288 "Path to the directory where imported textures will be copied");
1292 "tex_name_collision_mode",
1293 rna_enum_usd_tex_name_collision_mode_items,
1294 USD_TEX_NAME_COLLISION_USE_EXISTING,
1295 "File Name Collision",
1296 "Behavior when the name of an imported texture file conflicts with an existing file");
1300 rna_enum_usd_attr_import_mode_items,
1301 USD_ATTR_IMPORT_ALL,
1302 "Custom Properties",
1303 "Behavior when importing USD attributes as Blender custom properties");
1310 "Ensure the data is valid "
1311 "(when disabled, data may be imported which causes crashes displaying or editing)");
1314 "create_world_material",
1316 "Create World Material",
1317 "Convert the first discovered USD dome light to a world background shader");
1320 "import_defined_only",
1322 "Defined Primitives Only",
1323 "Import only defined USD primitives. When disabled this allows importing USD "
1324 "primitives which are not defined, such as those with an override specifier");
1330 auto fh = std::make_unique<blender::bke::FileHandlerType>();
1331 STRNCPY(fh->idname,
"IO_FH_usd");
1332 STRNCPY(fh->import_operator,
"WM_OT_usd_import");
1333 STRNCPY(fh->export_operator,
"WM_OT_usd_export");
1334 STRNCPY(fh->label,
"Universal Scene Description");
1335 STRNCPY(fh->file_extensions_str,
".usd;.usda;.usdc;.usdz");
SpaceFile * CTX_wm_space_file(const bContext *C)
Object * CTX_data_edit_object(const bContext *C)
void BKE_report(ReportList *reports, eReportType type, const char *message)
bool BLI_path_extension_ensure(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
bool BLI_path_extension_check_n(const char *path,...) ATTR_NONNULL(1) ATTR_SENTINEL(0)
#define STRNCPY(dst, src)
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
@ MOD_MESHSEQ_READ_ATTRIBUTES
@ MOD_TRIANGULATE_QUAD_SHORTEDGE
@ MOD_TRIANGULATE_NGON_BEAUTY
void ED_fileselect_ensure_default_filepath(bContext *C, wmOperator *op, const char *extension)
Read Guarded memory(de)allocation.
void uiLayoutSetActive(uiLayout *layout, bool active)
void uiLayoutSetEnabled(uiLayout *layout, bool enabled)
void uiItemL(uiLayout *layout, const char *name, int icon)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
PanelLayout uiLayoutPanel(const bContext *C, uiLayout *layout, const char *idname, bool default_closed)
uiLayout * uiLayoutColumnWithHeading(uiLayout *layout, bool align, const char *heading)
void uiLayoutSetPropDecorate(uiLayout *layout, bool is_sep)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
static void set_frame_range(ImportJobData *data)
CCL_NAMESPACE_BEGIN struct Options options
void WM_OT_usd_import(wmOperatorType *ot)
void WM_OT_usd_export(wmOperatorType *ot)
void MEM_freeN(void *vmemh)
void file_handler_add(std::unique_ptr< FileHandlerType > file_handler)
bool poll_file_object_drop(const bContext *C, blender::bke::FileHandlerType *)
void usd_file_handler_add()
int filesel_drop_import_invoke(bContext *C, wmOperator *op, const wmEvent *)
bool mode_set(bContext *C, eObjectMode mode)
@ USD_MTL_PURPOSE_PREVIEW
bool USD_import(const bContext *C, const char *filepath, const USDImportParams *params, bool as_background_job, ReportList *reports)
@ USD_TEX_NAME_COLLISION_USE_EXISTING
@ USD_TEX_NAME_COLLISION_OVERWRITE
void import_blendshapes(Main *bmain, Object *mesh_obj, const pxr::UsdPrim &prim, ReportList *reports, const bool import_anim)
bool USD_export(const bContext *C, const char *filepath, const USDExportParams *params, bool as_background_job, ReportList *reports)
@ USD_TEX_EXPORT_PRESERVE
@ USD_TEX_EXPORT_NEW_PATH
@ USD_MTL_NAME_COLLISION_MAKE_UNIQUE
@ USD_MTL_NAME_COLLISION_REFERENCE_EXISTING
eUSDZTextureDownscaleSize
@ USD_TEXTURE_SIZE_CUSTOM
const EnumPropertyItem io_transform_axis[]
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
bool RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, bool use_ghost)
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
int RNA_int_get(PointerRNA *ptr, const char *name)
char * RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
float RNA_float_get(PointerRNA *ptr, const char *name)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_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)
void RNA_def_property_update_runtime(PropertyRNA *prop, RNAPropertyUpdateFunc func)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
const EnumPropertyItem rna_enum_modifier_triangulate_ngon_method_items[]
const EnumPropertyItem rna_enum_modifier_triangulate_quad_method_items[]
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
bool(* check)(bContext *C, wmOperator *op)
int(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
void(* ui)(bContext *C, wmOperator *op)
void(* cancel)(bContext *C, wmOperator *op)
struct ReportList * reports
void WM_event_add_fileselect(bContext *C, wmOperator *op)
void WM_operator_properties_filesel(wmOperatorType *ot, const int filter, const short type, const eFileSel_Action action, const eFileSel_Flag flag, const short display, const short sort)
bool WM_operator_winactive(bContext *C)