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 
33 PXR_NAMESPACE_OPEN_SCOPE
34 
42 {
43 public:
44  HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrimvars);
45 
46  bool Has(const TfToken &name) override;
47  TfTokenVector GetNames() override;
48  HdDataSourceBaseHandle Get(const TfToken &name) override;
49 
50  // This map is passed to the constructor to specify non-"primvars:"
51  // attributes to include as primvars (e.g., "points" and "normals").
52  // The first token is the datasource name, and the second the USD name.
53  using CustomPrimvarMapping = std::vector<std::pair<TfToken, TfToken>>;
54 
55 private:
57  const SdfPath &sceneIndexPath,
58  UsdGeomPrimvarsAPI usdPrimvars,
59  const CustomPrimvarMapping &customPrimvarMapping,
60  const UsdImagingDataSourceStageGlobals &stageGlobals);
61 
62 private:
63 
64  TfToken _GetCustomPrimvarInterpolation(const UsdAttributeQuery &attrQuery);
65 
66  // Path of the owning prim.
67  SdfPath _sceneIndexPath;
68 
69  // Stage globals handle.
70  const UsdImagingDataSourceStageGlobals &_stageGlobals;
71 
72  // Maps to custom & namespace-enumerated primvars, populated at
73  // construction time...
74  using _CustomPrimvarsMap = std::map<TfToken, UsdAttributeQuery>;
75  _CustomPrimvarsMap _customPrimvars;
76  using _NamespacedPrimvarsMap = std::map<TfToken, UsdGeomPrimvar>;
77  _NamespacedPrimvarsMap _namespacedPrimvars;
78 };
79 
80 HD_DECLARE_DATASOURCE_HANDLES(UsdImagingDataSourcePrimvars);
81 
82 // ----------------------------------------------------------------------------
83 
97 {
98 public:
99  HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrimvar);
100 
101  bool Has(const TfToken & name) override;
102  TfTokenVector GetNames() override;
103  HdDataSourceBaseHandle Get(const TfToken & name) override;
104 
105 private:
107  const SdfPath &sceneIndexPath,
108  const TfToken &name,
109  const UsdImagingDataSourceStageGlobals &stageGlobals,
110  UsdAttributeQuery valueQuery,
111  UsdAttributeQuery indicesQuery,
112  HdTokenDataSourceHandle interpolation,
113  HdTokenDataSourceHandle role);
114 
115 private:
116  const UsdImagingDataSourceStageGlobals &_stageGlobals;
117  UsdAttributeQuery _valueQuery;
118  UsdAttributeQuery _indicesQuery;
119  HdTokenDataSourceHandle _interpolation;
120  HdTokenDataSourceHandle _role;
121 };
122 
123 HD_DECLARE_DATASOURCE_HANDLES(UsdImagingDataSourcePrimvar);
124 
125 PXR_NAMESPACE_CLOSE_SCOPE
126 
127 #endif // PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_PRIMVARS_H
Object for efficiently making repeated queries for attribute values.
A datasource representing structured (named, hierarchical) data, for example a geometric primitive or...
Definition: dataSource.h:102
UsdGeomPrimvarsAPI encodes geometric "primitive variables", as UsdGeomPrimvar, which interpolate acro...
Definition: primvarsAPI.h:82
HdDataSourceBaseHandle Get(const TfToken &name) override
Returns the child datasource of the given name.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
This class is used as a context object with global stage information, that gets passed down to dataso...
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
TfTokenVector GetNames() override
Returns the list of names for which Get(...) is expected to return a non-null value.
bool Has(const TfToken &name) override
Returns true if the container has a child datasource of the given name, in which case Get(name) is ex...
Data source representing USD primvars.
A data source representing a primvar.
bool Has(const TfToken &name) override
Returns true if the container has a child datasource of the given name, in which case Get(name) is ex...
HdDataSourceBaseHandle Get(const TfToken &name) override
Returns the child datasource of the given name.
TfTokenVector GetNames() override
Returns the list of names for which Get(...) is expected to return a non-null value.