HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
27 /// \file usdImaging/primAdapter.h
28 
29 #include "pxr/pxr.h"
35 
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 
49 
50 class UsdPrim;
51 
52 // Forward declaration for nested class.
53 class UsdImagingDelegate;
57 
59 
61  std::shared_ptr<class UsdImagingPrimAdapter>;
62 
63 /// \class UsdImagingPrimAdapter
64 ///
65 /// Base class for all PrimAdapters.
66 ///
68  : public std::enable_shared_from_this<UsdImagingPrimAdapter>
69 {
70 public:
71 
73  {}
74 
76  virtual ~UsdImagingPrimAdapter();
77 
78  // ---------------------------------------------------------------------- //
79  /// \name Scene Index Support
80  // ---------------------------------------------------------------------- //
81 
84 
86  virtual TfToken GetImagingSubprimType(TfToken const& subprim);
87 
89  virtual HdContainerDataSourceHandle GetImagingSubprimData(
90  TfToken const& subprim,
91  UsdPrim const& prim,
92  const UsdImagingDataSourceStageGlobals &stageGlobals);
93 
94  // ---------------------------------------------------------------------- //
95  /// \name Initialization
96  // ---------------------------------------------------------------------- //
97 
98  /// Called to populate the RenderIndex for this UsdPrim. The adapter is
99  /// expected to create one or more prims in the render index using the
100  /// given proxy.
101  virtual SdfPath Populate(UsdPrim const& prim,
104  instancerContext = nullptr) = 0;
105 
106  // Indicates whether population traversal should be pruned based on
107  // prim-specific features (like whether it's imageable).
109  static bool ShouldCullSubtree(UsdPrim const& prim);
110 
111  // Indicates whether population traversal should be pruned based on
112  // adapter-specific features (like whether the adapter is an instance
113  // adapter, and wants to do its own population).
115  virtual bool ShouldCullChildren() const;
116 
117  // Indicates whether or not native USD prim instancing should be ignored
118  // for prims using this delegate, along with their descendants.
120  virtual bool ShouldIgnoreNativeInstanceSubtrees() const;
121 
122  // Indicates the adapter is a multiplexing adapter (e.g. PointInstancer),
123  // potentially managing its children. This flag is used in nested
124  // instancer cases to determine which adapter is assigned to which prim.
126  virtual bool IsInstancerAdapter() const;
127 
128  // Indicates whether this adapter can directly populate USD instance prims.
129  //
130  // Normally, with USD instances, we make a firewall between the instance
131  // prim and the USD prototype tree. The instance adapter creates one
132  // hydra prototype per prim in the USD prototype tree, shared by all USD
133  // instances; this lets us recognize the benefits of instancing,
134  // by hopefully having a high instance count per prototype. The instance
135  // adapter additionally configures a hydra instancer for the prototype tree;
136  // and a small set of specially-handled data is allowed through: things like
137  // inherited constant primvars, transforms, visibility, and other things
138  // we know how to vary per-instance.
139  //
140  // We enforce the above policy by refusing to populate gprims which are
141  // USD instances, since we'd need one prototype per instance and would lose
142  // any instancing benefit.
143  //
144  // There are a handful of times when it really is useful to directly
145  // populate instance prims: for example, instances with cards applied,
146  // or instances of type UsdSkelRoot. In those cases, the adapters can
147  // opt into this scheme with "CanPopulateUsdInstance".
148  //
149  // Note that any adapters taking advantage of this feature will need
150  // extensive code support in instanceAdapter: the instance adapter will
151  // need to potentially create and track multiple hydra prototypes per
152  // USD prototype, and the adapter will need special handling to pass down
153  // any relevant instance-varying data.
154  //
155  // In summary: use with caution.
157  virtual bool CanPopulateUsdInstance() const;
158 
159  // ---------------------------------------------------------------------- //
160  /// \name Parallel Setup and Resolve
161  // ---------------------------------------------------------------------- //
162 
163  /// For the given \p prim, variability is detected and
164  /// stored in \p timeVaryingBits. Initial values are cached into the value
165  /// cache.
166  ///
167  /// This method is expected to be called from multiple threads.
168  virtual void TrackVariability(UsdPrim const& prim,
169  SdfPath const& cachePath,
170  HdDirtyBits* timeVaryingBits,
172  instancerContext = nullptr) const = 0;
173 
174  /// Populates the \p cache for the given \p prim, \p time and \p
175  /// requestedBits.
176  ///
177  /// This method is expected to be called from multiple threads.
178  virtual void UpdateForTime(UsdPrim const& prim,
179  SdfPath const& cachePath,
181  HdDirtyBits requestedBits,
183  instancerContext = nullptr) const = 0;
184 
185  // ---------------------------------------------------------------------- //
186  /// \name Change Processing
187  // ---------------------------------------------------------------------- //
188 
189  /// Returns a bit mask of attributes to be updated, or
190  /// HdChangeTracker::AllDirty if the entire prim must be resynchronized.
191  ///
192  /// \p changedFields contains a list of changed scene description fields
193  /// for this prim. This may be empty in certain cases, like the addition
194  /// of an inert prim spec for the given \p prim.
195  ///
196  /// The default implementation returns HdChangeTracker::AllDirty if any of
197  /// the changed fields are plugin metadata fields, HdChangeTracker::Clean
198  /// otherwise.
200  virtual HdDirtyBits ProcessPrimChange(UsdPrim const& prim,
201  SdfPath const& cachePath,
202  TfTokenVector const& changedFields);
203 
204  /// Returns a bit mask of attributes to be updated, or
205  /// HdChangeTracker::AllDirty if the entire prim must be resynchronized.
206  virtual HdDirtyBits ProcessPropertyChange(UsdPrim const& prim,
207  SdfPath const& cachePath,
208  TfToken const& propertyName) = 0;
209 
210  /// When a PrimResync event occurs, the prim may have been deleted entirely,
211  /// adapter plug-ins should override this method to free any per-prim state
212  /// that was accumulated in the adapter.
214  virtual void ProcessPrimResync(SdfPath const& cachePath,
216 
217  /// Removes all associated Rprims and dependencies from the render index
218  /// without scheduling them for repopulation.
220  virtual void ProcessPrimRemoval(SdfPath const& cachePath,
222 
223 
224  virtual void MarkDirty(UsdPrim const& prim,
225  SdfPath const& cachePath,
226  HdDirtyBits dirty,
228 
230  virtual void MarkRefineLevelDirty(UsdPrim const& prim,
231  SdfPath const& cachePath,
233 
235  virtual void MarkReprDirty(UsdPrim const& prim,
236  SdfPath const& cachePath,
238 
240  virtual void MarkCullStyleDirty(UsdPrim const& prim,
241  SdfPath const& cachePath,
243 
245  virtual void MarkRenderTagDirty(UsdPrim const& prim,
246  SdfPath const& cachePath,
248 
250  virtual void MarkTransformDirty(UsdPrim const& prim,
251  SdfPath const& cachePath,
253 
255  virtual void MarkVisibilityDirty(UsdPrim const& prim,
256  SdfPath const& cachePath,
258 
260  virtual void MarkMaterialDirty(UsdPrim const& prim,
261  SdfPath const& cachePath,
263 
265  virtual void MarkLightParamsDirty(UsdPrim const& prim,
266  SdfPath const& cachePath,
268 
270  virtual void MarkWindowPolicyDirty(UsdPrim const& prim,
271  SdfPath const& cachePath,
273 
275  virtual void MarkCollectionsDirty(UsdPrim const& prim,
276  SdfPath const& cachePath,
278 
279  // ---------------------------------------------------------------------- //
280  /// \name Computations
281  // ---------------------------------------------------------------------- //
283  virtual void InvokeComputation(SdfPath const& cachePath,
284  HdExtComputationContext* context);
285 
286  // ---------------------------------------------------------------------- //
287  /// \name Instancing
288  // ---------------------------------------------------------------------- //
289 
290  /// Return an array of the categories used by each instance.
292  virtual std::vector<VtArray<TfToken>>
293  GetInstanceCategories(UsdPrim const& prim);
294 
295  /// Get the instancer transform for the given prim.
296  /// \see HdSceneDelegate::GetInstancerTransform()
299  UsdPrim const& instancerPrim,
300  SdfPath const& instancerPath,
301  UsdTimeCode time) const;
302 
303  /// Sample the instancer transform for the given prim.
304  /// \see HdSceneDelegate::SampleInstancerTransform()
306  virtual size_t SampleInstancerTransform(
307  UsdPrim const& instancerPrim,
308  SdfPath const& instancerPath,
310  size_t maxNumSamples,
311  float *sampleTimes,
312  GfMatrix4d *sampleValues);
313 
314  /// Return the instancerId for this prim.
316  virtual SdfPath GetInstancerId(
317  UsdPrim const& usdPrim,
318  SdfPath const& cachePath) const;
319 
320  /// Return the list of known prototypes of this prim.
323  UsdPrim const& usdPrim,
324  SdfPath const& cachePath) const;
325 
326  /// Sample the primvar for the given prim. If *sampleIndices is not nullptr
327  /// and the primvar has indices, it will sample the unflattened primvar and
328  /// set *sampleIndices to the primvar's sampled indices.
329  /// \see HdSceneDelegate::SamplePrimvar() and
330  /// HdSceneDelegate::SampleIndexedPrimvar()
332  virtual size_t
333  SamplePrimvar(UsdPrim const& usdPrim,
334  SdfPath const& cachePath,
335  TfToken const& key,
337  size_t maxNumSamples,
338  float *sampleTimes,
339  VtValue *sampleValues,
340  VtIntArray *sampleIndices);
341 
342  /// Get the subdiv tags for this prim.
344  virtual PxOsdSubdivTags GetSubdivTags(UsdPrim const& usdPrim,
345  SdfPath const& cachePath,
346  UsdTimeCode time) const;
347 
348  // ---------------------------------------------------------------------- //
349  /// \name Nested instancing support
350  // ---------------------------------------------------------------------- //
351 
352  // NOTE: This method is currently only used by PointInstancer
353  // style instances, and not instanceable-references.
354 
355  /// Returns the transform of \p protoInstancerPath relative to
356  /// \p instancerPath. \p instancerPath must be managed by this
357  /// adapter.
360  SdfPath const &instancerPath,
361  SdfPath const &protoInstancerPath,
362  UsdTimeCode time) const;
363 
364  // ---------------------------------------------------------------------- //
365  /// \name Selection
366  // ---------------------------------------------------------------------- //
367 
368  /// \deprecated Call and implement GetScenePrimPaths instead.
370  virtual SdfPath GetScenePrimPath(SdfPath const& cachePath,
371  int instanceIndex,
372  HdInstancerContext *instancerCtx) const;
373 
375  virtual SdfPathVector GetScenePrimPaths(SdfPath const& cachePath,
376  std::vector<int> const& instanceIndices,
377  std::vector<HdInstancerContext> *instancerCtxs) const;
378 
380  virtual SdfPath GetDataSharingId(SdfPath const& cachePath) const;
381 
382  // Add the given usdPrim to the HdSelection object, to mark it for
383  // selection highlighting. cachePath is the path of the object referencing
384  // this adapter.
385  //
386  // If an instance index is provided to Delegate::PopulateSelection, it's
387  // interpreted as a hydra instance index and left unchanged (to make
388  // picking/selection round-tripping work). Otherwise, instance adapters
389  // will build up a composite instance index range at each level.
390  //
391  // Consider:
392  // /World/A (2 instances)
393  // /B (2 instances)
394  // /C (gprim)
395  // ... to select /World/A, instance 0, you want to select cartesian
396  // coordinates (0, *) -> (0, 0) and (0, 1). The flattened representation
397  // of this is:
398  // index = coordinate[0] * instance_count[1] + coordinate[1]
399  // Likewise, for one more nesting level you get:
400  // index = c[0] * count[1] * count[2] + c[1] * count[2] + c[2]
401  // ... since the adapter for /World/A has no idea what count[1+] are,
402  // this needs to be built up. The delegate initially sets
403  // parentInstanceIndices to []. /World/A sets this to [0]. /World/A/B,
404  // since it is selecting *, adds all possible instance indices:
405  // 0 * 2 + 0 = 0, 0 * 2 + 1 = 1. /World/A/B/C is a gprim, and adds
406  // instances [0,1] to its selection.
408  virtual bool PopulateSelection(
409  HdSelection::HighlightMode const& highlightMode,
410  SdfPath const &cachePath,
411  UsdPrim const &usdPrim,
412  int const hydraInstanceIndex,
413  VtIntArray const &parentInstanceIndices,
414  HdSelectionSharedPtr const &result) const;
415 
416  // ---------------------------------------------------------------------- //
417  /// \name Volume field information
418  // ---------------------------------------------------------------------- //
419 
422  GetVolumeFieldDescriptors(UsdPrim const& usdPrim, SdfPath const &id,
423  UsdTimeCode time) const;
424 
425  // ---------------------------------------------------------------------- //
426  /// \name Utilities
427  // ---------------------------------------------------------------------- //
428 
429  /// The root transform provided by the delegate.
432 
433  /// A thread-local XformCache provided by the delegate.
435  void SetDelegate(UsdImagingDelegate* delegate);
436 
438  bool IsChildPath(SdfPath const& path) const;
439 
440  /// Returns true if the given prim is visible, taking into account inherited
441  /// visibility values. Inherited values are strongest, Usd has no notion of
442  /// "super vis/invis".
444  virtual bool GetVisible(
445  UsdPrim const& prim,
446  SdfPath const& cachePath,
447  UsdTimeCode time) const;
448 
449  /// Returns the purpose token for \p prim. If a non-empty \p
450  /// instanceInheritablePurpose is specified and the prim doesn't have an
451  /// explicitly authored or inherited purpose, it may inherit the
452  /// instancer's purpose if the instance has an explicit purpose.
454  virtual TfToken GetPurpose(
455  UsdPrim const& prim,
456  SdfPath const& cachePath,
457  TfToken const& instanceInheritablePurpose) const;
458 
459  /// Returns the purpose token for \p prim, but only if it is inheritable
460  /// by child prims (i.e. it is an explicitly authored purpose on the prim
461  /// itself or one of the prim's ancestors), otherwise it returns the empty
462  /// token.
464  TfToken GetInheritablePurpose(UsdPrim const& prim) const;
465 
466  /// Fetches the transform for the given prim at the given time from a
467  /// pre-computed cache of prim transforms. Requesting transforms at
468  /// incoherent times is currently inefficient.
470  virtual GfMatrix4d GetTransform(UsdPrim const& prim,
471  SdfPath const& cachePath,
473  bool ignoreRootTransform = false) const;
474 
475  /// Samples the transform for the given prim.
477  virtual size_t SampleTransform(UsdPrim const& prim,
478  SdfPath const& cachePath,
480  size_t maxNumSamples,
481  float *sampleTimes,
482  GfMatrix4d *sampleValues);
483 
484  /// Gets the value of the parameter named key for the given prim (which
485  /// has the given cache path) and given time. If outIndices is not nullptr
486  /// and the value has indices, it will return the unflattened value and set
487  /// outIndices to the value's associated indices.
489  virtual VtValue Get(UsdPrim const& prim,
490  SdfPath const& cachePath,
491  TfToken const& key,
492  UsdTimeCode time,
493  VtIntArray *outIndices) const;
494 
495  /// Gets the cullstyle of a specific path in the scene graph.
497  virtual HdCullStyle GetCullStyle(UsdPrim const& prim,
498  SdfPath const& cachePath,
499  UsdTimeCode time) const;
500 
501  /// Gets the material path for the given prim, walking up namespace if
502  /// necessary.
504  SdfPath GetMaterialUsdPath(UsdPrim const& prim) const;
505 
506  /// Gets the model:drawMode attribute for the given prim, walking up
507  /// the namespace if necessary.
509  TfToken GetModelDrawMode(UsdPrim const& prim);
510 
511  /// Computes the per-prototype instance indices for a UsdGeomPointInstancer.
512  /// XXX: This needs to be defined on the base class, to have access to the
513  /// delegate, but it's a clear violation of abstraction. This call is only
514  /// legal for prims of type UsdGeomPointInstancer; in other cases, the
515  /// returned array will be empty and the computation will issue errors.
518  UsdTimeCode time) const;
519 
520  /// Gets the topology object of a specific Usd prim. If the
521  /// adapter is a mesh it will return an HdMeshTopology,
522  /// if it is of type basis curves, it will return an HdBasisCurvesTopology.
523  /// If the adapter does not have a topology, it returns an empty VtValue.
525  virtual VtValue GetTopology(UsdPrim const& prim,
526  SdfPath const& cachePath,
527  UsdTimeCode time) const;
528 
529  /// Reads the extent from the given prim. If the extent is not authored,
530  /// an empty GfRange3d is returned, the extent will not be computed.
532  virtual GfRange3d GetExtent(UsdPrim const& prim,
533  SdfPath const& cachePath,
534  UsdTimeCode time) const;
535 
536  /// Reads double-sided from the given prim. If not authored, returns false
538  virtual bool GetDoubleSided(UsdPrim const& prim,
539  SdfPath const& cachePath,
540  UsdTimeCode time) const;
541 
543  virtual SdfPath GetMaterialId(UsdPrim const& prim,
544  SdfPath const& cachePath,
545  UsdTimeCode time) const;
546 
548  virtual VtValue GetMaterialResource(UsdPrim const& prim,
549  SdfPath const& cachePath,
550  UsdTimeCode time) const;
551 
552  // ---------------------------------------------------------------------- //
553  /// \name ExtComputations
554  // ---------------------------------------------------------------------- //
557  SdfPath const& cachePath) const;
558 
561  GetExtComputationInputs(UsdPrim const& prim,
562  SdfPath const& cachePath,
563  const UsdImagingInstancerContext* instancerContext)
564  const;
565 
568  GetExtComputationOutputs(UsdPrim const& prim,
569  SdfPath const& cachePath,
570  const UsdImagingInstancerContext* instancerContext)
571  const;
572 
576  UsdPrim const& prim,
577  SdfPath const& cachePath,
578  HdInterpolation interpolation,
579  const UsdImagingInstancerContext* instancerContext) const;
580 
582  virtual VtValue
584  UsdPrim const& prim,
585  SdfPath const& cachePath,
586  TfToken const& name,
588  const UsdImagingInstancerContext* instancerContext) const;
589 
591  virtual size_t
593  UsdPrim const& prim,
594  SdfPath const& cachePath,
595  TfToken const& name,
597  const UsdImagingInstancerContext* instancerContext,
598  size_t maxSampleCount,
599  float *sampleTimes,
600  VtValue *sampleValues);
601 
603  virtual std::string
605  UsdPrim const& prim,
606  SdfPath const& cachePath,
607  const UsdImagingInstancerContext* instancerContext) const;
608 
610  virtual VtValue
611  GetInstanceIndices(UsdPrim const& instancerPrim,
612  SdfPath const& instancerCachePath,
613  SdfPath const& prototypeCachePath,
614  UsdTimeCode time) const;
615 
616  // ---------------------------------------------------------------------- //
617  /// \name Render Index Compatibility
618  // ---------------------------------------------------------------------- //
619 
620  /// Returns true if the adapter can be populated into the target index.
621  virtual bool IsSupported(UsdImagingIndexProxy const* index) const {
622  return true;
623  }
624 
625 protected:
627 
628  template <typename T>
629  T _Get(UsdPrim const& prim, TfToken const& attrToken,
630  UsdTimeCode time) const {
631  T value;
632  prim.GetAttribute(attrToken).Get<T>(&value, time);
633  return value;
634  }
635 
636  template <typename T>
637  void _GetPtr(UsdPrim const& prim, TfToken const& key, UsdTimeCode time,
638  T* out) const {
639  prim.GetAttribute(key).Get<T>(out, time);
640  }
641 
644 
647 
649  _GetBlurScaleCache() const;
650 
652  UsdPrim _GetPrim(SdfPath const& usdPath) const;
653 
654  // Returns the prim adapter for the given \p prim, or an invalid pointer if
655  // no adapter exists. If \p prim is an instance and \p ignoreInstancing
656  // is \c true, the instancing adapter will be ignored and an adapter will
657  // be looked up based on \p prim's type.
660  _GetPrimAdapter(UsdPrim const& prim, bool ignoreInstancing = false) const;
661 
664  _GetAdapter(TfToken const& adapterKey) const;
665 
666  // XXX: Transitional API
667  // Returns the instance proxy prim path for a USD-instanced prim, given the
668  // instance chain leading to that prim. The paths are sorted from more to
669  // less local; the first path is the prim path (possibly in prototype), then
670  // instance paths (possibly in prototype); the last path is the prim or
671  // instance path in the scene.
674  SdfPathVector const& instancerChain) const;
675 
678 
679  // Converts \p cachePath to the path in the render index.
681  SdfPath _ConvertCachePathToIndexPath(SdfPath const& cachePath) const;
682 
683  // Converts \p indexPath to the path in the USD stage
685  SdfPath _ConvertIndexPathToCachePath(SdfPath const& indexPath) const;
686 
687  // Returns the material binding purpose from the renderer delegate.
690 
691  // Returns the material contexts from the renderer delegate.
694 
695  /// Returns whether custom shading of prims is enabled.
697  bool _GetSceneMaterialsEnabled() const;
698 
699  /// Returns whether lights found in the usdscene are enabled.
701  bool _GetSceneLightsEnabled() const;
702 
703  // Returns true if render delegate wants primvars to be filtered based.
704  // This will filter the primvars based on the bound material primvar needs.
706  bool _IsPrimvarFilteringNeeded() const;
707 
708  // Returns the shader source type from the render delegate.
711 
712  // Returns \c true if \p usdPath is included in the scene delegate's
713  // invised path list.
715  bool _IsInInvisedPaths(SdfPath const& usdPath) const;
716 
717  // Determines if an attribute is varying and if so, sets the given
718  // \p dirtyFlag in the \p dirtyFlags and increments a perf counter. Returns
719  // true if the attribute is varying.
720  //
721  // If \p exists is non-null, _IsVarying will store whether the attribute
722  // was found. If the attribute is not found, it counts as non-varying.
723  //
724  // This only sets the dirty bit, never un-sets. The caller is responsible
725  // for setting the initial state correctly.
727  bool _IsVarying(UsdPrim prim, TfToken const& attrName,
728  HdDirtyBits dirtyFlag, TfToken const& perfToken,
729  HdDirtyBits* dirtyFlags, bool isInherited,
730  bool* exists = nullptr) const;
731 
732  // Determines if the prim's transform (CTM) is varying and if so, sets the
733  // given \p dirtyFlag in the \p dirtyFlags and increments a perf counter.
734  // Returns true if the prim's transform is varying.
735  //
736  // This only sets the dirty bit, never un-sets. The caller is responsible
737  // for setting the initial state correctly.
739  bool _IsTransformVarying(UsdPrim prim,
740  HdDirtyBits dirtyFlag,
741  TfToken const& perfToken,
742  HdDirtyBits* dirtyFlags) const;
743 
744  // Convenience method for adding or updating a primvar descriptor.
745  // Role defaults to empty token (none). Indexed defaults to false.
747  void _MergePrimvar(
749  TfToken const& name,
751  TfToken const& role = TfToken(),
752  bool indexed = false) const;
753 
754  // Convenience method for removing a primvar descriptor.
756  void _RemovePrimvar(
758  TfToken const& name) const;
759 
760  // Convenience method for computing a primvar. The primvar will only be
761  // added to the list of prim desc if there is no primvar of the same
762  // name already present. Thus, "local" primvars should be merged before
763  // inherited primvars.
766  UsdPrim const& prim,
767  UsdGeomPrimvar const& primvar,
769  HdPrimvarDescriptorVector* primvarDescs,
770  HdInterpolation *interpOverride = nullptr) const;
771 
772  // Returns true if the property name has the "primvars:" prefix.
774  static bool _HasPrimvarsPrefix(TfToken const& propertyName);
775 
776  // Convenience methods to figure out what changed about the primvar and
777  // return the appropriate dirty bit.
778  // Caller can optionally pass in a dirty bit to set for primvar value
779  // changes. This is useful for attributes that have a special dirty bit
780  // such as normals and widths.
781  //
782  // Handle USD attributes that are treated as primvars by Hydra. This
783  // requires the interpolation to be passed in, as well as the primvar
784  // name passed to Hydra.
787  UsdPrim const& prim,
788  SdfPath const& cachePath,
789  TfToken const& propertyName,
790  TfToken const& primvarName,
791  HdInterpolation const& primvarInterp,
792  HdDirtyBits valueChangeDirtyBit = HdChangeTracker::DirtyPrimvar) const;
793 
794  // Handle UsdGeomPrimvars that use the "primvars:" prefix, while also
795  // accommodating inheritance.
798  UsdPrim const& prim,
799  SdfPath const& cachePath,
800  TfToken const& propertyName,
801  HdDirtyBits valueChangeDirtyBit = HdChangeTracker::DirtyPrimvar,
802  bool inherited = true) const;
803 
804  virtual void _RemovePrim(SdfPath const& cachePath,
806 
807  // Utility to resync bound dependencies of a particular usd path.
808  // This is necessary for the resync processing of certain prim types
809  // (e.g. materials).
811  void _ResyncDependents(SdfPath const& usdPath,
813 
816 
818  UsdStageRefPtr _GetStage() const;
819 
822  _GetCoordSysBindings(UsdPrim const& prim) const;
823 
826  _GetInheritedPrimvars(UsdPrim const& prim) const;
827 
830  TfToken const& primvarName) const;
831 
834 
837 
840 
842  bool _DoesDelegateSupportCoordSys() const;
843 
844  // Conversion functions between usd and hydra enums.
846  static HdInterpolation _UsdToHdInterpolation(TfToken const& usdInterp);
848  static TfToken _UsdToHdRole(TfToken const& usdRole);
849 
850 private:
851  UsdImagingDelegate* _delegate;
852 };
853 
855 public:
856  virtual UsdImagingPrimAdapterSharedPtr New() const = 0;
857 };
858 
859 template <class T>
861 public:
863  {
864  return std::make_shared<T>();
865  }
866 };
867 
868 
870 
871 #endif // PXR_USD_IMAGING_USD_IMAGING_PRIM_ADAPTER_H
static USDIMAGING_API bool _HasPrimvarsPrefix(TfToken const &propertyName)
Returns true if the adapter can be populated into the target index.
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)
virtual USDIMAGING_API VtValue GetTopology(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
virtual USDIMAGING_API SdfPathVector GetInstancerPrototypes(UsdPrim const &usdPrim, SdfPath const &cachePath) const
Return the list of known prototypes of this prim.
virtual USDIMAGING_API void InvokeComputation(SdfPath const &cachePath, HdExtComputationContext *context)
virtual HdDirtyBits ProcessPropertyChange(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &propertyName)=0
virtual USDIMAGING_API PxOsdSubdivTags GetSubdivTags(UsdPrim const &usdPrim, SdfPath const &cachePath, UsdTimeCode time) const
Get the subdiv tags for this prim.
HdCullStyle
Definition: enums.h:122
virtual UsdImagingPrimAdapterSharedPtr New() const =0
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Definition: attribute.h:431
#define USDIMAGING_API
Definition: api.h:40
T _Get(UsdPrim const &prim, TfToken const &attrToken, UsdTimeCode time) const
Returns true if the adapter can be populated into the target index.
Definition: primAdapter.h:629
virtual USDIMAGING_API SdfPathVector GetScenePrimPaths(SdfPath const &cachePath, std::vector< int > const &instanceIndices, std::vector< HdInstancerContext > *instancerCtxs) const
USDIMAGING_API Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes() const
Returns true if the adapter can be populated into the target index.
USDIMAGING_API bool IsChildPath(SdfPath const &path) const
The root transform provided by the delegate.
USDIMAGING_API UsdImagingPrimvarDescCache * _GetPrimvarDescCache() const
Returns true if the adapter can be populated into the target index.
USDIMAGING_API void SetDelegate(UsdImagingDelegate *delegate)
A thread-local XformCache provided by the delegate.
USDIMAGING_API VtArray< VtIntArray > GetPerPrototypeIndices(UsdPrim const &prim, UsdTimeCode time) const
GT_API const UT_StringHolder time
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.
uint32_t HdDirtyBits
Definition: types.h:158
USDIMAGING_API UsdImaging_InheritedPrimvarStrategy::value_type _GetInheritedPrimvars(UsdPrim const &prim) const
Returns true if the adapter can be populated into the target index.
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
virtual USDIMAGING_API SdfPath GetInstancerId(UsdPrim const &usdPrim, SdfPath const &cachePath) const
Return the instancerId for this prim.
std::vector< HdExtComputationInputDescriptor > HdExtComputationInputDescriptorVector
virtual void UpdateForTime(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, HdDirtyBits requestedBits, UsdImagingInstancerContext const *instancerContext=nullptr) const =0
virtual USDIMAGING_API GfMatrix4d GetTransform(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time, bool ignoreRootTransform=false) const
USDIMAGING_API SdfPath GetMaterialUsdPath(UsdPrim const &prim) const
virtual USDIMAGING_API void MarkRenderTagDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index)
USDIMAGING_API UsdPrim _GetPrim(SdfPath const &usdPath) const
Returns true if the adapter can be populated into the target index.
virtual USDIMAGING_API void MarkVisibilityDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index)
USDIMAGING_API bool _IsTransformVarying(UsdPrim prim, HdDirtyBits dirtyFlag, TfToken const &perfToken, HdDirtyBits *dirtyFlags) const
Returns true if the adapter can be populated into the target index.
USDIMAGING_API HdDirtyBits _ProcessPrefixedPrimvarPropertyChange(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &propertyName, HdDirtyBits valueChangeDirtyBit=HdChangeTracker::DirtyPrimvar, bool inherited=true) const
Returns true if the adapter can be populated into the target index.
virtual USDIMAGING_API HdExtComputationPrimvarDescriptorVector GetExtComputationPrimvars(UsdPrim const &prim, SdfPath const &cachePath, HdInterpolation interpolation, const UsdImagingInstancerContext *instancerContext) const
std::vector< HdExtComputationOutputDescriptor > HdExtComputationOutputDescriptorVector
USDIMAGING_API UsdImaging_CollectionCache & _GetCollectionCache() const
Returns true if the adapter can be populated into the target index.
GLuint const GLchar * name
Definition: glcorearb.h:786
USDIMAGING_API Usd_PrimFlagsConjunction _GetDisplayPredicate() const
Returns true if the adapter can be populated into the target index.
USDIMAGING_API SdfPath _ConvertCachePathToIndexPath(SdfPath const &cachePath) const
Returns true if the adapter can be populated into the target index.
USDIMAGING_API const UsdImagingPrimAdapterSharedPtr & _GetAdapter(TfToken const &adapterKey) const
Returns true if the adapter can be populated into the target index.
virtual USDIMAGING_API size_t SampleExtComputationInput(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &name, UsdTimeCode time, const UsdImagingInstancerContext *instancerContext, size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues)
virtual USDIMAGING_API void MarkLightParamsDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index)
virtual USDIMAGING_API bool ShouldCullChildren() const
virtual USDIMAGING_API void ProcessPrimResync(SdfPath const &cachePath, UsdImagingIndexProxy *index)
virtual USDIMAGING_API TfTokenVector GetImagingSubprims()
UsdImaging_BlurScaleCache * _GetBlurScaleCache() const
Returns true if the adapter can be populated into the target index.
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 bool _IsPrimvarFilteringNeeded() const
Returns true if the adapter can be populated into the target index.
Base class of all factory types.
Definition: type.h:73
std::vector< std::pair< SdfPath, int > > HdInstancerContext
Instancer context: a pair of instancer paths and instance indices.
Definition: sceneDelegate.h:60
virtual void TrackVariability(UsdPrim const &prim, SdfPath const &cachePath, HdDirtyBits *timeVaryingBits, UsdImagingInstancerContext const *instancerContext=nullptr) const =0
USDIMAGING_API bool _IsInInvisedPaths(SdfPath const &usdPath) const
Returns true if the adapter can be populated into the target index.
virtual USDIMAGING_API std::string GetExtComputationKernel(UsdPrim const &prim, SdfPath const &cachePath, const UsdImagingInstancerContext *instancerContext) const
virtual void _RemovePrim(SdfPath const &cachePath, UsdImagingIndexProxy *index)=0
Returns true if the adapter can be populated into the target index.
USDIMAGING_API void _RemovePrimvar(HdPrimvarDescriptorVector *vec, TfToken const &name) const
Returns true if the adapter can be populated into the target index.
Definition: token.h:87
static USDIMAGING_API HdInterpolation _UsdToHdInterpolation(TfToken const &usdInterp)
Returns true if the adapter can be populated into the target index.
GLuint64EXT * result
Definition: glew.h:14311
USDIMAGING_API UsdGeomPrimvar _GetInheritedPrimvar(UsdPrim const &prim, TfToken const &primvarName) const
Returns true if the adapter can be populated into the target index.
static USDIMAGING_API TfToken _UsdToHdRole(TfToken const &usdRole)
Returns true if the adapter can be populated into the target index.
virtual USDIMAGING_API std::vector< VtArray< TfToken > > GetInstanceCategories(UsdPrim const &prim)
Return an array of the categories used by each instance.
virtual USDIMAGING_API bool ShouldIgnoreNativeInstanceSubtrees() const
virtual USDIMAGING_API GfRange3d GetExtent(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
GLuint interp
Definition: glew.h:8307
virtual USDIMAGING_API void MarkWindowPolicyDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index)
virtual USDIMAGING_API VtValue GetMaterialResource(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
The root transform provided by the delegate.
virtual USDIMAGING_API HdExtComputationOutputDescriptorVector GetExtComputationOutputs(UsdPrim const &prim, SdfPath const &cachePath, const UsdImagingInstancerContext *instancerContext) const
USDIMAGING_API bool _GetSceneLightsEnabled() const
Returns whether lights found in the usdscene are enabled.
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
virtual USDIMAGING_API SdfPath GetDataSharingId(SdfPath const &cachePath) const
virtual USDIMAGING_API void MarkReprDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index)
USDIMAGING_API UsdStageRefPtr _GetStage() const
Returns true if the adapter can be populated into the target index.
USDIMAGING_API TfToken _GetMaterialBindingPurpose() const
Returns true if the adapter can be populated into the target index.
USDIMAGING_API const UsdImagingPrimAdapterSharedPtr & _GetPrimAdapter(UsdPrim const &prim, bool ignoreInstancing=false) const
Returns true if the adapter can be populated into the target index.
virtual USDIMAGING_API void MarkCullStyleDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index)
USDIMAGING_API bool _IsVarying(UsdPrim prim, TfToken const &attrName, HdDirtyBits dirtyFlag, TfToken const &perfToken, HdDirtyBits *dirtyFlags, bool isInherited, bool *exists=nullptr) const
Returns true if the adapter can be populated into the target index.
Definition: prim.h:132
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
OIIO_UTIL_API bool exists(string_view path) noexcept
static USDIMAGING_API bool ShouldCullSubtree(UsdPrim const &prim)
Definition: types.h:166
HighlightMode
Selection modes allow differentiation in selection highlight behavior.
Definition: selection.h:55
Definition: path.h:290
virtual USDIMAGING_API VtValue GetInstanceIndices(UsdPrim const &instancerPrim, SdfPath const &instancerCachePath, SdfPath const &prototypeCachePath, UsdTimeCode time) const
virtual USDIMAGING_API void MarkCollectionsDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index)
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.
std::vector< HdVolumeFieldDescriptor > HdVolumeFieldDescriptorVector
virtual USDIMAGING_API HdExtComputationInputDescriptorVector GetExtComputationInputs(UsdPrim const &prim, SdfPath const &cachePath, const UsdImagingInstancerContext *instancerContext) const
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:211
virtual SdfPath Populate(UsdPrim const &prim, UsdImagingIndexProxy *index, UsdImagingInstancerContext const *instancerContext=nullptr)=0
virtual USDIMAGING_API ~UsdImagingPrimAdapter()
USDIMAGING_API UsdTimeCode _GetTimeWithOffset(float offset) const
Returns true if the adapter can be populated into the target index.
USDIMAGING_API TfTokenVector _GetMaterialRenderContexts() const
Returns true if the adapter can be populated into the target index.
virtual USDIMAGING_API bool IsInstancerAdapter() const
USDIMAGING_API SdfPath _ConvertIndexPathToCachePath(SdfPath const &indexPath) const
Returns true if the adapter can be populated into the target index.
USDIMAGING_API TfToken GetModelDrawMode(UsdPrim const &prim)
virtual void MarkDirty(UsdPrim const &prim, SdfPath const &cachePath, HdDirtyBits dirty, UsdImagingIndexProxy *index)=0
virtual USDIMAGING_API GfMatrix4d GetRelativeInstancerTransform(SdfPath const &instancerPath, SdfPath const &protoInstancerPath, UsdTimeCode time) const
virtual USDIMAGING_API TfToken GetPurpose(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &instanceInheritablePurpose) const
virtual USDIMAGING_API bool CanPopulateUsdInstance() const
virtual USDIMAGING_API TfToken GetImagingSubprimType(TfToken const &subprim)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1394
virtual USDIMAGING_API HdContainerDataSourceHandle GetImagingSubprimData(TfToken const &subprim, UsdPrim const &prim, const UsdImagingDataSourceStageGlobals &stageGlobals)
virtual USDIMAGING_API GfMatrix4d GetInstancerTransform(UsdPrim const &instancerPrim, SdfPath const &instancerPath, UsdTimeCode time) const
USDIMAGING_API TfToken GetInheritablePurpose(UsdPrim const &prim) const
virtual USDIMAGING_API bool GetVisible(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
USDIMAGING_API SdfPath _GetPrimPathFromInstancerChain(SdfPathVector const &instancerChain) const
Returns true if the adapter can be populated into the target index.
virtual USDIMAGING_API const TfTokenVector & GetExtComputationSceneInputNames(SdfPath const &cachePath) const
virtual USDIMAGING_API void MarkMaterialDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index)
virtual USDIMAGING_API void ProcessPrimRemoval(SdfPath const &cachePath, UsdImagingIndexProxy *index)
virtual USDIMAGING_API HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors(UsdPrim const &usdPrim, SdfPath const &id, UsdTimeCode time) const
void _GetPtr(UsdPrim const &prim, TfToken const &key, UsdTimeCode time, T *out) const
Returns true if the adapter can be populated into the target index.
Definition: primAdapter.h:637
GLuint index
Definition: glcorearb.h:786
virtual USDIMAGING_API VtValue GetExtComputationInput(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &name, UsdTimeCode time, const UsdImagingInstancerContext *instancerContext) const
virtual USDIMAGING_API size_t SampleInstancerTransform(UsdPrim const &instancerPrim, SdfPath const &instancerPath, UsdTimeCode time, size_t maxNumSamples, float *sampleTimes, GfMatrix4d *sampleValues)
HdInterpolation
Definition: enums.h:194
USDIMAGING_API GfMatrix4d GetRootTransform() const
The root transform provided by the delegate.
USDIMAGING_API GfInterval _GetCurrentTimeSamplingInterval()
Returns true if the adapter can be populated into the target index.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
USDIMAGING_API UsdImaging_CoordSysBindingStrategy::value_type _GetCoordSysBindings(UsdPrim const &prim) const
Returns true if the adapter can be populated into the target index.
std::shared_ptr< UsdImagingPrimAdapter > UsdImagingPrimAdapterSharedPtr
virtual USDIMAGING_API void MarkRefineLevelDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index)
GLsizei const GLfloat * value
Definition: glcorearb.h:824
virtual bool IsSupported(UsdImagingIndexProxy const *index) const
Returns true if the adapter can be populated into the target index.
Definition: primAdapter.h:621
std::shared_ptr< PrimvarRecord > value_type
GLintptr offset
Definition: glcorearb.h:665
virtual USDIMAGING_API HdDirtyBits ProcessPrimChange(UsdPrim const &prim, SdfPath const &cachePath, TfTokenVector const &changedFields)
virtual USDIMAGING_API void MarkTransformDirty(UsdPrim const &prim, SdfPath const &cachePath, UsdImagingIndexProxy *index)
virtual UsdImagingPrimAdapterSharedPtr New() const
Definition: primAdapter.h:862
USDIMAGING_API bool _GetSceneMaterialsEnabled() const
Returns whether custom shading of prims is enabled.
std::vector< HdPrimvarDescriptor > HdPrimvarDescriptorVector
virtual USDIMAGING_API SdfPath GetScenePrimPath(SdfPath const &cachePath, int instanceIndex, HdInstancerContext *instancerCtx) const
USDIMAGING_API void _ResyncDependents(SdfPath const &usdPath, UsdImagingIndexProxy *index)
Returns true if the adapter can be populated into the target index.
USDIMAGING_API HdDirtyBits _ProcessNonPrefixedPrimvarPropertyChange(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &propertyName, TfToken const &primvarName, HdInterpolation const &primvarInterp, HdDirtyBits valueChangeDirtyBit=HdChangeTracker::DirtyPrimvar) const
Returns true if the adapter can be populated into the target index.
USDIMAGING_API void _MergePrimvar(HdPrimvarDescriptorVector *vec, TfToken const &name, HdInterpolation interp, TfToken const &role=TfToken(), bool indexed=false) const
Returns true if the adapter can be populated into the target index.
std::shared_ptr< class HdSelection > HdSelectionSharedPtr
Definition: selection.h:40
USD_API UsdAttribute GetAttribute(const TfToken &attrName) const
virtual USDIMAGING_API VtValue Get(UsdPrim const &prim, SdfPath const &cachePath, TfToken const &key, UsdTimeCode time, VtIntArray *outIndices) const
USDIMAGING_API TfTokenVector _GetShaderSourceTypes() const
Returns true if the adapter can be populated into the target index.
Definition: value.h:166
UsdImaging_NonlinearSampleCountCache * _GetNonlinearSampleCountCache() const
Returns true if the adapter can be populated into the target index.
virtual USDIMAGING_API SdfPath GetMaterialId(UsdPrim const &prim, SdfPath const &cachePath, UsdTimeCode time) const
The root transform provided by the delegate.
USDIMAGING_API bool _DoesDelegateSupportCoordSys() const
Returns true if the adapter can be populated into the target index.
std::vector< HdExtComputationPrimvarDescriptor > HdExtComputationPrimvarDescriptorVector
virtual USDIMAGING_API bool PopulateSelection(HdSelection::HighlightMode const &highlightMode, SdfPath const &cachePath, UsdPrim const &usdPrim, int const hydraInstanceIndex, VtIntArray const &parentInstanceIndices, HdSelectionSharedPtr const &result) const
USDIMAGING_API void _ComputeAndMergePrimvar(UsdPrim const &prim, UsdGeomPrimvar const &primvar, UsdTimeCode time, HdPrimvarDescriptorVector *primvarDescs, HdInterpolation *interpOverride=nullptr) const
Returns true if the adapter can be populated into the target index.