Loading...
Searching...
No Matches
skeletonAdapter.h
1//
2// Copyright 2018 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_SKEL_IMAGING_SKELETON_ADAPTER_H
8#define PXR_USD_IMAGING_USD_SKEL_IMAGING_SKELETON_ADAPTER_H
9
10#include "pxr/pxr.h"
11#include "pxr/usdImaging/usdImaging/instanceablePrimAdapter.h"
12#include "pxr/usdImaging/usdSkelImaging/api.h"
13
14#include "pxr/imaging/hd/meshTopology.h"
15
21
22#include <unordered_map>
23
24
25PXR_NAMESPACE_OPEN_SCOPE
26
27
32class UsdSkelImagingSkeletonAdapter : public UsdImagingInstanceablePrimAdapter
33{
34public:
35 using BaseAdapter = UsdImagingInstanceablePrimAdapter;
36
37 UsdSkelImagingSkeletonAdapter()
38 : BaseAdapter()
39 {}
40
41 USDSKELIMAGING_API
42 virtual ~UsdSkelImagingSkeletonAdapter();
43
44 USDSKELIMAGING_API
46 Populate(const UsdPrim& prim,
49 instancerContext=nullptr) override;
50
51 USDSKELIMAGING_API
52 bool IsSupported(const UsdImagingIndexProxy* index) const override;
53
54 // ---------------------------------------------------------------------- //
56 // ---------------------------------------------------------------------- //
57
59 USDSKELIMAGING_API
60 void TrackVariability(const UsdPrim& prim,
61 const SdfPath& cachePath,
62 HdDirtyBits* timeVaryingBits,
64 instancerContext = nullptr) const override;
65
67 USDSKELIMAGING_API
68 void UpdateForTime(const UsdPrim& prim,
69 const SdfPath& cachePath,
70 UsdTimeCode time,
71 HdDirtyBits requestedBits,
73 instancerContext=nullptr) const override;
74
75 // ---------------------------------------------------------------------- //
77 // ---------------------------------------------------------------------- //
78
79 USDSKELIMAGING_API
80 HdDirtyBits ProcessPropertyChange(const UsdPrim& prim,
81 const SdfPath& cachePath,
82 const TfToken& propertyName) override;
83
84 USDSKELIMAGING_API
85 void ProcessPrimResync(SdfPath const& primPath,
86 UsdImagingIndexProxy* index) override;
87
88 USDSKELIMAGING_API
89 void ProcessPrimRemoval(SdfPath const& primPath,
90 UsdImagingIndexProxy* index) override;
91
92 USDSKELIMAGING_API
93 void MarkDirty(const UsdPrim& prim,
94 const SdfPath& cachePath,
95 HdDirtyBits dirty,
96 UsdImagingIndexProxy* index) override;
97
98 USDSKELIMAGING_API
99 void MarkRefineLevelDirty(UsdPrim const& prim,
100 SdfPath const& cachePath,
101 UsdImagingIndexProxy* index) override;
102
103 USDSKELIMAGING_API
104 void MarkReprDirty(UsdPrim const& prim,
105 SdfPath const& cachePath,
106 UsdImagingIndexProxy* index) override;
107
108 USDSKELIMAGING_API
109 void MarkCullStyleDirty(UsdPrim const& prim,
110 SdfPath const& cachePath,
111 UsdImagingIndexProxy* index) override;
112
113 USDSKELIMAGING_API
114 void MarkRenderTagDirty(UsdPrim const& prim,
115 SdfPath const& cachePath,
116 UsdImagingIndexProxy* index) override;
117
118 USDSKELIMAGING_API
119 void MarkTransformDirty(const UsdPrim& prim,
120 const SdfPath& cachePath,
121 UsdImagingIndexProxy* index) override;
122
123 USDSKELIMAGING_API
124 void MarkVisibilityDirty(const UsdPrim& prim,
125 const SdfPath& cachePath,
126 UsdImagingIndexProxy* index) override;
127
128 USDSKELIMAGING_API
129 void MarkMaterialDirty(const UsdPrim& prim,
130 const SdfPath& cachePath,
131 UsdImagingIndexProxy* index) override;
132
133 // ---------------------------------------------------------------------- //
135 // ---------------------------------------------------------------------- //
136 USDSKELIMAGING_API
137 void InvokeComputation(SdfPath const& cachePath,
138 HdExtComputationContext* context) override;
139
140 // ---------------------------------------------------------------------- //
142 // ---------------------------------------------------------------------- //
143
144 USDSKELIMAGING_API
145 void RegisterSkelBinding(UsdSkelBinding const& binding);
146
147 // ---------------------------------------------------------------------- //
149 // ---------------------------------------------------------------------- //
150
151 USDSKELIMAGING_API
153 SdfPath const& cachePath,
154 UsdTimeCode time) const override;
155
156 USDSKELIMAGING_API
157 VtValue GetTopology(UsdPrim const& prim,
158 SdfPath const& cachePath,
159 UsdTimeCode time) const override;
160
161 USDSKELIMAGING_API
162 GfRange3d GetExtent(UsdPrim const& prim,
163 SdfPath const& cachePath,
164 UsdTimeCode time) const override;
165
166 USDSKELIMAGING_API
167 TfToken GetPurpose(UsdPrim const& prim,
168 SdfPath const& cachePath,
169 TfToken const& instanceInheritablePurpose)
170 const override;
171
172 USDSKELIMAGING_API
173 bool GetDoubleSided(UsdPrim const& prim,
174 SdfPath const& cachePath,
175 UsdTimeCode time) const override;
176
177
178 USDSKELIMAGING_API
179 SdfPath GetMaterialId(UsdPrim const& prim,
180 SdfPath const& cachePath,
181 UsdTimeCode time) const override;
182
183
184 USDSKELIMAGING_API
185 const TfTokenVector &GetExtComputationSceneInputNames(
186 SdfPath const& cachePath) const override;
187
188 USDSKELIMAGING_API
189 HdExtComputationInputDescriptorVector
190 GetExtComputationInputs(UsdPrim const& prim,
191 SdfPath const& cachePath,
192 const UsdImagingInstancerContext *instancerContext)
193 const override;
194
195 USDSKELIMAGING_API
196 HdExtComputationOutputDescriptorVector
197 GetExtComputationOutputs(UsdPrim const& prim,
198 SdfPath const& cachePath,
199 const UsdImagingInstancerContext* instancerContext)
200 const override;
201
202 USDSKELIMAGING_API
203 HdExtComputationPrimvarDescriptorVector
204 GetExtComputationPrimvars(
205 UsdPrim const& prim,
206 SdfPath const& cachePath,
207 HdInterpolation interpolation,
208 const UsdImagingInstancerContext* instancerContext) const override;
209
210 USDSKELIMAGING_API
211 VtValue
212 GetExtComputationInput(
213 UsdPrim const& prim,
214 SdfPath const& cachePath,
215 TfToken const& name,
216 UsdTimeCode time,
217 const UsdImagingInstancerContext* instancerContext) const override;
218
219 USDSKELIMAGING_API
220 size_t
221 SampleExtComputationInput(
222 UsdPrim const& prim,
223 SdfPath const& cachePath,
224 TfToken const& name,
225 UsdTimeCode time,
226 const UsdImagingInstancerContext* instancerContext,
227 size_t maxSampleCount,
228 float *sampleTimes,
229 VtValue *sampleValues) override;
230
231 USDSKELIMAGING_API
232 std::string
233 GetExtComputationKernel(
234 UsdPrim const& prim,
235 SdfPath const& cachePath,
236 const UsdImagingInstancerContext* instancerContext) const override;
237
238
239 USDSKELIMAGING_API
240 VtValue Get(UsdPrim const& prim,
241 SdfPath const& cachePath,
242 TfToken const& key,
243 UsdTimeCode time,
244 VtIntArray *outIndices) const override;
245
246protected:
247 // ---------------------------------------------------------------------- //
249 // ---------------------------------------------------------------------- //
250 void _RemovePrim(const SdfPath& cachePath,
251 UsdImagingIndexProxy* index) override;
252
253private:
254 // ---------------------------------------------------------------------- //
256 // ---------------------------------------------------------------------- //
257 bool _IsCallbackForSkeleton(const UsdPrim& prim) const;
258
261 GfVec3f _GetSkeletonDisplayColor(const UsdPrim& prim,
262 UsdTimeCode time) const;
263
266 float _GetSkeletonDisplayOpacity(const UsdPrim& prim,
267 UsdTimeCode time) const;
268
269 void _TrackBoneMeshVariability(
270 const UsdPrim& prim,
271 const SdfPath& cachePath,
272 HdDirtyBits* timeVaryingBits,
274 instancerContext = nullptr) const;
275
276 void _UpdateBoneMeshForTime(
277 const UsdPrim& prim,
278 const SdfPath& cachePath,
279 UsdTimeCode time,
280 HdDirtyBits requestedBits,
281 const UsdImagingInstancerContext* instancerContext=nullptr) const;
282
283 // ---------------------------------------------------------------------- //
285 // ---------------------------------------------------------------------- //
286 bool _IsAffectedByTimeVaryingSkelAnim(const SdfPath& skinnedPrimPath)
287 const;
288
289 void _RemoveSkinnedPrimAndComputations(const SdfPath& cachePath,
290 UsdImagingIndexProxy* index);
291
292 // ---------------------------------------------------------------------- //
294 // ---------------------------------------------------------------------- //
295 bool _IsSkinningComputationPath(const SdfPath& cachePath) const;
296
297 bool
298 _IsSkinningInputAggregatorComputationPath(const SdfPath& cachePath)const;
299
300 void _TrackSkinningComputationVariability(
301 const UsdPrim& skinnedPrim,
302 const SdfPath& computationPath,
303 HdDirtyBits* timeVaryingBits,
305 instancerContext = nullptr) const;
306
307 VtVec3fArray _GetSkinnedPrimPoints(const UsdPrim& skinnedPrim,
308 const SdfPath& skinnedPrimCachePath,
309 UsdTimeCode time) const;
310
311 SdfPath _GetSkinningComputationPath(const SdfPath& skinnedPrimPath) const;
312
313 SdfPath _GetSkinningInputAggregatorComputationPath(
314 const SdfPath& skinnedPrimPath) const;
315
316 // Static helper methods
317 static
318 std::string _LoadSkinningComputeKernel(const TfToken& kernelKey);
319
320 static
321 const std::string& _GetLBSSkinningComputeKernel();
322
323 static
324 const std::string& _GetDQSSkinningComputeKernel();
325
326 // ---------------------------------------------------------------------- //
328 // ---------------------------------------------------------------------- //
329 bool _IsSkinnedPrimPath(const SdfPath& cachePath) const;
330
331 void _TrackSkinnedPrimVariability(
332 const UsdPrim& prim,
333 const SdfPath& cachePath,
334 HdDirtyBits* timeVaryingBits,
336 instancerContext = nullptr) const;
337
338 void _UpdateSkinnedPrimForTime(
339 const UsdPrim& prim,
340 const SdfPath& cachePath,
341 UsdTimeCode time,
342 HdDirtyBits requestedBits,
343 const UsdImagingInstancerContext* instancerContext=nullptr) const;
344
345 // ---------------------------------------------------------------------- //
347 // ---------------------------------------------------------------------- //
348
349 VtValue
350 _GetExtComputationInputForSkinningComputation(
351 UsdPrim const& prim,
352 SdfPath const& cachePath,
353 TfToken const& name,
354 UsdTimeCode time,
355 const UsdImagingInstancerContext* instancerContext) const;
356
357 VtValue
358 _GetExtComputationInputForInputAggregator(
359 UsdPrim const& prim,
360 SdfPath const& cachePath,
361 TfToken const& name,
362 UsdTimeCode time,
363 const UsdImagingInstancerContext* instancerContext) const;
364
365 size_t
366 _SampleExtComputationInputForSkinningComputation(
367 UsdPrim const& prim,
368 SdfPath const& cachePath,
369 TfToken const& name,
370 UsdTimeCode time,
371 const UsdImagingInstancerContext* instancerContext,
372 size_t maxSampleCount,
373 float *sampleTimes,
374 VtValue *sampleValues);
375
376 size_t
377 _SampleExtComputationInputForInputAggregator(
378 UsdPrim const& prim,
379 SdfPath const& cachePath,
380 TfToken const& name,
381 UsdTimeCode time,
382 const UsdImagingInstancerContext* instancerContext,
383 size_t maxSampleCount,
384 float *sampleTimes,
385 VtValue *sampleValues);
386
387
388 // ---------------------------------------------------------------------- //
390 // ---------------------------------------------------------------------- //
392 struct _SkelData {
393
394 UsdSkelSkeletonQuery skelQuery;
395 SdfPathSet skelRootPaths;
396
399 HdMeshTopology ComputeTopologyAndRestState();
400
402 VtVec3fArray ComputePoints(UsdTimeCode time) const;
403
406 TfToken ComputePurpose() const;
407
408 private:
409 // Cache of a mesh for a skeleton (at rest)
410 // TODO: Dedupe this infromation across UsdSkelSkeleton instances.
411 VtVec3fArray _boneMeshPoints;
412 VtIntArray _boneMeshJointIndices;
413 size_t _numJoints;
414 };
415
416 _SkelData* _GetSkelData(const SdfPath& cachePath) const;
417
418 UsdSkelCache _skelCache;
419 using _SkelDataMap =
420 std::unordered_map<SdfPath, std::shared_ptr<_SkelData>, SdfPath::Hash>;
421 _SkelDataMap _skelDataCache;
422
423 // Data for each skinned prim.
424 struct _SkinnedPrimData {
425 _SkinnedPrimData() = default;
426
430 _SkinnedPrimData(const SdfPath& skelPath,
431 const UsdSkelSkeletonQuery& skelQuery,
432 const UsdSkelSkinningQuery& skinningQuery,
433 const SdfPath& skelRootPath);
434
435 std::shared_ptr<UsdSkelBlendShapeQuery> blendShapeQuery;
436 UsdSkelSkinningQuery skinningQuery;
437 UsdSkelAnimQuery animQuery;
438 SdfPath skelPath, skelRootPath;
439 bool hasJointInfluences = false;
440 };
441
442 const _SkinnedPrimData* _GetSkinnedPrimData(const SdfPath& cachePath) const;
443
444 using _SkinnedPrimDataMap =
445 std::unordered_map<SdfPath, _SkinnedPrimData, SdfPath::Hash>;
446 _SkinnedPrimDataMap _skinnedPrimDataCache;
447
448 // ---------------------------------------------------------------------- //
451 // ---------------------------------------------------------------------- //
452
453 using _SkelBindingMap =
454 std::unordered_map<SdfPath, UsdSkelBinding, SdfPath::Hash>;
455 _SkelBindingMap _skelBindingMap;
456};
457
458
459PXR_NAMESPACE_CLOSE_SCOPE
460
461#endif // USDSKELIMAGING_SKELETONADAPTER
462
Basic type: 3-dimensional floating point range.
Definition: range3d.h:47
Basic type for a vector of 3 float components.
Definition: vec3f.h:46
Interface class that defines the execution environment for the client to run a computation.
Topology data for meshes.
Definition: meshTopology.h:38
Tags for non-hierarchial subdiv surfaces.
Definition: subdivTags.h:26
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
This proxy class exposes a subset of the private Delegate API to PrimAdapters.
Definition: indexProxy.h:30
An abstract adapter class for prims that are instanceable.
virtual USDIMAGING_API void ProcessPrimResync(SdfPath const &cachePath, UsdImagingIndexProxy *index)
When a PrimResync event occurs, the prim may have been deleted entirely, adapter plug-ins should over...
virtual USDIMAGING_API VtValue Get(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &key, UsdTimeCode time, VtIntArray *outIndices) const
Gets the value of the parameter named key for the given prim (which has the given cache path) and giv...
virtual HdDirtyBits ProcessPropertyChange(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &propertyName)=0
Returns a bit mask of attributes to be updated, or HdChangeTracker::AllDirty if the entire prim must ...
virtual SdfPath Populate(UsdPrim const &prim, UsdImagingIndexProxy *index, UsdImagingInstancerContext const *instancerContext=nullptr)=0
Called to populate the RenderIndex for this UsdPrim.
virtual void TrackVariability(UsdPrim const &prim, SdfPath const &cachePath, HdDirtyBits *timeVaryingBits, UsdImagingInstancerContext const *instancerContext=nullptr) const =0
For the given prim, variability is detected and stored in timeVaryingBits.
virtual USDIMAGING_API void ProcessPrimRemoval(SdfPath const &cachePath, UsdImagingIndexProxy *index)
Removes all associated Rprims and dependencies from the render index without scheduling them for repo...
virtual USDIMAGING_API VtValue GetTopology(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
Gets the topology object of a specific Usd prim.
virtual USDIMAGING_API TfToken GetPurpose(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &instanceInheritablePurpose) const
Returns the purpose token for prim.
virtual bool IsSupported(UsdImagingIndexProxy const *index) const
Returns true if the adapter can be populated into the target index.
Definition: primAdapter.h:668
virtual USDIMAGING_API GfRange3d GetExtent(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
Reads the extent from the given prim.
virtual void UpdateForTime(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, HdDirtyBits requestedBits, UsdImagingInstancerContext const *instancerContext=nullptr) const =0
Populates the cache for the given prim, time and requestedBits.
virtual USDIMAGING_API PxOsdSubdivTags GetSubdivTags(UsdPrim const &usdPrim, SdfPath const &cachePath, UsdTimeCode time) const
Get the subdiv tags for this prim.
virtual USDIMAGING_API bool GetDoubleSided(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
Reads double-sided from the given prim. If not authored, returns false.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
Class providing efficient queries of primitives that provide skel animation.
Definition: animQuery.h:38
Helper object that describes the binding of a skeleton to a set of skinnable objects.
Definition: binding.h:28
Thread-safe cache for accessing query objects for evaluating skeletal data.
Definition: cache.h:41
Primary interface to reading bound skeleton data.
Definition: skeletonQuery.h:54
Object used for querying resolved bindings for skinning.
Definition: skinningQuery.h:35
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:67
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
Object used by instancer prim adapters to pass along context about the instancer and instance prim to...
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440