HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
delegate.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_IMAGING_USD_IMAGING_DELEGATE_H
8 #define PXR_USD_IMAGING_USD_IMAGING_DELEGATE_H
9 
10 /// \file usdImaging/delegate.h
11 
12 #include "pxr/pxr.h"
19 
21 
25 #include "pxr/imaging/hd/version.h"
26 
28 #include "pxr/usd/sdf/path.h"
29 #include "pxr/usd/sdf/pathTable.h"
30 #include "pxr/usd/usd/attribute.h"
31 #include "pxr/usd/usd/notice.h"
32 #include "pxr/usd/usd/prim.h"
33 #include "pxr/usd/usd/stage.h"
34 #include "pxr/usd/usdGeom/cube.h"
35 #include "pxr/usd/usdGeom/sphere.h"
37 #include "pxr/base/vt/value.h"
38 
39 #include "pxr/base/gf/range3d.h"
40 #include "pxr/base/gf/interval.h"
42 #include "pxr/base/tf/hashmap.h"
43 #include "pxr/base/tf/hashset.h"
45 
46 #include <tbb/spin_rw_mutex.h>
47 #include <map>
48 #include <string>
49 
51 
52 
54 typedef std::vector<UsdPrim> UsdPrimVector;
55 
59 
60 using UsdImagingPrimAdapterSharedPtr = std::shared_ptr<UsdImagingPrimAdapter>;
61 
62 /// \class UsdImagingDelegate
63 ///
64 /// The primary translation layer between the Hydra (Hd) core and the Usd
65 /// scene graph.
66 ///
68  typedef UsdImagingDelegate This;
69 public:
70 
72 
74  UsdImagingDelegate(HdRenderIndex *parentIndex,
75  SdfPath const& delegateID);
76 
78  virtual ~UsdImagingDelegate();
79 
81  virtual void Sync(HdSyncRequestVector* request) override;
82 
83  // Helper for clients who don't want to drive the sync behavior (unit
84  // tests). Note this method is not virtual.
86  void SyncAll(bool includeUnvarying);
87 
88  /// Populates the rootPrim in the HdRenderIndex.
90  void Populate(UsdPrim const& rootPrim);
91 
92  /// Populates the rootPrim in the HdRenderIndex, excluding all paths in the
93  /// \p excludedPrimPaths, as well as their prim children.
95  void Populate(UsdPrim const& rootPrim,
96  SdfPathVector const& excludedPrimPaths,
97  SdfPathVector const &invisedPrimPaths=SdfPathVector());
98 
99  /// For each delegate in \p delegates, sets the current time from
100  /// which data wil be read to the corresponding time in \p times.
101  ///
102  /// This is equivalent to calling SetTime on each delegate individually.
103  /// However, this method will try to parallelize certain operations,
104  /// making it potentially more efficient.
106  static void SetTimes(const std::vector<UsdImagingDelegate*>& delegates,
107  const std::vector<UsdTimeCode>& times);
108 
109  /// Sets the current time from which data will be read by the delegate.
110  ///
111  /// Changing the current time immediately triggers invalidation in the
112  /// HdChangeTracker. Redundantly setting the time to its existing value is a
113  /// no-op and will not trigger invalidation.
115  void SetTime(UsdTimeCode time);
116 
117  /// Returns the current time.
118  UsdTimeCode GetTime() const { return _time; }
119 
120  /// Apply a relative offset to the current time.
121  /// This has no effect in the case of the default USD timecode.
122  UsdTimeCode GetTimeWithOffset(float offset) const;
123 
124  /// Applies any scene edits which have been queued up by notices from USD.
126  void ApplyPendingUpdates();
127 
128  /// Returns the refinement level that is used when prims have no explicit
129  /// level set.
130  ///
131  /// The refinement level indicates how many iterations to apply when
132  /// subdividing subdivision surfaces or other refinable primitives.
133  ///
134  /// Refinement level is always in the range [0,8].
135  int GetRefineLevelFallback() const { return _refineLevelFallback; }
136 
137  /// Sets the fallback refinement level to \p level, triggers dirty
138  /// refine level bit to be set on all Rprims that don't have explicit refine
139  /// levels set.
140  ///
141  /// Level is expected to be in the range [0,8], where 0 indicates no
142  /// refinement.
144  void SetRefineLevelFallback(int level);
145 
146  /// Removes any explicit refine level set for the given USD prim.
147  /// Marks dirty if a change in level occurs.
149  void ClearRefineLevel(SdfPath const& usdPath);
150 
151  /// Sets an explicit refinement level for the given USD prim.
152  /// If no level is explicitly set, the fallback is used;
153  /// see GetRefineLevelFallback().
154  /// If setting an explicit level does not change the effective level, no
155  /// dirty bit is set.
157  void SetRefineLevel(SdfPath const& usdPath, int level);
158 
159  /// Returns the fallback repr name.
160  HdReprSelector GetReprFallback() const { return _reprFallback; }
161 
162  /// Sets the fallback repr name. Note that currently UsdImagingDelegate
163  /// doesn't support per-prim repr.
165  void SetReprFallback(HdReprSelector const &repr);
166 
167  /// Returns the fallback cull style.
168  HdCullStyle GetCullStyleFallback() const { return _cullStyleFallback; }
169 
170  /// Sets the fallback cull style.
172  void SetCullStyleFallback(HdCullStyle cullStyle);
173 
174  /// Sets the root transform for the entire delegate, which is applied to all
175  /// render prims generated. Setting this value will immediately invalidate
176  /// existing rprim transforms.
178  void SetRootTransform(GfMatrix4d const& xf);
179 
180  /// Returns the root transform for the entire delegate.
181  const GfMatrix4d &GetRootTransform() const { return _rootXf; }
182 
183  /// Sets the root visibility for the entire delegate, which is applied to
184  /// all render prims generated. Setting this value will immediately
185  /// invalidate existing rprim visibility.
187  void SetRootVisibility(bool isVisible);
188 
189  /// Returns the root visibility for the entire delegate.
190  bool GetRootVisibility() const { return _rootIsVisible; }
191 
192  /// Sets the root instancer id for the entire delegate, which is used as a
193  /// fallback value for GetInstancerId.
195  void SetRootInstancerId(SdfPath const& instancerId);
196 
197  /// Returns the root instancer id for the entire delegate.
198  SdfPath GetRootInstancerId() const { return _rootInstancerId; }
199 
200  /// Set the list of paths that must be invised.
202  void SetInvisedPrimPaths(SdfPathVector const &invisedPaths);
203 
204  /// Set transform value overrides on a set of paths.
206  void SetRigidXformOverrides(RigidXformOverridesMap const &overrides);
207 
208  /// Sets display of prims with purpose "render"
210  void SetDisplayRender(const bool displayRender);
211  bool GetDisplayRender() const { return _displayRender; }
212 
213  /// Sets display of prims with purpose "proxy"
215  void SetDisplayProxy(const bool displayProxy);
216  bool GetDisplayProxy() const { return _displayProxy; }
217 
218  /// Sets display of prims with purpose "guide"
220  void SetDisplayGuides(const bool displayGuides);
221  bool GetDisplayGuides() const { return _displayGuides; }
222 
223  /// Returns whether draw modes are enabled.
225  void SetUsdDrawModesEnabled(bool enableUsdDrawModes);
226  bool GetUsdDrawModesEnabled() const { return _enableUsdDrawModes; }
227 
228  /// Enables custom shading on prims.
230  void SetSceneMaterialsEnabled(bool enable);
231 
232  /// Enables lights found in the usdscene.
234  void SetSceneLightsEnabled(bool enable);
235 
236  /// Set the window policy on all scene cameras. This comes from
237  /// the application.
240 
241  /// Sets display of unloaded prims as bounding boxes.
242  /// Unloaded prims will need to satisfy one of the following set of
243  /// conditions in order to see them:
244  /// 1. The prim is a UsdGeomBoundable with an authored 'extent' attribute.
245  /// 2. The prim is a UsdPrim.IsModel() and has an authored 'extentsHint'
246  /// attribute (see UsdGeomModelAPI::GetExtentsHint).
247  /// Effective only for delegates that support draw modes (see
248  /// GetUsdDrawModesEnabled()).
250  void SetDisplayUnloadedPrimsWithBounds(bool displayUnloaded);
252  return _displayUnloadedPrimsWithBounds;
253  }
254 
255  /// Setup for the shutter open and close to be used for motion sampling.
257  void SetCameraForSampling(SdfPath const& id);
258 
259  /// Returns the current interval that will be used when using the
260  /// sample* API in the scene delegate.
263 
264  // ---------------------------------------------------------------------- //
265  // See HdSceneDelegate for documentation of the following virtual methods.
266  // ---------------------------------------------------------------------- //
268  virtual TfToken GetRenderTag(SdfPath const& id) override;
270  virtual HdMeshTopology GetMeshTopology(SdfPath const& id) override;
273  override;
275 
276  // XXX: animated subdiv tags are not currently supported
277  // XXX: subdiv tags currently fetched on-demand
279  virtual SubdivTags GetSubdivTags(SdfPath const& id) override;
280 
282  virtual GfRange3d GetExtent(SdfPath const & id) override;
284  virtual GfMatrix4d GetTransform(SdfPath const & id) override;
286  virtual bool GetVisible(SdfPath const & id) override;
288  virtual bool GetDoubleSided(SdfPath const & id) override;
290  virtual HdCullStyle GetCullStyle(SdfPath const &id) override;
291 
292  /// Gets the explicit display style for the given prim, if no refine level
293  /// is explicitly set, the fallback is returned; also see
294  /// GetRefineLevelFallback().
296  virtual HdDisplayStyle GetDisplayStyle(SdfPath const& id) override;
297 
299  HdModelDrawMode GetModelDrawMode(SdfPath const& id) override;
300 
302  virtual VtValue Get(SdfPath const& id, TfToken const& key) override;
304  virtual VtValue GetIndexedPrimvar(SdfPath const& id,
305  TfToken const& key,
306  VtIntArray *outIndices) override;
309  virtual GetCoordSysBindings(SdfPath const& id) override;
311  virtual HdReprSelector GetReprSelector(SdfPath const &id) override;
313  virtual VtArray<TfToken> GetCategories(SdfPath const &id) override;
315  virtual std::vector<VtArray<TfToken>>
316  GetInstanceCategories(SdfPath const &instancerId) override;
319  GetPrimvarDescriptors(SdfPath const& id,
320  HdInterpolation interpolation) override;
322  virtual VtIntArray GetInstanceIndices(SdfPath const &instancerId,
323  SdfPath const &prototypeId) override;
325  virtual GfMatrix4d GetInstancerTransform(SdfPath const &instancerId)
326  override;
327 
329  virtual SdfPath GetInstancerId(SdfPath const &primId) override;
330 
332  virtual SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override;
333 
334  // Motion samples
336  virtual size_t
337  SampleTransform(SdfPath const & id, size_t maxNumSamples,
338  float *times, GfMatrix4d *samples) override;
340  virtual size_t
341  SampleInstancerTransform(SdfPath const &instancerId,
342  size_t maxSampleCount, float *times,
343  GfMatrix4d *samples) override;
345  virtual size_t
346  SamplePrimvar(SdfPath const& id, TfToken const& key,
347  size_t maxNumSamples, float *times,
348  VtValue *samples) override;
349 
351  virtual size_t
352  SampleIndexedPrimvar(SdfPath const& id, TfToken const& key,
353  size_t maxNumSamples, float *times,
354  VtValue *samples, VtIntArray *indices) override;
355 
356  // Material Support
358  virtual SdfPath GetMaterialId(SdfPath const &rprimId) override;
359 
361  virtual VtValue GetMaterialResource(SdfPath const &materialId) override;
362 
363  // Light Support
365  virtual VtValue GetLightParamValue(SdfPath const &id,
366  TfToken const &paramName) override;
367  // Camera Support
369  virtual VtValue GetCameraParamValue(SdfPath const &id,
370  TfToken const &paramName) override;
371 
372  // Volume Support
375  GetVolumeFieldDescriptors(SdfPath const &volumeId) override;
376 
378  virtual VtValue GetVolumeParamValue(SdfPath const &id,
379  TfToken const &paramName) override;
380 
381  // Picking path resolution
382  // Resolves a \p rprimId and \p instanceIndex back to the original USD
383  // gprim and instance index. For point-instanced prims, \p instanceContext
384  // returns extra information about which instance this is of which level of
385  // point-instancer. For example:
386  // /World/PI instances /World/PI/proto/PI
387  // /World/PI/proto/PI instances /World/PI/proto/PI/proto/Gprim
388  // instancerContext = [/World/PI, 0], [/World/PI/proto/PI, 1] means that
389  // this instance represents "protoIndex = 0" of /World/PI, etc.
390 
392  virtual SdfPath
393  GetScenePrimPath(SdfPath const& rprimId,
394  int instanceIndex,
395  HdInstancerContext *instancerContext = nullptr) override;
396 
398  virtual SdfPathVector
399  GetScenePrimPaths(SdfPath const& rprimId,
400  std::vector<int> instanceIndices,
401  std::vector<HdInstancerContext> *instancerContexts = nullptr) override;
402 
404  virtual SdfPath GetDataSharingId(SdfPath const& primId) override;
405 
406  // ExtComputation support
409  GetExtComputationSceneInputNames(SdfPath const& computationId) override;
410 
413  GetExtComputationInputDescriptors(SdfPath const& computationId) override;
414 
417  GetExtComputationOutputDescriptors(SdfPath const& computationId) override;
418 
421  GetExtComputationPrimvarDescriptors(SdfPath const& computationId,
422  HdInterpolation interpolation) override;
423 
425  VtValue GetExtComputationInput(SdfPath const& computationId,
426  TfToken const& input) override;
427 
429  size_t SampleExtComputationInput(SdfPath const& computationId,
430  TfToken const& input,
431  size_t maxSampleCount,
432  float *sampleTimes,
433  VtValue *sampleValues) override;
434 
436  std::string GetExtComputationKernel(SdfPath const& computationId) override;
437 
439  void InvokeExtComputation(SdfPath const& computationId,
440  HdExtComputationContext *context) override;
441 
442 public:
443  // Converts a cache path to a path in the render index.
446  SdfPathMap::const_iterator it = _cache2indexPath.find(cachePath);
447  if (it != _cache2indexPath.end()) {
448  return it->second;
449  }
450 
451  // For pure/plain usdImaging, there is no prefix to replace
452  SdfPath const &delegateID = GetDelegateID();
453  if (delegateID == SdfPath::AbsoluteRootPath()) {
454  return cachePath;
455  }
456  if (cachePath.IsEmpty()) {
457  return cachePath;
458  }
459 
460  return cachePath.ReplacePrefix(SdfPath::AbsoluteRootPath(), delegateID);
461  }
462 
463  /// Convert the given Hydra ID to a UsdImaging cache path,
464  /// by stripping the scene delegate prefix.
465  ///
466  /// The UsdImaging cache path is the same as a USD prim path,
467  /// except for instanced prims, which get a name-mangled encoding.
470  SdfPathMap::const_iterator it = _index2cachePath.find(indexPath);
471  if (it != _index2cachePath.end()) {
472  return it->second;
473  }
474 
475  // For pure/plain usdImaging, there is no prefix to replace
476  SdfPath const &delegateID = GetDelegateID();
477  if (delegateID == SdfPath::AbsoluteRootPath()) {
478  return indexPath;
479  }
480 
481  return indexPath.ReplacePrefix(delegateID, SdfPath::AbsoluteRootPath());
482  }
483 
484  /// Populate HdxSelection for given \p path (root) and \p instanceIndex.
485  /// If indexPath is an instancer and instanceIndex is ALL_INSTANCES (-1),
486  /// all instances will be selected.
487  ///
488  /// Note: if usdPath points to a gprim, "instanceIndex" (if provided)
489  /// is assumed to be the hydra-computed instance index returned from
490  /// picking code.
491  ///
492  /// If usdPath points to a point instancer, "instanceIndex" is assumed to
493  /// be the instance of the point instancer to selection highlight (e.g.
494  /// instance N of the protoIndices array). This would correspond to
495  /// returning one of the tuples from GetScenePrimPath's "instancerContext".
496  ///
497  /// In any other case, the interpretation of instanceIndex is undefined.
498  static constexpr int ALL_INSTANCES = -1;
500  bool PopulateSelection(HdSelection::HighlightMode const& highlightMode,
501  const SdfPath &usdPath,
502  int instanceIndex,
504 
505  /// Returns true if \p usdPath is included in invised path list.
507  bool IsInInvisedPaths(const SdfPath &usdPath) const;
508 
509 private:
510  // Internal Get and SamplePrimvar
511  VtValue _Get(SdfPath const& id, TfToken const& key, VtIntArray *outIndices);
512 
513  size_t _SamplePrimvar(SdfPath const& id, TfToken const& key,
514  size_t maxNumSamples, float *times, VtValue *samples,
515  VtIntArray *indices);
516 
517  // Internal friend class.
518  class _Worker;
519  friend class UsdImagingIndexProxy;
520  friend class UsdImagingPrimAdapter;
521 
522  bool _ValidateRefineLevel(int level) {
523  if (!(0 <= level && level <= 8)) {
524  TF_CODING_ERROR("Invalid refinement level(%d), "
525  "expected range is [0,8]",
526  level);
527  return false;
528  }
529  return true;
530  }
531 
532  void _AddTask(UsdImagingDelegate::_Worker *worker, SdfPath const& usdPath);
533 
534  // ---------------------------------------------------------------------- //
535  // Draw mode support
536  // ---------------------------------------------------------------------- //
537  // Determine whether to assign a draw mode adapter to the given prim.
538  bool _IsDrawModeApplied(UsdPrim const& prim);
539  // Get the inherited model:drawMode attribute of the given prim.
540  TfToken _GetModelDrawMode(UsdPrim const& prim);
541 
542  // ---------------------------------------------------------------------- //
543  // Usd Change Processing / Notice Handlers
544  // ---------------------------------------------------------------------- //
545  void _OnUsdObjectsChanged(UsdNotice::ObjectsChanged const&,
546  UsdStageWeakPtr const& sender);
547 
548  // Map holding USD subtree path keys mapped to associated hydra prim cache
549  // paths. This may be prepopulated and provided to the Refresh and Resync
550  // methods below to speed up dependency gathering.
552  _FlattenedDependenciesCacheMap;
553 
554  // The lightest-weight update, it does fine-grained invalidation of
555  // individual properties at the given path (prim or property).
556  //
557  // If \p path is a prim path, changedPrimInfoFields will be populated
558  // with the list of scene description fields that caused this prim to
559  // be refreshed.
560  //
561  // Returns whether the prim or the subtree rooted at `usdPath` needed to
562  // be resync'd (i.e., removed and repopulated).
563  //
564  bool _RefreshUsdObject(SdfPath const& usdPath,
565  TfTokenVector const& changedPrimInfoFields,
566  _FlattenedDependenciesCacheMap const &cache,
567  UsdImagingIndexProxy* proxy,
568  SdfPathSet* allTrackedVariabilityPaths);
569 
570  // Heavy-weight invalidation of an entire prim subtree. All cached data is
571  // reconstructed for all prims below \p rootPath.
572  //
573  // By default, _ResyncPrim will remove each affected prim and call
574  // Repopulate() on those prims individually. If repopulateFromRoot is
575  // true, Repopulate() will be called on \p rootPath instead. This is slower,
576  // but handles changes in tree topology.
577  void _ResyncUsdPrim(SdfPath const& usdRootPath,
578  _FlattenedDependenciesCacheMap const &cache,
579  UsdImagingIndexProxy* proxy,
580  bool repopulateFromRoot = false);
581 
582  // ---------------------------------------------------------------------- //
583  // Usd Data-Access Helper Methods
584  // ---------------------------------------------------------------------- //
585  UsdPrim _GetUsdPrim(SdfPath const& usdPath) {
586  UsdPrim const& p =
587  _stage->GetPrimAtPath(usdPath.GetAbsoluteRootOrPrimPath());
588  TF_VERIFY(p, "No prim found for id: %s",
589  usdPath.GetAbsoluteRootOrPrimPath().GetText());
590  return p;
591  }
592 
593  void _UpdateSingleValue(SdfPath const& cachePath, int dirtyFlags);
594 
595  // ---------------------------------------------------------------------- //
596  // Cache structures and related methods for population.
597  // ---------------------------------------------------------------------- //
598 
599  // Returns true if this delegate can be populated, false otherwise.
600  bool _CanPopulate(UsdPrim const& rootPrim) const;
601 
602  // Set the delegate's state to reflect that it will be populated from
603  // the given root prim with the given excluded paths.
604  void _SetStateForPopulation(UsdPrim const& rootPrim,
605  SdfPathVector const& excludedPaths,
606  SdfPathVector const& invisedPaths);
607 
608  // Populates this delegate's render index from the paths specified
609  // in the given index proxy.
610  void _Populate(class UsdImagingIndexProxy* proxy);
611 
612  // Execute all variability update tasks that have been added to the given
613  // worker.
614  static void _ExecuteWorkForVariabilityUpdate(_Worker* worker);
615 
616  /// Returns true if the given prim is visible, taking into account inherited
617  /// visibility values. Inherited values are strongest, Usd has no notion of
618  /// "super vis/invis".
619  bool _GetVisible(UsdPrim const& prim);
620 
621  /// Helper method for filtering discovered primvar names.
622  TfTokenVector _GetPrimvarNames(SdfPath const& usdPath,
623  TfToken const& interpolation);
624 
625  // ---------------------------------------------------------------------- //
626  // Helper methods for updating the delegate on time changes
627  // ---------------------------------------------------------------------- //
628 
629  // Execute all time update tasks that have been added to the given worker.
630  static void _ExecuteWorkForTimeUpdate(_Worker* worker);
631 
632  // ---------------------------------------------------------------------- //
633  // Core Delegate state
634  // ---------------------------------------------------------------------- //
635 
636  // Usd Prim Type to Adapter lookup table.
638  TfToken::HashFunctor> _AdapterMap;
639  _AdapterMap _adapterMap;
640 
641  // Per-Hydra-Primitive tracking data
642  struct _HdPrimInfo {
643  UsdImagingPrimAdapterSharedPtr adapter; // The adapter to use for the
644  // prim
645  UsdPrim usdPrim; // Reference to the Usd prim
646  HdDirtyBits timeVaryingBits; // Dirty Bits to set when
647  // time changes
648  HdDirtyBits dirtyBits; // Current dirty state of the prim.
650  extraDependencies;// Dependencies that aren't usdPrim.
651  };
652 
653  typedef TfHashMap<SdfPath, _HdPrimInfo, SdfPath::Hash> _HdPrimInfoMap;
654 
655  // Map from cache path to Hydra prim info
656  _HdPrimInfoMap _hdPrimInfoMap;
657 
658  typedef std::multimap<SdfPath, SdfPath> _DependencyMap;
659 
660  // Map from USD path to Hydra path, for tracking USD->hydra dependencies.
661  _DependencyMap _dependencyInfo;
662 
663  // Appends hydra prim cache paths corresponding to the USD subtree
664  // provided by looking up the dependency map (above).
665  void _GatherDependencies(SdfPath const& subtree,
666  SdfPathVector *affectedCachePaths);
667 
668  // Overload that takes an additional cache argument to help speed up the
669  // dependency gathering operation. The onus is on the client to prepopulate
670  // the cache.
671  void
672  _GatherDependencies(SdfPath const &subtree,
673  _FlattenedDependenciesCacheMap const &cache,
674  SdfPathVector *affectedCachePaths);
675 
676  // SdfPath::ReplacePrefix() is used frequently to convert between
677  // cache path and Hydra render index path and is a performance bottleneck.
678  // These maps pre-computes these conversion.
680  SdfPathMap _cache2indexPath;
681  SdfPathMap _index2cachePath;
682 
683  // Only use this method when we think no existing adapter has been
684  // established. For example, during initial Population.
685  UsdImagingPrimAdapterSharedPtr const& _AdapterLookup(
686  UsdPrim const& prim,
687  bool ignoreInstancing = false);
688  UsdImagingPrimAdapterSharedPtr const& _AdapterLookup(
689  TfToken const& adapterKey);
690 
691  // Obtain the prim tracking data for the given cache path.
692  _HdPrimInfo *_GetHdPrimInfo(const SdfPath &cachePath);
693 
694  Usd_PrimFlagsConjunction _GetDisplayPredicate() const;
695  Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes() const;
696 
697  // Mark render tags dirty for all prims.
698  // This is done in response to toggling the purpose-based display settings.
699  void _MarkRenderTagsDirty();
700 
701  typedef TfHashSet<SdfPath, SdfPath::Hash> _DirtySet;
702 
703  // Set of cache paths that are due a Sync()
704  _DirtySet _dirtyCachePaths;
705 
706  /// Refinement level per-USD-prim and fallback.
707  typedef TfHashMap<SdfPath, int, SdfPath::Hash> _RefineLevelMap;
708  /// Map from USD prim path to refine level.
709  _RefineLevelMap _refineLevelMap;
710 
711  /// Cached/pre-fetched primvar descriptors.
712  UsdImagingPrimvarDescCache _primvarDescCache;
713 
714  /// Usd binding.
715  UsdStageRefPtr _stage;
716  SdfPath _rootPrimPath;
717  SdfPathVector _excludedPrimPaths;
718  SdfPathVector _invisedPrimPaths;
719 
720  RigidXformOverridesMap _rigidXformOverrides;
721 
722  // Aspects of the delegate root that apply to all items in the index.
723  SdfPath _compensationPath;
724 
725  GfMatrix4d _rootXf;
726  bool _rootIsVisible;
727  SdfPath _rootInstancerId;
728 
729  /// The current time from which the delegate will read data.
730  UsdTimeCode _time;
731 
732  /// Path to the camera that its shutter will be used for time samples.
733  SdfPath _cameraPathForSampling;
734 
735  int _refineLevelFallback;
736  HdReprSelector _reprFallback;
737  HdCullStyle _cullStyleFallback;
738 
739  // Cache of which prims are time-varying.
740  SdfPathVector _timeVaryingPrimCache;
741  bool _timeVaryingPrimCacheValid;
742 
743  // Change processing
744  TfNotice::Key _objectsChangedNoticeKey;
745  SdfPathVector _usdPathsToResync;
746 
747  // Map from path of Usd object to update to list of changed scene
748  // description fields for that object. This list of fields is only
749  // populated for prim paths.
750  typedef std::unordered_map<SdfPath, TfTokenVector, SdfPath::Hash>
751  _PathsToUpdateMap;
752  _PathsToUpdateMap _usdPathsToUpdate;
753 
754  UsdImaging_XformCache _xformCache;
755  UsdImaging_MaterialBindingImplData _materialBindingImplData;
756  UsdImaging_MaterialBindingCache _materialBindingCache;
757  UsdImaging_CoordSysBindingCache _coordSysBindingCache;
758  UsdImaging_VisCache _visCache;
759  UsdImaging_PurposeCache _purposeCache;
760  UsdImaging_DrawModeCache _drawModeCache;
761  UsdImaging_CollectionCache _collectionCache;
762  UsdImaging_InheritedPrimvarCache _inheritedPrimvarCache;
763  UsdImaging_PointInstancerIndicesCache _pointInstancerIndicesCache;
764  UsdImaging_NonlinearSampleCountCache _nonlinearSampleCountCache;
765  UsdImaging_BlurScaleCache _blurScaleCache;
766 
767  // Purpose-based rendering toggles
768  bool _displayRender;
769  bool _displayProxy;
770  bool _displayGuides;
771  bool _enableUsdDrawModes;
772 
773  const bool _hasDrawModeAdapter;
774 
775  /// Enable custom shading of prims
776  bool _sceneMaterialsEnabled;
777 
778  /// Enable lights found in the usdscene
779  bool _sceneLightsEnabled;
780 
781  CameraUtilConformWindowPolicy _appWindowPolicy;
782 
783  // Enable HdCoordSys tracking
784  const bool _coordSysEnabled;
785 
786  // Display unloaded prims with Bounds adapter
787  bool _displayUnloadedPrimsWithBounds;
788 
789  UsdImagingDelegate() = delete;
790  UsdImagingDelegate(UsdImagingDelegate const &) = delete;
791  UsdImagingDelegate &operator =(UsdImagingDelegate const &) = delete;
792 };
793 
795 
796 #endif //PXR_USD_IMAGING_USD_IMAGING_DELEGATE_H
std::shared_ptr< SdfPathVector > HdIdVectorSharedPtr
A shared pointer to a vector of id's.
Definition: sceneDelegate.h:38
SDF_API const char * GetText() const
TfHashMap< SdfPath, GfMatrix4d, SdfPath::Hash > RigidXformOverridesMap
Definition: delegate.h:71
USDIMAGING_API void Populate(UsdPrim const &rootPrim)
Populates the rootPrim in the HdRenderIndex.
PxOsdSubdivTags SubdivTags
Definition: delegate.h:274
virtual USDIMAGING_API ~UsdImagingDelegate()
USDIMAGING_API void ClearRefineLevel(SdfPath const &usdPath)
std::shared_ptr< UsdImagingPrimAdapter > UsdImagingPrimAdapterSharedPtr
Definition: delegate.h:60
static SDF_API const SdfPath & AbsoluteRootPath()
USDIMAGING_API void SetDisplayGuides(const bool displayGuides)
Sets display of prims with purpose "guide".
GLsizei GLenum const void * indices
Definition: glcorearb.h:406
bool GetDisplayGuides() const
Definition: delegate.h:221
HdCullStyle
Definition: enums.h:105
virtual USDIMAGING_API GfMatrix4d GetTransform(SdfPath const &id) override
Returns the object space transform, including all parent transforms.
USDIMAGING_API void InvokeExtComputation(SdfPath const &computationId, HdExtComputationContext *context) override
USDIMAGING_API void SetDisplayUnloadedPrimsWithBounds(bool displayUnloaded)
#define USDIMAGING_API
Definition: api.h:23
virtual USDIMAGING_API VtArray< TfToken > GetCategories(SdfPath const &id) override
virtual USDIMAGING_API std::vector< VtArray< TfToken > > GetInstanceCategories(SdfPath const &instancerId) override
Returns the categories for each of the instances in the instancer.
GT_API const UT_StringHolder time
USDIMAGING_API HdExtComputationInputDescriptorVector GetExtComputationInputDescriptors(SdfPath const &computationId) override
virtual USDIMAGING_API SdfPathVector GetScenePrimPaths(SdfPath const &rprimId, std::vector< int > instanceIndices, std::vector< HdInstancerContext > *instancerContexts=nullptr) override
USDIMAGING_API void SetTime(UsdTimeCode time)
iterator end()
Definition: hashmap.h:301
uint32_t HdDirtyBits
Definition: types.h:143
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
static USDIMAGING_API void SetTimes(const std::vector< UsdImagingDelegate * > &delegates, const std::vector< UsdTimeCode > &times)
USDIMAGING_API void SetInvisedPrimPaths(SdfPathVector const &invisedPaths)
Set the list of paths that must be invised.
USDIMAGING_API bool PopulateSelection(HdSelection::HighlightMode const &highlightMode, const SdfPath &usdPath, int instanceIndex, HdSelectionSharedPtr const &result)
HighlightMode
Selection modes allow differentiation in selection highlight behavior.
Definition: selection.h:39
virtual USDIMAGING_API size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key, size_t maxNumSamples, float *times, VtValue *samples, VtIntArray *indices) override
virtual USDIMAGING_API size_t SampleInstancerTransform(SdfPath const &instancerId, size_t maxSampleCount, float *times, GfMatrix4d *samples) override
std::vector< HdExtComputationInputDescriptor > HdExtComputationInputDescriptorVector
#define TF_CODING_ERROR
virtual USDIMAGING_API VtValue GetMaterialResource(SdfPath const &materialId) override
Returns the material ID bound to the rprim rprimId.
SDF_API SdfPath GetAbsoluteRootOrPrimPath() const
GLint level
Definition: glcorearb.h:108
virtual USDIMAGING_API VtValue Get(SdfPath const &id, TfToken const &key) override
Returns a named value.
virtual USDIMAGING_API HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors(SdfPath const &volumeId) override
USDIMAGING_API void SetSceneMaterialsEnabled(bool enable)
Enables custom shading on prims.
virtual USDIMAGING_API size_t SampleTransform(SdfPath const &id, size_t maxNumSamples, float *times, GfMatrix4d *samples) override
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
Definition: path.h:405
USDIMAGING_API void SetCameraForSampling(SdfPath const &id)
Setup for the shutter open and close to be used for motion sampling.
Functor to use for hash maps from tokens to other things.
Definition: token.h:149
std::vector< HdExtComputationOutputDescriptor > HdExtComputationOutputDescriptorVector
USDIMAGING_API size_t SampleExtComputationInput(SdfPath const &computationId, TfToken const &input, size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues) override
**But if you need a result
Definition: thread.h:622
virtual USDIMAGING_API SdfPath GetMaterialId(SdfPath const &rprimId) override
Returns the material ID bound to the rprim rprimId.
HdReprSelector GetReprFallback() const
Returns the fallback repr name.
Definition: delegate.h:160
USDIMAGING_API HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(SdfPath const &computationId) override
virtual USDIMAGING_API GfRange3d GetExtent(SdfPath const &id) override
UsdStagePtr UsdStageWeakPtr
Definition: common.h:38
virtual USDIMAGING_API VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key, VtIntArray *outIndices) override
USDIMAGING_API GfInterval GetCurrentTimeSamplingInterval()
USDIMAGING_API void SetRootInstancerId(SdfPath const &instancerId)
virtual USDIMAGING_API HdReprSelector GetReprSelector(SdfPath const &id) override
Returns the authored repr (if any) for the given prim.
virtual USDIMAGING_API SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override
virtual USDIMAGING_API VtIntArray GetInstanceIndices(SdfPath const &instancerId, SdfPath const &prototypeId) override
std::vector< std::pair< SdfPath, int > > HdInstancerContext
Instancer context: a pair of instancer paths and instance indices.
Definition: sceneDelegate.h:44
USDIMAGING_API void SetDisplayRender(const bool displayRender)
Sets display of prims with purpose "render".
USDIMAGING_API void SetSceneLightsEnabled(bool enable)
Enables lights found in the usdscene.
USDIMAGING_API void SetRootVisibility(bool isVisible)
USDIMAGING_API void SetCullStyleFallback(HdCullStyle cullStyle)
Sets the fallback cull style.
UsdTimeCode GetTimeWithOffset(float offset) const
USDIMAGING_API void SetUsdDrawModesEnabled(bool enableUsdDrawModes)
Returns whether draw modes are enabled.
bool GetDisplayUnloadedPrimsWithBounds() const
Definition: delegate.h:251
virtual USDIMAGING_API VtValue GetLightParamValue(SdfPath const &id, TfToken const &paramName) override
Definition: token.h:70
virtual USDIMAGING_API VtValue GetVolumeParamValue(SdfPath const &id, TfToken const &paramName) override
GLintptr offset
Definition: glcorearb.h:665
virtual USDIMAGING_API HdCullStyle GetCullStyle(SdfPath const &id) override
Returns the cullstyle for the given prim.
std::vector< UsdPrim > UsdPrimVector
Definition: delegate.h:54
USDIMAGING_API TfTokenVector GetExtComputationSceneInputNames(SdfPath const &computationId) override
virtual USDIMAGING_API size_t SamplePrimvar(SdfPath const &id, TfToken const &key, size_t maxNumSamples, float *times, VtValue *samples) override
HdCullStyle GetCullStyleFallback() const
Returns the fallback cull style.
Definition: delegate.h:168
std::vector< class SdfPath > SdfPathVector
USDIMAGING_API void SetRefineLevelFallback(int level)
UsdTimeCode GetTime() const
Returns the current time.
Definition: delegate.h:118
SdfPath GetRootInstancerId() const
Returns the root instancer id for the entire delegate.
Definition: delegate.h:198
virtual USDIMAGING_API HdMeshTopology GetMeshTopology(SdfPath const &id) override
Gets the topological mesh data for a given prim.
bool GetDisplayRender() const
Definition: delegate.h:211
USDIMAGING_API void SetRootTransform(GfMatrix4d const &xf)
virtual USDIMAGING_API bool GetVisible(SdfPath const &id) override
Returns the authored visible state of the prim.
virtual USDIMAGING_API bool GetDoubleSided(SdfPath const &id) override
Returns the doubleSided state for the given prim.
bool GetRootVisibility() const
Returns the root visibility for the entire delegate.
Definition: delegate.h:190
Definition: prim.h:116
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_PTRS(UsdImagingDelegate)
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: path.h:280
virtual USDIMAGING_API GfMatrix4d GetInstancerTransform(SdfPath const &instancerId) override
Returns the instancer transform.
std::vector< HdVolumeFieldDescriptor > HdVolumeFieldDescriptorVector
USDIMAGING_API void SetRigidXformOverrides(RigidXformOverridesMap const &overrides)
Set transform value overrides on a set of paths.
USDIMAGING_API HdExtComputationPrimvarDescriptorVector GetExtComputationPrimvarDescriptors(SdfPath const &computationId, HdInterpolation interpolation) override
GLsizei samples
Definition: glcorearb.h:1298
USDIMAGING_API void SetRefineLevel(SdfPath const &usdPath, int level)
USDIMAGING_API bool IsInInvisedPaths(const SdfPath &usdPath) const
Returns true if usdPath is included in invised path list.
std::set< class SdfPath > SdfPathSet
A set of SdfPaths.
Definition: path.h:199
CameraUtilConformWindowPolicy
Definition: conformWindow.h:27
SdfPath const & GetDelegateID() const
virtual USDIMAGING_API void Sync(HdSyncRequestVector *request) override
Synchronizes the delegate state for the given request vector.
virtual USDIMAGING_API TfToken GetRenderTag(SdfPath const &id) override
USDIMAGING_API VtValue GetExtComputationInput(SdfPath const &computationId, TfToken const &input) override
USDIMAGING_API void SetDisplayProxy(const bool displayProxy)
Sets display of prims with purpose "proxy".
virtual USDIMAGING_API VtValue GetCameraParamValue(SdfPath const &id, TfToken const &paramName) override
virtual USDIMAGING_API HdPrimvarDescriptorVector GetPrimvarDescriptors(SdfPath const &id, HdInterpolation interpolation) override
Returns descriptors for all primvars of the given interpolation type.
USDIMAGING_API SdfPath ConvertIndexPathToCachePath(SdfPath const &indexPath)
Definition: delegate.h:469
virtual USDIMAGING_API HdDisplayStyle GetDisplayStyle(SdfPath const &id) override
bool GetUsdDrawModesEnabled() const
Definition: delegate.h:226
static constexpr int ALL_INSTANCES
Definition: delegate.h:498
HdInterpolation
Definition: enums.h:177
virtual USDIMAGING_API HdBasisCurvesTopology GetBasisCurvesTopology(SdfPath const &id) override
Gets the topological curve data for a given prim.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
std::shared_ptr< UsdImagingPrimAdapter > UsdImagingPrimAdapterSharedPtr
USDIMAGING_API SdfPath ConvertCachePathToIndexPath(SdfPath const &cachePath)
Definition: delegate.h:445
USDIMAGING_API void SyncAll(bool includeUnvarying)
USDIMAGING_API std::string GetExtComputationKernel(SdfPath const &computationId) override
USDIMAGING_API void ApplyPendingUpdates()
Applies any scene edits which have been queued up by notices from USD.
virtual USDIMAGING_API SdfPath GetInstancerId(SdfPath const &primId) override
Returns the parent instancer of the given rprim or instancer.
USDIMAGING_API void SetWindowPolicy(CameraUtilConformWindowPolicy policy)
virtual USDIMAGING_API SubdivTags GetSubdivTags(SdfPath const &id) override
Gets the subdivision surface tags (sharpness, holes, etc).
std::vector< HdPrimvarDescriptor > HdPrimvarDescriptorVector
bool GetDisplayProxy() const
Definition: delegate.h:216
std::shared_ptr< class HdSelection > HdSelectionSharedPtr
Definition: selection.h:23
USDIMAGING_API HdModelDrawMode GetModelDrawMode(SdfPath const &id) override
Returns the model draw mode object for the given prim.
virtual USDIMAGING_API SdfPath GetScenePrimPath(SdfPath const &rprimId, int instanceIndex, HdInstancerContext *instancerContext=nullptr) override
USDIMAGING_API virtual HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id) override
Returns the coordinate system bindings, or a nullptr if none are bound.
Definition: value.h:89
virtual USDIMAGING_API SdfPath GetDataSharingId(SdfPath const &primId) override
SDF_API SdfPath ReplacePrefix(const SdfPath &oldPrefix, const SdfPath &newPrefix, bool fixTargetPaths=true) const
const GfMatrix4d & GetRootTransform() const
Returns the root transform for the entire delegate.
Definition: delegate.h:181
int GetRefineLevelFallback() const
Definition: delegate.h:135
std::vector< HdExtComputationPrimvarDescriptor > HdExtComputationPrimvarDescriptorVector
USDIMAGING_API void SetReprFallback(HdReprSelector const &repr)