add usd-21-11-win64_py39

This commit is contained in:
Sébastien Albert committed 2021-12-07 17:43:55 +01:00
1 parent 41d23e71ba
commit ba5e1f7e67
15684 files changed
+3069957

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
//
// Copyright 2017 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSHADE_API_H
#define USDSHADE_API_H
#include "pxr/base/arch/export.h"
#if defined(PXR_STATIC)
# define USDSHADE_API
# define USDSHADE_API_TEMPLATE_CLASS(...)
# define USDSHADE_API_TEMPLATE_STRUCT(...)
# define USDSHADE_LOCAL
#else
# if defined(USDSHADE_EXPORTS)
# define USDSHADE_API ARCH_EXPORT
# define USDSHADE_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
# define USDSHADE_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
# else
# define USDSHADE_API ARCH_IMPORT
# define USDSHADE_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
# define USDSHADE_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
# endif
# define USDSHADE_LOCAL ARCH_HIDDEN
#endif
#endif
+830
View File
@@ -0,0 +1,830 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSHADE_GENERATED_CONNECTABLEAPI_H
#define USDSHADE_GENERATED_CONNECTABLEAPI_H
/// \file usdShade/connectableAPI.h
#include "pxr/pxr.h"
#include "pxr/usd/usdShade/api.h"
#include "pxr/usd/usd/apiSchemaBase.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usd/typed.h"
#include "pxr/usd/usdShade/input.h"
#include "pxr/usd/usdShade/output.h"
#include "pxr/usd/usdShade/tokens.h"
#include "pxr/usd/usdShade/types.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class SdfAssetPath;
// -------------------------------------------------------------------------- //
// CONNECTABLEAPI //
// -------------------------------------------------------------------------- //
/// \class UsdShadeConnectableAPI
///
/// UsdShadeConnectableAPI is an API schema that provides a common
/// interface for creating outputs and making connections between shading
/// parameters and outputs. The interface is common to all UsdShade schemas
/// that support Inputs and Outputs, which currently includes UsdShadeShader,
/// UsdShadeNodeGraph, and UsdShadeMaterial .
///
/// One can construct a UsdShadeConnectableAPI directly from a UsdPrim, or
/// from objects of any of the schema classes listed above. If it seems
/// onerous to need to construct a secondary schema object to interact with
/// Inputs and Outputs, keep in mind that any function whose purpose is either
/// to walk material/shader networks via their connections, or to create such
/// networks, can typically be written entirely in terms of
/// UsdShadeConnectableAPI objects, without needing to care what the underlying
/// prim type is.
///
/// Additionally, the most common UsdShadeConnectableAPI behaviors
/// (creating Inputs and Outputs, and making connections) are wrapped as
/// convenience methods on the prim schema classes (creation) and
/// UsdShadeInput and UsdShadeOutput.
///
///
class UsdShadeConnectableAPI : public UsdAPISchemaBase
{
public:
/// Compile time constant representing what kind of schema this class is.
///
/// \sa UsdSchemaKind
static const UsdSchemaKind schemaKind = UsdSchemaKind::NonAppliedAPI;
/// Construct a UsdShadeConnectableAPI on UsdPrim \p prim .
/// Equivalent to UsdShadeConnectableAPI::Get(prim.GetStage(), prim.GetPath())
/// for a \em valid \p prim, but will not immediately throw an error for
/// an invalid \p prim
explicit UsdShadeConnectableAPI(const UsdPrim& prim=UsdPrim())
: UsdAPISchemaBase(prim)
{
}
/// Construct a UsdShadeConnectableAPI on the prim held by \p schemaObj .
/// Should be preferred over UsdShadeConnectableAPI(schemaObj.GetPrim()),
/// as it preserves SchemaBase state.
explicit UsdShadeConnectableAPI(const UsdSchemaBase& schemaObj)
: UsdAPISchemaBase(schemaObj)
{
}
/// Destructor.
USDSHADE_API
virtual ~UsdShadeConnectableAPI();
/// 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.
USDSHADE_API
static const TfTokenVector &
GetSchemaAttributeNames(bool includeInherited=true);
/// Return a UsdShadeConnectableAPI holding the prim adhering to this
/// schema at \p path on \p stage. If no prim exists at \p path on
/// \p 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:
///
/// \code
/// UsdShadeConnectableAPI(stage->GetPrimAtPath(path));
/// \endcode
///
USDSHADE_API
static UsdShadeConnectableAPI
Get(const UsdStagePtr &stage, const SdfPath &path);
protected:
/// Returns the kind of schema this class belongs to.
///
/// \sa UsdSchemaKind
USDSHADE_API
UsdSchemaKind _GetSchemaKind() const override;
private:
// needs to invoke _GetStaticTfType.
friend class UsdSchemaRegistry;
USDSHADE_API
static const TfType &_GetStaticTfType();
static bool _IsTypedSchema();
// override SchemaBase virtuals.
USDSHADE_API
const TfType &_GetTfType() const override;
public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
// the code generator.
//
// Just remember to:
// - Close the class declaration with };
// - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
// - Close the include guard with #endif
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
protected:
/// Returns true if the given prim is compatible with this API schema,
/// i.e. if it is a valid shader or a node-graph.
/// A prim has a compatible connectableAPI if a valid behavior is registered
/// for it.
USDSHADE_API
bool _IsCompatible() const override;
public:
/// Returns true if the prim is a container.
///
/// The underlying prim type may provide runtime behavior
/// that defines whether it is a container.
USDSHADE_API
bool IsContainer() const;
/// Returns true if container encapsulation rules should be respected when
/// evaluating connectibility behavior, false otherwise.
///
/// The underlying prim type may provide runtime behavior that defines if
/// encapsulation rules are respected or not.
USDSHADE_API
bool RequiresEncapsulation() const;
/// \name Connections
///
/// Inputs and outputs on shaders and node-graphs are connectable.
/// This section provides API for authoring and managing these connections
/// in a shading network.
///
/// @{
/// Determines whether the given input can be connected to the given
/// source attribute, which can be an input or an output.
///
/// The result depends on the "connectability" of the input and the source
/// attributes. Depending on the prim type, this may require the plugin
/// that defines connectability behavior for that prim type be loaded.
///
/// \sa UsdShadeInput::SetConnectability
/// \sa UsdShadeInput::GetConnectability
USDSHADE_API
static bool CanConnect(const UsdShadeInput &input,
const UsdAttribute &source);
/// \overload
USDSHADE_API
static bool CanConnect(const UsdShadeInput &input,
const UsdShadeInput &sourceInput) {
return CanConnect(input, sourceInput.GetAttr());
}
/// \overload
USDSHADE_API
static bool CanConnect(const UsdShadeInput &input,
const UsdShadeOutput &sourceOutput) {
return CanConnect(input, sourceOutput.GetAttr());
}
/// Determines whether the given output can be connected to the given
/// source attribute, which can be an input or an output.
///
/// An output is considered to be connectable only if it belongs to a
/// node-graph. Shader outputs are not connectable.
///
/// \p source is an optional argument. If a valid UsdAttribute is supplied
/// for it, this method will return true only if the source attribute is
/// owned by a descendant of the node-graph owning the output.
///
USDSHADE_API
static bool CanConnect(const UsdShadeOutput &output,
const UsdAttribute &source=UsdAttribute());
/// \overload
USDSHADE_API
static bool CanConnect(const UsdShadeOutput &output,
const UsdShadeInput &sourceInput) {
return CanConnect(output, sourceInput.GetAttr());
}
/// \overload
USDSHADE_API
static bool CanConnect(const UsdShadeOutput &output,
const UsdShadeOutput &sourceOutput) {
return CanConnect(output, sourceOutput.GetAttr());
}
using ConnectionModification = UsdShadeConnectionModification;
/// Authors a connection for a given shading attribute \p shadingAttr.
///
/// \p shadingAttr can represent a parameter, an input or an output.
/// \p source is a struct that describes the upstream source attribute
/// with all the information necessary to make a connection. See the
/// documentation for UsdShadeConnectionSourceInfo.
/// \p mod describes the operation that should be applied to the list of
/// connections. By default the new connection will replace any existing
/// connections, but it can add to the list of connections to represent
/// multiple input connections.
///
/// \return
/// \c true if a connection was created successfully.
/// \c false if \p shadingAttr or \p source is invalid.
///
/// \note This method does not verify the connectability of the shading
/// attribute to the source. Clients must invoke CanConnect() themselves
/// to ensure compatibility.
/// \note The source shading attribute is created if it doesn't exist
/// already.
///
USDSHADE_API
static bool ConnectToSource(
UsdAttribute const &shadingAttr,
UsdShadeConnectionSourceInfo const &source,
ConnectionModification const mod = ConnectionModification::Replace);
/// \overload
USDSHADE_API
static bool ConnectToSource(
UsdShadeInput const &input,
UsdShadeConnectionSourceInfo const &source,
ConnectionModification const mod = ConnectionModification::Replace)
{
return ConnectToSource(input.GetAttr(), source, mod);
}
/// \overload
USDSHADE_API
static bool ConnectToSource(
UsdShadeOutput const &output,
UsdShadeConnectionSourceInfo const &source,
ConnectionModification const mod = ConnectionModification::Replace)
{
return ConnectToSource(output.GetAttr(), source, mod);
}
/// \deprecated Please use the versions that take a
/// UsdShadeConnectionSourceInfo to describe the upstream source
/// \overload
USDSHADE_API
static bool ConnectToSource(
UsdAttribute const &shadingAttr,
UsdShadeConnectableAPI const &source,
TfToken const &sourceName,
UsdShadeAttributeType const sourceType=UsdShadeAttributeType::Output,
SdfValueTypeName typeName=SdfValueTypeName());
/// \deprecated
/// \overload
USDSHADE_API
static bool ConnectToSource(
UsdShadeInput const &input,
UsdShadeConnectableAPI const &source,
TfToken const &sourceName,
UsdShadeAttributeType const sourceType=UsdShadeAttributeType::Output,
SdfValueTypeName typeName=SdfValueTypeName())
{
return ConnectToSource(input.GetAttr(), source, sourceName, sourceType,
typeName);
}
/// \deprecated
/// \overload
USDSHADE_API
static bool ConnectToSource(
UsdShadeOutput const &output,
UsdShadeConnectableAPI const &source,
TfToken const &sourceName,
UsdShadeAttributeType const sourceType=UsdShadeAttributeType::Output,
SdfValueTypeName typeName=SdfValueTypeName())
{
return ConnectToSource(output.GetAttr(), source, sourceName, sourceType,
typeName);
}
/// \overload
///
/// Connect the given shading attribute to the source at path, \p sourcePath.
///
/// \p sourcePath should be the fully namespaced property path.
///
/// This overload is provided for convenience, for use in contexts where
/// the prim types are unknown or unavailable.
///
USDSHADE_API
static bool ConnectToSource(UsdAttribute const &shadingAttr,
SdfPath const &sourcePath);
/// \overload
USDSHADE_API
static bool ConnectToSource(UsdShadeInput const &input,
SdfPath const &sourcePath) {
return ConnectToSource(input.GetAttr(), sourcePath);
}
/// \overload
USDSHADE_API
static bool ConnectToSource(UsdShadeOutput const &output,
SdfPath const &sourcePath) {
return ConnectToSource(output.GetAttr(), sourcePath);
}
/// \overload
///
/// Connect the given shading attribute to the given source input.
///
USDSHADE_API
static bool ConnectToSource(UsdAttribute const &shadingAttr,
UsdShadeInput const &sourceInput);
/// \overload
USDSHADE_API
static bool ConnectToSource(UsdShadeInput const &input,
UsdShadeInput const &sourceInput) {
return ConnectToSource(input.GetAttr(), sourceInput);
}
/// \overload
USDSHADE_API
static bool ConnectToSource(UsdShadeOutput const &output,
UsdShadeInput const &sourceInput) {
return ConnectToSource(output.GetAttr(), sourceInput);
}
/// \overload
///
/// Connect the given shading attribute to the given source output.
///
USDSHADE_API
static bool ConnectToSource(UsdAttribute const &shadingAttr,
UsdShadeOutput const &sourceOutput);
/// \overload
USDSHADE_API
static bool ConnectToSource(UsdShadeInput const &input,
UsdShadeOutput const &sourceOutput) {
return ConnectToSource(input.GetAttr(), sourceOutput);
}
/// \overload
USDSHADE_API
static bool ConnectToSource(UsdShadeOutput const &output,
UsdShadeOutput const &sourceOutput) {
return ConnectToSource(output.GetAttr(), sourceOutput);
}
/// Authors a list of connections for a given shading attribute
/// \p shadingAttr.
///
/// \p shadingAttr can represent a parameter, an input or an output.
/// \p sourceInfos is a vector of structs that describes the upstream source
/// attributes with all the information necessary to make all the
/// connections. See the documentation for UsdShadeConnectionSourceInfo.
///
/// \return
/// \c true if all connection were created successfully.
/// \c false if the \p shadingAttr or one of the sources are invalid.
///
/// \note A valid connection is one that has a valid
/// \p UsdShadeConnectionSourceInfo, which requires the existence of the
/// upstream source prim. It does not require the existence of the source
/// attribute as it will be create if necessary.
USDSHADE_API
static bool SetConnectedSources(
UsdAttribute const &shadingAttr,
std::vector<UsdShadeConnectionSourceInfo> const &sourceInfos);
/// \deprecated Shading attributes can have multiple connections and so
/// using GetConnectedSources is needed in general
///
/// Finds the source of a connection for the given shading attribute.
///
/// \p shadingAttr is the shading attribute whose connection we want to
/// interrogate.
/// \p source is an output parameter which will be set to the source
/// connectable prim.
/// \p sourceName will be set to the name of the source shading attribute,
/// which may be an input or an output, as specified by \p sourceType
/// \p sourceType will have the type of the source shading attribute, i.e.
/// whether it is an \c Input or \c Output
///
/// \return
/// \c true if the shading attribute is connected to a valid, defined source
/// attribute.
/// \c false if the shading attribute is not connected to a single, defined
/// source attribute.
///
/// \note Previously this method would silently return false for multiple
/// connections. We are changing the behavior of this method to return the
/// result for the first connection and issue a TfWarn about it. We want to
/// encourage clients to use GetConnectedSources going forward.
/// \note The python wrapping for this method returns a
/// (source, sourceName, sourceType) tuple if the parameter is connected,
/// else \c None
USDSHADE_API
static bool GetConnectedSource(UsdAttribute const &shadingAttr,
UsdShadeConnectableAPI *source,
TfToken *sourceName,
UsdShadeAttributeType *sourceType);
/// \deprecated
/// \overload
USDSHADE_API
static bool GetConnectedSource(UsdShadeInput const &input,
UsdShadeConnectableAPI *source,
TfToken *sourceName,
UsdShadeAttributeType *sourceType) {
return GetConnectedSource(input.GetAttr(), source, sourceName,
sourceType);
}
/// \deprecated
/// \overload
USDSHADE_API
static bool GetConnectedSource(UsdShadeOutput const &output,
UsdShadeConnectableAPI *source,
TfToken *sourceName,
UsdShadeAttributeType *sourceType) {
return GetConnectedSource(output.GetAttr(), source, sourceName,
sourceType);
}
/// Finds the valid sources of connections for the given shading attribute.
///
/// \p shadingAttr is the shading attribute whose connections we want to
/// interrogate.
/// \p invalidSourcePaths is an optional output parameter to collect the
/// invalid source paths that have not been reported in the returned vector.
///
/// Returns a vector of \p UsdShadeConnectionSourceInfo structs with
/// information about each upsteam attribute. If the vector is empty, there
/// have been no connections.
///
/// \note A valid connection requires the existence of the source attribute
/// and also requires that the source prim is UsdShadeConnectableAPI
/// compatible.
/// \note The python wrapping returns a tuple with the valid connections
/// first, followed by the invalid source paths.
USDSHADE_API
static UsdShadeSourceInfoVector GetConnectedSources(
UsdAttribute const &shadingAttr,
SdfPathVector *invalidSourcePaths = nullptr);
/// \overload
USDSHADE_API
static UsdShadeSourceInfoVector GetConnectedSources(
UsdShadeInput const &input,
SdfPathVector *invalidSourcePaths = nullptr);
/// \overload
USDSHADE_API
static UsdShadeSourceInfoVector GetConnectedSources(
UsdShadeOutput const &output,
SdfPathVector *invalidSourcePaths = nullptr);
/// \deprecated Please us GetConnectedSources to retrieve multiple
/// connections
///
/// Returns the "raw" (authored) connected source paths for the given
/// shading attribute.
USDSHADE_API
static bool GetRawConnectedSourcePaths(UsdAttribute const &shadingAttr,
SdfPathVector *sourcePaths);
/// \deprecated
/// \overload
USDSHADE_API
static bool GetRawConnectedSourcePaths(UsdShadeInput const &input,
SdfPathVector *sourcePaths) {
return GetRawConnectedSourcePaths(input.GetAttr(), sourcePaths);
}
/// \deprecated
/// \overload
USDSHADE_API
static bool GetRawConnectedSourcePaths(UsdShadeOutput const &output,
SdfPathVector *sourcePaths) {
return GetRawConnectedSourcePaths(output.GetAttr(), sourcePaths);
}
/// Returns true if and only if the shading attribute is currently connected
/// to at least one valid (defined) source.
///
/// If you will be calling GetConnectedSources() afterwards anyways,
/// it will be \em much faster to instead check if the returned vector is
/// empty:
/// \code
/// UsdShadeSourceInfoVector connections =
/// UsdShadeConnectableAPI::GetConnectedSources(attribute);
/// if (!connections.empty()){
/// // process connected attribute
/// } else {
/// // process unconnected attribute
/// }
/// \endcode
USDSHADE_API
static bool HasConnectedSource(const UsdAttribute &shadingAttr);
/// \overload
USDSHADE_API
static bool HasConnectedSource(const UsdShadeInput &input) {
return HasConnectedSource(input.GetAttr());
}
/// \overload
USDSHADE_API
static bool HasConnectedSource(const UsdShadeOutput &output) {
return HasConnectedSource(output.GetAttr());
}
/// Returns true if the connection to the given shading attribute's source,
/// as returned by UsdShadeConnectableAPI::GetConnectedSource(), is authored
/// across a specializes arc, which is used to denote a base material.
///
USDSHADE_API
static bool IsSourceConnectionFromBaseMaterial(
const UsdAttribute &shadingAttr);
/// \overload
USDSHADE_API
static bool IsSourceConnectionFromBaseMaterial(const UsdShadeInput &input) {
return IsSourceConnectionFromBaseMaterial(input.GetAttr());
}
/// \overload
USDSHADE_API
static bool IsSourceConnectionFromBaseMaterial(const UsdShadeOutput &output)
{
return IsSourceConnectionFromBaseMaterial(output.GetAttr());
}
/// Disconnect source for this shading attribute.
///
/// If \p sourceAttr is valid it will disconnect the connection to this
/// upstream attribute. Otherwise it will disconnect all connections by
/// authoring an empty list of connections for the attribute \p shadingAttr.
///
/// This may author more scene description than you might expect - we define
/// the behavior of disconnect to be that, even if a shading attribute
/// becomes connected in a weaker layer than the current UsdEditTarget, the
/// attribute will \em still be disconnected in the composition, therefore
/// we must "block" it in the current UsdEditTarget.
///
/// \sa ConnectToSource().
USDSHADE_API
static bool DisconnectSource(
UsdAttribute const &shadingAttr,
UsdAttribute const &sourceAttr = UsdAttribute());
/// \overload
USDSHADE_API
static bool DisconnectSource(
UsdShadeInput const &input,
UsdAttribute const &sourceAttr = UsdAttribute()) {
return DisconnectSource(input.GetAttr(), sourceAttr);
}
/// \overload
USDSHADE_API
static bool DisconnectSource(
UsdShadeOutput const &output,
UsdAttribute const &sourceAttr = UsdAttribute()) {
return DisconnectSource(output.GetAttr(), sourceAttr);
}
/// Clears sources for this shading attribute in the current UsdEditTarget.
///
/// Most of the time, what you probably want is DisconnectSource()
/// rather than this function.
///
/// \sa DisconnectSource()
USDSHADE_API
static bool ClearSources(UsdAttribute const &shadingAttr);
/// \overload
USDSHADE_API
static bool ClearSources(UsdShadeInput const &input) {
return ClearSources(input.GetAttr());
}
/// \overload
USDSHADE_API
static bool ClearSources(UsdShadeOutput const &output) {
return ClearSources(output.GetAttr());
}
/// \deprecated This is the older version that only referenced a single
/// source. Please use ClearSources instead.
USDSHADE_API
static bool ClearSource(UsdAttribute const &shadingAttr) {
return ClearSources(shadingAttr);
}
/// \deprecated
/// \overload
USDSHADE_API
static bool ClearSource(UsdShadeInput const &input) {
return ClearSources(input.GetAttr());
}
/// \deprecated
/// \overload
USDSHADE_API
static bool ClearSource(UsdShadeOutput const &output) {
return ClearSources(output.GetAttr());
}
/// Return true if the \p schemaType has a valid connectableAPIBehavior
/// registered, false otherwise.
/// To check if a prim's connectableAPI has a behavior defined, use
/// UsdSchemaBase::operator bool().
USDSHADE_API
static bool HasConnectableAPI(const TfType& schemaType);
/// Return true if the schema type \p T has a connectableAPIBehavior
/// registered, false otherwise.
template <typename T>
static bool HasConnectableAPI()
{
static_assert(std::is_base_of<UsdTyped, T>::value,
"Provided type must derive UsdTyped.");
return HasConnectableAPI(TfType::Find<T>());
};
/// @}
/// \name Outputs
/// @{
/// Create an output, which represents and externally computed, typed value.
/// Outputs on node-graphs can be connected.
///
/// The attribute representing an output is created in the "outputs:"
/// namespace.
///
USDSHADE_API
UsdShadeOutput CreateOutput(const TfToken& name,
const SdfValueTypeName& typeName) const;
/// Return the requested output if it exists.
///
/// \p name is the unnamespaced base name.
///
USDSHADE_API
UsdShadeOutput GetOutput(const TfToken &name) const;
/// Returns all outputs on the connectable prim (i.e. shader or node-graph).
/// Outputs are represented by attributes in the "outputs:" namespace.
/// If \p onlyAuthored is true (the default), then only return authored
/// attributes; otherwise, this also returns un-authored builtins.
///
USDSHADE_API
std::vector<UsdShadeOutput> GetOutputs(
bool onlyAuthored=true) const;
/// @}
/// \name Inputs
/// @{
/// Create an input which can both have a value and be connected.
/// The attribute representing the input is created in the "inputs:"
/// namespace.
///
USDSHADE_API
UsdShadeInput CreateInput(const TfToken& name,
const SdfValueTypeName& typeName) const;
/// Return the requested input if it exists.
///
/// \p name is the unnamespaced base name.
///
USDSHADE_API
UsdShadeInput GetInput(const TfToken &name) const;
/// Returns all inputs on the connectable prim (i.e. shader or node-graph).
/// Inputs are represented by attributes in the "inputs:" namespace.
/// If \p onlyAuthored is true (the default), then only return authored
/// attributes; otherwise, this also returns un-authored builtins.
///
USDSHADE_API
std::vector<UsdShadeInput> GetInputs(
bool onlyAuthored=true) const;
/// @}
};
/// A compact struct to represent a bundle of information about an upstream
/// source attribute
struct UsdShadeConnectionSourceInfo {
/// \p source is the connectable prim that produces or contains a value
/// for the given shading attribute.
UsdShadeConnectableAPI source;
/// \p sourceName is the name of the shading attribute that is the target
/// of the connection. This excludes any namespace prefix that determines
/// the type of the source (eg, output).
TfToken sourceName;
/// \p sourceType is used to indicate the type of the shading attribute
/// that is the target of the connection. The source type is used to
/// determine the namespace prefix that must be attached to \p sourceName
/// to determine the source full attribute name.
UsdShadeAttributeType sourceType = UsdShadeAttributeType::Invalid;
/// \p typeName, if specified, is the typename of the attribute to create
/// on the source if it doesn't exist when creating a connection
SdfValueTypeName typeName;
UsdShadeConnectionSourceInfo() = default;
explicit UsdShadeConnectionSourceInfo(
UsdShadeConnectableAPI const &source_,
TfToken const &sourceName_,
UsdShadeAttributeType sourceType_,
SdfValueTypeName typeName_ = SdfValueTypeName())
: source(source_)
, sourceName(sourceName_)
, sourceType(sourceType_)
, typeName(typeName_)
{}
explicit UsdShadeConnectionSourceInfo(UsdShadeInput const &input)
: source(input.GetPrim())
, sourceName(input.GetBaseName())
, sourceType(UsdShadeAttributeType::Input)
, typeName(input.GetAttr().GetTypeName())
{}
explicit UsdShadeConnectionSourceInfo(UsdShadeOutput const &output)
: source(output.GetPrim())
, sourceName(output.GetBaseName())
, sourceType(UsdShadeAttributeType::Output)
, typeName(output.GetAttr().GetTypeName())
{}
/// Construct the information for this struct from a property path. The
/// source attribute does not have to exist, but the \p sourcePath needs to
/// have a valid prefix to identify the sourceType. The source prim needs
/// to exist and be UsdShadeConnectableAPI compatible
USDSHADE_API
explicit UsdShadeConnectionSourceInfo(
UsdStagePtr const& stage,
SdfPath const& sourcePath);
/// Return true if this source info is valid for setting up a connection
bool IsValid() const {
// typeName can be invalid, so we don't check it. Order of checks is in
// order of cost (cheap to expensive).
// Note, for the source we only check that the prim is valid. We do not
// verify that the prim is compatibel with UsdShadeConnectableAPI. This
// makes it possible to target pure overs
return (sourceType != UsdShadeAttributeType::Invalid) &&
!sourceName.IsEmpty() &&
(bool)source.GetPrim();
}
explicit operator bool() const {
return IsValid();
}
bool operator==(UsdShadeConnectionSourceInfo const& other) const {
// We don't compare the typeName, since it is optional
return sourceName == other.sourceName &&
sourceType == other.sourceType &&
source.GetPrim() == other.source.GetPrim();
}
bool operator!=(const UsdShadeConnectionSourceInfo &other) const {
return !(*this == other);
}
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,225 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SHADE_CONNECTABLE_BEHAVIOR_H
#define PXR_USD_USD_SHADE_CONNECTABLE_BEHAVIOR_H
/// \file usdShade/connectableAPIBehavior.h
#include "pxr/pxr.h"
#include "pxr/usd/usdShade/api.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/vt/array.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class UsdAttribute;
class UsdShadeInput;
class UsdShadeOutput;
/// UsdShadeConnectableAPIBehavior defines the compatibilty and behavior
/// UsdShadeConnectableAPIof when applied to a particular prim type.
///
/// This enables schema libraries to enable UsdShadeConnectableAPI for
/// their prim types and define its behavior.
class UsdShadeConnectableAPIBehavior
{
public:
/// An enum describing the types of connectable nodes which will govern what
/// connectibility rule is invoked for these.
enum ConnectableNodeTypes
{
BasicNodes, // Shader, NodeGraph
DerivedContainerNodes, // Material, etc
};
// By default we want a connectableBehavior to not exhibit a container like
// behavior. And we want encapsulation behavior enabled by default.
USDSHADE_API
UsdShadeConnectableAPIBehavior()
: _isContainer(false), _requiresEncapsulation(true) {}
USDSHADE_API
UsdShadeConnectableAPIBehavior(const bool isContainer,
const bool requiresEncapsulation)
: _isContainer(isContainer),
_requiresEncapsulation(requiresEncapsulation) {}
USDSHADE_API
virtual ~UsdShadeConnectableAPIBehavior();
/// The prim owning the input is guaranteed to be of the type this
/// behavior was registered with. The function must be thread-safe.
///
/// It should return true if the connection is allowed, false
/// otherwise. If the connection is prohibited and \p reason is
/// non-NULL, it should be set to a user-facing description of the
/// reason the connection is prohibited.
///
/// The base implementation checks that the input is defined; that
/// the source attribute exists; and that the connectability metadata
/// on the input allows a connection from the attribute -- see
/// UsdShadeInput::GetConnectability().
///
USDSHADE_API
virtual bool
CanConnectInputToSource(const UsdShadeInput &,
const UsdAttribute &,
std::string *reason) const;
/// The prim owning the output is guaranteed to be of the type this
/// behavior was registered with. The function must be thread-safe.
///
/// It should return true if the connection is allowed, false
/// otherwise. If the connection is prohibited and \p reason is
/// non-NULL, it should be set to a user-facing description of the
/// reason the connection is prohibited.
///
/// The base implementation returns false. Outputs of most prim
/// types will be defined by the underlying node definition (see
/// UsdShadeNodeDefAPI), not a connection.
///
USDSHADE_API
virtual bool
CanConnectOutputToSource(const UsdShadeOutput &,
const UsdAttribute &,
std::string *reason) const;
/// The function must be thread-safe.
///
/// It should return true if the associated prim type is considered
/// a "container" for connected nodes.
/// Returns the value set for _isContainer.
USDSHADE_API
virtual bool
IsContainer() const final;
/// The function must be thread-safe.
///
/// Determines if the behavior should respect container encapsulation rules
/// (\ref UsdShadeConnectability), when evaluating CanConnectInputToSource
/// or CanConnectOutputToSource. This should return true if the container
/// encapsulation rules need to be respected, false otherwise.
//
/// Returns the value set for _requiresEncapsulation.
///
/// \sa IsContainer()
///
USDSHADE_API
virtual bool
RequiresEncapsulation() const final;
protected:
/// Helper function to separate and share special connectivity logic for
/// specialized, NodeGraph-derived nodes, like Material (and other in other
/// domains) that allow their inputs to be connected to an output of a
/// source that they directly contain/encapsulate. The default behavior is
/// for Shader Nodes or NodeGraphs which allow their input connections to
/// output of a sibling source, both encapsulated by the same container
/// node.
USDSHADE_API
bool _CanConnectInputToSource(const UsdShadeInput&, const UsdAttribute&,
std::string *reason,
ConnectableNodeTypes nodeType =
ConnectableNodeTypes::BasicNodes) const;
USDSHADE_API
bool _CanConnectOutputToSource(const UsdShadeOutput&, const UsdAttribute&,
std::string *reason,
ConnectableNodeTypes nodeType =
ConnectableNodeTypes::BasicNodes) const;
private:
bool _isContainer;
bool _requiresEncapsulation;
};
/// Registers \p behavior to define connectability of attributes for \p PrimType.
///
/// Plugins should call this function in a TF_REGISTRY_FUNCTION. For example:
///
/// \code
/// class MyBehavior : public UsdShadeConnectableAPIBehavior { ... }
///
/// TF_REGISTRY_FUNCTION(UsdShadeConnectableAPI)
/// {
/// UsdShadeRegisterConnectableAPIBehavior<MyPrim, MyBehavior>();
/// }
/// \endcode
///
/// Plugins must also note that UsdShadeConnectableAPI behavior is implemented
/// for a prim type in that type's schema definnition. For example:
///
/// \code
/// class "MyPrim" (
/// ...
/// customData = {
/// dictionary extraPlugInfo = {
/// bool providesUsdShadeConnectableAPIBehavior = true
/// }
/// }
/// ...
/// )
/// { ... }
/// \endcode
///
/// This allows the plugin system to discover this behavior dynamically
/// and load the plugin if needed.
///
/// In addition to Typed schemas, single apply API schemas can also include
/// **providesUsdShadeConnectableAPIBehavior** in their **extraPlugInfo** and
/// hence impart connectableAPIBehavior to the prim definition in which they
/// are participating. Additionally a schema can include metadata in their
/// extraPlugInfo fields to override isContainer and requiresEncapsulation
/// properties by specifying bool values for **isUsdShadeContainer** and
/// **requiresUsdShadeEncapsulation**. This can be especially useful for
/// \ref codeless_schema that cannot provide a C++ derivation of
/// UsdShadeConnectableAPIBehavior.
///
/// \ref UsdShadeConnectableAPIBehavior_ResolutionOrder defines the
/// resolution order when multiple types and apiSchemas provide a
/// UsdShadeConnectableAPIBehavior.
///
template <class PrimType, class BehaviorType = UsdShadeConnectableAPIBehavior>
inline void
UsdShadeRegisterConnectableAPIBehavior()
{
UsdShadeRegisterConnectableAPIBehavior(
TfType::Find<PrimType>(),
std::shared_ptr<UsdShadeConnectableAPIBehavior>(new BehaviorType));
}
/// Registers \p behavior to define connectability of attributes for
/// \p PrimType.
USDSHADE_API
void
UsdShadeRegisterConnectableAPIBehavior(
const TfType& connectablePrimType,
const std::shared_ptr<UsdShadeConnectableAPIBehavior>& behavior);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_USD_SHADE_CONNECTABLE_BEHAVIOR_H
+231
View File
@@ -0,0 +1,231 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSHADE_GENERATED_COORDSYSAPI_H
#define USDSHADE_GENERATED_COORDSYSAPI_H
/// \file usdShade/coordSysAPI.h
#include "pxr/pxr.h"
#include "pxr/usd/usdShade/api.h"
#include "pxr/usd/usd/apiSchemaBase.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usdShade/tokens.h"
#include "pxr/usd/usdGeom/xformable.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class SdfAssetPath;
// -------------------------------------------------------------------------- //
// COORDSYSAPI //
// -------------------------------------------------------------------------- //
/// \class UsdShadeCoordSysAPI
///
/// UsdShadeCoordSysAPI provides a way to designate, name,
/// and discover coordinate systems.
///
/// Coordinate systems are implicitly established by UsdGeomXformable
/// prims, using their local space. That coordinate system may be
/// bound (i.e., named) from another prim. The binding is encoded
/// as a single-target relationship in the "coordSys:" namespace.
/// Coordinate system bindings apply to descendants of the prim
/// where the binding is expressed, but names may be re-bound by
/// descendant prims.
///
/// Named coordinate systems are useful in shading workflows.
/// An example is projection paint, which projects a texture
/// from a certain view (the paint coordinate system). Using
/// the paint coordinate frame avoids the need to assign a UV
/// set to the object, and can be a concise way to project
/// paint across a collection of objects with a single shared
/// paint coordinate system.
///
/// This is a non-applied API schema.
///
///
class UsdShadeCoordSysAPI : public UsdAPISchemaBase
{
public:
/// Compile time constant representing what kind of schema this class is.
///
/// \sa UsdSchemaKind
static const UsdSchemaKind schemaKind = UsdSchemaKind::NonAppliedAPI;
/// Construct a UsdShadeCoordSysAPI on UsdPrim \p prim .
/// Equivalent to UsdShadeCoordSysAPI::Get(prim.GetStage(), prim.GetPath())
/// for a \em valid \p prim, but will not immediately throw an error for
/// an invalid \p prim
explicit UsdShadeCoordSysAPI(const UsdPrim& prim=UsdPrim())
: UsdAPISchemaBase(prim)
{
}
/// Construct a UsdShadeCoordSysAPI on the prim held by \p schemaObj .
/// Should be preferred over UsdShadeCoordSysAPI(schemaObj.GetPrim()),
/// as it preserves SchemaBase state.
explicit UsdShadeCoordSysAPI(const UsdSchemaBase& schemaObj)
: UsdAPISchemaBase(schemaObj)
{
}
/// Destructor.
USDSHADE_API
virtual ~UsdShadeCoordSysAPI();
/// 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.
USDSHADE_API
static const TfTokenVector &
GetSchemaAttributeNames(bool includeInherited=true);
/// Return a UsdShadeCoordSysAPI holding the prim adhering to this
/// schema at \p path on \p stage. If no prim exists at \p path on
/// \p 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:
///
/// \code
/// UsdShadeCoordSysAPI(stage->GetPrimAtPath(path));
/// \endcode
///
USDSHADE_API
static UsdShadeCoordSysAPI
Get(const UsdStagePtr &stage, const SdfPath &path);
protected:
/// Returns the kind of schema this class belongs to.
///
/// \sa UsdSchemaKind
USDSHADE_API
UsdSchemaKind _GetSchemaKind() const override;
private:
// needs to invoke _GetStaticTfType.
friend class UsdSchemaRegistry;
USDSHADE_API
static const TfType &_GetStaticTfType();
static bool _IsTypedSchema();
// override SchemaBase virtuals.
USDSHADE_API
const TfType &_GetTfType() const override;
public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
// the code generator.
//
// Just remember to:
// - Close the class declaration with };
// - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
// - Close the include guard with #endif
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
/// A coordinate system binding.
/// Binds a name to a coordSysPrim for the bindingPrim
/// (and its descendants, unless overriden).
typedef struct {
TfToken name;
SdfPath bindingRelPath;
SdfPath coordSysPrimPath;
} Binding;
/// Returns true if the prim has local coordinate system binding
/// opinions. Note that the resulting binding list may still be
/// empty.
USDSHADE_API
bool HasLocalBindings() const;
/// Get the list of coordinate system bindings local to this prim.
/// This does not process inherited bindings. It does not
/// validate that a prim exists at the indicated path.
/// If the binding relationship has multiple targets,
/// only the first is used.
USDSHADE_API
std::vector<Binding> GetLocalBindings() const;
/// Find the list of coordinate system bindings that apply
/// to this prim, including inherited bindings.
///
/// This computation examines this prim and ancestors for
/// the strongest binding for each name. A binding expressed by
/// a child prim supercedes bindings on ancestors.
///
/// Note that this API does not validate the prims at the
/// target paths; they may be of incorrect type, or missing
/// entirely.
///
/// Binding relationships with no resolved targets are skipped.
USDSHADE_API
std::vector<Binding> FindBindingsWithInheritance() const;
/// Bind the name to the given path.
/// The prim at the given path is expected to be UsdGeomXformable,
/// in order for the binding to be succesfully resolved.
USDSHADE_API
bool Bind(const TfToken &name, const SdfPath &path) const;
/// Clear the indicated coordinate system binding on this prim
/// from the current edit target.
///
/// Only remove the spec if \p removeSpec is true (leave the spec to
/// preserve meta-data we may have intentionally authored on the
/// relationship)
USDSHADE_API
bool ClearBinding(const TfToken &name, bool removeSpec) const;
/// Block the indicated coordinate system binding on this prim
/// by blocking targets on the underlying relationship.
USDSHADE_API
bool BlockBinding(const TfToken &name) const;
/// Returns the fully namespaced coordinate system relationship
/// name, given the coordinate system name.
USDSHADE_API
static TfToken GetCoordSysRelationshipName(const std::string &coordSysName);
/// Test whether a given \p name contains the "coordSys:" prefix
///
USDSHADE_API
static bool CanContainPropertyName(const TfToken &name);
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+527
View File
@@ -0,0 +1,527 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SHADE_INPUT_H
#define PXR_USD_USD_SHADE_INPUT_H
#include "pxr/pxr.h"
#include "pxr/usd/usdShade/api.h"
#include "pxr/usd/usdShade/types.h"
#include "pxr/usd/usdShade/utils.h"
#include "pxr/usd/usd/attribute.h"
#include "pxr/usd/ndr/declare.h"
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
class UsdShadeConnectableAPI;
struct UsdShadeConnectionSourceInfo;
class UsdShadeOutput;
/// \class UsdShadeInput
///
/// This class encapsulates a shader or node-graph input, which is a
/// connectable attribute representing a typed value.
///
class UsdShadeInput
{
public:
/// Default constructor returns an invalid Input. Exists for the sake of
/// container classes
UsdShadeInput()
{
// nothing
}
/// Get the name of the attribute associated with the Input.
///
TfToken const &GetFullName() const {
return _attr.GetName();
}
/// Returns the name of the input.
///
/// We call this the base name since it strips off the "inputs:" namespace
/// prefix from the attribute name, and returns it.
///
USDSHADE_API
TfToken GetBaseName() const;
/// Get the "scene description" value type name of the attribute associated
/// with the Input.
///
USDSHADE_API
SdfValueTypeName GetTypeName() const;
/// Get the prim that the input belongs to.
UsdPrim GetPrim() const {
return _attr.GetPrim();
}
/// Convenience wrapper for the templated UsdAttribute::Get().
template <typename T>
bool Get(T* value, UsdTimeCode time = UsdTimeCode::Default()) const {
return GetAttr().Get(value, time);
}
/// Convenience wrapper for VtValue version of UsdAttribute::Get().
USDSHADE_API
bool Get(VtValue* value, UsdTimeCode time = UsdTimeCode::Default()) const;
/// Set a value for the Input at \p time.
///
USDSHADE_API
bool Set(const VtValue& value,
UsdTimeCode time = UsdTimeCode::Default()) const;
/// \overload
/// Set a value of the Input at \p time.
///
template <typename T>
bool Set(const T& value, UsdTimeCode time = UsdTimeCode::Default()) const {
return _attr.Set(value, time);
}
/// Hash functor.
struct Hash {
inline size_t operator()(const UsdShadeInput &input) const {
return hash_value(input._attr);
}
};
/// \name Configuring the Input's Type
/// @{
/// Specify an alternative, renderer-specific type to use when
/// emitting/translating this Input, rather than translating based
/// on its GetTypeName()
///
/// For example, we set the renderType to "struct" for Inputs that
/// are of renderman custom struct types.
///
/// \return true on success.
///
USDSHADE_API
bool SetRenderType(TfToken const& renderType) const;
/// Return this Input's specialized renderType, or an empty
/// token if none was authored.
///
/// \sa SetRenderType()
USDSHADE_API
TfToken GetRenderType() const;
/// Return true if a renderType has been specified for this Input.
///
/// \sa SetRenderType()
USDSHADE_API
bool HasRenderType() const;
/// @}
/// \name API to author and query an Input's sdrMetadata
///
/// This section provides API for authoring and querying shader registry
/// metadata on an Input. When the owning shader prim is providing a shader
/// definition, the authored "sdrMetadata" dictionary value provides
/// metadata needed to populate the Input correctly in the shader registry.
///
/// We expect the keys in sdrMetadata to correspond to the keys
/// in \ref SdrPropertyMetadata. However, this is not strictly enforced by
/// the API. The only allowed value type in the "sdrMetadata" dictionary is
/// a std::string since it needs to be converted into a NdrTokenMap, which
/// Sdr will parse using the utilities available in \ref SdrMetadataHelpers.
///
/// @{
/// Returns this Input's composed "sdrMetadata" dictionary as a
/// NdrTokenMap.
USDSHADE_API
NdrTokenMap GetSdrMetadata() const;
/// Returns the value corresponding to \p key in the composed
/// <b>sdrMetadata</b> dictionary.
USDSHADE_API
std::string GetSdrMetadataByKey(const TfToken &key) const;
/// Authors the given \p sdrMetadata value on this Input at the current
/// EditTarget.
USDSHADE_API
void SetSdrMetadata(const NdrTokenMap &sdrMetadata) const;
/// Sets the value corresponding to \p key to the given string \p value, in
/// the Input's "sdrMetadata" dictionary at the current EditTarget.
USDSHADE_API
void SetSdrMetadataByKey(
const TfToken &key,
const std::string &value) const;
/// Returns true if the Input has a non-empty composed "sdrMetadata"
/// dictionary value.
USDSHADE_API
bool HasSdrMetadata() const;
/// Returns true if there is a value corresponding to the given \p key in
/// the composed "sdrMetadata" dictionary.
USDSHADE_API
bool HasSdrMetadataByKey(const TfToken &key) const;
/// Clears any "sdrMetadata" value authored on the Input in the current
/// EditTarget.
USDSHADE_API
void ClearSdrMetadata() const;
/// Clears the entry corresponding to the given \p key in the
/// "sdrMetadata" dictionary authored in the current EditTarget.
USDSHADE_API
void ClearSdrMetadataByKey(const TfToken &key) const;
/// @}
// ---------------------------------------------------------------
/// \name UsdAttribute API
// ---------------------------------------------------------------
/// @{
/// Speculative constructor that will produce a valid UsdShadeInput when
/// \p attr already represents a shade Input, and produces an \em invalid
/// UsdShadeInput otherwise (i.e. the explicit bool conversion operator will
/// return false).
USDSHADE_API
explicit UsdShadeInput(const UsdAttribute &attr);
/// Test whether a given UsdAttribute represents a valid Input, which
/// implies that creating a UsdShadeInput from the attribute will succeed.
///
/// Success implies that \c attr.IsDefined() is true.
USDSHADE_API
static bool IsInput(const UsdAttribute &attr);
/// Test if this name has a namespace that indicates it could be an
/// input.
USDSHADE_API
static bool IsInterfaceInputName(const std::string & name);
/// Explicit UsdAttribute extractor.
const UsdAttribute &GetAttr() const { return _attr; }
/// Allow UsdShadeInput to auto-convert to UsdAttribute, so you can
/// pass a UsdShadeInput to any function that accepts a UsdAttribute or
/// const-ref thereto.
operator const UsdAttribute & () const { return GetAttr(); }
/// Return true if the wrapped UsdAttribute is defined, and in addition the
/// attribute is identified as an input.
bool IsDefined() const {
return _attr && IsInput(_attr);
}
/// Set documentation string for this Input.
/// \sa UsdObject::SetDocumentation()
USDSHADE_API
bool SetDocumentation(const std::string& docs) const;
/// Get documentation string for this Input.
/// \sa UsdObject::GetDocumentation()
USDSHADE_API
std::string GetDocumentation() const;
/// Set the displayGroup metadata for this Input, i.e. hinting for the
/// location and nesting of the attribute.
/// \sa UsdProperty::SetDisplayGroup(), UsdProperty::SetNestedDisplayGroup()
USDSHADE_API
bool SetDisplayGroup(const std::string& displayGroup) const;
/// Get the displayGroup metadata for this Input, i.e. hint for the location
/// and nesting of the attribute.
/// \sa UsdProperty::GetDisplayGroup(), UsdProperty::GetNestedDisplayGroup()
USDSHADE_API
std::string GetDisplayGroup() const;
/// @}
/// Return true if this Input is valid for querying and authoring
/// values and metadata, which is identically equivalent to IsDefined().
explicit operator bool() const {
return IsDefined();
}
/// Equality comparison. Returns true if \a lhs and \a rhs represent the
/// same UsdShadeInput, false otherwise.
friend bool operator==(const UsdShadeInput &lhs, const UsdShadeInput &rhs) {
return lhs.GetAttr() == rhs.GetAttr();
}
/// Inequality comparison. Return false if \a lhs and \a rhs represent the
/// same UsdShadeInput, true otherwise.
friend bool operator!=(const UsdShadeInput &lhs, const UsdShadeInput &rhs) {
return !(lhs == rhs);
}
// -------------------------------------------------------------------------
/// \name Connections API
// -------------------------------------------------------------------------
/// @{
/// Determines whether this Input can be connected to the given
/// source attribute, which can be an input or an output.
///
/// \sa UsdShadeConnectableAPI::CanConnect
USDSHADE_API
bool CanConnect(const UsdAttribute &source) const;
/// \overload
USDSHADE_API
bool CanConnect(const UsdShadeInput &sourceInput) const;
/// \overload
USDSHADE_API
bool CanConnect(const UsdShadeOutput &sourceOutput) const;
using ConnectionModification = UsdShadeConnectionModification;
/// Authors a connection for this Input
///
/// \p source is a struct that describes the upstream source attribute
/// with all the information necessary to make a connection. See the
/// documentation for UsdShadeConnectionSourceInfo.
/// \p mod describes the operation that should be applied to the list of
/// connections. By default the new connection will replace any existing
/// connections, but it can add to the list of connections to represent
/// multiple input connections.
///
/// \return
/// \c true if a connection was created successfully.
/// \c false if this input or \p source is invalid.
///
/// \note This method does not verify the connectability of the shading
/// attribute to the source. Clients must invoke CanConnect() themselves
/// to ensure compatibility.
/// \note The source shading attribute is created if it doesn't exist
/// already.
///
/// \sa UsdShadeConnectableAPI::ConnectToSource
///
USDSHADE_API
bool ConnectToSource(
UsdShadeConnectionSourceInfo const &source,
ConnectionModification const mod =
ConnectionModification::Replace) const;
/// \deprecated
/// \overload
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 at the given path.
///
/// \sa UsdShadeConnectableAPI::ConnectToSource
///
USDSHADE_API
bool ConnectToSource(SdfPath const &sourcePath) const;
/// Connects this Input to the given input, \p sourceInput.
///
/// \sa UsdShadeConnectableAPI::ConnectToSource
///
USDSHADE_API
bool ConnectToSource(UsdShadeInput const &sourceInput) const;
/// Connects this Input to the given output, \p sourceOutput.
///
/// \sa UsdShadeConnectableAPI::ConnectToSource
///
USDSHADE_API
bool ConnectToSource(UsdShadeOutput const &sourceOutput) const;
/// Connects this Input to the given sources, \p sourceInfos
///
/// \sa UsdShadeConnectableAPI::SetConnectedSources
///
USDSHADE_API
bool SetConnectedSources(
std::vector<UsdShadeConnectionSourceInfo> const &sourceInfos) const;
using SourceInfoVector = TfSmallVector<UsdShadeConnectionSourceInfo, 1>;
/// Finds the valid sources of connections for the Input.
///
/// \p invalidSourcePaths is an optional output parameter to collect the
/// invalid source paths that have not been reported in the returned vector.
///
/// Returns a vector of \p UsdShadeConnectionSourceInfo structs with
/// information about each upsteam attribute. If the vector is empty, there
/// have been no valid connections.
///
/// \note A valid connection requires the existence of the source attribute
/// and also requires that the source prim is UsdShadeConnectableAPI
/// compatible.
/// \note The python wrapping returns a tuple with the valid connections
/// first, followed by the invalid source paths.
///
/// \sa UsdShadeConnectableAPI::GetConnectedSources
///
USDSHADE_API
SourceInfoVector GetConnectedSources(
SdfPathVector *invalidSourcePaths = nullptr) const;
/// \deprecated
USDSHADE_API
bool GetConnectedSource(UsdShadeConnectableAPI *source,
TfToken *sourceName,
UsdShadeAttributeType *sourceType) const;
/// \deprecated
/// Returns the "raw" (authored) connected source paths for this Input.
///
/// \sa UsdShadeConnectableAPI::GetRawConnectedSourcePaths
///
USDSHADE_API
bool GetRawConnectedSourcePaths(SdfPathVector *sourcePaths) const;
/// Returns true if and only if this Input is currently connected to a
/// valid (defined) source.
///
/// \sa UsdShadeConnectableAPI::HasConnectedSource
///
USDSHADE_API
bool HasConnectedSource() const;
/// Returns true if the connection to this Input's source, as returned by
/// GetConnectedSource(), is authored across a specializes arc, which is
/// used to denote a base material.
///
/// \sa UsdShadeConnectableAPI::IsSourceConnectionFromBaseMaterial
///
USDSHADE_API
bool IsSourceConnectionFromBaseMaterial() const;
/// Disconnect source for this Input. If \p sourceAttr is valid, only a
/// connection to the specified attribute is disconnected, otherwise all
/// connections are removed.
///
/// \sa UsdShadeConnectableAPI::DisconnectSource
///
USDSHADE_API
bool DisconnectSource(UsdAttribute const &sourceAttr = UsdAttribute()) const;
/// Clears sources for this Input in the current UsdEditTarget.
///
/// Most of the time, what you probably want is DisconnectSource()
/// rather than this function.
///
/// \sa UsdShadeConnectableAPI::ClearSources
///
USDSHADE_API
bool ClearSources() const;
/// \deprecated
USDSHADE_API
bool ClearSource() const;
/// @}
// -------------------------------------------------------------------------
/// \name Connectability API
// -------------------------------------------------------------------------
/// @{
/// \brief Set the connectability of the Input.
///
/// In certain shading data models, there is a need to distinguish which
/// inputs <b>can</b> vary over a surface from those that must be
/// <b>uniform</b>. This is accomplished in UsdShade by limiting the
/// connectability of the input. This is done by setting the
/// "connectability" metadata on the associated attribute.
///
/// Connectability of an Input can be set to UsdShadeTokens->full or
/// UsdShadeTokens->interfaceOnly.
///
/// \li <b>full</b> implies that the Input can be connected to any other
/// Input or Output.
/// \li <b>interfaceOnly</b> implies that the Input can only be connected to
/// a NodeGraph Input (which represents an interface override, not a
/// render-time dataflow connection), or another Input whose connectability
/// is also "interfaceOnly".
///
/// The default connectability of an input is UsdShadeTokens->full.
///
/// \sa SetConnectability()
USDSHADE_API
bool SetConnectability(const TfToken &connectability) const;
/// \brief Returns the connectability of the Input.
///
/// \sa SetConnectability()
USDSHADE_API
TfToken GetConnectability() const;
/// \brief Clears any authored connectability on the Input.
///
USDSHADE_API
bool ClearConnectability() const;
/// @}
// -------------------------------------------------------------------------
/// \name Connected Value API
// -------------------------------------------------------------------------
/// @{
/// \brief Find what is connected to this Input recursively
///
/// \sa UsdShadeUtils::GetValueProducingAttributes
USDSHADE_API
UsdShadeAttributeVector GetValueProducingAttributes(
bool shaderOutputsOnly = false) const;
/// \deprecated in favor of calling GetValueProducingAttributes
USDSHADE_API
UsdAttribute GetValueProducingAttribute(
UsdShadeAttributeType* attrType) const;
/// @}
private:
friend class UsdShadeConnectableAPI;
// Constructor that creates a UsdShadeInput with the given name on the
// given prim.
// \p name here is the unnamespaced name of the input.
UsdShadeInput(UsdPrim prim,
TfToken const &name,
SdfValueTypeName const &typeName);
UsdAttribute _attr;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_USD_SHADE_INPUT_H
+701
View File
@@ -0,0 +1,701 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSHADE_GENERATED_MATERIAL_H
#define USDSHADE_GENERATED_MATERIAL_H
/// \file usdShade/material.h
#include "pxr/pxr.h"
#include "pxr/usd/usdShade/api.h"
#include "pxr/usd/usdShade/nodeGraph.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usdShade/tokens.h"
#include "pxr/usd/usd/variantSets.h"
#include "pxr/usd/usdGeom/subset.h"
#include "pxr/usd/usdShade/connectableAPI.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class SdfAssetPath;
// -------------------------------------------------------------------------- //
// MATERIAL //
// -------------------------------------------------------------------------- //
/// \class UsdShadeMaterial
///
/// A Material provides a container into which multiple "render targets"
/// can add data that defines a "shading material" for a renderer. Typically
/// this consists of one or more UsdRelationship properties that target
/// other prims of type \em Shader - though a target/client is free to add
/// any data that is suitable. We <b>strongly advise</b> that all targets
/// adopt the convention that all properties be prefixed with a namespace
/// that identifies the target, e.g. "rel ri:surface = </Shaders/mySurf>".
///
/// ## Binding Materials
///
/// In the UsdShading model, geometry expresses a binding to a single Material or
/// to a set of Materials partitioned by UsdGeomSubsets defined beneath the
/// geometry; it is legal to bind a Material at the root (or other sub-prim) of
/// a model, and then bind a different Material to individual gprims, but the
/// meaning of inheritance and "ancestral overriding" of Material bindings is
/// left to each render-target to determine. Since UsdGeom has no concept of
/// shading, we provide the API for binding and unbinding geometry on the API
/// schema UsdShadeMaterialBindingAPI.
///
/// ## Material Variation
///
/// The entire power of USD VariantSets and all the other composition
/// operators can leveraged when encoding shading variation.
/// UsdShadeMaterial provides facilities for a particular way of building
/// "Material variants" in which neither the identity of the Materials themselves
/// nor the geometry Material-bindings need to change - instead we vary the
/// targeted networks, interface values, and even parameter values within
/// a single variantSet.
/// See \ref UsdShadeMaterial_Variations "Authoring Material Variations"
/// for more details.
///
/// ## Materials Encapsulate their Networks in Namespace
///
/// UsdShade requires that all of the shaders that "belong" to the Material
/// live under the Material in namespace. This supports powerful, easy reuse
/// of Materials, because it allows us to *reference* a Material from one
/// asset (the asset might be a library of Materials) into another asset: USD
/// references compose all descendant prims of the reference target into the
/// referencer's namespace, which means that all of the referenced Material's
/// shader networks will come along with the Material. When referenced in this
/// way, Materials can also be [instanced](http://openusd.org/docs/USD-Glossary.html#USDGlossary-Instancing), for ease of deduplication and compactness.
/// Finally, Material encapsulation also allows us to
/// \ref UsdShadeMaterial_BaseMaterial "specialize" child materials from
/// parent materials.
///
///
///
/// For any described attribute \em Fallback \em Value or \em Allowed \em Values below
/// that are text/tokens, the actual token is published and defined in \ref UsdShadeTokens.
/// So to set an attribute to the value "rightHanded", use UsdShadeTokens->rightHanded
/// as the value.
///
class UsdShadeMaterial : public UsdShadeNodeGraph
{
public:
/// Compile time constant representing what kind of schema this class is.
///
/// \sa UsdSchemaKind
static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped;
/// Construct a UsdShadeMaterial on UsdPrim \p prim .
/// Equivalent to UsdShadeMaterial::Get(prim.GetStage(), prim.GetPath())
/// for a \em valid \p prim, but will not immediately throw an error for
/// an invalid \p prim
explicit UsdShadeMaterial(const UsdPrim& prim=UsdPrim())
: UsdShadeNodeGraph(prim)
{
}
/// Construct a UsdShadeMaterial on the prim held by \p schemaObj .
/// Should be preferred over UsdShadeMaterial(schemaObj.GetPrim()),
/// as it preserves SchemaBase state.
explicit UsdShadeMaterial(const UsdSchemaBase& schemaObj)
: UsdShadeNodeGraph(schemaObj)
{
}
/// Destructor.
USDSHADE_API
virtual ~UsdShadeMaterial();
/// 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.
USDSHADE_API
static const TfTokenVector &
GetSchemaAttributeNames(bool includeInherited=true);
/// Return a UsdShadeMaterial holding the prim adhering to this
/// schema at \p path on \p stage. If no prim exists at \p path on
/// \p 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:
///
/// \code
/// UsdShadeMaterial(stage->GetPrimAtPath(path));
/// \endcode
///
USDSHADE_API
static UsdShadeMaterial
Get(const UsdStagePtr &stage, const SdfPath &path);
/// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
/// is defined (according to UsdPrim::IsDefined()) on this stage.
///
/// If a prim adhering to this schema at \p path is already defined on this
/// stage, return that prim. Otherwise author an \a SdfPrimSpec with
/// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
/// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
/// with \p specifier == \a SdfSpecifierDef and empty typeName at the
/// current EditTarget for any nonexistent, or existing but not \a Defined
/// ancestors.
///
/// The given \a path must be an absolute prim path that does not contain
/// any variant selections.
///
/// If it is impossible to author any of the necessary PrimSpecs, (for
/// example, in case \a path cannot map to the current UsdEditTarget's
/// namespace) issue an error and return an invalid \a UsdPrim.
///
/// Note that this method may return a defined prim whose typeName does not
/// specify this schema class, in case a stronger typeName opinion overrides
/// the opinion at the current EditTarget.
///
USDSHADE_API
static UsdShadeMaterial
Define(const UsdStagePtr &stage, const SdfPath &path);
protected:
/// Returns the kind of schema this class belongs to.
///
/// \sa UsdSchemaKind
USDSHADE_API
UsdSchemaKind _GetSchemaKind() const override;
private:
// needs to invoke _GetStaticTfType.
friend class UsdSchemaRegistry;
USDSHADE_API
static const TfType &_GetStaticTfType();
static bool _IsTypedSchema();
// override SchemaBase virtuals.
USDSHADE_API
const TfType &_GetTfType() const override;
public:
// --------------------------------------------------------------------- //
// SURFACE
// --------------------------------------------------------------------- //
/// Represents the universal "surface" output terminal of a
/// material.
///
/// | ||
/// | -- | -- |
/// | Declaration | `token outputs:surface` |
/// | C++ Type | TfToken |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
USDSHADE_API
UsdAttribute GetSurfaceAttr() const;
/// See GetSurfaceAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSHADE_API
UsdAttribute CreateSurfaceAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// DISPLACEMENT
// --------------------------------------------------------------------- //
/// Represents the universal "displacement" output terminal of a
/// material.
///
/// | ||
/// | -- | -- |
/// | Declaration | `token outputs:displacement` |
/// | C++ Type | TfToken |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
USDSHADE_API
UsdAttribute GetDisplacementAttr() const;
/// See GetDisplacementAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSHADE_API
UsdAttribute CreateDisplacementAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// VOLUME
// --------------------------------------------------------------------- //
/// Represents the universal "volume" output terminal of a
/// material.
///
/// | ||
/// | -- | -- |
/// | Declaration | `token outputs:volume` |
/// | C++ Type | TfToken |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
USDSHADE_API
UsdAttribute GetVolumeAttr() const;
/// See GetVolumeAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSHADE_API
UsdAttribute CreateVolumeAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
// the code generator.
//
// Just remember to:
// - Close the class declaration with };
// - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
// - Close the include guard with #endif
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
// --------------------------------------------------------------------- //
/// \name Helpful Types
/// @{
// --------------------------------------------------------------------- //
/// A function type that takes a path and returns a bool.
typedef std::function<bool (const SdfPath &)> PathPredicate;
/// @}
// --------------------------------------------------------------------- //
/// \anchor UsdShadeMaterial_Outputs
/// \name Standard Material Terminal Outputs
/// A UsdShadeMaterial can have any number of "terminal" outputs. These
/// outputs are generally used to point to outputs of shader prims or
/// NodeGraphs that describe certain properties of the material that a
/// renderer might wish to consume. There are three standard output
/// terminals that are supported by the core API: <b>surface</b>,
/// <b>displacement</b> and <b>volume</b>.
///
/// Each terminal output can further be qualified by a token-valued
/// <b>renderContext</b>. When a non-empty renderContext value is specified
/// to the API, the output is considered to have a specific or restricted
/// renderContext. If the renderContext value is empty (i.e. equal to
/// UsdShadeTokens->universalRenderContext), then the output is considered
/// to be a "universal", meaning it could apply to any render contexts.
/// Render context token values is typically driven by the rendering backend
/// consuming the terminal output (eg, RI or glslfx).
/// @{
/// Creates and returns the "surface" output on this material for the
/// specified \p renderContext.
///
/// If the output already exists on the material, it is returned and no
/// authoring is performed. The returned output will always have the
/// requested renderContext.
USDSHADE_API
UsdShadeOutput CreateSurfaceOutput(const TfToken &renderContext
=UsdShadeTokens->universalRenderContext) const;
/// Returns the "surface" output of this material for the specified
/// \p renderContext. The returned output will always have the requested
/// renderContext.
///
/// An invalid output is returned if an output corresponding to the
/// requested specific-renderContext does not exist.
///
/// \sa UsdShadeMaterial::ComputeSurfaceSource()
USDSHADE_API
UsdShadeOutput GetSurfaceOutput(const TfToken &renderContext
=UsdShadeTokens->universalRenderContext) const;
/// Returns the "surface" outputs of this material for all available
/// renderContexts.
///
/// The returned vector will include all authored "surface" outputs with
/// the <i>universal</i> renderContext output first, if present. Outputs
/// are returned regardless of whether they are connected to a valid
/// source.
USDSHADE_API
std::vector<UsdShadeOutput> GetSurfaceOutputs() const;
/// \deprecated Use the form that takes a TfTokenVector or renderContexts.
USDSHADE_API
UsdShadeShader ComputeSurfaceSource(
const TfToken &renderContext,
TfToken *sourceName=nullptr,
UsdShadeAttributeType *sourceType=nullptr) const;
/// Computes the resolved "surface" output source for the given
/// \p contextVector. Using the earliest renderContext in the contextVector
/// that produces a valid Shader object.
///
/// If a "surface" output corresponding to each of the renderContexts
/// does not exist <b>or</b> is not connected to a valid source, then this
/// checks the <i>universal</i> surface output.
///
/// Returns an empty Shader object if there is no valid <i>surface</i>
/// output source for any of the renderContexts in the \p contextVector.
/// The python version of this method returns a tuple containing three
/// elements (the source surface shader, sourceName, sourceType).
USDSHADE_API
UsdShadeShader ComputeSurfaceSource(
const TfTokenVector &contextVector={UsdShadeTokens->universalRenderContext},
TfToken *sourceName=nullptr,
UsdShadeAttributeType *sourceType=nullptr) const;
/// Creates and returns the "displacement" output on this material for the
/// specified \p renderContext.
///
/// If the output already exists on the material, it is returned and no
/// authoring is performed. The returned output will always have the
/// requested renderContext.
USDSHADE_API
UsdShadeOutput CreateDisplacementOutput(const TfToken &renderContext
=UsdShadeTokens->universalRenderContext) const;
/// Returns the "displacement" output of this material for the specified
/// renderContext. The returned output will always have the requested
/// renderContext.
///
/// An invalid output is returned if an output corresponding to the
/// requested specific-renderContext does not exist.
///
/// \sa UsdShadeMaterial::ComputeDisplacementSource()
USDSHADE_API
UsdShadeOutput GetDisplacementOutput(const TfToken &renderContext
=UsdShadeTokens->universalRenderContext) const;
/// Returns the "displacement" outputs of this material for all available
/// renderContexts.
///
/// The returned vector will include all authored "displacement" outputs
/// with the <i>universal</i> renderContext output first, if present.
/// Outputs are returned regardless of whether they are connected to a
/// valid source.
USDSHADE_API
std::vector<UsdShadeOutput> GetDisplacementOutputs() const;
/// \deprecated Use the form that takes a TfTokenVector or renderContexts
USDSHADE_API
UsdShadeShader ComputeDisplacementSource(
const TfToken &renderContext,
TfToken *sourceName=nullptr,
UsdShadeAttributeType *sourceType=nullptr) const;
/// Computes the resolved "displacement" output source for the given
/// \p contextVector. Using the earliest renderContext in the contextVector
/// that produces a valid Shader object.
///
/// If a "displacement" output corresponding to each of the renderContexts
/// does not exist <b>or</b> is not connected to a valid source, then this
/// checks the <i>universal</i> displacement output.
///
/// Returns an empty Shader object if there is no valid <i>displacement</i>
/// output source for any of the renderContexts in the \p contextVector.
/// The python version of this method returns a tuple containing three
/// elements (the source displacement shader, sourceName, sourceType).
USDSHADE_API
UsdShadeShader ComputeDisplacementSource(
const TfTokenVector &contextVector={UsdShadeTokens->universalRenderContext},
TfToken *sourceName=nullptr,
UsdShadeAttributeType *sourceType=nullptr) const;
/// Creates and returns the "volume" output on this material for the
/// specified \p renderContext.
///
/// If the output already exists on the material, it is returned and no
/// authoring is performed. The returned output will always have the
/// requested renderContext.
USDSHADE_API
UsdShadeOutput CreateVolumeOutput(const TfToken &renderContext
=UsdShadeTokens->universalRenderContext) const;
/// Returns the "volume" output of this material for the specified
/// renderContext. The returned output will always have the requested
/// renderContext.
///
/// An invalid output is returned if an output corresponding to the
/// requested specific-renderContext does not exist.
///
/// \sa UsdShadeMaterial::ComputeVolumeSource()
USDSHADE_API
UsdShadeOutput GetVolumeOutput(const TfToken &renderContext
=UsdShadeTokens->universalRenderContext) const;
/// Returns the "volume" outputs of this material for all available
/// renderContexts.
///
/// The returned vector will include all authored "volume" outputs with the
/// <i>universal</i> renderContext output first, if present. Outputs are
/// returned regardless of whether they are connected to a valid source.
USDSHADE_API
std::vector<UsdShadeOutput> GetVolumeOutputs() const;
/// \deprecated Use the form that takes a TfTokenVector or renderContexts
USDSHADE_API
UsdShadeShader ComputeVolumeSource(
const TfToken &renderContext,
TfToken *sourceName=nullptr,
UsdShadeAttributeType *sourceType=nullptr) const;
/// Computes the resolved "volume" output source for the given
/// \p contextVector. Using the earliest renderContext in the contextVector
/// that produces a valid Shader object.
///
/// If a "volume" output corresponding to each of the renderContexts
/// does not exist <b>or</b> is not connected to a valid source, then this
/// checks the <i>universal</i> volume output.
///
/// Returns an empty Shader object if there is no valid <i>volume</i> output
/// output source for any of the renderContexts in the \p contextVector.
/// The python version of this method returns a tuple containing three
/// elements (the source volume shader, sourceName, sourceType).
USDSHADE_API
UsdShadeShader ComputeVolumeSource(
const TfTokenVector &contextVector={UsdShadeTokens->universalRenderContext},
TfToken *sourceName=nullptr,
UsdShadeAttributeType *sourceType=nullptr) const;
/// @}
private:
// Helper method to compute the sources of a given output, identified by its
// baseName, for the renderContexts in the specified contextVector.
UsdShadeAttributeVector _ComputeNamedOutputSources(
const TfToken &baseName,
const TfTokenVector &contextVector) const;
// Helper method to compute the source shader of a given output, identified
// by its baseName, for the renderContexts in the specified contextVector.
UsdShadeShader _ComputeNamedOutputShader(
const TfToken &baseName,
const TfTokenVector &contextVector,
TfToken *sourceName,
UsdShadeAttributeType *sourceType) const;
// Helper method to retrieve outputs in all renderContexts that match the
// given terminalName.
std::vector<UsdShadeOutput> _GetOutputsForTerminalName(
const TfToken& terminalName) const;
public:
// --------------------------------------------------------------------- //
/// \anchor UsdShadeMaterial_Variations
/// \name Authoring Material Variations
/// Each UsdShadeMaterial prim can host data for any number of render targets
/// (such as Renderman RIS, Arnold, or glslfx).
///
/// A single UsdShadeMaterial group can, however, encode variations on
/// appearance, varying any data authored on the material and its contents.
/// For example, we might have a logo'd baseball cap that
/// comes in denim, nylon, and corduroy variations.
///
/// We provide methods to aid in authoring such variations on individual
/// Material prims, and also a facility for creating a "master" look
/// variant on another prim (e.g. a model's root prim, or another common
/// ancestor of all Material prims in a model) that will be able to modify
/// Materials, bindings, connections and values at once.
///
/// <b>Note on variant vs "direct" opinions.</b>
/// For any given prim's spec in a layer, opinions expressed inside a
/// variant of a variantSet will be /weaker/ than any opinions expressed
/// "directly" at the location, outside of any layer.
///
/// Therefore, if you intend to author a default variant that is weaker than
/// more explicit variants, you will need to have those opinions be weaker
/// by setting them across a reference arc such as the following:
///
/// \code
/// def "MyMaterial" (
/// add references = </MyMaterial_defaultShadingVariant>
/// variants = {
/// string materialVariant = "SomeVariant"
/// }
/// add variantSets = "materialVariant"
/// )
/// {
/// float strongerThanVariantOpinion
///
/// variantSet "materialVariant" = {
/// "SomeVariant" {
/// float variantOpinion
/// }
/// }
/// }
///
/// over "MyMaterial_defaultShadingVariant"
/// {
/// float weakerThanVariantOpinion
/// }
/// \endcode
///
/// @{
///
// --------------------------------------------------------------------- //
/// Helper function for configuring a UsdStage's UsdEditTarget to author
/// Material variations. Takes care of creating the Material variantSet and
/// specified variant, if necessary.
///
/// Let's assume that we are authoring Materials into the Stage's current
/// UsdEditTarget, and that we are iterating over the variations of a
/// UsdShadeMaterial \em clothMaterial, and \em currVariant is the variant we are
/// processing (e.g. "denim").
///
/// In C++, then, we would use the following pattern:
/// \code
/// {
/// UsdEditContext ctxt(clothMaterial.GetEditContextForVariant(currVariant));
///
/// // All USD mutation of the UsdStage on which clothMaterial sits will
/// // now go "inside" the currVariant of the "MaterialVariant" variantSet
/// }
/// \endcode
///
/// In python, the pattern is:
/// \code{.py}
/// with clothMaterial.GetEditContextForVariant(currVariant):
/// # Now sending mutations to currVariant
/// \endcode
///
/// If \p layer is specified, then we will use it, rather than the stage's
/// current UsdEditTarget's layer as the destination layer for the
/// edit context we are building. If \p layer does not actually contribute
/// to the Material prim's definition, any editing will have no effect on this
/// Material.
///
/// <b>Note:</b> As just stated, using this method involves authoring
/// a selection for the MaterialVariant in the stage's current EditTarget.
/// When client is done authoring variations on this prim, they will likely
/// want to either UsdVariantSet::SetVariantSelection() to the appropriate
/// default selection, or possibly UsdVariantSet::ClearVariantSelection()
/// on the UsdShadeMaterial::GetMaterialVariant() UsdVariantSet.
/// \sa UsdVariantSet::GetVariantEditContext()
USDSHADE_API
std::pair<UsdStagePtr, UsdEditTarget>
GetEditContextForVariant(const TfToken &MaterialVariantName,
const SdfLayerHandle &layer = SdfLayerHandle()) const;
/// Return a UsdVariantSet object for interacting with the Material variant
/// variantSet
USDSHADE_API
UsdVariantSet GetMaterialVariant() const;
/// Create a variantSet on \p masterPrim that will set the MaterialVariant on
/// each of the given \em MaterialPrims.
///
/// The variantSet, whose name can be specified with \p
/// masterVariantSetName and defaults to the same MaterialVariant name
/// created on Materials by GetEditContextForVariant(), will have the same
/// variants as the Materials, and each Master variant will set every
/// \p MaterialPrims' MaterialVariant selection to the same variant as the
/// master. Thus, it allows all Materials to be switched with a single
/// variant selection, on \p masterPrim.
///
/// If \p masterPrim is an ancestor of any given member of \p MaterialPrims,
/// then we will author variant selections directly on the MaterialPrims.
/// However, it is often preferable to create a master MaterialVariant in
/// a separately rooted tree from the MaterialPrims, so that it can be
/// layered more strongly on top of the Materials. Therefore, for any MaterialPrim
/// in a different tree than masterPrim, we will create "overs" as children
/// of masterPrim that recreate the path to the MaterialPrim, substituting
/// masterPrim's full path for the MaterialPrim's root path component.
///
/// Upon successful completion, the new variantSet we created on
/// \p masterPrim will have its variant selection authored to the
/// "last" variant (determined lexicographically). It is up to the
/// calling client to either UsdVariantSet::ClearVariantSelection()
/// on \p masterPrim, or set the selection to the desired default setting.
///
/// Return \c true on success. It is an error if any of \p Materials
/// have a different set of variants for the MaterialVariant than the others.
USDSHADE_API
static bool CreateMasterMaterialVariant(
const UsdPrim &masterPrim,
const std::vector<UsdPrim> &MaterialPrims,
const TfToken &masterVariantSetName = TfToken());
/// @}
// --------------------------------------------------------------------- //
/// \anchor UsdShadeMaterial_BaseMaterial
/// \name BaseMaterial
/// A specialize arc describes child/parent inheritance.
/// A Material that derives from a BaseMaterial will retain a live
/// composition relationship to its BaseMaterial
///
/// @{
// --------------------------------------------------------------------- //
/// Get the path to the base Material of this Material.
/// If there is no base Material, an empty Material is returned
USDSHADE_API
UsdShadeMaterial GetBaseMaterial() const;
/// Get the base Material of this Material.
/// If there is no base Material, an empty path is returned
USDSHADE_API
SdfPath GetBaseMaterialPath() const;
/// Given a PcpPrimIndex, searches it for an arc to a parent material.
///
/// This is a public static function to support applications that use
/// Pcp but not Usd. Most clients should call \ref GetBaseMaterialPath,
/// which uses this function when appropriate.
USDSHADE_API
static SdfPath FindBaseMaterialPathInPrimIndex(
const PcpPrimIndex & primIndex,
const PathPredicate & pathIsMaterialPredicate);
/// Set the base Material of this Material.
/// An empty Material is equivalent to clearing the base Material.
USDSHADE_API
void SetBaseMaterial(const UsdShadeMaterial& baseMaterial) const;
/// Set the path to the base Material of this Material.
/// An empty path is equivalent to clearing the base Material.
USDSHADE_API
void SetBaseMaterialPath(const SdfPath& baseMaterialPath) const;
/// Clear the base Material of this Material.
USDSHADE_API
void ClearBaseMaterial() const;
// Check if this Material has a base Material
USDSHADE_API
bool HasBaseMaterial() const;
/// @}
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,926 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSHADE_GENERATED_MATERIALBINDINGAPI_H
#define USDSHADE_GENERATED_MATERIALBINDINGAPI_H
/// \file usdShade/materialBindingAPI.h
#include "pxr/pxr.h"
#include "pxr/usd/usdShade/api.h"
#include "pxr/usd/usd/apiSchemaBase.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usdShade/tokens.h"
#include "pxr/usd/usd/collectionAPI.h"
#include "pxr/usd/usdGeom/subset.h"
#include "pxr/usd/usdShade/material.h"
#include <tbb/concurrent_unordered_map.h>
#include "pxr/base/vt/value.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class SdfAssetPath;
// -------------------------------------------------------------------------- //
// MATERIALBINDINGAPI //
// -------------------------------------------------------------------------- //
/// \class UsdShadeMaterialBindingAPI
///
/// UsdShadeMaterialBindingAPI is an API schema that provides an
/// interface for binding materials to prims or collections of prims
/// (represented by UsdCollectionAPI objects).
///
/// In the USD shading model, each renderable gprim computes a single
/// <b>resolved Material</b> that will be used to shade the gprim (exceptions,
/// of course, for gprims that possess UsdGeomSubsets, as each subset can be
/// shaded by a different Material). A gprim <b>and each of its ancestor
/// prims</b> can possess, through the MaterialBindingAPI, both a
/// <b>direct</b> binding to a Material, and any number of
/// <b>collection-based</b> bindings to Materials; each binding can be generic
/// or declared for a particular <b>purpose</b>, and given a specific <b>binding
/// strength</b>. It is the process of "material resolution" (see
/// \ref UsdShadeMaterialBindingAPI_MaterialResolution) that examines all of
/// these bindings, and selects the one Material that best matches the
/// client's needs.
///
/// The intent of <b>purpose</b> is that each gprim should be able to resolve a
/// Material for any given purpose, which implies it can have differently bound
/// materials for different purposes. There are two <i>special</i> values of
/// <b>purpose</b> defined in UsdShade, although the API fully supports
/// specifying arbitrary values for it, for the sake of extensibility:
/// <ul><li><b>UsdShadeTokens->full</b>: to be used when the purpose of the
/// render is entirely to visualize the truest representation of a scene,
/// considering all lighting and material information, at highest fidelity.</li>
/// <li><b>UsdShadeTokens->preview</b>: to be used when the render is in
/// service of a goal other than a high fidelity "full" render (such as scene
/// manipulation, modeling, or realtime playback). Latency and speed are
/// generally of greater concern for preview renders, therefore preview
/// materials are generally designed to be "lighterweight" compared to full
/// materials.</li></ul>
/// A binding can also have no specific purpose at all, in which
/// case, it is considered to be the fallback or all-purpose binding (denoted
/// by the empty-valued token <b>UsdShadeTokens->allPurpose</b>).
///
/// The <b>purpose</b> of a material binding is encoded in the name of the
/// binding relationship.
/// <ul><li>
/// In the case of a direct binding, the <i>allPurpose</i> binding is
/// represented by the relationship named <b>"material:binding"</b>.
/// Special-purpose direct bindings are represented by relationships named
/// <b>"material:binding:<i>purpose</i></b>. A direct binding relationship
/// must have a single target path that points to a <b>UsdShadeMaterial</b>.</li>
/// <li>
/// In the case of a collection-based binding, the <i>allPurpose</i> binding is
/// represented by a relationship named
/// "material:binding:collection:<i>bindingName</i>", where
/// <b>bindingName</b> establishes an identity for the binding that is unique
/// on the prim. Attempting to establish two collection bindings of the same
/// name on the same prim will result in the first binding simply being
/// overridden. A special-purpose collection-based binding is represented by a
/// relationship named "material:binding:collection:<i>purpose:bindingName</i>".
/// A collection-based binding relationship must have exacly two targets, one of
/// which should be a collection-path (see
/// ef UsdCollectionAPI::GetCollectionPath()) and the other should point to a
/// <b>UsdShadeMaterial</b>. In the future, we may allow a single collection
/// binding to target multiple collections, if we can establish a reasonable
/// round-tripping pattern for applications that only allow a single collection
/// to be associated with each Material.
/// </li>
/// </ul>
///
/// <b>Note:</b> Both <b>bindingName</b> and <b>purpose</b> must be
/// non-namespaced tokens. This allows us to know the role of a binding
/// relationship simply from the number of tokens in it.
/// <ul><li><b>Two tokens</b>: the fallback, "all purpose", direct binding,
/// <i>material:binding</i></li>
/// <li><b>Three tokens</b>: a purpose-restricted, direct, fallback binding,
/// e.g. material:binding:preview</li>
/// <li><b>Four tokens</b>: an all-purpose, collection-based binding, e.g.
/// material:binding:collection:metalBits</li>
/// <li><b>Five tokens</b>: a purpose-restricted, collection-based binding,
/// e.g. material:binding:collection:full:metalBits</li>
/// </ul>
///
/// A <b>binding-strength</b> value is used to specify whether a binding
/// authored on a prim should be weaker or stronger than bindings that appear
/// lower in namespace. We encode the binding strength with as token-valued
/// metadata <b>'bindMaterialAs'</b> for future flexibility, even though for
/// now, there are only two possible values:
/// <i>UsdShadeTokens->weakerThanDescendants</i> and
/// <i>UsdShadeTokens->strongerThanDescendants</i>. When binding-strength is
/// not authored (i.e. empty) on a binding-relationship, the default behavior
/// matches UsdShadeTokens->weakerThanDescendants.
///
/// \note If a material binding relationship is a built-in property defined as
/// part of a typed prim's schema, a fallback value should not be provided for
/// it. This is because the "material resolution" algorithm only conisders
/// <i>authored</i> properties.
///
///
class UsdShadeMaterialBindingAPI : public UsdAPISchemaBase
{
public:
/// Compile time constant representing what kind of schema this class is.
///
/// \sa UsdSchemaKind
static const UsdSchemaKind schemaKind = UsdSchemaKind::SingleApplyAPI;
/// Construct a UsdShadeMaterialBindingAPI on UsdPrim \p prim .
/// Equivalent to UsdShadeMaterialBindingAPI::Get(prim.GetStage(), prim.GetPath())
/// for a \em valid \p prim, but will not immediately throw an error for
/// an invalid \p prim
explicit UsdShadeMaterialBindingAPI(const UsdPrim& prim=UsdPrim())
: UsdAPISchemaBase(prim)
{
}
/// Construct a UsdShadeMaterialBindingAPI on the prim held by \p schemaObj .
/// Should be preferred over UsdShadeMaterialBindingAPI(schemaObj.GetPrim()),
/// as it preserves SchemaBase state.
explicit UsdShadeMaterialBindingAPI(const UsdSchemaBase& schemaObj)
: UsdAPISchemaBase(schemaObj)
{
}
/// Destructor.
USDSHADE_API
virtual ~UsdShadeMaterialBindingAPI();
/// 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.
USDSHADE_API
static const TfTokenVector &
GetSchemaAttributeNames(bool includeInherited=true);
/// Return a UsdShadeMaterialBindingAPI holding the prim adhering to this
/// schema at \p path on \p stage. If no prim exists at \p path on
/// \p 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:
///
/// \code
/// UsdShadeMaterialBindingAPI(stage->GetPrimAtPath(path));
/// \endcode
///
USDSHADE_API
static UsdShadeMaterialBindingAPI
Get(const UsdStagePtr &stage, const SdfPath &path);
/// Returns true if this <b>single-apply</b> API schema can be applied to
/// the given \p prim. If this schema can not be a applied to the prim,
/// this returns false and, if provided, populates \p 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.
///
/// \sa UsdPrim::GetAppliedSchemas()
/// \sa UsdPrim::HasAPI()
/// \sa UsdPrim::CanApplyAPI()
/// \sa UsdPrim::ApplyAPI()
/// \sa UsdPrim::RemoveAPI()
///
USDSHADE_API
static bool
CanApply(const UsdPrim &prim, std::string *whyNot=nullptr);
/// Applies this <b>single-apply</b> API schema to the given \p prim.
/// This information is stored by adding "MaterialBindingAPI" to the
/// token-valued, listOp metadata \em apiSchemas on the prim.
///
/// \return A valid UsdShadeMaterialBindingAPI object is returned upon success.
/// An invalid (or empty) UsdShadeMaterialBindingAPI object is returned upon
/// failure. See \ref UsdPrim::ApplyAPI() for conditions
/// resulting in failure.
///
/// \sa UsdPrim::GetAppliedSchemas()
/// \sa UsdPrim::HasAPI()
/// \sa UsdPrim::CanApplyAPI()
/// \sa UsdPrim::ApplyAPI()
/// \sa UsdPrim::RemoveAPI()
///
USDSHADE_API
static UsdShadeMaterialBindingAPI
Apply(const UsdPrim &prim);
protected:
/// Returns the kind of schema this class belongs to.
///
/// \sa UsdSchemaKind
USDSHADE_API
UsdSchemaKind _GetSchemaKind() const override;
private:
// needs to invoke _GetStaticTfType.
friend class UsdSchemaRegistry;
USDSHADE_API
static const TfType &_GetStaticTfType();
static bool _IsTypedSchema();
// override SchemaBase virtuals.
USDSHADE_API
const TfType &_GetTfType() const override;
public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
// the code generator.
//
// Just remember to:
// - Close the class declaration with };
// - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
// - Close the include guard with #endif
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
/// \anchor UsdShadeMaterialBindingAPI_SchemaProperties
/// \name Schema property and associated data retrieval API
///
/// This section contains API for fetching the two kinds of binding
/// relationships and for computing the corresponding bindings.
///
/// @{
/// Returns the direct material-binding relationship on this prim for the
/// given material purpose.
///
/// The material purpose of the relationship that's returned will match
/// the specified \p materialPurpose.
USDSHADE_API
UsdRelationship GetDirectBindingRel(
const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
/// Returns the collection-based material-binding relationship with the
/// given \p bindingName and \p materialPurpose on this prim.
///
/// For info on \p bindingName, see UsdShadeMaterialBindingAPI::Bind().
/// The material purpose of the relationship that's returned will match
/// the specified \p materialPurpose.
USDSHADE_API
UsdRelationship GetCollectionBindingRel(
const TfToken &bindingName,
const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
/// Returns the list of collection-based material binding relationships
/// on this prim for the given material purpose, \p materialPurpose.
///
/// The returned list of binding relationships will be in native property
/// order. See UsdPrim::GetPropertyOrder(), UsdPrim::SetPropertyOrder().
/// Bindings that appear earlier in the property order are considered to be
/// stronger than the ones that come later. See rule #6 in
/// \ref UsdShadeMaterialBindingAPI_MaterialResolution.
USDSHADE_API
std::vector<UsdRelationship> GetCollectionBindingRels(
const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
/// \class DirectBinding
/// This class represents a direct material binding.
class DirectBinding {
public:
/// Default constructor initializes a DirectBinding object with
/// invalid material and bindingRel data members.
DirectBinding()
{}
USDSHADE_API
explicit DirectBinding(const UsdRelationship &bindingRel);
/// Gets the material object that this direct binding binds to.
USDSHADE_API
UsdShadeMaterial GetMaterial() const;
/// Returns the path to the material that is bound to by this
/// direct binding.
const SdfPath &GetMaterialPath() const {
return _materialPath;
}
/// Returns the binding-relationship that represents this direct
/// binding.
const UsdRelationship &GetBindingRel() const {
return _bindingRel;
}
/// Returns the purpose of the direct binding.
const TfToken &GetMaterialPurpose() const {
return _materialPurpose;
}
private:
// The path to the material that is bound to.
SdfPath _materialPath;
// The binding relationship.
UsdRelationship _bindingRel;
// The purpose of the material binding.
TfToken _materialPurpose;
};
/// \class CollectionBinding
/// This struct is used to represent a collection-based material binding,
/// which contains two objects - a collection and a bound material.
class CollectionBinding {
public:
/// Default constructor initializes a CollectionBinding object with
/// invalid collection, material and bindingRel data members.
CollectionBinding()
{}
/// Constructs a CollectionBinding object from the given collection-
/// binding relationship. This inspects the targets of the relationship
/// and determines the bound collection and the target material that
/// the collection is bound to.
USDSHADE_API
explicit CollectionBinding(const UsdRelationship &collBindingRel);
/// Constructs and returns the material object that this
/// collection-based binding binds to.
USDSHADE_API
UsdShadeMaterial GetMaterial() const;
/// Constructs and returns the CollectionAPI object for the collection
/// that is bound by this collection-binding.
USDSHADE_API
UsdCollectionAPI GetCollection() const;
/// Returns true if the CollectionBinding points to a valid material
/// and collection.
bool IsValid() const {
return GetCollection() && GetMaterial();
}
/// Returns the path to the collection that is bound by this binding.
const SdfPath &GetCollectionPath() const {
return _collectionPath;
}
/// Returns the path to the material that is bound to by this binding.
const SdfPath &GetMaterialPath() const {
return _materialPath;
}
/// Returns the binding-relationship that represents this collection-
/// based binding.
const UsdRelationship &GetBindingRel() const {
return _bindingRel;
}
private:
// The collection being bound.
SdfPath _collectionPath;
// The material that is bound to.
SdfPath _materialPath;
// The relationship that binds the collection to the material.
UsdRelationship _bindingRel;
};
using CollectionBindingVector = std::vector<CollectionBinding>;
/// Computes and returns the direct binding for the given material purpose
/// on this prim.
///
/// The returned binding always has the specified \p materialPurpose
/// (i.e. the all-purpose binding is not returned if a special purpose
/// binding is requested).
///
/// If the direct binding is to a prim that is not a Material, this does not
/// generate an error, but the returned Material will be invalid (i.e.
/// evaluate to false).
USDSHADE_API
DirectBinding GetDirectBinding(
const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
/// Returns all the collection-based bindings on this prim for the given
/// material purpose.
///
/// The returned CollectionBinding objects always have the specified
/// \p materialPurpose (i.e. the all-purpose binding is not returned if a
/// special purpose binding is requested).
///
/// If one or more collection based bindings are to prims that are not
/// Materials, this does not generate an error, but the corresponding
/// Material(s) will be invalid (i.e. evaluate to false).
///
/// The python version of this API returns a tuple containing the
/// vector of CollectionBinding objects and the corresponding vector
/// of binding relationships.
///
/// The returned list of collection-bindings will be in native property
/// order of the associated binding relationships. See
/// UsdPrim::GetPropertyOrder(), UsdPrim::SetPropertyOrder().
/// Binding relationships that come earlier in the list are considered to
/// be stronger than the ones that come later. See rule #6 in
/// \ref UsdShadeMaterialBindingAPI_MaterialResolution.
USDSHADE_API
CollectionBindingVector GetCollectionBindings(
const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
/// Resolves the 'bindMaterialAs' token-valued metadata on the given binding
/// relationship and returns it.
/// If the resolved value is empty, this returns the fallback value
/// UsdShadeTokens->weakerThanDescendants.
///
/// \sa UsdShadeMaterialBindingAPI::SetMaterialBindingStrength()
USDSHADE_API
static TfToken GetMaterialBindingStrength(
const UsdRelationship &bindingRel);
/// Sets the 'bindMaterialAs' token-valued metadata on the given binding
/// relationship.
///
/// If \p bindingStrength is <i>UsdShadeTokens->fallbackStrength</i>, the
/// value UsdShadeTokens->weakerThanDescendants is authored sparsely, i.e.
/// only when there is a different existing bindingStrength value.
/// To stamp out the bindingStrength value explicitly, clients can pass in
/// UsdShadeTokens->weakerThanDescendants or
/// UsdShadeTokens->strongerThanDescendants directly.
/// Returns true on success, false otherwise.
///
/// \sa UsdShadeMaterialBindingAPI::GetMaterialBindingStrength()
USDSHADE_API
static bool SetMaterialBindingStrength(
const UsdRelationship &bindingRel,
const TfToken &bindingStrength);
/// @}
/// \anchor UsdShadeMaterialBindingAPI_Binding
/// \name Binding authoring and clearing API
///
/// This section provides API for authoring and clearing both direct and
/// collection-based material bindings on a prim.
///
/// @{
/// Authors a direct binding to the given \p material on this prim.
///
/// If \p bindingStrength is UsdShadeTokens->fallbackStrength, the value
/// UsdShadeTokens->weakerThanDescendants is authored sparsely.
/// To stamp out the bindingStrength value explicitly, clients can pass in
/// UsdShadeTokens->weakerThanDescendants or
/// UsdShadeTokens->strongerThanDescendants directly.
///
/// If \p materialPurpose is specified and isn't equal to
/// UsdShadeTokens->allPurpose, the binding only applies to the specified
/// material purpose.
///
/// Note that UsdShadeMaterialBindingAPI is a SingleAppliedAPI schema which
/// when applied updates the prim definition accordingly. This information
/// on the prim definition is helpful in multiple queries and more
/// performant. Hence its recommended to call
/// UsdShadeMaterialBindingAPI::Apply() when Binding a material.
///
/// Returns true on success, false otherwise.
USDSHADE_API
bool Bind(
const UsdShadeMaterial &material,
const TfToken &bindingStrength=UsdShadeTokens->fallbackStrength,
const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
/// Authors a collection-based binding, which binds the given \p material
/// to the given \p collection on this prim.
///
/// \p bindingName establishes an identity for the binding that is unique
/// on the prim. Attempting to establish two collection bindings of the same
/// name on the same prim will result in the first binding simply being
/// overridden. If \p bindingName is empty, it is set to the base-name of
/// the collection being bound (which is the collection-name with any
/// namespaces stripped out). If there are multiple collections with the
/// same base-name being bound at the same prim, clients should pass in a
/// unique binding name per binding, in order to preserve all bindings.
/// The binding name used in constructing the collection-binding
/// relationship name shoud not contain namespaces. Hence, a coding error
/// is issued and no binding is authored if the provided value of
/// \p bindingName is non-empty and contains namespaces.
///
/// If \p bindingStrength is <i>UsdShadeTokens->fallbackStrength</i>, the
/// value UsdShadeTokens->weakerThanDescendants is authored sparsely, i.e.
/// only when there is an existing binding with a different bindingStrength.
/// To stamp out the bindingStrength value explicitly, clients can pass in
/// UsdShadeTokens->weakerThanDescendants or
/// UsdShadeTokens->strongerThanDescendants directly.
///
/// If \p materialPurpose is specified and isn't equal to
/// UsdShadeTokens->allPurpose, the binding only applies to the specified
/// material purpose.
///
/// Note that UsdShadeMaterialBindingAPI is a SingleAppliedAPI schema which
/// when applied updates the prim definition accordingly. This information
/// on the prim definition is helpful in multiple queries and more
/// performant. Hence its recommended to call
/// UsdShadeMaterialBindingAPI::Apply() when Binding a material.
///
/// Returns true on success, false otherwise.
USDSHADE_API
bool Bind(
const UsdCollectionAPI &collection,
const UsdShadeMaterial &material,
const TfToken &bindingName=TfToken(),
const TfToken &bindingStrength=UsdShadeTokens->fallbackStrength,
const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
/// Unbinds the direct binding for the given material purpose
/// (\p materialPurpose) on this prim. It accomplishes this by blocking
/// the targets of the binding relationship in the current edit target.
USDSHADE_API
bool UnbindDirectBinding(
const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
/// Unbinds the collection-based binding with the given \p bindingName, for
/// the given \p materialPurpose on this prim. It accomplishes this by
/// blocking the targets of the associated binding relationship in the
/// current edit target.
USDSHADE_API
bool UnbindCollectionBinding(
const TfToken &bindingName,
const TfToken &materialPurpose=UsdShadeTokens->allPurpose) const;
/// Unbinds all direct and collection-based bindings on this prim.
USDSHADE_API
bool UnbindAllBindings() const;
/// Removes the specified \p prim from the collection targeted by the
/// binding relationship corresponding to given \p bindingName and
/// \p materialPurpose.
///
/// If the collection-binding relationship doesn't exist or if the
/// targeted collection does not include the \p prim, then this does
/// nothing and returns true.
///
/// If the targeted collection includes \p prim, then this modifies the
/// collection by removing the prim from it (by invoking
/// UsdCollectionAPI::RemovePrim()). This method can be used in conjunction
/// with the Unbind*() methods (if desired) to guarantee that a prim
/// has no resolved material binding.
USDSHADE_API
bool RemovePrimFromBindingCollection(
const UsdPrim &prim,
const TfToken &bindingName,
const TfToken &materialPurpose) const;
/// Adds the specified \p prim to the collection targeted by the
/// binding relationship corresponding to given \p bindingName and
/// \p materialPurpose.
///
/// If the collection-binding relationship doesn't exist or if the
/// targeted collection already includes the \p prim, then this does
/// nothing and returns true.
///
/// If the targeted collection does not include \p prim (or excludes it
/// explicitly), then this modifies the collection by adding the prim to it
/// (by invoking UsdCollectionAPI::AddPrim()).
USDSHADE_API
bool AddPrimToBindingCollection(
const UsdPrim &prim,
const TfToken &bindingName,
const TfToken &materialPurpose) const;
/// @}
/// \anchor UsdShadeMaterialBindingAPI_MaterialResolution
/// \name Bound Material Resolution
///
/// Material resolution is the process of determining the final bound
/// material for a given gprim (or UsdGeomSubset), for a given value of
/// material purpose. It involves examining all the bindings on the prim
/// and its ancestors, until a matching binding is found. The following
/// set of rules are applied in the process:
/// <ul>
/// <li>[1] Material bindings are inherited down the namespace chain.
/// Bindings lower in namespace (closer to leaf gprims) are stronger than
/// bindings on ancestors, unless they have their binding-strength set to
/// <i>UsdShadeTokens->strongerThanDescendants</i>.</li>
/// <li>[2] A collection binding only applies to members of the collection
/// that are at or beneath the prim owning the binding relationship.</li>
/// <li>[3] The purpose of the resolved material binding must either match
/// the requested special (i.e. restricted) purpose or be an all-purpose
/// binding. The restricted purpose binding, if available is preferred over
/// an all-purpose binding.
/// <li>[4] At any given prim, the collection-based bindings are considered
/// to be stronger than the direct bindings. This reflects our belief that
/// the combination would appear primarily to define a "fallback" material
/// to be used by any child prims that are not targeted by a more specific
/// assignment</li>
/// <li>[5] Collection-based binding relationships are applied in native
/// property order, with the earlier ordered binding relationships being
/// stronger.</li>
/// <li>[6] The "namespace specificity" with which a prim is included in a
/// collection is irrelevant to the binding strength of the collection. For
/// example, if a prim contains the ordered collection bindings
/// material:binding:collection:metalBits and
/// material:binding:collection:plasticBits, each of which targets a
/// collection of the same name, then if metalBits includes </Chair/Back>,
/// while plasticBits includes </Chair/Back/Brace/Rivet>, the binding for
/// </Chair/Back/Brace/Rivet> will be metalBits, because the metalBits
/// collection is bound more strongly than the plasticBits, and includes
/// an ancestor of </Chair/Back/Brace/Rivet>.
/// </li>
/// </ul>
///
/// \note If a material binding relationship is a built-in property defined
/// as part of a typed prim schema, a fallback value should not be provided
/// for it. This is because the "material resolution" algorithm only
/// conisders <i>authored</i> properties.
///
/// @{
/// An unordered list of collection paths mapped to the associated
/// collection's MembershipQuery object. This is used to cache the
/// MembershipQuery objects for collections that are encountered during
/// binding resolution for a tree of prims.
using CollectionQueryCache =
tbb::concurrent_unordered_map<SdfPath,
std::unique_ptr<UsdCollectionAPI::MembershipQuery>, SdfPath::Hash>;
/// Alias for a unique_ptr to a DirectBinding object.
using DirectBindingPtr = std::unique_ptr<DirectBinding>;
struct BindingsAtPrim {
/// Inspects all the material:binding* properties on the \p prim and
/// computes direct and collection-based bindings for the given
/// value of \p materialPurpose.
USDSHADE_API
BindingsAtPrim(const UsdPrim &prim, const TfToken &materialPurpose);
/// If the prim has a restricted purpose direct binding, then it is
/// stored here. If there is no restricted purpose binding on the prim,
/// then the all-purpose direct binding is stored.
DirectBindingPtr directBinding;
/// The ordered list of restricted-purpose collection bindings on the
/// prim.
CollectionBindingVector restrictedPurposeCollBindings;
/// The ordered list of all-purpose collection bindings on the prim.
CollectionBindingVector allPurposeCollBindings;
};
/// BindingsAtPrim needs to invoke private _GetCollectionBindings().
friend struct BindingsAtPrim;
/// An unordered list of prim-paths mapped to the corresponding set of
/// bindings at the associated prim. This is used when computing resolved
/// bindings to avoid redundant computations for the shared ancestor
/// prims and to re-use the computed results for leaf prims.
using BindingsCache = tbb::concurrent_unordered_map<SdfPath,
std::unique_ptr<BindingsAtPrim>, SdfPath::Hash>;
/// \overload
/// Computes the resolved bound material for this prim, for the given
/// material purpose.
///
/// This overload of ComputeBoundMaterial makes use of the BindingsCache
/// (\p bindingsCache) and CollectionQueryCache (\p collectionQueryCache)
/// that are passed in, to avoid redundant binding computations and
/// computations of MembershipQuery objects for collections.
/// It would be beneficial to make use of these when resolving bindings for
/// a tree of prims. These caches are populated lazily as more and more
/// bindings are resolved.
///
/// When the goal is to compute the bound material for a range (or list) of
/// prims, it is recommended to use this version of ComputeBoundMaterial().
/// Here's how you could compute the bindings of a range of prims
/// efficiently in C++:
///
/// \code
/// std::vector<std::pair<UsdPrim, UsdShadeMaterial> primBindings;
/// UsdShadeMaterialBindingAPI::BindingsCache bindingsCache;
/// UsdShadeMaterialBindingAPI::CollectionQueryCache collQueryCache;
///
/// for (auto prim : UsdPrimRange(rootPrim)) {
/// UsdShadeMaterial boundMaterial =
/// UsdShadeMaterialBindingAPI(prim).ComputeBoundMaterial(
/// &bindingsCache, &collQueryCache);
/// if (boundMaterial) {
/// primBindings.emplace_back({prim, boundMaterial});
/// }
/// }
/// \endcode
///
/// If \p bindingRel is not null, then it is set to the "winning" binding
/// relationship.
///
/// See \ref UsdShadeMaterialBindingAPI_MaterialResolution "Bound Material Resolution"
/// for details on the material resolution process.
///
/// The python version of this method returns a tuple containing the
/// bound material and the "winning" binding relationship.
USDSHADE_API
UsdShadeMaterial ComputeBoundMaterial(
BindingsCache *bindingsCache,
CollectionQueryCache *collectionQueryCache,
const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
UsdRelationship *bindingRel=nullptr) const;
/// \overload
/// Computes the resolved bound material for this prim, for the given
/// material purpose.
///
/// This overload does not utilize cached MembershipQuery object. However,
/// it only computes the MembershipQuery of every collection that bound
/// in the ancestor chain at most once.
///
/// If \p bindingRel is not null, then it is set to the winning binding
/// relationship.
///
/// See \ref UsdShadeMaterialBindingAPI_MaterialResolution "Bound Material Resolution"
/// for details on the material resolution process.
///
/// The python version of this method returns a tuple containing the
/// bound material and the "winning" binding relationship.
USDSHADE_API
UsdShadeMaterial ComputeBoundMaterial(
const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
UsdRelationship *bindingRel=nullptr) const;
/// Static API for efficiently and concurrently computing the resolved
/// material bindings for a vector of UsdPrims, \p prims for the
/// given \p materialPurpose.
///
/// The size of the returned vector always matches the size of the input
/// vector, \p prims. If a prim is not bound to any material, an invalid
/// or empty UsdShadeMaterial is returned at the index corresponding to it.
///
/// If the pointer \p bindingRels points to a valid vector, then it is
/// populated with the set of all "winning" binding relationships.
///
/// The python version of this method returns a tuple containing two lists -
/// the bound materials and the corresponding "winning" binding
/// relationships.
USDSHADE_API
static std::vector<UsdShadeMaterial> ComputeBoundMaterials(
const std::vector<UsdPrim> &prims,
const TfToken &materialPurpose=UsdShadeTokens->allPurpose,
std::vector<UsdRelationship> *bindingRels=nullptr);
/// @}
// --------------------------------------------------------------------- //
/// \anchor UsdShadeMaterialBindingAPI_Subsets
/// \name Binding materials to subsets
///
/// API to create, access and query the presence of GeomSubsets that are
/// created for the purpose of binding materials.
///
/// \note GeomSubsets can only be created on valid UsdGeomImageable prims.
/// Hence, this API only works when the prim held by the MaterialBindingAPI
/// schema object is an imageable prim.
///
/// \note Material bindings authored on GeomSubsets are honored by renderers
/// only if their familyName is <b>UsdShadeTokens->materialBind</b>. This
/// allows robust interchange of subset bindings between multiple DCC apps.
///
/// \note The family type of the <i>materialBind</i> family of subsets
/// defaults to UsdGeomTokens->nonOverlapping. It can be set to
/// UsdGeomTokens->partition, using the API
/// SetMaterialBindFaceSubsetsFamilyType(). It should never be set to
/// UsdGeomTokens->unrestricted, since it is invalid for a piece of
/// geometry to be bound to multiple materials.
///
/// Here's some sample code that shows how to create "face" subsets and
/// and bind materials to them.
/// \code
/// // Get the imageable prim under which subsets must be created and
/// // bound.
/// UsdGeomImageable mesh = UsdGeomImageable::Get(stage,
/// SdfPath("/path/to/meshPrim");
///
/// // Get the materials to bind to.
/// UsdShadeMaterial plastic = UsdShadeMaterial::Get(stage,
/// SdfPath("/path/to/PlasticMaterial");
/// UsdShadeMaterial metal = UsdShadeMaterial::Get(stage,
/// SdfPath("/path/to/MetalMaterial");
///
/// VtIntArray plasticFaces, metalFaces;
/// //.. populate faceIndices here.
/// //..
///
/// UsdGeomMaterialBindingAPI meshBindingAPI(mesh.GetPrim());
/// UsdGeomSubset plasticSubset = meshBindingAPI.CreateMaterialBindSubset(
/// "plasticSubset", plasticFaces);
/// UsdGeomSubset metalSubset = meshBindingAPI.CreateMaterialBindSubset(
/// "metalSubset", metalFaces);
///
/// // Bind materials to the created geom-subsets.
/// UsdShadeMaterialBindingAPI(pasticSubset.GetPrim()).Bind(plastic)
/// UsdShadeMaterialBindingAPI(metalSubset.GetPrim()).Bind(metal)
///
/// \endcode
/// @{
/// Creates a GeomSubset named \p subsetName with element type,
/// \p elementType and familyName <b>materialBind<b> below this prim.
///
/// If a GeomSubset named \p subsetName already exists, then its
/// "familyName" is updated to be UsdShadeTokens->materialBind and its
/// indices (at <i>default</i> timeCode) are updated with the provided
/// \p indices value before returning.
///
/// This method forces the familyType of the "materialBind" family of
/// subsets to UsdGeomTokens->nonOverlapping if it's unset or explicitly set
/// to UsdGeomTokens->unrestricted.
///
/// The default value \p elementType is UsdGeomTokens->face, as we expect
/// materials to be bound most often to subsets of faces on meshes.
USDSHADE_API
UsdGeomSubset CreateMaterialBindSubset(
const TfToken &subsetName,
const VtIntArray &indices,
const TfToken &elementType=UsdGeomTokens->face);
/// Returns all the existing GeomSubsets with
/// familyName=UsdShadeTokens->materialBind below this prim.
USDSHADE_API
std::vector<UsdGeomSubset> GetMaterialBindSubsets();
/// Author the <i>familyType</i> of the "materialBind" family of GeomSubsets
/// on this prim.
///
/// The default \p familyType is <i>UsdGeomTokens->nonOverlapping<i>. It
/// can be set to <i>UsdGeomTokens->partition</i> to indicate that the
/// entire imageable prim is included in the union of all the "materialBind"
/// subsets. The family type should never be set to
/// UsdGeomTokens->unrestricted, since it is invalid for a single piece
/// of geometry (in this case, a subset) to be bound to more than one
/// material. Hence, a coding error is issued if \p familyType is
/// UsdGeomTokens->unrestricted.
///
/// \sa UsdGeomSubset::SetFamilyType
USDSHADE_API
bool SetMaterialBindSubsetsFamilyType(const TfToken &familyType);
/// Returns the familyType of the family of "materialBind" GeomSubsets on
/// this prim.
///
/// By default, materialBind subsets have familyType="nonOverlapping", but
/// they can also be tagged as a "partition", using
/// SetMaterialBindFaceSubsetsFamilyType().
///
/// \sa UsdGeomSubset::GetFamilyNameAttr
USDSHADE_API
TfToken GetMaterialBindSubsetsFamilyType();
/// Test whether a given \p name contains the "material:binding:" prefix
///
USDSHADE_API
static bool CanContainPropertyName(const TfToken &name);
/// @}
private:
UsdRelationship _CreateDirectBindingRel(
const TfToken &materialPurpose) const;
UsdRelationship _CreateCollectionBindingRel(
const TfToken &bindingName,
const TfToken &materialPurpose) const;
// Helper method for getting collection bindings when the set of all
// collection binding relationship names for the required purpose is
// known.
CollectionBindingVector _GetCollectionBindings(
const TfTokenVector &collBindingPropertyNames) const;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+441
View File
@@ -0,0 +1,441 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSHADE_GENERATED_NODEDEFAPI_H
#define USDSHADE_GENERATED_NODEDEFAPI_H
/// \file usdShade/nodeDefAPI.h
#include "pxr/pxr.h"
#include "pxr/usd/usdShade/api.h"
#include "pxr/usd/usd/apiSchemaBase.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usdShade/tokens.h"
#include "pxr/usd/ndr/declare.h"
#include "pxr/usd/sdr/shaderNode.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class SdfAssetPath;
// -------------------------------------------------------------------------- //
// NODEDEFAPI //
// -------------------------------------------------------------------------- //
/// \class UsdShadeNodeDefAPI
///
/// 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 \em Fallback \em Value or \em Allowed \em Values below
/// that are text/tokens, the actual token is published and defined in \ref UsdShadeTokens.
/// So to set an attribute to the value "rightHanded", use UsdShadeTokens->rightHanded
/// as the value.
///
class UsdShadeNodeDefAPI : public UsdAPISchemaBase
{
public:
/// Compile time constant representing what kind of schema this class is.
///
/// \sa UsdSchemaKind
static const UsdSchemaKind schemaKind = UsdSchemaKind::SingleApplyAPI;
/// Construct a UsdShadeNodeDefAPI on UsdPrim \p prim .
/// Equivalent to UsdShadeNodeDefAPI::Get(prim.GetStage(), prim.GetPath())
/// for a \em valid \p prim, but will not immediately throw an error for
/// an invalid \p prim
explicit UsdShadeNodeDefAPI(const UsdPrim& prim=UsdPrim())
: UsdAPISchemaBase(prim)
{
}
/// Construct a UsdShadeNodeDefAPI on the prim held by \p schemaObj .
/// Should be preferred over UsdShadeNodeDefAPI(schemaObj.GetPrim()),
/// as it preserves SchemaBase state.
explicit UsdShadeNodeDefAPI(const UsdSchemaBase& schemaObj)
: UsdAPISchemaBase(schemaObj)
{
}
/// Destructor.
USDSHADE_API
virtual ~UsdShadeNodeDefAPI();
/// 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.
USDSHADE_API
static const TfTokenVector &
GetSchemaAttributeNames(bool includeInherited=true);
/// Return a UsdShadeNodeDefAPI holding the prim adhering to this
/// schema at \p path on \p stage. If no prim exists at \p path on
/// \p 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:
///
/// \code
/// UsdShadeNodeDefAPI(stage->GetPrimAtPath(path));
/// \endcode
///
USDSHADE_API
static UsdShadeNodeDefAPI
Get(const UsdStagePtr &stage, const SdfPath &path);
/// Returns true if this <b>single-apply</b> API schema can be applied to
/// the given \p prim. If this schema can not be a applied to the prim,
/// this returns false and, if provided, populates \p 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.
///
/// \sa UsdPrim::GetAppliedSchemas()
/// \sa UsdPrim::HasAPI()
/// \sa UsdPrim::CanApplyAPI()
/// \sa UsdPrim::ApplyAPI()
/// \sa UsdPrim::RemoveAPI()
///
USDSHADE_API
static bool
CanApply(const UsdPrim &prim, std::string *whyNot=nullptr);
/// Applies this <b>single-apply</b> API schema to the given \p prim.
/// This information is stored by adding "NodeDefAPI" to the
/// token-valued, listOp metadata \em apiSchemas on the prim.
///
/// \return A valid UsdShadeNodeDefAPI object is returned upon success.
/// An invalid (or empty) UsdShadeNodeDefAPI object is returned upon
/// failure. See \ref UsdPrim::ApplyAPI() for conditions
/// resulting in failure.
///
/// \sa UsdPrim::GetAppliedSchemas()
/// \sa UsdPrim::HasAPI()
/// \sa UsdPrim::CanApplyAPI()
/// \sa UsdPrim::ApplyAPI()
/// \sa UsdPrim::RemoveAPI()
///
USDSHADE_API
static UsdShadeNodeDefAPI
Apply(const UsdPrim &prim);
protected:
/// Returns the kind of schema this class belongs to.
///
/// \sa UsdSchemaKind
USDSHADE_API
UsdSchemaKind _GetSchemaKind() const override;
private:
// needs to invoke _GetStaticTfType.
friend class UsdSchemaRegistry;
USDSHADE_API
static const TfType &_GetStaticTfType();
static bool _IsTypedSchema();
// override SchemaBase virtuals.
USDSHADE_API
const TfType &_GetTfType() const override;
public:
// --------------------------------------------------------------------- //
// IMPLEMENTATIONSOURCE
// --------------------------------------------------------------------- //
/// 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 |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
/// | \ref UsdShadeTokens "Allowed Values" | id, sourceAsset, sourceCode |
USDSHADE_API
UsdAttribute GetImplementationSourceAttr() const;
/// See GetImplementationSourceAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSHADE_API
UsdAttribute CreateImplementationSourceAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// ID
// --------------------------------------------------------------------- //
/// 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 target: some will turn it
/// into an actual shader path, some will use it to generate shader source
/// code dynamically.
///
/// \sa SetShaderId()
///
///
/// | ||
/// | -- | -- |
/// | Declaration | `uniform token info:id` |
/// | C++ Type | TfToken |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
USDSHADE_API
UsdAttribute GetIdAttr() const;
/// See GetIdAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSHADE_API
UsdAttribute CreateIdAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
// the code generator.
//
// Just remember to:
// - Close the class declaration with };
// - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
// - Close the include guard with #endif
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
// -------------------------------------------------------------------------
/// \anchor UsdShadeNodeDefAPI_ImplementationSource
/// \name Shader Source API
///
/// This section provides API for identifying the source of a shader's
/// implementation.
///
/// @{
/// 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
/// * <b>id</b>, to indicate that the "info:id" attribute must be
/// consulted.
/// * <b>sourceAsset</b> to indicate that the asset-valued
/// "info:{sourceType}:sourceAsset" attribute associated with the desired
/// <b>sourceType</b> should be consulted to locate the asset with the
/// shader's source.
/// * <b>sourceCode</b> to indicate that the string-valued
/// "info:{sourceType}:sourceCode" attribute associated with the desired
/// <b>sourceType</b> should be read to get shader's source.
///
/// This issues a warning and returns <b>id</b> if the
/// <i>info:implementationSource</i> attribute has an invalid value.
///
/// <i>{sourceType}</i> 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 (\ref 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.
///
/// \sa GetShaderId()
/// \sa GetSourceAsset()
/// \sa GetSourceCode()
USDSHADE_API
TfToken GetImplementationSource() const;
/// Sets the shader's ID value. This also sets the
/// <i>info:implementationSource</i> attribute on the shader to
/// <b>UsdShadeTokens->id</b>, if the existing value is different.
USDSHADE_API
bool SetShaderId(const TfToken &id) const;
/// Fetches the shader's ID value from the <i>info:id</i> attribute, if the
/// shader's <i>info:implementationSource</i> is <b>id</b>.
///
/// Returns <b>true</b> if the shader's implementation source is <b>id</b>
/// and the value was fetched properly into \p id. Returns false otherwise.
///
/// \sa GetImplementationSource()
USDSHADE_API
bool GetShaderId(TfToken *id) const;
/// Sets the shader's source-asset path value to \p sourceAsset for the
/// given source type, \p sourceType.
///
/// This also sets the <i>info:implementationSource</i> attribute on the
/// shader to <b>UsdShadeTokens->sourceAsset</b>.
USDSHADE_API
bool SetSourceAsset(
const SdfAssetPath &sourceAsset,
const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
/// Fetches the shader's source asset value for the specified
/// \p sourceType value from the <b>info:<i>sourceType:</i>sourceAsset</b>
/// attribute, if the shader's <i>info:implementationSource</i> is
/// <b>sourceAsset</b>.
///
/// If the <i>sourceAsset</i> attribute corresponding to the requested
/// <i>sourceType</i> isn't present on the shader, then the <i>universal</i>
/// <i>fallback</i> sourceAsset attribute, i.e. <i>info:sourceAsset</i> is
/// consulted, if present, to get the source asset path.
///
/// Returns <b>true</b> if the shader's implementation source is
/// <b>sourceAsset</b> and the source asset path value was fetched
/// successfully into \p sourceAsset. Returns false otherwise.
///
/// \sa GetImplementationSource()
USDSHADE_API
bool GetSourceAsset(
SdfAssetPath *sourceAsset,
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 <b>info:<i>sourceType:</i>sourceAsset:subIdentifier
/// </b>.
///
/// This also sets the <i>info:implementationSource</i> attribute on the
/// shader to <b>UsdShadeTokens->sourceAsset</b>
USDSHADE_API
bool SetSourceAssetSubIdentifier(
const TfToken &subIdentifier,
const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
/// Fetches the shader's sub-identifier for the source asset with the
/// specified \p sourceType value from the <b>info:<i>sourceType:</i>
/// sourceAsset:subIdentifier</b> attribute, if the shader's <i>info:
/// implementationSource</i> is <b>sourceAsset</b>.
///
/// If the <i>subIdentifier</i> attribute corresponding to the requested
/// <i>sourceType</i> isn't present on the shader, then the <i>universal</i>
/// <i>fallback</i> sub-identifier attribute, i.e. <i>info:sourceAsset:
/// subIdentifier</i> is consulted, if present, to get the sub-identifier
/// name.
///
/// Returns <b>true</b> if the shader's implementation source is
/// <b>sourceAsset</b> and the sub-identifier for the given source type was
/// fetched successfully into \p subIdentifier. Returns false otherwise.
USDSHADE_API
bool GetSourceAssetSubIdentifier(
TfToken *subIdentifier,
const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
/// Sets the shader's source-code value to \p sourceCode for the given
/// source type, \p sourceType.
///
/// This also sets the <i>info:implementationSource</i> attribute on the
/// shader to <b>UsdShadeTokens->sourceCode</b>.
USDSHADE_API
bool SetSourceCode(
const std::string &sourceCode,
const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
/// Fetches the shader's source code for the specified \p sourceType value
/// by reading the <b>info:<i>sourceType:</i>sourceCode</b> attribute, if
/// the shader's <i>info:implementationSource</i> is <b>sourceCode</b>.
///
/// If the <i>sourceCode</i> attribute corresponding to the
/// requested <i>sourceType</i> isn't present on the shader, then the
/// <i>universal</i> or <i>fallback</i> sourceCode attribute (i.e.
/// <i>info:sourceCode</i>) is consulted, if present, to get the source
/// code.
///
/// Returns <b>true</b> if the shader's implementation source is
/// <b>sourceCode</b> and the source code string was fetched successfully
/// into \p sourceCode. Returns false otherwise.
///
/// \sa GetImplementationSource()
USDSHADE_API
bool GetSourceCode(
std::string *sourceCode,
const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
/// @}
// -------------------------------------------------------------------------
/// This method attempts to ensure that there is a ShaderNode in the shader
/// registry (i.e. \ref SdrRegistry) representing this shader for the
/// given \p sourceType. It may return a null pointer if none could be
/// found or created.
USDSHADE_API
SdrShaderNodeConstPtr GetShaderNodeForSourceType(const TfToken &sourceType)
const;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+386
View File
@@ -0,0 +1,386 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSHADE_GENERATED_NODEGRAPH_H
#define USDSHADE_GENERATED_NODEGRAPH_H
/// \file usdShade/nodeGraph.h
#include "pxr/pxr.h"
#include "pxr/usd/usdShade/api.h"
#include "pxr/usd/usd/typed.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/stage.h"
#include <utility>
#include "pxr/usd/usd/editTarget.h"
#include "pxr/usd/usd/relationship.h"
#include "pxr/usd/usdShade/input.h"
#include "pxr/usd/usdShade/output.h"
#include "pxr/usd/usdShade/shader.h"
#include "pxr/usd/usdShade/connectableAPIBehavior.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class SdfAssetPath;
// -------------------------------------------------------------------------- //
// NODEGRAPH //
// -------------------------------------------------------------------------- //
/// \class UsdShadeNodeGraph
///
/// A node-graph is a container for shading nodes, as well as other
/// node-graphs. It has a public input interface and provides a list of public
/// outputs.
///
/// <b>Node Graph Interfaces</b>
///
/// One of the most important functions of a node-graph is to host the "interface"
/// with which clients of already-built shading networks will interact. Please
/// see \ref UsdShadeNodeGraph_Interfaces "Interface Inputs" for a detailed
/// explanation of what the interface provides, and how to construct and
/// use it, to effectively share/instance shader networks.
///
/// <b>Node Graph Outputs</b>
///
/// These behave like outputs on a shader and are typically connected to an
/// output on a shader inside the node-graph.
///
///
class UsdShadeNodeGraph : public UsdTyped
{
public:
/// Compile time constant representing what kind of schema this class is.
///
/// \sa UsdSchemaKind
static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped;
/// Construct a UsdShadeNodeGraph on UsdPrim \p prim .
/// Equivalent to UsdShadeNodeGraph::Get(prim.GetStage(), prim.GetPath())
/// for a \em valid \p prim, but will not immediately throw an error for
/// an invalid \p prim
explicit UsdShadeNodeGraph(const UsdPrim& prim=UsdPrim())
: UsdTyped(prim)
{
}
/// Construct a UsdShadeNodeGraph on the prim held by \p schemaObj .
/// Should be preferred over UsdShadeNodeGraph(schemaObj.GetPrim()),
/// as it preserves SchemaBase state.
explicit UsdShadeNodeGraph(const UsdSchemaBase& schemaObj)
: UsdTyped(schemaObj)
{
}
/// Destructor.
USDSHADE_API
virtual ~UsdShadeNodeGraph();
/// 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.
USDSHADE_API
static const TfTokenVector &
GetSchemaAttributeNames(bool includeInherited=true);
/// Return a UsdShadeNodeGraph holding the prim adhering to this
/// schema at \p path on \p stage. If no prim exists at \p path on
/// \p 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:
///
/// \code
/// UsdShadeNodeGraph(stage->GetPrimAtPath(path));
/// \endcode
///
USDSHADE_API
static UsdShadeNodeGraph
Get(const UsdStagePtr &stage, const SdfPath &path);
/// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
/// is defined (according to UsdPrim::IsDefined()) on this stage.
///
/// If a prim adhering to this schema at \p path is already defined on this
/// stage, return that prim. Otherwise author an \a SdfPrimSpec with
/// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
/// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
/// with \p specifier == \a SdfSpecifierDef and empty typeName at the
/// current EditTarget for any nonexistent, or existing but not \a Defined
/// ancestors.
///
/// The given \a path must be an absolute prim path that does not contain
/// any variant selections.
///
/// If it is impossible to author any of the necessary PrimSpecs, (for
/// example, in case \a path cannot map to the current UsdEditTarget's
/// namespace) issue an error and return an invalid \a UsdPrim.
///
/// Note that this method may return a defined prim whose typeName does not
/// specify this schema class, in case a stronger typeName opinion overrides
/// the opinion at the current EditTarget.
///
USDSHADE_API
static UsdShadeNodeGraph
Define(const UsdStagePtr &stage, const SdfPath &path);
protected:
/// Returns the kind of schema this class belongs to.
///
/// \sa UsdSchemaKind
USDSHADE_API
UsdSchemaKind _GetSchemaKind() const override;
private:
// needs to invoke _GetStaticTfType.
friend class UsdSchemaRegistry;
USDSHADE_API
static const TfType &_GetStaticTfType();
static bool _IsTypedSchema();
// override SchemaBase virtuals.
USDSHADE_API
const TfType &_GetTfType() const override;
public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
// the code generator.
//
// Just remember to:
// - Close the class declaration with };
// - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
// - Close the include guard with #endif
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
/// Constructor that takes a ConnectableAPI object.
/// Allow implicit (auto) conversion of UsdShadeNodeGraph to
/// UsdShadeConnectableAPI, so that a NodeGraph can be passed into any
/// function that accepts a ConnectableAPI.
USDSHADE_API
UsdShadeNodeGraph(const UsdShadeConnectableAPI &connectable);
/// Contructs and returns a UsdShadeConnectableAPI object with this
/// node-graph.
///
/// Note that most tasks can be accomplished without explicitly constructing
/// a UsdShadeConnectable API, since connection-related API such as
/// UsdShadeConnectableAPI::ConnectToSource() are static methods, and
/// UsdShadeNodeGraph will auto-convert to a UsdShadeConnectableAPI when
/// passed to functions that want to act generically on a connectable
/// UsdShadeConnectableAPI object.
USDSHADE_API
UsdShadeConnectableAPI ConnectableAPI() const;
/// \anchor UsdShadeNodeGraph_Output
/// \name Outputs of a node-graph. These typically connect to outputs of
/// shaders or nested node-graphs within the node-graph.
///
/// @{
/// Create an output which can either have a value or can be connected.
/// The attribute representing the output is created in the "outputs:"
/// namespace.
///
USDSHADE_API
UsdShadeOutput CreateOutput(const TfToken& name,
const SdfValueTypeName& typeName) const;
/// Return the requested output if it exists.
///
USDSHADE_API
UsdShadeOutput GetOutput(const TfToken &name) const;
/// Outputs are represented by attributes in the "outputs:" namespace.
/// If \p onlyAuthored is true (the default), then only return authored
/// attributes; otherwise, this also returns un-authored builtins.
///
USDSHADE_API
std::vector<UsdShadeOutput> GetOutputs(bool onlyAuthored=true) const;
/// \deprecated in favor of GetValueProducingAttributes on UsdShadeOutput
/// Resolves the connection source of the requested output, identified by
/// \p outputName to a shader output.
///
/// \p sourceName is an output parameter that is set to the name of the
/// resolved output, if the node-graph output is connected to a valid
/// shader source.
///
/// \p sourceType is an output parameter that is set to the type of the
/// resolved output, if the node-graph output is connected to a valid
/// shader source.
///
/// \return Returns a valid shader object if the specified output exists and
/// is connected to one. Return an empty shader object otherwise.
/// The python version of this method returns a tuple containing three
/// elements (the source shader, sourceName, sourceType).
USDSHADE_API
UsdShadeShader ComputeOutputSource(
const TfToken &outputName,
TfToken *sourceName,
UsdShadeAttributeType *sourceType) const;
/// @}
/// \anchor UsdShadeNodeGraph_Interfaces
/// \name Interface inputs of a node-graph.
///
/// In addition to serving as the "head" for all of the shading networks
/// that describe each render target's particular node-graph, the node-graph
/// prim provides a unified "interface" that allows node-graphs to share
/// shading networks while retaining the ability for each to specify its own
/// set of unique values for the interface inputs that users may need to
/// modify.
///
/// A "Node-graph Interface" is a combination of:
/// \li a flat collection of attributes, of arbitrary names
/// \li for each such attribute, a list of UsdShaderInput targets
/// whose attributes on Shader prims should be driven by the interface
/// input.
///
/// A single interface input can drive multiple shader inputs and be
/// consumed by multiple render targets. The set of interface inputs itself
/// is intentionally flat, to encourage sharing of the interface between
/// render targets. Clients are always free to create interface inputs with
/// namespacing to segregate "private" attributes exclusive to the render
/// target, but we hope this will be an exception.
///
/// To facilitate connecting, qualifying, and interrogating interface
/// attributes, we use the attribute schema UsdShadeInput, which also
/// serves as an abstraction for shader inputs.
///
/// <b>Scoped Interfaces</b>
///
/// \todo describe scoped interfaces and fix bug/108940 to account for them.
///
/// @{
/// Create an Input which can either have a value or can be connected.
/// The attribute representing the input is created in the "inputs:"
/// namespace.
///
/// \todo clarify error behavior if typeName does not match existing,
/// defined attribute - should match UsdPrim::CreateAttribute - bug/108970
///
USDSHADE_API
UsdShadeInput CreateInput(const TfToken& name,
const SdfValueTypeName& typeName) const;
/// Return the requested input if it exists.
///
USDSHADE_API
UsdShadeInput GetInput(const TfToken &name) const;
/// Returns all inputs present on the node-graph. These are represented by
/// attributes in the "inputs:" namespace.
/// If \p onlyAuthored is true (the default), then only return authored
/// attributes; otherwise, this also returns un-authored builtins.
///
USDSHADE_API
std::vector<UsdShadeInput> GetInputs(bool onlyAuthored=true) const;
/// @}
// Provide custom hash and equality comparison function objects for
// UsdShadeNodeGraph until bug 143077 is resolved.
/// Hash functor for UsdShadeNodeGraph objects.
struct NodeGraphHasher {
inline size_t operator()(const UsdShadeNodeGraph &nodeGraph) const {
return hash_value(nodeGraph.GetPrim());
}
};
/// Equality comparator for UsdShadeNodeGraph objects.
struct NodeGraphEqualFn
{
inline bool operator() (UsdShadeNodeGraph const& s1,
UsdShadeNodeGraph const& s2) const
{
return s1.GetPrim() == s2.GetPrim();
}
};
// ---------------------------------------------------------------------- //
/// \anchor UsdShadeNodeGraph_InterfaceInputs
/// \name Interface Inputs
///
/// API to query the inputs that form the interface of the node-graph and
/// their connections.
///
/// @{
/// Returns all the "Interface Inputs" of the node-graph. This is the same
/// as GetInputs(), but is provided as a convenience, to allow clients to
/// distinguish between inputs on shaders vs. interface-inputs on
/// node-graphs.
USDSHADE_API
std::vector<UsdShadeInput> GetInterfaceInputs() const;
/// Map of interface inputs to corresponding vectors of inputs that
/// consume their values.
typedef std::unordered_map<UsdShadeInput, std::vector<UsdShadeInput>,
UsdShadeInput::Hash> InterfaceInputConsumersMap;
/// Map of node-graphs to their associated input-consumers map.
typedef std::unordered_map<UsdShadeNodeGraph,
InterfaceInputConsumersMap,
NodeGraphHasher,
NodeGraphEqualFn>
NodeGraphInputConsumersMap;
/// Walks the namespace subtree below the node-graph and computes a map
/// containing the list of all inputs on the node-graph and the associated
/// vector of consumers of their values. The consumers can be inputs on
/// shaders within the node-graph or on nested node-graphs).
///
/// If \p computeTransitiveConsumers is true, then value consumers
/// belonging to <b>node-graphs</b> are resolved transitively to compute the
/// transitive mapping from inputs on the node-graph to inputs on shaders
/// inside the material. Note that inputs on node-graphs that don't have
/// value consumers will continue to be included in the result.
///
/// This API is provided for use by DCC's that want to present node-graph
/// interface / shader connections in the opposite direction than they are
/// encoded in USD.
///
USDSHADE_API
InterfaceInputConsumersMap ComputeInterfaceInputConsumersMap(
bool computeTransitiveConsumers=false) const;
/// @}
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+448
View File
@@ -0,0 +1,448 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SHADE_OUTPUT_H
#define PXR_USD_USD_SHADE_OUTPUT_H
#include "pxr/pxr.h"
#include "pxr/usd/usdShade/api.h"
#include "pxr/usd/usdShade/types.h"
#include "pxr/usd/usdShade/utils.h"
#include "pxr/usd/usd/attribute.h"
#include "pxr/usd/ndr/declare.h"
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
class UsdShadeConnectableAPI;
struct UsdShadeConnectionSourceInfo;
class UsdShadeInput;
/// \class UsdShadeOutput
///
/// This class encapsulates a shader or node-graph output, which is a
/// connectable attribute representing a typed, externally computed value.
///
class UsdShadeOutput
{
public:
/// Default constructor returns an invalid Output. Exists for
/// container classes
UsdShadeOutput()
{
// nothing
}
/// Get the name of the attribute associated with the output.
///
TfToken const &GetFullName() const {
return _attr.GetName();
}
/// Returns the name of the output.
///
/// We call this the base name since it strips off the "outputs:" namespace
/// prefix from the attribute name, and returns it.
///
USDSHADE_API
TfToken GetBaseName() const;
/// Get the prim that the output belongs to.
UsdPrim GetPrim() const {
return _attr.GetPrim();
}
/// Get the "scene description" value type name of the attribute associated
/// with the output.
///
USDSHADE_API
SdfValueTypeName GetTypeName() const;
/// Set a value for the output.
///
/// It's unusual to be setting a value on an output since it represents
/// an externally computed value. The Set API is provided here just for the
/// sake of completeness and uniformity with other property schema.
///
USDSHADE_API
bool Set(const VtValue& value,
UsdTimeCode time = UsdTimeCode::Default()) const;
/// \overload
/// Set the attribute value of the Output at \p time
///
template <typename T>
bool Set(const T& value, UsdTimeCode time = UsdTimeCode::Default()) const {
if (UsdAttribute attr = GetAttr()) {
return attr.Set(value, time);
}
return false;
}
/// \name Configuring the Output's Type
/// @{
/// Specify an alternative, renderer-specific type to use when
/// emitting/translating this output, rather than translating based
/// on its GetTypeName()
///
/// For example, we set the renderType to "struct" for outputs that
/// are of renderman custom struct types.
///
/// \return true on success
USDSHADE_API
bool SetRenderType(TfToken const& renderType) const;
/// Return this output's specialized renderType, or an empty
/// token if none was authored.
///
/// \sa SetRenderType()
USDSHADE_API
TfToken GetRenderType() const;
/// Return true if a renderType has been specified for this
/// output.
///
/// \sa SetRenderType()
USDSHADE_API
bool HasRenderType() const;
/// @}
/// \name API to author and query an Output's sdrMetadata
///
/// This section provides API for authoring and querying shader registry
/// metadata on an Output. When the owning shader prim is providing a shader
/// definition, the authored "sdrMetadata" dictionary value provides
/// metadata needed to populate the Output correctly in the shader registry.
///
/// We expect the keys in sdrMetadata to correspond to the keys
/// in \ref SdrPropertyMetadata. However, this is not strictly enforced by
/// the API. The only allowed value type in the "sdrMetadata" dictionary is
/// a std::string since it needs to be converted into a NdrTokenMap, which
/// Sdr will parse using the utilities available in \ref SdrMetadataHelpers.
///
/// @{
/// Returns this Output's composed "sdrMetadata" dictionary as a
/// NdrTokenMap.
USDSHADE_API
NdrTokenMap GetSdrMetadata() const;
/// Returns the value corresponding to \p key in the composed
/// <b>sdrMetadata</b> dictionary.
USDSHADE_API
std::string GetSdrMetadataByKey(const TfToken &key) const;
/// Authors the given \p sdrMetadata value on this Output at the current
/// EditTarget.
USDSHADE_API
void SetSdrMetadata(const NdrTokenMap &sdrMetadata) const;
/// Sets the value corresponding to \p key to the given string \p value, in
/// the Output's "sdrMetadata" dictionary at the current EditTarget.
USDSHADE_API
void SetSdrMetadataByKey(
const TfToken &key,
const std::string &value) const;
/// Returns true if the Output has a non-empty composed "sdrMetadata"
/// dictionary value.
USDSHADE_API
bool HasSdrMetadata() const;
/// Returns true if there is a value corresponding to the given \p key in
/// the composed "sdrMetadata" dictionary.
USDSHADE_API
bool HasSdrMetadataByKey(const TfToken &key) const;
/// Clears any "sdrMetadata" value authored on the Output in the current
/// EditTarget.
USDSHADE_API
void ClearSdrMetadata() const;
/// Clears the entry corresponding to the given \p key in the
/// "sdrMetadata" dictionary authored in the current EditTarget.
USDSHADE_API
void ClearSdrMetadataByKey(const TfToken &key) const;
/// @}
// ---------------------------------------------------------------
/// \name UsdAttribute API
// ---------------------------------------------------------------
/// @{
/// Speculative constructor that will produce a valid UsdShadeOutput when
/// \p attr already represents a shade Output, and produces an \em invalid
/// UsdShadeOutput otherwise (i.e. the explicit bool conversion operator
/// will return false).
USDSHADE_API
explicit UsdShadeOutput(const UsdAttribute &attr);
/// Test whether a given UsdAttribute represents a valid Output, which
/// implies that creating a UsdShadeOutput from the attribute will succeed.
///
/// Success implies that \c attr.IsDefined() is true.
USDSHADE_API
static bool IsOutput(const UsdAttribute &attr);
/// Explicit UsdAttribute extractor.
UsdAttribute GetAttr() const { return _attr; }
/// Allow UsdShadeOutput to auto-convert to UsdAttribute, so you can
/// pass a UsdShadeOutput to any function that accepts a UsdAttribute or
/// const-ref thereto.
operator UsdAttribute () const { return GetAttr(); }
/// Return true if the wrapped UsdAttribute is defined, and in
/// addition the attribute is identified as an output.
///
bool IsDefined() const {
return IsOutput(_attr);
}
/// @}
// -------------------------------------------------------------------------
/// \name Connections API
// -------------------------------------------------------------------------
/// @{
/// Determines whether this Output can be connected to the given
/// source attribute, which can be an input or an output.
///
/// An output is considered to be connectable only if it belongs to a
/// node-graph. Shader outputs are not connectable.
///
/// \sa UsdShadeConnectableAPI::CanConnect
USDSHADE_API
bool CanConnect(const UsdAttribute &source) const;
/// \overload
USDSHADE_API
bool CanConnect(const UsdShadeInput &sourceInput) const;
/// \overload
USDSHADE_API
bool CanConnect(const UsdShadeOutput &sourceOutput) const;
using ConnectionModification = UsdShadeConnectionModification;
/// Authors a connection for this Output
///
/// \p source is a struct that describes the upstream source attribute
/// with all the information necessary to make a connection. See the
/// documentation for UsdShadeConnectionSourceInfo.
/// \p mod describes the operation that should be applied to the list of
/// connections. By default the new connection will replace any existing
/// connections, but it can add to the list of connections to represent
/// multiple input connections.
///
/// \return
/// \c true if a connection was created successfully.
/// \c false if \p shadingAttr or \p source is invalid.
///
/// \note This method does not verify the connectability of the shading
/// attribute to the source. Clients must invoke CanConnect() themselves
/// to ensure compatibility.
/// \note The source shading attribute is created if it doesn't exist
/// already.
///
/// \sa UsdShadeConnectableAPI::ConnectToSource
///
USDSHADE_API
bool ConnectToSource(
UsdShadeConnectionSourceInfo const &source,
ConnectionModification const mod =
ConnectionModification::Replace) const;
/// \deprecated
/// \overload
USDSHADE_API
bool ConnectToSource(
UsdShadeConnectableAPI const &source,
TfToken const &sourceName,
UsdShadeAttributeType const sourceType=UsdShadeAttributeType::Output,
SdfValueTypeName typeName=SdfValueTypeName()) const;
/// Authors a connection for this Output to the source at the given path.
///
/// \sa UsdShadeConnectableAPI::ConnectToSource
///
USDSHADE_API
bool ConnectToSource(SdfPath const &sourcePath) const;
/// Connects this Output to the given input, \p sourceInput.
///
/// \sa UsdShadeConnectableAPI::ConnectToSource
///
USDSHADE_API
bool ConnectToSource(UsdShadeInput const &sourceInput) const;
/// Connects this Output to the given output, \p sourceOutput.
///
/// \sa UsdShadeConnectableAPI::ConnectToSource
///
USDSHADE_API
bool ConnectToSource(UsdShadeOutput const &sourceOutput) const;
/// Connects this Output to the given sources, \p sourceInfos
///
/// \sa UsdShadeConnectableAPI::SetConnectedSources
///
USDSHADE_API
bool SetConnectedSources(
std::vector<UsdShadeConnectionSourceInfo> const &sourceInfos) const;
// XXX move to new header
using SourceInfoVector = TfSmallVector<UsdShadeConnectionSourceInfo, 1>;
/// Finds the valid sources of connections for the Output.
///
/// \p invalidSourcePaths is an optional output parameter to collect the
/// invalid source paths that have not been reported in the returned vector.
///
/// Returns a vector of \p UsdShadeConnectionSourceInfo structs with
/// information about each upsteam attribute. If the vector is empty, there
/// have been no valid connections.
///
/// \note A valid connection requires the existence of the source attribute
/// and also requires that the source prim is UsdShadeConnectableAPI
/// compatible.
/// \note The python wrapping returns a tuple with the valid connections
/// first, followed by the invalid source paths.
///
/// \sa UsdShadeConnectableAPI::GetConnectedSources
///
USDSHADE_API
SourceInfoVector GetConnectedSources(
SdfPathVector *invalidSourcePaths = nullptr) const;
/// \deprecated Please use GetConnectedSources instead
USDSHADE_API
bool GetConnectedSource(UsdShadeConnectableAPI *source,
TfToken *sourceName,
UsdShadeAttributeType *sourceType) const;
/// \deprecated
/// Returns the "raw" (authored) connected source paths for this Output.
///
/// \sa UsdShadeConnectableAPI::GetRawConnectedSourcePaths
///
USDSHADE_API
bool GetRawConnectedSourcePaths(SdfPathVector *sourcePaths) const;
/// Returns true if and only if this Output is currently connected to a
/// valid (defined) source.
///
/// \sa UsdShadeConnectableAPI::HasConnectedSource
///
USDSHADE_API
bool HasConnectedSource() const;
/// Returns true if the connection to this Output's source, as returned by
/// GetConnectedSource(), is authored across a specializes arc, which is
/// used to denote a base material.
///
/// \sa UsdShadeConnectableAPI::IsSourceConnectionFromBaseMaterial
///
USDSHADE_API
bool IsSourceConnectionFromBaseMaterial() const;
/// Disconnect source for this Output. If \p sourceAttr is valid, only a
/// connection to the specified attribute is disconnected, otherwise all
/// connections are removed.
///
/// \sa UsdShadeConnectableAPI::DisconnectSource
///
USDSHADE_API
bool DisconnectSource(UsdAttribute const &sourceAttr = UsdAttribute()) const;
/// Clears sources for this Output in the current UsdEditTarget.
///
/// Most of the time, what you probably want is DisconnectSource()
/// rather than this function.
///
/// \sa UsdShadeConnectableAPI::ClearSources
///
USDSHADE_API
bool ClearSources() const;
/// \deprecated
USDSHADE_API
bool ClearSource() const;
/// @}
// -------------------------------------------------------------------------
/// \name Connected Value API
// -------------------------------------------------------------------------
/// @{
/// \brief Find what is connected to this Output recursively
///
/// \sa UsdShadeUtils::GetValueProducingAttributes
USDSHADE_API
UsdShadeAttributeVector GetValueProducingAttributes(
bool shaderOutputsOnly = false) const;
/// @}
/// Return true if this Output is valid for querying and authoring
/// values and metadata, which is identically equivalent to IsDefined().
explicit operator bool() const {
return IsDefined();
}
/// Equality comparison. Returns true if \a lhs and \a rhs represent the
/// same UsdShadeOutput, false otherwise.
friend bool operator==(const UsdShadeOutput &lhs, const UsdShadeOutput &rhs) {
return lhs.GetAttr() == rhs.GetAttr();
}
/// Inequality comparison. Return false if \a lhs and \a rhs represent the
/// same UsdShadeOutput, true otherwise.
friend bool operator!=(const UsdShadeOutput &lhs, const UsdShadeOutput &rhs) {
return !(lhs == rhs);
}
private:
friend class UsdShadeConnectableAPI;
// Constructor that creates a UsdShadeOutput with the given name on the
// given prim.
// \p name here is the unnamespaced name of the output.
UsdShadeOutput(UsdPrim prim,
TfToken const &name,
SdfValueTypeName const &typeName);
UsdAttribute _attr;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_USD_SHADE_OUTPUT_H
+426
View File
@@ -0,0 +1,426 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSHADE_GENERATED_SHADER_H
#define USDSHADE_GENERATED_SHADER_H
/// \file usdShade/shader.h
#include "pxr/pxr.h"
#include "pxr/usd/usdShade/api.h"
#include "pxr/usd/usd/typed.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usdShade/input.h"
#include "pxr/usd/usdShade/output.h"
#include "pxr/usd/usdShade/tokens.h"
#include "pxr/usd/ndr/declare.h"
#include "pxr/usd/sdr/shaderNode.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class SdfAssetPath;
// -------------------------------------------------------------------------- //
// SHADER //
// -------------------------------------------------------------------------- //
/// \class UsdShadeShader
///
/// Base class for all USD shaders. Shaders are the building blocks
/// of shading networks. While UsdShadeShader objects are not target specific,
/// each renderer or application target may derive its own renderer-specific
/// shader object types from this base, if needed.
///
/// Objects of this class generally represent a single shading object, whether
/// it exists in the target renderer or not. For example, a texture, a fractal,
/// or a mix node.
///
/// The UsdShadeNodeDefAPI provides attributes to uniquely identify the
/// type of this node. The id resolution into a renderable shader target
/// type of this node. The id resolution into a renderable shader target
/// is deferred to the consuming application.
///
/// The purpose of representing them in Usd is two-fold:
/// \li To represent, via "connections" the topology of the shading network
/// that must be reconstructed in the renderer. Facilities for authoring and
/// manipulating connections are encapsulated in the API schema
/// UsdShadeConnectableAPI.
/// \li To present a (partial or full) interface of typed input parameters
/// whose values can be set and overridden in Usd, to be provided later at
/// render-time as parameter values to the actual render shader objects. Shader
/// input parameters are encapsulated in the property schema UsdShadeInput.
///
///
class UsdShadeShader : public UsdTyped
{
public:
/// Compile time constant representing what kind of schema this class is.
///
/// \sa UsdSchemaKind
static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped;
/// Construct a UsdShadeShader on UsdPrim \p prim .
/// Equivalent to UsdShadeShader::Get(prim.GetStage(), prim.GetPath())
/// for a \em valid \p prim, but will not immediately throw an error for
/// an invalid \p prim
explicit UsdShadeShader(const UsdPrim& prim=UsdPrim())
: UsdTyped(prim)
{
}
/// Construct a UsdShadeShader on the prim held by \p schemaObj .
/// Should be preferred over UsdShadeShader(schemaObj.GetPrim()),
/// as it preserves SchemaBase state.
explicit UsdShadeShader(const UsdSchemaBase& schemaObj)
: UsdTyped(schemaObj)
{
}
/// Destructor.
USDSHADE_API
virtual ~UsdShadeShader();
/// 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.
USDSHADE_API
static const TfTokenVector &
GetSchemaAttributeNames(bool includeInherited=true);
/// Return a UsdShadeShader holding the prim adhering to this
/// schema at \p path on \p stage. If no prim exists at \p path on
/// \p 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:
///
/// \code
/// UsdShadeShader(stage->GetPrimAtPath(path));
/// \endcode
///
USDSHADE_API
static UsdShadeShader
Get(const UsdStagePtr &stage, const SdfPath &path);
/// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
/// is defined (according to UsdPrim::IsDefined()) on this stage.
///
/// If a prim adhering to this schema at \p path is already defined on this
/// stage, return that prim. Otherwise author an \a SdfPrimSpec with
/// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
/// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
/// with \p specifier == \a SdfSpecifierDef and empty typeName at the
/// current EditTarget for any nonexistent, or existing but not \a Defined
/// ancestors.
///
/// The given \a path must be an absolute prim path that does not contain
/// any variant selections.
///
/// If it is impossible to author any of the necessary PrimSpecs, (for
/// example, in case \a path cannot map to the current UsdEditTarget's
/// namespace) issue an error and return an invalid \a UsdPrim.
///
/// Note that this method may return a defined prim whose typeName does not
/// specify this schema class, in case a stronger typeName opinion overrides
/// the opinion at the current EditTarget.
///
USDSHADE_API
static UsdShadeShader
Define(const UsdStagePtr &stage, const SdfPath &path);
protected:
/// Returns the kind of schema this class belongs to.
///
/// \sa UsdSchemaKind
USDSHADE_API
UsdSchemaKind _GetSchemaKind() const override;
private:
// needs to invoke _GetStaticTfType.
friend class UsdSchemaRegistry;
USDSHADE_API
static const TfType &_GetStaticTfType();
static bool _IsTypedSchema();
// override SchemaBase virtuals.
USDSHADE_API
const TfType &_GetTfType() const override;
public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
// the code generator.
//
// Just remember to:
// - Close the class declaration with };
// - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
// - Close the include guard with #endif
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
// -------------------------------------------------------------------------
/// \name Conversion to and from UsdShadeConnectableAPI
///
/// @{
/// Constructor that takes a ConnectableAPI object.
/// Allow implicit (auto) conversion of UsdShadeShader to
/// UsdShadeConnectableAPI, so that a shader can be passed into any function
/// that accepts a ConnectableAPI.
USDSHADE_API
UsdShadeShader(const UsdShadeConnectableAPI &connectable);
/// Contructs and returns a UsdShadeConnectableAPI object with this shader.
///
/// Note that most tasks can be accomplished without explicitly constructing
/// a UsdShadeConnectable API, since connection-related API such as
/// UsdShadeConnectableAPI::ConnectToSource() are static methods, and
/// UsdShadeShader will auto-convert to a UsdShadeConnectableAPI when
/// passed to functions that want to act generically on a connectable
/// UsdShadeConnectableAPI object.
USDSHADE_API
UsdShadeConnectableAPI ConnectableAPI() const;
/// @}
// -------------------------------------------------------------------------
/// \name Outputs API
///
/// Outputs represent a typed attribute on a shader or node-graph whose value
/// is computed externally.
///
/// When they exist on a node-graph, they are connectable and are typically
/// connected to the output of a shader within the node-graph.
///
/// @{
/// Create an output which can either have a value or can be connected.
/// The attribute representing the output is created in the "outputs:"
/// namespace. Outputs on a shader cannot be connected, as their
/// value is assumed to be computed externally.
///
USDSHADE_API
UsdShadeOutput CreateOutput(const TfToken& name,
const SdfValueTypeName& typeName);
/// Return the requested output if it exists.
///
USDSHADE_API
UsdShadeOutput GetOutput(const TfToken &name) const;
/// Outputs are represented by attributes in the "outputs:" namespace.
/// If \p onlyAuthored is true (the default), then only return authored
/// attributes; otherwise, this also returns un-authored builtins.
///
USDSHADE_API
std::vector<UsdShadeOutput> GetOutputs(bool onlyAuthored=true) const;
/// @}
// -------------------------------------------------------------------------
/// \name Inputs API
///
/// Inputs are connectable attribute with a typed value.
///
/// On shaders, the shader parameters are encoded as inputs. On node-graphs,
/// interface attributes are represented as inputs.
///
/// @{
/// Create an input which can either have a value or can be connected.
/// The attribute representing the input is created in the "inputs:"
/// namespace. Inputs on both shaders and node-graphs are connectable.
///
USDSHADE_API
UsdShadeInput CreateInput(const TfToken& name,
const SdfValueTypeName& typeName);
/// Return the requested input if it exists.
///
USDSHADE_API
UsdShadeInput GetInput(const TfToken &name) const;
/// Inputs are represented by attributes in the "inputs:" namespace.
/// If \p onlyAuthored is true (the default), then only return authored
/// attributes; otherwise, this also returns un-authored builtins.
///
USDSHADE_API
std::vector<UsdShadeInput> GetInputs(bool onlyAuthored=true) const;
/// @}
// -------------------------------------------------------------------------
/// \name UsdShadeNodeDefAPI forwarding
///
/// @{
/// Forwards to UsdShadeNodeDefAPI(prim).
USDSHADE_API
UsdAttribute GetImplementationSourceAttr() const;
/// Forwards to UsdShadeNodeDefAPI(prim).
USDSHADE_API
UsdAttribute CreateImplementationSourceAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
/// Forwards to UsdShadeNodeDefAPI(prim).
USDSHADE_API
UsdAttribute GetIdAttr() const;
/// Forwards to UsdShadeNodeDefAPI(prim).
USDSHADE_API
UsdAttribute CreateIdAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
/// Forwards to UsdShadeNodeDefAPI(prim).
USDSHADE_API
TfToken GetImplementationSource() const;
/// Forwards to UsdShadeNodeDefAPI(prim).
USDSHADE_API
bool SetShaderId(const TfToken &id) const;
/// Forwards to UsdShadeNodeDefAPI(prim).
USDSHADE_API
bool GetShaderId(TfToken *id) const;
/// Forwards to UsdShadeNodeDefAPI(prim).
USDSHADE_API
bool SetSourceAsset(
const SdfAssetPath &sourceAsset,
const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
/// Forwards to UsdShadeNodeDefAPI(prim).
USDSHADE_API
bool GetSourceAsset(
SdfAssetPath *sourceAsset,
const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
/// Forwards to UsdShadeNodeDefAPI(prim).
USDSHADE_API
bool SetSourceAssetSubIdentifier(
const TfToken &subIdentifier,
const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
/// Forwards to UsdShadeNodeDefAPI(prim).
USDSHADE_API
bool GetSourceAssetSubIdentifier(
TfToken *subIdentifier,
const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
/// Forwards to UsdShadeNodeDefAPI(prim).
USDSHADE_API
bool SetSourceCode(
const std::string &sourceCode,
const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
/// Forwards to UsdShadeNodeDefAPI(prim).
USDSHADE_API
bool GetSourceCode(
std::string *sourceCode,
const TfToken &sourceType=UsdShadeTokens->universalSourceType) const;
/// Forwards to UsdShadeNodeDefAPI(prim).
USDSHADE_API
SdrShaderNodeConstPtr GetShaderNodeForSourceType(const TfToken &sourceType)
const;
/// @}
// -------------------------------------------------------------------------
/// \anchor UsdShadeShader_SdrMetadata_API
/// \name Shader Sdr Metadata API
///
/// This section provides API for authoring and querying shader registry
/// metadata. When the shader's implementationSource is <b>sourceAsset</b>
/// or <b>sourceCode</b>, the authored "sdrMetadata" dictionary value
/// provides additional metadata needed to process the shader source
/// correctly. It is used in combination with the sourceAsset or sourceCode
/// value to fetch the appropriate node from the shader registry.
///
/// We expect the keys in sdrMetadata to correspond to the keys
/// in \ref SdrNodeMetadata. However, this is not strictly enforced in the
/// API. The only allowed value type in the "sdrMetadata" dictionary is a
/// std::string since it needs to be converted into a NdrTokenMap, which Sdr
/// will parse using the utilities available in \ref SdrMetadataHelpers.
///
/// @{
/// Returns this shader's composed "sdrMetadata" dictionary as a
/// NdrTokenMap.
USDSHADE_API
NdrTokenMap GetSdrMetadata() const;
/// Returns the value corresponding to \p key in the composed
/// <b>sdrMetadata</b> dictionary.
USDSHADE_API
std::string GetSdrMetadataByKey(const TfToken &key) const;
/// Authors the given \p sdrMetadata on this shader at the current
/// EditTarget.
USDSHADE_API
void SetSdrMetadata(const NdrTokenMap &sdrMetadata) const;
/// Sets the value corresponding to \p key to the given string \p value, in
/// the shader's "sdrMetadata" dictionary at the current EditTarget.
USDSHADE_API
void SetSdrMetadataByKey(
const TfToken &key,
const std::string &value) const;
/// Returns true if the shader has a non-empty composed "sdrMetadata"
/// dictionary value.
USDSHADE_API
bool HasSdrMetadata() const;
/// Returns true if there is a value corresponding to the given \p key in
/// the composed "sdrMetadata" dictionary.
USDSHADE_API
bool HasSdrMetadataByKey(const TfToken &key) const;
/// Clears any "sdrMetadata" value authored on the shader in the current
/// EditTarget.
USDSHADE_API
void ClearSdrMetadata() const;
/// Clears the entry corresponding to the given \p key in the
/// "sdrMetadata" dictionary authored in the current EditTarget.
USDSHADE_API
void ClearSdrMetadataByKey(const TfToken &key) const;
/// @}
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
@@ -0,0 +1,67 @@
//
// Copyright 2018 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SHADE_SHADER_DEF_PARSER_H
#define PXR_USD_USD_SHADE_SHADER_DEF_PARSER_H
#include "pxr/usd/usdShade/api.h"
#include "pxr/usd/ndr/declare.h"
#include "pxr/usd/ndr/discoveryPlugin.h"
#include "pxr/usd/ndr/parserPlugin.h"
PXR_NAMESPACE_OPEN_SCOPE
class UsdStageCache;
/// \class UsdShadeShaderDefParserPlugin
///
/// Parses shader definitions represented using USD scene description using the
/// schemas provided by UsdShade.
///
class UsdShadeShaderDefParserPlugin : public NdrParserPlugin
{
public:
USDSHADE_API
UsdShadeShaderDefParserPlugin() = default;
USDSHADE_API
~UsdShadeShaderDefParserPlugin() override = default;
USDSHADE_API
NdrNodeUniquePtr Parse(const NdrNodeDiscoveryResult &discoveryResult)
override;
USDSHADE_API
const NdrTokenVec &GetDiscoveryTypes() const override;
USDSHADE_API
const TfToken &GetSourceType() const override;
private:
static UsdStageCache _cache;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_USD_SHADE_SHADER_DEF_PARSER_H
+99
View File
@@ -0,0 +1,99 @@
//
// Copyright 2018 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SHADE_SHADER_DEF_UTILS_H
#define PXR_USD_USD_SHADE_SHADER_DEF_UTILS_H
#include "pxr/pxr.h"
#include "pxr/usd/usdShade/api.h"
#include "pxr/usd/usdShade/connectableAPI.h"
#include "pxr/usd/ndr/nodeDiscoveryResult.h"
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
class UsdShadeShader;
/// \class UsdShadeShaderDefUtils
///
/// This class contains a set of utility functions used for populating the
/// shader registry with shaders definitions specified using UsdShade schemas.
///
class UsdShadeShaderDefUtils {
public:
/// Given a shader's \p identifier token, computes the corresponding
/// SdrShaderNode's family name, implementation name and shader version
/// (as NdrVersion).
///
/// * \p familyName is the prefix of \p identifier up to and not
/// including the first underscore.
/// * \p version is the suffix of \p identifier comprised of one or
/// two integers representing the major and minor version numbers.
/// * \p implementationName is the string we get by joining
/// <i>familyName</i> with everything that's in between <i>familyName</i>
/// and <i>version</i> with an underscore.
///
/// Returns true if \p identifier is valid and was successfully split
/// into the different components.
///
/// \note The python version of this function returns a tuple containing
/// (famiyName, implementationName, version).
USDSHADE_API
static bool SplitShaderIdentifier(const TfToken &identifier,
TfToken *familyName,
TfToken *implementationName,
NdrVersion *version);
/// Returns the list of NdrNodeDiscoveryResult objects that must be added
/// to the shader registry for the given shader \p shaderDef, assuming it
/// is found in a shader definition file found by an Ndr discovery plugin.
///
/// To enable the shaderDef parser to find and parse this shader,
/// \p sourceUri should have the resolved path to the usd file containing
/// this shader prim.
USDSHADE_API
static NdrNodeDiscoveryResultVec GetNodeDiscoveryResults(
const UsdShadeShader &shaderDef,
const std::string &sourceUri);
/// Gets all input and output properties of the given \p shaderDef and
/// translates them into NdrProperties that can be used as the properties
/// for an SdrShaderNode.
USDSHADE_API
static NdrPropertyUniquePtrVec GetShaderProperties(
const UsdShadeConnectableAPI &shaderDef);
/// Collects all the names of valid primvar inputs of the given \p metadata
/// and the given \p shaderDef and returns the string used to represent
/// them in SdrShaderNode metadata.
USDSHADE_API
static std::string GetPrimvarNamesMetadataString(
const NdrTokenMap metadata,
const UsdShadeConnectableAPI &shaderDef);
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+197
View File
@@ -0,0 +1,197 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSHADE_TOKENS_H
#define USDSHADE_TOKENS_H
/// \file usdShade/tokens.h
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//
// This is an automatically generated file (by usdGenSchema.py).
// Do not hand-edit!
//
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include "pxr/pxr.h"
#include "pxr/usd/usdShade/api.h"
#include "pxr/base/tf/staticData.h"
#include "pxr/base/tf/token.h"
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \class UsdShadeTokensType
///
/// \link UsdShadeTokens \endlink provides static, efficient
/// \link TfToken TfTokens\endlink for use in all public USD API.
///
/// These tokens are auto-generated from the module's schema, representing
/// property names, for when you need to fetch an attribute or relationship
/// directly by name, e.g. UsdPrim::GetAttribute(), in the most efficient
/// manner, and allow the compiler to verify that you spelled the name
/// correctly.
///
/// UsdShadeTokens also contains all of the \em allowedTokens values
/// declared for schema builtin attributes of 'token' scene description type.
/// Use UsdShadeTokens like so:
///
/// \code
/// gprim.GetMyTokenValuedAttr().Set(UsdShadeTokens->allPurpose);
/// \endcode
struct UsdShadeTokensType {
USDSHADE_API UsdShadeTokensType();
/// \brief ""
///
/// Possible value for the 'materialPurpose' parameter in the various methods available in UsdShadeMaterialBindingAPI. Its value is empty and its purpose is to represent a general purpose material-binding that applies in the absence of a specific-purpose binding.
const TfToken allPurpose;
/// \brief "bindMaterialAs"
///
/// Token valued metadata key authored on a material binding relationship to indicate the strength of the binding relative to bindings authored on descendants.
const TfToken bindMaterialAs;
/// \brief "coordSys:"
///
/// Namespace prefix for relationships that bind coordinate systems.
const TfToken coordSys;
/// \brief "displacement"
///
/// Describes the <i>displacement</i> output terminal on a UsdShadeMaterial. It is used to define the terminal UsdShadeShader describing the displacement of a UsdShadeMaterial.
const TfToken displacement;
/// \brief "fallbackStrength"
///
/// Sentinal value to be used for 'bindMaterialAs' metadata's default value. Clients should pass this in for the 'bindingStrength' argument to UsdShadeMaterialBindingAPI::Bind(), if they want to author the default value (weakerThanDescendants) sparsely. The value "fallbackStrength" never gets authored into scene description.
const TfToken fallbackStrength;
/// \brief "full"
///
/// Possible value for 'connectability' metadata on a UsdShadeInput. When connectability of an input is set to "full", it implies that it can be connected to any input or output. , Possible value for the 'materialPurpose' parameter in UsdShadeMaterialBindingAPI, to be used when the purpose of the render is entirely about visualizing the truest representation of a scene, considering all lighting and material information, at highest fidelity.
const TfToken full;
/// \brief "id"
///
/// Possible value for UsdShadeNodeDefAPI::GetImplementationSourceAttr(), Default value for UsdShadeNodeDefAPI::GetImplementationSourceAttr()
const TfToken id;
/// \brief "info:id"
///
/// UsdShadeNodeDefAPI
const TfToken infoId;
/// \brief "info:implementationSource"
///
/// UsdShadeNodeDefAPI
const TfToken infoImplementationSource;
/// \brief "inputs:"
///
/// The prefix on shading attributes denoting an input.
const TfToken inputs;
/// \brief "interfaceOnly"
///
/// Possible value for 'connectability' metadata on a UsdShadeInput. It implies that the input can only connect to a NodeGraph Input (which represents an interface override, not a render-time dataflow connection), or another Input whose connectability is also 'interfaceOnly'.
const TfToken interfaceOnly;
/// \brief "materialBind"
///
/// The name of the GeomSubset family used to identify face subsets defined for the purpose of binding materials to facesets.
const TfToken materialBind;
/// \brief "material:binding"
///
/// The relationship name on non-shading prims to denote a binding to a UsdShadeMaterial.
const TfToken materialBinding;
/// \brief "material:binding:collection"
///
/// The relationship name on non-shading prims to denote a collection-based binding to a UsdShadeMaterial.
const TfToken materialBindingCollection;
/// \brief "materialVariant"
///
/// The variant name of material variation described on a UsdShadeMaterial.
const TfToken materialVariant;
/// \brief "outputs:"
///
/// The prefix on shading attributes denoting an output.
const TfToken outputs;
/// \brief "outputs:displacement"
///
/// UsdShadeMaterial
const TfToken outputsDisplacement;
/// \brief "outputs:surface"
///
/// UsdShadeMaterial
const TfToken outputsSurface;
/// \brief "outputs:volume"
///
/// UsdShadeMaterial
const TfToken outputsVolume;
/// \brief "preview"
///
/// Possible value for the 'materialPurpose' parameter in UsdShadeMaterialBindingAPI, to be used when the render is in service of a goal other than a high fidelity "full" render (such as scene manipulation, modeling, or realtime playback). Latency and speed are generally of greater concern for preview renders, therefore preview materials are generally designed to be "lighterweight" compared to full materials.
const TfToken preview;
/// \brief "sdrMetadata"
///
/// Dictionary valued metadata key authored on Shader prims with implementationSource value of sourceAsset or sourceCode to pass along metadata to the shader parser or compiler. It is also used to author metadata on shader properties in a UsdShade-based shader definition file.
const TfToken sdrMetadata;
/// \brief "sourceAsset"
///
/// Possible value for UsdShadeNodeDefAPI::GetImplementationSourceAttr()
const TfToken sourceAsset;
/// \brief "sourceCode"
///
/// Possible value for UsdShadeNodeDefAPI::GetImplementationSourceAttr()
const TfToken sourceCode;
/// \brief "strongerThanDescendants"
///
/// Possible value for 'bindMaterialAs' metadata on the collection-based material binding relationship. Indicates that the binding represented by the relationship is stronger than any bindings authored on the descendants.
const TfToken strongerThanDescendants;
/// \brief "subIdentifier"
///
/// This identifier is used in conjunction with a specific source asset to indicate a particular definition within the source asset, if the source asset specifies more than one shader node definition.
const TfToken subIdentifier;
/// \brief "surface"
///
/// Describes the <i>surface</i> output terminal on a UsdShadeMaterial. It is used to define the terminal UsdShadeShader describing the surface of a UsdShadeMaterial.
const TfToken surface;
/// \brief ""
///
/// Possible value for the "renderContext" parameter in \ref UsdShadeMaterial_Outputs API. Represents the universal renderContext. An output with a universal renderContext is applicable to all possible rendering contexts.
const TfToken universalRenderContext;
/// \brief ""
///
/// Possible value for the "sourceType" parameter in \ref UsdShadeNodeDefAPI_ImplementationSource API. Represents the universal or fallback source type.
const TfToken universalSourceType;
/// \brief "volume"
///
/// Describes the <i>volume</i> output terminal on a UsdShadeMaterial. It is used to define the terminal UsdShadeShader describing the volume of a UsdShadeMaterial.
const TfToken volume;
/// \brief "weakerThanDescendants"
///
/// Possible value for 'bindMaterialAs' metadata on the collection-based material binding relationship. Indicates that the binding represented by the relationship is weaker than any bindings authored on the descendants.
const TfToken weakerThanDescendants;
/// A vector of all of the tokens listed above.
const std::vector<TfToken> allTokens;
};
/// \var UsdShadeTokens
///
/// A global variable with static, efficient \link TfToken TfTokens\endlink
/// for use in all public USD API. \sa UsdShadeTokensType
extern USDSHADE_API TfStaticData<UsdShadeTokensType> UsdShadeTokens;
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+84
View File
@@ -0,0 +1,84 @@
//
// Copyright 2020 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SHADE_TYPES_H
#define PXR_USD_USD_SHADE_TYPES_H
#include "pxr/pxr.h"
#include "pxr/usd/usdShade/api.h"
#include "pxr/usd/usd/attribute.h"
#include "pxr/base/tf/smallVector.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \enum UsdShadeAttributeType
///
/// Specifies the type of a shading attribute.
///
enum class UsdShadeAttributeType {
Invalid,
Input,
Output,
};
/// \enum UsdShadeConnectionModification
///
/// Choice when creating a single connection with the \p ConnectToSource method
/// for a shading attribute. The new connection can replace any existing
/// connections or be added to the list of existing connections. In which case
/// there is a choice between prepending and appending to said list, which will
/// be represented by Usd's list editing operations.
///
enum class UsdShadeConnectionModification {
Replace,
Prepend,
Append
};
/// \typedef UsdShadeAttributeVector
///
/// For performance reasons we want to be extra careful when reporting
/// attributes. It is possible to have multiple connections for a shading
/// attribute, but by far the more common cases are one or no connection. So we
/// use a small vector that can be stack allocated that holds space for a single
/// attributes, but that can "spill" to the heap in the case of multiple
/// upstream attributes.
using UsdShadeAttributeVector = TfSmallVector<UsdAttribute, 1>;
/// \typedef UsdShadeSourceInfoVector
///
/// For performance reasons we want to be extra careful when reporting
/// connections. It is possible to have multiple connections for a shading
/// attribute, but by far the more common cases are one or no connection.
/// So we use a small vector that can be stack allocated that holds space
/// for a single source, but that can "spill" to the heap in the case
/// of a multi-connection.
///
/// /sa UsdShadeConnectionSourceInfo in connectableAPI.h
struct UsdShadeConnectionSourceInfo;
using UsdShadeSourceInfoVector = TfSmallVector<UsdShadeConnectionSourceInfo, 1>;
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+129
View File
@@ -0,0 +1,129 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SHADE_UTILS_H
#define PXR_USD_USD_SHADE_UTILS_H
#include "pxr/pxr.h"
#include "pxr/usd/usdShade/api.h"
#include "pxr/usd/usdShade/types.h"
#include "pxr/usd/usd/attribute.h"
#include "pxr/base/tf/smallVector.h"
#include "pxr/base/tf/token.h"
#include <string>
#include <utility>
PXR_NAMESPACE_OPEN_SCOPE
class UsdShadeInput;
class UsdShadeOutput;
/// \class UsdShadeUtils
///
/// This class contains a set of utility functions used when authoring and
/// querying shading networks.
///
class UsdShadeUtils {
public:
/// Returns the namespace prefix of the USD attribute associated with the
/// given shading attribute type.
USDSHADE_API
static std::string GetPrefixForAttributeType(
UsdShadeAttributeType sourceType);
/// Given the full name of a shading attribute, returns it's base name and
/// shading attribute type.
USDSHADE_API
static std::pair<TfToken, UsdShadeAttributeType>
GetBaseNameAndType(const TfToken &fullName);
/// Given the full name of a shading attribute, returns its shading
/// attribute type.
USDSHADE_API
static UsdShadeAttributeType GetType(const TfToken &fullName);
/// Returns the full shading attribute name given the basename and the
/// shading attribute type. \p baseName is the name of the input or output
/// on the shading node. \p type is the \ref UsdShadeAttributeType of the
/// shading attribute.
USDSHADE_API
static TfToken GetFullName(const TfToken &baseName,
const UsdShadeAttributeType type);
/// \brief Find what is connected to an Input or Output recursively
///
/// GetValueProducingAttributes implements the UsdShade connectivity rules
/// described in \ref 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 \p UsdShadeUtils::GetType function.
///
/// If \p 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.
USDSHADE_API
static UsdShadeAttributeVector GetValueProducingAttributes(
UsdShadeInput const &input,
bool shaderOutputsOnly = false);
/// \overload
USDSHADE_API
static UsdShadeAttributeVector GetValueProducingAttributes(
UsdShadeOutput const &output,
bool shaderOutputsOnly = false);
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif