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  TfTokenVector GetNames() override;
47  HdDataSourceBaseHandle Get(const TfToken &name) override;
48 
49  struct CustomPrimvarMapping {
50  CustomPrimvarMapping(
51  const TfToken &primvarName,
52  const TfToken &usdAttrName,
53  const TfToken &interpolation = TfToken())
54  : primvarName(primvarName)
55  , usdAttrName(usdAttrName)
56  , interpolation(interpolation)
57  { }
58 
59  TfToken primvarName;
60  TfToken usdAttrName;
61  TfToken interpolation;
62  };
63 
64  // This map is passed to the constructor to specify non-"primvars:"
65  // attributes to include as primvars (e.g., "points" and "normals").
66  // The first token is the datasource name, and the second the USD name.
67  using CustomPrimvarMappings = std::vector<CustomPrimvarMapping>;
68 
69 private:
71  const SdfPath &sceneIndexPath,
72  UsdPrim const &usdPrim,
73  UsdGeomPrimvarsAPI usdPrimvars,
74  const CustomPrimvarMappings &customPrimvarMappings,
75  const UsdImagingDataSourceStageGlobals &stageGlobals);
76 
77 private:
78  static TfToken _GetPrefixedName(const TfToken &name);
79 
80  // Path of the owning prim.
81  SdfPath _sceneIndexPath;
82 
83  UsdPrim _usdPrim;
84 
85  // Stage globals handle.
86  const UsdImagingDataSourceStageGlobals &_stageGlobals;
87 
88  // Maps to custom & namespace-enumerated primvars, populated at
89  // construction time...
90  using _CustomPrimvarsMap =
91  std::map<TfToken,
92  std::pair<UsdAttributeQuery,
93  TfToken /* forced interpolation */>>;
94  _CustomPrimvarsMap _customPrimvars;
95  using _NamespacedPrimvarsMap = std::map<TfToken, UsdGeomPrimvar>;
96  _NamespacedPrimvarsMap _namespacedPrimvars;
97 };
98 
99 HD_DECLARE_DATASOURCE_HANDLES(UsdImagingDataSourcePrimvars);
100 
101 // ----------------------------------------------------------------------------
102 
116 {
117 public:
118  HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrimvar);
119 
120  TfTokenVector GetNames() override;
121  HdDataSourceBaseHandle Get(const TfToken & name) override;
122 
123 private:
125  const SdfPath &sceneIndexPath,
126  const TfToken &name,
127  const UsdImagingDataSourceStageGlobals &stageGlobals,
128  UsdAttributeQuery valueQuery,
129  UsdAttributeQuery indicesQuery,
130  HdTokenDataSourceHandle interpolation,
131  HdTokenDataSourceHandle role);
132 
133 private:
134  const UsdImagingDataSourceStageGlobals &_stageGlobals;
135  UsdAttributeQuery _valueQuery;
136  UsdAttributeQuery _indicesQuery;
137  HdTokenDataSourceHandle _interpolation;
138  HdTokenDataSourceHandle _role;
139 };
140 
141 HD_DECLARE_DATASOURCE_HANDLES(UsdImagingDataSourcePrimvar);
142 
143 PXR_NAMESPACE_CLOSE_SCOPE
144 
145 #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...
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: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.
Data source representing USD primvars.
A data source representing a primvar.
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.