Blender V4.3
usd_reader_material.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 NVIDIA Corporation. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#pragma once
5
6#include "usd.hh"
7
8#include "WM_types.hh"
9
10#include "BLI_map.hh"
11#include "BLI_vector.hh"
12
13#include <pxr/usd/usdShade/material.h>
14
15#include <string>
16
17struct Main;
18struct Material;
19struct bNode;
20struct bNodeTree;
21
22namespace blender::io::usd {
23
25
26/* Helper struct used when arranging nodes in columns, keeping track the
27 * occupancy information for a given column. I.e., for column n,
28 * column_offsets[n] is the y-offset (from top to bottom) of the occupied
29 * region in that column. */
31 float origx;
32 float origy;
34 const float horizontal_step;
35 const float vertical_step;
36
37 /* Map a USD shader prim path to the Blender node converted
38 * from that shader. This map is updated during shader
39 * conversion and is used to avoid creating duplicate nodes
40 * for a given shader. */
42
43 NodePlacementContext(float in_origx,
44 float in_origy,
45 float in_horizontal_step = 300.0f,
46 float in_vertical_step = 300.0f)
47 : origx(in_origx),
48 origy(in_origy),
49 column_offsets(64, 0.0f),
50 horizontal_step(in_horizontal_step),
51 vertical_step(in_vertical_step)
52 {
53 }
54};
55
56/* Helper struct which carries an assortment of optional
57 * information that is sometimes required when linking
58 * nodes together. */
60 bool is_color_corrected = false;
61
62 float opacity_threshold = 0.0f;
63};
64
65/* Converts USD materials to Blender representation. */
66
91 protected:
93
95
96 public:
98
99 Material *add_material(const pxr::UsdShadeMaterial &usd_material) const;
100
103 {
105 }
106
107 protected:
109 void import_usd_preview(Material *mtl, const pxr::UsdShadeShader &usd_shader) const;
110
111 void set_principled_node_inputs(bNode *principled_node,
112 bNodeTree *ntree,
113 const pxr::UsdShadeShader &usd_shader) const;
114
116 bool set_node_input(const pxr::UsdShadeInput &usd_input,
117 bNode *dest_node,
118 const char *dest_socket_name,
119 bNodeTree *ntree,
120 int column,
122 const ExtraLinkInfo &extra = {}) const;
123
128 bool follow_connection(const pxr::UsdShadeInput &usd_input,
129 bNode *dest_node,
130 const char *dest_socket_name,
131 bNodeTree *ntree,
132 int column,
133 NodePlacementContext *r_ctx,
134 const ExtraLinkInfo &extra = {}) const;
135
136 void convert_usd_uv_texture(const pxr::UsdShadeShader &usd_shader,
137 const pxr::TfToken &usd_source_name,
138 bNode *dest_node,
139 const char *dest_socket_name,
140 bNodeTree *ntree,
141 int column,
142 NodePlacementContext *r_ctx,
143 const ExtraLinkInfo &extra = {}) const;
144
145 void convert_usd_transform_2d(const pxr::UsdShadeShader &usd_shader,
146 bNode *dest_node,
147 const char *dest_socket_name,
148 bNodeTree *ntree,
149 int column,
150 NodePlacementContext *r_ctx) const;
151
156 void load_tex_image(const pxr::UsdShadeShader &usd_shader,
157 bNode *tex_image,
158 const ExtraLinkInfo &extra = {}) const;
159
166 void convert_usd_primvar_reader_float2(const pxr::UsdShadeShader &usd_shader,
167 const pxr::TfToken &usd_source_name,
168 bNode *dest_node,
169 const char *dest_socket_name,
170 bNodeTree *ntree,
171 int column,
172 NodePlacementContext *r_ctx) const;
173};
174
175/* Utility functions. */
176
184
199 const pxr::SdfPath &usd_mat_path,
200 const USDImportParams &params,
202 const blender::Map<std::string, std::string> &usd_path_to_mat_name);
203
204} // namespace blender::io::usd
Material * add_material(const pxr::UsdShadeMaterial &usd_material) const
USDMaterialReader(const USDImportParams &params, Main *bmain)
void convert_usd_transform_2d(const pxr::UsdShadeShader &usd_shader, bNode *dest_node, const char *dest_socket_name, bNodeTree *ntree, int column, NodePlacementContext *r_ctx) const
void convert_usd_primvar_reader_float2(const pxr::UsdShadeShader &usd_shader, const pxr::TfToken &usd_source_name, bNode *dest_node, const char *dest_socket_name, bNodeTree *ntree, int column, NodePlacementContext *r_ctx) const
void convert_usd_uv_texture(const pxr::UsdShadeShader &usd_shader, const pxr::TfToken &usd_source_name, bNode *dest_node, const char *dest_socket_name, bNodeTree *ntree, int column, NodePlacementContext *r_ctx, const ExtraLinkInfo &extra={}) const
bool set_node_input(const pxr::UsdShadeInput &usd_input, bNode *dest_node, const char *dest_socket_name, bNodeTree *ntree, int column, NodePlacementContext *r_ctx, const ExtraLinkInfo &extra={}) const
bool follow_connection(const pxr::UsdShadeInput &usd_input, bNode *dest_node, const char *dest_socket_name, bNodeTree *ntree, int column, NodePlacementContext *r_ctx, const ExtraLinkInfo &extra={}) const
void import_usd_preview(Material *mtl, const pxr::UsdShadeShader &usd_shader) const
void set_principled_node_inputs(bNode *principled_node, bNodeTree *ntree, const pxr::UsdShadeShader &usd_shader) const
void load_tex_image(const pxr::UsdShadeShader &usd_shader, bNode *tex_image, const ExtraLinkInfo &extra={}) const
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void build_material_map(const Main *bmain, blender::Map< std::string, Material * > *r_mat_map)
Material * find_existing_material(const pxr::SdfPath &usd_mat_path, const USDImportParams &params, const blender::Map< std::string, Material * > &mat_map, const blender::Map< std::string, std::string > &usd_path_to_mat_name)
NodePlacementContext(float in_origx, float in_origy, float in_horizontal_step=300.0f, float in_vertical_step=300.0f)
blender::Vector< float, 0 > column_offsets
wmJobWorkerStatus * worker_status
Definition usd.hh:228
ReportList * reports
Definition WM_types.hh:985