HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
utils.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_USD_SHADE_UTILS_H
8 #define PXR_USD_USD_SHADE_UTILS_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/usd/usdShade/api.h"
12 #include "pxr/usd/usdShade/types.h"
13 #include "pxr/usd/sdf/path.h"
14 #include "pxr/usd/usd/attribute.h"
15 
17 #include "pxr/base/tf/token.h"
18 
19 #include <string>
20 #include <utility>
21 
23 
24 class UsdShadeInput;
25 class UsdShadeOutput;
27 
28 /// \class UsdShadeUtils
29 ///
30 /// This class contains a set of utility functions used when authoring and
31 /// querying shading networks.
32 ///
34 public:
35  /// Returns the namespace prefix of the USD attribute associated with the
36  /// given shading attribute type.
38  static std::string GetPrefixForAttributeType(
39  UsdShadeAttributeType sourceType);
40 
41  /// For a valid UsdShadeConnectionSourceInfo, return the complete path
42  /// to the source property; otherwise the empty path.
44  static SdfPath
46 
47  /// Given the full name of a shading attribute, returns it's base name and
48  /// shading attribute type.
50  static std::pair<TfToken, UsdShadeAttributeType>
51  GetBaseNameAndType(const TfToken &fullName);
52 
53  /// Given the full name of a shading attribute, returns its shading
54  /// attribute type.
56  static UsdShadeAttributeType GetType(const TfToken &fullName);
57 
58  /// Returns the full shading attribute name given the basename and the
59  /// shading attribute type. \p baseName is the name of the input or output
60  /// on the shading node. \p type is the \ref UsdShadeAttributeType of the
61  /// shading attribute.
63  static TfToken GetFullName(const TfToken &baseName,
65 
66  /// \brief Find what is connected to an Input or Output recursively
67  ///
68  /// GetValueProducingAttributes implements the UsdShade connectivity rules
69  /// described in \ref UsdShadeAttributeResolution .
70  ///
71  /// When tracing connections within networks that contain containers like
72  /// UsdShadeNodeGraph nodes, the actual output(s) or value(s) at the end of
73  /// an input or output might be multiple connections removed. The methods
74  /// below resolves this across multiple physical connections.
75  ///
76  /// An UsdShadeInput is getting its value from one of these sources:
77  /// - If the input is not connected the UsdAttribute for this input is
78  /// returned, but only if it has an authored value. The input attribute
79  /// itself carries the value for this input.
80  /// - If the input is connected we follow the connection(s) until we reach
81  /// a valid output of a UsdShadeShader node or if we reach a valid
82  /// UsdShadeInput attribute of a UsdShadeNodeGraph or UsdShadeMaterial that
83  /// has an authored value.
84  ///
85  /// An UsdShadeOutput on a container can get its value from the same
86  /// type of sources as a UsdShadeInput on either a UsdShadeShader or
87  /// UsdShadeNodeGraph. Outputs on non-containers (UsdShadeShaders) cannot be
88  /// connected.
89  ///
90  /// This function returns a vector of UsdAttributes. The vector is empty if
91  /// no valid attribute was found. The type of each attribute can be
92  /// determined with the \p UsdShadeUtils::GetType function.
93  ///
94  /// If \p shaderOutputsOnly is true, it will only report attributes that are
95  /// outputs of non-containers (UsdShadeShaders). This is a bit faster and
96  /// what is need when determining the connections for Material terminals.
97  ///
98  /// \note This will return the last attribute along the connection chain
99  /// that has an authored value, which might not be the last attribute in the
100  /// chain itself.
101  /// \note When the network contains multi-connections, this function can
102  /// return multiple attributes for a single input or output. The list of
103  /// attributes is build by a depth-first search, following the underlying
104  /// connection paths in order. The list can contain both UsdShadeOutput and
105  /// UsdShadeInput attributes. It is up to the caller to decide how to
106  /// process such a mixture.
109  UsdShadeInput const &input,
110  bool shaderOutputsOnly = false);
111  /// \overload
114  UsdShadeOutput const &output,
115  bool shaderOutputsOnly = false);
116 };
117 
119 
120 #endif
#define USDSHADE_API
Definition: api.h:23
static USDSHADE_API UsdShadeAttributeVector GetValueProducingAttributes(UsdShadeInput const &input, bool shaderOutputsOnly=false)
Find what is connected to an Input or Output recursively.
static USDSHADE_API std::pair< TfToken, UsdShadeAttributeType > GetBaseNameAndType(const TfToken &fullName)
static USDSHADE_API std::string GetPrefixForAttributeType(UsdShadeAttributeType sourceType)
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
Definition: token.h:70
Definition: path.h:273
static USDSHADE_API TfToken GetFullName(const TfToken &baseName, const UsdShadeAttributeType type)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static USDSHADE_API UsdShadeAttributeType GetType(const TfToken &fullName)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static USDSHADE_API SdfPath GetConnectedSourcePath(const UsdShadeConnectionSourceInfo &srcInfo)
UsdShadeAttributeType
Definition: types.h:22