All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
output.h
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_OUTPUT_H
25 #define PXR_USD_USD_SHADE_OUTPUT_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usdShade/api.h"
29 #include "pxr/usd/usd/attribute.h"
30 #include "pxr/usd/ndr/declare.h"
31 #include "pxr/usd/usdShade/utils.h"
32 
33 #include <vector>
34 
35 PXR_NAMESPACE_OPEN_SCOPE
36 
38 class UsdShadeInput;
39 
46 {
47 public:
51  {
52  // nothing
53  }
54 
57  TfToken const &GetFullName() const {
58  return _attr.GetName();
59  }
60 
66  USDSHADE_API
67  TfToken GetBaseName() const;
68 
70  UsdPrim GetPrim() const {
71  return _attr.GetPrim();
72  }
73 
77  USDSHADE_API
79 
86  USDSHADE_API
87  bool Set(const VtValue& value,
88  UsdTimeCode time = UsdTimeCode::Default()) const;
89 
93  template <typename T>
94  bool Set(const T& value, UsdTimeCode time = UsdTimeCode::Default()) const {
95  if (UsdAttribute attr = GetAttr()) {
96  return attr.Set(value, time);
97  }
98  return false;
99  }
100 
103 
112  USDSHADE_API
113  bool SetRenderType(TfToken const& renderType) const;
114 
119  USDSHADE_API
120  TfToken GetRenderType() const;
121 
126  USDSHADE_API
127  bool HasRenderType() const;
128 
130 
145 
148  USDSHADE_API
149  NdrTokenMap GetSdrMetadata() const;
150 
153  USDSHADE_API
154  std::string GetSdrMetadataByKey(const TfToken &key) const;
155 
158  USDSHADE_API
159  void SetSdrMetadata(const NdrTokenMap &sdrMetadata) const;
160 
163  USDSHADE_API
164  void SetSdrMetadataByKey(
165  const TfToken &key,
166  const std::string &value) const;
167 
170  USDSHADE_API
171  bool HasSdrMetadata() const;
172 
175  USDSHADE_API
176  bool HasSdrMetadataByKey(const TfToken &key) const;
177 
180  USDSHADE_API
181  void ClearSdrMetadata() const;
182 
185  USDSHADE_API
186  void ClearSdrMetadataByKey(const TfToken &key) const;
187 
189 
190  // ---------------------------------------------------------------
192  // ---------------------------------------------------------------
193 
195 
200  USDSHADE_API
201  explicit UsdShadeOutput(const UsdAttribute &attr);
202 
207  USDSHADE_API
208  static bool IsOutput(const UsdAttribute &attr);
209 
211  UsdAttribute GetAttr() const { return _attr; }
212 
216  operator UsdAttribute () const { return GetAttr(); }
217 
221  bool IsDefined() const {
222  return IsOutput(_attr);
223  }
224 
226 
227  // -------------------------------------------------------------------------
229  // -------------------------------------------------------------------------
231 
239  USDSHADE_API
240  bool CanConnect(const UsdAttribute &source) const;
241 
243  USDSHADE_API
244  bool CanConnect(const UsdShadeInput &sourceInput) const;
245 
247  USDSHADE_API
248  bool CanConnect(const UsdShadeOutput &sourceOutput) const;
249 
262  USDSHADE_API
263  bool ConnectToSource(
264  UsdShadeConnectableAPI const &source,
265  TfToken const &sourceName,
266  UsdShadeAttributeType const sourceType=UsdShadeAttributeType::Output,
267  SdfValueTypeName typeName=SdfValueTypeName()) const;
268 
273  USDSHADE_API
274  bool ConnectToSource(SdfPath const &sourcePath) const;
275 
280  USDSHADE_API
281  bool ConnectToSource(UsdShadeInput const &sourceInput) const;
282 
287  USDSHADE_API
288  bool ConnectToSource(UsdShadeOutput const &sourceOutput) const;
289 
311  USDSHADE_API
313  TfToken *sourceName,
314  UsdShadeAttributeType *sourceType) const;
315 
320  USDSHADE_API
321  bool GetRawConnectedSourcePaths(SdfPathVector *sourcePaths) const;
322 
328  USDSHADE_API
329  bool HasConnectedSource() const;
330 
337  USDSHADE_API
339 
344  USDSHADE_API
345  bool DisconnectSource() const;
346 
354  USDSHADE_API
355  bool ClearSource() const;
356 
358 
361  explicit operator bool() const {
362  return IsDefined();
363  }
364 
367  friend bool operator==(const UsdShadeOutput &lhs, const UsdShadeOutput &rhs) {
368  return lhs.GetAttr() == rhs.GetAttr();
369  }
370 
371 private:
372  friend class UsdShadeConnectableAPI;
373 
374  // Constructor that creates a UsdShadeOutput with the given name on the
375  // given prim.
376  // \p name here is the unnamespaced name of the output.
377  UsdShadeOutput(UsdPrim prim,
378  TfToken const &name,
379  SdfValueTypeName const &typeName);
380 
381  UsdAttribute _attr;
382 };
383 
384 
385 PXR_NAMESPACE_CLOSE_SCOPE
386 
387 #endif // PXR_USD_USD_SHADE_OUTPUT_H
USDSHADE_API bool GetRawConnectedSourcePaths(SdfPathVector *sourcePaths) const
Returns the &quot;raw&quot; (authored) connected source paths for this Output.
USDSHADE_API bool HasConnectedSource() const
Returns true if and only if this Output is currently connected to a valid (defined) source...
USDSHADE_API bool HasRenderType() const
Return true if a renderType has been specified for this output.
USDSHADE_API bool GetConnectedSource(UsdShadeConnectableAPI *source, TfToken *sourceName, UsdShadeAttributeType *sourceType) const
Finds the source of a connection for this Output.
UsdShadeOutput()
Default constructor returns an invalid Output.
Definition: output.h:50
USDSHADE_API bool SetRenderType(TfToken const &renderType) const
Specify an alternative, renderer-specific type to use when emitting/translating this output...
UsdAttribute GetAttr() const
Explicit UsdAttribute extractor.
Definition: output.h:211
USDSHADE_API void SetSdrMetadataByKey(const TfToken &key, const std::string &value) const
Sets the value corresponding to key to the given string value, in the Output&#39;s &quot;sdrMetadata&quot; dictiona...
Represents a value type name, i.e.
Definition: valueTypeName.h:83
Scenegraph object for authoring and retrieving numeric, string, and array valued data, sampled over time.
Definition: attribute.h:176
static USDSHADE_API bool IsOutput(const UsdAttribute &attr)
Test whether a given UsdAttribute represents a valid Output, which implies that creating a UsdShadeOu...
bool IsDefined() const
Return true if the wrapped UsdAttribute is defined, and in addition the attribute is identified as an...
Definition: output.h:221
USDSHADE_API bool IsSourceConnectionFromBaseMaterial() const
Returns true if the connection to this Output&#39;s source, as returned by GetConnectedSource(), is authored across a specializes arc, which is used to denote a base material.
This class encapsulates a shader or node-graph input, which is a connectable attribute representing a...
Definition: input.h:46
USDSHADE_API bool Set(const VtValue &value, UsdTimeCode time=UsdTimeCode::Default()) const
Set a value for the output.
USDSHADE_API void SetSdrMetadata(const NdrTokenMap &sdrMetadata) const
Authors the given sdrMetadata value on this Output at the current EditTarget.
USDSHADE_API bool CanConnect(const UsdAttribute &source) const
Determines whether this Output can be connected to the given source attribute, which can be an input ...
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
USDSHADE_API bool DisconnectSource() const
Disconnect source for this Output.
USDSHADE_API std::string GetSdrMetadataByKey(const TfToken &key) const
Returns the value corresponding to key in the composed sdrMetadata dictionary.
USDSHADE_API bool ConnectToSource(UsdShadeConnectableAPI const &source, TfToken const &sourceName, UsdShadeAttributeType const sourceType=UsdShadeAttributeType::Output, SdfValueTypeName typeName=SdfValueTypeName()) const
Authors a connection for this Output to the source described by the following three elements: source...
USDSHADE_API TfToken GetRenderType() const
Return this output&#39;s specialized renderType, or an empty token if none was authored.
USDSHADE_API void ClearSdrMetadata() const
Clears any &quot;sdrMetadata&quot; value authored on the Output in the current EditTarget.
USDSHADE_API bool HasSdrMetadata() const
Returns true if the Output has a non-empty composed &quot;sdrMetadata&quot; dictionary value.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
USDSHADE_API SdfValueTypeName GetTypeName() const
Get the &quot;scene description&quot; value type name of the attribute associated with the output.
UsdPrim GetPrim() const
Return this object if it is a prim, otherwise return this object&#39;s nearest owning prim...
Definition: prim.h:1694
UsdShadeConnectableAPI is an API schema that provides a common interface for creating outputs and mak...
bool Set(const T &value, UsdTimeCode time=UsdTimeCode::Default()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: output.h:94
USDSHADE_API bool HasSdrMetadataByKey(const TfToken &key) const
Returns true if there is a value corresponding to the given key in the composed &quot;sdrMetadata&quot; diction...
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:132
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
USDSHADE_API void ClearSdrMetadataByKey(const TfToken &key) const
Clears the entry corresponding to the given key in the &quot;sdrMetadata&quot; dictionary authored in the curre...
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for &#39;default&#39;.
Definition: timeCode.h:113
UsdPrim GetPrim() const
Get the prim that the output belongs to.
Definition: output.h:70
const TfToken & GetName() const
Return the full name of this object, i.e.
Definition: object.h:229
USDSHADE_API NdrTokenMap GetSdrMetadata() const
Returns this Output&#39;s composed &quot;sdrMetadata&quot; dictionary as a NdrTokenMap.
This class encapsulates a shader or node-graph output, which is a connectable attribute representing ...
Definition: output.h:45
friend bool operator==(const UsdShadeOutput &lhs, const UsdShadeOutput &rhs)
Equality comparison.
Definition: output.h:367
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:174
TfToken const & GetFullName() const
Get the name of the attribute associated with the output.
Definition: output.h:57
USDSHADE_API bool ClearSource() const
Clears source for this shading attribute in the current UsdEditTarget.
USDSHADE_API TfToken GetBaseName() const
Returns the name of the output.