HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dataSourceMaterialNetworkInterface.h
Go to the documentation of this file.
1 //
2 // Copyright 2021 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 #ifndef HD_DATA_SOURCE_MATERIAL_NETWORK_INTERFACE_H
25 #define HD_DATA_SOURCE_MATERIAL_NETWORK_INTERFACE_H
26 
27 #include "pxr/usd/sdf/path.h"
33 #include <unordered_map>
34 #include <unordered_set>
35 
37 
38 /// \class HdDataSourceMaterialNetworkInterface
39 ///
40 /// Implements HdMaterialNetworkInterface for reading from and overriding
41 /// values within data sources. Overrides are managed internally via an
42 /// HdContainerDataSourceEditor. Calling Finish returns the resulting
43 /// container data resource representing an individual material network. If
44 /// nothing is overriden, the input data source is returned.
47 {
48 public:
49 
51  const SdfPath &materialPrimPath,
52  const HdContainerDataSourceHandle &networkContainer,
53  const HdContainerDataSourceHandle &primContainer)
54  : _materialPrimPath(materialPrimPath)
55  , _networkSchema(networkContainer)
56  , _networkEditor(networkContainer)
57  , _primContainer(primContainer)
58  , _nodesSchema(nullptr)
59  , _lastAccessedNodeSchema(nullptr)
60  , _lastAccessedNodeParametersSchema(nullptr)
61  , _lastAccessedNodeConnectionsSchema(nullptr)
62  {}
63 
64  HD_API
65  SdfPath GetMaterialPrimPath() const override {
66  return _materialPrimPath;
67  }
68 
69  HD_API
70  std::string GetModelAssetName() const override;
71 
72  HD_API
73  TfTokenVector GetNodeNames() const override;
74 
75  HD_API
76  TfToken GetNodeType(const TfToken &nodeName) const override;
77 
78  HD_API
79  TfTokenVector GetNodeTypeInfoKeys(const TfToken& nodeName) const override;
80  HD_API
82  const TfToken& nodeName, const TfToken& value) const override;
83 
84  HD_API
86  const TfToken &nodeName) const override;
87 
88  HD_API
90  const TfToken &nodeName,
91  const TfToken &paramName) const override;
92 
93  HD_API
95  const TfToken &nodeName,
96  const TfToken &paramName) const override;
97 
98  HD_API
100  const TfToken &nodeName) const override;
101 
102  HD_API
104  const TfToken &nodeName,
105  const TfToken &inputName) const override;
106 
107  HD_API
108  void DeleteNode(const TfToken &nodeName) override;
109 
110  HD_API
111  void SetNodeType(
112  const TfToken &nodeName,
113  const TfToken &nodeType) override;
114 
115  HD_API
117  const TfToken &nodeName,
118  const TfToken &paramName,
119  const VtValue &value) override;
120 
121  HD_API
123  const TfToken &nodeName,
124  const TfToken &paramName,
125  const NodeParamData &paramData) override;
126 
127  HD_API
128  void DeleteNodeParameter(
129  const TfToken &nodeName,
130  const TfToken &paramName) override;
131 
132  HD_API
134  const TfToken &nodeName,
135  const TfToken &inputName,
136  const InputConnectionVector &connections) override;
137 
138  HD_API
140  const TfToken &nodeName,
141  const TfToken &inputName) override;
142 
143  HD_API
144  TfTokenVector GetTerminalNames() const override;
145 
146  HD_API
148  const TfToken &terminalName) const override;
149 
150  HD_API
151  void DeleteTerminal(
152  const TfToken &terminalName) override;
153 
154  HD_API
156  const TfToken &terminalName,
157  const InputConnection &connection) override;
158 
159  HD_API
160  HdContainerDataSourceHandle Finish();
161 
162 private:
163  HdContainerDataSourceHandle _GetNodeTypeInfo(
164  const TfToken& nodeName) const;
165 
166  using _OverrideMap =
167  std::unordered_map<HdDataSourceLocator, HdDataSourceBaseHandle,
168  TfHash>;
169 
170  using _TokenSet = std::unordered_set<TfToken, TfHash>;
171 
172  void _SetOverride(
173  const HdDataSourceLocator &loc,
174  const HdDataSourceBaseHandle &ds);
175 
176  SdfPath _materialPrimPath;
177  mutable HdMaterialNetworkSchema _networkSchema;
178  HdContainerDataSourceEditor _networkEditor;
179  HdContainerDataSourceHandle _primContainer;
180  _OverrideMap _existingOverrides;
181  _TokenSet _overriddenNodes;
182  _TokenSet _deletedNodes;
183  bool _terminalsOverridden = false;
184 
185  // cache some common child containers to avoid repeated access
186  HdMaterialNodeSchema _ResetIfNecessaryAndGetNode(
187  const TfToken &nodeName) const;
188  HdMaterialNodeParameterContainerSchema _GetNodeParameters(
189  const TfToken &nodeName) const;
190  HdMaterialConnectionVectorContainerSchema _GetNodeConnections(
191  const TfToken &nodeName) const;
192 
193  mutable HdMaterialNodeContainerSchema _nodesSchema;
194 
195 
196  mutable TfToken _lastAccessedNodeName;
197 
198 
199  mutable HdMaterialNodeSchema _lastAccessedNodeSchema;
200  mutable HdMaterialNodeParameterContainerSchema _lastAccessedNodeParametersSchema;
201  mutable HdMaterialConnectionVectorContainerSchema _lastAccessedNodeConnectionsSchema;
202 };
203 
205 
206 #endif // HD_DATA_SOURCE_MATERIAL_NETWORK_INTERFACE_H
HdDataSourceMaterialNetworkInterface(const SdfPath &materialPrimPath, const HdContainerDataSourceHandle &networkContainer, const HdContainerDataSourceHandle &primContainer)
HD_API void DeleteNode(const TfToken &nodeName) override
HD_API void SetNodeParameterData(const TfToken &nodeName, const TfToken &paramName, const NodeParamData &paramData) override
HD_API VtValue GetNodeParameterValue(const TfToken &nodeName, const TfToken &paramName) const override
HD_API void DeleteNodeInputConnection(const TfToken &nodeName, const TfToken &inputName) override
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
HD_API TfTokenVector GetNodeNames() const override
HD_API HdMaterialNetworkInterface::NodeParamData GetNodeParameterData(const TfToken &nodeName, const TfToken &paramName) const override
HD_API TfToken GetNodeType(const TfToken &nodeName) const override
HD_API void SetNodeType(const TfToken &nodeName, const TfToken &nodeType) override
#define HD_API
Definition: api.h:40
HD_API TfTokenVector GetNodeTypeInfoKeys(const TfToken &nodeName) const override
HD_API HdContainerDataSourceHandle Finish()
Definition: hash.h:477
Definition: token.h:87
HD_API void DeleteNodeParameter(const TfToken &nodeName, const TfToken &paramName) override
HD_API void SetNodeParameterValue(const TfToken &nodeName, const TfToken &paramName, const VtValue &value) override
HD_API VtValue GetNodeTypeInfoValue(const TfToken &nodeName, const TfToken &value) const override
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457
Definition: path.h:290
HD_API void DeleteTerminal(const TfToken &terminalName) override
HD_API TfTokenVector GetNodeInputConnectionNames(const TfToken &nodeName) const override
HD_API InputConnectionResult GetTerminalConnection(const TfToken &terminalName) const override
HD_API TfTokenVector GetTerminalNames() const override
TfSmallVector< InputConnection, 4 > InputConnectionVector
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
HD_API void SetNodeInputConnection(const TfToken &nodeName, const TfToken &inputName, const InputConnectionVector &connections) override
HD_API InputConnectionVector GetNodeInputConnection(const TfToken &nodeName, const TfToken &inputName) const override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HD_API TfTokenVector GetAuthoredNodeParameterNames(const TfToken &nodeName) const override
Definition: core.h:1131
HD_API std::string GetModelAssetName() const override
HD_API void SetTerminalConnection(const TfToken &terminalName, const InputConnection &connection) override
std::pair< bool, InputConnection > InputConnectionResult
Definition: value.h:164