Loading...
Searching...
No Matches
dataSourceMaterialNetworkInterface.h
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 HD_DATA_SOURCE_MATERIAL_NETWORK_INTERFACE_H
8#define HD_DATA_SOURCE_MATERIAL_NETWORK_INTERFACE_H
9
10#include "pxr/usd/sdf/path.h"
11#include "pxr/imaging/hd/containerDataSourceEditor.h"
12#include "pxr/imaging/hd/materialNetworkInterface.h"
15#include "pxr/imaging/hd/schemaTypeDefs.h"
16#include <unordered_map>
17#include <unordered_set>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
30{
31public:
32
34 const SdfPath &materialPrimPath,
35 const HdContainerDataSourceHandle &networkContainer,
36 const HdContainerDataSourceHandle &primContainer)
37 : _materialPrimPath(materialPrimPath)
38 , _networkSchema(networkContainer)
39 , _networkEditor(networkContainer)
40 , _primContainer(primContainer)
41 , _nodesSchema(nullptr)
42 , _lastAccessedNodeSchema(nullptr)
43 , _lastAccessedNodeParametersSchema(nullptr)
44 , _lastAccessedNodeConnectionsSchema(nullptr)
45 {}
46
47 HD_API
48 SdfPath GetMaterialPrimPath() const override {
49 return _materialPrimPath;
50 }
51
52 HD_API
54 HD_API
55 VtValue GetMaterialConfigValue(const TfToken& key) const override;
56
57 HD_API
58 std::string GetModelAssetName() const override;
59
60 HD_API
61 TfTokenVector GetNodeNames() const override;
62
63 HD_API
64 TfToken GetNodeType(const TfToken &nodeName) const override;
65
66 HD_API
67 TfTokenVector GetNodeTypeInfoKeys(const TfToken& nodeName) const override;
68 HD_API
69 VtValue GetNodeTypeInfoValue(
70 const TfToken& nodeName, const TfToken& value) const override;
71
72 HD_API
73 TfTokenVector GetAuthoredNodeParameterNames(
74 const TfToken &nodeName) const override;
75
76 HD_API
77 VtValue GetNodeParameterValue(
78 const TfToken &nodeName,
79 const TfToken &paramName) const override;
80
81 HD_API
82 HdMaterialNetworkInterface::NodeParamData GetNodeParameterData(
83 const TfToken &nodeName,
84 const TfToken &paramName) const override;
85
86 HD_API
87 TfTokenVector GetNodeInputConnectionNames(
88 const TfToken &nodeName) const override;
89
90 HD_API
91 InputConnectionVector GetNodeInputConnection(
92 const TfToken &nodeName,
93 const TfToken &inputName) const override;
94
95 HD_API
96 void DeleteNode(const TfToken &nodeName) override;
97
101 HD_API
103 const TfToken &nodeName,
104 const TfToken &nodeType) override;
105
106 HD_API
107 void SetNodeTypeInfoValue(
108 const TfToken &nodeName,
109 const TfToken &key,
110 const VtValue &value) override;
111
112 HD_API
113 void SetNodeParameterValue(
114 const TfToken &nodeName,
115 const TfToken &paramName,
116 const VtValue &value) override;
117
118 HD_API
119 void SetNodeParameterData(
120 const TfToken &nodeName,
121 const TfToken &paramName,
122 const NodeParamData &paramData) override;
123
124 HD_API
125 void DeleteNodeParameter(
126 const TfToken &nodeName,
127 const TfToken &paramName) override;
128
129 HD_API
130 void SetNodeInputConnection(
131 const TfToken &nodeName,
132 const TfToken &inputName,
133 const InputConnectionVector &connections) override;
134
135 HD_API
136 void DeleteNodeInputConnection(
137 const TfToken &nodeName,
138 const TfToken &inputName) override;
139
140 HD_API
142
143 HD_API
144 InputConnectionResult GetTerminalConnection(
145 const TfToken &terminalName) const override;
146
147 HD_API
148 void DeleteTerminal(
149 const TfToken &terminalName) override;
150
151 HD_API
152 void SetTerminalConnection(
153 const TfToken &terminalName,
154 const InputConnection &connection) override;
155
156 HD_API
157 HdContainerDataSourceHandle Finish();
158
159private:
160
164 HdContainerDataSourceHandle _GetOriginalNodeTypeInfo(
165 const TfToken& nodeName) const;
166
169 HdContainerDataSourceHandle _GetNodeTypeInfo(
170 const TfToken& nodeName) const;
171
172 using _OverrideMap =
173 std::unordered_map<HdDataSourceLocator, HdDataSourceBaseHandle,
174 TfHash>;
175
176 using _HdContainerDataSourceEditorSharedPtr =
177 std::shared_ptr<class HdContainerDataSourceEditor>;
178
179 using _NodeTypeInfoMap =
180 std::unordered_map<TfToken, _HdContainerDataSourceEditorSharedPtr,
182
183 using _TokenSet = std::unordered_set<TfToken, TfHash>;
184
185 void _SetOverride(
186 const HdDataSourceLocator &loc,
187 const HdDataSourceBaseHandle &ds);
188
189 SdfPath _materialPrimPath;
190 mutable HdMaterialNetworkSchema _networkSchema;
191 HdContainerDataSourceEditor _networkEditor;
192 _NodeTypeInfoMap _nodeTypeInfoOverrides;
193 HdContainerDataSourceHandle _primContainer;
194 _OverrideMap _existingOverrides;
195 _TokenSet _overriddenNodes;
196 _TokenSet _deletedNodes;
197 bool _terminalsOverridden = false;
198
199 // cache some common child containers to avoid repeated access
200 HdMaterialNodeSchema _ResetIfNecessaryAndGetNode(
201 const TfToken &nodeName) const;
203 const TfToken &nodeName) const;
205 const TfToken &nodeName) const;
206
207 mutable HdMaterialNodeContainerSchema _nodesSchema;
208
209
210 mutable TfToken _lastAccessedNodeName;
211
212
213 mutable HdMaterialNodeSchema _lastAccessedNodeSchema;
214 mutable HdMaterialNodeParameterContainerSchema _lastAccessedNodeParametersSchema;
215 mutable HdMaterialConnectionVectorContainerSchema _lastAccessedNodeConnectionsSchema;
216};
217
218PXR_NAMESPACE_CLOSE_SCOPE
219
220#endif // HD_DATA_SOURCE_MATERIAL_NETWORK_INTERFACE_H
Represents an object that can identify the location of a data source.
Implements HdMaterialNetworkInterface for reading from and overriding values within data sources.
HD_API TfTokenVector GetMaterialConfigKeys() const override
Material config is a collection of data related to the entire material, e.g.
HD_API TfTokenVector GetTerminalNames() const override
HD_API std::string GetModelAssetName() const override
Returns the nearest enclosing model asset name, as described by the model schema, or empty string if ...
HD_API void SetNodeType(const TfToken &nodeName, const TfToken &nodeType) override
Set the nodeType for the shader node with the given nodeName.
HD_API TfTokenVector GetNodeTypeInfoKeys(const TfToken &nodeName) const override
Node type info is a collection of data related to the node type, often used to determine the node typ...
Abstract interface for querying and mutating a material network.
The MaterialNetwork schema is a container schema that defines a material for a specific render contex...
The MaterialNode schema is a container schema that defines a particular node in a material network.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
A user-extensible hashing mechanism for use with runtime hash tables.
Definition: hash.h:472
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:157
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:152
Functor to use for hash maps from tokens to other things.
Definition: token.h:149
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440