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 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 
29 
32 
34 
35 ///
36 /// \class UsdImagingDataSourcePrimvars
37 ///
38 /// Data source representing USD primvars. This is a container for all
39 /// primvars.
40 ///
42 {
43 public:
45 
46  TfTokenVector GetNames() override;
47  HdDataSourceBaseHandle Get(const TfToken &name) override;
48 
49 private:
51  const SdfPath &sceneIndexPath,
52  UsdPrim const &usdPrim,
53  UsdGeomPrimvarsAPI usdPrimvars,
54  const UsdImagingDataSourceStageGlobals &stageGlobals);
55 
56 private:
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 
72 
73 // ----------------------------------------------------------------------------
74 
76 {
77 public:
79 
81  TfTokenVector GetNames() override;
82 
84  HdDataSourceBaseHandle Get(const TfToken &name) override;
85 
86  struct Mapping {
88  const TfToken &primvarName,
89  const TfToken &usdAttrName,
90  const TfToken &interpolation = TfToken())
91  : primvarName(primvarName)
92  , usdAttrName(usdAttrName)
94  { }
95 
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 
108  const TfTokenVector &properties,
109  const Mappings &mappings);
110 
111 private:
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 
134 
135 // ----------------------------------------------------------------------------
136 
137 /// \class UsdImagingDataSourcePrimvar
138 ///
139 /// A data source representing a primvar. A primvar contains data,
140 /// interpolation, and role, but data can be a flat value or a value/index pair.
141 /// We also take location information for variability tracking.
142 ///
143 /// Note: the schema for this specifies that you can return "primvarValue"
144 /// for a flattened value, or "indexedPrimvarValue" and "indices" for
145 /// an un-flattened value. Since we don't want to duplicate the flattening
146 /// logic, we check whether indices are present and then return only one of
147 /// "primvarValue" or "indexedPrimvarValue" from the result of valueQuery.
148 ///
150 {
151 public:
153 
154  TfTokenVector GetNames() override;
155  HdDataSourceBaseHandle Get(const TfToken & name) override;
156 
157 private:
159  const SdfPath &sceneIndexPath,
160  const TfToken &name,
161  const UsdImagingDataSourceStageGlobals &stageGlobals,
162  UsdAttributeQuery valueQuery,
163  UsdAttributeQuery indicesQuery,
164  HdTokenDataSourceHandle interpolation,
166 
167 private:
168  const UsdImagingDataSourceStageGlobals &_stageGlobals;
169  UsdAttributeQuery _valueQuery;
170  UsdAttributeQuery _indicesQuery;
171  HdTokenDataSourceHandle _interpolation;
173 };
174 
176 
178 
179 #endif // PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_PRIMVARS_H
HdDataSourceBaseHandle Get(const TfToken &name) override
#define USDIMAGING_API
Definition: api.h:40
HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrimvar)
HdDataSourceBaseHandle Get(const TfToken &name) override
HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrimvars)
HD_DECLARE_DATASOURCE(UsdImagingDataSourceCustomPrimvars)
TfTokenVector GetNames() override
Definition: token.h:87
Definition: prim.h:133
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:290
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:1432
USDIMAGING_API TfTokenVector GetNames() override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HD_DECLARE_DATASOURCE_HANDLES(UsdImagingDataSourcePrimvars)
static USDIMAGING_API HdDataSourceLocatorSet Invalidate(const TfTokenVector &properties, const Mappings &mappings)
HdTokenDataSource::Handle HdTokenDataSourceHandle