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(UsdPrim const& prim);
84 
85  USDIMAGING_API
86  virtual TfToken GetImagingSubprimType(
87  UsdPrim const& prim, TfToken const& subprim);
88 
89  USDIMAGING_API
90  virtual HdContainerDataSourceHandle GetImagingSubprimData(
91  UsdPrim const& prim,
92  TfToken const& subprim,
93  const UsdImagingDataSourceStageGlobals &stageGlobals);
94 
95  USDIMAGING_API
96  virtual HdDataSourceLocatorSet InvalidateImagingSubprim(
97  UsdPrim const& prim,
98  TfToken const& subprim,
99  TfTokenVector const& properties);
100 
107  {
111 
117 
126  };
127 
130  USDIMAGING_API
132 
137  USDIMAGING_API
139  UsdPrim const& prim,
140  UsdPrim const& descendentPrim,
141  TfToken const& subprim,
142  TfTokenVector const& properties);
143 
144  // ---------------------------------------------------------------------- //
146  // ---------------------------------------------------------------------- //
147 
151  virtual SdfPath Populate(UsdPrim const& prim,
152  UsdImagingIndexProxy* index,
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>>
343  GetInstanceCategories(UsdPrim const& prim);
344 
347  USDIMAGING_API
349  UsdPrim const& instancerPrim,
350  SdfPath const& instancerPath,
351  UsdTimeCode time) const;
352 
355  USDIMAGING_API
356  virtual size_t SampleInstancerTransform(
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
366  virtual SdfPath GetInstancerId(
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 
477  USDIMAGING_API
479 
481  USDIMAGING_API
482  void SetDelegate(UsdImagingDelegate* delegate);
483 
484  USDIMAGING_API
485  bool IsChildPath(SdfPath const& path) const;
486 
490  USDIMAGING_API
491  virtual bool GetVisible(
492  UsdPrim const& prim,
493  SdfPath const& cachePath,
494  UsdTimeCode time) const;
495 
500  USDIMAGING_API
501  virtual TfToken GetPurpose(
502  UsdPrim const& prim,
503  SdfPath const& cachePath,
504  TfToken const& instanceInheritablePurpose) const;
505 
510  USDIMAGING_API
511  TfToken GetInheritablePurpose(UsdPrim const& prim) const;
512 
516  USDIMAGING_API
517  virtual GfMatrix4d GetTransform(UsdPrim const& prim,
518  SdfPath const& cachePath,
519  UsdTimeCode time,
520  bool ignoreRootTransform = false) const;
521 
523  USDIMAGING_API
524  virtual size_t SampleTransform(UsdPrim const& prim,
525  SdfPath const& cachePath,
526  UsdTimeCode time,
527  size_t maxNumSamples,
528  float *sampleTimes,
529  GfMatrix4d *sampleValues);
530 
535  USDIMAGING_API
536  virtual VtValue Get(UsdPrim const& prim,
537  SdfPath const& cachePath,
538  TfToken const& key,
539  UsdTimeCode time,
540  VtIntArray *outIndices) const;
541 
543  USDIMAGING_API
544  virtual HdCullStyle GetCullStyle(UsdPrim const& prim,
545  SdfPath const& cachePath,
546  UsdTimeCode time) const;
547 
550  USDIMAGING_API
551  SdfPath GetMaterialUsdPath(UsdPrim const& prim) const;
552 
555  USDIMAGING_API
556  TfToken GetModelDrawMode(UsdPrim const& prim);
557 
563  USDIMAGING_API
565  UsdTimeCode time) const;
566 
571  USDIMAGING_API
572  virtual VtValue GetTopology(UsdPrim const& prim,
573  SdfPath const& cachePath,
574  UsdTimeCode time) const;
575 
578  USDIMAGING_API
579  virtual GfRange3d GetExtent(UsdPrim const& prim,
580  SdfPath const& cachePath,
581  UsdTimeCode time) const;
582 
584  USDIMAGING_API
585  virtual bool GetDoubleSided(UsdPrim const& prim,
586  SdfPath const& cachePath,
587  UsdTimeCode time) const;
588 
589  USDIMAGING_API
590  virtual SdfPath GetMaterialId(UsdPrim const& prim,
591  SdfPath const& cachePath,
592  UsdTimeCode time) const;
593 
594  USDIMAGING_API
595  virtual VtValue GetMaterialResource(UsdPrim const& prim,
596  SdfPath const& cachePath,
597  UsdTimeCode time) const;
598 
599  // ---------------------------------------------------------------------- //
601  // ---------------------------------------------------------------------- //
602  USDIMAGING_API
603  virtual const TfTokenVector &GetExtComputationSceneInputNames(
604  SdfPath const& cachePath) const;
605 
606  USDIMAGING_API
607  virtual HdExtComputationInputDescriptorVector
608  GetExtComputationInputs(UsdPrim const& prim,
609  SdfPath const& cachePath,
610  const UsdImagingInstancerContext* instancerContext)
611  const;
612 
613  USDIMAGING_API
614  virtual HdExtComputationOutputDescriptorVector
615  GetExtComputationOutputs(UsdPrim const& prim,
616  SdfPath const& cachePath,
617  const UsdImagingInstancerContext* instancerContext)
618  const;
619 
620  USDIMAGING_API
621  virtual HdExtComputationPrimvarDescriptorVector
622  GetExtComputationPrimvars(
623  UsdPrim const& prim,
624  SdfPath const& cachePath,
625  HdInterpolation interpolation,
626  const UsdImagingInstancerContext* instancerContext) const;
627 
628  USDIMAGING_API
629  virtual VtValue
630  GetExtComputationInput(
631  UsdPrim const& prim,
632  SdfPath const& cachePath,
633  TfToken const& name,
634  UsdTimeCode time,
635  const UsdImagingInstancerContext* instancerContext) const;
636 
637  USDIMAGING_API
638  virtual size_t
639  SampleExtComputationInput(
640  UsdPrim const& prim,
641  SdfPath const& cachePath,
642  TfToken const& name,
643  UsdTimeCode time,
644  const UsdImagingInstancerContext* instancerContext,
645  size_t maxSampleCount,
646  float *sampleTimes,
647  VtValue *sampleValues);
648 
649  USDIMAGING_API
650  virtual std::string
651  GetExtComputationKernel(
652  UsdPrim const& prim,
653  SdfPath const& cachePath,
654  const UsdImagingInstancerContext* instancerContext) const;
655 
656  USDIMAGING_API
657  virtual VtValue
658  GetInstanceIndices(UsdPrim const& instancerPrim,
659  SdfPath const& instancerCachePath,
660  SdfPath const& prototypeCachePath,
661  UsdTimeCode time) const;
662 
663  // ---------------------------------------------------------------------- //
665  // ---------------------------------------------------------------------- //
666 
668  virtual bool IsSupported(UsdImagingIndexProxy const* index) const {
669  return true;
670  }
671 
672 protected:
673  using Keys = UsdImagingPrimvarDescCache::Key;
674 
675  template <typename T>
676  T _Get(UsdPrim const& prim, TfToken const& attrToken,
677  UsdTimeCode time) const {
678  T value;
679  prim.GetAttribute(attrToken).Get<T>(&value, time);
680  return value;
681  }
682 
683  template <typename T>
684  void _GetPtr(UsdPrim const& prim, TfToken const& key, UsdTimeCode time,
685  T* out) const {
686  prim.GetAttribute(key).Get<T>(out, time);
687  }
688 
689  USDIMAGING_API
690  UsdImagingPrimvarDescCache* _GetPrimvarDescCache() const;
691 
692  UsdImaging_NonlinearSampleCountCache*
693  _GetNonlinearSampleCountCache() const;
694 
695  UsdImaging_BlurScaleCache*
696  _GetBlurScaleCache() const;
697 
698  USDIMAGING_API
699  UsdPrim _GetPrim(SdfPath const& usdPath) const;
700 
701  // Returns the prim adapter for the given \p prim, or an invalid pointer if
702  // no adapter exists. If \p prim is an instance and \p ignoreInstancing
703  // is \c true, the instancing adapter will be ignored and an adapter will
704  // be looked up based on \p prim's type.
705  USDIMAGING_API
706  const UsdImagingPrimAdapterSharedPtr&
707  _GetPrimAdapter(UsdPrim const& prim, bool ignoreInstancing = false) const;
708 
709  USDIMAGING_API
710  const UsdImagingPrimAdapterSharedPtr&
711  _GetAdapter(TfToken const& adapterKey) const;
712 
713  // XXX: Transitional API
714  // Returns the instance proxy prim path for a USD-instanced prim, given the
715  // instance chain leading to that prim. The paths are sorted from more to
716  // less local; the first path is the prim path (possibly in prototype), then
717  // instance paths (possibly in prototype); the last path is the prim or
718  // instance path in the scene.
719  USDIMAGING_API
720  SdfPath _GetPrimPathFromInstancerChain(
721  SdfPathVector const& instancerChain) const;
722 
723  USDIMAGING_API
724  UsdTimeCode _GetTimeWithOffset(float offset) const;
725 
726  // Converts \p cachePath to the path in the render index.
727  USDIMAGING_API
728  SdfPath _ConvertCachePathToIndexPath(SdfPath const& cachePath) const;
729 
730  // Converts \p indexPath to the path in the USD stage
731  USDIMAGING_API
732  SdfPath _ConvertIndexPathToCachePath(SdfPath const& indexPath) const;
733 
734  // Returns the material binding purpose from the renderer delegate.
735  USDIMAGING_API
736  TfToken _GetMaterialBindingPurpose() const;
737 
738  // Returns the material contexts from the renderer delegate.
739  USDIMAGING_API
740  TfTokenVector _GetMaterialRenderContexts() const;
741 
742  // Returns the namespace prefixes for render settings attributes relevant
743  // to a renderer delegate.
744  USDIMAGING_API
745  TfTokenVector _GetRenderSettingsNamespaces() const;
746 
748  USDIMAGING_API
749  bool _GetSceneMaterialsEnabled() const;
750 
752  USDIMAGING_API
753  bool _GetSceneLightsEnabled() const;
754 
755  // Returns true if render delegate wants primvars to be filtered based.
756  // This will filter the primvars based on the bound material primvar needs.
757  USDIMAGING_API
758  bool _IsPrimvarFilteringNeeded() const;
759 
760  // Returns the shader source type from the render delegate.
761  USDIMAGING_API
762  TfTokenVector _GetShaderSourceTypes() const;
763 
764  // Returns \c true if \p usdPath is included in the scene delegate's
765  // invised path list.
766  USDIMAGING_API
767  bool _IsInInvisedPaths(SdfPath const& usdPath) const;
768 
769  // Determines if an attribute is varying and if so, sets the given
770  // \p dirtyFlag in the \p dirtyFlags and increments a perf counter. Returns
771  // true if the attribute is varying.
772  //
773  // If \p exists is non-null, _IsVarying will store whether the attribute
774  // was found. If the attribute is not found, it counts as non-varying.
775  //
776  // This only sets the dirty bit, never un-sets. The caller is responsible
777  // for setting the initial state correctly.
778  USDIMAGING_API
779  bool _IsVarying(UsdPrim prim, TfToken const& attrName,
780  HdDirtyBits dirtyFlag, TfToken const& perfToken,
781  HdDirtyBits* dirtyFlags, bool isInherited,
782  bool* exists = nullptr) const;
783 
784  // Determines if the prim's transform (CTM) is varying and if so, sets the
785  // given \p dirtyFlag in the \p dirtyFlags and increments a perf counter.
786  // Returns true if the prim's transform is varying.
787  //
788  // This only sets the dirty bit, never un-sets. The caller is responsible
789  // for setting the initial state correctly.
790  USDIMAGING_API
791  bool _IsTransformVarying(UsdPrim prim,
792  HdDirtyBits dirtyFlag,
793  TfToken const& perfToken,
794  HdDirtyBits* dirtyFlags) const;
795 
796  // Convenience method for adding or updating a primvar descriptor.
797  // Role defaults to empty token (none). Indexed defaults to false.
798  USDIMAGING_API
799  void _MergePrimvar(
800  HdPrimvarDescriptorVector* vec,
801  TfToken const& name,
802  HdInterpolation interp,
803  TfToken const& role = TfToken(),
804  bool indexed = false) const;
805 
806  // Convenience method for removing a primvar descriptor.
807  USDIMAGING_API
808  void _RemovePrimvar(
809  HdPrimvarDescriptorVector* vec,
810  TfToken const& name) const;
811 
812  // Convenience method for computing a primvar. The primvar will only be
813  // added to the list of prim desc if there is no primvar of the same
814  // name already present. Thus, "local" primvars should be merged before
815  // inherited primvars.
816  USDIMAGING_API
817  void _ComputeAndMergePrimvar(
818  UsdPrim const& prim,
819  UsdGeomPrimvar const& primvar,
820  UsdTimeCode time,
821  HdPrimvarDescriptorVector* primvarDescs,
822  HdInterpolation *interpOverride = nullptr) const;
823 
824  // Returns true if the property name has the "primvars:" prefix.
825  USDIMAGING_API
826  static bool _HasPrimvarsPrefix(TfToken const& propertyName);
827 
828  // Convenience methods to figure out what changed about the primvar and
829  // return the appropriate dirty bit.
830  // Caller can optionally pass in a dirty bit to set for primvar value
831  // changes. This is useful for attributes that have a special dirty bit
832  // such as normals and widths.
833  //
834  // Handle USD attributes that are treated as primvars by Hydra. This
835  // requires the interpolation to be passed in, as well as the primvar
836  // name passed to Hydra.
837  USDIMAGING_API
838  HdDirtyBits _ProcessNonPrefixedPrimvarPropertyChange(
839  UsdPrim const& prim,
840  SdfPath const& cachePath,
841  TfToken const& propertyName,
842  TfToken const& primvarName,
843  HdInterpolation const& primvarInterp,
844  HdDirtyBits valueChangeDirtyBit = HdChangeTracker::DirtyPrimvar) const;
845 
846  // Handle UsdGeomPrimvars that use the "primvars:" prefix, while also
847  // accommodating inheritance.
848  USDIMAGING_API
849  HdDirtyBits _ProcessPrefixedPrimvarPropertyChange(
850  UsdPrim const& prim,
851  SdfPath const& cachePath,
852  TfToken const& propertyName,
853  HdDirtyBits valueChangeDirtyBit = HdChangeTracker::DirtyPrimvar,
854  bool inherited = true) const;
855 
856  virtual void _RemovePrim(SdfPath const& cachePath,
857  UsdImagingIndexProxy* index) = 0;
858 
859  // Utility to resync bound dependencies of a particular usd path.
860  // This is necessary for the resync processing of certain prim types
861  // (e.g. materials).
862  USDIMAGING_API
863  void _ResyncDependents(SdfPath const& usdPath,
864  UsdImagingIndexProxy *index);
865 
866  USDIMAGING_API
867  UsdImaging_CollectionCache& _GetCollectionCache() const;
868 
869  USDIMAGING_API
870  UsdStageRefPtr _GetStage() const;
871 
872  USDIMAGING_API
873  UsdImaging_CoordSysBindingStrategy::value_type
874  _GetCoordSysBindings(UsdPrim const& prim) const;
875 
876  USDIMAGING_API
877  UsdImaging_InheritedPrimvarStrategy::value_type
878  _GetInheritedPrimvars(UsdPrim const& prim) const;
879 
880  // Utility for derived classes to try to find an inherited primvar.
881  USDIMAGING_API
882  UsdGeomPrimvar _GetInheritedPrimvar(UsdPrim const& prim,
883  TfToken const& primvarName) const;
884 
885  USDIMAGING_API
886  GfInterval _GetCurrentTimeSamplingInterval();
887 
888  USDIMAGING_API
889  Usd_PrimFlagsConjunction _GetDisplayPredicate() const;
890 
891  USDIMAGING_API
892  Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes() const;
893 
894  USDIMAGING_API
895  bool _DoesDelegateSupportCoordSys() const;
896 
897 private:
898  UsdImagingDelegate* _delegate;
899 };
900 
901 class UsdImagingPrimAdapterFactoryBase : public TfType::FactoryBase {
902 public:
903  virtual UsdImagingPrimAdapterSharedPtr New() const = 0;
904 };
905 
906 template <class T>
907 class UsdImagingPrimAdapterFactory : public UsdImagingPrimAdapterFactoryBase {
908 public:
909  virtual UsdImagingPrimAdapterSharedPtr New() const
910  {
911  return std::make_shared<T>();
912  }
913 };
914 
915 
916 PXR_NAMESPACE_CLOSE_SCOPE
917 
918 #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.
The adapter is responsible for USD prims of its registered type as well as any descendents of those p...
Definition: primAdapter.h:116
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:56
This proxy class exposes a subset of the private Delegate API to PrimAdapters.
Definition: indexProxy.h:47
Changes to prims of this adapter's registered type are sent to the first ancestor prim whose adapter'...
Definition: primAdapter.h:125
USDIMAGING_API void SetDelegate(UsdImagingDelegate *delegate)
A thread-local XformCache provided by the delegate.
The adapter is responsible only for USD prims of its registered type.
Definition: primAdapter.h:110
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
virtual USDIMAGING_API PopulationMode GetPopulationMode()
Returns the prim's behavior with regard to population and invalidation.
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:230
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 HdDataSourceLocatorSet InvalidateImagingSubprimFromDescendent(UsdPrim const &prim, UsdPrim const &descendentPrim, TfToken const &subprim, TfTokenVector const &properties)
This is called (for each result of GetImagingSubprims) when this adapter's GetScope() result is Repre...
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:668
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.