Loading...
Searching...
No Matches
primAdapter.h
Go to the documentation of this file.
1//
2// Copyright 2016 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_IMAGING_PRIM_ADAPTER_H
25#define PXR_USD_IMAGING_USD_IMAGING_PRIM_ADAPTER_H
26
28
29#include "pxr/pxr.h"
30#include "pxr/usdImaging/usdImaging/api.h"
31#include "pxr/usdImaging/usdImaging/version.h"
35#include "pxr/usdImaging/usdImaging/types.h"
36
37#include "pxr/imaging/hd/changeTracker.h"
38#include "pxr/imaging/hd/selection.h"
39#include "pxr/usd/sdf/path.h"
40#include "pxr/usd/usd/attribute.h"
41#include "pxr/usd/usd/prim.h"
42#include "pxr/usd/usd/timeCode.h"
43
45
46#include "pxr/base/tf/type.h"
47
48#include <memory>
49
50PXR_NAMESPACE_OPEN_SCOPE
51
52class UsdPrim;
53
54// Forward declaration for nested class.
59
61
62using UsdImagingPrimAdapterSharedPtr =
63 std::shared_ptr<class UsdImagingPrimAdapter>;
64
70 : public std::enable_shared_from_this<UsdImagingPrimAdapter>
71{
72public:
73 USDIMAGING_API
74 virtual ~UsdImagingPrimAdapter() = default;
75
76 // ---------------------------------------------------------------------- //
78 // ---------------------------------------------------------------------- //
79
80 USDIMAGING_API
81 virtual TfTokenVector GetImagingSubprims(UsdPrim const& prim);
82
83 USDIMAGING_API
84 virtual TfToken GetImagingSubprimType(
85 UsdPrim const& prim, TfToken const& subprim);
86
87 USDIMAGING_API
88 virtual HdContainerDataSourceHandle GetImagingSubprimData(
89 UsdPrim const& prim,
90 TfToken const& subprim,
91 const UsdImagingDataSourceStageGlobals &stageGlobals);
92
93 USDIMAGING_API
94 virtual HdDataSourceLocatorSet InvalidateImagingSubprim(
95 UsdPrim const& prim,
96 TfToken const& subprim,
97 TfTokenVector const& properties,
98 UsdImagingPropertyInvalidationType invalidationType);
99
106 {
110
116
125 };
126
129 USDIMAGING_API
131
136 USDIMAGING_API
138 UsdPrim const& prim,
139 UsdPrim const& descendentPrim,
140 TfToken const& subprim,
141 TfTokenVector const& properties,
142 UsdImagingPropertyInvalidationType invalidationType);
143
144 // ---------------------------------------------------------------------- //
146 // ---------------------------------------------------------------------- //
147
151 virtual SdfPath Populate(UsdPrim const& prim,
154 instancerContext = nullptr) = 0;
155
156 // Indicates whether population traversal should be pruned based on
157 // prim-specific features (like whether it's imageable).
158 USDIMAGING_API
159 static bool ShouldCullSubtree(UsdPrim const& prim);
160
161 // Indicates whether population traversal should be pruned based on
162 // adapter-specific features (like whether the adapter is an instance
163 // adapter, and wants to do its own population).
164 USDIMAGING_API
165 virtual bool ShouldCullChildren() const;
166
167 // Indicates whether or not native USD prim instancing should be ignored
168 // for prims using this delegate, along with their descendants.
169 USDIMAGING_API
170 virtual bool ShouldIgnoreNativeInstanceSubtrees() const;
171
172 // Indicates the adapter is a multiplexing adapter (e.g. PointInstancer),
173 // potentially managing its children. This flag is used in nested
174 // instancer cases to determine which adapter is assigned to which prim.
175 USDIMAGING_API
176 virtual bool IsInstancerAdapter() const;
177
178 // Indicates whether this adapter can directly populate USD instance prims.
179 //
180 // Normally, with USD instances, we make a firewall between the instance
181 // prim and the USD prototype tree. The instance adapter creates one
182 // hydra prototype per prim in the USD prototype tree, shared by all USD
183 // instances; this lets us recognize the benefits of instancing,
184 // by hopefully having a high instance count per prototype. The instance
185 // adapter additionally configures a hydra instancer for the prototype tree;
186 // and a small set of specially-handled data is allowed through: things like
187 // inherited constant primvars, transforms, visibility, and other things
188 // we know how to vary per-instance.
189 //
190 // We enforce the above policy by refusing to populate gprims which are
191 // USD instances, since we'd need one prototype per instance and would lose
192 // any instancing benefit.
193 //
194 // There are a handful of times when it really is useful to directly
195 // populate instance prims: for example, instances with cards applied,
196 // or instances of type UsdSkelRoot. In those cases, the adapters can
197 // opt into this scheme with "CanPopulateUsdInstance".
198 //
199 // Note that any adapters taking advantage of this feature will need
200 // extensive code support in instanceAdapter: the instance adapter will
201 // need to potentially create and track multiple hydra prototypes per
202 // USD prototype, and the adapter will need special handling to pass down
203 // any relevant instance-varying data.
204 //
205 // In summary: use with caution.
206 USDIMAGING_API
207 virtual bool CanPopulateUsdInstance() const;
208
209 // ---------------------------------------------------------------------- //
211 // ---------------------------------------------------------------------- //
212
218 virtual void TrackVariability(UsdPrim const& prim,
219 SdfPath const& cachePath,
220 HdDirtyBits* timeVaryingBits,
222 instancerContext = nullptr) const = 0;
223
228 virtual void UpdateForTime(UsdPrim const& prim,
229 SdfPath const& cachePath,
230 UsdTimeCode time,
231 HdDirtyBits requestedBits,
233 instancerContext = nullptr) const = 0;
234
235 // ---------------------------------------------------------------------- //
237 // ---------------------------------------------------------------------- //
238
249 USDIMAGING_API
250 virtual HdDirtyBits ProcessPrimChange(UsdPrim const& prim,
251 SdfPath const& cachePath,
252 TfTokenVector const& changedFields);
253
256 virtual HdDirtyBits ProcessPropertyChange(UsdPrim const& prim,
257 SdfPath const& cachePath,
258 TfToken const& propertyName) = 0;
259
263 USDIMAGING_API
264 virtual void ProcessPrimResync(SdfPath const& cachePath,
265 UsdImagingIndexProxy* index);
266
269 USDIMAGING_API
270 virtual void ProcessPrimRemoval(SdfPath const& cachePath,
271 UsdImagingIndexProxy* index);
272
273
274 virtual void MarkDirty(UsdPrim const& prim,
275 SdfPath const& cachePath,
276 HdDirtyBits dirty,
277 UsdImagingIndexProxy* index) = 0;
278
279 USDIMAGING_API
280 virtual void MarkRefineLevelDirty(UsdPrim const& prim,
281 SdfPath const& cachePath,
282 UsdImagingIndexProxy* index);
283
284 USDIMAGING_API
285 virtual void MarkReprDirty(UsdPrim const& prim,
286 SdfPath const& cachePath,
287 UsdImagingIndexProxy* index);
288
289 USDIMAGING_API
290 virtual void MarkCullStyleDirty(UsdPrim const& prim,
291 SdfPath const& cachePath,
292 UsdImagingIndexProxy* index);
293
294 USDIMAGING_API
295 virtual void MarkRenderTagDirty(UsdPrim const& prim,
296 SdfPath const& cachePath,
297 UsdImagingIndexProxy* index);
298
299 USDIMAGING_API
300 virtual void MarkTransformDirty(UsdPrim const& prim,
301 SdfPath const& cachePath,
302 UsdImagingIndexProxy* index);
303
304 USDIMAGING_API
305 virtual void MarkVisibilityDirty(UsdPrim const& prim,
306 SdfPath const& cachePath,
307 UsdImagingIndexProxy* index);
308
309 USDIMAGING_API
310 virtual void MarkMaterialDirty(UsdPrim const& prim,
311 SdfPath const& cachePath,
312 UsdImagingIndexProxy* index);
313
314 USDIMAGING_API
315 virtual void MarkLightParamsDirty(UsdPrim const& prim,
316 SdfPath const& cachePath,
317 UsdImagingIndexProxy* index);
318
319 USDIMAGING_API
320 virtual void MarkWindowPolicyDirty(UsdPrim const& prim,
321 SdfPath const& cachePath,
322 UsdImagingIndexProxy* index);
323
324 USDIMAGING_API
325 virtual void MarkCollectionsDirty(UsdPrim const& prim,
326 SdfPath const& cachePath,
327 UsdImagingIndexProxy* index);
328
329 // ---------------------------------------------------------------------- //
331 // ---------------------------------------------------------------------- //
332 USDIMAGING_API
333 virtual void InvokeComputation(SdfPath const& cachePath,
334 HdExtComputationContext* context);
335
336 // ---------------------------------------------------------------------- //
338 // ---------------------------------------------------------------------- //
339
341 USDIMAGING_API
342 virtual std::vector<VtArray<TfToken>>
344
347 USDIMAGING_API
349 UsdPrim const& instancerPrim,
350 SdfPath const& instancerPath,
351 UsdTimeCode time) const;
352
355 USDIMAGING_API
357 UsdPrim const& instancerPrim,
358 SdfPath const& instancerPath,
359 UsdTimeCode time,
360 size_t maxNumSamples,
361 float *sampleTimes,
362 GfMatrix4d *sampleValues);
363
365 USDIMAGING_API
367 UsdPrim const& usdPrim,
368 SdfPath const& cachePath) const;
369
371 USDIMAGING_API
372 virtual SdfPathVector GetInstancerPrototypes(
373 UsdPrim const& usdPrim,
374 SdfPath const& cachePath) const;
375
381 USDIMAGING_API
382 virtual size_t
383 SamplePrimvar(UsdPrim const& usdPrim,
384 SdfPath const& cachePath,
385 TfToken const& key,
386 UsdTimeCode time,
387 size_t maxNumSamples,
388 float *sampleTimes,
389 VtValue *sampleValues,
390 VtIntArray *sampleIndices);
391
393 USDIMAGING_API
394 virtual PxOsdSubdivTags GetSubdivTags(UsdPrim const& usdPrim,
395 SdfPath const& cachePath,
396 UsdTimeCode time) const;
397
398 // ---------------------------------------------------------------------- //
400 // ---------------------------------------------------------------------- //
401
402 // NOTE: This method is currently only used by PointInstancer
403 // style instances, and not instanceable-references.
404
408 USDIMAGING_API
410 SdfPath const &instancerPath,
411 SdfPath const &protoInstancerPath,
412 UsdTimeCode time) const;
413
414 // ---------------------------------------------------------------------- //
416 // ---------------------------------------------------------------------- //
417
419 USDIMAGING_API
420 virtual SdfPath GetScenePrimPath(SdfPath const& cachePath,
421 int instanceIndex,
422 HdInstancerContext *instancerCtx) const;
423
424 USDIMAGING_API
425 virtual SdfPathVector GetScenePrimPaths(SdfPath const& cachePath,
426 std::vector<int> const& instanceIndices,
427 std::vector<HdInstancerContext> *instancerCtxs) const;
428
429 // Add the given usdPrim to the HdSelection object, to mark it for
430 // selection highlighting. cachePath is the path of the object referencing
431 // this adapter.
432 //
433 // If an instance index is provided to Delegate::PopulateSelection, it's
434 // interpreted as a hydra instance index and left unchanged (to make
435 // picking/selection round-tripping work). Otherwise, instance adapters
436 // will build up a composite instance index range at each level.
437 //
438 // Consider:
439 // /World/A (2 instances)
440 // /B (2 instances)
441 // /C (gprim)
442 // ... to select /World/A, instance 0, you want to select cartesian
443 // coordinates (0, *) -> (0, 0) and (0, 1). The flattened representation
444 // of this is:
445 // index = coordinate[0] * instance_count[1] + coordinate[1]
446 // Likewise, for one more nesting level you get:
447 // index = c[0] * count[1] * count[2] + c[1] * count[2] + c[2]
448 // ... since the adapter for /World/A has no idea what count[1+] are,
449 // this needs to be built up. The delegate initially sets
450 // parentInstanceIndices to []. /World/A sets this to [0]. /World/A/B,
451 // since it is selecting *, adds all possible instance indices:
452 // 0 * 2 + 0 = 0, 0 * 2 + 1 = 1. /World/A/B/C is a gprim, and adds
453 // instances [0,1] to its selection.
454 USDIMAGING_API
455 virtual bool PopulateSelection(
456 HdSelection::HighlightMode const& highlightMode,
457 SdfPath const &cachePath,
458 UsdPrim const &usdPrim,
459 int const hydraInstanceIndex,
460 VtIntArray const &parentInstanceIndices,
461 HdSelectionSharedPtr const &result) const;
462
463 // ---------------------------------------------------------------------- //
465 // ---------------------------------------------------------------------- //
466
467 USDIMAGING_API
468 virtual HdVolumeFieldDescriptorVector
469 GetVolumeFieldDescriptors(UsdPrim const& usdPrim, SdfPath const &id,
470 UsdTimeCode time) const;
471
472 // ---------------------------------------------------------------------- //
474 // ---------------------------------------------------------------------- //
475
476 USDIMAGING_API
477 virtual VtValue
478 GetLightParamValue(
479 const UsdPrim& prim,
480 const SdfPath& cachePath,
481 const TfToken& paramName,
482 UsdTimeCode time) const;
483
484 // ---------------------------------------------------------------------- //
486 // ---------------------------------------------------------------------- //
487
489 USDIMAGING_API
491
493 USDIMAGING_API
495
496 USDIMAGING_API
497 bool IsChildPath(SdfPath const& path) const;
498
502 USDIMAGING_API
503 virtual bool GetVisible(
504 UsdPrim const& prim,
505 SdfPath const& cachePath,
506 UsdTimeCode time) const;
507
512 USDIMAGING_API
514 UsdPrim const& prim,
515 SdfPath const& cachePath,
516 TfToken const& instanceInheritablePurpose) const;
517
522 USDIMAGING_API
524
528 USDIMAGING_API
529 virtual GfMatrix4d GetTransform(UsdPrim const& prim,
530 SdfPath const& cachePath,
531 UsdTimeCode time,
532 bool ignoreRootTransform = false) const;
533
535 USDIMAGING_API
536 virtual size_t SampleTransform(UsdPrim const& prim,
537 SdfPath const& cachePath,
538 UsdTimeCode time,
539 size_t maxNumSamples,
540 float *sampleTimes,
541 GfMatrix4d *sampleValues);
542
547 USDIMAGING_API
548 virtual VtValue Get(UsdPrim const& prim,
549 SdfPath const& cachePath,
550 TfToken const& key,
551 UsdTimeCode time,
552 VtIntArray *outIndices) const;
553
555 USDIMAGING_API
556 virtual HdCullStyle GetCullStyle(UsdPrim const& prim,
557 SdfPath const& cachePath,
558 UsdTimeCode time) const;
559
562 USDIMAGING_API
564
567 USDIMAGING_API
569
572 USDIMAGING_API
574
580 USDIMAGING_API
582 UsdTimeCode time) const;
583
588 USDIMAGING_API
589 virtual VtValue GetTopology(UsdPrim const& prim,
590 SdfPath const& cachePath,
591 UsdTimeCode time) const;
592
595 USDIMAGING_API
596 virtual GfRange3d GetExtent(UsdPrim const& prim,
597 SdfPath const& cachePath,
598 UsdTimeCode time) const;
599
601 USDIMAGING_API
602 virtual bool GetDoubleSided(UsdPrim const& prim,
603 SdfPath const& cachePath,
604 UsdTimeCode time) const;
605
606 USDIMAGING_API
607 virtual SdfPath GetMaterialId(UsdPrim const& prim,
608 SdfPath const& cachePath,
609 UsdTimeCode time) const;
610
611 USDIMAGING_API
612 virtual VtValue GetMaterialResource(UsdPrim const& prim,
613 SdfPath const& cachePath,
614 UsdTimeCode time) const;
615
616 // ---------------------------------------------------------------------- //
618 // ---------------------------------------------------------------------- //
619 USDIMAGING_API
620 virtual const TfTokenVector &GetExtComputationSceneInputNames(
621 SdfPath const& cachePath) const;
622
623 USDIMAGING_API
624 virtual HdExtComputationInputDescriptorVector
625 GetExtComputationInputs(UsdPrim const& prim,
626 SdfPath const& cachePath,
627 const UsdImagingInstancerContext* instancerContext)
628 const;
629
630 USDIMAGING_API
631 virtual HdExtComputationOutputDescriptorVector
632 GetExtComputationOutputs(UsdPrim const& prim,
633 SdfPath const& cachePath,
634 const UsdImagingInstancerContext* instancerContext)
635 const;
636
637 USDIMAGING_API
638 virtual HdExtComputationPrimvarDescriptorVector
639 GetExtComputationPrimvars(
640 UsdPrim const& prim,
641 SdfPath const& cachePath,
642 HdInterpolation interpolation,
643 const UsdImagingInstancerContext* instancerContext) const;
644
645 USDIMAGING_API
646 virtual VtValue
647 GetExtComputationInput(
648 UsdPrim const& prim,
649 SdfPath const& cachePath,
650 TfToken const& name,
651 UsdTimeCode time,
652 const UsdImagingInstancerContext* instancerContext) const;
653
654 USDIMAGING_API
655 virtual size_t
656 SampleExtComputationInput(
657 UsdPrim const& prim,
658 SdfPath const& cachePath,
659 TfToken const& name,
660 UsdTimeCode time,
661 const UsdImagingInstancerContext* instancerContext,
662 size_t maxSampleCount,
663 float *sampleTimes,
664 VtValue *sampleValues);
665
666 USDIMAGING_API
667 virtual std::string
668 GetExtComputationKernel(
669 UsdPrim const& prim,
670 SdfPath const& cachePath,
671 const UsdImagingInstancerContext* instancerContext) const;
672
673 USDIMAGING_API
674 virtual VtValue
675 GetInstanceIndices(UsdPrim const& instancerPrim,
676 SdfPath const& instancerCachePath,
677 SdfPath const& prototypeCachePath,
678 UsdTimeCode time) const;
679
680 // ---------------------------------------------------------------------- //
682 // ---------------------------------------------------------------------- //
683
685 virtual bool IsSupported(UsdImagingIndexProxy const* index) const
686 {
687 return true;
688 }
689
690 // ---------------------------------------------------------------------- //
692 // ---------------------------------------------------------------------- //
693
695 USDIMAGING_API
697 UsdPrim const& prim,
698 TfToken const& paramName);
699
700protected:
701 friend class UsdImagingInstanceAdapter;
703 // ---------------------------------------------------------------------- //
705 // ---------------------------------------------------------------------- //
706
707 // Given the USD path for a prim of this adapter's type, returns
708 // the prim's Hydra cache path.
709 USDIMAGING_API
710 virtual SdfPath
711 ResolveCachePath(
712 const SdfPath& usdPath,
713 const UsdImagingInstancerContext* instancerContext = nullptr) const;
714
715 using Keys = UsdImagingPrimvarDescCache::Key;
716
717 template <typename T>
718 T _Get(UsdPrim const& prim, TfToken const& attrToken,
719 UsdTimeCode time) const {
720 T value;
721 prim.GetAttribute(attrToken).Get<T>(&value, time);
722 return value;
723 }
724
725 template <typename T>
726 void _GetPtr(UsdPrim const& prim, TfToken const& key, UsdTimeCode time,
727 T* out) const {
728 prim.GetAttribute(key).Get<T>(out, time);
729 }
730
731 USDIMAGING_API
732 UsdImagingPrimvarDescCache* _GetPrimvarDescCache() const;
733
734 USDIMAGING_API
735 UsdImaging_NonlinearSampleCountCache*
736 _GetNonlinearSampleCountCache() const;
737
738 USDIMAGING_API
739 UsdImaging_BlurScaleCache*
740 _GetBlurScaleCache() const;
741
742 USDIMAGING_API
743 UsdPrim _GetPrim(SdfPath const& usdPath) const;
744
745 // Returns the prim adapter for the given \p prim, or an invalid pointer if
746 // no adapter exists. If \p prim is an instance and \p ignoreInstancing
747 // is \c true, the instancing adapter will be ignored and an adapter will
748 // be looked up based on \p prim's type.
749 USDIMAGING_API
750 const UsdImagingPrimAdapterSharedPtr&
751 _GetPrimAdapter(UsdPrim const& prim, bool ignoreInstancing = false) const;
752
753 USDIMAGING_API
754 const UsdImagingPrimAdapterSharedPtr&
755 _GetAdapter(TfToken const& adapterKey) const;
756
757 // XXX: Transitional API
758 // Returns the instance proxy prim path for a USD-instanced prim, given the
759 // instance chain leading to that prim. The paths are sorted from more to
760 // less local; the first path is the prim path (possibly in prototype), then
761 // instance paths (possibly in prototype); the last path is the prim or
762 // instance path in the scene.
763 USDIMAGING_API
764 SdfPath _GetPrimPathFromInstancerChain(
765 SdfPathVector const& instancerChain) const;
766
767 USDIMAGING_API
768 UsdTimeCode _GetTimeWithOffset(float offset) const;
769
770 // Converts \p cachePath to the path in the render index.
771 USDIMAGING_API
772 SdfPath _ConvertCachePathToIndexPath(SdfPath const& cachePath) const;
773
774 // Converts \p indexPath to the path in the USD stage
775 USDIMAGING_API
776 SdfPath _ConvertIndexPathToCachePath(SdfPath const& indexPath) const;
777
778 // Returns the material binding purpose from the renderer delegate.
779 USDIMAGING_API
780 TfToken _GetMaterialBindingPurpose() const;
781
782 // Returns the material contexts from the renderer delegate.
783 USDIMAGING_API
784 TfTokenVector _GetMaterialRenderContexts() const;
785
786 // Returns the namespace prefixes for render settings attributes relevant
787 // to a renderer delegate.
788 USDIMAGING_API
789 TfTokenVector _GetRenderSettingsNamespaces() const;
790
792 USDIMAGING_API
794
796 USDIMAGING_API
798
799 // Returns true if render delegate wants primvars to be filtered based.
800 // This will filter the primvars based on the bound material primvar needs.
801 USDIMAGING_API
802 bool _IsPrimvarFilteringNeeded() const;
803
804 // Returns the shader source type from the render delegate.
805 USDIMAGING_API
806 TfTokenVector _GetShaderSourceTypes() const;
807
808 // Returns \c true if \p usdPath is included in the scene delegate's
809 // invised path list.
810 USDIMAGING_API
811 bool _IsInInvisedPaths(SdfPath const& usdPath) const;
812
813 // Determines if an attribute is varying and if so, sets the given
814 // \p dirtyFlag in the \p dirtyFlags and increments a perf counter. Returns
815 // true if the attribute is varying.
816 //
817 // If \p exists is non-null, _IsVarying will store whether the attribute
818 // was found. If the attribute is not found, it counts as non-varying.
819 //
820 // This only sets the dirty bit, never un-sets. The caller is responsible
821 // for setting the initial state correctly.
822 USDIMAGING_API
823 bool _IsVarying(UsdPrim prim, TfToken const& attrName,
824 HdDirtyBits dirtyFlag, TfToken const& perfToken,
825 HdDirtyBits* dirtyFlags, bool isInherited,
826 bool* exists = nullptr) const;
827
828 // Determines if the prim's transform (CTM) is varying and if so, sets the
829 // given \p dirtyFlag in the \p dirtyFlags and increments a perf counter.
830 // Returns true if the prim's transform is varying.
831 //
832 // This only sets the dirty bit, never un-sets. The caller is responsible
833 // for setting the initial state correctly.
834 USDIMAGING_API
835 bool _IsTransformVarying(UsdPrim prim,
836 HdDirtyBits dirtyFlag,
837 TfToken const& perfToken,
838 HdDirtyBits* dirtyFlags) const;
839
840 // Convenience method for adding or updating a primvar descriptor.
841 // Role defaults to empty token (none). Indexed defaults to false.
842 USDIMAGING_API
843 void _MergePrimvar(
844 HdPrimvarDescriptorVector* vec,
845 TfToken const& name,
846 HdInterpolation interp,
847 TfToken const& role = TfToken(),
848 bool indexed = false) const;
849
850 // Convenience method for removing a primvar descriptor.
851 USDIMAGING_API
852 void _RemovePrimvar(
853 HdPrimvarDescriptorVector* vec,
854 TfToken const& name) const;
855
856 // Convenience method for computing a primvar. The primvar will only be
857 // added to the list of prim desc if there is no primvar of the same
858 // name already present. Thus, "local" primvars should be merged before
859 // inherited primvars.
860 USDIMAGING_API
861 void _ComputeAndMergePrimvar(
862 UsdPrim const& prim,
863 UsdGeomPrimvar const& primvar,
864 UsdTimeCode time,
865 HdPrimvarDescriptorVector* primvarDescs,
866 HdInterpolation *interpOverride = nullptr) const;
867
868 // Returns true if the property name has the "primvars:" prefix.
869 USDIMAGING_API
870 static bool _HasPrimvarsPrefix(TfToken const& propertyName);
871
872 // Convenience methods to figure out what changed about the primvar and
873 // return the appropriate dirty bit.
874 // Caller can optionally pass in a dirty bit to set for primvar value
875 // changes. This is useful for attributes that have a special dirty bit
876 // such as normals and widths.
877 //
878 // Handle USD attributes that are treated as primvars by Hydra. This
879 // requires the interpolation to be passed in, as well as the primvar
880 // name passed to Hydra.
881 USDIMAGING_API
882 HdDirtyBits _ProcessNonPrefixedPrimvarPropertyChange(
883 UsdPrim const& prim,
884 SdfPath const& cachePath,
885 TfToken const& propertyName,
886 TfToken const& primvarName,
887 HdInterpolation const& primvarInterp,
888 HdDirtyBits valueChangeDirtyBit = HdChangeTracker::DirtyPrimvar) const;
889
890 // Handle UsdGeomPrimvars that use the "primvars:" prefix, while also
891 // accommodating inheritance.
892 USDIMAGING_API
893 HdDirtyBits _ProcessPrefixedPrimvarPropertyChange(
894 UsdPrim const& prim,
895 SdfPath const& cachePath,
896 TfToken const& propertyName,
897 HdDirtyBits valueChangeDirtyBit = HdChangeTracker::DirtyPrimvar,
898 bool inherited = true) const;
899
900 virtual void _RemovePrim(SdfPath const& cachePath,
901 UsdImagingIndexProxy* index) = 0;
902
903 // Utility to resync bound dependencies of a particular usd path.
904 // This is necessary for the resync processing of certain prim types
905 // (e.g. materials).
906 USDIMAGING_API
907 void _ResyncDependents(SdfPath const& usdPath,
908 UsdImagingIndexProxy *index);
909
910 USDIMAGING_API
911 UsdImaging_CollectionCache& _GetCollectionCache() const;
912
913 USDIMAGING_API
914 UsdStageRefPtr _GetStage() const;
915
916 USDIMAGING_API
917 UsdImaging_CoordSysBindingStrategy::value_type
918 _GetCoordSysBindings(UsdPrim const& prim) const;
919
920 USDIMAGING_API
921 UsdImaging_InheritedPrimvarStrategy::value_type
922 _GetInheritedPrimvars(UsdPrim const& prim) const;
923
924 // Utility for derived classes to try to find an inherited primvar.
925 USDIMAGING_API
926 UsdGeomPrimvar _GetInheritedPrimvar(UsdPrim const& prim,
927 TfToken const& primvarName) const;
928
929 USDIMAGING_API
930 GfInterval _GetCurrentTimeSamplingInterval();
931
932 USDIMAGING_API
933 Usd_PrimFlagsConjunction _GetDisplayPredicate() const;
934
935 USDIMAGING_API
936 Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes() const;
937
938 USDIMAGING_API
939 bool _DoesDelegateSupportCoordSys() const;
940
941private:
942 UsdImagingDelegate* _delegate;
943};
944
945class UsdImagingPrimAdapterFactoryBase : public TfType::FactoryBase {
946public:
947 virtual UsdImagingPrimAdapterSharedPtr New() const = 0;
948};
949
950template <class T>
951class UsdImagingPrimAdapterFactory : public UsdImagingPrimAdapterFactoryBase {
952public:
953 virtual UsdImagingPrimAdapterSharedPtr New() const
954 {
955 return std::make_shared<T>();
956 }
957};
958
959PXR_NAMESPACE_CLOSE_SCOPE
960
961#endif // PXR_USD_IMAGING_USD_IMAGING_PRIM_ADAPTER_H
A basic mathematical interval class.
Definition: interval.h:50
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
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:56
Tags for non-hierarchial subdiv surfaces.
Definition: subdivTags.h:43
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Base class of all factory types.
Definition: type.h:73
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:176
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:436
Schema wrapper for UsdAttribute for authoring and introspecting attributes that are primvars.
Definition: primvar.h:262
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:84
This proxy class exposes a subset of the private Delegate API to PrimAdapters.
Definition: indexProxy.h:47
Delegate support for instanced prims.
Delegate support for UsdGeomPointInstancer.
Base class for all PrimAdapters.
Definition: primAdapter.h:71
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:685
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:115
@ RepresentedByAncestor
Changes to prims of this adapter's registered type are sent to the first ancestor prim whose adapter'...
Definition: primAdapter.h:124
@ RepresentsSelf
The adapter is responsible only for USD prims of its registered type.
Definition: primAdapter.h:109
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:134
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:84
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:228
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...
Describes optional alternative imaging behavior for prims.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457