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 USDSHADE_INPUT_H
25 #define USDSHADE_INPUT_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usdShade/api.h"
29 #include "pxr/usd/usd/attribute.h"
30 
31 #include "pxr/usd/ndr/declare.h"
32 #include "pxr/usd/usdShade/utils.h"
33 
34 #include <vector>
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
39 class UsdShadeOutput;
40 
47 {
48 public:
52  {
53  // nothing
54  }
55 
58  TfToken const &GetFullName() const {
59  return _attr.GetName();
60  }
61 
67  USDSHADE_API
68  TfToken GetBaseName() const;
69 
73  USDSHADE_API
75 
77  UsdPrim GetPrim() const {
78  return _attr.GetPrim();
79  }
80 
82  template <typename T>
83  bool Get(T* value, UsdTimeCode time = UsdTimeCode::Default()) const {
84  return GetAttr().Get(value, time);
85  }
86 
88  USDSHADE_API
89  bool Get(VtValue* value, UsdTimeCode time = UsdTimeCode::Default()) const;
90 
93  USDSHADE_API
94  bool Set(const VtValue& value,
95  UsdTimeCode time = UsdTimeCode::Default()) const;
96 
100  template <typename T>
101  bool Set(const T& value, UsdTimeCode time = UsdTimeCode::Default()) const {
102  return _attr.Set(value, time);
103  }
104 
106  struct Hash {
107  inline size_t operator()(const UsdShadeInput &input) const {
108  return hash_value(input._attr);
109  }
110  };
111 
114 
124  USDSHADE_API
125  bool SetRenderType(TfToken const& renderType) const;
126 
131  USDSHADE_API
132  TfToken GetRenderType() const;
133 
137  USDSHADE_API
138  bool HasRenderType() const;
139 
141 
156 
159  USDSHADE_API
160  NdrTokenMap GetSdrMetadata() const;
161 
164  USDSHADE_API
165  std::string GetSdrMetadataByKey(const TfToken &key) const;
166 
169  USDSHADE_API
170  void SetSdrMetadata(const NdrTokenMap &sdrMetadata) const;
171 
174  USDSHADE_API
175  void SetSdrMetadataByKey(
176  const TfToken &key,
177  const std::string &value) const;
178 
181  USDSHADE_API
182  bool HasSdrMetadata() const;
183 
186  USDSHADE_API
187  bool HasSdrMetadataByKey(const TfToken &key) const;
188 
191  USDSHADE_API
192  void ClearSdrMetadata() const;
193 
196  USDSHADE_API
197  void ClearSdrMetadataByKey(const TfToken &key) const;
198 
200 
201  // ---------------------------------------------------------------
203  // ---------------------------------------------------------------
204 
206 
211  USDSHADE_API
212  explicit UsdShadeInput(const UsdAttribute &attr);
213 
218  USDSHADE_API
219  static bool IsInput(const UsdAttribute &attr);
220 
223  USDSHADE_API
224  static bool IsInterfaceInputName(const std::string & name);
225 
227  const UsdAttribute &GetAttr() const { return _attr; }
228 
232  operator const UsdAttribute & () const { return GetAttr(); }
233 
236  bool IsDefined() const {
237  return _attr && IsInput(_attr);
238  }
239 
242  USDSHADE_API
243  bool SetDocumentation(const std::string& docs) const;
244 
247  USDSHADE_API
248  std::string GetDocumentation() const;
249 
253  USDSHADE_API
254  bool SetDisplayGroup(const std::string& displayGroup) const;
255 
259  USDSHADE_API
260  std::string GetDisplayGroup() const;
261 
263 
266  explicit operator bool() const {
267  return IsDefined();
268  }
269 
272  friend bool operator==(const UsdShadeInput &lhs, const UsdShadeInput &rhs) {
273  return lhs.GetAttr() == rhs.GetAttr();
274  }
275 
276  // -------------------------------------------------------------------------
278  // -------------------------------------------------------------------------
280 
285  USDSHADE_API
286  bool CanConnect(const UsdAttribute &source) const;
287 
289  USDSHADE_API
290  bool CanConnect(const UsdShadeInput &sourceInput) const;
291 
293  USDSHADE_API
294  bool CanConnect(const UsdShadeOutput &sourceOutput) const;
295 
308  USDSHADE_API
309  bool ConnectToSource(
310  UsdShadeConnectableAPI const &source,
311  TfToken const &sourceName,
312  UsdShadeAttributeType const sourceType=UsdShadeAttributeType::Output,
313  SdfValueTypeName typeName=SdfValueTypeName()) const;
314 
319  USDSHADE_API
320  bool ConnectToSource(SdfPath const &sourcePath) const;
321 
326  USDSHADE_API
327  bool ConnectToSource(UsdShadeInput const &sourceInput) const;
328 
333  USDSHADE_API
334  bool ConnectToSource(UsdShadeOutput const &sourceOutput) const;
335 
357  USDSHADE_API
359  TfToken *sourceName,
360  UsdShadeAttributeType *sourceType) const;
361 
366  USDSHADE_API
367  bool GetRawConnectedSourcePaths(SdfPathVector *sourcePaths) const;
368 
374  USDSHADE_API
375  bool HasConnectedSource() const;
376 
383  USDSHADE_API
385 
390  USDSHADE_API
391  bool DisconnectSource() const;
392 
400  USDSHADE_API
401  bool ClearSource() const;
402 
404 
405  // -------------------------------------------------------------------------
407  // -------------------------------------------------------------------------
409 
431  USDSHADE_API
432  bool SetConnectability(const TfToken &connectability) const;
433 
437  USDSHADE_API
438  TfToken GetConnectability() const;
439 
442  USDSHADE_API
443  bool ClearConnectability() const;
444 
446 
447  // -------------------------------------------------------------------------
449  // -------------------------------------------------------------------------
451 
475  USDSHADE_API
477  UsdShadeAttributeType* attrType) const;
478 
480 
481 private:
482  friend class UsdShadeConnectableAPI;
483 
484  // Constructor that creates a UsdShadeInput with the given name on the
485  // given prim.
486  // \p name here is the unnamespaced name of the input.
487  UsdShadeInput(UsdPrim prim,
488  TfToken const &name,
489  SdfValueTypeName const &typeName);
490 
491  UsdAttribute _attr;
492 };
493 
494 PXR_NAMESPACE_CLOSE_SCOPE
495 
496 #endif // USDSHADE_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:466
Hash functor.
Definition: input.h:106
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 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.
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:83
USDSHADE_API bool GetRawConnectedSourcePaths(SdfPathVector *sourcePaths) const
Returns the &quot;raw&quot; (authored) connected source paths for this Input.
Represents a value type name, i.e.
Definition: valueTypeName.h:83
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:236
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 property representing a ...
Definition: input.h:46
TfToken const & GetFullName() const
Get the name of the attribute associated with the Input.
Definition: input.h:58
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:89
friend bool operator==(const UsdShadeInput &lhs, const UsdShadeInput &rhs)
Equality comparison.
Definition: input.h:272
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:1644
USDSHADE_API std::string GetSdrMetadataByKey(const TfToken &key) const
Returns the value corresponding to key in the composed sdrMetadata dictionary.
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
Finds the source of a connection for this Input.
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:131
const UsdAttribute & GetAttr() const
Explicit UsdAttribute extractor.
Definition: input.h:227
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
USDSHADE_API TfToken GetRenderType() const
Return this Input&#39;s specialized renderType, or an empty token if none was authored.
USDSHADE_API bool DisconnectSource() const
Disconnect source for this Input.
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:435
UsdShadeInput()
Default constructor returns an invalid Input.
Definition: input.h:51
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
Find what is connected to an Input recursively.
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:228
USDSHADE_API bool ConnectToSource(UsdShadeConnectableAPI const &source, TfToken const &sourceName, UsdShadeAttributeType const sourceType=UsdShadeAttributeType::Output, SdfValueTypeName typeName=SdfValueTypeName()) const
Authors a connection for this Input to the source described by the following three elements: source...
UsdPrim GetPrim() const
Get the prim that the input belongs to.
Definition: input.h:77
USDSHADE_API bool ClearSource() const
Clears source for this shading property in the current UsdEditTarget.
This class encapsulates a shader or node-graph output, which is a connectable property representing a...
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:101
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182
USDSHADE_API TfToken GetBaseName() const
Returns the name of the input.
USDSHADE_API TfToken GetConnectability() const
Returns the connectability of the Input.