dataSourceMaterialNetworkInterface.h
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"
28 #include "pxr/imaging/hd/containerDataSourceEditor.h"
29 #include "pxr/imaging/hd/materialNetworkInterface.h"
30 #include <unordered_map>
31 #include <unordered_set>
32 
33 PXR_NAMESPACE_OPEN_SCOPE
34 
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
68  VtValue GetNodeTypeInfoValue(
69  const TfToken& nodeName, const TfToken& value) const override;
70 
71  HD_API
72  TfTokenVector GetAuthoredNodeParameterNames(
73  const TfToken &nodeName) const override;
74 
75  HD_API
76  VtValue GetNodeParameterValue(
77  const TfToken &nodeName,
78  const TfToken &paramName) const override;
79 
80  HD_API
81  TfTokenVector GetNodeInputConnectionNames(
82  const TfToken &nodeName) const override;
83 
84  HD_API
85  InputConnectionVector GetNodeInputConnection(
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
98  void SetNodeParameterValue(
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
109  void SetNodeInputConnection(
110  const TfToken &nodeName,
111  const TfToken &inputName,
112  const InputConnectionVector &connections) override;
113 
114  HD_API
115  void DeleteNodeInputConnection(
116  const TfToken &nodeName,
117  const TfToken &inputName) override;
118 
119  HD_API
120  TfTokenVector GetTerminalNames() const override;
121 
122  HD_API
123  InputConnectionResult GetTerminalConnection(
124  const TfToken &terminalName) const override;
125 
126  HD_API
127  void DeleteTerminal(
128  const TfToken &terminalName) override;
129 
130  HD_API
131  void SetTerminalConnection(
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 
175 PXR_NAMESPACE_CLOSE_SCOPE
176 
177 #endif // HD_DATA_SOURCE_MATERIAL_NETWORK_INTERFACE_H
Abstract interface for querying and mutating a material network.
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:177
Implements HdMaterialNetworkInterface for reading from and overriding values within data sources.
A user-extensible hashing mechanism for use with runtime hash tables.
Definition: hash.h:447
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
Represents an object that can identify the location of a data source.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
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...
HD_API TfTokenVector GetTerminalNames() const override
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166