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>;
22  using NodeDefPtr = std::shared_ptr<class NodeDef>;
24 
26 
27 class SdfPath;
28 class VtValue;
29 struct HdMaterialNetwork2;
30 struct HdMaterialNode2;
32 
33 /// Return the MaterialX search paths. In order, this includes:
34 /// - Paths set in the environment variable 'PXR_MTLX_PLUGIN_SEARCH_PATHS'
35 /// - Paths set in the environment variable 'PXR_MTLX_STDLIB_SEARCH_PATHS'
36 /// - Path to the MaterialX standard library discovered at build time.
38 const MaterialX::FileSearchPath&
40 
41 /// Return a MaterialX document with the stdlibraries loaded using the above
42 /// search paths.
46 
47 /// Converts the HdParameterValue to a string MaterialX can understand
49 std::string
50 HdMtlxConvertToString(VtValue const& hdParameterValue);
51 
52 // Storing MaterialX-Hydra texture and primvar information
54  HdMtlxTexturePrimvarData() = default;
55  using TextureMap = std::map<std::string, std::set<std::string>>;
56  TextureMap mxHdTextureMap; // Mx-Hd texture name mapping
57  std::set<SdfPath> hdTextureNodes; // Paths to HdTexture Nodes
58  std::set<SdfPath> hdPrimvarNodes; // Paths to HdPrimvar nodes
59 };
60 
62 std::string
64 
65 /// Custom nodes may have their nodeDefs in a separate mtlx file, this function
66 /// additional looks to the ImplementationURI stored on the sdr to find this
67 /// mtlx file and nodeDef.
68 /// This method is preferred over mxDoc->getNodeDef() to catch this custom
69 /// node case.
73  TfToken const& hdNodeType,
74  MaterialX::DocumentPtr const& mxDoc=nullptr);
75 
76 /// NodeDef names may change between MaterialX versions, this function returns
77 /// the nodeDef name appropriate for the version of MaterialX being used.
79 std::string
80 HdMtlxGetNodeDefName(std::string const& prevMxNodeDefName);
81 
82 /// Get the terminal name used in the MaterialX document based on the Hydra
83 /// terminal node.
85 std::string
87  HdMaterialNetworkInterface *netInterface,
88  TfToken const& hdTerminalNodeName);
89 
90 /// Get the terminal name used in the MaterialX document based on the MaterialX
91 /// terminal node type.
93 std::string
94 HdMtlxGetMxTerminalName(std::string const& mxTerminalType);
95 
96 /// Creates and returns a MaterialX Document from the given HdMaterialNetwork2
97 /// Collecting the hdTextureNodes and hdPrimvarNodes as the network is
98 /// traversed as well as the Texture name mapping between MaterialX and Hydra.
102  HdMaterialNetwork2 const& hdNetwork,
103  HdMaterialNode2 const& hdMaterialXNode,
104  SdfPath const& hdMaterialXNodePath,
105  SdfPath const& materialPath,
106  MaterialX::DocumentPtr const& libraries,
107  HdMtlxTexturePrimvarData *mxHdData = nullptr);
108 
109 /// Implementation that uses the material network interface.
113  HdMaterialNetworkInterface *netInterface,
114  TfToken const& terminalNodeName,
115  TfTokenVector const& terminalNodeConnectionNames,
116  MaterialX::DocumentPtr const& libraries,
117  HdMtlxTexturePrimvarData *mxHdData = nullptr);
118 
120 
121 #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
HDMTLX_API std::string HdMtlxGetMxTerminalName(HdMaterialNetworkInterface *netInterface, TfToken const &hdTerminalNodeName)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
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:57
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)
HDMTLX_API std::string HdMtlxGetNodeDefName(std::string const &prevMxNodeDefName)
std::map< std::string, std::set< std::string >> TextureMap
Definition: hdMtlx.h:55
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
HDMTLX_API MaterialX::NodeDefPtr HdMtlxGetNodeDef(TfToken const &hdNodeType, MaterialX::DocumentPtr const &mxDoc=nullptr)
Definition: path.h:280
TextureMap mxHdTextureMap
Definition: hdMtlx.h:56
std::set< SdfPath > hdPrimvarNodes
Definition: hdMtlx.h:58
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
std::shared_ptr< class NodeDef > NodeDefPtr
Definition: hdMtlx.h:22
#define HDMTLX_API
Definition: api.h:23
Definition: value.h:89
HDMTLX_API const MaterialX::DocumentPtr & HdMtlxStdLibraries()
shared_ptr< NodeDef > NodeDefPtr
A shared pointer to a NodeDef.
Definition: Definition.h:32