Blender  V3.3
usd_reader_material.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2021 NVIDIA Corporation. All rights reserved. */
3 #pragma once
4 
5 #include "usd.h"
6 
7 #include <pxr/usd/usdShade/material.h>
8 
9 struct Main;
10 struct Material;
11 struct bNode;
12 struct bNodeTree;
13 
14 namespace blender::io::usd {
15 
16 /* Helper struct used when arranging nodes in columns, keeping track the
17  * occupancy information for a given column. I.e., for column n,
18  * column_offsets[n] is the y-offset (from top to bottom) of the occupied
19  * region in that column. */
21  float origx;
22  float origy;
23  std::vector<float> column_offsets;
24  const float horizontal_step;
25  const float vertical_step;
26 
27  NodePlacementContext(float in_origx,
28  float in_origy,
29  float in_horizontal_step = 300.0f,
30  float in_vertical_step = 300.0f)
31  : origx(in_origx),
32  origy(in_origy),
33  column_offsets(64, 0.0f),
34  horizontal_step(in_horizontal_step),
35  vertical_step(in_vertical_step)
36  {
37  }
38 };
39 
40 /* Converts USD materials to Blender representation. */
41 
66  protected:
68 
70 
71  public:
73 
74  Material *add_material(const pxr::UsdShadeMaterial &usd_material) const;
75 
76  protected:
78  void import_usd_preview(Material *mtl, const pxr::UsdShadeShader &usd_shader) const;
79 
80  void set_principled_node_inputs(bNode *principled_node,
82  const pxr::UsdShadeShader &usd_shader) const;
83 
85  void set_node_input(const pxr::UsdShadeInput &usd_input,
86  bNode *dest_node,
87  const char *dest_socket_name,
89  int column,
90  NodePlacementContext *r_ctx) const;
91 
96  void follow_connection(const pxr::UsdShadeInput &usd_input,
97  bNode *dest_node,
98  const char *dest_socket_name,
100  int column,
101  NodePlacementContext *r_ctx) const;
102 
103  void convert_usd_uv_texture(const pxr::UsdShadeShader &usd_shader,
104  const pxr::TfToken &usd_source_name,
105  bNode *dest_node,
106  const char *dest_socket_name,
107  bNodeTree *ntree,
108  int column,
109  NodePlacementContext *r_ctx) const;
110 
115  void load_tex_image(const pxr::UsdShadeShader &usd_shader, bNode *tex_image) const;
116 
123  void convert_usd_primvar_reader_float2(const pxr::UsdShadeShader &usd_shader,
124  const pxr::TfToken &usd_source_name,
125  bNode *dest_node,
126  const char *dest_socket_name,
127  bNodeTree *ntree,
128  int column,
129  NodePlacementContext *r_ctx) const;
130 };
131 
132 } // namespace blender::io::usd
Material * add_material(const pxr::UsdShadeMaterial &usd_material) 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
USDMaterialReader(const USDImportParams &params, Main *bmain)
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
void import_usd_preview(Material *mtl, const pxr::UsdShadeShader &usd_shader) 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 load_tex_image(const pxr::UsdShadeShader &usd_shader, bNode *tex_image) const
void set_principled_node_inputs(bNode *principled_node, bNodeTree *ntree, const pxr::UsdShadeShader &usd_shader) const
bNodeTree * ntree
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
Definition: BKE_main.h:121
NodePlacementContext(float in_origx, float in_origy, float in_horizontal_step=300.0f, float in_vertical_step=300.0f)