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  const UsdImagingDataSourceStageGlobals &stageGlobals);
37 
38 private:
39  static TfToken _GetPrefixedName(const TfToken &name);
40 
41  // Path of the owning prim.
42  SdfPath _sceneIndexPath;
43 
44  UsdPrim _usdPrim;
45 
46  // Stage globals handle.
47  const UsdImagingDataSourceStageGlobals &_stageGlobals;
48 };
49 
51 
52 // ----------------------------------------------------------------------------
53 
55 {
56 public:
58 
60  TfTokenVector GetNames() override;
61 
63  HdDataSourceBaseHandle Get(const TfToken &name) override;
64 
65  struct Mapping {
67  const TfToken &primvarName,
68  const TfToken &usdAttrName,
69  const TfToken &interpolation = TfToken())
70  : primvarName(primvarName)
71  , usdAttrName(usdAttrName)
73  { }
74 
78  };
79 
80  // This map is passed to the constructor to specify non-"primvars:"
81  // attributes to include as primvars (e.g., "points" and "normals").
82  // The first token is the datasource name, and the second the USD name.
83  using Mappings = std::vector<Mapping>;
84 
87  const TfTokenVector &properties,
88  const Mappings &mappings);
89 
90 private:
93  const SdfPath &sceneIndexPath,
94  UsdPrim const &usdPrim,
95  const Mappings &mappings,
96  const UsdImagingDataSourceStageGlobals &stageGlobals);
97 
98  // Path of the owning prim.
99  SdfPath _sceneIndexPath;
100 
101  UsdPrim _usdPrim;
102 
103  // Stage globals handle.
104  const UsdImagingDataSourceStageGlobals &_stageGlobals;
105 
106  const Mappings _mappings;
107 };
108 
110 
111 // ----------------------------------------------------------------------------
112 
113 /// \class UsdImagingDataSourcePrimvar
114 ///
115 /// A data source representing a primvar. A primvar contains data,
116 /// interpolation, and role, but data can be a flat value or a value/index pair.
117 /// We also take location information for variability tracking.
118 ///
119 /// Note: the schema for this specifies that you can return "primvarValue"
120 /// for a flattened value, or "indexedPrimvarValue" and "indices" for
121 /// an un-flattened value. Since we don't want to duplicate the flattening
122 /// logic, we check whether indices are present and then return only one of
123 /// "primvarValue" or "indexedPrimvarValue" from the result of valueQuery.
124 ///
126 {
127 public:
129 
130  TfTokenVector GetNames() override;
131  HdDataSourceBaseHandle Get(const TfToken & name) override;
132 
133 private:
135  const SdfPath &sceneIndexPath,
136  const TfToken &name,
137  const UsdImagingDataSourceStageGlobals &stageGlobals,
138  UsdAttributeQuery valueQuery,
139  UsdAttributeQuery indicesQuery,
140  HdTokenDataSourceHandle interpolation,
142  HdTokenDataSourceHandle colorSpace = nullptr,
143  HdIntDataSourceHandle elementSize = nullptr);
144 
145 private:
146  const UsdImagingDataSourceStageGlobals &_stageGlobals;
147  UsdAttributeQuery _valueQuery;
148  UsdAttributeQuery _indicesQuery;
149  HdTokenDataSourceHandle _interpolation;
151  HdTokenDataSourceHandle _colorSpace;
152  HdIntDataSourceHandle _elementSize;
153 };
154 
156 
158 
159 #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
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
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:280
USDIMAGING_API HdDataSourceBaseHandle Get(const TfToken &name) override
Mapping(const TfToken &primvarName, const TfToken &usdAttrName, const TfToken &interpolation=TfToken())
TfTokenVector GetNames() override
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