HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dataSourcePrim.h
Go to the documentation of this file.
1 //
2 // Copyright 2020 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_PRIM_H
25 #define PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_PRIM_H
26 
29 
30 #include "pxr/usd/usd/prim.h"
31 
35 
40 
42 
43 /// \class UsdImagingDataSourceVisibility
44 ///
45 /// Data source representing prim visibility for a USD imageable.
47 {
48 public:
50 
51  /// Returns the names contained in this data source.
52  ///
53  /// This class only returns 'visibility'.
54  TfTokenVector GetNames() override;
55 
56  /// Returns the data source for the given \p 'name'.
57  ///
58  /// Only 'visibility' returns anything for this class.
59  HdDataSourceBaseHandle Get(const TfToken &name) override;
60 
61 private:
62  /// Use to construct a new UsdImagingDataSourceVisibility.
63  ///
64  /// \p visibilityQuery is the USD attribute query holding visibility data.
65  /// \p sceneIndexPath is the path of this object in the scene index.
66  /// \p stageGlobals is the context object for the USD stage.
67  ///
68  /// Note: client code calls this via static New().
70  const UsdAttributeQuery &visibilityQuery,
71  const SdfPath &sceneIndexPath,
72  const UsdImagingDataSourceStageGlobals &stageGlobals);
73 
74 private:
75  UsdAttributeQuery _visibilityQuery;
76  const UsdImagingDataSourceStageGlobals &_stageGlobals;
77 };
78 
80 
81 
82 // ----------------------------------------------------------------------------
83 
84 /// \class UsdImagingDataSourcePurpose
85 ///
86 /// Data source representing prim purpose for a USD imageable.
88 {
89 public:
91 
92  /// Returns the names contained in this data source.
93  ///
94  /// This class only returns 'purpose'.
95  TfTokenVector GetNames() override;
96 
97  /// Returns the data source for the given \p 'name'.
98  ///
99  /// Only 'purpose' returns anything for this class.
100  HdDataSourceBaseHandle Get(const TfToken &name) override;
101 
102 private:
103  /// Use to construct a new UsdImagingDataSourcePurpose.
104  ///
105  /// \p purposeQuery is the USD attribute query holding purpose data.
106  /// \p stageGlobals is the context object for the USD stage.
107  ///
108  /// Note: client code calls this via static New().
110  const UsdAttributeQuery &purposeQuery,
111  const UsdImagingDataSourceStageGlobals &stageGlobals);
112 
113 private:
114  UsdAttributeQuery _purposeQuery;
115  const UsdImagingDataSourceStageGlobals &_stageGlobals;
116 };
117 
119 
120 
121 // ----------------------------------------------------------------------------
122 
123 /// \class UsdImagingDataSourceExtentCoordinate
124 ///
125 /// Data source representing either the minimum or maximum of the local prim
126 /// extent.
128 {
129 public:
131 
132  /// Returns VtValue at a given \p shutterOffset for the value of this flag.
133  VtValue GetValue(HdSampledDataSource::Time shutterOffset) override;
134 
135  /// Returns bool at a given \p shutterOffset for the value of this flag.
136  GfVec3d GetTypedValue(HdSampledDataSource::Time shutterOffset) override;
137 
138  /// Fills the \p outSampleTimes with the times between \p startTime and
139  /// \p endTime that have valid sample data and returns \c true.
141  HdSampledDataSource::Time startTime,
143  std::vector<HdSampledDataSource::Time> *outSampleTimes) override;
144 
145 private:
146  /// Use to construct a new UsdImagingDataSourceExtentCoordinate.
147  ///
148  /// \p extentDs is the float3 array holding all extent coordinates.
149  /// \p attrPath is the USD path of the underlying extents attribute.
150  /// \p index is the index of the value we want out of extentDs.
151  ///
152  /// Note: client code calls this via static New().
154  const HdVec3fArrayDataSourceHandle &extentDs,
155  const SdfPath &attrPath,
156  unsigned int index);
157 
158 private:
160  SdfPath _attrPath;
161  unsigned int _index;
162 };
163 
164 // ----------------------------------------------------------------------------
165 
166 /// \class UsdImagingDataSourceExtent
167 ///
168 /// Data source representing local prim extent.
170 {
171 public:
173 
174  /// Returns the names contained in this datasource.
175  ///
176  /// This class only returns 'min' and 'max'.
177  TfTokenVector GetNames() override;
178 
179  /// Returns the data source for the given \p 'name'.
180  ///
181  /// Only 'min' and 'max' return anything for this class.
182  HdDataSourceBaseHandle Get(const TfToken &name) override;
183 
184 private:
185  /// Use to construct a new UsdImagingDataSourceExtent.
186  ///
187  /// \p extentQuery is the USD attribute query holding extent data.
188  /// \p sceneIndexPath is the path of this object in the scene index.
189  /// \p stageGlobals is the context object for the USD stage.
190  ///
191  /// Note: client code calls this via static New().
193  const UsdAttributeQuery &extentQuery,
194  const SdfPath &sceneIndexPath,
195  const UsdImagingDataSourceStageGlobals &stageGlobals);
196 
197 private:
198  // Note: the constructor takes sceneIndexPath for change-tracking,
199  // but here we're storing the USD attribute path for error reporting!
200  SdfPath _attrPath;
202 };
203 
205 
206 // ----------------------------------------------------------------------------
207 
208 /// \class UsdImagingDataSourceExtentsHint
209 ///
210 /// Data source representing extents hint of a model API prim.
212 {
213 public:
215 
216  /// Returns number of vec3 pairs authored on extentsHint.
217  ///
218  size_t GetNumElements() override;
219 
220  /// Returns i-th pair of vec3 authored on extentsHint as
221  /// extent schema.
222  HdDataSourceBaseHandle GetElement(size_t element) override;
223 
224 private:
225  /// Use to construct a new UsdImagingDataSourceExtentsHint.
226  ///
227  /// \p extentQuery is the USD attribute query holding extent data.
228  /// \p sceneIndexPath is the path of this object in the scene index.
229  /// \p stageGlobals is the context object for the USD stage.
230  ///
231  /// Note: client code calls this via static New().
233  const UsdAttributeQuery &extentQuery,
234  const SdfPath &sceneIndexPath,
235  const UsdImagingDataSourceStageGlobals &stageGlobals);
236 
237 private:
238  // Note: the constructor takes sceneIndexPath for change-tracking,
239  // but here we're storing the USD attribute path for error reporting!
240  SdfPath _attrPath;
242 };
243 
245 
246 
247 // ----------------------------------------------------------------------------
248 
249 /// \class UsdImagingDataSourceXformResetXformStack
250 ///
251 /// Data source representing the "reset xform stack" flag for a USD
252 /// xformable.
254 {
255 public:
257 
258  /// Returns VtValue at a given \p shutterOffset for the value of this flag.
259  VtValue GetValue(HdSampledDataSource::Time shutterOffset) override;
260 
261  /// Returns bool at a given \p shutterOffset for the value of this flag.
262  bool GetTypedValue(HdSampledDataSource::Time shutterOffset) override;
263 
264  /// Fills the \p outSampleTimes with the times between \p startTime and
265  /// \p endTime that have valid sample data and returns \c true.
267  HdSampledDataSource::Time startTime,
269  std::vector<HdSampledDataSource::Time> *outSampleTimes) override {
270  return false;
271  }
272 
273 private:
274  /// Use to construct a new UsdImagingDataSourceXformResetXformStack.
275  ///
276  /// \p xformQuery is the USD XformQuery object that this class
277  /// can extract a matrix from.
278  ///
279  /// \p stageGlobals represents the context object for the UsdStage with
280  /// which to evaluate this attribute data source.
281  ///
282  /// Note: client code calls this via static New().
284  const UsdGeomXformable::XformQuery &xformQuery,
285  const UsdImagingDataSourceStageGlobals &stageGlobals);
286 
287 private:
288  UsdGeomXformable::XformQuery _xformQuery;
289  const UsdImagingDataSourceStageGlobals &_stageGlobals;
290 };
291 
293 
294 // ----------------------------------------------------------------------------
295 
296 ///
297 /// \class UsdImagingDataSourceXformMatrix
298 ///
299 /// Data source representing a generic transform value accessor for a
300 /// USD Xformable.
301 ///
303 {
304 public:
305 
307 
308  /// Returns VtValue at a given \p shutterOffset for the value of this
309  /// xform.
310  ///
311  VtValue GetValue(HdSampledDataSource::Time shutterOffset) override;
312 
313  /// Returns GfMatrix4d at a given \p shutterOffset for the value of this
314  /// xform.
315  ///
316  GfMatrix4d GetTypedValue(HdSampledDataSource::Time shutterOffset) override;
317 
318  /// Fills the \p outSampleTimes with the times between \p startTime and
319  /// \p endTime that have valid sample data and returns \c true.
320  ///
322  HdSampledDataSource::Time startTime,
324  std::vector<HdSampledDataSource::Time> *outSampleTimes) override;
325 
326 private:
327  /// Use to construct a new UsdImagingDataSourceXformMatrix.
328  ///
329  /// \p xformQuery is the USD XformQuery object that this class
330  /// can extract a matrix from.
331  ///
332  /// \p stageGlobals represents the context object for the UsdStage with
333  /// which to evaluate this attribute data source.
334  ///
335  /// Note: client code calls this via static New().
337  const UsdGeomXformable::XformQuery &xformQuery,
338  const UsdImagingDataSourceStageGlobals &stageGlobals);
339 
340 private:
341  UsdGeomXformable::XformQuery _xformQuery;
342  const UsdImagingDataSourceStageGlobals &_stageGlobals;
343 };
344 
346 
347 // ----------------------------------------------------------------------------
348 
349 ///
350 /// \class UsdImagingDataSourceXform
351 ///
352 /// Data source representing a container that stores a USD Xformable.
353 ///
354 /// Note that this container only represents a flattened matrix right now,
355 /// but could be expanded in the future to include more granular XformOps,
356 /// which is why it exists as a separate entity.
357 ///
359 {
360 public:
362 
363  /// Returns the names contained in this data source.
364  ///
365  /// This class only returns 'matrix' and 'resetXformStack'.
366  ///
367  TfTokenVector GetNames() override;
368 
369  /// Returns the data source for the given \p 'name'.
370  ///
371  /// Only 'matrix' and 'resetXformStack' return anything in this class.
372  ///
373  HdDataSourceBaseHandle Get(const TfToken &name) override;
374 
375 private:
376  /// Use to construct a new UsdImagingDataSourceXform.
377  ///
378  /// \p xformQuery is the USD XformQuery object that this class
379  /// can extract a matrix from.
380  /// \p sceneIndexPath is the path of this object in the scene index.
381  /// \p stageGlobals represents the context object for the UsdStage with
382  /// which to evaluate this attribute data source.
383  ///
384  /// Note: client code calls this via static New().
386  const UsdGeomXformable::XformQuery &xformQuery,
387  const SdfPath &sceneIndexPath,
388  const UsdImagingDataSourceStageGlobals &stageGlobals);
389 
390 private:
391  UsdGeomXformable::XformQuery _xformQuery;
392  const UsdImagingDataSourceStageGlobals &_stageGlobals;
393 };
394 
396 
397 // ----------------------------------------------------------------------------
398 
399 ///
400 /// \class UsdImagingDataSourceModel
401 ///
402 /// Data source representing model API for a USD prim.
403 ///
405 {
406 public:
408 
409  /// Return attribute names of UsdImagingModelSchema.
410  ///
411  TfTokenVector GetNames() override;
412 
413  /// Returns data authored on USD prim (without resolving inherited) for
414  /// attribute names of UsdImagingModelSchema.
415  ///
416  HdDataSourceBaseHandle Get(const TfToken &name) override;
417 
418 private:
419  /// C'tor.
420  ///
421  /// \p model is API schema from which this class can extract values from.
422  /// \p sceneIndexPath is the path of this object in the scene index.
423  /// \p stageGlobals represents the context object for the UsdStage with
424  /// which to evaluate this attribute data source.
425  ///
426  /// Note: client code calls this via static New().
428  const UsdGeomModelAPI &model,
429  const SdfPath &sceneIndexPath,
430  const UsdImagingDataSourceStageGlobals &stageGlobals);
431 
432 private:
433  UsdGeomModelAPI _model;
434  const SdfPath _sceneIndexPath;
435  const UsdImagingDataSourceStageGlobals &_stageGlobals;
436 };
437 
439 
440 // ----------------------------------------------------------------------------
441 
442 ///
443 /// \class UsdImagingDataSourcePrimOrigin
444 ///
445 /// Data source to access the underlying UsdPrim.
446 ///
448 {
449 public:
451 
452  TfTokenVector GetNames() override;
453 
454  /// Get(UsdImagingTokens->usdPrim) returns a data source containing
455  /// the underyling UsdPrim.
456  HdDataSourceBaseHandle Get(const TfToken &name) override;
457 
458 private:
459  UsdImagingDataSourcePrimOrigin(const UsdPrim &usdPrim);
460 
461 private:
462  UsdPrim _usdPrim;
463 };
464 
466 
467 // ----------------------------------------------------------------------------
468 
469 ///
470 /// \class UsdImagingDataSourcePrim
471 ///
472 /// Data source representing a basic USD prim. This class is meant to check for
473 /// behaviors we might expect on all nodes of the scene, including interior
474 /// nodes; e.g. xform, visibility. It's expected that concrete imaging types
475 /// would derive from this and add imaging prim-related attributes.
476 ///
477 /// Note: while every prim gets at least this datasource defined on it, this
478 /// datasource tries to aggressively early out of attribute checks based on
479 /// type information (IsA/HasA) or namespace-accelerated attribute checks.
480 ///
481 /// Since a Usd prim can populate multiple imaging prims (e.g. /prim, /prim.a,
482 /// /prim.b); and since the default prim path (/prim) is always populated; we
483 /// drop inherited attributes on subprims (/prim.a), letting them inherit from
484 /// /prim instead. This way we don't (e.g.) double-apply transforms.
485 ///
487 {
488 public:
490 
491  /// Returns the names for which this data source can return meaningful
492  /// results.
493  ///
495  TfTokenVector GetNames() override;
496 
497  /// Returns the data source representing \p name, if valid.
498  ///
500  HdDataSourceBaseHandle Get(const TfToken &name) override;
501 
502  /// Returns the hydra attribute set we should invalidate if the value of
503  /// the USD properties in \p properties change.
506  UsdPrim const& prim,
507  const TfToken &subprim,
508  const TfTokenVector &properties,
509  UsdImagingPropertyInvalidationType invalidationType);
510 
511 protected:
512  /// Use to construct a new UsdImagingDataSourcePrim.
513  ///
514  /// \p sceneIndexPath is the path of this object in the scene index.
515  /// (Note: this can be different than the usd path if one usd prim
516  /// inserts multiple imaging prims).
517  ///
518  /// \p usdPrim is the USD prim object that this data source represents.
519  ///
520  /// \p stageGlobals represents the context object for the UsdStage with
521  /// which to evaluate this attribute data source.
522  ///
523  /// Note: client code calls this via static New().
526  const SdfPath &sceneIndexPath,
527  UsdPrim usdPrim,
528  const UsdImagingDataSourceStageGlobals &stageGlobals);
529 
530  // Accessors, for derived classes...
531  const SdfPath &_GetSceneIndexPath() const {
532  return _sceneIndexPath;
533  }
534 
535  const UsdPrim &_GetUsdPrim() const {
536  return _usdPrim;
537  }
538 
540  return _stageGlobals;
541  }
542 
543 private:
544  const SdfPath _sceneIndexPath;
545  UsdPrim _usdPrim;
546  const UsdImagingDataSourceStageGlobals &_stageGlobals;
547 };
548 
550 
552 
553 #endif // PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_PRIM_H
HD_DECLARE_DATASOURCE(UsdImagingDataSourceExtentsHint)
const UsdImagingDataSourceStageGlobals & _GetStageGlobals() const
VtValue GetValue(HdSampledDataSource::Time shutterOffset) override
Returns VtValue at a given shutterOffset for the value of this flag.
USDIMAGING_API TfTokenVector GetNames() override
TfTokenVector GetNames() override
HdDataSourceBaseHandle Get(const TfToken &name) override
bool GetContributingSampleTimesForInterval(HdSampledDataSource::Time startTime, HdSampledDataSource::Time endTime, std::vector< HdSampledDataSource::Time > *outSampleTimes) override
#define USDIMAGING_API
Definition: api.h:40
HD_DECLARE_DATASOURCE(UsdImagingDataSourceVisibility)
TfTokenVector GetNames() override
VtValue GetValue(HdSampledDataSource::Time shutterOffset) override
HD_DECLARE_DATASOURCE(UsdImagingDataSourceXformMatrix)
TfTokenVector GetNames() override
HD_DECLARE_DATASOURCE_HANDLES(UsdImagingDataSourceVisibility)
const SdfPath & _GetSceneIndexPath() const
TfTokenVector GetNames() override
static USDIMAGING_API HdDataSourceLocatorSet Invalidate(UsdPrim const &prim, const TfToken &subprim, const TfTokenVector &properties, UsdImagingPropertyInvalidationType invalidationType)
HdDataSourceBaseHandle Get(const TfToken &name) override
GfVec3d GetTypedValue(HdSampledDataSource::Time shutterOffset) override
Returns bool at a given shutterOffset for the value of this flag.
HD_DECLARE_DATASOURCE(UsdImagingDataSourceModel)
HD_DECLARE_DATASOURCE(UsdImagingDataSourceExtent)
HD_DECLARE_DATASOURCE(UsdImagingDataSourceExtentCoordinate)
Definition: token.h:87
USDIMAGING_API UsdImagingDataSourcePrim(const SdfPath &sceneIndexPath, UsdPrim usdPrim, const UsdImagingDataSourceStageGlobals &stageGlobals)
HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrim)
HdDataSourceBaseHandle Get(const TfToken &name) override
Definition: prim.h:135
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
USDIMAGING_API HdDataSourceBaseHandle Get(const TfToken &name) override
GLuint const GLchar * name
Definition: glcorearb.h:786
bool GetContributingSampleTimesForInterval(HdSampledDataSource::Time startTime, HdSampledDataSource::Time endTime, std::vector< HdSampledDataSource::Time > *outSampleTimes) override
Definition: path.h:291
HdVec3fArrayDataSource::Handle HdVec3fArrayDataSourceHandle
VtValue GetValue(HdSampledDataSource::Time shutterOffset) override
Returns VtValue at a given shutterOffset for the value of this flag.
HD_DECLARE_DATASOURCE(UsdImagingDataSourcePurpose)
const UsdPrim & _GetUsdPrim() const
HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrimOrigin)
TfTokenVector GetNames() override
HdDataSourceBaseHandle Get(const TfToken &name) override
bool GetTypedValue(HdSampledDataSource::Time shutterOffset) override
Returns bool at a given shutterOffset for the value of this flag.
HD_DECLARE_DATASOURCE(UsdImagingDataSourceXformResetXformStack)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
HdDataSourceBaseHandle GetElement(size_t element) override
bool GetContributingSampleTimesForInterval(HdSampledDataSource::Time startTime, HdSampledDataSource::Time endTime, std::vector< HdSampledDataSource::Time > *outSampleTimes) override
GLuint index
Definition: glcorearb.h:786
Definition: vec3d.h:62
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HdDataSourceBaseHandle Get(const TfToken &name) override
TfTokenVector GetNames() override
GfMatrix4d GetTypedValue(HdSampledDataSource::Time shutterOffset) override
HD_DECLARE_DATASOURCE(UsdImagingDataSourceXform)
HdDataSourceBaseHandle Get(const TfToken &name) override
size_t GetNumElements() override
Definition: value.h:167
UsdImagingPropertyInvalidationType
Definition: types.h:34