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"
30 #include <unordered_map>
31 #include <unordered_set>
32 
34 
35 /// \class HdDataSourceMaterialNetworkInterface
36 ///
37 /// Implements HdMaterialNetworkInterface for reading from and overriding
38 /// values within data sources. Overrides are managed internally via an
39 /// HdContainerDataSourceEditor. Calling Finish returns the resulting
40 /// container data resource representing an individual material network. If
41 /// nothing is overriden, the input data source is returned.
44 {
45 public:
46 
48  const SdfPath &materialPrimPath,
49  const HdContainerDataSourceHandle &networkContainer)
50  : _materialPrimPath(materialPrimPath)
51  , _networkContainer(networkContainer)
52  , _containerEditor(networkContainer)
53  {}
54 
55  SdfPath GetMaterialPrimPath() const override {
56  return _materialPrimPath;
57  }
58 
59  HD_API
60  TfTokenVector GetNodeNames() const override;
61 
62  HD_API
63  TfToken GetNodeType(const TfToken &nodeName) const override;
64 
65  HD_API
66  TfTokenVector GetNodeTypeInfoKeys(const TfToken& nodeName) const override;
67  HD_API
69  const TfToken& nodeName, const TfToken& value) const override;
70 
71  HD_API
73  const TfToken &nodeName) const override;
74 
75  HD_API
77  const TfToken &nodeName,
78  const TfToken &paramName) const override;
79 
80  HD_API
82  const TfToken &nodeName) const override;
83 
84  HD_API
86  const TfToken &nodeName,
87  const TfToken &inputName) const override;
88 
89  HD_API
90  void DeleteNode(const TfToken &nodeName) override;
91 
92  HD_API
93  void SetNodeType(
94  const TfToken &nodeName,
95  const TfToken &nodeType) override;
96 
97  HD_API
99  const TfToken &nodeName,
100  const TfToken &paramName,
101  const VtValue &value) override;
102 
103  HD_API
104  void DeleteNodeParameter(
105  const TfToken &nodeName,
106  const TfToken &paramName) override;
107 
108  HD_API
110  const TfToken &nodeName,
111  const TfToken &inputName,
112  const InputConnectionVector &connections) override;
113 
114  HD_API
116  const TfToken &nodeName,
117  const TfToken &inputName) override;
118 
119  HD_API
120  TfTokenVector GetTerminalNames() const override;
121 
122  HD_API
124  const TfToken &terminalName) const override;
125 
126  HD_API
127  void DeleteTerminal(
128  const TfToken &terminalName) override;
129 
130  HD_API
132  const TfToken &terminalName,
133  const InputConnection &connection) override;
134 
135  HD_API
136  HdContainerDataSourceHandle Finish();
137 
138 private:
139  HdContainerDataSourceHandle _GetNodeTypeInfo(
140  const TfToken& nodeName) const;
141 
142  using _OverrideMap =
143  std::unordered_map<HdDataSourceLocator, HdDataSourceBaseHandle,
144  TfHash>;
145 
146  using _TokenSet = std::unordered_set<TfToken, TfHash>;
147 
148  void _SetOverride(
149  const HdDataSourceLocator &loc,
150  const HdDataSourceBaseHandle &ds);
151 
152  SdfPath _materialPrimPath;
153  HdContainerDataSourceHandle _networkContainer;
154  HdContainerDataSourceEditor _containerEditor;
155  _OverrideMap _existingOverrides;
156  _TokenSet _overriddenNodes;
157  _TokenSet _deletedNodes;
158  bool _terminalsOverridden = false;
159 
160  // cache some common child containers to avoid repeated access
161  HdContainerDataSourceHandle _GetNode(
162  const TfToken &nodeName) const;
163  HdContainerDataSourceHandle _GetNodeParameters(
164  const TfToken &nodeName) const;
165  HdContainerDataSourceHandle _GetNodeConnections(
166  const TfToken &nodeName) const;
167 
168  mutable HdContainerDataSourceHandle _nodesContainer;
169  mutable TfToken _lastAccessedNodeName;
170  mutable HdContainerDataSourceHandle _lastAccessedNode;
171  mutable HdContainerDataSourceHandle _lastAccessedNodeParameters;
172  mutable HdContainerDataSourceHandle _lastAccessedNodeConnections;
173 };
174 
176 
177 #endif // HD_DATA_SOURCE_MATERIAL_NETWORK_INTERFACE_H
HD_API void DeleteNode(const TfToken &nodeName) override
HD_API VtValue GetNodeParameterValue(const TfToken &nodeName, const TfToken &paramName) const override
HD_API void DeleteNodeInputConnection(const TfToken &nodeName, const TfToken &inputName) override
HD_API TfTokenVector GetNodeNames() 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()
HdDataSourceMaterialNetworkInterface(const SdfPath &materialPrimPath, const HdContainerDataSourceHandle &networkContainer)
Definition: hash.h:504
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:442
Definition: path.h:291
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:1441
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 void SetTerminalConnection(const TfToken &terminalName, const InputConnection &connection) override
std::pair< bool, InputConnection > InputConnectionResult
Definition: value.h:167