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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 
25 #ifndef PXR_USD_USDMTLX_UTILS_H
26 #define PXR_USD_USDMTLX_UTILS_H
27 
28 #include "pxr/pxr.h"
29 #include "pxr/usd/usdMtlx/api.h"
30 #include "pxr/usd/ndr/declare.h"
33 #include "pxr/base/vt/value.h"
34 #include <MaterialXCore/Document.h>
35 #include <string>
36 #include <vector>
37 
39 
40 #define USD_MTLX_TOKENS \
41  ((DefaultOutputName, "out"))
42 
44 
45 /// Return the MaterialX standard library paths. All standard library
46 /// files (and only standard library files) should be found on these
47 /// paths.
49 const NdrStringVec&
51 
52 /// Return the paths to directories containing custom MaterialX files, set in
53 /// the environment variable 'PXR_MTLX_PLUGIN_SEARCH_PATHS'
55 const NdrStringVec&
57 
58 /// Return the MaterialX search paths. In order, this includes:
59 /// - directories containing custom MaterialX files set in the env var
60 /// 'PXR_MTLX_PLUGIN_SEARCH_PATHS'
61 /// - standard library paths set in the env var 'PXR_MTLX_STDLIB_SEARCH_PATHS'
62 /// - path to the MaterialX standard library discovered at build time.
64 const NdrStringVec&
66 
67 /// Return the MaterialX standard file extensions.
71 
72 /// Return the MaterialX document at \p resolvedPath. Return null if the
73 /// document could not be read and report a runtime error.
74 ///
75 /// Unlike UsdMtlxGetDocument, this function does not implement any
76 /// caching or special behavior for MaterialX standard library documents.
79 UsdMtlxReadDocument(const std::string& resolvedPath);
80 
81 /// Return the (possibly cached) MaterialX document at \p resolvedUri.
82 /// Return null if the document could not be read and report a
83 /// warning (once per uri). \p resolvedUri may be empty to indicate
84 /// the MaterialX standard library documents all rolled into one.
87 UsdMtlxGetDocument(const std::string& resolvedUri);
88 
89 /// Returns the (possibly cached) MaterialX document created from the given
90 /// string containing the source MaterialX XML.
94 
95 // Return the version of the mtlx element. If the version cannot be
96 // found then return an invalid default version. If implicitDefault
97 // isn't null then we do to two things: we set implicitDefault to
98 // false iff the isdefaultversion attribute exists and isn't empty,
99 // otherwise we set it to true; and we return the version as a
100 // default if isdefaultversion exists and is set to "true".
104  bool* implicitDefault = nullptr);
105 
106 /// Return the source URI for a MaterialX element. If the element
107 /// doesn't have a non-empty URI then return the source URI of the
108 /// closest element up the element hierarchy that does have one.
109 /// Return the empty string if no element has a source URI.
111 const std::string&
113 
114 /// Result of \c UsdMtlxGetUsdType().
120  int arraySize=0)
121  : valueTypeName(valueTypeName)
122  , shaderPropertyType(shaderPropertyType)
124  , valueTypeNameIsExact(valueTypeNameIsExact)
125  { }
126 
127  /// The value type name that most closely matches the MaterialX type.
128  /// If the type isn't recognized this is the invalid value type name.
129  /// Clients can check for array types by calling \c IsArray() on this.
131 
132  /// The exact \c SdrShaderProperty type name. If there is no exact
133  /// match this is empty.
135 
136  /// If the value type is a fixed-size array/tuple, this will be greater
137  /// then zero. For "dynamic arrays" this will be zero.
139 
140  /// \c true iff the value type name is an exact match to the
141  /// MaterialX type.
143 };
144 
145 /// Convert a (standard) MaterialX type name.
148 UsdMtlxGetUsdType(const std::string& mtlxTypeName);
149 
150 /// Return the value in \p mtlx as a \c VtValue. Returns an
151 /// empty VtValue and reports an error if the conversion cannot be
152 /// applied. If \p getDefaultValue is \c true then converts the
153 /// default value. It is not an error if the value doesn't exist;
154 /// that silently returns an empty VtValue.
156 VtValue
158  bool getDefaultValue = false);
159 
160 /// Return the MaterialX values in \p values assuming it contains an
161 /// array of values of MaterialX type \p type as a vector of VtValue.
163 std::vector<VtValue>
165 
166 /// Split a MaterialX string array into a vector of strings.
167 ///
168 /// The MaterialX specification says:
169 ///
170 /// > Individual string values within stringarrays may not contain
171 /// > commas or semicolons, and any leading and trailing whitespace
172 /// > characters in them is ignored.
173 ///
174 /// These restrictions do not apply to the string type.
176 std::vector<std::string>
178 
180 
181 #endif // PXR_USD_USDMTLX_UTILS_H
shared_ptr< const Element > ConstElementPtr
A shared pointer to a const Element.
Definition: Element.h:33
USDMTLX_API const NdrStringVec & UsdMtlxCustomSearchPaths()
USDMTLX_API MaterialX::ConstDocumentPtr UsdMtlxGetDocumentFromString(const std::string &mtlxXml)
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
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
USDMTLX_API const NdrStringVec & UsdMtlxStandardLibraryPaths()
USDMTLX_API MaterialX::ConstDocumentPtr UsdMtlxGetDocument(const std::string &resolvedUri)
USDMTLX_API NdrVersion UsdMtlxGetVersion(const MaterialX::ConstInterfaceElementPtr &mtlx, bool *implicitDefault=nullptr)
GLdouble s
Definition: glad.h:3009
SdfValueTypeName valueTypeName
Definition: utils.h:130
#define USD_MTLX_TOKENS
Definition: utils.h:40
USDMTLX_API const std::string & UsdMtlxGetSourceURI(const MaterialX::ConstElementPtr &element)
Definition: token.h:87
TF_DECLARE_PUBLIC_TOKENS(UsdMtlxTokens, USDMTLX_API, USD_MTLX_TOKENS)
std::vector< std::string > NdrStringVec
Definition: declare.h:79
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
USDMTLX_API UsdMtlxUsdTypeInfo UsdMtlxGetUsdType(const std::string &mtlxTypeName)
Convert a (standard) MaterialX type name.
TfToken shaderPropertyType
Definition: utils.h:134
USDMTLX_API const NdrStringVec & UsdMtlxSearchPaths()
USDMTLX_API std::vector< std::string > UsdMtlxSplitStringArray(const std::string &s)
USDMTLX_API NdrStringVec UsdMtlxStandardFileExtensions()
Return the MaterialX standard file extensions.
bool valueTypeNameIsExact
Definition: utils.h:142
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
Result of UsdMtlxGetUsdType().
Definition: utils.h:115
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
type
Definition: core.h:1059
#define USDMTLX_API
Definition: api.h:40
shared_ptr< const Document > ConstDocumentPtr
A shared pointer to a const Document.
Definition: Document.h:24
Definition: value.h:167
USDMTLX_API VtValue UsdMtlxGetUsdValue(const MaterialX::ConstElementPtr &mtlx, bool getDefaultValue=false)
UsdMtlxUsdTypeInfo(SdfValueTypeName valueTypeName, bool valueTypeNameIsExact, TfToken shaderPropertyType, int arraySize=0)
Definition: utils.h:116
USDMTLX_API std::vector< VtValue > UsdMtlxGetPackedUsdValues(const std::string &values, const std::string &type)