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 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_SDR_API_H
#define PXR_USD_SDR_API_H
#include "pxr/base/arch/export.h"
#if defined(PXR_STATIC)
# define SDR_API
# define SDR_API_TEMPLATE_CLASS(...)
# define SDR_API_TEMPLATE_STRUCT(...)
# define SDR_LOCAL
#else
# if defined(SDR_EXPORTS)
# define SDR_API ARCH_EXPORT
# define SDR_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
# define SDR_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
# else
# define SDR_API ARCH_IMPORT
# define SDR_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
# define SDR_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
# endif
# define SDR_LOCAL ARCH_HIDDEN
#endif
#endif
+40
View File
@@ -0,0 +1,40 @@
//
// Copyright 2021 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_SDR_DEBUG_CODES_H
#define PXR_USD_SDR_DEBUG_CODES_H
#include "pxr/pxr.h"
#include "pxr/base/tf/debug.h"
PXR_NAMESPACE_OPEN_SCOPE
TF_DEBUG_CODES(
SDR_TYPE_CONFORMANCE
);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_SDR_DEBUG_CODES_H
+57
View File
@@ -0,0 +1,57 @@
//
// 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_SDR_DECLARE_H
#define PXR_USD_SDR_DECLARE_H
/// \file sdr/declare.h
#include "pxr/pxr.h"
#include "pxr/usd/ndr/declare.h"
#include <memory>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
class SdrShaderNode;
class SdrShaderProperty;
/// Common typedefs that are used throughout the SDR library.
// ShaderNode
typedef SdrShaderNode* SdrShaderNodePtr;
typedef SdrShaderNode const* SdrShaderNodeConstPtr;
typedef std::unique_ptr<SdrShaderNode> SdrShaderNodeUniquePtr;
typedef std::vector<SdrShaderNodeConstPtr> SdrShaderNodePtrVec;
// ShaderProperty
typedef SdrShaderProperty* SdrShaderPropertyPtr;
typedef SdrShaderProperty const* SdrShaderPropertyConstPtr;
typedef std::unique_ptr<SdrShaderProperty> SdrShaderPropertyUniquePtr;
typedef std::unordered_map<TfToken, SdrShaderPropertyConstPtr,
TfToken::HashFunctor> SdrPropertyMap;
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_SDR_DECLARE_H
+126
View File
@@ -0,0 +1,126 @@
//
// 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_SDR_REGISTRY_H
#define PXR_USD_SDR_REGISTRY_H
/// \file sdr/registry.h
#include "pxr/pxr.h"
#include "pxr/base/tf/singleton.h"
#include "pxr/usd/sdr/api.h"
#include "pxr/usd/ndr/registry.h"
#include "pxr/usd/sdr/declare.h"
#include "pxr/usd/sdr/shaderNode.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class SdrRegistry
///
/// The shading-specialized version of `NdrRegistry`.
///
class SdrRegistry : public NdrRegistry
{
public:
/// Get the single `SdrRegistry` instance.
SDR_API
static SdrRegistry& GetInstance();
/// Exactly like `NdrRegistry::GetNodeByIdentifier()`, but returns a
/// `SdrShaderNode` pointer instead of a `NdrNode` pointer.
SDR_API
SdrShaderNodeConstPtr GetShaderNodeByIdentifier(
const NdrIdentifier& identifier,
const NdrTokenVec& typePriority = NdrTokenVec());
/// Exactly like `NdrRegistry::GetNodeByIdentifierAndType()`, but returns
/// a `SdrShaderNode` pointer instead of a `NdrNode` pointer.
SDR_API
SdrShaderNodeConstPtr GetShaderNodeByIdentifierAndType(
const NdrIdentifier& identifier,
const TfToken& nodeType);
/// Exactly like `NdrRegistry::GetNodeByName()`, but returns a
/// `SdrShaderNode` pointer instead of a `NdrNode` pointer.
SDR_API
SdrShaderNodeConstPtr GetShaderNodeByName(
const std::string& name,
const NdrTokenVec& typePriority = NdrTokenVec(),
NdrVersionFilter filter = NdrVersionFilterDefaultOnly);
/// Exactly like `NdrRegistry::GetNodeByNameAndType()`, but returns a
/// `SdrShaderNode` pointer instead of a `NdrNode` pointer.
SDR_API
SdrShaderNodeConstPtr GetShaderNodeByNameAndType(
const std::string& name,
const TfToken& nodeType,
NdrVersionFilter filter = NdrVersionFilterDefaultOnly);
/// Wrapper method for NdrRegistry::GetNodeFromAsset().
/// Returns a valid SdrShaderNode pointer upon success.
SDR_API
SdrShaderNodeConstPtr GetShaderNodeFromAsset(
const SdfAssetPath &shaderAsset,
const NdrTokenMap &metadata=NdrTokenMap(),
const TfToken &subIdentifier=TfToken(),
const TfToken &sourceType=TfToken());
/// Wrapper method for NdrRegistry::GetNodeFromSourceCode().
/// Returns a valid SdrShaderNode pointer upon success.
SDR_API
SdrShaderNodeConstPtr GetShaderNodeFromSourceCode(
const std::string &sourceCode,
const TfToken &sourceType,
const NdrTokenMap &metadata=NdrTokenMap());
/// Exactly like `NdrRegistry::GetNodesByIdentifier()`, but returns a vector
/// of `SdrShaderNode` pointers instead of a vector of `NdrNode` pointers.
SDR_API
SdrShaderNodePtrVec GetShaderNodesByIdentifier(const NdrIdentifier& identifier);
/// Exactly like `NdrRegistry::GetNodesByName()`, but returns a vector of
/// `SdrShaderNode` pointers instead of a vector of `NdrNode` pointers.
SDR_API
SdrShaderNodePtrVec GetShaderNodesByName(
const std::string& name,
NdrVersionFilter filter = NdrVersionFilterDefaultOnly);
/// Exactly like `NdrRegistry::GetNodesByFamily()`, but returns a vector of
/// `SdrShaderNode` pointers instead of a vector of `NdrNode` pointers.
SDR_API
SdrShaderNodePtrVec GetShaderNodesByFamily(
const TfToken& family = TfToken(),
NdrVersionFilter filter = NdrVersionFilterDefaultOnly);
protected:
// Allow TF to construct the class
friend class TfSingleton<SdrRegistry>;
SdrRegistry();
~SdrRegistry();
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_SDR_REGISTRY_H
+116
View File
@@ -0,0 +1,116 @@
//
// 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_SDR_SHADER_METADATA_HELPERS_H
#define PXR_USD_SDR_SHADER_METADATA_HELPERS_H
/// \file sdr/shaderMetadataHelpers.h
#include "pxr/pxr.h"
#include "pxr/usd/sdr/api.h"
#include "pxr/base/tf/token.h"
#include "pxr/usd/sdr/declare.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \namespace ShaderMetadataHelpers
///
/// Various utilities for parsing metadata contained within shaders.
///
namespace ShaderMetadataHelpers
{
/// Determines if the given metadatum in the metadata dictionary has a
/// truthy value. All values are considered to be true except the following
/// (case-insensitive): '0', 'false', and 'f'. The absence of `key`
/// in the metadata also evaluates to false.
SDR_API
bool
IsTruthy(const TfToken& key, const NdrTokenMap& metadata);
/// Extracts the string value from the given metadatum if it exists,
/// otherwise returns \p defaultValue.
SDR_API
std::string
StringVal(const TfToken& key, const NdrTokenMap& metadata,
const std::string& defaultValue = std::string());
/// Extracts the tokenized value from the given metadatum if it exists,
/// otherwise returns \p defaultValue.
SDR_API
TfToken
TokenVal(const TfToken& key, const NdrTokenMap& metadata,
const TfToken& defaultValue = TfToken());
/// Extracts the int value from the given metadatum if it exists and is a
/// valid integer value, otherwise returns \p default value.
SDR_API
int
IntVal(const TfToken& key, const NdrTokenMap& metadata,
int defaultValue = std::numeric_limits<int>::max());
/// Extracts a vector of strings from the given metadatum. An empty vector
/// is returned if the metadatum does not exist.
SDR_API
NdrStringVec
StringVecVal(const TfToken& key, const NdrTokenMap& metadata);
/// Extracts a vector of tokenized values from the given metadatum. An empty
/// vector is returned if the metadatum does not exist.
SDR_API
NdrTokenVec
TokenVecVal(const TfToken& key, const NdrTokenMap& metadata);
/// Extracts an "options" vector from the given string.
SDR_API
NdrOptionVec
OptionVecVal(const std::string& optionStr);
/// Serializes a vector of strings into a string using the pipe character
/// as the delimiter.
SDR_API
std::string
CreateStringFromStringVec(const NdrStringVec& stringVec);
/// Determines if the specified property metadata has a widget that
/// indicates the property is an asset identifier.
SDR_API
bool
IsPropertyAnAssetIdentifier(const NdrTokenMap& metadata);
/// Determines if the specified property metadata has a 'renderType' that
/// indicates the property should be a SdrPropertyTypes->Terminal
SDR_API
bool
IsPropertyATerminal(const NdrTokenMap& metadata);
/// Gets the "role" from metadata if one is provided. Only returns a value
// if it's a valid role as defined by SdrPropertyRole tokens.
SDR_API
TfToken
GetRoleFromMetadata(const NdrTokenMap& metadata);
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_SDR_SHADER_METADATA_HELPERS_H
+257
View File
@@ -0,0 +1,257 @@
//
// 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_SDR_SHADER_NODE_H
#define PXR_USD_SDR_SHADER_NODE_H
/// \file sdr/shaderNode.h
#include "pxr/pxr.h"
#include "pxr/usd/sdr/api.h"
#include "pxr/base/tf/staticTokens.h"
#include "pxr/usd/ndr/node.h"
#include "pxr/usd/sdr/declare.h"
PXR_NAMESPACE_OPEN_SCOPE
// Note: Metadata keys that are generated by parsers should start with
// "__SDR__" to reduce the risk of collision with metadata actually in the
// shader.
#define SDR_NODE_METADATA_TOKENS \
((Category, "category")) \
((Role, "role")) \
((Departments, "departments")) \
((Help, "help")) \
((Label, "label")) \
((Pages, "pages")) \
((Primvars, "primvars")) \
((ImplementationName, "__SDR__implementationName"))\
((Target, "__SDR__target")) \
((SdrUsdEncodingVersion, "sdrUsdEncodingVersion"))
// Note: The concept of context is defined on NdrNode and can be queried with
// the GetContext() method. Sdr categorizes shaders by the context in which they
// are used inside of a renderer. For instance during 'pattern' evaluation to
// feed into a surface or volume shader. For BXDFs used in 'surface' and
// 'volume' rendering situations.
#define SDR_NODE_CONTEXT_TOKENS \
((Pattern, "pattern")) \
((Surface, "surface")) \
((Volume, "volume")) \
((Displacement, "displacement")) \
((Light, "light")) \
((LightFilter, "lightFilter")) \
((SampleFilter, "sampleFilter")) \
((PixelFilter, "pixelFilter"))
#define SDR_NODE_ROLE_TOKENS \
((Primvar, "primvar")) \
((Texture, "texture")) \
((Field, "field")) \
((Math, "math")) \
TF_DECLARE_PUBLIC_TOKENS(SdrNodeMetadata, SDR_API, SDR_NODE_METADATA_TOKENS);
TF_DECLARE_PUBLIC_TOKENS(SdrNodeContext, SDR_API, SDR_NODE_CONTEXT_TOKENS);
TF_DECLARE_PUBLIC_TOKENS(SdrNodeRole, SDR_API, SDR_NODE_ROLE_TOKENS);
/// \class SdrShaderNode
///
/// A specialized version of `NdrNode` which holds shading information.
///
class SdrShaderNode : public NdrNode
{
public:
/// Constructor.
SDR_API
SdrShaderNode(const NdrIdentifier& identifier,
const NdrVersion& version,
const std::string& name,
const TfToken& family,
const TfToken& context,
const TfToken& sourceType,
const std::string& definitionURI,
const std::string& implementationURI,
NdrPropertyUniquePtrVec&& properties,
const NdrTokenMap& metadata = NdrTokenMap(),
const std::string &sourceCode = std::string());
/// \name Inputs and Outputs
/// An input or output is also generically referred to as a "property".
/// @{
/// Get a shader input property by name. `nullptr` is returned if an input
/// with the given name does not exist.
SDR_API
SdrShaderPropertyConstPtr GetShaderInput(const TfToken& inputName) const;
/// Get a shader output property by name. `nullptr` is returned if an output
/// with the given name does not exist.
SDR_API
SdrShaderPropertyConstPtr GetShaderOutput(const TfToken& outputName) const;
/// Returns the list of all inputs that are tagged as asset identifier
/// inputs.
SDR_API
NdrTokenVec GetAssetIdentifierInputNames() const;
/// Returns the first shader input that is tagged as the default input.
/// A default input and its value can be used to acquire a fallback value
/// for a node when the node is considered 'disabled' or otherwise
/// incapable of producing an output value.
SDR_API
SdrShaderPropertyConstPtr GetDefaultInput() const;
/// @}
/// \name Metadata
/// The metadata returned here is a direct result of what the parser plugin
/// is able to determine about the node. See the documentation for a
/// specific parser plugin to get help on what the parser is looking for to
/// populate these values.
/// @{
/// The label assigned to this node, if any. Distinct from the name
/// returned from `GetName()`. In the context of a UI, the label value
/// might be used as the display name for the node instead of the name.
SDR_API
const TfToken& GetLabel() const { return _label; }
/// The category assigned to this node, if any. Distinct from the family
/// returned from `GetFamily()`.
SDR_API
const TfToken& GetCategory() const { return _category; }
/// Returns the role of this node. This is used to annotate the role that
/// the shader node plays inside a shader network. We can tag certain
/// shaders to indicate their role within a shading network. We currently
/// tag primvar reading nodes, texture reading nodes and nodes that access
/// volume fields (like extinction or scattering). This is done to identify
/// resources used by a shading network.
SDR_API
std::string GetRole() const;
/// The help message assigned to this node, if any.
SDR_API
std::string GetHelp() const;
/// The departments this node is associated with, if any.
SDR_API
const NdrTokenVec& GetDepartments() const { return _departments; }
/// Gets the pages on which the node's properties reside (an aggregate of
/// the unique `SdrShaderProperty::GetPage()` values for all of the node's
/// properties). Nodes themselves do not reside on pages. In an example
/// scenario, properties might be divided into two pages, 'Simple' and
/// 'Advanced'.
SDR_API
const NdrTokenVec& GetPages() const { return _pages; };
/// The list of primvars this node knows it requires / uses.
/// For example, a shader node may require the 'normals' primvar to function
/// correctly. Additional, user specified primvars may have been authored on
/// the node. These can be queried via `GetAdditionalPrimvarProperties()`.
/// Together, `GetPrimvars()` and `GetAdditionalPrimvarProperties()`,
/// provide the complete list of primvar requirements for the node.
SDR_API
const NdrTokenVec& GetPrimvars() const { return _primvars; }
/// The list of string input properties whose values provide the names of
/// additional primvars consumed by this node. For example, this may return
/// a token named `varname`. This indicates that the client should query the
/// value of a (presumed to be string-valued) input attribute named varname
/// from its scene description to determine the name of a primvar the
/// node will consume. See `GetPrimvars()` for additional information.
SDR_API
const NdrTokenVec& GetAdditionalPrimvarProperties() const {
return _primvarNamingProperties;
}
/// Returns the implementation name of this node. The name of the node
/// is how to refer to the node in shader networks. The label is how to
/// present this node to users. The implementation name is the name of
/// the function (or something) this node represents in the
/// implementation. Any client using the implementation \b must call
/// this method to get the correct name; using \c getName() is not
/// correct.
SDR_API
std::string GetImplementationName() const;
/// @}
/// \name Aggregate Information
/// @{
/// Gets the names of the properties on a certain page (one that was
/// returned by `GetPages()`). To get properties that are not assigned to a
/// page, an empty string can be used for \p pageName.
SDR_API
NdrTokenVec GetPropertyNamesForPage(const std::string& pageName) const;
/// Gets all vstructs that are present in the shader.
SDR_API
NdrTokenVec GetAllVstructNames() const;
/// @}
/// \cond
/// Hide from the API.
// Performs a post-process on properties to determine information that can
// only be determined after parsing or in aggregate. Clients SHOULD NOT
// need to call this.
void _PostProcessProperties();
/// \endcond
protected:
// Processed primvar metadata. `_primvars` contains the names of primvars
// consumed by this node, whereas `_primvarNamingProperties` contains the
// names of string input properties whose values provide the names of
// additional primvars consumed by this node.
NdrTokenVec _primvars;
NdrTokenVec _primvarNamingProperties;
// Tokenized metadata
TfToken _label;
TfToken _category;
NdrTokenVec _departments;
NdrTokenVec _pages;
SdrPropertyMap _shaderInputs;
SdrPropertyMap _shaderOutputs;
private:
// Initializes `_primvars` and `_primvarNamingProperties`
void _InitializePrimvars();
// Determines which pages are present on the node's properties
NdrTokenVec _ComputePages() const;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_SDR_SHADER_NODE_H
+309
View File
@@ -0,0 +1,309 @@
//
// 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_SDR_SHADER_PROPERTY_H
#define PXR_USD_SDR_SHADER_PROPERTY_H
/// \file sdr/shaderProperty.h
#include "pxr/pxr.h"
#include "pxr/usd/sdr/api.h"
#include "pxr/base/tf/staticTokens.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/weakBase.h"
#include "pxr/base/vt/value.h"
#include "pxr/usd/ndr/property.h"
#include "pxr/usd/sdr/shaderNode.h"
PXR_NAMESPACE_OPEN_SCOPE
// If additional types are added here, it's also worth trying to add a mapping
// to the equivalent Sdf type in the implementation file.
#define SDR_PROPERTY_TYPE_TOKENS \
((Int, "int")) \
((String, "string")) \
((Float, "float")) \
((Color, "color")) \
((Point, "point")) \
((Normal, "normal")) \
((Vector, "vector")) \
((Matrix, "matrix")) \
((Struct, "struct")) \
((Terminal, "terminal")) \
((Vstruct, "vstruct")) \
((Unknown, "unknown"))
// Note: Metadata keys that are generated by parsers should start with
// "__SDR__" to reduce the risk of collision with metadata actually in the
// shader.
#define SDR_PROPERTY_METADATA_TOKENS \
((Label, "label")) \
((Help, "help")) \
((Page, "page")) \
((RenderType, "renderType")) \
((Role, "role")) \
((Widget, "widget")) \
((Hints, "hints")) \
((Options, "options")) \
((IsDynamicArray, "isDynamicArray")) \
((Connectable, "connectable")) \
((ValidConnectionTypes, "validConnectionTypes")) \
((VstructMemberOf, "vstructMemberOf")) \
((VstructMemberName, "vstructMemberName")) \
((VstructConditionalExpr, "vstructConditionalExpr"))\
((IsAssetIdentifier, "__SDR__isAssetIdentifier"))\
((ImplementationName, "__SDR__implementationName"))\
((SdrUsdDefinitionType, "sdrUsdDefinitionType"))\
((DefaultInput, "__SDR__defaultinput")) \
((Target, "__SDR__target")) \
((Colorspace, "__SDR__colorspace"))
// The following tokens are valid values for the metadata "role"
#define SDR_PROPERTY_ROLE_TOKENS \
((None, "none"))
TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTypes, SDR_API, SDR_PROPERTY_TYPE_TOKENS);
TF_DECLARE_PUBLIC_TOKENS(SdrPropertyMetadata, SDR_API,
SDR_PROPERTY_METADATA_TOKENS);
TF_DECLARE_PUBLIC_TOKENS(SdrPropertyRole, SDR_API,
SDR_PROPERTY_ROLE_TOKENS);
/// \class SdrShaderProperty
///
/// A specialized version of `NdrProperty` which holds shading information.
///
class SdrShaderProperty : public NdrProperty
{
public:
// Constructor.
SDR_API
SdrShaderProperty(
const TfToken& name,
const TfToken& type,
const VtValue& defaultValue,
bool isOutput,
size_t arraySize,
const NdrTokenMap& metadata,
const NdrTokenMap& hints,
const NdrOptionVec& options
);
/// \name Metadata
/// The metadata returned here is a direct result of what the parser plugin
/// is able to determine about the property. See the documentation for a
/// specific parser plugin to get help on what the parser is looking for to
/// populate these values.
/// @{
/// The label assigned to this property, if any. Distinct from the name
/// returned from `GetName()`. In the context of a UI, the label value
/// might be used as the display name for the property instead of the name.
SDR_API
const TfToken& GetLabel() const { return _label; }
/// The help message assigned to this property, if any.
SDR_API
std::string GetHelp() const;
/// The page (group), eg "Advanced", this property appears on, if any.
SDR_API
const TfToken& GetPage() const { return _page; }
/// The widget "hint" that indicates the widget that can best display the
/// type of data contained in this property, if any. Examples of this value
/// could include "number", "slider", etc.
SDR_API
const TfToken& GetWidget() const { return _widget; }
/// Any UI "hints" that are associated with this property. "Hints" are
/// simple key/value pairs.
SDR_API
const NdrTokenMap& GetHints() const { return _hints; }
/// If the property has a set of valid values that are pre-determined, this
/// will return the valid option names and corresponding string values (if
/// the option was specified with a value).
SDR_API
const NdrOptionVec& GetOptions() const { return _options; }
/// Returns the implementation name of this property. The name of the
/// property is how to refer to the property in shader networks. The
/// label is how to present this property to users. The implementation
/// name is the name of the parameter this property represents in the
/// implementation. Any client using the implementation \b must call
/// this method to get the correct name; using \c getName() is not
/// correct.
SDR_API
std::string GetImplementationName() const;
/// @}
/// \name VStruct Information
/// @{
/// If this field is part of a vstruct, this is the name of the struct.
SDR_API
const TfToken& GetVStructMemberOf() const {
return _vstructMemberOf;
}
/// If this field is part of a vstruct, this is its name in the struct.
SDR_API
const TfToken& GetVStructMemberName() const {
return _vstructMemberName;
}
/// Returns true if this field is part of a vstruct.
SDR_API
bool IsVStructMember() const;
/// Returns true if the field is the head of a vstruct.
SDR_API
bool IsVStruct() const;
/// If this field is part of a vstruct, this is the conditional expression
SDR_API
const TfToken& GetVStructConditionalExpr() const {
return _vstructConditionalExpr;
}
/// @}
/// \name Connection Information
/// @{
/// Whether this property can be connected to other properties. If this
/// returns `true`, connectability to a specific property can be tested via
/// `CanConnectTo()`.
SDR_API
bool IsConnectable() const override { return _isConnectable; }
/// Gets the list of valid connection types for this property. This value
/// comes from shader metadata, and may not be specified. The value from
/// `NdrProperty::GetType()` can be used as a fallback, or you can use the
/// connectability test in `CanConnectTo()`.
SDR_API
const NdrTokenVec& GetValidConnectionTypes() const {
return _validConnectionTypes;
}
/// Determines if this property can be connected to the specified property.
SDR_API
bool CanConnectTo(const NdrProperty& other) const override;
/// @}
/// \name Utilities
/// @{
/// Converts the property's type from `GetType()` into a `SdfValueTypeName`.
///
/// Two scenarios can result: an exact mapping from property type to Sdf
/// type, and an inexact mapping. In the first scenario, the first element
/// in the pair will be the cleanly-mapped Sdf type, and the second element,
/// a TfToken, will be empty. In the second scenario, the Sdf type will be
/// set to `Token` to indicate an unclean mapping, and the second element
/// will be set to the original type returned by `GetType()`.
///
/// \sa GetDefaultValueAsSdfType
SDR_API
const NdrSdfTypeIndicator GetTypeAsSdfType() const override;
/// Accessor for default value corresponding to the SdfValueTypeName
/// returned by GetTypeAsSdfType. Note that this could be different than
/// value returned by GetDefaultValue.
///
/// \sa GetTypeAsSdfType
SDR_API
const VtValue& GetDefaultValueAsSdfType() const override {
return _sdfTypeDefaultValue;
}
/// Determines if the value held by this property is an asset identifier
/// (eg, a file path); the logic for this is left up to the parser.
///
/// Note: The type returned from `GetTypeAsSdfType()` will be `Asset` if
/// this method returns `true` (even though its true underlying data type
/// is string).
SDR_API
bool IsAssetIdentifier() const;
/// Determines if the value held by this property is the default input
/// for this node.
SDR_API
bool IsDefaultInput() const;
/// @}
protected:
SdrShaderProperty& operator=(const SdrShaderProperty&) = delete;
// Allow the shader's post process function to access the property's
// internals. Some property information can only be determined after parse
// time.
friend void SdrShaderNode::_PostProcessProperties();
// Set the USD encoding version to something other than the default.
// This can be set in SdrShaderNode::_PostProcessProperties for all the
// properties on a shader node.
void _SetUsdEncodingVersion(int usdEncodingVersion);
// Convert this property to a VStruct, which has a special type and a
// different default value
void _ConvertToVStruct();
// This function is called by SdrShaderNode::_PostProcessProperties once all
// information is locked in and won't be changed anymore. This allows each
// property to take some extra steps once all information is available.
void _FinalizeProperty();
// Some metadata values cannot be returned by reference from the main
// metadata dictionary because they need additional parsing.
const NdrTokenMap _hints;
const NdrOptionVec _options;
// Tokenized metadata
NdrTokenVec _validConnectionTypes;
TfToken _label;
TfToken _page;
TfToken _widget;
TfToken _vstructMemberOf;
TfToken _vstructMemberName;
TfToken _vstructConditionalExpr;
VtValue _sdfTypeDefaultValue;
// Metadatum to control the behavior of GetTypeAsSdfType and indirectly
// CanConnectTo
int _usdEncodingVersion;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_SDR_SHADER_PROPERTY_H