HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nodeGraph.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 USDSHADE_GENERATED_NODEGRAPH_H
25 #define USDSHADE_GENERATED_NODEGRAPH_H
26 
27 /// \file usdShade/nodeGraph.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/usdShade/api.h"
31 #include "pxr/usd/usd/typed.h"
32 #include "pxr/usd/usd/prim.h"
33 #include "pxr/usd/usd/stage.h"
34 
35 #include <utility>
36 #include "pxr/usd/usd/editTarget.h"
38 #include "pxr/usd/usdShade/input.h"
42 
43 #include "pxr/base/vt/value.h"
44 
45 #include "pxr/base/gf/vec3d.h"
46 #include "pxr/base/gf/vec3f.h"
47 #include "pxr/base/gf/matrix4d.h"
48 
49 #include "pxr/base/tf/token.h"
50 #include "pxr/base/tf/type.h"
51 
53 
54 class SdfAssetPath;
55 
56 // -------------------------------------------------------------------------- //
57 // NODEGRAPH //
58 // -------------------------------------------------------------------------- //
59 
60 /// \class UsdShadeNodeGraph
61 ///
62 /// A node-graph is a container for shading nodes, as well as other
63 /// node-graphs. It has a public input interface and provides a list of public
64 /// outputs.
65 ///
66 /// <b>Node Graph Interfaces</b>
67 ///
68 /// One of the most important functions of a node-graph is to host the "interface"
69 /// with which clients of already-built shading networks will interact. Please
70 /// see \ref UsdShadeNodeGraph_Interfaces "Interface Inputs" for a detailed
71 /// explanation of what the interface provides, and how to construct and
72 /// use it, to effectively share/instance shader networks.
73 ///
74 /// <b>Node Graph Outputs</b>
75 ///
76 /// These behave like outputs on a shader and are typically connected to an
77 /// output on a shader inside the node-graph.
78 ///
79 ///
81 {
82 public:
83  /// Compile time constant representing what kind of schema this class is.
84  ///
85  /// \sa UsdSchemaKind
87 
88  /// Construct a UsdShadeNodeGraph on UsdPrim \p prim .
89  /// Equivalent to UsdShadeNodeGraph::Get(prim.GetStage(), prim.GetPath())
90  /// for a \em valid \p prim, but will not immediately throw an error for
91  /// an invalid \p prim
92  explicit UsdShadeNodeGraph(const UsdPrim& prim=UsdPrim())
93  : UsdTyped(prim)
94  {
95  }
96 
97  /// Construct a UsdShadeNodeGraph on the prim held by \p schemaObj .
98  /// Should be preferred over UsdShadeNodeGraph(schemaObj.GetPrim()),
99  /// as it preserves SchemaBase state.
100  explicit UsdShadeNodeGraph(const UsdSchemaBase& schemaObj)
101  : UsdTyped(schemaObj)
102  {
103  }
104 
105  /// Destructor.
107  virtual ~UsdShadeNodeGraph();
108 
109  /// Return a vector of names of all pre-declared attributes for this schema
110  /// class and all its ancestor classes. Does not include attributes that
111  /// may be authored by custom/extended methods of the schemas involved.
113  static const TfTokenVector &
114  GetSchemaAttributeNames(bool includeInherited=true);
115 
116  /// Return a UsdShadeNodeGraph holding the prim adhering to this
117  /// schema at \p path on \p stage. If no prim exists at \p path on
118  /// \p stage, or if the prim at that path does not adhere to this schema,
119  /// return an invalid schema object. This is shorthand for the following:
120  ///
121  /// \code
122  /// UsdShadeNodeGraph(stage->GetPrimAtPath(path));
123  /// \endcode
124  ///
126  static UsdShadeNodeGraph
127  Get(const UsdStagePtr &stage, const SdfPath &path);
128 
129  /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
130  /// is defined (according to UsdPrim::IsDefined()) on this stage.
131  ///
132  /// If a prim adhering to this schema at \p path is already defined on this
133  /// stage, return that prim. Otherwise author an \a SdfPrimSpec with
134  /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
135  /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
136  /// with \p specifier == \a SdfSpecifierDef and empty typeName at the
137  /// current EditTarget for any nonexistent, or existing but not \a Defined
138  /// ancestors.
139  ///
140  /// The given \a path must be an absolute prim path that does not contain
141  /// any variant selections.
142  ///
143  /// If it is impossible to author any of the necessary PrimSpecs, (for
144  /// example, in case \a path cannot map to the current UsdEditTarget's
145  /// namespace) issue an error and return an invalid \a UsdPrim.
146  ///
147  /// Note that this method may return a defined prim whose typeName does not
148  /// specify this schema class, in case a stronger typeName opinion overrides
149  /// the opinion at the current EditTarget.
150  ///
152  static UsdShadeNodeGraph
153  Define(const UsdStagePtr &stage, const SdfPath &path);
154 
155 protected:
156  /// Returns the kind of schema this class belongs to.
157  ///
158  /// \sa UsdSchemaKind
160  UsdSchemaKind _GetSchemaKind() const override;
161 
162 private:
163  // needs to invoke _GetStaticTfType.
164  friend class UsdSchemaRegistry;
166  static const TfType &_GetStaticTfType();
167 
168  static bool _IsTypedSchema();
169 
170  // override SchemaBase virtuals.
172  const TfType &_GetTfType() const override;
173 
174 public:
175  // ===================================================================== //
176  // Feel free to add custom code below this line, it will be preserved by
177  // the code generator.
178  //
179  // Just remember to:
180  // - Close the class declaration with };
181  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
182  // - Close the include guard with #endif
183  // ===================================================================== //
184  // --(BEGIN CUSTOM CODE)--
185 
186  /// Constructor that takes a ConnectableAPI object. Allow implicit
187  /// (auto) conversion of UsdShadeConnectableAPI to UsdShadeNodeGraph, so
188  /// that a ConnectableAPI can be passed into any function that accepts a
189  /// NodeGraph.
190  ///
191  /// \note that the conversion may produce an invalid NodeGraph object,
192  /// because not all UsdShadeConnectableAPI%s are UsdShadeNodeGraph%s
194  UsdShadeNodeGraph(const UsdShadeConnectableAPI &connectable);
195 
196  /// Contructs and returns a UsdShadeConnectableAPI object with this
197  /// node-graph.
198  ///
199  /// Note that most tasks can be accomplished without explicitly constructing
200  /// a UsdShadeConnectable API, since connection-related API such as
201  /// UsdShadeConnectableAPI::ConnectToSource() are static methods, and
202  /// UsdShadeNodeGraph will auto-convert to a UsdShadeConnectableAPI when
203  /// passed to functions that want to act generically on a connectable
204  /// UsdShadeConnectableAPI object.
207 
208  /// \anchor UsdShadeNodeGraph_Output
209  /// \name Outputs of a node-graph. These typically connect to outputs of
210  /// shaders or nested node-graphs within the node-graph.
211  ///
212  /// @{
213 
214  /// Create an output which can either have a value or can be connected.
215  /// The attribute representing the output is created in the "outputs:"
216  /// namespace.
217  ///
220  const SdfValueTypeName& typeName) const;
221 
222  /// Return the requested output if it exists.
223  ///
225  UsdShadeOutput GetOutput(const TfToken &name) const;
226 
227  /// Outputs are represented by attributes in the "outputs:" namespace.
228  /// If \p onlyAuthored is true (the default), then only return authored
229  /// attributes; otherwise, this also returns un-authored builtins.
230  ///
232  std::vector<UsdShadeOutput> GetOutputs(bool onlyAuthored=true) const;
233 
234  /// \deprecated in favor of GetValueProducingAttributes on UsdShadeOutput
235  /// Resolves the connection source of the requested output, identified by
236  /// \p outputName to a shader output.
237  ///
238  /// \p sourceName is an output parameter that is set to the name of the
239  /// resolved output, if the node-graph output is connected to a valid
240  /// shader source.
241  ///
242  /// \p sourceType is an output parameter that is set to the type of the
243  /// resolved output, if the node-graph output is connected to a valid
244  /// shader source.
245  ///
246  /// \return Returns a valid shader object if the specified output exists and
247  /// is connected to one. Return an empty shader object otherwise.
248  /// The python version of this method returns a tuple containing three
249  /// elements (the source shader, sourceName, sourceType).
252  const TfToken &outputName,
253  TfToken *sourceName,
254  UsdShadeAttributeType *sourceType) const;
255 
256  /// @}
257 
258  /// \anchor UsdShadeNodeGraph_Interfaces
259  /// \name Interface inputs of a node-graph.
260  ///
261  /// In addition to serving as the "head" for all of the shading networks
262  /// that describe each render target's particular node-graph, the node-graph
263  /// prim provides a unified "interface" that allows node-graphs to share
264  /// shading networks while retaining the ability for each to specify its own
265  /// set of unique values for the interface inputs that users may need to
266  /// modify.
267  ///
268  /// A "Node-graph Interface" is a combination of:
269  /// \li a flat collection of attributes, of arbitrary names
270  /// \li for each such attribute, a list of UsdShaderInput targets
271  /// whose attributes on Shader prims should be driven by the interface
272  /// input.
273  ///
274  /// A single interface input can drive multiple shader inputs and be
275  /// consumed by multiple render targets. The set of interface inputs itself
276  /// is intentionally flat, to encourage sharing of the interface between
277  /// render targets. Clients are always free to create interface inputs with
278  /// namespacing to segregate "private" attributes exclusive to the render
279  /// target, but we hope this will be an exception.
280  ///
281  /// To facilitate connecting, qualifying, and interrogating interface
282  /// attributes, we use the attribute schema UsdShadeInput, which also
283  /// serves as an abstraction for shader inputs.
284  ///
285  /// <b>Scoped Interfaces</b>
286  ///
287  /// \todo describe scoped interfaces and fix bug/108940 to account for them.
288  ///
289  /// @{
290 
291  /// Create an Input which can either have a value or can be connected.
292  /// The attribute representing the input is created in the "inputs:"
293  /// namespace.
294  ///
295  /// \todo clarify error behavior if typeName does not match existing,
296  /// defined attribute - should match UsdPrim::CreateAttribute - bug/108970
297  ///
300  const SdfValueTypeName& typeName) const;
301 
302  /// Return the requested input if it exists.
303  ///
305  UsdShadeInput GetInput(const TfToken &name) const;
306 
307  /// Returns all inputs present on the node-graph. These are represented by
308  /// attributes in the "inputs:" namespace.
309  /// If \p onlyAuthored is true (the default), then only return authored
310  /// attributes; otherwise, this also returns un-authored builtins.
311  ///
313  std::vector<UsdShadeInput> GetInputs(bool onlyAuthored=true) const;
314 
315  /// @}
316 
317  // Provide custom hash and equality comparison function objects for
318  // UsdShadeNodeGraph until bug 143077 is resolved.
319 
320  /// Hash functor for UsdShadeNodeGraph objects.
322  inline size_t operator()(const UsdShadeNodeGraph &nodeGraph) const {
323  return hash_value(nodeGraph.GetPrim());
324  }
325  };
326  /// Equality comparator for UsdShadeNodeGraph objects.
328  {
329  inline bool operator() (UsdShadeNodeGraph const& s1,
330  UsdShadeNodeGraph const& s2) const
331  {
332  return s1.GetPrim() == s2.GetPrim();
333  }
334  };
335 
336  // ---------------------------------------------------------------------- //
337  /// \anchor UsdShadeNodeGraph_InterfaceInputs
338  /// \name Interface Inputs
339  ///
340  /// API to query the inputs that form the interface of the node-graph and
341  /// their connections.
342  ///
343  /// @{
344 
345  /// Returns all the "Interface Inputs" of the node-graph. This is the same
346  /// as GetInputs(), but is provided as a convenience, to allow clients to
347  /// distinguish between inputs on shaders vs. interface-inputs on
348  /// node-graphs.
350  std::vector<UsdShadeInput> GetInterfaceInputs() const;
351 
352  /// Map of interface inputs to corresponding vectors of inputs that
353  /// consume their values.
354  typedef std::unordered_map<UsdShadeInput, std::vector<UsdShadeInput>,
356 
357  /// Map of node-graphs to their associated input-consumers map.
358  typedef std::unordered_map<UsdShadeNodeGraph,
363 
364  /// Walks the namespace subtree below the node-graph and computes a map
365  /// containing the list of all inputs on the node-graph and the associated
366  /// vector of consumers of their values. The consumers can be inputs on
367  /// shaders within the node-graph or on nested node-graphs).
368  ///
369  /// If \p computeTransitiveConsumers is true, then value consumers
370  /// belonging to <b>node-graphs</b> are resolved transitively to compute the
371  /// transitive mapping from inputs on the node-graph to inputs on shaders
372  /// inside the material. Note that inputs on node-graphs that don't have
373  /// value consumers will continue to be included in the result.
374  ///
375  /// This API is provided for use by DCC's that want to present node-graph
376  /// interface / shader connections in the opposite direction than they are
377  /// encoded in USD.
378  ///
381  bool computeTransitiveConsumers=false) const;
382 
383  /// @}
384 
385 };
386 
388 
389 #endif
#define USDSHADE_API
Definition: api.h:40
Hash functor.
Definition: input.h:108
virtual USDSHADE_API ~UsdShadeNodeGraph()
Destructor.
std::unordered_map< UsdShadeInput, std::vector< UsdShadeInput >, UsdShadeInput::Hash > InterfaceInputConsumersMap
Definition: nodeGraph.h:355
USDSHADE_API UsdShadeShader ComputeOutputSource(const TfToken &outputName, TfToken *sourceName, UsdShadeAttributeType *sourceType) const
std::unordered_map< UsdShadeNodeGraph, InterfaceInputConsumersMap, NodeGraphHasher, NodeGraphEqualFn > NodeGraphInputConsumersMap
Map of node-graphs to their associated input-consumers map.
Definition: nodeGraph.h:362
bool operator()(UsdShadeNodeGraph const &s1, UsdShadeNodeGraph const &s2) const
Definition: nodeGraph.h:329
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USDSHADE_API std::vector< UsdShadeInput > GetInputs(bool onlyAuthored=true) const
USDSHADE_API UsdShadeConnectableAPI ConnectableAPI() const
UsdShadeNodeGraph(const UsdPrim &prim=UsdPrim())
Definition: nodeGraph.h:92
static USDSHADE_API UsdShadeNodeGraph Get(const UsdStagePtr &stage, const SdfPath &path)
Definition: token.h:87
Represents a concrete typed schema.
USDSHADE_API std::vector< UsdShadeInput > GetInterfaceInputs() const
UsdShadeNodeGraph(const UsdSchemaBase &schemaObj)
Definition: nodeGraph.h:100
USDSHADE_API std::vector< UsdShadeOutput > GetOutputs(bool onlyAuthored=true) const
static USDSHADE_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
Definition: prim.h:133
static const UsdSchemaKind schemaKind
Definition: nodeGraph.h:86
Definition: typed.h:61
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:290
USDSHADE_API UsdShadeOutput GetOutput(const TfToken &name) const
size_t operator()(const UsdShadeNodeGraph &nodeGraph) const
Definition: nodeGraph.h:322
UsdSchemaKind
Definition: common.h:129
Hash functor for UsdShadeNodeGraph objects.
Definition: nodeGraph.h:321
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
USDSHADE_API UsdShadeOutput CreateOutput(const TfToken &name, const SdfValueTypeName &typeName) const
static USDSHADE_API UsdShadeNodeGraph Define(const UsdStagePtr &stage, const SdfPath &path)
Definition: type.h:64
USDSHADE_API UsdShadeInput CreateInput(const TfToken &name, const SdfValueTypeName &typeName) const
USDSHADE_API UsdShadeInput GetInput(const TfToken &name) const
size_t hash_value(const CH_ChannelRef &ref)
USDSHADE_API InterfaceInputConsumersMap ComputeInterfaceInputConsumersMap(bool computeTransitiveConsumers=false) const
Equality comparator for UsdShadeNodeGraph objects.
Definition: nodeGraph.h:327
UsdPrim GetPrim() const
Return this schema object's held prim.
Definition: schemaBase.h:120
USDSHADE_API UsdSchemaKind _GetSchemaKind() const override
UsdShadeAttributeType
Definition: types.h:39