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
24PXR_NAMESPACE_OPEN_SCOPE
25
31{
32public:
34
36 : BaseAdapter()
37 {}
38
39 USDSKELIMAGING_API
41
42 USDSKELIMAGING_API
44 Populate(const UsdPrim& prim,
47 instancerContext=nullptr) override;
48
49 USDSKELIMAGING_API
50 bool IsSupported(const UsdImagingIndexProxy* index) const override;
51
52 // ---------------------------------------------------------------------- //
54 // ---------------------------------------------------------------------- //
55
57 USDSKELIMAGING_API
58 void TrackVariability(const UsdPrim& prim,
59 const SdfPath& cachePath,
60 HdDirtyBits* timeVaryingBits,
62 instancerContext = nullptr) const override;
63
65 USDSKELIMAGING_API
66 void UpdateForTime(const UsdPrim& prim,
67 const SdfPath& cachePath,
68 UsdTimeCode time,
69 HdDirtyBits requestedBits,
71 instancerContext=nullptr) const override;
72
73 // ---------------------------------------------------------------------- //
75 // ---------------------------------------------------------------------- //
76
77 USDSKELIMAGING_API
78 HdDirtyBits ProcessPropertyChange(const UsdPrim& prim,
79 const SdfPath& cachePath,
80 const TfToken& propertyName) override;
81
82 USDSKELIMAGING_API
83 void ProcessPrimResync(SdfPath const& primPath,
84 UsdImagingIndexProxy* index) override;
85
86 USDSKELIMAGING_API
87 void ProcessPrimRemoval(SdfPath const& primPath,
88 UsdImagingIndexProxy* index) override;
89
90 USDSKELIMAGING_API
91 void MarkDirty(const UsdPrim& prim,
92 const SdfPath& cachePath,
93 HdDirtyBits dirty,
94 UsdImagingIndexProxy* index) override;
95
96 USDSKELIMAGING_API
97 void MarkRefineLevelDirty(UsdPrim const& prim,
98 SdfPath const& cachePath,
99 UsdImagingIndexProxy* index) override;
100
101 USDSKELIMAGING_API
102 void MarkReprDirty(UsdPrim const& prim,
103 SdfPath const& cachePath,
104 UsdImagingIndexProxy* index) override;
105
106 USDSKELIMAGING_API
107 void MarkCullStyleDirty(UsdPrim const& prim,
108 SdfPath const& cachePath,
109 UsdImagingIndexProxy* index) override;
110
111 USDSKELIMAGING_API
112 void MarkRenderTagDirty(UsdPrim const& prim,
113 SdfPath const& cachePath,
114 UsdImagingIndexProxy* index) override;
115
116 USDSKELIMAGING_API
117 void MarkTransformDirty(const UsdPrim& prim,
118 const SdfPath& cachePath,
119 UsdImagingIndexProxy* index) override;
120
121 USDSKELIMAGING_API
122 void MarkVisibilityDirty(const UsdPrim& prim,
123 const SdfPath& cachePath,
124 UsdImagingIndexProxy* index) override;
125
126 USDSKELIMAGING_API
127 void MarkMaterialDirty(const UsdPrim& prim,
128 const SdfPath& cachePath,
129 UsdImagingIndexProxy* index) override;
130
131 // ---------------------------------------------------------------------- //
133 // ---------------------------------------------------------------------- //
134 USDSKELIMAGING_API
135 void InvokeComputation(SdfPath const& cachePath,
136 HdExtComputationContext* context) override;
137
138 // ---------------------------------------------------------------------- //
140 // ---------------------------------------------------------------------- //
141
142 USDSKELIMAGING_API
143 void RegisterSkelBinding(UsdSkelBinding const& binding);
144
145 // ---------------------------------------------------------------------- //
147 // ---------------------------------------------------------------------- //
148
149 USDSKELIMAGING_API
151 SdfPath const& cachePath,
152 UsdTimeCode time) const override;
153
154 USDSKELIMAGING_API
156 SdfPath const& cachePath,
157 UsdTimeCode time) const override;
158
159 USDSKELIMAGING_API
161 SdfPath const& cachePath,
162 UsdTimeCode time) const override;
163
164 USDSKELIMAGING_API
166 SdfPath const& cachePath,
167 TfToken const& instanceInheritablePurpose)
168 const override;
169
170 USDSKELIMAGING_API
171 bool GetDoubleSided(UsdPrim const& prim,
172 SdfPath const& cachePath,
173 UsdTimeCode time) const override;
174
175
176 USDSKELIMAGING_API
177 SdfPath GetMaterialId(UsdPrim const& prim,
178 SdfPath const& cachePath,
179 UsdTimeCode time) const override;
180
181
182 USDSKELIMAGING_API
183 const TfTokenVector &GetExtComputationSceneInputNames(
184 SdfPath const& cachePath) const override;
185
186 USDSKELIMAGING_API
187 HdExtComputationInputDescriptorVector
188 GetExtComputationInputs(UsdPrim const& prim,
189 SdfPath const& cachePath,
190 const UsdImagingInstancerContext *instancerContext)
191 const override;
192
193 USDSKELIMAGING_API
194 HdExtComputationOutputDescriptorVector
195 GetExtComputationOutputs(UsdPrim const& prim,
196 SdfPath const& cachePath,
197 const UsdImagingInstancerContext* instancerContext)
198 const override;
199
200 USDSKELIMAGING_API
201 HdExtComputationPrimvarDescriptorVector
202 GetExtComputationPrimvars(
203 UsdPrim const& prim,
204 SdfPath const& cachePath,
205 HdInterpolation interpolation,
206 const UsdImagingInstancerContext* instancerContext) const override;
207
208 USDSKELIMAGING_API
209 VtValue
210 GetExtComputationInput(
211 UsdPrim const& prim,
212 SdfPath const& cachePath,
213 TfToken const& name,
214 UsdTimeCode time,
215 const UsdImagingInstancerContext* instancerContext) const override;
216
217 USDSKELIMAGING_API
218 size_t
219 SampleExtComputationInput(
220 UsdPrim const& prim,
221 SdfPath const& cachePath,
222 TfToken const& name,
223 UsdTimeCode time,
224 const UsdImagingInstancerContext* instancerContext,
225 size_t maxSampleCount,
226 float *sampleTimes,
227 VtValue *sampleValues) override;
228
229 USDSKELIMAGING_API
230 std::string
231 GetExtComputationKernel(
232 UsdPrim const& prim,
233 SdfPath const& cachePath,
234 const UsdImagingInstancerContext* instancerContext) const override;
235
236
237 USDSKELIMAGING_API
238 VtValue Get(UsdPrim const& prim,
239 SdfPath const& cachePath,
240 TfToken const& key,
241 UsdTimeCode time,
242 VtIntArray *outIndices) const override;
243
244 // ---------------------------------------------------------------------- //
246 // ---------------------------------------------------------------------- //
247 USDSKELIMAGING_API
248 TfTokenVector GetImagingSubprims(UsdPrim const &prim) override;
249
250 USDSKELIMAGING_API
251 TfToken GetImagingSubprimType(
252 UsdPrim const &prim,
253 TfToken const &subprim) override;
254
255 USDSKELIMAGING_API
256 HdContainerDataSourceHandle GetImagingSubprimData(
257 UsdPrim const& prim,
258 TfToken const& subprim,
259 const UsdImagingDataSourceStageGlobals &stageGlobals) override;
260
261 USDSKELIMAGING_API
262 HdDataSourceLocatorSet InvalidateImagingSubprim(
263 UsdPrim const& prim,
264 TfToken const& subprim,
265 TfTokenVector const& properties,
266 UsdImagingPropertyInvalidationType invalidationType) override;
267
268protected:
269 // ---------------------------------------------------------------------- //
271 // ---------------------------------------------------------------------- //
272 void _RemovePrim(const SdfPath& cachePath,
273 UsdImagingIndexProxy* index) override;
274
275private:
276 // ---------------------------------------------------------------------- //
278 // ---------------------------------------------------------------------- //
279 bool _IsCallbackForSkeleton(const UsdPrim& prim) const;
280
283 GfVec3f _GetSkeletonDisplayColor(const UsdPrim& prim,
284 UsdTimeCode time) const;
285
288 float _GetSkeletonDisplayOpacity(const UsdPrim& prim,
289 UsdTimeCode time) const;
290
291 void _TrackBoneMeshVariability(
292 const UsdPrim& prim,
293 const SdfPath& cachePath,
294 HdDirtyBits* timeVaryingBits,
296 instancerContext = nullptr) const;
297
298 void _UpdateBoneMeshForTime(
299 const UsdPrim& prim,
300 const SdfPath& cachePath,
301 UsdTimeCode time,
302 HdDirtyBits requestedBits,
303 const UsdImagingInstancerContext* instancerContext=nullptr) const;
304
305 // ---------------------------------------------------------------------- //
307 // ---------------------------------------------------------------------- //
308 bool _IsAffectedByTimeVaryingSkelAnim(const SdfPath& skinnedPrimPath)
309 const;
310
311 void _RemoveSkinnedPrimAndComputations(const SdfPath& cachePath,
312 UsdImagingIndexProxy* index);
313
314 // ---------------------------------------------------------------------- //
316 // ---------------------------------------------------------------------- //
317 bool _IsSkinningComputationPath(const SdfPath& cachePath) const;
318
319 bool
320 _IsSkinningInputAggregatorComputationPath(const SdfPath& cachePath)const;
321
322 void _TrackSkinningComputationVariability(
323 const UsdPrim& skinnedPrim,
324 const SdfPath& computationPath,
325 HdDirtyBits* timeVaryingBits,
327 instancerContext = nullptr) const;
328
329 VtVec3fArray _GetSkinnedPrimPoints(const UsdPrim& skinnedPrim,
330 const SdfPath& skinnedPrimCachePath,
331 UsdTimeCode time) const;
332
333 SdfPath _GetSkinningComputationPath(const SdfPath& skinnedPrimPath) const;
334
335 SdfPath _GetSkinningInputAggregatorComputationPath(
336 const SdfPath& skinnedPrimPath) const;
337
338 // Static helper methods
339 static
340 std::string _LoadSkinningComputeKernel(const TfToken& kernelKey);
341
342 static
343 const std::string& _GetLBSSkinningComputeKernel();
344
345 static
346 const std::string& _GetDQSSkinningComputeKernel();
347
348 // ---------------------------------------------------------------------- //
350 // ---------------------------------------------------------------------- //
351 bool _IsSkinnedPrimPath(const SdfPath& cachePath) const;
352
353 void _TrackSkinnedPrimVariability(
354 const UsdPrim& prim,
355 const SdfPath& cachePath,
356 HdDirtyBits* timeVaryingBits,
358 instancerContext = nullptr) const;
359
360 void _UpdateSkinnedPrimForTime(
361 const UsdPrim& prim,
362 const SdfPath& cachePath,
363 UsdTimeCode time,
364 HdDirtyBits requestedBits,
365 const UsdImagingInstancerContext* instancerContext=nullptr) const;
366
367 // ---------------------------------------------------------------------- //
369 // ---------------------------------------------------------------------- //
370
371 VtValue
372 _GetExtComputationInputForSkinningComputation(
373 UsdPrim const& prim,
374 SdfPath const& cachePath,
375 TfToken const& name,
376 UsdTimeCode time,
377 const UsdImagingInstancerContext* instancerContext) const;
378
379 VtValue
380 _GetExtComputationInputForInputAggregator(
381 UsdPrim const& prim,
382 SdfPath const& cachePath,
383 TfToken const& name,
384 UsdTimeCode time,
385 const UsdImagingInstancerContext* instancerContext) const;
386
387 size_t
388 _SampleExtComputationInputForSkinningComputation(
389 UsdPrim const& prim,
390 SdfPath const& cachePath,
391 TfToken const& name,
392 UsdTimeCode time,
393 const UsdImagingInstancerContext* instancerContext,
394 size_t maxSampleCount,
395 float *sampleTimes,
396 VtValue *sampleValues);
397
398 size_t
399 _SampleExtComputationInputForInputAggregator(
400 UsdPrim const& prim,
401 SdfPath const& cachePath,
402 TfToken const& name,
403 UsdTimeCode time,
404 const UsdImagingInstancerContext* instancerContext,
405 size_t maxSampleCount,
406 float *sampleTimes,
407 VtValue *sampleValues);
408
411 double _GetDefaultSampleTime(UsdTimeCode time);
412
413
414 // ---------------------------------------------------------------------- //
416 // ---------------------------------------------------------------------- //
418 struct _SkelData {
419
420 UsdSkelSkeletonQuery skelQuery;
421 SdfPathSet skelRootPaths;
422
425 HdMeshTopology ComputeTopologyAndRestState();
426
428 VtVec3fArray ComputePoints(UsdTimeCode time) const;
429
432 TfToken ComputePurpose() const;
433
434 private:
435 // Cache of a mesh for a skeleton (at rest)
436 // TODO: Dedupe this infromation across UsdSkelSkeleton instances.
437 VtVec3fArray _boneMeshPoints;
438 VtIntArray _boneMeshJointIndices;
439 size_t _numJoints;
440 };
441
442 _SkelData* _GetSkelData(const SdfPath& cachePath) const;
443
444 UsdSkelCache _skelCache;
445 using _SkelDataMap =
446 std::unordered_map<SdfPath, std::shared_ptr<_SkelData>, SdfPath::Hash>;
447 _SkelDataMap _skelDataCache;
448
449 // Data for each skinned prim.
450 struct _SkinnedPrimData {
451 _SkinnedPrimData() = default;
452
456 _SkinnedPrimData(const SdfPath& skelPath,
457 const UsdSkelSkeletonQuery& skelQuery,
458 const UsdSkelSkinningQuery& skinningQuery,
459 const SdfPath& skelRootPath);
460
461 std::shared_ptr<UsdSkelBlendShapeQuery> blendShapeQuery;
462 UsdSkelSkinningQuery skinningQuery;
463 UsdSkelAnimQuery animQuery;
464 SdfPath skelPath, skelRootPath;
465 bool hasJointInfluences = false;
466 };
467
468 const _SkinnedPrimData* _GetSkinnedPrimData(const SdfPath& cachePath) const;
469
470 using _SkinnedPrimDataMap =
471 std::unordered_map<SdfPath, _SkinnedPrimData, SdfPath::Hash>;
472 _SkinnedPrimDataMap _skinnedPrimDataCache;
473
474 // ---------------------------------------------------------------------- //
477 // ---------------------------------------------------------------------- //
478
479 using _SkelBindingMap =
480 std::unordered_map<SdfPath, UsdSkelBinding, SdfPath::Hash>;
481 _SkelBindingMap _skelBindingMap;
482};
483
484
485PXR_NAMESPACE_CLOSE_SCOPE
486
487#endif // USDSKELIMAGING_SKELETONADAPTER
488
Basic type: 3-dimensional floating point range.
Definition: range3d.h:47
Basic type for a vector of 3 float components.
Definition: vec3f.h:46
Represents a set of data source locators closed under descendancy.
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 class is used as a context object with global stage information, that gets passed down to dataso...
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.
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
Prim adapter for UsdSkel's Skeleton.
USDSKELIMAGING_API void ProcessPrimResync(SdfPath const &primPath, UsdImagingIndexProxy *index) override
When a PrimResync event occurs, the prim may have been deleted entirely, adapter plug-ins should over...
USDSKELIMAGING_API VtValue Get(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &key, UsdTimeCode time, VtIntArray *outIndices) const override
Gets the value of the parameter named key for the given prim (which has the given cache path) and giv...
USDSKELIMAGING_API TfToken GetPurpose(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &instanceInheritablePurpose) const override
Returns the purpose token for prim.
USDSKELIMAGING_API SdfPath Populate(const UsdPrim &prim, UsdImagingIndexProxy *index, const UsdImagingInstancerContext *instancerContext=nullptr) override
Called to populate the RenderIndex for this UsdPrim.
USDSKELIMAGING_API VtValue GetTopology(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
Gets the topology object of a specific Usd prim.
USDSKELIMAGING_API bool GetDoubleSided(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
Reads double-sided from the given prim. If not authored, returns false.
USDSKELIMAGING_API PxOsdSubdivTags GetSubdivTags(UsdPrim const &usdPrim, SdfPath const &cachePath, UsdTimeCode time) const override
Get the subdiv tags for this prim.
USDSKELIMAGING_API void ProcessPrimRemoval(SdfPath const &primPath, UsdImagingIndexProxy *index) override
Removes all associated Rprims and dependencies from the render index without scheduling them for repo...
USDSKELIMAGING_API HdDirtyBits ProcessPropertyChange(const UsdPrim &prim, const SdfPath &cachePath, const TfToken &propertyName) override
Returns a bit mask of attributes to be updated, or HdChangeTracker::AllDirty if the entire prim must ...
USDSKELIMAGING_API bool IsSupported(const UsdImagingIndexProxy *index) const override
Returns true if the adapter can be populated into the target index.
USDSKELIMAGING_API GfRange3d GetExtent(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const override
Reads the extent from the given prim.
USDSKELIMAGING_API void TrackVariability(const UsdPrim &prim, const SdfPath &cachePath, HdDirtyBits *timeVaryingBits, const UsdImagingInstancerContext *instancerContext=nullptr) const override
Thread Safe.
USDSKELIMAGING_API void UpdateForTime(const UsdPrim &prim, const SdfPath &cachePath, UsdTimeCode time, HdDirtyBits requestedBits, const UsdImagingInstancerContext *instancerContext=nullptr) const override
Thread Safe.
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:72
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:152
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