Loading...
Searching...
No Matches
dataSourcePrimvars.h
1//
2// Copyright 2022 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 PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_PRIMVARS_H
25#define PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_PRIMVARS_H
26
27#include "pxr/usdImaging/usdImaging/dataSourceAttribute.h"
28#include "pxr/usdImaging/usdImaging/dataSourceStageGlobals.h"
29
30#include "pxr/usd/usdGeom/primvar.h"
32
33PXR_NAMESPACE_OPEN_SCOPE
34
42{
43public:
44 HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrimvars);
45
47 HdDataSourceBaseHandle Get(const TfToken &name) override;
48
49private:
51 const SdfPath &sceneIndexPath,
52 UsdPrim const &usdPrim,
53 UsdGeomPrimvarsAPI usdPrimvars,
54 const UsdImagingDataSourceStageGlobals &stageGlobals);
55
56private:
57 static TfToken _GetPrefixedName(const TfToken &name);
58
59 // Path of the owning prim.
60 SdfPath _sceneIndexPath;
61
62 UsdPrim _usdPrim;
63
64 // Stage globals handle.
65 const UsdImagingDataSourceStageGlobals &_stageGlobals;
66
67 using _NamespacedPrimvarsMap = std::map<TfToken, UsdGeomPrimvar>;
68 _NamespacedPrimvarsMap _namespacedPrimvars;
69};
70
71HD_DECLARE_DATASOURCE_HANDLES(UsdImagingDataSourcePrimvars);
72
73// ----------------------------------------------------------------------------
74
75class UsdImagingDataSourceCustomPrimvars : public HdContainerDataSource
76{
77public:
78 HD_DECLARE_DATASOURCE(UsdImagingDataSourceCustomPrimvars);
79
80 USDIMAGING_API
81 TfTokenVector GetNames() override;
82
83 USDIMAGING_API
84 HdDataSourceBaseHandle Get(const TfToken &name) override;
85
86 struct Mapping {
87 Mapping(
88 const TfToken &primvarName,
89 const TfToken &usdAttrName,
90 const TfToken &interpolation = TfToken())
91 : primvarName(primvarName)
92 , usdAttrName(usdAttrName)
93 , interpolation(interpolation)
94 { }
95
96 TfToken primvarName;
97 TfToken usdAttrName;
98 TfToken interpolation;
99 };
100
101 // This map is passed to the constructor to specify non-"primvars:"
102 // attributes to include as primvars (e.g., "points" and "normals").
103 // The first token is the datasource name, and the second the USD name.
104 using Mappings = std::vector<Mapping>;
105
106 USDIMAGING_API
107 static HdDataSourceLocatorSet Invalidate(
108 const TfTokenVector &properties,
109 const Mappings &mappings);
110
111private:
112 UsdImagingDataSourceCustomPrimvars(
113 const SdfPath &sceneIndexPath,
114 UsdPrim const &usdPrim,
115 const Mappings &mappings,
116 const UsdImagingDataSourceStageGlobals &stageGlobals);
117
118 // Path of the owning prim.
119 SdfPath _sceneIndexPath;
120
121 UsdPrim _usdPrim;
122
123 // Stage globals handle.
124 const UsdImagingDataSourceStageGlobals &_stageGlobals;
125
126 using _CustomPrimvarsMap =
127 std::map<TfToken,
128 std::pair<UsdAttributeQuery,
129 TfToken /* forced interpolation */>>;
130 _CustomPrimvarsMap _customPrimvars;
131};
132
133HD_DECLARE_DATASOURCE_HANDLES(UsdImagingDataSourceCustomPrimvars);
134
135// ----------------------------------------------------------------------------
136
150{
151public:
152 HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrimvar);
153
155 HdDataSourceBaseHandle Get(const TfToken & name) override;
156
157private:
159 const SdfPath &sceneIndexPath,
160 const TfToken &name,
161 const UsdImagingDataSourceStageGlobals &stageGlobals,
162 UsdAttributeQuery valueQuery,
163 UsdAttributeQuery indicesQuery,
164 HdTokenDataSourceHandle interpolation,
165 HdTokenDataSourceHandle role);
166
167private:
168 const UsdImagingDataSourceStageGlobals &_stageGlobals;
169 UsdAttributeQuery _valueQuery;
170 UsdAttributeQuery _indicesQuery;
171 HdTokenDataSourceHandle _interpolation;
172 HdTokenDataSourceHandle _role;
173};
174
175HD_DECLARE_DATASOURCE_HANDLES(UsdImagingDataSourcePrimvar);
176
177PXR_NAMESPACE_CLOSE_SCOPE
178
179#endif // PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_PRIMVARS_H
A datasource representing structured (named, hierarchical) data, for example a geometric primitive or...
Definition: dataSource.h:116
virtual TfTokenVector GetNames()=0
Returns the list of names for which Get(...) is expected to return a non-null value.
virtual HdDataSourceBaseHandle Get(const TfToken &name)=0
Returns the child datasource of the given name.
Represents a set of data source locators closed under descendancy.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Object for efficiently making repeated queries for attribute values.
UsdGeomPrimvarsAPI encodes geometric "primitive variables", as UsdGeomPrimvar, which interpolate acro...
Definition: primvarsAPI.h:83
A data source representing a primvar.
TfTokenVector GetNames() override
Returns the list of names for which Get(...) is expected to return a non-null value.
HdDataSourceBaseHandle Get(const TfToken &name) override
Returns the child datasource of the given name.
Data source representing USD primvars.
TfTokenVector GetNames() override
Returns the list of names for which Get(...) is expected to return a non-null value.
HdDataSourceBaseHandle Get(const TfToken &name) override
Returns the child datasource of the given name.
This class is used as a context object with global stage information, that gets passed down to dataso...
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:134
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457