HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dataSourcePrimvars.h
Go to the documentation of this file.
1 //
2 // Copyright 2022 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_PRIMVARS_H
8 #define PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_PRIMVARS_H
9 
12 
15 
17 
18 ///
19 /// \class UsdImagingDataSourcePrimvars
20 ///
21 /// Data source representing USD primvars. This is a container for all
22 /// primvars.
23 ///
25 {
26 public:
28 
29  TfTokenVector GetNames() override;
30  HdDataSourceBaseHandle Get(const TfToken &name) override;
31 
32 private:
34  const SdfPath &sceneIndexPath,
35  UsdPrim const &usdPrim,
36  UsdGeomPrimvarsAPI usdPrimvars,
37  const UsdImagingDataSourceStageGlobals &stageGlobals);
38 
39 private:
40  static TfToken _GetPrefixedName(const TfToken &name);
41 
42  // Path of the owning prim.
43  SdfPath _sceneIndexPath;
44 
45  UsdPrim _usdPrim;
46 
47  // Stage globals handle.
48  const UsdImagingDataSourceStageGlobals &_stageGlobals;
49 
50  using _NamespacedPrimvarsMap = std::map<TfToken, UsdGeomPrimvar>;
51  _NamespacedPrimvarsMap _namespacedPrimvars;
52 };
53 
55 
56 // ----------------------------------------------------------------------------
57 
59 {
60 public:
62 
64  TfTokenVector GetNames() override;
65 
67  HdDataSourceBaseHandle Get(const TfToken &name) override;
68 
69  struct Mapping {
71  const TfToken &primvarName,
72  const TfToken &usdAttrName,
73  const TfToken &interpolation = TfToken())
74  : primvarName(primvarName)
75  , usdAttrName(usdAttrName)
77  { }
78 
82  };
83 
84  // This map is passed to the constructor to specify non-"primvars:"
85  // attributes to include as primvars (e.g., "points" and "normals").
86  // The first token is the datasource name, and the second the USD name.
87  using Mappings = std::vector<Mapping>;
88 
91  const TfTokenVector &properties,
92  const Mappings &mappings);
93 
94 private:
96  const SdfPath &sceneIndexPath,
97  UsdPrim const &usdPrim,
98  const Mappings &mappings,
99  const UsdImagingDataSourceStageGlobals &stageGlobals);
100 
101  // Path of the owning prim.
102  SdfPath _sceneIndexPath;
103 
104  UsdPrim _usdPrim;
105 
106  // Stage globals handle.
107  const UsdImagingDataSourceStageGlobals &_stageGlobals;
108 
109  const Mappings _mappings;
110 };
111 
113 
114 // ----------------------------------------------------------------------------
115 
116 /// \class UsdImagingDataSourcePrimvar
117 ///
118 /// A data source representing a primvar. A primvar contains data,
119 /// interpolation, and role, but data can be a flat value or a value/index pair.
120 /// We also take location information for variability tracking.
121 ///
122 /// Note: the schema for this specifies that you can return "primvarValue"
123 /// for a flattened value, or "indexedPrimvarValue" and "indices" for
124 /// an un-flattened value. Since we don't want to duplicate the flattening
125 /// logic, we check whether indices are present and then return only one of
126 /// "primvarValue" or "indexedPrimvarValue" from the result of valueQuery.
127 ///
129 {
130 public:
132 
133  TfTokenVector GetNames() override;
134  HdDataSourceBaseHandle Get(const TfToken & name) override;
135 
136 private:
138  const SdfPath &sceneIndexPath,
139  const TfToken &name,
140  const UsdImagingDataSourceStageGlobals &stageGlobals,
141  UsdAttributeQuery valueQuery,
142  UsdAttributeQuery indicesQuery,
143  HdTokenDataSourceHandle interpolation,
145  HdIntDataSourceHandle elementSize = nullptr);
146 
147 private:
148  const UsdImagingDataSourceStageGlobals &_stageGlobals;
149  UsdAttributeQuery _valueQuery;
150  UsdAttributeQuery _indicesQuery;
151  HdTokenDataSourceHandle _interpolation;
153  HdIntDataSourceHandle _elementSize;
154 };
155 
157 
159 
160 #endif // PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_PRIMVARS_H
HdDataSourceBaseHandle Get(const TfToken &name) override
#define USDIMAGING_API
Definition: api.h:23
HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrimvar)
HdDataSourceBaseHandle Get(const TfToken &name) override
HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrimvars)
HD_DECLARE_DATASOURCE(UsdImagingDataSourceCustomPrimvars)
TfTokenVector GetNames() override
Definition: token.h:70
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:273
USDIMAGING_API HdDataSourceBaseHandle Get(const TfToken &name) override
Mapping(const TfToken &primvarName, const TfToken &usdAttrName, const TfToken &interpolation=TfToken())
TfTokenVector GetNames() override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USDIMAGING_API TfTokenVector GetNames() override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HdIntDataSource::Handle HdIntDataSourceHandle
HD_DECLARE_DATASOURCE_HANDLES(UsdImagingDataSourcePrimvars)
static USDIMAGING_API HdDataSourceLocatorSet Invalidate(const TfTokenVector &properties, const Mappings &mappings)
HdTokenDataSource::Handle HdTokenDataSourceHandle