All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
input.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_INPUT_H
25 #define PXR_USD_USD_SHADE_INPUT_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/usdShade/utils.h"
31 #include "pxr/usd/usd/attribute.h"
32 
33 #include "pxr/usd/ndr/declare.h"
34 
35 #include <vector>
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
41 class UsdShadeOutput;
42 
49 {
50 public:
54  {
55  // nothing
56  }
57 
60  TfToken const &GetFullName() const {
61  return _attr.GetName();
62  }
63 
69  USDSHADE_API
70  TfToken GetBaseName() const;
71 
75  USDSHADE_API
77 
79  UsdPrim GetPrim() const {
80  return _attr.GetPrim();
81  }
82 
84  template <typename T>
85  bool Get(T* value, UsdTimeCode time = UsdTimeCode::Default()) const {
86  return GetAttr().Get(value, time);
87  }
88 
90  USDSHADE_API
91  bool Get(VtValue* value, UsdTimeCode time = UsdTimeCode::Default()) const;
92 
95  USDSHADE_API
96  bool Set(const VtValue& value,
97  UsdTimeCode time = UsdTimeCode::Default()) const;
98 
102  template <typename T>
103  bool Set(const T& value, UsdTimeCode time = UsdTimeCode::Default()) const {
104  return _attr.Set(value, time);
105  }
106 
108  struct Hash {
109  inline size_t operator()(const UsdShadeInput &input) const {
110  return hash_value(input._attr);
111  }
112  };
113 
116 
126  USDSHADE_API
127  bool SetRenderType(TfToken const& renderType) const;
128 
133  USDSHADE_API
134  TfToken GetRenderType() const;
135 
139  USDSHADE_API
140  bool HasRenderType() const;
141 
143 
158 
161  USDSHADE_API
162  NdrTokenMap GetSdrMetadata() const;
163 
166  USDSHADE_API
167  std::string GetSdrMetadataByKey(const TfToken &key) const;
168 
171  USDSHADE_API
172  void SetSdrMetadata(const NdrTokenMap &sdrMetadata) const;
173 
176  USDSHADE_API
177  void SetSdrMetadataByKey(
178  const TfToken &key,
179  const std::string &value) const;
180 
183  USDSHADE_API
184  bool HasSdrMetadata() const;
185 
188  USDSHADE_API
189  bool HasSdrMetadataByKey(const TfToken &key) const;
190 
193  USDSHADE_API
194  void ClearSdrMetadata() const;
195 
198  USDSHADE_API
199  void ClearSdrMetadataByKey(const TfToken &key) const;
200 
202 
203  // ---------------------------------------------------------------
205  // ---------------------------------------------------------------
206 
208 
213  USDSHADE_API
214  explicit UsdShadeInput(const UsdAttribute &attr);
215 
220  USDSHADE_API
221  static bool IsInput(const UsdAttribute &attr);
222 
225  USDSHADE_API
226  static bool IsInterfaceInputName(const std::string & name);
227 
229  const UsdAttribute &GetAttr() const { return _attr; }
230 
234  operator const UsdAttribute & () const { return GetAttr(); }
235 
238  bool IsDefined() const {
239  return _attr && IsInput(_attr);
240  }
241 
244  USDSHADE_API
245  bool SetDocumentation(const std::string& docs) const;
246 
249  USDSHADE_API
250  std::string GetDocumentation() const;
251 
255  USDSHADE_API
256  bool SetDisplayGroup(const std::string& displayGroup) const;
257 
261  USDSHADE_API
262  std::string GetDisplayGroup() const;
263 
265 
268  explicit operator bool() const {
269  return IsDefined();
270  }
271 
274  friend bool operator==(const UsdShadeInput &lhs, const UsdShadeInput &rhs) {
275  return lhs.GetAttr() == rhs.GetAttr();
276  }
277 
280  friend bool operator!=(const UsdShadeInput &lhs, const UsdShadeInput &rhs) {
281  return !(lhs == rhs);
282  }
283 
284  // -------------------------------------------------------------------------
286  // -------------------------------------------------------------------------
288 
293  USDSHADE_API
294  bool CanConnect(const UsdAttribute &source) const;
295 
297  USDSHADE_API
298  bool CanConnect(const UsdShadeInput &sourceInput) const;
299 
301  USDSHADE_API
302  bool CanConnect(const UsdShadeOutput &sourceOutput) const;
303 
304  using ConnectionModification = UsdShadeConnectionModification;
305 
328  USDSHADE_API
329  bool ConnectToSource(
330  UsdShadeConnectionSourceInfo const &source,
331  ConnectionModification const mod =
332  ConnectionModification::Replace) const;
333 
336  USDSHADE_API
337  bool ConnectToSource(
338  UsdShadeConnectableAPI const &source,
339  TfToken const &sourceName,
340  UsdShadeAttributeType const sourceType=UsdShadeAttributeType::Output,
341  SdfValueTypeName typeName=SdfValueTypeName()) const;
342 
347  USDSHADE_API
348  bool ConnectToSource(SdfPath const &sourcePath) const;
349 
354  USDSHADE_API
355  bool ConnectToSource(UsdShadeInput const &sourceInput) const;
356 
361  USDSHADE_API
362  bool ConnectToSource(UsdShadeOutput const &sourceOutput) const;
363 
368  USDSHADE_API
369  bool SetConnectedSources(
370  std::vector<UsdShadeConnectionSourceInfo> const &sourceInfos) const;
371 
372  using SourceInfoVector = TfSmallVector<UsdShadeConnectionSourceInfo, 1>;
373 
391  USDSHADE_API
392  SourceInfoVector GetConnectedSources(
393  SdfPathVector *invalidSourcePaths = nullptr) const;
394 
396  USDSHADE_API
398  TfToken *sourceName,
399  UsdShadeAttributeType *sourceType) const;
400 
406  USDSHADE_API
407  bool GetRawConnectedSourcePaths(SdfPathVector *sourcePaths) const;
408 
414  USDSHADE_API
415  bool HasConnectedSource() const;
416 
423  USDSHADE_API
425 
432  USDSHADE_API
433  bool DisconnectSource(UsdAttribute const &sourceAttr = UsdAttribute()) const;
434 
442  USDSHADE_API
443  bool ClearSources() const;
444 
446  USDSHADE_API
447  bool ClearSource() const;
448 
450 
451  // -------------------------------------------------------------------------
453  // -------------------------------------------------------------------------
455 
477  USDSHADE_API
478  bool SetConnectability(const TfToken &connectability) const;
479 
483  USDSHADE_API
484  TfToken GetConnectability() const;
485 
488  USDSHADE_API
489  bool ClearConnectability() const;
490 
492 
493  // -------------------------------------------------------------------------
495  // -------------------------------------------------------------------------
497 
501  USDSHADE_API
503  bool shaderOutputsOnly = false) const;
504 
506  USDSHADE_API
508  UsdShadeAttributeType* attrType) const;
509 
511 
512 private:
513  friend class UsdShadeConnectableAPI;
514 
515  // Constructor that creates a UsdShadeInput with the given name on the
516  // given prim.
517  // \p name here is the unnamespaced name of the input.
518  UsdShadeInput(UsdPrim prim,
519  TfToken const &name,
520  SdfValueTypeName const &typeName);
521 
522  UsdAttribute _attr;
523 };
524 
525 PXR_NAMESPACE_CLOSE_SCOPE
526 
527 #endif // PXR_USD_USD_SHADE_INPUT_H
bool Set(const T &value, UsdTimeCode time=UsdTimeCode::Default()) const
Set the value of this attribute in the current UsdEditTarget to value at UsdTimeCode time...
Definition: attribute.h:462
Hash functor.
Definition: input.h:108
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...
USDSHADE_API bool DisconnectSource(UsdAttribute const &sourceAttr=UsdAttribute()) const
Disconnect source for this Input.
USDSHADE_API bool SetDisplayGroup(const std::string &displayGroup) const
Set the displayGroup metadata for this Input, i.e.
USDSHADE_API bool HasRenderType() const
Return true if a renderType has been specified for this Input.
USDSHADE_API bool HasSdrMetadata() const
Returns true if the Input has a non-empty composed &quot;sdrMetadata&quot; dictionary value.
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:177
USDSHADE_API std::string GetDisplayGroup() const
Get the displayGroup metadata for this Input, i.e.
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Convenience wrapper for the templated UsdAttribute::Get().
Definition: input.h:85
USDSHADE_API bool GetRawConnectedSourcePaths(SdfPathVector *sourcePaths) const
Represents a value type name, i.e.
Definition: valueTypeName.h:87
USDSHADE_API bool Set(const VtValue &value, UsdTimeCode time=UsdTimeCode::Default()) const
Set a value for the Input at time.
USDSHADE_API NdrTokenMap GetSdrMetadata() const
Returns this Input&#39;s composed &quot;sdrMetadata&quot; dictionary as a NdrTokenMap.
bool IsDefined() const
Return true if the wrapped UsdAttribute is defined, and in addition the attribute is identified as an...
Definition: input.h:238
Scenegraph object for authoring and retrieving numeric, string, and array valued data, sampled over time.
Definition: attribute.h:176
This class encapsulates a shader or node-graph input, which is a connectable attribute representing a...
Definition: input.h:48
TfToken const & GetFullName() const
Get the name of the attribute associated with the Input.
Definition: input.h:60
USDSHADE_API void SetSdrMetadata(const NdrTokenMap &sdrMetadata) const
Authors the given sdrMetadata value on this Input at the current EditTarget.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
USDSHADE_API bool ConnectToSource(UsdShadeConnectionSourceInfo const &source, ConnectionModification const mod=ConnectionModification::Replace) const
Authors a connection for this Input.
USDSHADE_API bool SetConnectedSources(std::vector< UsdShadeConnectionSourceInfo > const &sourceInfos) const
Connects this Input to the given sources, sourceInfos.
friend bool operator==(const UsdShadeInput &lhs, const UsdShadeInput &rhs)
Equality comparison.
Definition: input.h:274
friend bool operator!=(const UsdShadeInput &lhs, const UsdShadeInput &rhs)
Inequality comparison.
Definition: input.h:280
USDSHADE_API bool SetDocumentation(const std::string &docs) const
Set documentation string for this Input.
USDSHADE_API std::string GetDocumentation() const
Get documentation string for this Input.
static USDSHADE_API bool IsInterfaceInputName(const std::string &name)
Test if this name has a namespace that indicates it could be an input.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
UsdPrim GetPrim() const
Return this object if it is a prim, otherwise return this object&#39;s nearest owning prim...
Definition: prim.h:2107
USDSHADE_API std::string GetSdrMetadataByKey(const TfToken &key) const
Returns the value corresponding to key in the composed sdrMetadata dictionary.
USDSHADE_API SourceInfoVector GetConnectedSources(SdfPathVector *invalidSourcePaths=nullptr) const
Finds the valid sources of connections for the Input.
USDSHADE_API bool HasConnectedSource() const
Returns true if and only if this Input is currently connected to a valid (defined) source...
UsdShadeConnectableAPI is an API schema that provides a common interface for creating outputs and mak...
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 Input&#39;s &quot;sdrMetadata&quot; dictionar...
static USDSHADE_API bool IsInput(const UsdAttribute &attr)
Test whether a given UsdAttribute represents a valid Input, which implies that creating a UsdShadeInp...
USDSHADE_API bool GetConnectedSource(UsdShadeConnectableAPI *source, TfToken *sourceName, UsdShadeAttributeType *sourceType) const
USDSHADE_API bool CanConnect(const UsdAttribute &source) const
Determines whether this Input can be connected to the given source attribute, which can be an input o...
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:132
const UsdAttribute & GetAttr() const
Explicit UsdAttribute extractor.
Definition: input.h:229
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:288
USDSHADE_API TfToken GetRenderType() const
Return this Input&#39;s specialized renderType, or an empty token if none was authored.
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Perform value resolution to fetch the value of this attribute at the requested UsdTimeCode time...
Definition: attribute.h:431
UsdShadeInput()
Default constructor returns an invalid Input.
Definition: input.h:53
USDSHADE_API bool SetRenderType(TfToken const &renderType) const
Specify an alternative, renderer-specific type to use when emitting/translating this Input...
USDSHADE_API UsdAttribute GetValueProducingAttribute(UsdShadeAttributeType *attrType) const
USDSHADE_API SdfValueTypeName GetTypeName() const
Get the &quot;scene description&quot; value type name of the attribute associated with the Input.
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...
USDSHADE_API bool ClearConnectability() const
Clears any authored connectability on the Input.
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for &#39;default&#39;.
Definition: timeCode.h:113
USDSHADE_API void ClearSdrMetadata() const
Clears any &quot;sdrMetadata&quot; value authored on the Input in the current EditTarget.
const TfToken & GetName() const
Return the full name of this object, i.e.
Definition: object.h:229
UsdPrim GetPrim() const
Get the prim that the input belongs to.
Definition: input.h:79
A compact struct to represent a bundle of information about an upstream source attribute.
USDSHADE_API bool ClearSource() const
USDSHADE_API UsdShadeAttributeVector GetValueProducingAttributes(bool shaderOutputsOnly=false) const
Find what is connected to this Input recursively.
USDSHADE_API bool ClearSources() const
Clears sources for this Input in the current UsdEditTarget.
This class encapsulates a shader or node-graph output, which is a connectable attribute representing ...
Definition: output.h:47
USDSHADE_API bool SetConnectability(const TfToken &connectability) const
Set the connectability of the Input.
USDSHADE_API bool IsSourceConnectionFromBaseMaterial() const
Returns true if the connection to this Input&#39;s source, as returned by GetConnectedSource(), is authored across a specializes arc, which is used to denote a base material.
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: input.h:103
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:168
USDSHADE_API TfToken GetBaseName() const
Returns the name of the input.
USDSHADE_API TfToken GetConnectability() const
Returns the connectability of the Input.