All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
output.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_USD_USD_SHADE_OUTPUT_H
8#define PXR_USD_USD_SHADE_OUTPUT_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/usdShade/api.h"
12#include "pxr/usd/usdShade/types.h"
13#include "pxr/usd/usdShade/utils.h"
14#include "pxr/usd/usd/attribute.h"
15#include "pxr/usd/ndr/declare.h"
16
17#include <vector>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
23class UsdShadeInput;
24
31{
32public:
36 {
37 // nothing
38 }
39
42 TfToken const &GetFullName() const {
43 return _attr.GetName();
44 }
45
51 USDSHADE_API
53
55 UsdPrim GetPrim() const {
56 return _attr.GetPrim();
57 }
58
62 USDSHADE_API
64
71 USDSHADE_API
72 bool Set(const VtValue& value,
73 UsdTimeCode time = UsdTimeCode::Default()) const;
74
78 template <typename T>
79 bool Set(const T& value, UsdTimeCode time = UsdTimeCode::Default()) const {
80 if (UsdAttribute attr = GetAttr()) {
81 return attr.Set(value, time);
82 }
83 return false;
84 }
85
88
97 USDSHADE_API
98 bool SetRenderType(TfToken const& renderType) const;
99
104 USDSHADE_API
106
111 USDSHADE_API
112 bool HasRenderType() const;
113
115
130
133 USDSHADE_API
134 NdrTokenMap GetSdrMetadata() const;
135
138 USDSHADE_API
139 std::string GetSdrMetadataByKey(const TfToken &key) const;
140
143 USDSHADE_API
144 void SetSdrMetadata(const NdrTokenMap &sdrMetadata) const;
145
148 USDSHADE_API
150 const TfToken &key,
151 const std::string &value) const;
152
155 USDSHADE_API
156 bool HasSdrMetadata() const;
157
160 USDSHADE_API
161 bool HasSdrMetadataByKey(const TfToken &key) const;
162
165 USDSHADE_API
166 void ClearSdrMetadata() const;
167
170 USDSHADE_API
171 void ClearSdrMetadataByKey(const TfToken &key) const;
172
174
175 // ---------------------------------------------------------------
177 // ---------------------------------------------------------------
178
180
185 USDSHADE_API
186 explicit UsdShadeOutput(const UsdAttribute &attr);
187
192 USDSHADE_API
193 static bool IsOutput(const UsdAttribute &attr);
194
196 const UsdAttribute &GetAttr() const { return _attr; }
197
201 operator UsdAttribute () const { return GetAttr(); }
202
206 bool IsDefined() const {
207 return IsOutput(_attr);
208 }
209
211
212 // -------------------------------------------------------------------------
214 // -------------------------------------------------------------------------
216
224 USDSHADE_API
225 bool CanConnect(const UsdAttribute &source) const;
226
228 USDSHADE_API
229 bool CanConnect(const UsdShadeInput &sourceInput) const;
230
232 USDSHADE_API
233 bool CanConnect(const UsdShadeOutput &sourceOutput) const;
234
235 using ConnectionModification = UsdShadeConnectionModification;
236
259 USDSHADE_API
261 UsdShadeConnectionSourceInfo const &source,
262 ConnectionModification const mod =
263 ConnectionModification::Replace) const;
264
267 USDSHADE_API
269 UsdShadeConnectableAPI const &source,
270 TfToken const &sourceName,
271 UsdShadeAttributeType const sourceType=UsdShadeAttributeType::Output,
272 SdfValueTypeName typeName=SdfValueTypeName()) const;
273
278 USDSHADE_API
279 bool ConnectToSource(SdfPath const &sourcePath) const;
280
285 USDSHADE_API
286 bool ConnectToSource(UsdShadeInput const &sourceInput) const;
287
292 USDSHADE_API
293 bool ConnectToSource(UsdShadeOutput const &sourceOutput) const;
294
299 USDSHADE_API
301 std::vector<UsdShadeConnectionSourceInfo> const &sourceInfos) const;
302
303 // XXX move to new header
305
323 USDSHADE_API
325 SdfPathVector *invalidSourcePaths = nullptr) const;
326
328 USDSHADE_API
330 TfToken *sourceName,
331 UsdShadeAttributeType *sourceType) const;
332
338 USDSHADE_API
339 bool GetRawConnectedSourcePaths(SdfPathVector *sourcePaths) const;
340
346 USDSHADE_API
347 bool HasConnectedSource() const;
348
355 USDSHADE_API
357
364 USDSHADE_API
365 bool DisconnectSource(UsdAttribute const &sourceAttr = UsdAttribute()) const;
366
374 USDSHADE_API
375 bool ClearSources() const;
376
378 USDSHADE_API
379 bool ClearSource() const;
380
382
383 // -------------------------------------------------------------------------
385 // -------------------------------------------------------------------------
387
391 USDSHADE_API
393 bool shaderOutputsOnly = false) const;
394
396
399 explicit operator bool() const {
400 return IsDefined();
401 }
402
405 friend bool operator==(const UsdShadeOutput &lhs, const UsdShadeOutput &rhs) {
406 return lhs.GetAttr() == rhs.GetAttr();
407 }
408
411 friend bool operator!=(const UsdShadeOutput &lhs, const UsdShadeOutput &rhs) {
412 return !(lhs == rhs);
413 }
414
415private:
416 friend class UsdShadeConnectableAPI;
417
418 // Constructor that creates a UsdShadeOutput with the given name on the
419 // given prim.
420 // \p name here is the unnamespaced name of the output.
422 TfToken const &name,
423 SdfValueTypeName const &typeName);
424
425 UsdAttribute _attr;
426};
427
428
429PXR_NAMESPACE_CLOSE_SCOPE
430
431#endif // PXR_USD_USD_SHADE_OUTPUT_H
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Represents a value type name, i.e.
Definition: valueTypeName.h:71
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:157
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:160
UsdPrim GetPrim() const
Return this object if it is a prim, otherwise return this object's nearest owning prim.
Definition: prim.h:2787
const TfToken & GetName() const
Return the full name of this object, i.e.
Definition: object.h:221
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
UsdShadeConnectableAPI is an API schema that provides a common interface for creating outputs and mak...
This class encapsulates a shader or node-graph input, which is a connectable attribute representing a...
Definition: input.h:32
This class encapsulates a shader or node-graph output, which is a connectable attribute representing ...
Definition: output.h:31
friend bool operator!=(const UsdShadeOutput &lhs, const UsdShadeOutput &rhs)
Inequality comparison.
Definition: output.h:411
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 ...
USDSHADE_API bool ConnectToSource(SdfPath const &sourcePath) const
Authors a connection for this Output to the source at the given path.
USDSHADE_API std::string GetSdrMetadataByKey(const TfToken &key) const
Returns the value corresponding to key in the composed sdrMetadata dictionary.
USDSHADE_API UsdShadeAttributeVector GetValueProducingAttributes(bool shaderOutputsOnly=false) const
Find what is connected to this Output recursively.
USDSHADE_API bool Set(const VtValue &value, UsdTimeCode time=UsdTimeCode::Default()) const
Set a value for the output.
USDSHADE_API bool HasRenderType() const
Return true if a renderType has been specified for this output.
USDSHADE_API bool CanConnect(const UsdShadeOutput &sourceOutput) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
USDSHADE_API TfToken GetRenderType() const
Return this output's specialized renderType, or an empty token if none was authored.
USDSHADE_API bool HasConnectedSource() const
Returns true if and only if this Output is currently connected to a valid (defined) source.
UsdPrim GetPrim() const
Get the prim that the output belongs to.
Definition: output.h:55
USDSHADE_API bool ConnectToSource(UsdShadeOutput const &sourceOutput) const
Connects this Output to the given output, sourceOutput.
USDSHADE_API bool ConnectToSource(UsdShadeConnectionSourceInfo const &source, ConnectionModification const mod=ConnectionModification::Replace) const
Authors a connection for this Output.
TfToken const & GetFullName() const
Get the name of the attribute associated with the output.
Definition: output.h:42
USDSHADE_API TfToken GetBaseName() const
Returns the name of the output.
USDSHADE_API bool ConnectToSource(UsdShadeConnectableAPI const &source, TfToken const &sourceName, UsdShadeAttributeType const sourceType=UsdShadeAttributeType::Output, SdfValueTypeName typeName=SdfValueTypeName()) const
const UsdAttribute & GetAttr() const
Explicit UsdAttribute extractor.
Definition: output.h:196
static USDSHADE_API bool IsOutput(const UsdAttribute &attr)
Test whether a given UsdAttribute represents a valid Output, which implies that creating a UsdShadeOu...
USDSHADE_API NdrTokenMap GetSdrMetadata() const
Returns this Output's composed "sdrMetadata" dictionary as a NdrTokenMap.
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:79
bool IsDefined() const
Return true if the wrapped UsdAttribute is defined, and in addition the attribute is identified as an...
Definition: output.h:206
USDSHADE_API SourceInfoVector GetConnectedSources(SdfPathVector *invalidSourcePaths=nullptr) const
Finds the valid sources of connections for the Output.
USDSHADE_API bool SetConnectedSources(std::vector< UsdShadeConnectionSourceInfo > const &sourceInfos) const
Connects this Output to the given sources, sourceInfos.
friend bool operator==(const UsdShadeOutput &lhs, const UsdShadeOutput &rhs)
Equality comparison.
Definition: output.h:405
USDSHADE_API void SetSdrMetadata(const NdrTokenMap &sdrMetadata) const
Authors the given sdrMetadata value on this Output at the current EditTarget.
USDSHADE_API bool IsSourceConnectionFromBaseMaterial() const
Returns true if the connection to this Output's source, as returned by GetConnectedSource(),...
USDSHADE_API UsdShadeOutput(const UsdAttribute &attr)
Speculative constructor that will produce a valid UsdShadeOutput when attr already represents a shade...
USDSHADE_API void ClearSdrMetadata() const
Clears any "sdrMetadata" value authored on the Output in the current EditTarget.
USDSHADE_API bool CanConnect(const UsdShadeInput &sourceInput) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
USDSHADE_API bool HasSdrMetadata() const
Returns true if the Output has a non-empty composed "sdrMetadata" dictionary value.
USDSHADE_API SdfValueTypeName GetTypeName() const
Get the "scene description" value type name of the attribute associated with the output.
USDSHADE_API bool SetRenderType(TfToken const &renderType) const
Specify an alternative, renderer-specific type to use when emitting/translating this output,...
USDSHADE_API bool HasSdrMetadataByKey(const TfToken &key) const
Returns true if there is a value corresponding to the given key in the composed "sdrMetadata" diction...
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's "sdrMetadata" dictiona...
USDSHADE_API void ClearSdrMetadataByKey(const TfToken &key) const
Clears the entry corresponding to the given key in the "sdrMetadata" dictionary authored in the curre...
USDSHADE_API bool GetConnectedSource(UsdShadeConnectableAPI *source, TfToken *sourceName, UsdShadeAttributeType *sourceType) const
UsdShadeOutput()
Default constructor returns an invalid Output.
Definition: output.h:35
USDSHADE_API bool DisconnectSource(UsdAttribute const &sourceAttr=UsdAttribute()) const
Disconnect source for this Output.
USDSHADE_API bool ClearSource() const
USDSHADE_API bool ClearSources() const
Clears sources for this Output in the current UsdEditTarget.
USDSHADE_API bool ConnectToSource(UsdShadeInput const &sourceInput) const
Connects this Output to the given input, sourceInput.
USDSHADE_API bool GetRawConnectedSourcePaths(SdfPathVector *sourcePaths) const
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:67
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for 'default'.
Definition: timeCode.h:95
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
A compact struct to represent a bundle of information about an upstream source attribute.
Common typedefs that are used throughout the NDR library.