Cleanup: Remove unused include
[blender.git] / source / blender / io / usd / usd.hh
blob3ff67fe051cda635ad22dcd171f44a0e37050cf4
1 /* SPDX-FileCopyrightText: 2019 Blender Authors
3 * SPDX-License-Identifier: GPL-2.0-or-later */
5 #pragma once
7 #include <memory>
9 #include "../common/IO_orientation.hh"
11 #include "DEG_depsgraph.hh"
13 #include "DNA_modifier_types.h"
14 #include "RNA_types.hh"
16 struct bContext;
17 struct CacheArchiveHandle;
18 struct CacheReader;
19 struct ListBase;
20 struct Mesh;
21 struct Object;
22 struct ReportList;
23 struct wmJobWorkerStatus;
25 namespace blender::bke {
26 struct GeometrySet;
29 namespace blender::io::usd {
31 /**
32 * Behavior when the name of an imported material
33 * conflicts with an existing material.
35 enum eUSDMtlNameCollisionMode {
36 USD_MTL_NAME_COLLISION_MAKE_UNIQUE = 0,
37 USD_MTL_NAME_COLLISION_REFERENCE_EXISTING = 1,
40 /* Enums specifying the USD material purpose,
41 * corresponding to #pxr::UsdShadeTokens 'allPurpose',
42 * 'preview', and 'render', respectively. */
43 enum eUSDMtlPurpose {
44 USD_MTL_PURPOSE_ALL = 0,
45 USD_MTL_PURPOSE_PREVIEW = 1,
46 USD_MTL_PURPOSE_FULL = 2
49 /**
50 * Behavior for importing of custom
51 * attributes / properties outside
52 * a prim's regular schema.
54 enum eUSDAttrImportMode {
55 USD_ATTR_IMPORT_NONE = 0,
56 USD_ATTR_IMPORT_USER = 1,
57 USD_ATTR_IMPORT_ALL = 2,
60 /**
61 * Behavior when importing textures from a package
62 * (e.g., USDZ archive) or from a URI path.
64 enum eUSDTexImportMode {
65 USD_TEX_IMPORT_NONE = 0,
66 USD_TEX_IMPORT_PACK,
67 USD_TEX_IMPORT_COPY,
70 /**
71 * Behavior when the name of an imported texture
72 * file conflicts with an existing file.
74 enum eUSDTexNameCollisionMode {
75 USD_TEX_NAME_COLLISION_USE_EXISTING = 0,
76 USD_TEX_NAME_COLLISION_OVERWRITE = 1,
79 enum eSubdivExportMode {
80 /** Subdivision scheme = None, export base mesh without subdivision. */
81 USD_SUBDIV_IGNORE = 0,
82 /** Subdivision scheme = None, export subdivided mesh. */
83 USD_SUBDIV_TESSELLATE = 1,
84 /**
85 * Apply the USD subdivision scheme that is the closest match to Blender.
86 * Reverts to #USD_SUBDIV_TESSELLATE if the subdivision method is not supported.
88 USD_SUBDIV_BEST_MATCH = 2,
91 enum eUSDXformOpMode {
92 USD_XFORM_OP_TRS = 0,
93 USD_XFORM_OP_TOS = 1,
94 USD_XFORM_OP_MAT = 2,
97 enum eUSDZTextureDownscaleSize {
98 USD_TEXTURE_SIZE_CUSTOM = -1,
99 USD_TEXTURE_SIZE_KEEP = 0,
100 USD_TEXTURE_SIZE_256 = 256,
101 USD_TEXTURE_SIZE_512 = 512,
102 USD_TEXTURE_SIZE_1024 = 1024,
103 USD_TEXTURE_SIZE_2048 = 2048,
104 USD_TEXTURE_SIZE_4096 = 4096
108 * Behavior when exporting textures.
110 enum eUSDTexExportMode {
111 USD_TEX_EXPORT_KEEP = 0,
112 USD_TEX_EXPORT_PRESERVE,
113 USD_TEX_EXPORT_NEW_PATH,
116 typedef enum eUSDSceneUnits {
117 USD_SCENE_UNITS_CUSTOM = -1,
118 USD_SCENE_UNITS_METERS = 0,
119 USD_SCENE_UNITS_KILOMETERS = 1,
120 USD_SCENE_UNITS_CENTIMETERS = 2,
121 USD_SCENE_UNITS_MILLIMETERS = 3,
122 USD_SCENE_UNITS_INCHES = 4,
123 USD_SCENE_UNITS_FEET = 5,
124 USD_SCENE_UNITS_YARDS = 6,
125 } eUSDSceneUnits;
127 struct USDExportParams {
128 bool export_animation = false;
129 bool selected_objects_only = false;
130 bool visible_objects_only = true;
132 bool export_meshes = true;
133 bool export_lights = true;
134 bool export_cameras = true;
135 bool export_curves = true;
136 bool export_points = true;
137 bool export_volumes = true;
138 bool export_hair = true;
139 bool export_uvmaps = true;
140 bool rename_uvmaps = true;
141 bool export_normals = true;
142 bool export_mesh_colors = true;
143 bool export_materials = true;
145 bool export_armatures = true;
146 bool export_shapekeys = true;
147 bool only_deform_bones = false;
149 bool convert_world_material = true;
150 bool merge_parent_xform = false;
152 bool use_instancing = false;
153 bool export_custom_properties = true;
154 bool author_blender_name = true;
155 bool allow_unicode = false;
157 eSubdivExportMode export_subdiv = USD_SUBDIV_BEST_MATCH;
158 enum eEvaluationMode evaluation_mode = DAG_EVAL_VIEWPORT;
160 bool generate_preview_surface = true;
161 bool generate_materialx_network = true;
162 bool export_textures = false;
163 bool overwrite_textures = true;
164 bool relative_paths = true;
165 bool use_original_paths = false;
167 bool triangulate_meshes = false;
168 int quad_method = MOD_TRIANGULATE_QUAD_SHORTEDGE;
169 int ngon_method = MOD_TRIANGULATE_NGON_BEAUTY;
171 bool convert_orientation = false;
172 enum eIOAxis forward_axis = eIOAxis::IO_AXIS_NEGATIVE_Z;
173 enum eIOAxis up_axis = eIOAxis::IO_AXIS_Y;
174 eUSDXformOpMode xform_op_mode = eUSDXformOpMode::USD_XFORM_OP_TRS;
176 eUSDZTextureDownscaleSize usdz_downscale_size = eUSDZTextureDownscaleSize::USD_TEXTURE_SIZE_KEEP;
177 int usdz_downscale_custom_size = 128;
179 char root_prim_path[1024] = ""; /* FILE_MAX */
180 char collection[MAX_IDPROP_NAME] = "";
181 char custom_properties_namespace[MAX_IDPROP_NAME] = "";
183 eUSDSceneUnits convert_scene_units = eUSDSceneUnits::USD_SCENE_UNITS_METERS;
184 float custom_meters_per_unit = 1.0f;
186 /** Communication structure between the wmJob management code and the worker code. Currently used
187 * to generate safely reports from the worker thread. */
188 wmJobWorkerStatus *worker_status = nullptr;
191 struct USDImportParams {
192 char *prim_path_mask;
193 float scale;
194 float light_intensity_scale;
195 bool apply_unit_conversion_scale;
197 char mesh_read_flag;
198 bool set_frame_range;
199 bool is_sequence;
200 int sequence_len;
201 int offset;
203 bool import_defined_only;
204 bool import_visible_only;
206 bool import_cameras;
207 bool import_curves;
208 bool import_lights;
209 bool import_materials;
210 bool import_all_materials;
211 bool import_meshes;
212 bool import_points;
213 bool import_subdiv;
214 bool import_volumes;
216 bool import_shapes;
217 bool import_skeletons;
218 bool import_blendshapes;
220 bool create_collection;
221 bool create_world_material;
222 bool support_scene_instancing;
224 bool import_guide;
225 bool import_proxy;
226 bool import_render;
227 bool import_usd_preview;
228 bool set_material_blend;
230 bool validate_meshes;
231 bool merge_parent_xform;
233 eUSDMtlPurpose mtl_purpose;
234 eUSDMtlNameCollisionMode mtl_name_collision_mode;
235 eUSDTexImportMode import_textures_mode;
237 char import_textures_dir[768]; /* FILE_MAXDIR */
238 eUSDTexNameCollisionMode tex_name_collision_mode;
239 eUSDAttrImportMode attr_import_mode;
242 * Communication structure between the wmJob management code and the worker code. Currently used
243 * to generate safely reports from the worker thread.
245 wmJobWorkerStatus *worker_status;
249 * This struct is in place to store the mesh sequence parameters needed when reading a data from a
250 * USD file for the mesh sequence cache.
252 struct USDMeshReadParams {
253 double motion_sample_time; /* USD TimeCode in frames. */
254 int read_flags; /* MOD_MESHSEQ_xxx value that is set from MeshSeqCacheModifierData.read_flag. */
257 USDMeshReadParams create_mesh_read_params(double motion_sample_time, int read_flags);
260 * The USD_export takes a `as_background_job` parameter, and returns a boolean.
262 * When `as_background_job=true`, returns false immediately after scheduling
263 * a background job.
265 * When `as_background_job=false`, performs the export synchronously, and returns
266 * true when the export was ok, and false if there were any errors.
268 bool USD_export(const bContext *C,
269 const char *filepath,
270 const USDExportParams *params,
271 bool as_background_job,
272 ReportList *reports);
274 bool USD_import(const bContext *C,
275 const char *filepath,
276 const USDImportParams *params,
277 bool as_background_job,
278 ReportList *reports);
280 int USD_get_version();
282 /* USD Import and Mesh Cache interface. */
284 /* Similar to BLI_path_abs(), but also invokes the USD asset resolver
285 * to determine the absolute path. This is necessary for resolving
286 * paths with URIs that BLI_path_abs() would otherwise alter when
287 * attempting to normalize the path. */
288 void USD_path_abs(char *path, const char *basepath, bool for_import);
290 CacheArchiveHandle *USD_create_handle(Main *bmain, const char *filepath, ListBase *object_paths);
292 void USD_free_handle(CacheArchiveHandle *handle);
294 void USD_get_transform(CacheReader *reader, float r_mat[4][4], float time, float scale);
296 /** Either modifies current_mesh in-place or constructs a new mesh. */
297 void USD_read_geometry(CacheReader *reader,
298 const Object *ob,
299 blender::bke::GeometrySet &geometry_set,
300 USDMeshReadParams params,
301 const char **r_err_str);
303 bool USD_mesh_topology_changed(CacheReader *reader,
304 const Object *ob,
305 const Mesh *existing_mesh,
306 double time,
307 const char **r_err_str);
309 CacheReader *CacheReader_open_usd_object(CacheArchiveHandle *handle,
310 CacheReader *reader,
311 Object *object,
312 const char *object_path);
314 void USD_CacheReader_free(CacheReader *reader);
316 /** Data for registering USD IO hooks. */
317 struct USDHook {
319 /* Identifier used for class name. */
320 char idname[64];
321 /* Identifier used as label. */
322 char name[64];
323 /* Short help/description. */
324 char description[1024]; /* #RNA_DYN_DESCR_MAX */
326 /* rna_ext.data points to the USDHook class PyObject. */
327 ExtensionRNA rna_ext;
330 void USD_register_hook(std::unique_ptr<USDHook> hook);
332 * Remove the given entry from the list of registered hooks and
333 * free the allocated memory for the hook instance.
335 void USD_unregister_hook(USDHook *hook);
336 USDHook *USD_find_hook_name(const char idname[]);
338 double get_meters_per_unit(const USDExportParams &params);
340 }; // namespace blender::io::usd