utils.h
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"
31 #include "pxr/usd/sdf/valueTypeName.h"
33 #include "pxr/base/vt/value.h"
34 #include <MaterialXCore/Document.h>
35 #include <string>
36 #include <vector>
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
40 #define USD_MTLX_TOKENS \
41  ((DefaultOutputName, "out"))
42 
43 TF_DECLARE_PUBLIC_TOKENS(UsdMtlxTokens, USDMTLX_API, USD_MTLX_TOKENS);
44 
48 USDMTLX_API
49 const NdrStringVec&
50 UsdMtlxStandardLibraryPaths();
51 
54 USDMTLX_API
55 const NdrStringVec&
56 UsdMtlxCustomSearchPaths();
57 
63 USDMTLX_API
64 const NdrStringVec&
65 UsdMtlxSearchPaths();
66 
68 USDMTLX_API
69 NdrStringVec
70 UsdMtlxStandardFileExtensions();
71 
77 USDMTLX_API
78 MaterialX::DocumentPtr
79 UsdMtlxReadDocument(const std::string& resolvedPath);
80 
85 USDMTLX_API
86 MaterialX::ConstDocumentPtr
87 UsdMtlxGetDocument(const std::string& resolvedUri);
88 
91 USDMTLX_API
92 MaterialX::ConstDocumentPtr
93 UsdMtlxGetDocumentFromString(const std::string &mtlxXml);
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".
101 USDMTLX_API
102 NdrVersion
103 UsdMtlxGetVersion(const MaterialX::ConstInterfaceElementPtr& mtlx,
104  bool* implicitDefault = nullptr);
105 
110 USDMTLX_API
111 const std::string&
112 UsdMtlxGetSourceURI(const MaterialX::ConstElementPtr& element);
113 
120  int arraySize=0)
125  { }
126 
131 
135 
139 
143 };
144 
146 USDMTLX_API
148 UsdMtlxGetUsdType(const std::string& mtlxTypeName);
149 
155 USDMTLX_API
156 VtValue
157 UsdMtlxGetUsdValue(const MaterialX::ConstElementPtr& mtlx,
158  bool getDefaultValue = false);
159 
162 USDMTLX_API
163 std::vector<VtValue>
164 UsdMtlxGetPackedUsdValues(const std::string& values, const std::string& type);
165 
175 USDMTLX_API
176 std::vector<std::string>
177 UsdMtlxSplitStringArray(const std::string& s);
178 
179 PXR_NAMESPACE_CLOSE_SCOPE
180 
181 #endif // PXR_USD_USDMTLX_UTILS_H
Represents a value type name, i.e.
Definition: valueTypeName.h:87
TfToken shaderPropertyType
The exact SdrShaderProperty type name.
Definition: utils.h:134
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
This file defines some macros that are useful for declaring and using static TfTokens.
int arraySize
If the value type is a fixed-size array/tuple, this will be greater then zero.
Definition: utils.h:138
SdfValueTypeName valueTypeName
The value type name that most closely matches the MaterialX type.
Definition: utils.h:130
Result of UsdMtlxGetUsdType().
Definition: utils.h:115
bool valueTypeNameIsExact
true iff the value type name is an exact match to the MaterialX type.
Definition: utils.h:142
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166