usdrt::UsdShadeUtils

Defined in usdrt/scenegraph/usd/usdShade/utils.h

class UsdShadeUtils

This class contains a set of utility functions used when authoring and querying shading networks.

Public Static Functions

static inline std::string GetPrefixForAttributeType(UsdShadeAttributeType sourceType)

Returns the namespace prefix of the USD attribute associated with the given shading attribute type.

static inline std::pair<TfToken, UsdShadeAttributeType> GetBaseNameAndType(const TfToken &fullName)

Given the full name of a shading attribute, returns it’s base name and shading attribute type.

static UsdShadeAttributeVector GetValueProducingAttributes(UsdShadeInput const &input, bool shaderOutputsOnly = false)

Find what is connected to an Input or Output recursively.

GetValueProducingAttributes implements the UsdShade connectivity rules described in UsdShadeAttributeResolution .

When tracing connections within networks that contain containers like UsdShadeNodeGraph nodes, the actual output(s) or value(s) at the end of an input or output might be multiple connections removed. The methods below resolves this across multiple physical connections.

An UsdShadeInput is getting its value from one of these sources:

  • If the input is not connected the UsdAttribute for this input is returned, but only if it has an authored value. The input attribute itself carries the value for this input.

  • If the input is connected we follow the connection(s) until we reach a valid output of a UsdShadeShader node or if we reach a valid UsdShadeInput attribute of a UsdShadeNodeGraph or UsdShadeMaterial that has an authored value.

An UsdShadeOutput on a container can get its value from the same type of sources as a UsdShadeInput on either a UsdShadeShader or UsdShadeNodeGraph. Outputs on non-containers (UsdShadeShaders) cannot be connected.

This function returns a vector of UsdAttributes. The vector is empty if no valid attribute was found. The type of each attribute can be determined with the UsdShadeUtils::GetType function.

If shaderOutputsOnly is true, it will only report attributes that are outputs of non-containers (UsdShadeShaders). This is a bit faster and what is need when determining the connections for Material terminals.

Note

This will return the last attribute along the connection chain that has an authored value, which might not be the last attribute in the chain itself.

Note

When the network contains multi-connections, this function can return multiple attributes for a single input or output. The list of attributes is build by a depth-first search, following the underlying connection paths in order. The list can contain both UsdShadeOutput and UsdShadeInput attributes. It is up to the caller to decide how to process such a mixture.

Note

These functions work recursively, but that is not supported

static UsdShadeAttributeVector GetValueProducingAttributes(UsdShadeOutput const &output, bool shaderOutputsOnly = false)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.