[Bf-blender-cvs] [f47fa1c8376] usd-importer-T81257-merge: USD Import format fixes.
makowalski
noreply at git.blender.org
Sat Mar 6 02:02:42 CET 2021
Commit: f47fa1c8376d81120c84e569873257221091449a
Author: makowalski
Date: Fri Mar 5 19:56:07 2021 -0500
Branches: usd-importer-T81257-merge
https://developer.blender.org/rBf47fa1c8376d81120c84e569873257221091449a
USD Import format fixes.
===================================================================
M source/blender/io/usd/intern/usd_reader_material.cc
M source/blender/io/usd/intern/usd_reader_material.h
===================================================================
diff --git a/source/blender/io/usd/intern/usd_reader_material.cc b/source/blender/io/usd/intern/usd_reader_material.cc
index 8a8f5506ba1..acac2f49df2 100644
--- a/source/blender/io/usd/intern/usd_reader_material.cc
+++ b/source/blender/io/usd/intern/usd_reader_material.cc
@@ -188,390 +188,390 @@ void compute_node_loc(
} // namespace
- USDMaterialReader::USDMaterialReader(const USDImportParams ¶ms, Main *bmain)
- : m_params(params), bmain_(bmain)
- {
- }
-
- Material *USDMaterialReader::add_material(const pxr::UsdShadeMaterial &usd_material) const
- {
- if (!(bmain_ && usd_material)) {
- return nullptr;
- }
+USDMaterialReader::USDMaterialReader(const USDImportParams ¶ms, Main *bmain)
+ : m_params(params), bmain_(bmain)
+{
+}
+
+Material *USDMaterialReader::add_material(const pxr::UsdShadeMaterial &usd_material) const
+{
+ if (!(bmain_ && usd_material)) {
+ return nullptr;
+ }
+
+ std::string mtl_name = usd_material.GetPrim().GetName().GetString().c_str();
+
+ /* Create the material. */
+ Material *mtl = BKE_material_add(bmain_, mtl_name.c_str());
+
+ /* Optionally, create shader nodes to represent a UsdPreviewSurface. */
+ if (m_params.import_usd_preview) {
+ import_usd_preview(mtl, usd_material);
+ }
+
+ return mtl;
+}
+
+/* Convert a UsdPreviewSurface shader network to Blender nodes.
+ * The logic doesn't yet handle converting arbitrary prim var reader nodes. */
+
+void USDMaterialReader::import_usd_preview(Material *mtl,
+ const pxr::UsdShadeMaterial &usd_material) const
+{
+ if (!usd_material) {
+ return;
+ }
+
+ /* Get the surface shader. */
+ pxr::UsdShadeShader surf_shader = usd_material.ComputeSurfaceSource();
+
+ if (surf_shader) {
+ /* Check if we have a UsdPreviewSurface shader. */
+ pxr::TfToken shader_id;
+ if (surf_shader.GetShaderId(&shader_id) && shader_id == usdtokens::UsdPreviewSurface) {
+ import_usd_preview(mtl, surf_shader);
+ }
+ }
+}
+
+/* Create the Principled BSDF shader node network. */
+void USDMaterialReader::import_usd_preview(Material *mtl,
+ const pxr::UsdShadeShader &usd_shader) const
+{
+ if (!(bmain_ && mtl && usd_shader)) {
+ return;
+ }
+
+ /* Create the Material's node tree containing the principled
+ * and output shader. */
+
+ bNodeTree *ntree = ntreeAddTree(NULL, "Shader Nodetree", "ShaderNodeTree");
+ mtl->nodetree = ntree;
+ mtl->use_nodes = true;
+
+ bNode *principled = add_node(NULL, ntree, SH_NODE_BSDF_PRINCIPLED, 0.0f, 300.0f);
+
+ if (!principled) {
+ std::cerr << "ERROR: Couldn't create SH_NODE_BSDF_PRINCIPLED node for USD shader "
+ << usd_shader.GetPath() << std::endl;
+ return;
+ }
+
+ bNode *output = add_node(NULL, ntree, SH_NODE_OUTPUT_MATERIAL, 300.0f, 300.0f);
+
+ if (!output) {
+ std::cerr << "ERROR: Couldn't create SH_NODE_OUTPUT_MATERIAL node for USD shader "
+ << usd_shader.GetPath() << std::endl;
+ return;
+ }
+
+ link_nodes(ntree, principled, "BSDF", output, "Surface");
+
+ /* Set up the principled shader inputs. */
+
+ /* The following keep track of the locations for adding
+ * input nodes. */
+
+ NodePlacementContext context(0.0f, 300.0);
+ int column = 0;
+
+ /* Set the principled shader inputs. */
+
+ if (pxr::UsdShadeInput diffuse_input = usd_shader.GetInput(usdtokens::diffuseColor)) {
+ set_node_input(diffuse_input, principled, "Base Color", ntree, column, context);
+ }
+
+ if (pxr::UsdShadeInput emissive_input = usd_shader.GetInput(usdtokens::emissiveColor)) {
+ set_node_input(emissive_input, principled, "Emission", ntree, column, context);
+ }
+
+ if (pxr::UsdShadeInput specular_input = usd_shader.GetInput(usdtokens::specularColor)) {
+ set_node_input(specular_input, principled, "Specular", ntree, column, context);
+ }
+
+ if (pxr::UsdShadeInput metallic_input = usd_shader.GetInput(usdtokens::metallic)) {
+ ;
+ set_node_input(metallic_input, principled, "Metallic", ntree, column, context);
+ }
+
+ if (pxr::UsdShadeInput roughness_input = usd_shader.GetInput(usdtokens::roughness)) {
+ set_node_input(roughness_input, principled, "Roughness", ntree, column, context);
+ }
+
+ if (pxr::UsdShadeInput clearcoat_input = usd_shader.GetInput(usdtokens::clearcoat)) {
+ set_node_input(clearcoat_input, principled, "Clearcoat", ntree, column, context);
+ }
+
+ if (pxr::UsdShadeInput clearcoat_roughness_input = usd_shader.GetInput(
+ usdtokens::clearcoatRoughness)) {
+ set_node_input(
+ clearcoat_roughness_input, principled, "Clearcoat Roughness", ntree, column, context);
+ }
- std::string mtl_name = usd_material.GetPrim().GetName().GetString().c_str();
-
- /* Create the material. */
- Material *mtl = BKE_material_add(bmain_, mtl_name.c_str());
-
- /* Optionally, create shader nodes to represent a UsdPreviewSurface. */
- if (m_params.import_usd_preview) {
- import_usd_preview(mtl, usd_material);
- }
-
- return mtl;
- }
-
- /* Convert a UsdPreviewSurface shader network to Blender nodes.
- * The logic doesn't yet handle converting arbitrary prim var reader nodes. */
-
- void USDMaterialReader::import_usd_preview(Material *mtl,
- const pxr::UsdShadeMaterial &usd_material) const
- {
- if (!usd_material) {
- return;
- }
+ if (pxr::UsdShadeInput opacity_input = usd_shader.GetInput(usdtokens::opacity)) {
+ set_node_input(opacity_input, principled, "Alpha", ntree, column, context);
+ }
+
+ if (pxr::UsdShadeInput ior_input = usd_shader.GetInput(usdtokens::ior)) {
+ set_node_input(ior_input, principled, "IOR", ntree, column, context);
+ }
+
+ if (pxr::UsdShadeInput normal_input = usd_shader.GetInput(usdtokens::normal)) {
+ set_node_input(normal_input, principled, "Normal", ntree, column, context);
+ }
- /* Get the surface shader. */
- pxr::UsdShadeShader surf_shader = usd_material.ComputeSurfaceSource();
+ nodeSetActive(ntree, output);
- if (surf_shader) {
- /* Check if we have a UsdPreviewSurface shader. */
- pxr::TfToken shader_id;
- if (surf_shader.GetShaderId(&shader_id) && shader_id == usdtokens::UsdPreviewSurface) {
- import_usd_preview(mtl, surf_shader);
- }
- }
- }
-
- /* Create the Principled BSDF shader node network. */
- void USDMaterialReader::import_usd_preview(Material *mtl,
- const pxr::UsdShadeShader &usd_shader) const
- {
- if (!(bmain_ && mtl && usd_shader)) {
- return;
- }
-
- /* Create the Material's node tree containing the principled
- * and output shader. */
-
- bNodeTree *ntree = ntreeAddTree(NULL, "Shader Nodetree", "ShaderNodeTree");
- mtl->nodetree = ntree;
- mtl->use_nodes = true;
-
- bNode *principled = add_node(NULL, ntree, SH_NODE_BSDF_PRINCIPLED, 0.0f, 300.0f);
-
- if (!principled) {
- std::cerr << "ERROR: Couldn't create SH_NODE_BSDF_PRINCIPLED node for USD shader "
- << usd_shader.GetPath() << std::endl;
- return;
- }
-
- bNode *output = add_node(NULL, ntree, SH_NODE_OUTPUT_MATERIAL, 300.0f, 300.0f);
-
- if (!output) {
- std::cerr << "ERROR: Couldn't create SH_NODE_OUTPUT_MATERIAL node for USD shader "
- << usd_shader.GetPath() << std::endl;
- return;
- }
-
- link_nodes(ntree, principled, "BSDF", output, "Surface");
-
- /* Set up the principled shader inputs. */
-
- /* The following keep track of the locations for adding
- * input nodes. */
-
- NodePlacementContext context(0.0f, 300.0);
- int column = 0;
-
- /* Set the principled shader inputs. */
-
- if (pxr::UsdShadeInput diffuse_input = usd_shader.GetInput(usdtokens::diffuseColor)) {
- set_node_input(diffuse_input, principled, "Base Color", ntree, column, context);
- }
-
- if (pxr::UsdShadeInput emissive_input = usd_shader.GetInput(usdtokens::emissiveColor)) {
- set_node_input(emissive_input, principled, "Emission", ntree, column, context);
- }
-
- if (pxr::UsdShadeInput specular_input = usd_shader.GetInput(usdtokens::specularColor)) {
- set_node_input(specular_input, principled, "Specular", ntree, column, context);
- }
-
- if (pxr::UsdShadeInput metallic_input = usd_shader.GetInput(usdtokens::metallic)) {
- ;
- set_node_input(metallic_input, principled, "Metallic", ntree, column, context);
- }
-
- if (pxr::UsdShadeInput roughness_input = usd_shader.GetInput(usdtokens::roughness)) {
- set_node_input(roughness_input, principled, "Roughness", ntree, column, context);
- }
-
- if (pxr::UsdShadeInput clearcoat_input = usd_shader.GetInput(usdtokens::clearcoat)) {
- set_node_input(clearcoat_input, principled, "Clearcoat", ntree, column, context);
- }
-
- if (pxr::UsdShadeInput clearcoat_roughness_input = usd_shader.GetInput(
- usdtokens::clearcoatRoughness)) {
- set_node_input(
- clearcoat_roughness_input, principled, "Clearcoat Roughness", ntree, column, context);
- }
-
- if (pxr::UsdShadeInput opacity_input = usd_shader.GetInput(usdtokens::opacity)) {
- set_node_input(opacity_input, principled, "Alpha", ntree, column, context);
- }
-
- if (pxr::UsdShadeInput ior_input = usd_shader.GetInput(usdtokens::ior)) {
- set_node_input(ior_input, principled, "IOR", ntree, column, context);
- }
-
- if (pxr::UsdShadeInput normal_input = usd_shader.GetInput(usdtokens::normal)) {
- set_node_input(normal_input, principled, "Normal", ntree, column, context);
- }
-
- nodeSetActive(ntree, output);
-
- // Optionally, set the material blend mode.
-
- if (m_params.set_material_blend) {
- float opacity_threshold = 0.0f;
- if (needs_blend(usd_shader, opacity_threshold)) {
- if (opacity_threshold > 0.0f) {
- mtl->blend_method = MA_BM_CLIP;
- mtl->alpha_threshold = opacity_threshold;
- }
- else {
- mtl->blend_method = MA_BM_BLEND;
- }
- }
- }
- }
-
- /* Convert the given USD shader input to an input on the given node. */
- void USDMaterialReader::set_node_input(const pxr::UsdShadeInput &usd_input,
- bNode *dest_node,
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list