Loading...
Searching...
No Matches
dataSourcePrimvars.h
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
10#include "pxr/usdImaging/usdImaging/dataSourceAttribute.h"
11#include "pxr/usdImaging/usdImaging/dataSourceStageGlobals.h"
12
13#include "pxr/usd/usdGeom/primvar.h"
15
16PXR_NAMESPACE_OPEN_SCOPE
17
25{
26public:
27 HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrimvars);
28
30 HdDataSourceBaseHandle Get(const TfToken &name) override;
31
32private:
34 const SdfPath &sceneIndexPath,
35 UsdPrim const &usdPrim,
36 UsdGeomPrimvarsAPI usdPrimvars,
37 const UsdImagingDataSourceStageGlobals &stageGlobals);
38
39private:
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
54HD_DECLARE_DATASOURCE_HANDLES(UsdImagingDataSourcePrimvars);
55
56// ----------------------------------------------------------------------------
57
58class UsdImagingDataSourceCustomPrimvars : public HdContainerDataSource
59{
60public:
61 HD_DECLARE_DATASOURCE(UsdImagingDataSourceCustomPrimvars);
62
63 USDIMAGING_API
64 TfTokenVector GetNames() override;
65
66 USDIMAGING_API
67 HdDataSourceBaseHandle Get(const TfToken &name) override;
68
69 struct Mapping {
70 Mapping(
71 const TfToken &primvarName,
72 const TfToken &usdAttrName,
73 const TfToken &interpolation = TfToken())
74 : primvarName(primvarName)
75 , usdAttrName(usdAttrName)
76 , interpolation(interpolation)
77 { }
78
79 TfToken primvarName;
80 TfToken usdAttrName;
81 TfToken interpolation;
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
89 USDIMAGING_API
90 static HdDataSourceLocatorSet Invalidate(
91 const TfTokenVector &properties,
92 const Mappings &mappings);
93
94private:
95 UsdImagingDataSourceCustomPrimvars(
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
112HD_DECLARE_DATASOURCE_HANDLES(UsdImagingDataSourceCustomPrimvars);
113
114// ----------------------------------------------------------------------------
115
129{
130public:
131 HD_DECLARE_DATASOURCE(UsdImagingDataSourcePrimvar);
132
134 HdDataSourceBaseHandle Get(const TfToken & name) override;
135
136private:
138 const SdfPath &sceneIndexPath,
139 const TfToken &name,
140 const UsdImagingDataSourceStageGlobals &stageGlobals,
141 UsdAttributeQuery valueQuery,
142 UsdAttributeQuery indicesQuery,
143 HdTokenDataSourceHandle interpolation,
144 HdTokenDataSourceHandle role);
145
146private:
147 const UsdImagingDataSourceStageGlobals &_stageGlobals;
148 UsdAttributeQuery _valueQuery;
149 UsdAttributeQuery _indicesQuery;
150 HdTokenDataSourceHandle _interpolation;
151 HdTokenDataSourceHandle _role;
152};
153
154HD_DECLARE_DATASOURCE_HANDLES(UsdImagingDataSourcePrimvar);
155
156PXR_NAMESPACE_CLOSE_SCOPE
157
158#endif // PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_PRIMVARS_H
A datasource representing structured (named, hierarchical) data, for example a geometric primitive or...
Definition: dataSource.h:99
virtual TfTokenVector GetNames()=0
Returns the list of names for which Get(...) is expected to return a non-null value.
virtual HdDataSourceBaseHandle Get(const TfToken &name)=0
Returns the child datasource of the given name.
Represents a set of data source locators closed under descendancy.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Object for efficiently making repeated queries for attribute values.
UsdGeomPrimvarsAPI encodes geometric "primitive variables", as UsdGeomPrimvar, which interpolate acro...
Definition: primvarsAPI.h:66
A data source representing a primvar.
TfTokenVector GetNames() override
Returns the list of names for which Get(...) is expected to return a non-null value.
HdDataSourceBaseHandle Get(const TfToken &name) override
Returns the child datasource of the given name.
Data source representing USD primvars.
TfTokenVector GetNames() override
Returns the list of names for which Get(...) is expected to return a non-null value.
HdDataSourceBaseHandle Get(const TfToken &name) override
Returns the child datasource of the given name.
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:117
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440