Loading...
Searching...
No Matches
skeletonAdapter.h
1//
2// Copyright 2018 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_SKEL_IMAGING_SKELETON_ADAPTER_H
25#define PXR_USD_IMAGING_USD_SKEL_IMAGING_SKELETON_ADAPTER_H
26
27#include "pxr/pxr.h"
29#include "pxr/usdImaging/usdSkelImaging/api.h"
30
31#include "pxr/imaging/hd/meshTopology.h"
32
38
39#include <boost/unordered_map.hpp>
40#include <unordered_map>
41
42
43PXR_NAMESPACE_OPEN_SCOPE
44
45
50class UsdSkelImagingSkeletonAdapter : public UsdImagingPrimAdapter
51{
52public:
53 using BaseAdapter = UsdImagingPrimAdapter;
54
55 UsdSkelImagingSkeletonAdapter()
56 : BaseAdapter()
57 {}
58
59 USDSKELIMAGING_API
60 virtual ~UsdSkelImagingSkeletonAdapter();
61
62 USDSKELIMAGING_API
64 Populate(const UsdPrim& prim,
67 instancerContext=nullptr) override;
68
69 USDSKELIMAGING_API
70 bool IsSupported(const UsdImagingIndexProxy* index) const override;
71
72 // ---------------------------------------------------------------------- //
74 // ---------------------------------------------------------------------- //
75
77 USDSKELIMAGING_API
78 void TrackVariability(const UsdPrim& prim,
79 const SdfPath& cachePath,
80 HdDirtyBits* timeVaryingBits,
82 instancerContext = nullptr) const override;
83
85 USDSKELIMAGING_API
86 void UpdateForTime(const UsdPrim& prim,
87 const SdfPath& cachePath,
88 UsdTimeCode time,
89 HdDirtyBits requestedBits,
91 instancerContext=nullptr) const override;
92
93 // ---------------------------------------------------------------------- //
95 // ---------------------------------------------------------------------- //
96
97 USDSKELIMAGING_API
98 HdDirtyBits ProcessPropertyChange(const UsdPrim& prim,
99 const SdfPath& cachePath,
100 const TfToken& propertyName) override;
101
102 USDSKELIMAGING_API
103 void ProcessPrimResync(SdfPath const& primPath,
104 UsdImagingIndexProxy* index) override;
105
106 USDSKELIMAGING_API
107 void ProcessPrimRemoval(SdfPath const& primPath,
108 UsdImagingIndexProxy* index) override;
109
110 USDSKELIMAGING_API
111 void MarkDirty(const UsdPrim& prim,
112 const SdfPath& cachePath,
113 HdDirtyBits dirty,
114 UsdImagingIndexProxy* index) override;
115
116 USDSKELIMAGING_API
117 void MarkRefineLevelDirty(UsdPrim const& prim,
118 SdfPath const& cachePath,
119 UsdImagingIndexProxy* index) override;
120
121 USDSKELIMAGING_API
122 void MarkReprDirty(UsdPrim const& prim,
123 SdfPath const& cachePath,
124 UsdImagingIndexProxy* index) override;
125
126 USDSKELIMAGING_API
127 void MarkCullStyleDirty(UsdPrim const& prim,
128 SdfPath const& cachePath,
129 UsdImagingIndexProxy* index) override;
130
131 USDSKELIMAGING_API
132 void MarkRenderTagDirty(UsdPrim const& prim,
133 SdfPath const& cachePath,
134 UsdImagingIndexProxy* index) override;
135
136 USDSKELIMAGING_API
137 void MarkTransformDirty(const UsdPrim& prim,
138 const SdfPath& cachePath,
139 UsdImagingIndexProxy* index) override;
140
141 USDSKELIMAGING_API
142 void MarkVisibilityDirty(const UsdPrim& prim,
143 const SdfPath& cachePath,
144 UsdImagingIndexProxy* index) override;
145
146 USDSKELIMAGING_API
147 void MarkMaterialDirty(const UsdPrim& prim,
148 const SdfPath& cachePath,
149 UsdImagingIndexProxy* index) override;
150
151 // ---------------------------------------------------------------------- //
153 // ---------------------------------------------------------------------- //
154 USDSKELIMAGING_API
155 void InvokeComputation(SdfPath const& cachePath,
156 HdExtComputationContext* context) override;
157
158 // ---------------------------------------------------------------------- //
160 // ---------------------------------------------------------------------- //
161
162 USDSKELIMAGING_API
163 void RegisterSkelBinding(UsdSkelBinding const& binding);
164
165 // ---------------------------------------------------------------------- //
167 // ---------------------------------------------------------------------- //
168
169 USDSKELIMAGING_API
171 SdfPath const& cachePath,
172 UsdTimeCode time) const override;
173
174 USDSKELIMAGING_API
175 VtValue GetTopology(UsdPrim const& prim,
176 SdfPath const& cachePath,
177 UsdTimeCode time) const override;
178
179 USDSKELIMAGING_API
180 GfRange3d GetExtent(UsdPrim const& prim,
181 SdfPath const& cachePath,
182 UsdTimeCode time) const override;
183
184 USDSKELIMAGING_API
185 TfToken GetPurpose(UsdPrim const& prim,
186 SdfPath const& cachePath,
187 TfToken const& instanceInheritablePurpose)
188 const override;
189
190 USDSKELIMAGING_API
191 bool GetDoubleSided(UsdPrim const& prim,
192 SdfPath const& cachePath,
193 UsdTimeCode time) const override;
194
195
196 USDSKELIMAGING_API
197 SdfPath GetMaterialId(UsdPrim const& prim,
198 SdfPath const& cachePath,
199 UsdTimeCode time) const override;
200
201
202 USDSKELIMAGING_API
203 const TfTokenVector &GetExtComputationSceneInputNames(
204 SdfPath const& cachePath) const override;
205
206 USDSKELIMAGING_API
207 HdExtComputationInputDescriptorVector
208 GetExtComputationInputs(UsdPrim const& prim,
209 SdfPath const& cachePath,
210 const UsdImagingInstancerContext *instancerContext)
211 const override;
212
213 HdExtComputationOutputDescriptorVector
214 GetExtComputationOutputs(UsdPrim const& prim,
215 SdfPath const& cachePath,
216 const UsdImagingInstancerContext* instancerContext)
217 const override;
218
219 HdExtComputationPrimvarDescriptorVector
220 GetExtComputationPrimvars(
221 UsdPrim const& prim,
222 SdfPath const& cachePath,
223 HdInterpolation interpolation,
224 const UsdImagingInstancerContext* instancerContext) const override;
225
226 USDIMAGING_API
227 VtValue
228 GetExtComputationInput(
229 UsdPrim const& prim,
230 SdfPath const& cachePath,
231 TfToken const& name,
232 UsdTimeCode time,
233 const UsdImagingInstancerContext* instancerContext) const override;
234
235 USDIMAGING_API
236 size_t
237 SampleExtComputationInput(
238 UsdPrim const& prim,
239 SdfPath const& cachePath,
240 TfToken const& name,
241 UsdTimeCode time,
242 const UsdImagingInstancerContext* instancerContext,
243 size_t maxSampleCount,
244 float *sampleTimes,
245 VtValue *sampleValues) override;
246
247 USDIMAGING_API
248 std::string
249 GetExtComputationKernel(
250 UsdPrim const& prim,
251 SdfPath const& cachePath,
252 const UsdImagingInstancerContext* instancerContext) const override;
253
254
255 USDSKELIMAGING_API
256 VtValue Get(UsdPrim const& prim,
257 SdfPath const& cachePath,
258 TfToken const& key,
259 UsdTimeCode time,
260 VtIntArray *outIndices) const override;
261
262protected:
263 // ---------------------------------------------------------------------- //
265 // ---------------------------------------------------------------------- //
266 void _RemovePrim(const SdfPath& cachePath,
267 UsdImagingIndexProxy* index) override;
268
269private:
270 // ---------------------------------------------------------------------- //
272 // ---------------------------------------------------------------------- //
273 bool _IsCallbackForSkeleton(const UsdPrim& prim) const;
274
277 GfVec3f _GetSkeletonDisplayColor(const UsdPrim& prim,
278 UsdTimeCode time) const;
279
282 float _GetSkeletonDisplayOpacity(const UsdPrim& prim,
283 UsdTimeCode time) const;
284
285 void _TrackBoneMeshVariability(
286 const UsdPrim& prim,
287 const SdfPath& cachePath,
288 HdDirtyBits* timeVaryingBits,
290 instancerContext = nullptr) const;
291
292 void _UpdateBoneMeshForTime(
293 const UsdPrim& prim,
294 const SdfPath& cachePath,
295 UsdTimeCode time,
296 HdDirtyBits requestedBits,
297 const UsdImagingInstancerContext* instancerContext=nullptr) const;
298
299 // ---------------------------------------------------------------------- //
301 // ---------------------------------------------------------------------- //
302 bool _IsAffectedByTimeVaryingSkelAnim(const SdfPath& skinnedPrimPath)
303 const;
304
305 void _RemoveSkinnedPrimAndComputations(const SdfPath& cachePath,
306 UsdImagingIndexProxy* index);
307
308 // ---------------------------------------------------------------------- //
310 // ---------------------------------------------------------------------- //
311 bool _IsSkinningComputationPath(const SdfPath& cachePath) const;
312
313 bool
314 _IsSkinningInputAggregatorComputationPath(const SdfPath& cachePath)const;
315
316 void _TrackSkinningComputationVariability(
317 const UsdPrim& skinnedPrim,
318 const SdfPath& computationPath,
319 HdDirtyBits* timeVaryingBits,
321 instancerContext = nullptr) const;
322
323 VtVec3fArray _GetSkinnedPrimPoints(const UsdPrim& skinnedPrim,
324 const SdfPath& skinnedPrimCachePath,
325 UsdTimeCode time) const;
326
327 SdfPath _GetSkinningComputationPath(const SdfPath& skinnedPrimPath) const;
328
329 SdfPath _GetSkinningInputAggregatorComputationPath(
330 const SdfPath& skinnedPrimPath) const;
331
332 // Static helper methods
333 static
334 std::string _LoadSkinningComputeKernel(const TfToken& kernelKey);
335
336 static
337 const std::string& _GetLBSSkinningComputeKernel();
338
339 static
340 const std::string& _GetDQSSkinningComputeKernel();
341
342 // ---------------------------------------------------------------------- //
344 // ---------------------------------------------------------------------- //
345 bool _IsSkinnedPrimPath(const SdfPath& cachePath) const;
346
347 void _TrackSkinnedPrimVariability(
348 const UsdPrim& prim,
349 const SdfPath& cachePath,
350 HdDirtyBits* timeVaryingBits,
352 instancerContext = nullptr) const;
353
354 void _UpdateSkinnedPrimForTime(
355 const UsdPrim& prim,
356 const SdfPath& cachePath,
357 UsdTimeCode time,
358 HdDirtyBits requestedBits,
359 const UsdImagingInstancerContext* instancerContext=nullptr) const;
360
361 // ---------------------------------------------------------------------- //
363 // ---------------------------------------------------------------------- //
364
365 VtValue
366 _GetExtComputationInputForSkinningComputation(
367 UsdPrim const& prim,
368 SdfPath const& cachePath,
369 TfToken const& name,
370 UsdTimeCode time,
371 const UsdImagingInstancerContext* instancerContext) const;
372
373 VtValue
374 _GetExtComputationInputForInputAggregator(
375 UsdPrim const& prim,
376 SdfPath const& cachePath,
377 TfToken const& name,
378 UsdTimeCode time,
379 const UsdImagingInstancerContext* instancerContext) const;
380
381 size_t
382 _SampleExtComputationInputForSkinningComputation(
383 UsdPrim const& prim,
384 SdfPath const& cachePath,
385 TfToken const& name,
386 UsdTimeCode time,
387 const UsdImagingInstancerContext* instancerContext,
388 size_t maxSampleCount,
389 float *sampleTimes,
390 VtValue *sampleValues);
391
392 size_t
393 _SampleExtComputationInputForInputAggregator(
394 UsdPrim const& prim,
395 SdfPath const& cachePath,
396 TfToken const& name,
397 UsdTimeCode time,
398 const UsdImagingInstancerContext* instancerContext,
399 size_t maxSampleCount,
400 float *sampleTimes,
401 VtValue *sampleValues);
402
403
404 // ---------------------------------------------------------------------- //
406 // ---------------------------------------------------------------------- //
408 struct _SkelData {
409
410 UsdSkelSkeletonQuery skelQuery;
411 SdfPathSet skelRootPaths;
412
415 HdMeshTopology ComputeTopologyAndRestState();
416
418 VtVec3fArray ComputePoints(UsdTimeCode time) const;
419
422 TfToken ComputePurpose() const;
423
424 private:
425 // Cache of a mesh for a skeleton (at rest)
426 // TODO: Dedupe this infromation across UsdSkelSkeleton instances.
427 VtVec3fArray _boneMeshPoints;
428 VtIntArray _boneMeshJointIndices;
429 size_t _numJoints;
430 };
431
432 _SkelData* _GetSkelData(const SdfPath& cachePath) const;
433
434 UsdSkelCache _skelCache;
435 using _SkelDataMap =
436 std::unordered_map<SdfPath, std::shared_ptr<_SkelData>, SdfPath::Hash>;
437 _SkelDataMap _skelDataCache;
438
439 // Data for each skinned prim.
440 struct _SkinnedPrimData {
441 _SkinnedPrimData() = default;
442
446 _SkinnedPrimData(const SdfPath& skelPath,
447 const UsdSkelSkeletonQuery& skelQuery,
448 const UsdSkelSkinningQuery& skinningQuery,
449 const SdfPath& skelRootPath);
450
451 std::shared_ptr<UsdSkelBlendShapeQuery> blendShapeQuery;
452 UsdSkelSkinningQuery skinningQuery;
453 UsdSkelAnimQuery animQuery;
454 SdfPath skelPath, skelRootPath;
455 bool hasJointInfluences = false;
456 };
457
458 const _SkinnedPrimData* _GetSkinnedPrimData(const SdfPath& cachePath) const;
459
460 using _SkinnedPrimDataMap =
461 std::unordered_map<SdfPath, _SkinnedPrimData, SdfPath::Hash>;
462 _SkinnedPrimDataMap _skinnedPrimDataCache;
463
464 // ---------------------------------------------------------------------- //
467 // ---------------------------------------------------------------------- //
468
469 using _SkelBindingMap =
470 std::unordered_map<SdfPath, UsdSkelBinding, SdfPath::Hash>;
471 _SkelBindingMap _skelBindingMap;
472};
473
474
475PXR_NAMESPACE_CLOSE_SCOPE
476
477#endif // USDSKELIMAGING_SKELETONADAPTER
478
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
Interface class that defines the execution environment for the client to run a computation.
Topology data for meshes.
Definition: meshTopology.h:55
Tags for non-hierarchial subdiv surfaces.
Definition: subdivTags.h:43
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:291
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
This proxy class exposes a subset of the private Delegate API to PrimAdapters.
Definition: indexProxy.h:47
Base class for all PrimAdapters.
Definition: primAdapter.h:70
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:688
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:134
Class providing efficient queries of primitives that provide skel animation.
Definition: animQuery.h:55
Helper object that describes the binding of a skeleton to a set of skinnable objects.
Definition: binding.h:45
Thread-safe cache for accessing query objects for evaluating skeletal data.
Definition: cache.h:58
Primary interface to reading bound skeleton data.
Definition: skeletonQuery.h:71
Object used for querying resolved bindings for skinning.
Definition: skinningQuery.h:52
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:84
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:164
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:442