HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
utils.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_USD_USDMTLX_UTILS_H
9 #define PXR_USD_USDMTLX_UTILS_H
10 
11 #include "pxr/pxr.h"
12 #include "pxr/usd/usdMtlx/api.h"
13 #include "pxr/usd/sdr/declare.h"
16 #include "pxr/base/vt/value.h"
17 #include <MaterialXCore/Document.h>
18 #include <string>
19 #include <vector>
20 
22 
23 /// Return the MaterialX standard library paths. All standard library
24 /// files (and only standard library files) should be found on these
25 /// paths.
27 const SdrStringVec&
29 
30 /// Return the paths to directories containing custom MaterialX files, set in
31 /// the environment variable 'PXR_MTLX_PLUGIN_SEARCH_PATHS'
33 const SdrStringVec&
35 
36 /// Return the MaterialX search paths. In order, this includes:
37 /// - directories containing custom MaterialX files set in the env var
38 /// 'PXR_MTLX_PLUGIN_SEARCH_PATHS'
39 /// - standard library paths set in the env var 'PXR_MTLX_STDLIB_SEARCH_PATHS'
40 /// - path to the MaterialX standard library discovered at build time.
42 const SdrStringVec&
44 
45 /// Return the MaterialX standard file extensions.
49 
50 /// Return the MaterialX document at \p resolvedPath. Return null if the
51 /// document could not be read and report a runtime error.
52 ///
53 /// Unlike UsdMtlxGetDocument, this function does not implement any
54 /// caching or special behavior for MaterialX standard library documents.
57 UsdMtlxReadDocument(const std::string& resolvedPath);
58 
59 /// Return the (possibly cached) MaterialX document at \p resolvedUri.
60 /// Return null if the document could not be read and report a
61 /// warning (once per uri). \p resolvedUri may be empty to indicate
62 /// the MaterialX standard library documents all rolled into one.
65 UsdMtlxGetDocument(const std::string& resolvedUri);
66 
67 /// Returns the (possibly cached) MaterialX document created from the given
68 /// string containing the source MaterialX XML.
71 UsdMtlxGetDocumentFromString(const std::string &mtlxXml);
72 
73 // Return the version of the mtlx element. If the version cannot be
74 // found then return an invalid default version. If implicitDefault
75 // isn't null then we do to two things: we set implicitDefault to
76 // false iff the isdefaultversion attribute exists and isn't empty,
77 // otherwise we set it to true; and we return the version as a
78 // default if isdefaultversion exists and is set to "true".
82  bool* implicitDefault = nullptr);
83 
84 /// Return the source URI for a MaterialX element. If the element
85 /// doesn't have a non-empty URI then return the source URI of the
86 /// closest element up the element hierarchy that does have one.
87 /// Return the empty string if no element has a source URI.
89 const std::string&
91 
92 /// Result of \c UsdMtlxGetUsdType().
98  int arraySize=0)
99  : valueTypeName(valueTypeName)
100  , shaderPropertyType(shaderPropertyType)
102  , valueTypeNameIsExact(valueTypeNameIsExact)
103  { }
104 
105  /// The value type name that most closely matches the MaterialX type.
106  /// If the type isn't recognized this is the invalid value type name.
107  /// Clients can check for array types by calling \c IsArray() on this.
109 
110  /// The exact \c SdrShaderProperty type name. If there is no exact
111  /// match this is empty.
113 
114  /// If the value type is a fixed-size array/tuple, this will be greater
115  /// then zero. For "dynamic arrays" this will be zero.
117 
118  /// \c true iff the value type name is an exact match to the
119  /// MaterialX type.
121 };
122 
123 /// Convert a (standard) MaterialX type name.
126 UsdMtlxGetUsdType(const std::string& mtlxTypeName);
127 
128 /// Return the value in \p mtlx as a \c VtValue. Returns an
129 /// empty VtValue and reports an error if the conversion cannot be
130 /// applied. If \p getDefaultValue is \c true then converts the
131 /// default value. It is not an error if the value doesn't exist;
132 /// that silently returns an empty VtValue.
134 VtValue
136  bool getDefaultValue = false);
137 
138 /// Return the MaterialX values in \p values assuming it contains an
139 /// array of values of MaterialX type \p type as a vector of VtValue.
141 std::vector<VtValue>
142 UsdMtlxGetPackedUsdValues(const std::string& values, const std::string& type);
143 
144 /// Split a MaterialX string array into a vector of strings.
145 ///
146 /// The MaterialX specification says:
147 ///
148 /// > Individual string values within stringarrays may not contain
149 /// > commas or semicolons, and any leading and trailing whitespace
150 /// > characters in them is ignored.
151 ///
152 /// These restrictions do not apply to the string type.
154 std::vector<std::string>
155 UsdMtlxSplitStringArray(const std::string& s);
156 
158 
159 #endif // PXR_USD_USDMTLX_UTILS_H
std::vector< std::string > SdrStringVec
Definition: declare.h:67
shared_ptr< const Element > ConstElementPtr
A shared pointer to a const Element.
Definition: Element.h:33
USDMTLX_API MaterialX::ConstDocumentPtr UsdMtlxGetDocumentFromString(const std::string &mtlxXml)
USDMTLX_API SdrStringVec UsdMtlxStandardFileExtensions()
Return the MaterialX standard file extensions.
USDMTLX_API SdrVersion UsdMtlxGetVersion(const MaterialX::ConstInterfaceElementPtr &mtlx, bool *implicitDefault=nullptr)
USDMTLX_API MaterialX::DocumentPtr UsdMtlxReadDocument(const std::string &resolvedPath)
shared_ptr< const InterfaceElement > ConstInterfaceElementPtr
A shared pointer to a const InterfaceElement.
Definition: Interface.h:43
USDMTLX_API MaterialX::ConstDocumentPtr UsdMtlxGetDocument(const std::string &resolvedUri)
GLdouble s
Definition: glad.h:3009
SdfValueTypeName valueTypeName
Definition: utils.h:108
USDMTLX_API const std::string & UsdMtlxGetSourceURI(const MaterialX::ConstElementPtr &element)
SdrVersion.
Definition: declare.h:73
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
Definition: token.h:70
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
USDMTLX_API const SdrStringVec & UsdMtlxCustomSearchPaths()
USDMTLX_API UsdMtlxUsdTypeInfo UsdMtlxGetUsdType(const std::string &mtlxTypeName)
Convert a (standard) MaterialX type name.
TfToken shaderPropertyType
Definition: utils.h:112
USDMTLX_API std::vector< std::string > UsdMtlxSplitStringArray(const std::string &s)
PXR_NAMESPACE_OPEN_SCOPE USDMTLX_API const SdrStringVec & UsdMtlxStandardLibraryPaths()
bool valueTypeNameIsExact
Definition: utils.h:120
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
Result of UsdMtlxGetUsdType().
Definition: utils.h:93
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
#define USDMTLX_API
Definition: api.h:23
shared_ptr< const Document > ConstDocumentPtr
A shared pointer to a const Document.
Definition: Document.h:24
USDMTLX_API const SdrStringVec & UsdMtlxSearchPaths()
Definition: value.h:146
USDMTLX_API VtValue UsdMtlxGetUsdValue(const MaterialX::ConstElementPtr &mtlx, bool getDefaultValue=false)
UsdMtlxUsdTypeInfo(SdfValueTypeName valueTypeName, bool valueTypeNameIsExact, TfToken shaderPropertyType, int arraySize=0)
Definition: utils.h:94
USDMTLX_API std::vector< VtValue > UsdMtlxGetPackedUsdValues(const std::string &values, const std::string &type)