Blender
V3.3
|
#include <usd_reader_material.h>
Public Member Functions | |
USDMaterialReader (const USDImportParams ¶ms, Main *bmain) | |
Material * | add_material (const pxr::UsdShadeMaterial &usd_material) const |
Protected Member Functions | |
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 | set_node_input (const pxr::UsdShadeInput &usd_input, bNode *dest_node, const char *dest_socket_name, bNodeTree *ntree, int column, NodePlacementContext *r_ctx) const |
void | follow_connection (const pxr::UsdShadeInput &usd_input, 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 |
void | load_tex_image (const pxr::UsdShadeShader &usd_shader, bNode *tex_image) 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 |
Protected Attributes | |
USDImportParams | params_ |
Main * | bmain_ |
By default, the USDMaterialReader creates a Blender material with the same name as the USD material. If the USD material has a #UsdPreviewSurface source, the Blender material's viewport display color, roughness and metallic properties are set to the corresponding #UsdPreoviewSurface inputs.
If the Import USD Preview option is enabled, the current implementation converts #UsdPreviewSurface to Blender nodes as follows:
Limitations: arbitrary primvar readers or UsdTransform2d not yet supported. For #UsdUVTexture, only the file, st and #sourceColorSpace inputs are handled.
TODO(makowalski): Investigate adding support for converting additional shaders and inputs. Supporting certain types of inputs, such as texture scale and bias, will probably require creating Blender Group nodes with the corresponding inputs.
Definition at line 65 of file usd_reader_material.h.
blender::io::usd::USDMaterialReader::USDMaterialReader | ( | const USDImportParams & | params, |
Main * | bmain | ||
) |
Definition at line 255 of file usd_reader_material.cc.
Material * blender::io::usd::USDMaterialReader::add_material | ( | const pxr::UsdShadeMaterial & | usd_material | ) | const |
Definition at line 260 of file usd_reader_material.cc.
References BKE_material_add(), bmain_, get_usd_preview_surface(), Material::id, id_us_min(), import_usd_preview(), USDImportParams::import_usd_preview, params_, and set_viewport_material_props().
Referenced by utils::assign_materials().
|
protected |
This function creates a Blender UV Map node, under the simplifying assumption that UsdPrimvarReader_float2 shaders output UV coordinates. TODO(makowalski): investigate supporting conversion to other Blender node types (e.g., Attribute Nodes) if needed.
Definition at line 637 of file usd_reader_material.cc.
References add_node(), BLI_strncpy(), bmain_, link_nodes(), ntree, SH_NODE_UVMAP, bNode::storage, NodeShaderUVMap::uv_map, and usdtokens::varname().
Referenced by follow_connection().
|
protected |
Definition at line 539 of file usd_reader_material.cc.
References usdtokens::a(), add_node(), bmain_, link_nodes(), load_tex_image(), ntree, set_node_input(), SH_NODE_TEX_IMAGE, and usdtokens::st().
Referenced by follow_connection().
|
protected |
Follow the connected source of the USD input to create corresponding inputs for the given Blender node.
Definition at line 472 of file usd_reader_material.cc.
References add_node(), convert_usd_primvar_reader_float2(), convert_usd_uv_texture(), link_nodes(), ntree, SH_NODE_NORMAL_MAP, usdtokens::UsdPrimvarReader_float2(), and usdtokens::UsdUVTexture().
Referenced by set_node_input().
|
protected |
Create the Principled BSDF shader node network.
Definition at line 288 of file usd_reader_material.cc.
References add_node(), Material::alpha_threshold, BKE_ntree_update_main_tree(), Material::blend_method, bmain_, get_opacity_threshold(), link_nodes(), MA_BM_BLEND, MA_BM_CLIP, needs_blend(), nodeSetActive(), Material::nodetree, ntree, ntreeAddTree(), output, params_, USDImportParams::set_material_blend, set_principled_node_inputs(), SH_NODE_BSDF_PRINCIPLED, SH_NODE_OUTPUT_MATERIAL, and Material::use_nodes.
Referenced by add_material().
|
protected |
Load the texture image node's texture from the path given by the USD shader's file input value.
Definition at line 580 of file usd_reader_material.cc.
References BKE_image_load_exists(), bmain_, ELEM, usdtokens::file(), get_source_color_space(), bNode::id, image(), usdtokens::raw(), usdtokens::RAW(), SH_NODE_TEX_IMAGE, STRNCPY, and bNode::type.
Referenced by convert_usd_uv_texture().
|
protected |
Convert the given USD shader input to an input on the given Blender node.
Definition at line 405 of file usd_reader_material.cc.
References average(), copy_v2_v2(), copy_v3_v3(), bNodeSocket::default_value, follow_connection(), bNodeSocket::idname, nodeFindSocket(), ntree, SOCK_FLOAT, SOCK_IN, SOCK_RGBA, SOCK_VECTOR, and bNodeSocket::type.
Referenced by convert_usd_uv_texture(), and set_principled_node_inputs().
|
protected |
Definition at line 347 of file usd_reader_material.cc.
References usdtokens::clearcoat(), usdtokens::clearcoatRoughness(), blender::compositor::context, usdtokens::diffuseColor(), usdtokens::emissiveColor(), usdtokens::ior(), usdtokens::metallic(), usdtokens::normal(), ntree, usdtokens::opacity(), usdtokens::roughness(), set_node_input(), and usdtokens::specularColor().
Referenced by import_usd_preview().
|
protected |
Definition at line 69 of file usd_reader_material.h.
Referenced by add_material(), convert_usd_primvar_reader_float2(), convert_usd_uv_texture(), import_usd_preview(), and load_tex_image().
|
protected |
Definition at line 67 of file usd_reader_material.h.
Referenced by add_material(), and import_usd_preview().