dataSourceMaterialNetworkInterface.h
1 
2 //
3 // Copyright 2021 Pixar
4 //
5 // Licensed under the Apache License, Version 2.0 (the "Apache License")
6 // with the following modification; you may not use this file except in
7 // compliance with the Apache License and the following modification to it:
8 // Section 6. Trademarks. is deleted and replaced with:
9 //
10 // 6. Trademarks. This License does not grant permission to use the trade
11 // names, trademarks, service marks, or product names of the Licensor
12 // and its affiliates, except as required to comply with Section 4(c) of
13 // the License and to reproduce the content of the NOTICE file.
14 //
15 // You may obtain a copy of the Apache License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the Apache License with the above modification is
21 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22 // KIND, either express or implied. See the Apache License for the specific
23 // language governing permissions and limitations under the Apache License.
24 //
25 #ifndef HD_DATA_SOURCE_MATERIAL_NETWORK_INTERFACE_H
26 #define HD_DATA_SOURCE_MATERIAL_NETWORK_INTERFACE_H
27 
28 #include "pxr/usd/sdf/path.h"
29 #include "pxr/imaging/hd/containerDataSourceEditor.h"
30 #include "pxr/imaging/hd/materialNetworkInterface.h"
31 #include <unordered_map>
32 #include <unordered_set>
33 
34 PXR_NAMESPACE_OPEN_SCOPE
35 
45 {
46 public:
47 
49  const SdfPath &materialPrimPath,
50  const HdContainerDataSourceHandle &networkContainer)
51  : _materialPrimPath(materialPrimPath)
52  , _networkContainer(networkContainer)
53  , _containerEditor(networkContainer)
54  {}
55 
56  SdfPath GetMaterialPrimPath() const override {
57  return _materialPrimPath;
58  }
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 GetAuthoredNodeParameterNames(
68  const TfToken &nodeName) const override;
69 
70  HD_API
71  VtValue GetNodeParameterValue(
72  const TfToken &nodeName,
73  const TfToken &paramName) const override;
74 
75  HD_API
76  TfTokenVector GetNodeInputConnectionNames(
77  const TfToken &nodeName) const override;
78 
79  HD_API
80  InputConnectionVector GetNodeInputConnection(
81  const TfToken &nodeName,
82  const TfToken &inputName) const override;
83 
84  HD_API
85  void DeleteNode(const TfToken &nodeName) override;
86 
87  HD_API
88  void SetNodeType(
89  const TfToken &nodeName,
90  const TfToken &nodeType) override;
91 
92  HD_API
93  void SetNodeParameterValue(
94  const TfToken &nodeName,
95  const TfToken &paramName,
96  const VtValue &value) override;
97 
98  HD_API
99  void DeleteNodeParameter(
100  const TfToken &nodeName,
101  const TfToken &paramName) override;
102 
103  HD_API
104  void SetNodeInputConnection(
105  const TfToken &nodeName,
106  const TfToken &inputName,
107  const InputConnectionVector &connections) override;
108 
109  HD_API
110  void DeleteNodeInputConnection(
111  const TfToken &nodeName,
112  const TfToken &inputName) override;
113 
114  HD_API
115  TfTokenVector GetTerminalNames() const override;
116 
117  HD_API
118  InputConnectionResult GetTerminalConnection(
119  const TfToken &terminalName) const override;
120 
121  HD_API
122  void DeleteTerminal(
123  const TfToken &terminalName) override;
124 
125  HD_API
126  void SetTerminalConnection(
127  const TfToken &terminalName,
128  const InputConnection &connection) override;
129 
130  HD_API
131  HdContainerDataSourceHandle Finish();
132 
133 private:
134  using _OverrideMap =
135  std::unordered_map<HdDataSourceLocator, HdDataSourceBaseHandle,
136  TfHash>;
137 
138  using _TokenSet = std::unordered_set<TfToken, TfHash>;
139 
140  void _SetOverride(
141  const HdDataSourceLocator &loc,
142  const HdDataSourceBaseHandle &ds);
143 
144  SdfPath _materialPrimPath;
145  HdContainerDataSourceHandle _networkContainer;
146  HdContainerDataSourceEditor _containerEditor;
147  _OverrideMap _existingOverrides;
148  _TokenSet _overriddenNodes;
149  _TokenSet _deletedNodes;
150  bool _terminalsOverridden = false;
151 
152  // cache some common child containers to avoid repeated access
153  HdContainerDataSourceHandle _GetNode(
154  const TfToken &nodeName) const;
155  HdContainerDataSourceHandle _GetNodeParameters(
156  const TfToken &nodeName) const;
157  HdContainerDataSourceHandle _GetNodeConnections(
158  const TfToken &nodeName) const;
159 
160  mutable HdContainerDataSourceHandle _nodesContainer;
161  mutable TfToken _lastAccessedNodeName;
162  mutable HdContainerDataSourceHandle _lastAccessedNode;
163  mutable HdContainerDataSourceHandle _lastAccessedNodeParameters;
164  mutable HdContainerDataSourceHandle _lastAccessedNodeConnections;
165 };
166 
167 PXR_NAMESPACE_CLOSE_SCOPE
168 
169 #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 GetTerminalNames() const override
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166