HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dataSourceResolvedPointsBasedPrim.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_USD_IMAGING_USD_SKEL_IMAGING_DATA_SOURCE_RESOLVED_POINTS_BASED_PRIM_H
9 #define PXR_USD_IMAGING_USD_SKEL_IMAGING_DATA_SOURCE_RESOLVED_POINTS_BASED_PRIM_H
10 
14 
17 
19 
21 
25 
26 /// \class UsdSkelImagingDataSourceResolvedPointsBasedPrim
27 ///
28 /// A prim data source providing resolved data for a points based prim (mesh,
29 /// basisCurves, points) deformed by a skeleton.
30 /// As a data source, it populates the HdExtComputationPrimvarsSchema for points
31 /// and removes points from the HdPrimvarsSchema.
32 ///
33 /// Used by the UsdSkelImagingPointsResolvingSceneIndex in conjunction with the
34 /// UsdSkelImagingDataSourceResolvedExtComputationPrim.
35 ///
37  : public HdContainerDataSource
38  , public std::enable_shared_from_this<
39  UsdSkelImagingDataSourceResolvedPointsBasedPrim>
40 {
41 public:
43 
44  /// C'tor.
45  ///
46  /// Note that it takes the data source for the prim at primPath in the
47  /// given sceneIndex. This is for performance: the client probably already
48  /// retrieved this data source so we want to avoid looking it up again here.
49  ///
50  /// Returns a nullptr if there the prim in the input scene does not bind a
51  /// skeleton.
53  static
54  Handle New(
55  HdSceneIndexBaseRefPtr const &sceneIndex,
56  SdfPath primPath,
57  HdContainerDataSourceHandle primSource);
58 
61 
63  TfTokenVector GetNames() override;
64 
66  HdDataSourceBaseHandle Get(const TfToken &name) override;
67 
68  /// Path of prim in input scene (and for prim this data source is for).
69  const SdfPath &GetPrimPath() const { return _primPath; }
70 
71  /// Path of bound skeleton.
72  const SdfPath &GetSkeletonPath() const { return _skeletonPath; }
73 
74  /// Paths to BlendShape prims.
76  return _blendShapeTargetPaths;
77  }
78 
79  /// Primvars of prim in the input scene.
80  const HdPrimvarsSchema &GetPrimvars() const { return _primvars; }
81 
82  /// Resolved skeleton of prim in the input scene.
84  return _resolvedSkeletonSchema;
85  }
86 
87  /// Typed sampled data source for the inverse of the xform matrix of the
88  /// prim in the input scene.
91 
92  /// Blend shape data computed from primvars, skel bindings and skeleton.
94  std::shared_ptr<UsdSkelImagingBlendShapeData> GetBlendShapeData();
95 
96  /// Joint influences data computed from primvars.
98  std::shared_ptr<UsdSkelImagingJointInfluencesData> GetJointInfluencesData();
99 
100  /// Skinning method computed from corresponding primvar.
101  const TfToken &GetSkinningMethod() const {
102  return _skinningMethod;
103  }
104 
105  /// Should the points for this primvar be given by an ext computation
106  /// or from the primvars schema.
107  bool HasExtComputations() const {
108  return
109  // Points are only posed if we bind a Skeleton prim (and the
110  // UsdSkelImagingSkeletonResolvingSceneIndex has populated the
111  // resolved skeleton schema).
112  _resolvedSkeletonSchema &&
113  // Do not use ext computation if this prim was the Skeleton itself.
114  // For the Skeleton prim itself, the
115  // UsdSkelImagingSkeletonResolvingSceneIndex has populated the
116  // points primvar already (with the points for the mesh guide)
117  // and changed the prim type to mesh.
118  _primPath != _skeletonPath &&
119  // We only skin prims if they are under a SkelRoot.
120  //
121  // Note that when we bake the points of a skinned prim, we also
122  // change the SkelRoot to a different prim type (such as Scope
123  // or Xform) so that the baked points are not skinned again.
124  _hasSkelRoot;
125  }
126 
127  /// Data source locators (on this prim) that this prim depends on.
128  ///
129  /// That is, if the input scene sends a dirty entry for this prim path
130  /// with dirty locators intersecting these data source locators, we need
131  /// to call ProcessDirtyLocators.
132  ///
133  /// (Similar to dependendedOnDataSourceLocator in HdDependencySchema).
134  ///
136  static const HdDataSourceLocatorSet &
138 
139  /// Dirty internal structures in response to dirty locators for the
140  /// target (resolved) skeleton prim (dirtiedPrimType = "skeleton"), a
141  /// targeted skelBlendShape prim (dirtiedPrimType = "skelBlendShape") or
142  /// the prim in the input scene itself (any other dirtiedPrimType).
143  /// Fills dirtied prim entries with affected locators for this prim
144  /// or returns true to indicate that we could not dirty this data
145  /// source and need to refetch it.
146  ///
149  const TfToken &dirtiedPrimType,
150  const HdDataSourceLocatorSet &dirtyLocators,
152 
153 private:
156  HdSceneIndexBaseRefPtr const &sceneIndex,
157  SdfPath primPath,
158  HdContainerDataSourceHandle primSource,
159  bool hasSkelRoot,
160  VtArray<SdfPath> blendShapeTargetPaths,
161  SdfPath skelPath,
162  HdContainerDataSourceHandle skeletonPrimSource,
163  UsdSkelImagingResolvedSkeletonSchema resolvedSkeletonSchema);
164 
165  bool
166  _ProcessDirtyLocators(
167  const HdDataSourceLocatorSet &dirtyLocators,
168  HdDataSourceLocatorSet * dirtyLocatorsForAggregatorComputation,
169  HdDataSourceLocatorSet * dirtyLocatorsForComputation);
170 
171  bool
172  _ProcessDirtySkeletonLocators(
173  const HdDataSourceLocatorSet &dirtyLocators,
174  HdDataSourceLocatorSet * dirtyLocatorsForAggregatorComputation,
175  HdDataSourceLocatorSet * dirtyLocatorsForComputation);
176 
177  bool
178  _ProcessDirtySkelBlendShapeLocators(
179  const HdDataSourceLocatorSet &dirtyLocators,
180  HdDataSourceLocatorSet * dirtyLocatorsForAggregatorComputation,
181  HdDataSourceLocatorSet * dirtyLocatorsForComputation);
182 
183  // Input scene.
184  HdSceneIndexBaseRefPtr const _sceneIndex;
185  // Path of prim in the input scene.
186  const SdfPath _primPath;
187  // Data source for _primPath from input scene _sceneIndex.
188  HdContainerDataSourceHandle const _primSource;
189  const bool _hasSkelRoot;
190  // From prim at _primPath in input scene _sceneIndex.
191  HdPrimvarsSchema const _primvars;
192  const TfToken _skinningMethod;
193  VtArray<SdfPath> _blendShapeTargetPaths;
194  const SdfPath _skeletonPath;
195  HdContainerDataSourceHandle const _skeletonPrimSource;
196  const UsdSkelImagingResolvedSkeletonSchema _resolvedSkeletonSchema;
197 
198  class _BlendShapeDataCache
199  : public UsdSkelImagingSharedPtrThunk<UsdSkelImagingBlendShapeData>
200  {
201  public:
202  _BlendShapeDataCache(
203  HdSceneIndexBaseRefPtr const &sceneIndex,
204  const SdfPath &primPath);
205  protected:
206  Handle _Compute() override;
207  private:
208  HdSceneIndexBaseRefPtr const _sceneIndex;
209  const SdfPath _primPath;
210  };
211  _BlendShapeDataCache _blendShapeDataCache;
212 
213  class _JointInfluencesDataCache
214  : public UsdSkelImagingSharedPtrThunk<UsdSkelImagingJointInfluencesData>
215  {
216  public:
217  _JointInfluencesDataCache(
218  HdContainerDataSourceHandle const &primSource,
219  HdContainerDataSourceHandle const &skeletonPrimSource);
220  protected:
221  Handle _Compute() override;
222  private:
223  HdContainerDataSourceHandle const _primSource;
224  HdContainerDataSourceHandle const _skeletonPrimSource;
225  };
226  _JointInfluencesDataCache _jointInfluencesDataCache;
227 };
228 
230 
232 
233 #endif
HD_DECLARE_DATASOURCE(UsdSkelImagingDataSourceResolvedPointsBasedPrim)
const VtArray< SdfPath > & GetBlendShapeTargetPaths() const
Paths to BlendShape prims.
USDSKELIMAGING_API TfTokenVector GetNames() override
const HdPrimvarsSchema & GetPrimvars() const
Primvars of prim in the input scene.
USDSKELIMAGING_API HdMatrixDataSourceHandle GetPrimWorldToLocal() const
USDSKELIMAGING_API ~UsdSkelImagingDataSourceResolvedPointsBasedPrim()
Definition: token.h:70
USDSKELIMAGING_API bool ProcessDirtyLocators(const TfToken &dirtiedPrimType, const HdDataSourceLocatorSet &dirtyLocators, HdSceneIndexObserver::DirtiedPrimEntries *entries)
static USDSKELIMAGING_API Handle New(HdSceneIndexBaseRefPtr const &sceneIndex, SdfPath primPath, HdContainerDataSourceHandle primSource)
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:273
HdMatrixDataSource::Handle HdMatrixDataSourceHandle
const UsdSkelImagingResolvedSkeletonSchema & GetResolvedSkeletonSchema()
Resolved skeleton of prim in the input scene.
static USDSKELIMAGING_API const HdDataSourceLocatorSet & GetDependendendOnDataSourceLocators()
const TfToken & GetSkinningMethod() const
Skinning method computed from corresponding primvar.
#define USDSKELIMAGING_API
Definition: api.h:23
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USDSKELIMAGING_API std::shared_ptr< UsdSkelImagingJointInfluencesData > GetJointInfluencesData()
Joint influences data computed from primvars.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USDSKELIMAGING_API std::shared_ptr< UsdSkelImagingBlendShapeData > GetBlendShapeData()
Blend shape data computed from primvars, skel bindings and skeleton.
const SdfPath & GetPrimPath() const
Path of prim in input scene (and for prim this data source is for).
const SdfPath & GetSkeletonPath() const
Path of bound skeleton.
USDSKELIMAGING_API HdDataSourceBaseHandle Get(const TfToken &name) override
HD_DECLARE_DATASOURCE_HANDLES(UsdSkelImagingDataSourceResolvedPointsBasedPrim)
TF_DECLARE_REF_PTRS(HdSceneIndexBase)
void * Handle
Definition: plugin.h:27