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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_USD_SHADE_UTILS_H
25 #define PXR_USD_USD_SHADE_UTILS_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usdShade/api.h"
29 #include "pxr/usd/usdShade/types.h"
30 #include "pxr/usd/sdf/path.h"
31 #include "pxr/usd/usd/attribute.h"
32 
34 #include "pxr/base/tf/token.h"
35 
36 #include <string>
37 #include <utility>
38 
40 
41 class UsdShadeInput;
42 class UsdShadeOutput;
44 
45 /// \class UsdShadeUtils
46 ///
47 /// This class contains a set of utility functions used when authoring and
48 /// querying shading networks.
49 ///
51 public:
52  /// Returns the namespace prefix of the USD attribute associated with the
53  /// given shading attribute type.
56  UsdShadeAttributeType sourceType);
57 
58  /// For a valid UsdShadeConnectionSourceInfo, return the complete path
59  /// to the source property; otherwise the empty path.
61  static SdfPath
63 
64  /// Given the full name of a shading attribute, returns it's base name and
65  /// shading attribute type.
67  static std::pair<TfToken, UsdShadeAttributeType>
68  GetBaseNameAndType(const TfToken &fullName);
69 
70  /// Given the full name of a shading attribute, returns its shading
71  /// attribute type.
73  static UsdShadeAttributeType GetType(const TfToken &fullName);
74 
75  /// Returns the full shading attribute name given the basename and the
76  /// shading attribute type. \p baseName is the name of the input or output
77  /// on the shading node. \p type is the \ref UsdShadeAttributeType of the
78  /// shading attribute.
80  static TfToken GetFullName(const TfToken &baseName,
82 
83  /// \brief Find what is connected to an Input or Output recursively
84  ///
85  /// GetValueProducingAttributes implements the UsdShade connectivity rules
86  /// described in \ref UsdShadeAttributeResolution .
87  ///
88  /// When tracing connections within networks that contain containers like
89  /// UsdShadeNodeGraph nodes, the actual output(s) or value(s) at the end of
90  /// an input or output might be multiple connections removed. The methods
91  /// below resolves this across multiple physical connections.
92  ///
93  /// An UsdShadeInput is getting its value from one of these sources:
94  /// - If the input is not connected the UsdAttribute for this input is
95  /// returned, but only if it has an authored value. The input attribute
96  /// itself carries the value for this input.
97  /// - If the input is connected we follow the connection(s) until we reach
98  /// a valid output of a UsdShadeShader node or if we reach a valid
99  /// UsdShadeInput attribute of a UsdShadeNodeGraph or UsdShadeMaterial that
100  /// has an authored value.
101  ///
102  /// An UsdShadeOutput on a container can get its value from the same
103  /// type of sources as a UsdShadeInput on either a UsdShadeShader or
104  /// UsdShadeNodeGraph. Outputs on non-containers (UsdShadeShaders) cannot be
105  /// connected.
106  ///
107  /// This function returns a vector of UsdAttributes. The vector is empty if
108  /// no valid attribute was found. The type of each attribute can be
109  /// determined with the \p UsdShadeUtils::GetType function.
110  ///
111  /// If \p shaderOutputsOnly is true, it will only report attributes that are
112  /// outputs of non-containers (UsdShadeShaders). This is a bit faster and
113  /// what is need when determining the connections for Material terminals.
114  ///
115  /// \note This will return the last attribute along the connection chain
116  /// that has an authored value, which might not be the last attribute in the
117  /// chain itself.
118  /// \note When the network contains multi-connections, this function can
119  /// return multiple attributes for a single input or output. The list of
120  /// attributes is build by a depth-first search, following the underlying
121  /// connection paths in order. The list can contain both UsdShadeOutput and
122  /// UsdShadeInput attributes. It is up to the caller to decide how to
123  /// process such a mixture.
126  UsdShadeInput const &input,
127  bool shaderOutputsOnly = false);
128  /// \overload
131  UsdShadeOutput const &output,
132  bool shaderOutputsOnly = false);
133 };
134 
136 
137 #endif
#define USDSHADE_API
Definition: api.h:40
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
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)
Definition: token.h:87
Definition: path.h:291
static USDSHADE_API TfToken GetFullName(const TfToken &baseName, const UsdShadeAttributeType type)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
static USDSHADE_API UsdShadeAttributeType GetType(const TfToken &fullName)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
static USDSHADE_API SdfPath GetConnectedSourcePath(const UsdShadeConnectionSourceInfo &srcInfo)
type
Definition: core.h:1059
UsdShadeAttributeType
Definition: types.h:39