Loading...
Searching...
No Matches
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"
32#include "pxr/imaging/hd/schemaTypeDefs.h"
33#include <unordered_map>
34#include <unordered_set>
35
36PXR_NAMESPACE_OPEN_SCOPE
37
47{
48public:
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
81 VtValue GetNodeTypeInfoValue(
82 const TfToken& nodeName, const TfToken& value) const override;
83
84 HD_API
85 TfTokenVector GetAuthoredNodeParameterNames(
86 const TfToken &nodeName) const override;
87
88 HD_API
89 VtValue GetNodeParameterValue(
90 const TfToken &nodeName,
91 const TfToken &paramName) const override;
92
93 HD_API
94 HdMaterialNetworkInterface::NodeParamData GetNodeParameterData(
95 const TfToken &nodeName,
96 const TfToken &paramName) const override;
97
98 HD_API
99 TfTokenVector GetNodeInputConnectionNames(
100 const TfToken &nodeName) const override;
101
102 HD_API
103 InputConnectionVector GetNodeInputConnection(
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
116 void SetNodeParameterValue(
117 const TfToken &nodeName,
118 const TfToken &paramName,
119 const VtValue &value) override;
120
121 HD_API
122 void SetNodeParameterData(
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
133 void SetNodeInputConnection(
134 const TfToken &nodeName,
135 const TfToken &inputName,
136 const InputConnectionVector &connections) override;
137
138 HD_API
139 void DeleteNodeInputConnection(
140 const TfToken &nodeName,
141 const TfToken &inputName) override;
142
143 HD_API
145
146 HD_API
147 InputConnectionResult GetTerminalConnection(
148 const TfToken &terminalName) const override;
149
150 HD_API
151 void DeleteTerminal(
152 const TfToken &terminalName) override;
153
154 HD_API
155 void SetTerminalConnection(
156 const TfToken &terminalName,
157 const InputConnection &connection) override;
158
159 HD_API
160 HdContainerDataSourceHandle Finish();
161
162private:
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;
189 const TfToken &nodeName) const;
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
204PXR_NAMESPACE_CLOSE_SCOPE
205
206#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 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 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.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:291
A user-extensible hashing mechanism for use with runtime hash tables.
Definition: hash.h:477
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:179
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:165
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457