Loading...
Searching...
No Matches
primAdapter.h
Go to the documentation of this file.
1//
2// Copyright 2016 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_PRIM_ADAPTER_H
8#define PXR_USD_IMAGING_USD_IMAGING_PRIM_ADAPTER_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usdImaging/usdImaging/api.h"
14#include "pxr/usdImaging/usdImaging/version.h"
18#include "pxr/usdImaging/usdImaging/types.h"
19
20#include "pxr/imaging/hd/changeTracker.h"
21#include "pxr/imaging/hd/selection.h"
22#include "pxr/usd/sdf/path.h"
23#include "pxr/usd/usd/attribute.h"
24#include "pxr/usd/usd/prim.h"
25#include "pxr/usd/usd/timeCode.h"
26
28
29#include "pxr/base/tf/type.h"
30
31#include <memory>
32
33PXR_NAMESPACE_OPEN_SCOPE
34
35class UsdPrim;
36
37// Forward declaration for nested class.
42
44
45using UsdImagingPrimAdapterSharedPtr =
46 std::shared_ptr<class UsdImagingPrimAdapter>;
47
53 : public std::enable_shared_from_this<UsdImagingPrimAdapter>
54{
55public:
56 USDIMAGING_API
57 virtual ~UsdImagingPrimAdapter() = default;
58
59 // ---------------------------------------------------------------------- //
61 // ---------------------------------------------------------------------- //
62
63 USDIMAGING_API
64 virtual TfTokenVector GetImagingSubprims(UsdPrim const& prim);
65
66 USDIMAGING_API
67 virtual TfToken GetImagingSubprimType(
68 UsdPrim const& prim, TfToken const& subprim);
69
70 USDIMAGING_API
71 virtual HdContainerDataSourceHandle GetImagingSubprimData(
72 UsdPrim const& prim,
73 TfToken const& subprim,
74 const UsdImagingDataSourceStageGlobals &stageGlobals);
75
76 USDIMAGING_API
77 virtual HdDataSourceLocatorSet InvalidateImagingSubprim(
78 UsdPrim const& prim,
79 TfToken const& subprim,
80 TfTokenVector const& properties,
81 UsdImagingPropertyInvalidationType invalidationType);
82
89 {
93
99
108 };
109
112 USDIMAGING_API
114
119 USDIMAGING_API
121 UsdPrim const& prim,
122 UsdPrim const& descendentPrim,
123 TfToken const& subprim,
124 TfTokenVector const& properties,
125 UsdImagingPropertyInvalidationType invalidationType);
126
127 // ---------------------------------------------------------------------- //
129 // ---------------------------------------------------------------------- //
130
134 virtual SdfPath Populate(UsdPrim const& prim,
137 instancerContext = nullptr) = 0;
138
139 // Indicates whether population traversal should be pruned based on
140 // prim-specific features (like whether it's imageable).
141 USDIMAGING_API
142 static bool ShouldCullSubtree(UsdPrim const& prim);
143
144 // Indicates whether population traversal should be pruned based on
145 // adapter-specific features (like whether the adapter is an instance
146 // adapter, and wants to do its own population).
147 USDIMAGING_API
148 virtual bool ShouldCullChildren() const;
149
150 // Indicates whether or not native USD prim instancing should be ignored
151 // for prims using this delegate, along with their descendants.
152 USDIMAGING_API
153 virtual bool ShouldIgnoreNativeInstanceSubtrees() const;
154
155 // Indicates the adapter is a multiplexing adapter (e.g. PointInstancer),
156 // potentially managing its children. This flag is used in nested
157 // instancer cases to determine which adapter is assigned to which prim.
158 USDIMAGING_API
159 virtual bool IsInstancerAdapter() const;
160
161 // Indicates whether this adapter can directly populate USD instance prims.
162 //
163 // Normally, with USD instances, we make a firewall between the instance
164 // prim and the USD prototype tree. The instance adapter creates one
165 // hydra prototype per prim in the USD prototype tree, shared by all USD
166 // instances; this lets us recognize the benefits of instancing,
167 // by hopefully having a high instance count per prototype. The instance
168 // adapter additionally configures a hydra instancer for the prototype tree;
169 // and a small set of specially-handled data is allowed through: things like
170 // inherited constant primvars, transforms, visibility, and other things
171 // we know how to vary per-instance.
172 //
173 // We enforce the above policy by refusing to populate gprims which are
174 // USD instances, since we'd need one prototype per instance and would lose
175 // any instancing benefit.
176 //
177 // There are a handful of times when it really is useful to directly
178 // populate instance prims: for example, instances with cards applied,
179 // or instances of type UsdSkelRoot. In those cases, the adapters can
180 // opt into this scheme with "CanPopulateUsdInstance".
181 //
182 // Note that any adapters taking advantage of this feature will need
183 // extensive code support in instanceAdapter: the instance adapter will
184 // need to potentially create and track multiple hydra prototypes per
185 // USD prototype, and the adapter will need special handling to pass down
186 // any relevant instance-varying data.
187 //
188 // In summary: use with caution.
189 USDIMAGING_API
190 virtual bool CanPopulateUsdInstance() const;
191
192 // ---------------------------------------------------------------------- //
194 // ---------------------------------------------------------------------- //
195
201 virtual void TrackVariability(UsdPrim const& prim,
202 SdfPath const& cachePath,
203 HdDirtyBits* timeVaryingBits,
205 instancerContext = nullptr) const = 0;
206
211 virtual void UpdateForTime(UsdPrim const& prim,
212 SdfPath const& cachePath,
213 UsdTimeCode time,
214 HdDirtyBits requestedBits,
216 instancerContext = nullptr) const = 0;
217
218 // ---------------------------------------------------------------------- //
220 // ---------------------------------------------------------------------- //
221
232 USDIMAGING_API
233 virtual HdDirtyBits ProcessPrimChange(UsdPrim const& prim,
234 SdfPath const& cachePath,
235 TfTokenVector const& changedFields);
236
239 virtual HdDirtyBits ProcessPropertyChange(UsdPrim const& prim,
240 SdfPath const& cachePath,
241 TfToken const& propertyName) = 0;
242
246 USDIMAGING_API
247 virtual void ProcessPrimResync(SdfPath const& cachePath,
248 UsdImagingIndexProxy* index);
249
252 USDIMAGING_API
253 virtual void ProcessPrimRemoval(SdfPath const& cachePath,
254 UsdImagingIndexProxy* index);
255
256
257 virtual void MarkDirty(UsdPrim const& prim,
258 SdfPath const& cachePath,
259 HdDirtyBits dirty,
260 UsdImagingIndexProxy* index) = 0;
261
262 USDIMAGING_API
263 virtual void MarkRefineLevelDirty(UsdPrim const& prim,
264 SdfPath const& cachePath,
265 UsdImagingIndexProxy* index);
266
267 USDIMAGING_API
268 virtual void MarkReprDirty(UsdPrim const& prim,
269 SdfPath const& cachePath,
270 UsdImagingIndexProxy* index);
271
272 USDIMAGING_API
273 virtual void MarkCullStyleDirty(UsdPrim const& prim,
274 SdfPath const& cachePath,
275 UsdImagingIndexProxy* index);
276
277 USDIMAGING_API
278 virtual void MarkRenderTagDirty(UsdPrim const& prim,
279 SdfPath const& cachePath,
280 UsdImagingIndexProxy* index);
281
282 USDIMAGING_API
283 virtual void MarkTransformDirty(UsdPrim const& prim,
284 SdfPath const& cachePath,
285 UsdImagingIndexProxy* index);
286
287 USDIMAGING_API
288 virtual void MarkVisibilityDirty(UsdPrim const& prim,
289 SdfPath const& cachePath,
290 UsdImagingIndexProxy* index);
291
292 USDIMAGING_API
293 virtual void MarkMaterialDirty(UsdPrim const& prim,
294 SdfPath const& cachePath,
295 UsdImagingIndexProxy* index);
296
297 USDIMAGING_API
298 virtual void MarkLightParamsDirty(UsdPrim const& prim,
299 SdfPath const& cachePath,
300 UsdImagingIndexProxy* index);
301
302 USDIMAGING_API
303 virtual void MarkWindowPolicyDirty(UsdPrim const& prim,
304 SdfPath const& cachePath,
305 UsdImagingIndexProxy* index);
306
307 USDIMAGING_API
308 virtual void MarkCollectionsDirty(UsdPrim const& prim,
309 SdfPath const& cachePath,
310 UsdImagingIndexProxy* index);
311
312 // ---------------------------------------------------------------------- //
314 // ---------------------------------------------------------------------- //
315 USDIMAGING_API
316 virtual void InvokeComputation(SdfPath const& cachePath,
317 HdExtComputationContext* context);
318
319 // ---------------------------------------------------------------------- //
321 // ---------------------------------------------------------------------- //
322
324 USDIMAGING_API
325 virtual std::vector<VtArray<TfToken>>
327
330 USDIMAGING_API
332 UsdPrim const& instancerPrim,
333 SdfPath const& instancerPath,
334 UsdTimeCode time) const;
335
338 USDIMAGING_API
340 UsdPrim const& instancerPrim,
341 SdfPath const& instancerPath,
342 UsdTimeCode time,
343 size_t maxNumSamples,
344 float *sampleTimes,
345 GfMatrix4d *sampleValues);
346
348 USDIMAGING_API
350 UsdPrim const& usdPrim,
351 SdfPath const& cachePath) const;
352
354 USDIMAGING_API
355 virtual SdfPathVector GetInstancerPrototypes(
356 UsdPrim const& usdPrim,
357 SdfPath const& cachePath) const;
358
364 USDIMAGING_API
365 virtual size_t
366 SamplePrimvar(UsdPrim const& usdPrim,
367 SdfPath const& cachePath,
368 TfToken const& key,
369 UsdTimeCode time,
370 size_t maxNumSamples,
371 float *sampleTimes,
372 VtValue *sampleValues,
373 VtIntArray *sampleIndices);
374
376 USDIMAGING_API
377 virtual PxOsdSubdivTags GetSubdivTags(UsdPrim const& usdPrim,
378 SdfPath const& cachePath,
379 UsdTimeCode time) const;
380
381 // ---------------------------------------------------------------------- //
383 // ---------------------------------------------------------------------- //
384
385 // NOTE: This method is currently only used by PointInstancer
386 // style instances, and not instanceable-references.
387
391 USDIMAGING_API
393 SdfPath const &instancerPath,
394 SdfPath const &protoInstancerPath,
395 UsdTimeCode time) const;
396
397 // ---------------------------------------------------------------------- //
399 // ---------------------------------------------------------------------- //
400
402 USDIMAGING_API
403 virtual SdfPath GetScenePrimPath(SdfPath const& cachePath,
404 int instanceIndex,
405 HdInstancerContext *instancerCtx) const;
406
407 USDIMAGING_API
408 virtual SdfPathVector GetScenePrimPaths(SdfPath const& cachePath,
409 std::vector<int> const& instanceIndices,
410 std::vector<HdInstancerContext> *instancerCtxs) const;
411
412 // Add the given usdPrim to the HdSelection object, to mark it for
413 // selection highlighting. cachePath is the path of the object referencing
414 // this adapter.
415 //
416 // If an instance index is provided to Delegate::PopulateSelection, it's
417 // interpreted as a hydra instance index and left unchanged (to make
418 // picking/selection round-tripping work). Otherwise, instance adapters
419 // will build up a composite instance index range at each level.
420 //
421 // Consider:
422 // /World/A (2 instances)
423 // /B (2 instances)
424 // /C (gprim)
425 // ... to select /World/A, instance 0, you want to select cartesian
426 // coordinates (0, *) -> (0, 0) and (0, 1). The flattened representation
427 // of this is:
428 // index = coordinate[0] * instance_count[1] + coordinate[1]
429 // Likewise, for one more nesting level you get:
430 // index = c[0] * count[1] * count[2] + c[1] * count[2] + c[2]
431 // ... since the adapter for /World/A has no idea what count[1+] are,
432 // this needs to be built up. The delegate initially sets
433 // parentInstanceIndices to []. /World/A sets this to [0]. /World/A/B,
434 // since it is selecting *, adds all possible instance indices:
435 // 0 * 2 + 0 = 0, 0 * 2 + 1 = 1. /World/A/B/C is a gprim, and adds
436 // instances [0,1] to its selection.
437 USDIMAGING_API
438 virtual bool PopulateSelection(
439 HdSelection::HighlightMode const& highlightMode,
440 SdfPath const &cachePath,
441 UsdPrim const &usdPrim,
442 int const hydraInstanceIndex,
443 VtIntArray const &parentInstanceIndices,
444 HdSelectionSharedPtr const &result) const;
445
446 // ---------------------------------------------------------------------- //
448 // ---------------------------------------------------------------------- //
449
450 USDIMAGING_API
451 virtual HdVolumeFieldDescriptorVector
452 GetVolumeFieldDescriptors(UsdPrim const& usdPrim, SdfPath const &id,
453 UsdTimeCode time) const;
454
455 // ---------------------------------------------------------------------- //
457 // ---------------------------------------------------------------------- //
458
459 USDIMAGING_API
460 virtual VtValue
461 GetVolumeParamValue(
462 const UsdPrim& prim,
463 const SdfPath& cachePath,
464 const TfToken& paramName,
465 UsdTimeCode time) const;
466
467 // ---------------------------------------------------------------------- //
469 // ---------------------------------------------------------------------- //
470
471 USDIMAGING_API
472 virtual VtValue
473 GetLightParamValue(
474 const UsdPrim& prim,
475 const SdfPath& cachePath,
476 const TfToken& paramName,
477 UsdTimeCode time) const;
478
479 // ---------------------------------------------------------------------- //
481 // ---------------------------------------------------------------------- //
482
484 USDIMAGING_API
486
488 USDIMAGING_API
490
491 USDIMAGING_API
492 virtual bool IsChildPath(const SdfPath& path) const;
493
497 USDIMAGING_API
498 virtual bool GetVisible(
499 UsdPrim const& prim,
500 SdfPath const& cachePath,
501 UsdTimeCode time) const;
502
507 USDIMAGING_API
509 UsdPrim const& prim,
510 SdfPath const& cachePath,
511 TfToken const& instanceInheritablePurpose) const;
512
517 USDIMAGING_API
519
523 USDIMAGING_API
524 virtual GfMatrix4d GetTransform(UsdPrim const& prim,
525 SdfPath const& cachePath,
526 UsdTimeCode time,
527 bool ignoreRootTransform = false) const;
528
530 USDIMAGING_API
531 virtual size_t SampleTransform(UsdPrim const& prim,
532 SdfPath const& cachePath,
533 UsdTimeCode time,
534 size_t maxNumSamples,
535 float *sampleTimes,
536 GfMatrix4d *sampleValues);
537
542 USDIMAGING_API
543 virtual VtValue Get(UsdPrim const& prim,
544 SdfPath const& cachePath,
545 TfToken const& key,
546 UsdTimeCode time,
547 VtIntArray *outIndices) const;
548
550 USDIMAGING_API
551 virtual HdCullStyle GetCullStyle(UsdPrim const& prim,
552 SdfPath const& cachePath,
553 UsdTimeCode time) const;
554
557 USDIMAGING_API
559
562 USDIMAGING_API
564
567 USDIMAGING_API
569
575 USDIMAGING_API
577 UsdTimeCode time) const;
578
583 USDIMAGING_API
584 virtual VtValue GetTopology(UsdPrim const& prim,
585 SdfPath const& cachePath,
586 UsdTimeCode time) const;
587
590 USDIMAGING_API
591 virtual GfRange3d GetExtent(UsdPrim const& prim,
592 SdfPath const& cachePath,
593 UsdTimeCode time) const;
594
596 USDIMAGING_API
597 virtual bool GetDoubleSided(UsdPrim const& prim,
598 SdfPath const& cachePath,
599 UsdTimeCode time) const;
600
601 USDIMAGING_API
602 virtual SdfPath GetMaterialId(UsdPrim const& prim,
603 SdfPath const& cachePath,
604 UsdTimeCode time) const;
605
606 USDIMAGING_API
607 virtual VtValue GetMaterialResource(UsdPrim const& prim,
608 SdfPath const& cachePath,
609 UsdTimeCode time) const;
610
611 // ---------------------------------------------------------------------- //
613 // ---------------------------------------------------------------------- //
614 USDIMAGING_API
615 virtual const TfTokenVector &GetExtComputationSceneInputNames(
616 SdfPath const& cachePath) const;
617
618 USDIMAGING_API
619 virtual HdExtComputationInputDescriptorVector
620 GetExtComputationInputs(UsdPrim const& prim,
621 SdfPath const& cachePath,
622 const UsdImagingInstancerContext* instancerContext)
623 const;
624
625 USDIMAGING_API
626 virtual HdExtComputationOutputDescriptorVector
627 GetExtComputationOutputs(UsdPrim const& prim,
628 SdfPath const& cachePath,
629 const UsdImagingInstancerContext* instancerContext)
630 const;
631
632 USDIMAGING_API
633 virtual HdExtComputationPrimvarDescriptorVector
634 GetExtComputationPrimvars(
635 UsdPrim const& prim,
636 SdfPath const& cachePath,
637 HdInterpolation interpolation,
638 const UsdImagingInstancerContext* instancerContext) const;
639
640 USDIMAGING_API
641 virtual VtValue
642 GetExtComputationInput(
643 UsdPrim const& prim,
644 SdfPath const& cachePath,
645 TfToken const& name,
646 UsdTimeCode time,
647 const UsdImagingInstancerContext* instancerContext) const;
648
649 USDIMAGING_API
650 virtual size_t
651 SampleExtComputationInput(
652 UsdPrim const& prim,
653 SdfPath const& cachePath,
654 TfToken const& name,
655 UsdTimeCode time,
656 const UsdImagingInstancerContext* instancerContext,
657 size_t maxSampleCount,
658 float *sampleTimes,
659 VtValue *sampleValues);
660
661 USDIMAGING_API
662 virtual std::string
663 GetExtComputationKernel(
664 UsdPrim const& prim,
665 SdfPath const& cachePath,
666 const UsdImagingInstancerContext* instancerContext) const;
667
668 USDIMAGING_API
669 virtual VtValue
670 GetInstanceIndices(UsdPrim const& instancerPrim,
671 SdfPath const& instancerCachePath,
672 SdfPath const& prototypeCachePath,
673 UsdTimeCode time) const;
674
675 // ---------------------------------------------------------------------- //
677 // ---------------------------------------------------------------------- //
678
680 virtual bool IsSupported(UsdImagingIndexProxy const* index) const
681 {
682 return true;
683 }
684
685 // ---------------------------------------------------------------------- //
687 // ---------------------------------------------------------------------- //
688
690 USDIMAGING_API
692 UsdPrim const& prim,
693 TfToken const& paramName);
694
695protected:
696 friend class UsdImagingInstanceAdapter;
698 // ---------------------------------------------------------------------- //
700 // ---------------------------------------------------------------------- //
701
702 // Given the USD path for a prim of this adapter's type, returns
703 // the prim's Hydra cache path.
704 USDIMAGING_API
705 virtual SdfPath
706 ResolveCachePath(
707 const SdfPath& usdPath,
708 const UsdImagingInstancerContext* instancerContext = nullptr) const;
709
710 using Keys = UsdImagingPrimvarDescCache::Key;
711
712 template <typename T>
713 T _Get(UsdPrim const& prim, TfToken const& attrToken,
714 UsdTimeCode time) const {
715 T value;
716 prim.GetAttribute(attrToken).Get<T>(&value, time);
717 return value;
718 }
719
720 template <typename T>
721 void _GetPtr(UsdPrim const& prim, TfToken const& key, UsdTimeCode time,
722 T* out) const {
723 prim.GetAttribute(key).Get<T>(out, time);
724 }
725
726 USDIMAGING_API
727 UsdImagingPrimvarDescCache* _GetPrimvarDescCache() const;
728
729 USDIMAGING_API
730 UsdImaging_NonlinearSampleCountCache*
731 _GetNonlinearSampleCountCache() const;
732
733 USDIMAGING_API
734 UsdImaging_BlurScaleCache*
735 _GetBlurScaleCache() const;
736
737 USDIMAGING_API
738 UsdPrim _GetPrim(SdfPath const& usdPath) const;
739
740 // Returns the prim adapter for the given \p prim, or an invalid pointer if
741 // no adapter exists. If \p prim is an instance and \p ignoreInstancing
742 // is \c true, the instancing adapter will be ignored and an adapter will
743 // be looked up based on \p prim's type.
744 USDIMAGING_API
745 const UsdImagingPrimAdapterSharedPtr&
746 _GetPrimAdapter(UsdPrim const& prim, bool ignoreInstancing = false) const;
747
748 USDIMAGING_API
749 const UsdImagingPrimAdapterSharedPtr&
750 _GetAdapter(TfToken const& adapterKey) const;
751
752 // XXX: Transitional API
753 // Returns the instance proxy prim path for a USD-instanced prim, given the
754 // instance chain leading to that prim. The paths are sorted from more to
755 // less local; the first path is the prim path (possibly in prototype), then
756 // instance paths (possibly in prototype); the last path is the prim or
757 // instance path in the scene.
758 USDIMAGING_API
759 SdfPath _GetPrimPathFromInstancerChain(
760 SdfPathVector const& instancerChain) const;
761
762 USDIMAGING_API
763 UsdTimeCode _GetTimeWithOffset(float offset) const;
764
765 // Converts \p cachePath to the path in the render index.
766 USDIMAGING_API
767 SdfPath _ConvertCachePathToIndexPath(SdfPath const& cachePath) const;
768
769 // Converts \p indexPath to the path in the USD stage
770 USDIMAGING_API
771 SdfPath _ConvertIndexPathToCachePath(SdfPath const& indexPath) const;
772
773 // Returns the material binding purpose from the renderer delegate.
774 USDIMAGING_API
775 TfToken _GetMaterialBindingPurpose() const;
776
777 // Returns the material contexts from the renderer delegate.
778 USDIMAGING_API
779 TfTokenVector _GetMaterialRenderContexts() const;
780
781 // Returns the namespace prefixes for render settings attributes relevant
782 // to a renderer delegate.
783 USDIMAGING_API
784 TfTokenVector _GetRenderSettingsNamespaces() const;
785
787 USDIMAGING_API
789
791 USDIMAGING_API
793
794 // Returns true if render delegate wants primvars to be filtered based.
795 // This will filter the primvars based on the bound material primvar needs.
796 USDIMAGING_API
797 bool _IsPrimvarFilteringNeeded() const;
798
799 // Returns the shader source type from the render delegate.
800 USDIMAGING_API
801 TfTokenVector _GetShaderSourceTypes() const;
802
803 // Returns \c true if \p usdPath is included in the scene delegate's
804 // invised path list.
805 USDIMAGING_API
806 bool _IsInInvisedPaths(SdfPath const& usdPath) const;
807
808 // Determines if an attribute is varying and if so, sets the given
809 // \p dirtyFlag in the \p dirtyFlags and increments a perf counter. Returns
810 // true if the attribute is varying.
811 //
812 // If \p exists is non-null, _IsVarying will store whether the attribute
813 // was found. If the attribute is not found, it counts as non-varying.
814 //
815 // This only sets the dirty bit, never un-sets. The caller is responsible
816 // for setting the initial state correctly.
817 USDIMAGING_API
818 bool _IsVarying(UsdPrim prim, TfToken const& attrName,
819 HdDirtyBits dirtyFlag, TfToken const& perfToken,
820 HdDirtyBits* dirtyFlags, bool isInherited,
821 bool* exists = nullptr) const;
822
823 // Determines if the prim's transform (CTM) is varying and if so, sets the
824 // given \p dirtyFlag in the \p dirtyFlags and increments a perf counter.
825 // Returns true if the prim's transform is varying.
826 //
827 // This only sets the dirty bit, never un-sets. The caller is responsible
828 // for setting the initial state correctly.
829 USDIMAGING_API
830 bool _IsTransformVarying(UsdPrim prim,
831 HdDirtyBits dirtyFlag,
832 TfToken const& perfToken,
833 HdDirtyBits* dirtyFlags) const;
834
835 // Convenience method for adding or updating a primvar descriptor.
836 // Role defaults to empty token (none). Indexed defaults to false.
837 USDIMAGING_API
838 void _MergePrimvar(
839 HdPrimvarDescriptorVector* vec,
840 TfToken const& name,
841 HdInterpolation interp,
842 TfToken const& role = TfToken(),
843 bool indexed = false) const;
844
845 // Convenience method for removing a primvar descriptor.
846 USDIMAGING_API
847 void _RemovePrimvar(
848 HdPrimvarDescriptorVector* vec,
849 TfToken const& name) const;
850
851 // Convenience method for computing a primvar. The primvar will only be
852 // added to the list of prim desc if there is no primvar of the same
853 // name already present. Thus, "local" primvars should be merged before
854 // inherited primvars.
855 USDIMAGING_API
856 void _ComputeAndMergePrimvar(
857 UsdPrim const& prim,
858 UsdGeomPrimvar const& primvar,
859 UsdTimeCode time,
860 HdPrimvarDescriptorVector* primvarDescs,
861 HdInterpolation *interpOverride = nullptr) const;
862
863 // Returns true if the property name has the "primvars:" prefix.
864 USDIMAGING_API
865 static bool _HasPrimvarsPrefix(TfToken const& propertyName);
866
867 // Convenience methods to figure out what changed about the primvar and
868 // return the appropriate dirty bit.
869 // Caller can optionally pass in a dirty bit to set for primvar value
870 // changes. This is useful for attributes that have a special dirty bit
871 // such as normals and widths.
872 //
873 // Handle USD attributes that are treated as primvars by Hydra. This
874 // requires the interpolation to be passed in, as well as the primvar
875 // name passed to Hydra.
876 USDIMAGING_API
877 HdDirtyBits _ProcessNonPrefixedPrimvarPropertyChange(
878 UsdPrim const& prim,
879 SdfPath const& cachePath,
880 TfToken const& propertyName,
881 TfToken const& primvarName,
882 HdInterpolation const& primvarInterp,
883 HdDirtyBits valueChangeDirtyBit = HdChangeTracker::DirtyPrimvar) const;
884
885 // Handle UsdGeomPrimvars that use the "primvars:" prefix, while also
886 // accommodating inheritance.
887 USDIMAGING_API
888 HdDirtyBits _ProcessPrefixedPrimvarPropertyChange(
889 UsdPrim const& prim,
890 SdfPath const& cachePath,
891 TfToken const& propertyName,
892 HdDirtyBits valueChangeDirtyBit = HdChangeTracker::DirtyPrimvar,
893 bool inherited = true) const;
894
895 virtual void _RemovePrim(SdfPath const& cachePath,
896 UsdImagingIndexProxy* index) = 0;
897
898 // Utility to resync bound dependencies of a particular usd path.
899 // This is necessary for the resync processing of certain prim types
900 // (e.g. materials).
901 USDIMAGING_API
902 void _ResyncDependents(SdfPath const& usdPath,
903 UsdImagingIndexProxy *index);
904
905 USDIMAGING_API
906 UsdImaging_CollectionCache& _GetCollectionCache() const;
907
908 USDIMAGING_API
909 UsdStageRefPtr _GetStage() const;
910
911 USDIMAGING_API
912 UsdImaging_CoordSysBindingStrategy::value_type
913 _GetCoordSysBindings(UsdPrim const& prim) const;
914
915 USDIMAGING_API
916 UsdImaging_InheritedPrimvarStrategy::value_type
917 _GetInheritedPrimvars(UsdPrim const& prim) const;
918
919 // Utility for derived classes to try to find an inherited primvar.
920 USDIMAGING_API
921 UsdGeomPrimvar _GetInheritedPrimvar(UsdPrim const& prim,
922 TfToken const& primvarName) const;
923
924 USDIMAGING_API
925 GfInterval _GetCurrentTimeSamplingInterval();
926
927 USDIMAGING_API
928 Usd_PrimFlagsConjunction _GetDisplayPredicate() const;
929
930 USDIMAGING_API
931 Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes() const;
932
933 USDIMAGING_API
934 bool _DoesDelegateSupportCoordSys() const;
935
936private:
937 UsdImagingDelegate* _delegate;
938};
939
940class UsdImagingPrimAdapterFactoryBase : public TfType::FactoryBase {
941public:
942 virtual UsdImagingPrimAdapterSharedPtr New() const = 0;
943};
944
945template <class T>
946class UsdImagingPrimAdapterFactory : public UsdImagingPrimAdapterFactoryBase {
947public:
948 virtual UsdImagingPrimAdapterSharedPtr New() const
949 {
950 return std::make_shared<T>();
951 }
952};
953
954PXR_NAMESPACE_CLOSE_SCOPE
955
956#endif // PXR_USD_IMAGING_USD_IMAGING_PRIM_ADAPTER_H
A basic mathematical interval class.
Definition: interval.h:33
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
Basic type: 3-dimensional floating point range.
Definition: range3d.h:47
Represents a set of data source locators closed under descendancy.
Interface class that defines the execution environment for the client to run a computation.
HighlightMode
Selection modes allow differentiation in selection highlight behavior.
Definition: selection.h:39
Tags for non-hierarchial subdiv surfaces.
Definition: subdivTags.h:26
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:281
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Base class of all factory types.
Definition: type.h:56
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:183
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Perform value resolution to fetch the value of this attribute at the requested UsdTimeCode time,...
Definition: attribute.h:468
Schema wrapper for UsdAttribute for authoring and introspecting attributes that are primvars.
Definition: primvar.h:248
This class is used as a context object with global stage information, that gets passed down to dataso...
The primary translation layer between the Hydra (Hd) core and the Usd scene graph.
Definition: delegate.h:67
This proxy class exposes a subset of the private Delegate API to PrimAdapters.
Definition: indexProxy.h:30
Delegate support for instanced prims.
Delegate support for UsdGeomPointInstancer.
Base class for all PrimAdapters.
Definition: primAdapter.h:54
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...
USDIMAGING_API SdfPath GetMaterialUsdPath(UsdPrim const &prim) const
Gets the material path for the given prim, walking up namespace if necessary.
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 USDIMAGING_API GfMatrix4d GetTransform(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, bool ignoreRootTransform=false) const
Fetches the transform for the given prim at the given time from a pre-computed cache of prim transfor...
virtual USDIMAGING_API HdCullStyle GetCullStyle(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
Gets the cullstyle of a specific path in the scene graph.
USDIMAGING_API VtArray< VtIntArray > GetPerPrototypeIndices(UsdPrim const &prim, UsdTimeCode time) const
Computes the per-prototype instance indices for a UsdGeomPointInstancer.
USDIMAGING_API HdModelDrawMode GetFullModelDrawMode(UsdPrim const &prim)
Gets the model draw mode object for the given prim, walking up the namespace if necessary.
USDIMAGING_API void SetDelegate(UsdImagingDelegate *delegate)
A thread-local XformCache provided by the delegate.
virtual USDIMAGING_API GfMatrix4d GetRelativeInstancerTransform(SdfPath const &instancerPath, SdfPath const &protoInstancerPath, UsdTimeCode time) const
Returns the transform of protoInstancerPath relative to instancerPath.
virtual USDIMAGING_API size_t SamplePrimvar(UsdPrim const &usdPrim, SdfPath const &cachePath, TfToken const &key, UsdTimeCode time, size_t maxNumSamples, float *sampleTimes, VtValue *sampleValues, VtIntArray *sampleIndices)
Sample the primvar for the given prim.
virtual USDIMAGING_API PopulationMode GetPopulationMode()
Returns the prim's behavior with regard to population and invalidation.
virtual USDIMAGING_API size_t SampleTransform(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, size_t maxNumSamples, float *sampleTimes, GfMatrix4d *sampleValues)
Samples the transform for the given prim.
virtual SdfPath Populate(UsdPrim const &prim, UsdImagingIndexProxy *index, UsdImagingInstancerContext const *instancerContext=nullptr)=0
Called to populate the RenderIndex for this UsdPrim.
virtual USDIMAGING_API SdfPathVector GetInstancerPrototypes(UsdPrim const &usdPrim, SdfPath const &cachePath) const
Return the list of known prototypes of this prim.
virtual USDIMAGING_API GfMatrix4d GetInstancerTransform(UsdPrim const &instancerPrim, SdfPath const &instancerPath, UsdTimeCode time) const
Get the instancer transform for the given prim.
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.
USDIMAGING_API TfToken GetInheritablePurpose(UsdPrim const &prim) const
Returns the purpose token for prim, but only if it is inheritable by child prims (i....
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 bool GetVisible(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
Returns true if the given prim is visible, taking into account inherited visibility values.
virtual USDIMAGING_API std::vector< VtArray< TfToken > > GetInstanceCategories(UsdPrim const &prim)
Return an array of the categories used by each instance.
virtual USDIMAGING_API HdDirtyBits ProcessPrimChange(UsdPrim const &prim, SdfPath const &cachePath, TfTokenVector const &changedFields)
Returns a bit mask of attributes to be updated, or HdChangeTracker::AllDirty if the entire prim must ...
virtual USDIMAGING_API VtValue GetTopology(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
Gets the topology object of a specific Usd prim.
USDIMAGING_API GfMatrix4d GetRootTransform() const
The root transform provided by the delegate.
virtual USDIMAGING_API TfToken GetPurpose(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &instanceInheritablePurpose) const
Returns the purpose token for prim.
static USDIMAGING_API UsdAttribute LookupLightParamAttribute(UsdPrim const &prim, TfToken const &paramName)
Provides to paramName->UsdAttribute value mappings.
virtual bool IsSupported(UsdImagingIndexProxy const *index) const
Returns true if the adapter can be populated into the target index.
Definition: primAdapter.h:680
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 size_t SampleInstancerTransform(UsdPrim const &instancerPrim, SdfPath const &instancerPath, UsdTimeCode time, size_t maxNumSamples, float *sampleTimes, GfMatrix4d *sampleValues)
Sample the instancer transform for the given prim.
USDIMAGING_API bool _GetSceneLightsEnabled() const
Returns whether lights found in the usdscene are enabled.
USDIMAGING_API TfToken GetModelDrawMode(UsdPrim const &prim)
Gets the model:drawMode attribute for the given prim, walking up the namespace if necessary.
virtual USDIMAGING_API HdDataSourceLocatorSet InvalidateImagingSubprimFromDescendent(UsdPrim const &prim, UsdPrim const &descendentPrim, TfToken const &subprim, TfTokenVector const &properties, UsdImagingPropertyInvalidationType invalidationType)
This is called (for each result of GetImagingSubprims) when this adapter's GetScope() result is Repre...
virtual USDIMAGING_API SdfPath GetInstancerId(UsdPrim const &usdPrim, SdfPath const &cachePath) const
Return the instancerId 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.
USDIMAGING_API bool _GetSceneMaterialsEnabled() const
Returns whether custom shading of prims is enabled.
@ RepresentsSelfAndDescendents
The adapter is responsible for USD prims of its registered type as well as any descendents of those p...
Definition: primAdapter.h:98
@ RepresentedByAncestor
Changes to prims of this adapter's registered type are sent to the first ancestor prim whose adapter'...
Definition: primAdapter.h:107
@ RepresentsSelf
The adapter is responsible only for USD prims of its registered type.
Definition: primAdapter.h:92
virtual USDIMAGING_API SdfPath GetScenePrimPath(SdfPath const &cachePath, int instanceIndex, HdInstancerContext *instancerCtx) const
A cache for primvar descriptors.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
USD_API UsdAttribute GetAttribute(const TfToken &attrName) const
Return a UsdAttribute with the name attrName.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:72
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:213
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
Object used by instancer prim adapters to pass along context about the instancer and instance prim to...
Describes optional alternative imaging behavior for prims.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440