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 
36 #include "pxr/imaging/hd/changeTracker.h"
37 #include "pxr/imaging/hd/selection.h"
38 #include "pxr/usd/usd/attribute.h"
39 #include "pxr/usd/usd/prim.h"
40 #include "pxr/usd/usd/timeCode.h"
41 
43 
44 #include "pxr/base/tf/type.h"
45 
46 #include <memory>
47 
48 PXR_NAMESPACE_OPEN_SCOPE
49 
50 class UsdPrim;
51 
52 // Forward declaration for nested class.
53 class UsdImagingDelegate;
57 
59 
60 using UsdImagingPrimAdapterSharedPtr =
61  std::shared_ptr<class UsdImagingPrimAdapter>;
62 
68  : public std::enable_shared_from_this<UsdImagingPrimAdapter>
69 {
70 public:
71 
73  {}
74 
75  USDIMAGING_API
76  virtual ~UsdImagingPrimAdapter();
77 
78  // ---------------------------------------------------------------------- //
80  // ---------------------------------------------------------------------- //
81 
82  USDIMAGING_API
83  virtual TfTokenVector GetImagingSubprims();
84 
85  USDIMAGING_API
86  virtual TfToken GetImagingSubprimType(TfToken const& subprim);
87 
88  USDIMAGING_API
89  virtual HdContainerDataSourceHandle GetImagingSubprimData(
90  TfToken const& subprim,
91  UsdPrim const& prim,
92  const UsdImagingDataSourceStageGlobals &stageGlobals);
93 
94  USDIMAGING_API
95  virtual HdDataSourceLocatorSet InvalidateImagingSubprim(
96  TfToken const& subprim,
97  TfTokenVector const& properties);
98 
99  // ---------------------------------------------------------------------- //
101  // ---------------------------------------------------------------------- //
102 
106  virtual SdfPath Populate(UsdPrim const& prim,
107  UsdImagingIndexProxy* index,
109  instancerContext = nullptr) = 0;
110 
111  // Indicates whether population traversal should be pruned based on
112  // prim-specific features (like whether it's imageable).
113  USDIMAGING_API
114  static bool ShouldCullSubtree(UsdPrim const& prim);
115 
116  // Indicates whether population traversal should be pruned based on
117  // adapter-specific features (like whether the adapter is an instance
118  // adapter, and wants to do its own population).
119  USDIMAGING_API
120  virtual bool ShouldCullChildren() const;
121 
122  // Indicates whether or not native USD prim instancing should be ignored
123  // for prims using this delegate, along with their descendants.
124  USDIMAGING_API
125  virtual bool ShouldIgnoreNativeInstanceSubtrees() const;
126 
127  // Indicates the adapter is a multiplexing adapter (e.g. PointInstancer),
128  // potentially managing its children. This flag is used in nested
129  // instancer cases to determine which adapter is assigned to which prim.
130  USDIMAGING_API
131  virtual bool IsInstancerAdapter() const;
132 
133  // Indicates whether this adapter can directly populate USD instance prims.
134  //
135  // Normally, with USD instances, we make a firewall between the instance
136  // prim and the USD prototype tree. The instance adapter creates one
137  // hydra prototype per prim in the USD prototype tree, shared by all USD
138  // instances; this lets us recognize the benefits of instancing,
139  // by hopefully having a high instance count per prototype. The instance
140  // adapter additionally configures a hydra instancer for the prototype tree;
141  // and a small set of specially-handled data is allowed through: things like
142  // inherited constant primvars, transforms, visibility, and other things
143  // we know how to vary per-instance.
144  //
145  // We enforce the above policy by refusing to populate gprims which are
146  // USD instances, since we'd need one prototype per instance and would lose
147  // any instancing benefit.
148  //
149  // There are a handful of times when it really is useful to directly
150  // populate instance prims: for example, instances with cards applied,
151  // or instances of type UsdSkelRoot. In those cases, the adapters can
152  // opt into this scheme with "CanPopulateUsdInstance".
153  //
154  // Note that any adapters taking advantage of this feature will need
155  // extensive code support in instanceAdapter: the instance adapter will
156  // need to potentially create and track multiple hydra prototypes per
157  // USD prototype, and the adapter will need special handling to pass down
158  // any relevant instance-varying data.
159  //
160  // In summary: use with caution.
161  USDIMAGING_API
162  virtual bool CanPopulateUsdInstance() const;
163 
164  // ---------------------------------------------------------------------- //
166  // ---------------------------------------------------------------------- //
167 
173  virtual void TrackVariability(UsdPrim const& prim,
174  SdfPath const& cachePath,
175  HdDirtyBits* timeVaryingBits,
177  instancerContext = nullptr) const = 0;
178 
183  virtual void UpdateForTime(UsdPrim const& prim,
184  SdfPath const& cachePath,
185  UsdTimeCode time,
186  HdDirtyBits requestedBits,
188  instancerContext = nullptr) const = 0;
189 
190  // ---------------------------------------------------------------------- //
192  // ---------------------------------------------------------------------- //
193 
204  USDIMAGING_API
205  virtual HdDirtyBits ProcessPrimChange(UsdPrim const& prim,
206  SdfPath const& cachePath,
207  TfTokenVector const& changedFields);
208 
211  virtual HdDirtyBits ProcessPropertyChange(UsdPrim const& prim,
212  SdfPath const& cachePath,
213  TfToken const& propertyName) = 0;
214 
218  USDIMAGING_API
219  virtual void ProcessPrimResync(SdfPath const& cachePath,
220  UsdImagingIndexProxy* index);
221 
224  USDIMAGING_API
225  virtual void ProcessPrimRemoval(SdfPath const& cachePath,
226  UsdImagingIndexProxy* index);
227 
228 
229  virtual void MarkDirty(UsdPrim const& prim,
230  SdfPath const& cachePath,
231  HdDirtyBits dirty,
232  UsdImagingIndexProxy* index) = 0;
233 
234  USDIMAGING_API
235  virtual void MarkRefineLevelDirty(UsdPrim const& prim,
236  SdfPath const& cachePath,
237  UsdImagingIndexProxy* index);
238 
239  USDIMAGING_API
240  virtual void MarkReprDirty(UsdPrim const& prim,
241  SdfPath const& cachePath,
242  UsdImagingIndexProxy* index);
243 
244  USDIMAGING_API
245  virtual void MarkCullStyleDirty(UsdPrim const& prim,
246  SdfPath const& cachePath,
247  UsdImagingIndexProxy* index);
248 
249  USDIMAGING_API
250  virtual void MarkRenderTagDirty(UsdPrim const& prim,
251  SdfPath const& cachePath,
252  UsdImagingIndexProxy* index);
253 
254  USDIMAGING_API
255  virtual void MarkTransformDirty(UsdPrim const& prim,
256  SdfPath const& cachePath,
257  UsdImagingIndexProxy* index);
258 
259  USDIMAGING_API
260  virtual void MarkVisibilityDirty(UsdPrim const& prim,
261  SdfPath const& cachePath,
262  UsdImagingIndexProxy* index);
263 
264  USDIMAGING_API
265  virtual void MarkMaterialDirty(UsdPrim const& prim,
266  SdfPath const& cachePath,
267  UsdImagingIndexProxy* index);
268 
269  USDIMAGING_API
270  virtual void MarkLightParamsDirty(UsdPrim const& prim,
271  SdfPath const& cachePath,
272  UsdImagingIndexProxy* index);
273 
274  USDIMAGING_API
275  virtual void MarkWindowPolicyDirty(UsdPrim const& prim,
276  SdfPath const& cachePath,
277  UsdImagingIndexProxy* index);
278 
279  USDIMAGING_API
280  virtual void MarkCollectionsDirty(UsdPrim const& prim,
281  SdfPath const& cachePath,
282  UsdImagingIndexProxy* index);
283 
284  // ---------------------------------------------------------------------- //
286  // ---------------------------------------------------------------------- //
287  USDIMAGING_API
288  virtual void InvokeComputation(SdfPath const& cachePath,
289  HdExtComputationContext* context);
290 
291  // ---------------------------------------------------------------------- //
293  // ---------------------------------------------------------------------- //
294 
296  USDIMAGING_API
297  virtual std::vector<VtArray<TfToken>>
298  GetInstanceCategories(UsdPrim const& prim);
299 
302  USDIMAGING_API
304  UsdPrim const& instancerPrim,
305  SdfPath const& instancerPath,
306  UsdTimeCode time) const;
307 
310  USDIMAGING_API
311  virtual size_t SampleInstancerTransform(
312  UsdPrim const& instancerPrim,
313  SdfPath const& instancerPath,
314  UsdTimeCode time,
315  size_t maxNumSamples,
316  float *sampleTimes,
317  GfMatrix4d *sampleValues);
318 
320  USDIMAGING_API
321  virtual SdfPath GetInstancerId(
322  UsdPrim const& usdPrim,
323  SdfPath const& cachePath) const;
324 
326  USDIMAGING_API
327  virtual SdfPathVector GetInstancerPrototypes(
328  UsdPrim const& usdPrim,
329  SdfPath const& cachePath) const;
330 
336  USDIMAGING_API
337  virtual size_t
338  SamplePrimvar(UsdPrim const& usdPrim,
339  SdfPath const& cachePath,
340  TfToken const& key,
341  UsdTimeCode time,
342  size_t maxNumSamples,
343  float *sampleTimes,
344  VtValue *sampleValues,
345  VtIntArray *sampleIndices);
346 
348  USDIMAGING_API
349  virtual PxOsdSubdivTags GetSubdivTags(UsdPrim const& usdPrim,
350  SdfPath const& cachePath,
351  UsdTimeCode time) const;
352 
353  // ---------------------------------------------------------------------- //
355  // ---------------------------------------------------------------------- //
356 
357  // NOTE: This method is currently only used by PointInstancer
358  // style instances, and not instanceable-references.
359 
363  USDIMAGING_API
365  SdfPath const &instancerPath,
366  SdfPath const &protoInstancerPath,
367  UsdTimeCode time) const;
368 
369  // ---------------------------------------------------------------------- //
371  // ---------------------------------------------------------------------- //
372 
374  USDIMAGING_API
375  virtual SdfPath GetScenePrimPath(SdfPath const& cachePath,
376  int instanceIndex,
377  HdInstancerContext *instancerCtx) const;
378 
379  USDIMAGING_API
380  virtual SdfPathVector GetScenePrimPaths(SdfPath const& cachePath,
381  std::vector<int> const& instanceIndices,
382  std::vector<HdInstancerContext> *instancerCtxs) const;
383 
384  // Add the given usdPrim to the HdSelection object, to mark it for
385  // selection highlighting. cachePath is the path of the object referencing
386  // this adapter.
387  //
388  // If an instance index is provided to Delegate::PopulateSelection, it's
389  // interpreted as a hydra instance index and left unchanged (to make
390  // picking/selection round-tripping work). Otherwise, instance adapters
391  // will build up a composite instance index range at each level.
392  //
393  // Consider:
394  // /World/A (2 instances)
395  // /B (2 instances)
396  // /C (gprim)
397  // ... to select /World/A, instance 0, you want to select cartesian
398  // coordinates (0, *) -> (0, 0) and (0, 1). The flattened representation
399  // of this is:
400  // index = coordinate[0] * instance_count[1] + coordinate[1]
401  // Likewise, for one more nesting level you get:
402  // index = c[0] * count[1] * count[2] + c[1] * count[2] + c[2]
403  // ... since the adapter for /World/A has no idea what count[1+] are,
404  // this needs to be built up. The delegate initially sets
405  // parentInstanceIndices to []. /World/A sets this to [0]. /World/A/B,
406  // since it is selecting *, adds all possible instance indices:
407  // 0 * 2 + 0 = 0, 0 * 2 + 1 = 1. /World/A/B/C is a gprim, and adds
408  // instances [0,1] to its selection.
409  USDIMAGING_API
410  virtual bool PopulateSelection(
411  HdSelection::HighlightMode const& highlightMode,
412  SdfPath const &cachePath,
413  UsdPrim const &usdPrim,
414  int const hydraInstanceIndex,
415  VtIntArray const &parentInstanceIndices,
416  HdSelectionSharedPtr const &result) const;
417 
418  // ---------------------------------------------------------------------- //
420  // ---------------------------------------------------------------------- //
421 
422  USDIMAGING_API
423  virtual HdVolumeFieldDescriptorVector
424  GetVolumeFieldDescriptors(UsdPrim const& usdPrim, SdfPath const &id,
425  UsdTimeCode time) const;
426 
427  // ---------------------------------------------------------------------- //
429  // ---------------------------------------------------------------------- //
430 
432  USDIMAGING_API
434 
436  USDIMAGING_API
437  void SetDelegate(UsdImagingDelegate* delegate);
438 
439  USDIMAGING_API
440  bool IsChildPath(SdfPath const& path) const;
441 
445  USDIMAGING_API
446  virtual bool GetVisible(
447  UsdPrim const& prim,
448  SdfPath const& cachePath,
449  UsdTimeCode time) const;
450 
455  USDIMAGING_API
456  virtual TfToken GetPurpose(
457  UsdPrim const& prim,
458  SdfPath const& cachePath,
459  TfToken const& instanceInheritablePurpose) const;
460 
465  USDIMAGING_API
466  TfToken GetInheritablePurpose(UsdPrim const& prim) const;
467 
471  USDIMAGING_API
472  virtual GfMatrix4d GetTransform(UsdPrim const& prim,
473  SdfPath const& cachePath,
474  UsdTimeCode time,
475  bool ignoreRootTransform = false) const;
476 
478  USDIMAGING_API
479  virtual size_t SampleTransform(UsdPrim const& prim,
480  SdfPath const& cachePath,
481  UsdTimeCode time,
482  size_t maxNumSamples,
483  float *sampleTimes,
484  GfMatrix4d *sampleValues);
485 
490  USDIMAGING_API
491  virtual VtValue Get(UsdPrim const& prim,
492  SdfPath const& cachePath,
493  TfToken const& key,
494  UsdTimeCode time,
495  VtIntArray *outIndices) const;
496 
498  USDIMAGING_API
499  virtual HdCullStyle GetCullStyle(UsdPrim const& prim,
500  SdfPath const& cachePath,
501  UsdTimeCode time) const;
502 
505  USDIMAGING_API
506  SdfPath GetMaterialUsdPath(UsdPrim const& prim) const;
507 
510  USDIMAGING_API
511  TfToken GetModelDrawMode(UsdPrim const& prim);
512 
518  USDIMAGING_API
520  UsdTimeCode time) const;
521 
526  USDIMAGING_API
527  virtual VtValue GetTopology(UsdPrim const& prim,
528  SdfPath const& cachePath,
529  UsdTimeCode time) const;
530 
533  USDIMAGING_API
534  virtual GfRange3d GetExtent(UsdPrim const& prim,
535  SdfPath const& cachePath,
536  UsdTimeCode time) const;
537 
539  USDIMAGING_API
540  virtual bool GetDoubleSided(UsdPrim const& prim,
541  SdfPath const& cachePath,
542  UsdTimeCode time) const;
543 
544  USDIMAGING_API
545  virtual SdfPath GetMaterialId(UsdPrim const& prim,
546  SdfPath const& cachePath,
547  UsdTimeCode time) const;
548 
549  USDIMAGING_API
550  virtual VtValue GetMaterialResource(UsdPrim const& prim,
551  SdfPath const& cachePath,
552  UsdTimeCode time) const;
553 
554  // ---------------------------------------------------------------------- //
556  // ---------------------------------------------------------------------- //
557  USDIMAGING_API
558  virtual const TfTokenVector &GetExtComputationSceneInputNames(
559  SdfPath const& cachePath) const;
560 
561  USDIMAGING_API
562  virtual HdExtComputationInputDescriptorVector
563  GetExtComputationInputs(UsdPrim const& prim,
564  SdfPath const& cachePath,
565  const UsdImagingInstancerContext* instancerContext)
566  const;
567 
568  USDIMAGING_API
569  virtual HdExtComputationOutputDescriptorVector
570  GetExtComputationOutputs(UsdPrim const& prim,
571  SdfPath const& cachePath,
572  const UsdImagingInstancerContext* instancerContext)
573  const;
574 
575  USDIMAGING_API
576  virtual HdExtComputationPrimvarDescriptorVector
577  GetExtComputationPrimvars(
578  UsdPrim const& prim,
579  SdfPath const& cachePath,
580  HdInterpolation interpolation,
581  const UsdImagingInstancerContext* instancerContext) const;
582 
583  USDIMAGING_API
584  virtual VtValue
585  GetExtComputationInput(
586  UsdPrim const& prim,
587  SdfPath const& cachePath,
588  TfToken const& name,
589  UsdTimeCode time,
590  const UsdImagingInstancerContext* instancerContext) const;
591 
592  USDIMAGING_API
593  virtual size_t
594  SampleExtComputationInput(
595  UsdPrim const& prim,
596  SdfPath const& cachePath,
597  TfToken const& name,
598  UsdTimeCode time,
599  const UsdImagingInstancerContext* instancerContext,
600  size_t maxSampleCount,
601  float *sampleTimes,
602  VtValue *sampleValues);
603 
604  USDIMAGING_API
605  virtual std::string
606  GetExtComputationKernel(
607  UsdPrim const& prim,
608  SdfPath const& cachePath,
609  const UsdImagingInstancerContext* instancerContext) const;
610 
611  USDIMAGING_API
612  virtual VtValue
613  GetInstanceIndices(UsdPrim const& instancerPrim,
614  SdfPath const& instancerCachePath,
615  SdfPath const& prototypeCachePath,
616  UsdTimeCode time) const;
617 
618  // ---------------------------------------------------------------------- //
620  // ---------------------------------------------------------------------- //
621 
623  virtual bool IsSupported(UsdImagingIndexProxy const* index) const {
624  return true;
625  }
626 
627 protected:
628  using Keys = UsdImagingPrimvarDescCache::Key;
629 
630  template <typename T>
631  T _Get(UsdPrim const& prim, TfToken const& attrToken,
632  UsdTimeCode time) const {
633  T value;
634  prim.GetAttribute(attrToken).Get<T>(&value, time);
635  return value;
636  }
637 
638  template <typename T>
639  void _GetPtr(UsdPrim const& prim, TfToken const& key, UsdTimeCode time,
640  T* out) const {
641  prim.GetAttribute(key).Get<T>(out, time);
642  }
643 
644  USDIMAGING_API
645  UsdImagingPrimvarDescCache* _GetPrimvarDescCache() const;
646 
647  UsdImaging_NonlinearSampleCountCache*
648  _GetNonlinearSampleCountCache() const;
649 
650  UsdImaging_BlurScaleCache*
651  _GetBlurScaleCache() const;
652 
653  USDIMAGING_API
654  UsdPrim _GetPrim(SdfPath const& usdPath) const;
655 
656  // Returns the prim adapter for the given \p prim, or an invalid pointer if
657  // no adapter exists. If \p prim is an instance and \p ignoreInstancing
658  // is \c true, the instancing adapter will be ignored and an adapter will
659  // be looked up based on \p prim's type.
660  USDIMAGING_API
661  const UsdImagingPrimAdapterSharedPtr&
662  _GetPrimAdapter(UsdPrim const& prim, bool ignoreInstancing = false) const;
663 
664  USDIMAGING_API
665  const UsdImagingPrimAdapterSharedPtr&
666  _GetAdapter(TfToken const& adapterKey) const;
667 
668  // XXX: Transitional API
669  // Returns the instance proxy prim path for a USD-instanced prim, given the
670  // instance chain leading to that prim. The paths are sorted from more to
671  // less local; the first path is the prim path (possibly in prototype), then
672  // instance paths (possibly in prototype); the last path is the prim or
673  // instance path in the scene.
674  USDIMAGING_API
675  SdfPath _GetPrimPathFromInstancerChain(
676  SdfPathVector const& instancerChain) const;
677 
678  USDIMAGING_API
679  UsdTimeCode _GetTimeWithOffset(float offset) const;
680 
681  // Converts \p cachePath to the path in the render index.
682  USDIMAGING_API
683  SdfPath _ConvertCachePathToIndexPath(SdfPath const& cachePath) const;
684 
685  // Converts \p indexPath to the path in the USD stage
686  USDIMAGING_API
687  SdfPath _ConvertIndexPathToCachePath(SdfPath const& indexPath) const;
688 
689  // Returns the material binding purpose from the renderer delegate.
690  USDIMAGING_API
691  TfToken _GetMaterialBindingPurpose() const;
692 
693  // Returns the material contexts from the renderer delegate.
694  USDIMAGING_API
695  TfTokenVector _GetMaterialRenderContexts() const;
696 
698  USDIMAGING_API
699  bool _GetSceneMaterialsEnabled() const;
700 
702  USDIMAGING_API
703  bool _GetSceneLightsEnabled() const;
704 
705  // Returns true if render delegate wants primvars to be filtered based.
706  // This will filter the primvars based on the bound material primvar needs.
707  USDIMAGING_API
708  bool _IsPrimvarFilteringNeeded() const;
709 
710  // Returns the shader source type from the render delegate.
711  USDIMAGING_API
712  TfTokenVector _GetShaderSourceTypes() const;
713 
714  // Returns \c true if \p usdPath is included in the scene delegate's
715  // invised path list.
716  USDIMAGING_API
717  bool _IsInInvisedPaths(SdfPath const& usdPath) const;
718 
719  // Determines if an attribute is varying and if so, sets the given
720  // \p dirtyFlag in the \p dirtyFlags and increments a perf counter. Returns
721  // true if the attribute is varying.
722  //
723  // If \p exists is non-null, _IsVarying will store whether the attribute
724  // was found. If the attribute is not found, it counts as non-varying.
725  //
726  // This only sets the dirty bit, never un-sets. The caller is responsible
727  // for setting the initial state correctly.
728  USDIMAGING_API
729  bool _IsVarying(UsdPrim prim, TfToken const& attrName,
730  HdDirtyBits dirtyFlag, TfToken const& perfToken,
731  HdDirtyBits* dirtyFlags, bool isInherited,
732  bool* exists = nullptr) const;
733 
734  // Determines if the prim's transform (CTM) is varying and if so, sets the
735  // given \p dirtyFlag in the \p dirtyFlags and increments a perf counter.
736  // Returns true if the prim's transform is varying.
737  //
738  // This only sets the dirty bit, never un-sets. The caller is responsible
739  // for setting the initial state correctly.
740  USDIMAGING_API
741  bool _IsTransformVarying(UsdPrim prim,
742  HdDirtyBits dirtyFlag,
743  TfToken const& perfToken,
744  HdDirtyBits* dirtyFlags) const;
745 
746  // Convenience method for adding or updating a primvar descriptor.
747  // Role defaults to empty token (none). Indexed defaults to false.
748  USDIMAGING_API
749  void _MergePrimvar(
750  HdPrimvarDescriptorVector* vec,
751  TfToken const& name,
752  HdInterpolation interp,
753  TfToken const& role = TfToken(),
754  bool indexed = false) const;
755 
756  // Convenience method for removing a primvar descriptor.
757  USDIMAGING_API
758  void _RemovePrimvar(
759  HdPrimvarDescriptorVector* vec,
760  TfToken const& name) const;
761 
762  // Convenience method for computing a primvar. The primvar will only be
763  // added to the list of prim desc if there is no primvar of the same
764  // name already present. Thus, "local" primvars should be merged before
765  // inherited primvars.
766  USDIMAGING_API
767  void _ComputeAndMergePrimvar(
768  UsdPrim const& prim,
769  UsdGeomPrimvar const& primvar,
770  UsdTimeCode time,
771  HdPrimvarDescriptorVector* primvarDescs,
772  HdInterpolation *interpOverride = nullptr) const;
773 
774  // Returns true if the property name has the "primvars:" prefix.
775  USDIMAGING_API
776  static bool _HasPrimvarsPrefix(TfToken const& propertyName);
777 
778  // Convenience methods to figure out what changed about the primvar and
779  // return the appropriate dirty bit.
780  // Caller can optionally pass in a dirty bit to set for primvar value
781  // changes. This is useful for attributes that have a special dirty bit
782  // such as normals and widths.
783  //
784  // Handle USD attributes that are treated as primvars by Hydra. This
785  // requires the interpolation to be passed in, as well as the primvar
786  // name passed to Hydra.
787  USDIMAGING_API
788  HdDirtyBits _ProcessNonPrefixedPrimvarPropertyChange(
789  UsdPrim const& prim,
790  SdfPath const& cachePath,
791  TfToken const& propertyName,
792  TfToken const& primvarName,
793  HdInterpolation const& primvarInterp,
794  HdDirtyBits valueChangeDirtyBit = HdChangeTracker::DirtyPrimvar) const;
795 
796  // Handle UsdGeomPrimvars that use the "primvars:" prefix, while also
797  // accommodating inheritance.
798  USDIMAGING_API
799  HdDirtyBits _ProcessPrefixedPrimvarPropertyChange(
800  UsdPrim const& prim,
801  SdfPath const& cachePath,
802  TfToken const& propertyName,
803  HdDirtyBits valueChangeDirtyBit = HdChangeTracker::DirtyPrimvar,
804  bool inherited = true) const;
805 
806  virtual void _RemovePrim(SdfPath const& cachePath,
807  UsdImagingIndexProxy* index) = 0;
808 
809  // Utility to resync bound dependencies of a particular usd path.
810  // This is necessary for the resync processing of certain prim types
811  // (e.g. materials).
812  USDIMAGING_API
813  void _ResyncDependents(SdfPath const& usdPath,
814  UsdImagingIndexProxy *index);
815 
816  USDIMAGING_API
817  UsdImaging_CollectionCache& _GetCollectionCache() const;
818 
819  USDIMAGING_API
820  UsdStageRefPtr _GetStage() const;
821 
822  USDIMAGING_API
823  UsdImaging_CoordSysBindingStrategy::value_type
824  _GetCoordSysBindings(UsdPrim const& prim) const;
825 
826  USDIMAGING_API
827  UsdImaging_InheritedPrimvarStrategy::value_type
828  _GetInheritedPrimvars(UsdPrim const& prim) const;
829 
830  // Utility for derived classes to try to find an inherited primvar.
831  USDIMAGING_API
832  UsdGeomPrimvar _GetInheritedPrimvar(UsdPrim const& prim,
833  TfToken const& primvarName) const;
834 
835  USDIMAGING_API
836  GfInterval _GetCurrentTimeSamplingInterval();
837 
838  USDIMAGING_API
839  Usd_PrimFlagsConjunction _GetDisplayPredicate() const;
840 
841  USDIMAGING_API
842  Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes() const;
843 
844  USDIMAGING_API
845  bool _DoesDelegateSupportCoordSys() const;
846 
847 private:
848  UsdImagingDelegate* _delegate;
849 };
850 
851 class UsdImagingPrimAdapterFactoryBase : public TfType::FactoryBase {
852 public:
853  virtual UsdImagingPrimAdapterSharedPtr New() const = 0;
854 };
855 
856 template <class T>
857 class UsdImagingPrimAdapterFactory : public UsdImagingPrimAdapterFactoryBase {
858 public:
859  virtual UsdImagingPrimAdapterSharedPtr New() const
860  {
861  return std::make_shared<T>();
862  }
863 };
864 
865 
866 PXR_NAMESPACE_CLOSE_SCOPE
867 
868 #endif // PXR_USD_IMAGING_USD_IMAGING_PRIM_ADAPTER_H
USDIMAGING_API TfToken GetInheritablePurpose(UsdPrim const &prim) const
Returns the purpose token for prim, but only if it is inheritable by child prims (i....
USDIMAGING_API SdfPath GetMaterialUsdPath(UsdPrim const &prim) const
Gets the material path for the given prim, walking up namespace if necessary.
Interface class that defines the execution environment for the client to run a computation.
Tags for non-hierarchial subdiv surfaces.
Definition: subdivTags.h:43
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:431
Basic type: 3-dimensional floating point range.
Definition: range3d.h:64
USDIMAGING_API VtArray< VtIntArray > GetPerPrototypeIndices(UsdPrim const &prim, UsdTimeCode time) const
Computes the per-prototype instance indices for a UsdGeomPointInstancer.
virtual USDIMAGING_API GfMatrix4d GetInstancerTransform(UsdPrim const &instancerPrim, SdfPath const &instancerPath, UsdTimeCode time) const
Get the instancer transform for the given prim.
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 ...
USDIMAGING_API bool _GetSceneLightsEnabled() const
Returns whether lights found in the usdscene are enabled.
virtual USDIMAGING_API PxOsdSubdivTags GetSubdivTags(UsdPrim const &usdPrim, SdfPath const &cachePath, UsdTimeCode time) const
Get the subdiv tags for this prim.
HighlightMode
Selection modes allow differentiation in selection highlight behavior.
Definition: selection.h:55
This proxy class exposes a subset of the private Delegate API to PrimAdapters.
Definition: indexProxy.h:47
USDIMAGING_API void SetDelegate(UsdImagingDelegate *delegate)
A thread-local XformCache provided by the delegate.
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 SdfPath GetInstancerId(UsdPrim const &usdPrim, SdfPath const &cachePath) const
Return the instancerId for this prim.
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...
Base class of all factory types.
Definition: type.h:73
USD_API UsdAttribute GetAttribute(const TfToken &attrName) const
Return a UsdAttribute with the name attrName.
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.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
virtual USDIMAGING_API GfRange3d GetExtent(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
Reads the extent from the given prim.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
This class is used as a context object with global stage information, that gets passed down to dataso...
Base class for all PrimAdapters.
Definition: primAdapter.h:67
USDIMAGING_API TfToken GetModelDrawMode(UsdPrim const &prim)
Gets the model:drawMode attribute for the given prim, walking up the namespace if necessary.
Represents a set of data source locators closed under descendancy.
virtual USDIMAGING_API GfMatrix4d GetRelativeInstancerTransform(SdfPath const &instancerPath, SdfPath const &protoInstancerPath, UsdTimeCode time) const
Returns the transform of protoInstancerPath relative to instancerPath.
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.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:134
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
A basic mathematical interval class.
Definition: interval.h:50
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:228
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
A cache for primvar descriptors.
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.
virtual USDIMAGING_API SdfPath GetScenePrimPath(SdfPath const &cachePath, int instanceIndex, HdInstancerContext *instancerCtx) const
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 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 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.
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.
Object used by instancer prim adapters to pass along context about the instancer and instance prim to...
Schema wrapper for UsdAttribute for authoring and introspecting attributes that are primvars.
Definition: primvar.h:261
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...
USDIMAGING_API bool _GetSceneMaterialsEnabled() const
Returns whether custom shading of prims is enabled.
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.
The primary translation layer between the Hydra (Hd) core and the Usd scene graph.
Definition: delegate.h:87
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 bool IsSupported(UsdImagingIndexProxy const *index) const
Returns true if the adapter can be populated into the target index.
Definition: primAdapter.h:623
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166
USDIMAGING_API GfMatrix4d GetRootTransform() const
The root transform provided by the delegate.
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 SdfPathVector GetInstancerPrototypes(UsdPrim const &usdPrim, SdfPath const &cachePath) const
Return the list of known prototypes of this prim.
virtual USDIMAGING_API std::vector< VtArray< TfToken > > GetInstanceCategories(UsdPrim const &prim)
Return an array of the categories used by each instance.