35#include <pxr/base/gf/vec3f.h>
36#include <pxr/usd/ar/packageUtils.h>
37#include <pxr/usd/usdShade/material.h>
38#include <pxr/usd/usdShade/shader.h>
46static const pxr::TfToken
a(
"a", pxr::TfToken::Immortal);
47static const pxr::TfToken
b(
"b", pxr::TfToken::Immortal);
48static const pxr::TfToken
bias(
"bias", pxr::TfToken::Immortal);
49static const pxr::TfToken
clearcoat(
"clearcoat", pxr::TfToken::Immortal);
51static const pxr::TfToken
diffuseColor(
"diffuseColor", pxr::TfToken::Immortal);
52static const pxr::TfToken
displacement(
"displacement", pxr::TfToken::Immortal);
53static const pxr::TfToken
emissiveColor(
"emissiveColor", pxr::TfToken::Immortal);
54static const pxr::TfToken
file(
"file", pxr::TfToken::Immortal);
55static const pxr::TfToken
g(
"g", pxr::TfToken::Immortal);
56static const pxr::TfToken
ior(
"ior", pxr::TfToken::Immortal);
57static const pxr::TfToken
in(
"in", pxr::TfToken::Immortal);
58static const pxr::TfToken
metallic(
"metallic", pxr::TfToken::Immortal);
59static const pxr::TfToken
normal(
"normal", pxr::TfToken::Immortal);
60static const pxr::TfToken
occlusion(
"occlusion", pxr::TfToken::Immortal);
61static const pxr::TfToken
opacity(
"opacity", pxr::TfToken::Immortal);
63static const pxr::TfToken
r(
"r", pxr::TfToken::Immortal);
64static const pxr::TfToken
rgb(
"rgb", pxr::TfToken::Immortal);
65static const pxr::TfToken
rgba(
"rgba", pxr::TfToken::Immortal);
66static const pxr::TfToken
roughness(
"roughness", pxr::TfToken::Immortal);
67static const pxr::TfToken
scale(
"scale", pxr::TfToken::Immortal);
69static const pxr::TfToken
specularColor(
"specularColor", pxr::TfToken::Immortal);
70static const pxr::TfToken
st(
"st", pxr::TfToken::Immortal);
71static const pxr::TfToken
varname(
"varname", pxr::TfToken::Immortal);
74static const pxr::TfToken
auto_(
"auto", pxr::TfToken::Immortal);
75static const pxr::TfToken
sRGB(
"sRGB", pxr::TfToken::Immortal);
76static const pxr::TfToken
raw(
"raw", pxr::TfToken::Immortal);
77static const pxr::TfToken
RAW(
"RAW", pxr::TfToken::Immortal);
80static const pxr::TfToken
black(
"black", pxr::TfToken::Immortal);
81static const pxr::TfToken
clamp(
"clamp", pxr::TfToken::Immortal);
82static const pxr::TfToken
repeat(
"repeat", pxr::TfToken::Immortal);
83static const pxr::TfToken
mirror(
"mirror", pxr::TfToken::Immortal);
84static const pxr::TfToken
wrapS(
"wrapS", pxr::TfToken::Immortal);
85static const pxr::TfToken
wrapT(
"wrapT", pxr::TfToken::Immortal);
88static const pxr::TfToken
rotation(
"rotation", pxr::TfToken::Immortal);
89static const pxr::TfToken
translation(
"translation", pxr::TfToken::Immortal);
94 pxr::TfToken::Immortal);
95static const pxr::TfToken
UsdUVTexture(
"UsdUVTexture", pxr::TfToken::Immortal);
96static const pxr::TfToken
UsdTransform2d(
"UsdTransform2d", pxr::TfToken::Immortal);
119 if (!source_socket) {
140 for (
const auto &PropertySpec : attribute.GetPropertyStack(pxr::UsdTimeCode::EarliestTime())) {
141 if (PropertySpec->HasDefaultValue() ||
142 PropertySpec->GetLayer()->GetNumTimeSamplesForPath(PropertySpec->GetPath()) > 0)
144 return PropertySpec->GetLayer();
148 return pxr::SdfLayerHandle();
156 STRNCPY(base_udim_path, file_path.c_str());
162 int tile_start, tile_range;
167 udim_tiles.
append(tile_number);
181 for (
int tile_number :
indices) {
198 if (opacity_input.HasConnectedSource()) {
203 if (opacity_input.GetAttr().HasAuthoredValue() && opacity_input.GetAttr().Get(&val)) {
204 float opacity = val.Get<
float>();
216 float default_value = 0.0f)
219 return default_value;
224 if (!opacity_threshold_input) {
225 return default_value;
229 if (opacity_threshold_input.GetAttr().HasAuthoredValue() &&
230 opacity_threshold_input.GetAttr().Get(&val))
232 return val.Get<
float>();
235 return default_value;
241 return pxr::TfToken();
246 if (!color_space_input) {
247 return pxr::TfToken();
250 pxr::VtValue color_space_val;
251 if (color_space_input.Get(&color_space_val) && color_space_val.IsHolding<pxr::TfToken>()) {
252 return color_space_val.Get<pxr::TfToken>();
255 return pxr::TfToken();
267 return default_value;
270 pxr::VtValue wrap_input_val;
271 if (!(wrap_input.Get(&wrap_input_val) && wrap_input_val.IsHolding<pxr::TfToken>())) {
272 return default_value;
275 pxr::TfToken wrap_val = wrap_input_val.Get<pxr::TfToken>();
293 return default_value;
300 pxr::UsdShadeShader &r_preview_surface)
306 if (pxr::UsdShadeShader surf_shader = usd_material.ComputeSurfaceSource()) {
308 pxr::TfToken shader_id;
310 r_preview_surface = surf_shader;
322 if (!(mtl && usd_preview)) {
328 if (diffuse_color_input.GetAttr().HasAuthoredValue() &&
329 diffuse_color_input.GetAttr().Get(&val) && val.IsHolding<pxr::GfVec3f>())
331 pxr::GfVec3f color = val.UncheckedGet<pxr::GfVec3f>();
340 if (metallic_input.GetAttr().HasAuthoredValue() && metallic_input.GetAttr().Get(&val) &&
341 val.IsHolding<
float>())
349 if (roughness_input.GetAttr().HasAuthoredValue() && roughness_input.GetAttr().Get(&val) &&
350 val.IsHolding<
float>())
357static pxr::UsdShadeInput
get_input(
const pxr::UsdShadeShader &usd_shader,
358 const pxr::TfToken &input_name)
360 pxr::UsdShadeInput
input = usd_shader.GetInput(input_name);
365 for (
const pxr::UsdShadeConnectionSourceInfo &source_info :
input.GetConnectedSources()) {
366 pxr::UsdShadeShader shader = pxr::UsdShadeShader(source_info.source.GetPrim());
367 pxr::UsdShadeInput secondary_input = shader.GetInput(source_info.sourceName);
368 if (secondary_input) {
369 input = secondary_input;
386 "%s: Error: Couldn't get input socket %s for node %s",
419 std::string key = usd_shader.GetPath().GetAsString();
441 : params_(
params), bmain_(bmain)
446 const bool read_usd_preview)
const
452 std::string mtl_name = usd_material.GetPrim().GetName().GetString();
458 if (read_usd_preview) {
469 const pxr::UsdShadeMaterial &usd_material)
const
473 pxr::UsdShadeShader usd_preview;
479 if (params_.import_usd_preview) {
486 const pxr::UsdShadeMaterial &usd_material,
487 const pxr::UsdShadeShader &usd_shader)
const
489 if (!(mtl && usd_shader)) {
498 nullptr, &mtl->
id,
"Shader Nodetree",
"ShaderNodeTree");
514 if (pxr::UsdShadeShader disp_shader = usd_material.ComputeDisplacementSource()) {
525 if (params_.set_material_blend) {
534 const pxr::UsdShadeShader &usd_shader)
const
549 set_node_input(diffuse_input, principled,
"Base Color", ntree, column, context, extra);
552 float emission_strength = 0.0f;
557 emissive_input, principled,
"Emission Color", ntree, column, context, extra))
559 emission_strength = 1.0f;
564 *principled,
SOCK_IN,
"Emission Strength");
568 set_node_input(specular_input, principled,
"Specular Tint", ntree, column, context);
572 set_node_input(metallic_input, principled,
"Metallic", ntree, column, context);
576 set_node_input(roughness_input, principled,
"Roughness", ntree, column, context);
580 set_node_input(coat_input, principled,
"Coat Weight", ntree, column, context);
585 set_node_input(coat_roughness_input, principled,
"Coat Roughness", ntree, column, context);
591 set_node_input(opacity_input, principled,
"Alpha", ntree, column, context, extra);
594 if (pxr::UsdShadeInput ior_input = usd_shader.GetInput(
usdtokens::ior)) {
595 set_node_input(ior_input, principled,
"IOR", ntree, column, context);
599 set_node_input(normal_input, principled,
"Normal", ntree, column, context);
605 const pxr::UsdShadeShader &usd_shader)
const
609 if (!displacement_input) {
625 set_node_input(displacement_input, displacement_node, height, ntree, column, context, extra);
630 if (!displacement_input.HasConnectedSource()) {
633 *displacement_node,
SOCK_IN,
"Midlevel");
642 link_nodes(ntree, displacement_node,
"Displacement",
output,
"Displacement");
654 if (!(usd_input && dest_node)) {
658 if (usd_input.HasConnectedSource()) {
661 return follow_connection(usd_input, dest_node, dest_socket_name, ntree, column, ctx, extra);
668 CLOG_ERROR(&
LOG,
"Couldn't get destination node socket %s", dest_socket_name.
c_str());
673 if (!usd_input.Get(&val)) {
675 "Couldn't get value for usd shader input %s",
676 usd_input.GetPrim().GetPath().GetAsString().c_str());
680 switch (sock->
type) {
682 if (val.IsHolding<
float>()) {
686 else if (val.IsHolding<pxr::GfVec3f>()) {
687 pxr::GfVec3f v3f = val.UncheckedGet<pxr::GfVec3f>();
688 float average = (v3f[0] + v3f[1] + v3f[2]) / 3.0f;
694 if (val.IsHolding<pxr::GfVec3f>()) {
695 pxr::GfVec3f v3f = val.UncheckedGet<pxr::GfVec3f>();
701 if (val.IsHolding<pxr::GfVec3f>()) {
702 pxr::GfVec3f v3f = val.UncheckedGet<pxr::GfVec3f>();
706 else if (val.IsHolding<pxr::GfVec2f>()) {
707 pxr::GfVec2f v2f = val.UncheckedGet<pxr::GfVec2f>();
714 "Unexpected type %s for destination node socket %s",
716 dest_socket_name.
c_str());
746 bool feeds_normal_map,
752 pxr::GfVec4f scale(1.0f, 1.0f, 1.0f, 1.0f);
753 pxr::GfVec4f bias(0.0f, 0.0f, 0.0f, 0.0f);
756 if (scale_input.Get(&val) && val.CanCast<pxr::GfVec4f>()) {
757 scale = pxr::VtValue::Cast<pxr::GfVec4f>(val).UncheckedGet<pxr::GfVec4f>();
759 if (bias_input.Get(&val) && val.CanCast<pxr::GfVec4f>()) {
760 bias = pxr::VtValue::Cast<pxr::GfVec4f>(val).UncheckedGet<pxr::GfVec4f>();
764 if (scale == pxr::GfVec4f{1.0f, 1.0f, 1.0f, 1.0f} &&
765 bias == pxr::GfVec4f{0.0f, 0.0f, 0.0f, 0.0f})
771 if (feeds_normal_map && (scale[0] == 2.0f && scale[1] == 2.0f && scale[2] == 2.0f) &&
772 (bias[0] == -1.0f && bias[1] == -1.0f && bias[2] == -1.0f))
791 scale_bias.
node = node;
826 const pxr::TfToken &usd_source_name,
846 separate_color.
node = node;
860 return separate_color;
905 pxr::GfVec4f scale(1.0f, 1.0f, 1.0f, 1.0f);
906 pxr::GfVec4f bias(0.0f, 0.0f, 0.0f, 0.0f);
909 if (scale_input.Get(&val) && val.CanCast<pxr::GfVec4f>()) {
910 scale = pxr::VtValue::Cast<pxr::GfVec4f>(val).UncheckedGet<pxr::GfVec4f>();
912 if (bias_input.Get(&val) && val.CanCast<pxr::GfVec4f>()) {
913 bias = pxr::VtValue::Cast<pxr::GfVec4f>(val).UncheckedGet<pxr::GfVec4f>();
916 const float scale_avg = (scale[0] + scale[1] + scale[2]) / 3.0f;
917 const float bias_avg = (bias[0] + bias[1] + bias[2]) / 3.0f;
926 const pxr::TfToken &output_name)
929 pxr::UsdShadeOutput
output = node_graph.GetOutput(output_name);
931 return pxr::UsdShadeShader();
934 pxr::UsdShadeAttributeVector attrs = pxr::UsdShadeUtils::GetValueProducingAttributes(
output);
936 return pxr::UsdShadeShader();
939 pxr::UsdAttribute attr = attrs[0];
941 std::pair<pxr::TfToken, pxr::UsdShadeAttributeType> name_and_type =
942 pxr::UsdShadeUtils::GetBaseNameAndType(attr.GetName());
944 pxr::UsdShadeShader shader(attr.GetPrim());
945 if (name_and_type.second != pxr::UsdShadeAttributeType::Output || !shader) {
946 return pxr::UsdShadeShader();
960 if (!(usd_input && dest_node && !dest_socket_name.
is_empty() && ntree)) {
964 pxr::UsdShadeConnectableAPI source;
965 pxr::TfToken source_name;
966 pxr::UsdShadeAttributeType source_type;
968 usd_input.GetConnectedSource(&source, &source_name, &source_type);
974 const pxr::UsdPrim source_prim = source.GetPrim();
975 pxr::UsdShadeShader source_shader;
976 if (source_prim.IsA<pxr::UsdShadeShader>()) {
977 source_shader = pxr::UsdShadeShader(source_prim);
979 else if (source_prim.IsA<pxr::UsdShadeNodeGraph>()) {
980 pxr::UsdShadeNodeGraph node_graph(source_prim);
984 if (!source_shader) {
988 pxr::TfToken shader_id;
989 if (!source_shader.GetShaderId(&shader_id)) {
991 "Couldn't get shader id for source shader %s",
992 source_shader.GetPath().GetAsString().c_str());
1002 const bool is_normal_map = dest_socket_name ==
"Normal";
1003 if (is_normal_map) {
1010 source_shader, source_name, ntree, column + shift, ctx);
1011 if (separate_color.
node) {
1017 if (dest_socket_name ==
"Height") {
1021 scale_bias =
add_scale_bias(source_shader, ntree, column + shift, is_normal_map, ctx);
1026 bNode *target_node = dest_node;
1028 if (normal_map.
node) {
1031 if (scale_bias.
node) {
1044 target_node = scale_bias.
node;
1049 target_node = normal_map.
node;
1055 else if (scale_bias.
node) {
1056 if (separate_color.
node) {
1058 separate_color.
node,
1065 separate_color.
node,
1072 target_node = scale_bias.
node;
1076 else if (separate_color.
node) {
1079 separate_color.
node,
1084 target_node = separate_color.
node;
1097 if (separate_color.
node) {
1099 separate_color.
node,
1105 target_node = lessthan.
node;
1121 source_shader, source_name, dest_node, dest_socket_name, ntree, column + 1, ctx);
1128 StringRef shader_id_name(shader_id.GetString());
1129 if (shader_id_name.
startswith(
"UsdPrimvarReader_")) {
1131 if (type_offset >= 0) {
1134 source_shader, output_type, dest_node, dest_socket_name, ntree, column + 1, ctx);
1143 const pxr::TfToken &usd_source_name,
1151 if (!usd_shader || !dest_node || !ntree || dest_socket_name.
is_empty()) {
1157 if (tex_image ==
nullptr) {
1175 link_nodes(ntree, tex_image, source_socket_name, dest_node, dest_socket_name);
1178 if (pxr::UsdShadeInput st_input = usd_shader.GetInput(
usdtokens::st)) {
1179 set_node_input(st_input, tex_image,
"Vector", ntree, column, ctx);
1190 if (!usd_shader || !dest_node || !ntree || dest_socket_name.
is_empty()) {
1196 if (mapping ==
nullptr) {
1210 if (scale_input.Get(&val) && val.CanCast<pxr::GfVec2f>()) {
1211 pxr::GfVec2f scale_val = val.Cast<pxr::GfVec2f>().UncheckedGet<pxr::GfVec2f>();
1212 float scale[3] = {scale_val[0], scale_val[1], 1.0f};
1221 if (trans_input.Get(&val) && val.CanCast<pxr::GfVec2f>()) {
1222 pxr::GfVec2f trans_val = val.Cast<pxr::GfVec2f>().UncheckedGet<pxr::GfVec2f>();
1223 float location[3] = {trans_val[0], trans_val[1], 0.0f};
1232 if (rot_input.Get(&val) && val.CanCast<
float>()) {
1233 float rot_val = val.Cast<
float>().UncheckedGet<float>() *
M_PI / 180.0f;
1234 float rot[3] = {0.0f, 0.0f, rot_val};
1242 link_nodes(ntree, mapping,
"Vector", dest_node, dest_socket_name);
1245 if (pxr::UsdShadeInput in_input = usd_shader.GetInput(
usdtokens::in)) {
1263 "Couldn't get file input property for USD shader %s",
1264 usd_shader.GetPath().GetAsString().c_str());
1270 if (file_input.HasConnectedSource()) {
1271 pxr::UsdShadeConnectableAPI source;
1272 pxr::TfToken source_name;
1273 pxr::UsdShadeAttributeType source_type;
1275 if (file_input.GetConnectedSource(&source, &source_name, &source_type)) {
1276 file_input = source.GetInput(source_name);
1280 "Couldn't get connected source for file input %s (%s)\n",
1281 file_input.GetPrim().GetPath().GetText(),
1282 file_input.GetFullName().GetText());
1286 pxr::VtValue file_val;
1287 if (!file_input.Get(&file_val) || !file_val.IsHolding<pxr::SdfAssetPath>()) {
1289 "Couldn't get file input value for USD shader %s",
1290 usd_shader.GetPath().GetAsString().c_str());
1294 const pxr::SdfAssetPath &asset_path = file_val.Get<pxr::SdfAssetPath>();
1295 std::string file_path = asset_path.GetResolvedPath();
1297 if (file_path.empty()) {
1299 file_path = asset_path.GetAssetPath();
1303 if (pxr::SdfLayerHandle layer_handle =
get_layer_handle(file_input.GetAttr())) {
1304 file_path = layer_handle->ComputeAbsolutePath(file_path);
1309 if (file_path.empty()) {
1311 "Couldn't resolve image asset '%s' for Texture Image node",
1312 asset_path.GetAssetPath().c_str());
1317 const bool is_relative = pxr::ArIsPackageRelativePath(file_path);
1318 const bool import_textures = params_.import_textures_mode !=
USD_TEX_IMPORT_NONE && is_relative;
1320 std::string imported_file_source_path;
1322 if (import_textures) {
1323 imported_file_source_path = file_path;
1329 params_.import_textures_dir;
1334 params_.tex_name_collision_mode;
1336 file_path =
import_asset(file_path.c_str(), textures_dir, name_collision_mode,
reports());
1347 const char *im_file = file_path.c_str();
1350 CLOG_WARN(&
LOG,
"Couldn't open image file '%s' for Texture Image node", im_file);
1358 tex_image->
id = &image->
id;
1367 if (color_space.IsEmpty()) {
1368 color_space = file_input.GetAttr().GetColorSpace();
1371 if (color_space.IsEmpty()) {
1401 if (import_textures && imported_file_source_path != file_path) {
1416 const pxr::TfToken & ,
1423 if (!usd_shader || !dest_node || !ntree || dest_socket_name.
is_empty()) {
1429 if (uv_map ==
nullptr) {
1443 if (varname_input) {
1444 for (
const pxr::UsdShadeConnectionSourceInfo &source_info :
1445 varname_input.GetConnectedSources())
1447 pxr::UsdShadeShader shader = pxr::UsdShadeShader(source_info.source.GetPrim());
1448 pxr::UsdShadeInput secondary_varname_input = shader.GetInput(source_info.sourceName);
1449 if (secondary_varname_input) {
1450 varname_input = secondary_varname_input;
1456 if (varname_input) {
1457 pxr::VtValue varname_val;
1460 if (varname_input.Get(&varname_val) && varname_val.CanCastToTypeid(
typeid(std::string))) {
1461 std::string varname = varname_val.Cast<std::string>().Get<std::string>();
1462 if (!varname.empty()) {
1471 link_nodes(ntree, uv_map,
"UV", dest_node, dest_socket_name);
1482 if (!usd_shader || !dest_node || !ntree) {
1488 if (attribute ==
nullptr) {
1502 if (varname_input) {
1503 for (
const pxr::UsdShadeConnectionSourceInfo &source_info :
1504 varname_input.GetConnectedSources())
1506 pxr::UsdShadeShader shader = pxr::UsdShadeShader(source_info.source.GetPrim());
1507 pxr::UsdShadeInput secondary_varname_input = shader.GetInput(source_info.sourceName);
1508 if (secondary_varname_input) {
1509 varname_input = secondary_varname_input;
1515 if (varname_input) {
1516 pxr::VtValue varname_val;
1519 if (varname_input.Get(&varname_val) && varname_val.CanCastToTypeid(
typeid(std::string))) {
1520 std::string varname = varname_val.Cast<std::string>().Get<std::string>();
1521 if (!varname.empty()) {
1530 if (
ELEM(output_type,
"float",
"int")) {
1531 link_nodes(ntree, attribute,
"Fac", dest_node, dest_socket_name);
1533 else if (
ELEM(output_type,
"float3",
"float4")) {
1534 link_nodes(ntree, attribute,
"Color", dest_node, dest_socket_name);
1536 else if (
ELEM(output_type,
"vector",
"normal",
"point")) {
1537 link_nodes(ntree, attribute,
"Vector", dest_node, dest_socket_name);
1546 std::string usd_name =
make_safe_name(material->id.name + 2,
true);
1547 r_mat_map.
add_new(usd_name, material);
void BKE_image_packfiles(ReportList *reports, Image *ima, const char *basepath)
Image * BKE_image_load_exists(Main *bmain, const char *filepath, bool *r_exists=nullptr)
bool BKE_image_get_tile_info(char *filepath, ListBase *tiles, int *r_tile_start, int *r_tile_range)
bool BKE_image_has_packedfile(const Image *image)
ImageTile * BKE_image_add_tile(Image *ima, int tile_number, const char *label)
General operations, lookup, etc. for materials.
Material * BKE_material_add(Main *bmain, const char *name)
#define SH_NODE_TEX_IMAGE
#define SH_NODE_BSDF_PRINCIPLED
#define SH_NODE_SEPARATE_COLOR
#define SH_NODE_VECTOR_MATH
#define SH_NODE_NORMAL_MAP
#define SH_NODE_OUTPUT_MATERIAL
#define SH_NODE_DISPLACEMENT
#define SH_NODE_ATTRIBUTE
void BKE_ntree_update_after_single_tree_change(Main &bmain, bNodeTree &modified_tree, const NodeTreeUpdateExtraParams ¶ms={})
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
#define BLI_assert_msg(a, msg)
File and directory operations.
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
bool BLI_is_dir(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
#define LISTBASE_FOREACH(type, var, list)
void void BLI_freelistN(ListBase *listbase) ATTR_NONNULL(1)
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
char * STRNCPY(char(&dst)[N], const char *src)
#define POINTER_AS_INT(i)
#define CLOG_ERROR(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
@ MA_SURFACE_METHOD_FORWARD
@ NODE_VECTOR_MATH_MULTIPLY_ADD
@ SHD_IMAGE_EXTENSION_MIRROR
@ SHD_IMAGE_EXTENSION_CLIP
@ SHD_IMAGE_EXTENSION_REPEAT
@ SHD_IMAGE_EXTENSION_EXTEND
const char * IMB_colormanagement_srgb_colorspace_name_get()
@ COLOR_ROLE_DEFAULT_BYTE
const char * IMB_colormanagement_role_colorspace_name_get(int role)
Value lookup_default(const Key &key, const Value &default_value) const
void add_new(const Key &key, const Value &value)
constexpr int64_t rfind(char c, int64_t pos=INT64_MAX) const
constexpr bool is_empty() const
constexpr bool startswith(StringRef prefix) const
constexpr const char * c_str() const
constexpr StringRef drop_prefix(int64_t n) const
void append(const T &value)
bool follow_connection(const pxr::UsdShadeInput &usd_input, bNode *dest_node, const StringRefNull dest_socket_name, bNodeTree *ntree, int column, NodePlacementContext &ctx, const ExtraLinkInfo &extra={}) const
void convert_usd_transform_2d(const pxr::UsdShadeShader &usd_shader, bNode *dest_node, const StringRefNull dest_socket_name, bNodeTree *ntree, int column, NodePlacementContext &ctx) const
Material * add_material(const pxr::UsdShadeMaterial &usd_material, bool read_usd_preview=true) const
void import_usd_preview_nodes(Material *mtl, const pxr::UsdShadeMaterial &usd_material, const pxr::UsdShadeShader &usd_shader) const
USDMaterialReader(const USDImportParams ¶ms, Main &bmain)
bool set_displacement_node_inputs(bNodeTree *ntree, bNode *output, const pxr::UsdShadeShader &usd_shader) const
bool set_node_input(const pxr::UsdShadeInput &usd_input, bNode *dest_node, const StringRefNull dest_socket_name, bNodeTree *ntree, int column, NodePlacementContext &ctx, const ExtraLinkInfo &extra={}) const
void convert_usd_primvar_reader_generic(const pxr::UsdShadeShader &usd_shader, StringRef output_type, bNode *dest_node, const StringRefNull dest_socket_name, bNodeTree *ntree, int column, NodePlacementContext &ctx) const
void convert_usd_primvar_reader_float2(const pxr::UsdShadeShader &usd_shader, const pxr::TfToken &usd_source_name, bNode *dest_node, const StringRefNull dest_socket_name, bNodeTree *ntree, int column, NodePlacementContext &ctx) const
ReportList * reports() const
void convert_usd_uv_texture(const pxr::UsdShadeShader &usd_shader, const pxr::TfToken &usd_source_name, bNode *dest_node, const StringRefNull dest_socket_name, bNodeTree *ntree, int column, NodePlacementContext &ctx, const ExtraLinkInfo &extra={}) const
void set_principled_node_inputs(bNode *principled_node, bNodeTree *ntree, const pxr::UsdShadeShader &usd_shader) const
void import_usd_preview(Material *mtl, const pxr::UsdShadeMaterial &usd_material) const
void load_tex_image(const pxr::UsdShadeShader &usd_shader, bNode *tex_image, const ExtraLinkInfo &extra={}) const
#define ID_BLEND_PATH(_bmain, _id)
CCL_NAMESPACE_BEGIN ccl_device float invert(const float color, const float factor)
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
const ccl_global KernelWorkTile * tile
ccl_device_inline float average(const float2 a)
bNodeTree * node_tree_add_tree_embedded(Main *bmain, ID *owner_id, StringRefNull name, StringRefNull idname)
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, StringRef identifier)
int node_count_socket_links(const bNodeTree &ntree, const bNodeSocket &sock)
bNode * node_add_static_node(const bContext *C, bNodeTree &ntree, int type)
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
void node_set_active(bNodeTree &ntree, bNode &node)
const char * temp_textures_dir()
static IntermediateNode add_separate_color(const pxr::UsdShadeShader &usd_shader, const pxr::TfToken &usd_source_name, bNodeTree *ntree, int column, NodePlacementContext &ctx)
Map< std::string, bNode * > ShaderToNodeMap
std::string import_asset(const char *src, const char *import_dir, eUSDTexNameCollisionMode name_collision_mode, ReportList *reports)
bool is_udim_path(const std::string &path)
static IntermediateNode add_scale_bias_adjust(bNodeTree *ntree, int column, NodePlacementContext &ctx)
void set_id_props_from_prim(ID *id, const pxr::UsdPrim &prim, const eUSDAttrImportMode attr_import_mode, const pxr::UsdTimeCode time_code)
static IntermediateNode add_scale_bias(const pxr::UsdShadeShader &usd_shader, bNodeTree *ntree, int column, bool feeds_normal_map, NodePlacementContext &ctx)
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 ¶ms, const blender::Map< std::string, Material * > &mat_map, const blender::Map< pxr::SdfPath, Material * > &usd_path_to_mat)
static pxr::UsdShadeShader node_graph_output_source(const pxr::UsdShadeNodeGraph &node_graph, const pxr::TfToken &output_name)
@ USD_TEX_NAME_COLLISION_OVERWRITE
static IntermediateNode add_oneminus(bNodeTree *ntree, int column, NodePlacementContext &ctx)
std::string make_safe_name(const StringRef name, bool allow_unicode)
static IntermediateNode add_normal_map(bNodeTree *ntree, int column, NodePlacementContext &ctx)
void ensure_usd_source_path_prop(const std::string &path, ID *id)
@ USD_MTL_NAME_COLLISION_MAKE_UNIQUE
static void configure_displacement(const pxr::UsdShadeShader &usd_shader, bNode *displacement_node)
static IntermediateNode add_lessthan(bNodeTree *ntree, float threshold, int column, NodePlacementContext &ctx)
VecBase< float, 2 > float2
static const pxr::TfToken sRGB("sRGB", pxr::TfToken::Immortal)
static const pxr::TfToken st("st", pxr::TfToken::Immortal)
static const pxr::TfToken bias("bias", pxr::TfToken::Immortal)
static const pxr::TfToken opacity("opacity", pxr::TfToken::Immortal)
static const pxr::TfToken UsdPreviewSurface("UsdPreviewSurface", pxr::TfToken::Immortal)
static const pxr::TfToken sourceColorSpace("sourceColorSpace", pxr::TfToken::Immortal)
static const pxr::TfToken clearcoat("clearcoat", pxr::TfToken::Immortal)
static const pxr::TfToken varname("varname", pxr::TfToken::Immortal)
static const pxr::TfToken emissiveColor("emissiveColor", pxr::TfToken::Immortal)
static const pxr::TfToken RAW("RAW", pxr::TfToken::Immortal)
static const pxr::TfToken r("r", pxr::TfToken::Immortal)
static const pxr::TfToken UsdUVTexture("UsdUVTexture", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static const pxr::TfToken rotation("rotation", pxr::TfToken::Immortal)
static const pxr::TfToken ior("ior", pxr::TfToken::Immortal)
static const pxr::TfToken rgba("rgba", pxr::TfToken::Immortal)
static const pxr::TfToken translation("translation", pxr::TfToken::Immortal)
static const pxr::TfToken raw("raw", pxr::TfToken::Immortal)
static const pxr::TfToken g("g", pxr::TfToken::Immortal)
static const pxr::TfToken in("in", pxr::TfToken::Immortal)
static const pxr::TfToken occlusion("occlusion", pxr::TfToken::Immortal)
static const pxr::TfToken auto_("auto", pxr::TfToken::Immortal)
static const pxr::TfToken clearcoatRoughness("clearcoatRoughness", pxr::TfToken::Immortal)
static const pxr::TfToken scale("scale", pxr::TfToken::Immortal)
static const pxr::TfToken file("file", pxr::TfToken::Immortal)
static const pxr::TfToken mirror("mirror", pxr::TfToken::Immortal)
static const pxr::TfToken opacityThreshold("opacityThreshold", pxr::TfToken::Immortal)
static const pxr::TfToken normal("normal", pxr::TfToken::Immortal)
static const pxr::TfToken clamp("clamp", pxr::TfToken::Immortal)
static const pxr::TfToken black("black", pxr::TfToken::Immortal)
static const pxr::TfToken UsdTransform2d("UsdTransform2d", pxr::TfToken::Immortal)
static const pxr::TfToken displacement("displacement", pxr::TfToken::Immortal)
static const pxr::TfToken roughness("roughness", pxr::TfToken::Immortal)
static const pxr::TfToken repeat("repeat", pxr::TfToken::Immortal)
static const pxr::TfToken metallic("metallic", pxr::TfToken::Immortal)
static const pxr::TfToken diffuseColor("diffuseColor", pxr::TfToken::Immortal)
static const pxr::TfToken wrapS("wrapS", pxr::TfToken::Immortal)
static const pxr::TfToken rgb("rgb", pxr::TfToken::Immortal)
static const pxr::TfToken specularColor("specularColor", pxr::TfToken::Immortal)
static const pxr::TfToken wrapT("wrapT", pxr::TfToken::Immortal)
static const pxr::TfToken a("a", pxr::TfToken::Immortal)
static const pxr::TfToken UsdPrimvarReader_float2("UsdPrimvarReader_float2", pxr::TfToken::Immortal)
ColorManagedColorspaceSettings colorspace_settings
char surface_render_method
const float horizontal_step_
bNode * get_cached_node(const pxr::UsdShadeShader &usd_shader, const blender::StringRef tag={}) const
const float vertical_step_
void cache_node(const pxr::UsdShadeShader &usd_shader, bNode *node, const blender::StringRef tag={})
float2 compute_node_loc(int column)
Vector< float, 8 > column_offsets_
std::string get_key(const pxr::UsdShadeShader &usd_shader, const blender::StringRef tag) const
ShaderToNodeMap node_cache_
static float get_opacity_threshold(const pxr::UsdShadeShader &usd_shader, float default_value=0.0f)
static pxr::TfToken get_source_color_space(const pxr::UsdShadeShader &usd_shader)
static pxr::UsdShadeInput get_input(const pxr::UsdShadeShader &usd_shader, const pxr::TfToken &input_name)
static bool needs_blend(const pxr::UsdShadeShader &usd_shader)
static blender::Vector< int > get_udim_tiles(const std::string &file_path)
static int get_image_extension(const pxr::UsdShadeShader &usd_shader, const int default_value)
static bNodeSocket * get_input_socket(bNode *node, const blender::StringRefNull identifier, ReportList *reports)
static bool get_usd_preview_surface(const pxr::UsdShadeMaterial &usd_material, pxr::UsdShadeShader &r_preview_surface)
static pxr::SdfLayerHandle get_layer_handle(const pxr::UsdAttribute &attribute)
static void link_nodes(bNodeTree *ntree, bNode *source, const blender::StringRefNull sock_out, bNode *dest, const blender::StringRefNull sock_in)
static void set_viewport_material_props(Material *mtl, const pxr::UsdShadeShader &usd_preview)
static void add_udim_tiles(Image *image, const blender::Vector< int > &indices)
static bNode * add_node(bNodeTree *ntree, const int type, const blender::float2 loc)