This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
UsdShadeNodeDefAPI Class Reference

UsdShadeNodeDefAPI is an API schema that provides attributes for a prim to select a corresponding Shader Node Definition ("Sdr Node"), as well as to look up a runtime entry for that shader node in the form of an SdrShaderNode. More...

#include <nodeDefAPI.h>

+ Inheritance diagram for UsdShadeNodeDefAPI:

Public Member Functions

 UsdShadeNodeDefAPI (const UsdPrim &prim=UsdPrim())
 Construct a UsdShadeNodeDefAPI on UsdPrim prim .
 
 UsdShadeNodeDefAPI (const UsdSchemaBase &schemaObj)
 Construct a UsdShadeNodeDefAPI on the prim held by schemaObj .
 
virtual USDSHADE_API ~UsdShadeNodeDefAPI ()
 Destructor.
 
USDSHADE_API UsdAttribute GetImplementationSourceAttr () const
 Specifies the attribute that should be consulted to get the shader's implementation or its source code.
 
USDSHADE_API UsdAttribute CreateImplementationSourceAttr (VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
 See GetImplementationSourceAttr(), and also Create vs Get Property Methods for when to use Get vs Create.
 
USDSHADE_API UsdAttribute GetIdAttr () const
 The id is an identifier for the type or purpose of the shader.
 
USDSHADE_API UsdAttribute CreateIdAttr (VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
 See GetIdAttr(), and also Create vs Get Property Methods for when to use Get vs Create.
 
USDSHADE_API SdrShaderNodeConstPtr GetShaderNodeForSourceType (const TfToken &sourceType) const
 This method attempts to ensure that there is a ShaderNode in the shader registry (i.e.
 
Shader Source API

This section provides API for identifying the source of a shader's implementation.

USDSHADE_API TfToken GetImplementationSource () const
 Reads the value of info:implementationSource attribute and returns a token identifying the attribute that must be consulted to identify the shader's source program.
 
USDSHADE_API bool SetShaderId (const TfToken &id) const
 Sets the shader's ID value.
 
USDSHADE_API bool GetShaderId (TfToken *id) const
 Fetches the shader's ID value from the info:id attribute, if the shader's info:implementationSource is id.
 
USDSHADE_API bool SetSourceAsset (const SdfAssetPath &sourceAsset, const TfToken &sourceType=UsdShadeTokens->universalSourceType) const
 Sets the shader's source-asset path value to sourceAsset for the given source type, sourceType.
 
USDSHADE_API bool GetSourceAsset (SdfAssetPath *sourceAsset, const TfToken &sourceType=UsdShadeTokens->universalSourceType) const
 Fetches the shader's source asset value for the specified sourceType value from the info:sourceType:sourceAsset attribute, if the shader's info:implementationSource is sourceAsset.
 
USDSHADE_API bool SetSourceAssetSubIdentifier (const TfToken &subIdentifier, const TfToken &sourceType=UsdShadeTokens->universalSourceType) const
 Set a sub-identifier to be used with a source asset of the given source type.
 
USDSHADE_API bool GetSourceAssetSubIdentifier (TfToken *subIdentifier, const TfToken &sourceType=UsdShadeTokens->universalSourceType) const
 Fetches the shader's sub-identifier for the source asset with the specified sourceType value from the info:sourceType: sourceAsset:subIdentifier attribute, if the shader's info: implementationSource is sourceAsset.
 
USDSHADE_API bool SetSourceCode (const std::string &sourceCode, const TfToken &sourceType=UsdShadeTokens->universalSourceType) const
 Sets the shader's source-code value to sourceCode for the given source type, sourceType.
 
USDSHADE_API bool GetSourceCode (std::string *sourceCode, const TfToken &sourceType=UsdShadeTokens->universalSourceType) const
 Fetches the shader's source code for the specified sourceType value by reading the info:sourceType:sourceCode attribute, if the shader's info:implementationSource is sourceCode.
 
USDSHADE_API std::vector< std::string > GetSourceTypes () const
 Fetches the source types for the specified prim value by reading the info:sourceType:<implementationSource> attribute, if the shader's info:implementationSource is sourceCode or sourceAsset.
 
- Public Member Functions inherited from UsdAPISchemaBase
 UsdAPISchemaBase (const UsdPrim &prim=UsdPrim())
 Construct a UsdAPISchemaBase on UsdPrim prim .
 
 UsdAPISchemaBase (const UsdSchemaBase &schemaObj)
 Construct a UsdAPISchemaBase on the prim held by schemaObj .
 
virtual USD_API ~UsdAPISchemaBase ()=0
 Destructor.
 
- Public Member Functions inherited from UsdSchemaBase
bool IsConcrete () const
 Returns whether or not this class corresponds to a concrete instantiable prim type in scene description.
 
bool IsTyped () const
 Returns whether or not this class inherits from UsdTyped.
 
bool IsAPISchema () const
 Returns whether this is an API schema or not.
 
bool IsAppliedAPISchema () const
 Returns whether this is an applied API schema or not.
 
bool IsMultipleApplyAPISchema () const
 Returns whether this is an applied API schema or not.
 
UsdSchemaKind GetSchemaKind () const
 Returns the kind of schema this class is.
 
USD_API UsdSchemaBase (const UsdPrim &prim=UsdPrim())
 Construct and store prim as the held prim.
 
USD_API UsdSchemaBase (const UsdSchemaBase &otherSchema)
 Construct and store for the same prim held by otherSchema.
 
virtual USD_API ~UsdSchemaBase ()
 Destructor.
 
UsdPrim GetPrim () const
 Return this schema object's held prim.
 
SdfPath GetPath () const
 Shorthand for GetPrim()->GetPath().
 
USD_API const UsdPrimDefinitionGetSchemaClassPrimDefinition () const
 Return the prim definition associated with this schema instance if one exists, otherwise return null.
 
USD_API operator bool () const
 Return true if this schema object is compatible with its held prim, false otherwise.
 

Static Public Member Functions

static USDSHADE_API const TfTokenVectorGetSchemaAttributeNames (bool includeInherited=true)
 Return a vector of names of all pre-declared attributes for this schema class and all its ancestor classes.
 
static USDSHADE_API UsdShadeNodeDefAPI Get (const UsdStagePtr &stage, const SdfPath &path)
 Return a UsdShadeNodeDefAPI holding the prim adhering to this schema at path on stage.
 
static USDSHADE_API bool CanApply (const UsdPrim &prim, std::string *whyNot=nullptr)
 Returns true if this single-apply API schema can be applied to the given prim.
 
static USDSHADE_API UsdShadeNodeDefAPI Apply (const UsdPrim &prim)
 Applies this single-apply API schema to the given prim.
 
- Static Public Member Functions inherited from UsdAPISchemaBase
static USD_API const TfTokenVectorGetSchemaAttributeNames (bool includeInherited=true)
 Return a vector of names of all pre-declared attributes for this schema class and all its ancestor classes.
 
- Static Public Member Functions inherited from UsdSchemaBase
static const TfTokenVectorGetSchemaAttributeNames (bool includeInherited=true)
 

Static Public Attributes

static const UsdSchemaKind schemaKind = UsdSchemaKind::SingleApplyAPI
 Compile time constant representing what kind of schema this class is.
 
- Static Public Attributes inherited from UsdAPISchemaBase
static const UsdSchemaKind schemaKind = UsdSchemaKind::AbstractBase
 Compile time constant representing what kind of schema this class is.
 
- Static Public Attributes inherited from UsdSchemaBase
static const UsdSchemaKind schemaKind = UsdSchemaKind::AbstractBase
 Compile time constant representing what kind of schema this class is.
 

Protected Member Functions

USDSHADE_API UsdSchemaKind _GetSchemaKind () const override
 Returns the kind of schema this class belongs to.
 
- Protected Member Functions inherited from UsdAPISchemaBase
USD_API UsdSchemaKind _GetSchemaKind () const override
 Returns the kind of schema this class belongs to.
 
 UsdAPISchemaBase (const UsdPrim &prim, const TfToken &instanceName)
 Construct a multiple-apply UsdAPISchemaBase on UsdPrim prim with the specified instanceName.
 
 UsdAPISchemaBase (const UsdSchemaBase &schemaObj, const TfToken &instanceName)
 Construct a multiple-apply UsdAPISchemaBase on the prim held by schemaObj with the given instanceName.
 
const TfToken_GetInstanceName () const
 Returns the instance name of the API schema object belonging to a multiple-apply API schema.
 
USD_API bool _IsCompatible () const override
 Check whether this APISchema object is valid for the currently held
prim.
 
- Protected Member Functions inherited from UsdSchemaBase
virtual UsdSchemaKind _GetSchemaType () const
 
const TfType_GetType () const
 
USD_API UsdAttribute _CreateAttr (TfToken const &attrName, SdfValueTypeName const &typeName, bool custom, SdfVariability variability, VtValue const &defaultValue, bool writeSparsely) const
 

Friends

class UsdSchemaRegistry
 

Additional Inherited Members

- Static Protected Member Functions inherited from UsdAPISchemaBase
static USD_API TfTokenVector _GetMultipleApplyInstanceNames (const UsdPrim &prim, const TfType &schemaType)
 Returns a vector of names of API schema objects belonging to a multiple-apply API schema applied to a given prim.
 

Detailed Description

UsdShadeNodeDefAPI is an API schema that provides attributes for a prim to select a corresponding Shader Node Definition ("Sdr Node"), as well as to look up a runtime entry for that shader node in the form of an SdrShaderNode.

UsdShadeNodeDefAPI is intended to be a pre-applied API schema for any prim type that wants to refer to the SdrRegistry for further implementation details about the behavior of that prim. The primary use in UsdShade itself is as UsdShadeShader, which is a basis for material shading networks (UsdShadeMaterial), but this is intended to be used in other domains that also use the Sdr node mechanism.

This schema provides properties that allow a prim to identify an external node definition, either by a direct identifier key into the SdrRegistry (info:id), an asset to be parsed by a suitable NdrParserPlugin (info:sourceAsset), or an inline source code that must also be parsed (info:sourceCode); as well as a selector attribute to determine which specifier is active (info:implementationSource).

For any described attribute Fallback Value or Allowed Values below that are text/tokens, the actual token is published and defined in UsdShadeTokens. So to set an attribute to the value "rightHanded", use UsdShadeTokens->rightHanded as the value.

Definition at line 67 of file nodeDefAPI.h.

Constructor & Destructor Documentation

◆ UsdShadeNodeDefAPI() [1/2]

UsdShadeNodeDefAPI ( const UsdPrim prim = UsdPrim())
inlineexplicit

Construct a UsdShadeNodeDefAPI on UsdPrim prim .

Equivalent to UsdShadeNodeDefAPI::Get(prim.GetStage(), prim.GetPath()) for a valid prim, but will not immediately throw an error for an invalid prim

Definition at line 79 of file nodeDefAPI.h.

◆ UsdShadeNodeDefAPI() [2/2]

UsdShadeNodeDefAPI ( const UsdSchemaBase schemaObj)
inlineexplicit

Construct a UsdShadeNodeDefAPI on the prim held by schemaObj .

Should be preferred over UsdShadeNodeDefAPI(schemaObj.GetPrim()), as it preserves SchemaBase state.

Definition at line 87 of file nodeDefAPI.h.

◆ ~UsdShadeNodeDefAPI()

virtual USDSHADE_API ~UsdShadeNodeDefAPI ( )
virtual

Destructor.

Member Function Documentation

◆ _GetSchemaKind()

USDSHADE_API UsdSchemaKind _GetSchemaKind ( ) const
overrideprotectedvirtual

Returns the kind of schema this class belongs to.

See also
UsdSchemaKind

Reimplemented from UsdAPISchemaBase.

◆ Apply()

static USDSHADE_API UsdShadeNodeDefAPI Apply ( const UsdPrim prim)
static

Applies this single-apply API schema to the given prim.

This information is stored by adding "NodeDefAPI" to the token-valued, listOp metadata apiSchemas on the prim.

Returns
A valid UsdShadeNodeDefAPI object is returned upon success. An invalid (or empty) UsdShadeNodeDefAPI object is returned upon failure. See UsdPrim::ApplyAPI() for conditions resulting in failure.
See also
UsdPrim::GetAppliedSchemas()
UsdPrim::HasAPI()
UsdPrim::CanApplyAPI()
UsdPrim::ApplyAPI()
UsdPrim::RemoveAPI()

◆ CanApply()

static USDSHADE_API bool CanApply ( const UsdPrim prim,
std::string *  whyNot = nullptr 
)
static

Returns true if this single-apply API schema can be applied to the given prim.

If this schema can not be a applied to the prim, this returns false and, if provided, populates whyNot with the reason it can not be applied.

Note that if CanApply returns false, that does not necessarily imply that calling Apply will fail. Callers are expected to call CanApply before calling Apply if they want to ensure that it is valid to apply a schema.

See also
UsdPrim::GetAppliedSchemas()
UsdPrim::HasAPI()
UsdPrim::CanApplyAPI()
UsdPrim::ApplyAPI()
UsdPrim::RemoveAPI()

◆ CreateIdAttr()

USDSHADE_API UsdAttribute CreateIdAttr ( VtValue const &  defaultValue = VtValue(),
bool  writeSparsely = false 
) const

See GetIdAttr(), and also Create vs Get Property Methods for when to use Get vs Create.

If specified, author defaultValue as the attribute's default, sparsely (when it makes sense to do so) if writeSparsely is true - the default for writeSparsely is false.

◆ CreateImplementationSourceAttr()

USDSHADE_API UsdAttribute CreateImplementationSourceAttr ( VtValue const &  defaultValue = VtValue(),
bool  writeSparsely = false 
) const

See GetImplementationSourceAttr(), and also Create vs Get Property Methods for when to use Get vs Create.

If specified, author defaultValue as the attribute's default, sparsely (when it makes sense to do so) if writeSparsely is true - the default for writeSparsely is false.

◆ Get()

static USDSHADE_API UsdShadeNodeDefAPI Get ( const UsdStagePtr &  stage,
const SdfPath path 
)
static

Return a UsdShadeNodeDefAPI holding the prim adhering to this schema at path on stage.

If no prim exists at path on stage, or if the prim at that path does not adhere to this schema, return an invalid schema object. This is shorthand for the following:

UsdShadeNodeDefAPI(stage->GetPrimAtPath(path));
UsdShadeNodeDefAPI is an API schema that provides attributes for a prim to select a corresponding Sha...
Definition: nodeDefAPI.h:68

◆ GetIdAttr()

USDSHADE_API UsdAttribute GetIdAttr ( ) const

The id is an identifier for the type or purpose of the shader.

E.g.: Texture or FractalFloat. The use of this id will depend on the render context: some will turn it into an actual shader path, some will use it to generate shader source code dynamically.

See also
SetShaderId()
Declaration uniform token info:id
C++ Type TfToken
Usd Type SdfValueTypeNames->Token
Variability SdfVariabilityUniform

◆ GetImplementationSource()

USDSHADE_API TfToken GetImplementationSource ( ) const

Reads the value of info:implementationSource attribute and returns a token identifying the attribute that must be consulted to identify the shader's source program.

This returns

  • id, to indicate that the "info:id" attribute must be consulted.
  • sourceAsset to indicate that the asset-valued "info:{sourceType}:sourceAsset" attribute associated with the desired sourceType should be consulted to locate the asset with the shader's source.
  • sourceCode to indicate that the string-valued "info:{sourceType}:sourceCode" attribute associated with the desired sourceType should be read to get shader's source.

This issues a warning and returns id if the info:implementationSource attribute has an invalid value.

{sourceType} above is a place holder for a token that identifies the type of shader source or its implementation. For example: osl, glslfx, riCpp etc. This allows a shader to specify different sourceAsset (or sourceCode) values for different sourceTypes. The sourceType tokens usually correspond to the sourceType value of the NdrParserPlugin that's used to parse the shader source (NdrParserPlugin::SourceType).

When sourceType is empty, the corresponding sourceAsset or sourceCode is considered to be "universal" (or fallback), which is represented by the empty-valued token UsdShadeTokens->universalSourceType. When the sourceAsset (or sourceCode) corresponding to a specific, requested sourceType is unavailable, the universal sourceAsset (or sourceCode) is returned by GetSourceAsset (and GetSourceCode} API, if present.

See also
GetShaderId()
GetSourceAsset()
GetSourceCode()

◆ GetImplementationSourceAttr()

USDSHADE_API UsdAttribute GetImplementationSourceAttr ( ) const

Specifies the attribute that should be consulted to get the shader's implementation or its source code.

  • If set to "id", the "info:id" attribute's value is used to determine the shader source from the shader registry.
  • If set to "sourceAsset", the resolved value of the "info:sourceAsset" attribute corresponding to the desired implementation (or source-type) is used to locate the shader source. A source asset file may also specify multiple shader definitions, so there is an optional attribute "info:sourceAsset:subIdentifier" whose value should be used to indicate a particular shader definition from a source asset file.
  • If set to "sourceCode", the value of "info:sourceCode" attribute corresponding to the desired implementation (or source type) is used as the shader source.
Declaration uniform token info:implementationSource = "id"
C++ Type TfToken
Usd Type SdfValueTypeNames->Token
Variability SdfVariabilityUniform
Allowed Values id, sourceAsset, sourceCode

◆ GetSchemaAttributeNames()

static USDSHADE_API const TfTokenVector & GetSchemaAttributeNames ( bool  includeInherited = true)
static

Return a vector of names of all pre-declared attributes for this schema class and all its ancestor classes.

Does not include attributes that may be authored by custom/extended methods of the schemas involved.

◆ GetShaderId()

USDSHADE_API bool GetShaderId ( TfToken id) const

Fetches the shader's ID value from the info:id attribute, if the shader's info:implementationSource is id.

Returns true if the shader's implementation source is id and the value was fetched properly into id. Returns false otherwise.

See also
GetImplementationSource()

◆ GetShaderNodeForSourceType()

USDSHADE_API SdrShaderNodeConstPtr GetShaderNodeForSourceType ( const TfToken sourceType) const

This method attempts to ensure that there is a ShaderNode in the shader registry (i.e.

SdrRegistry) representing this shader for the given sourceType. It may return a null pointer if none could be found or created.

◆ GetSourceAsset()

USDSHADE_API bool GetSourceAsset ( SdfAssetPath sourceAsset,
const TfToken sourceType = UsdShadeTokens->universalSourceType 
) const

Fetches the shader's source asset value for the specified sourceType value from the info:sourceType:sourceAsset attribute, if the shader's info:implementationSource is sourceAsset.

If the sourceAsset attribute corresponding to the requested sourceType isn't present on the shader, then the universal fallback sourceAsset attribute, i.e. info:sourceAsset is consulted, if present, to get the source asset path.

Returns true if the shader's implementation source is sourceAsset and the source asset path value was fetched successfully into sourceAsset. Returns false otherwise.

See also
GetImplementationSource()

◆ GetSourceAssetSubIdentifier()

USDSHADE_API bool GetSourceAssetSubIdentifier ( TfToken subIdentifier,
const TfToken sourceType = UsdShadeTokens->universalSourceType 
) const

Fetches the shader's sub-identifier for the source asset with the specified sourceType value from the info:sourceType: sourceAsset:subIdentifier attribute, if the shader's info: implementationSource is sourceAsset.

If the subIdentifier attribute corresponding to the requested sourceType isn't present on the shader, then the universal fallback sub-identifier attribute, i.e. info:sourceAsset: subIdentifier is consulted, if present, to get the sub-identifier name.

Returns true if the shader's implementation source is sourceAsset and the sub-identifier for the given source type was fetched successfully into subIdentifier. Returns false otherwise.

◆ GetSourceCode()

USDSHADE_API bool GetSourceCode ( std::string *  sourceCode,
const TfToken sourceType = UsdShadeTokens->universalSourceType 
) const

Fetches the shader's source code for the specified sourceType value by reading the info:sourceType:sourceCode attribute, if the shader's info:implementationSource is sourceCode.

If the sourceCode attribute corresponding to the requested sourceType isn't present on the shader, then the universal or fallback sourceCode attribute (i.e. info:sourceCode) is consulted, if present, to get the source code.

Returns true if the shader's implementation source is sourceCode and the source code string was fetched successfully into sourceCode. Returns false otherwise.

See also
GetImplementationSource()

◆ GetSourceTypes()

USDSHADE_API std::vector< std::string > GetSourceTypes ( ) const

Fetches the source types for the specified prim value by reading the info:sourceType:<implementationSource> attribute, if the shader's info:implementationSource is sourceCode or sourceAsset.

If there are no source types listed then this returns an empty list

See also
GetImplementationSource()

◆ SetShaderId()

USDSHADE_API bool SetShaderId ( const TfToken id) const

Sets the shader's ID value.

This also sets the info:implementationSource attribute on the shader to UsdShadeTokens->id, if the existing value is different.

◆ SetSourceAsset()

USDSHADE_API bool SetSourceAsset ( const SdfAssetPath sourceAsset,
const TfToken sourceType = UsdShadeTokens->universalSourceType 
) const

Sets the shader's source-asset path value to sourceAsset for the given source type, sourceType.

This also sets the info:implementationSource attribute on the shader to UsdShadeTokens->sourceAsset.

◆ SetSourceAssetSubIdentifier()

USDSHADE_API bool SetSourceAssetSubIdentifier ( const TfToken subIdentifier,
const TfToken sourceType = UsdShadeTokens->universalSourceType 
) const

Set a sub-identifier to be used with a source asset of the given source type.

This sets the info:sourceType:sourceAsset:subIdentifier .

This also sets the info:implementationSource attribute on the shader to UsdShadeTokens->sourceAsset

◆ SetSourceCode()

USDSHADE_API bool SetSourceCode ( const std::string &  sourceCode,
const TfToken sourceType = UsdShadeTokens->universalSourceType 
) const

Sets the shader's source-code value to sourceCode for the given source type, sourceType.

This also sets the info:implementationSource attribute on the shader to UsdShadeTokens->sourceCode.

Friends And Related Function Documentation

◆ UsdSchemaRegistry

friend class UsdSchemaRegistry
friend

Definition at line 165 of file nodeDefAPI.h.

Member Data Documentation

◆ schemaKind

const UsdSchemaKind schemaKind = UsdSchemaKind::SingleApplyAPI
static

Compile time constant representing what kind of schema this class is.

See also
UsdSchemaKind

Definition at line 73 of file nodeDefAPI.h.


The documentation for this class was generated from the following file: