HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hdMtlx.h
Go to the documentation of this file.
1 //
2 // Copyright 2021 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HD_MTLX_HDMTLX_H
8 #define PXR_IMAGING_HD_MTLX_HDMTLX_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/base/tf/token.h"
12 #include "pxr/imaging/hdMtlx/api.h"
13 #include <memory>
14 #include <set>
15 #include <unordered_map>
16 
17 #include <MaterialXCore/Library.h>
18 
20  class FileSearchPath;
21  using DocumentPtr = std::shared_ptr<class Document>;
23 
25 
26 class SdfPath;
27 class VtValue;
28 struct HdMaterialNetwork2;
29 struct HdMaterialNode2;
31 
32 /// Return the MaterialX search paths. In order, this includes:
33 /// - Paths set in the environment variable 'PXR_MTLX_PLUGIN_SEARCH_PATHS'
34 /// - Paths set in the environment variable 'PXR_MTLX_STDLIB_SEARCH_PATHS'
35 /// - Path to the MaterialX standard library discovered at build time.
37 const MaterialX::FileSearchPath&
39 
40 /// Return a MaterialX document with the stdlibraries loaded using the above
41 /// search paths.
45 
46 /// Converts the HdParameterValue to a string MaterialX can understand
48 std::string
49 HdMtlxConvertToString(VtValue const& hdParameterValue);
50 
51 // Storing MaterialX-Hydra texture and primvar information
53  HdMtlxTexturePrimvarData() = default;
54  using TextureMap = std::map<std::string, std::set<std::string>>;
55  TextureMap mxHdTextureMap; // Mx-Hd texture name mapping
56  std::set<SdfPath> hdTextureNodes; // Paths to HdTexture Nodes
57  std::set<SdfPath> hdPrimvarNodes; // Paths to HdPrimvar nodes
58 };
59 
61 std::string
63 
64 /// Creates and returns a MaterialX Document from the given HdMaterialNetwork2
65 /// Collecting the hdTextureNodes and hdPrimvarNodes as the network is
66 /// traversed as well as the Texture name mapping between MaterialX and Hydra.
70  HdMaterialNetwork2 const& hdNetwork,
71  HdMaterialNode2 const& hdMaterialXNode,
72  SdfPath const& hdMaterialXNodePath,
73  SdfPath const& materialPath,
74  MaterialX::DocumentPtr const& libraries,
75  HdMtlxTexturePrimvarData *mxHdData = nullptr);
76 
77 /// Implementation that uses the material network interface.
81  HdMaterialNetworkInterface *netInterface,
82  TfToken const& terminalNodeName,
83  TfTokenVector const& terminalNodeConnectionNames,
84  MaterialX::DocumentPtr const& libraries,
85  HdMtlxTexturePrimvarData *mxHdData = nullptr);
86 
88 
89 #endif
HDMTLX_API std::string HdMtlxConvertToString(VtValue const &hdParameterValue)
Converts the HdParameterValue to a string MaterialX can understand.
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
HDMTLX_API const MaterialX::FileSearchPath & HdMtlxSearchPaths()
std::shared_ptr< class Document > DocumentPtr
Definition: hdMtlx.h:21
HdMtlxTexturePrimvarData()=default
HDMTLX_API MaterialX::DocumentPtr HdMtlxCreateMtlxDocumentFromHdNetwork(HdMaterialNetwork2 const &hdNetwork, HdMaterialNode2 const &hdMaterialXNode, SdfPath const &hdMaterialXNodePath, SdfPath const &materialPath, MaterialX::DocumentPtr const &libraries, HdMtlxTexturePrimvarData *mxHdData=nullptr)
std::set< SdfPath > hdTextureNodes
Definition: hdMtlx.h:56
Definition: token.h:70
HDMTLX_API MaterialX::DocumentPtr HdMtlxCreateMtlxDocumentFromHdMaterialNetworkInterface(HdMaterialNetworkInterface *netInterface, TfToken const &terminalNodeName, TfTokenVector const &terminalNodeConnectionNames, MaterialX::DocumentPtr const &libraries, HdMtlxTexturePrimvarData *mxHdData=nullptr)
Implementation that uses the material network interface.
HDMTLX_API std::string HdMtlxCreateNameFromPath(SdfPath const &path)
std::map< std::string, std::set< std::string >> TextureMap
Definition: hdMtlx.h:54
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: path.h:273
TextureMap mxHdTextureMap
Definition: hdMtlx.h:55
std::set< SdfPath > hdPrimvarNodes
Definition: hdMtlx.h:57
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
#define HDMTLX_API
Definition: api.h:23
Definition: value.h:146
HDMTLX_API const MaterialX::DocumentPtr & HdMtlxStdLibraries()