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"
30#include <unordered_map>
31#include <unordered_set>
32
33PXR_NAMESPACE_OPEN_SCOPE
34
44{
45public:
46
48 const SdfPath &materialPrimPath,
49 const HdContainerDataSourceHandle &networkContainer,
50 const HdContainerDataSourceHandle &primContainer)
51 : _materialPrimPath(materialPrimPath)
52 , _networkContainer(networkContainer)
53 , _networkEditor(networkContainer)
54 , _primContainer(primContainer)
55 {}
56
57 HD_API
58 SdfPath GetMaterialPrimPath() const override {
59 return _materialPrimPath;
60 }
61
62 HD_API
63 std::string GetModelAssetName() const override;
64
65 HD_API
66 TfTokenVector GetNodeNames() const override;
67
68 HD_API
69 TfToken GetNodeType(const TfToken &nodeName) const override;
70
71 HD_API
72 TfTokenVector GetNodeTypeInfoKeys(const TfToken& nodeName) const override;
73 HD_API
74 VtValue GetNodeTypeInfoValue(
75 const TfToken& nodeName, const TfToken& value) const override;
76
77 HD_API
78 TfTokenVector GetAuthoredNodeParameterNames(
79 const TfToken &nodeName) const override;
80
81 HD_API
82 VtValue GetNodeParameterValue(
83 const TfToken &nodeName,
84 const TfToken &paramName) const override;
85
86 HD_API
87 TfTokenVector GetNodeInputConnectionNames(
88 const TfToken &nodeName) const override;
89
90 HD_API
91 InputConnectionVector GetNodeInputConnection(
92 const TfToken &nodeName,
93 const TfToken &inputName) const override;
94
95 HD_API
96 void DeleteNode(const TfToken &nodeName) override;
97
98 HD_API
99 void SetNodeType(
100 const TfToken &nodeName,
101 const TfToken &nodeType) override;
102
103 HD_API
104 void SetNodeParameterValue(
105 const TfToken &nodeName,
106 const TfToken &paramName,
107 const VtValue &value) override;
108
109 HD_API
110 void DeleteNodeParameter(
111 const TfToken &nodeName,
112 const TfToken &paramName) override;
113
114 HD_API
115 void SetNodeInputConnection(
116 const TfToken &nodeName,
117 const TfToken &inputName,
118 const InputConnectionVector &connections) override;
119
120 HD_API
121 void DeleteNodeInputConnection(
122 const TfToken &nodeName,
123 const TfToken &inputName) override;
124
125 HD_API
127
128 HD_API
129 InputConnectionResult GetTerminalConnection(
130 const TfToken &terminalName) const override;
131
132 HD_API
133 void DeleteTerminal(
134 const TfToken &terminalName) override;
135
136 HD_API
137 void SetTerminalConnection(
138 const TfToken &terminalName,
139 const InputConnection &connection) override;
140
141 HD_API
142 HdContainerDataSourceHandle Finish();
143
144private:
145 HdContainerDataSourceHandle _GetNodeTypeInfo(
146 const TfToken& nodeName) const;
147
148 using _OverrideMap =
149 std::unordered_map<HdDataSourceLocator, HdDataSourceBaseHandle,
150 TfHash>;
151
152 using _TokenSet = std::unordered_set<TfToken, TfHash>;
153
154 void _SetOverride(
155 const HdDataSourceLocator &loc,
156 const HdDataSourceBaseHandle &ds);
157
158 SdfPath _materialPrimPath;
159 HdContainerDataSourceHandle _networkContainer;
160 HdContainerDataSourceEditor _networkEditor;
161 HdContainerDataSourceHandle _primContainer;
162 _OverrideMap _existingOverrides;
163 _TokenSet _overriddenNodes;
164 _TokenSet _deletedNodes;
165 bool _terminalsOverridden = false;
166
167 // cache some common child containers to avoid repeated access
168 HdContainerDataSourceHandle _GetNode(
169 const TfToken &nodeName) const;
170 HdContainerDataSourceHandle _GetNodeParameters(
171 const TfToken &nodeName) const;
172 HdContainerDataSourceHandle _GetNodeConnections(
173 const TfToken &nodeName) const;
174
175 mutable HdContainerDataSourceHandle _nodesContainer;
176 mutable TfToken _lastAccessedNodeName;
177 mutable HdContainerDataSourceHandle _lastAccessedNode;
178 mutable HdContainerDataSourceHandle _lastAccessedNodeParameters;
179 mutable HdContainerDataSourceHandle _lastAccessedNodeConnections;
180};
181
182PXR_NAMESPACE_CLOSE_SCOPE
183
184#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:504
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:164
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442