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 
377  // Picking path resolution
378  // Resolves a \p rprimId and \p instanceIndex back to the original USD
379  // gprim and instance index. For point-instanced prims, \p instanceContext
380  // returns extra information about which instance this is of which level of
381  // point-instancer. For example:
382  // /World/PI instances /World/PI/proto/PI
383  // /World/PI/proto/PI instances /World/PI/proto/PI/proto/Gprim
384  // instancerContext = [/World/PI, 0], [/World/PI/proto/PI, 1] means that
385  // this instance represents "protoIndex = 0" of /World/PI, etc.
386 
388  virtual SdfPath
389  GetScenePrimPath(SdfPath const& rprimId,
390  int instanceIndex,
391  HdInstancerContext *instancerContext = nullptr) override;
392 
394  virtual SdfPathVector
395  GetScenePrimPaths(SdfPath const& rprimId,
396  std::vector<int> instanceIndices,
397  std::vector<HdInstancerContext> *instancerContexts = nullptr) override;
398 
400  virtual SdfPath GetDataSharingId(SdfPath const& primId) override;
401 
402  // ExtComputation support
405  GetExtComputationSceneInputNames(SdfPath const& computationId) override;
406 
409  GetExtComputationInputDescriptors(SdfPath const& computationId) override;
410 
413  GetExtComputationOutputDescriptors(SdfPath const& computationId) override;
414 
417  GetExtComputationPrimvarDescriptors(SdfPath const& computationId,
418  HdInterpolation interpolation) override;
419 
421  VtValue GetExtComputationInput(SdfPath const& computationId,
422  TfToken const& input) override;
423 
425  size_t SampleExtComputationInput(SdfPath const& computationId,
426  TfToken const& input,
427  size_t maxSampleCount,
428  float *sampleTimes,
429  VtValue *sampleValues) override;
430 
432  std::string GetExtComputationKernel(SdfPath const& computationId) override;
433 
435  void InvokeExtComputation(SdfPath const& computationId,
436  HdExtComputationContext *context) override;
437 
438 public:
439  // Converts a cache path to a path in the render index.
442  SdfPathMap::const_iterator it = _cache2indexPath.find(cachePath);
443  if (it != _cache2indexPath.end()) {
444  return it->second;
445  }
446 
447  // For pure/plain usdImaging, there is no prefix to replace
448  SdfPath const &delegateID = GetDelegateID();
449  if (delegateID == SdfPath::AbsoluteRootPath()) {
450  return cachePath;
451  }
452  if (cachePath.IsEmpty()) {
453  return cachePath;
454  }
455 
456  return cachePath.ReplacePrefix(SdfPath::AbsoluteRootPath(), delegateID);
457  }
458 
459  /// Convert the given Hydra ID to a UsdImaging cache path,
460  /// by stripping the scene delegate prefix.
461  ///
462  /// The UsdImaging cache path is the same as a USD prim path,
463  /// except for instanced prims, which get a name-mangled encoding.
466  SdfPathMap::const_iterator it = _index2cachePath.find(indexPath);
467  if (it != _index2cachePath.end()) {
468  return it->second;
469  }
470 
471  // For pure/plain usdImaging, there is no prefix to replace
472  SdfPath const &delegateID = GetDelegateID();
473  if (delegateID == SdfPath::AbsoluteRootPath()) {
474  return indexPath;
475  }
476 
477  return indexPath.ReplacePrefix(delegateID, SdfPath::AbsoluteRootPath());
478  }
479 
480  /// Populate HdxSelection for given \p path (root) and \p instanceIndex.
481  /// If indexPath is an instancer and instanceIndex is ALL_INSTANCES (-1),
482  /// all instances will be selected.
483  ///
484  /// Note: if usdPath points to a gprim, "instanceIndex" (if provided)
485  /// is assumed to be the hydra-computed instance index returned from
486  /// picking code.
487  ///
488  /// If usdPath points to a point instancer, "instanceIndex" is assumed to
489  /// be the instance of the point instancer to selection highlight (e.g.
490  /// instance N of the protoIndices array). This would correspond to
491  /// returning one of the tuples from GetScenePrimPath's "instancerContext".
492  ///
493  /// In any other case, the interpretation of instanceIndex is undefined.
494  static constexpr int ALL_INSTANCES = -1;
496  bool PopulateSelection(HdSelection::HighlightMode const& highlightMode,
497  const SdfPath &usdPath,
498  int instanceIndex,
500 
501  /// Returns true if \p usdPath is included in invised path list.
503  bool IsInInvisedPaths(const SdfPath &usdPath) const;
504 
505 private:
506  // Internal Get and SamplePrimvar
507  VtValue _Get(SdfPath const& id, TfToken const& key, VtIntArray *outIndices);
508 
509  size_t _SamplePrimvar(SdfPath const& id, TfToken const& key,
510  size_t maxNumSamples, float *times, VtValue *samples,
511  VtIntArray *indices);
512 
513  // Internal friend class.
514  class _Worker;
515  friend class UsdImagingIndexProxy;
516  friend class UsdImagingPrimAdapter;
517 
518  bool _ValidateRefineLevel(int level) {
519  if (!(0 <= level && level <= 8)) {
520  TF_CODING_ERROR("Invalid refinement level(%d), "
521  "expected range is [0,8]",
522  level);
523  return false;
524  }
525  return true;
526  }
527 
528  void _AddTask(UsdImagingDelegate::_Worker *worker, SdfPath const& usdPath);
529 
530  // ---------------------------------------------------------------------- //
531  // Draw mode support
532  // ---------------------------------------------------------------------- //
533  // Determine whether to assign a draw mode adapter to the given prim.
534  bool _IsDrawModeApplied(UsdPrim const& prim);
535  // Get the inherited model:drawMode attribute of the given prim.
536  TfToken _GetModelDrawMode(UsdPrim const& prim);
537 
538  // ---------------------------------------------------------------------- //
539  // Usd Change Processing / Notice Handlers
540  // ---------------------------------------------------------------------- //
541  void _OnUsdObjectsChanged(UsdNotice::ObjectsChanged const&,
542  UsdStageWeakPtr const& sender);
543 
544  // Map holding USD subtree path keys mapped to associated hydra prim cache
545  // paths. This may be prepopulated and provided to the Refresh and Resync
546  // methods below to speed up dependency gathering.
548  _FlattenedDependenciesCacheMap;
549 
550  // The lightest-weight update, it does fine-grained invalidation of
551  // individual properties at the given path (prim or property).
552  //
553  // If \p path is a prim path, changedPrimInfoFields will be populated
554  // with the list of scene description fields that caused this prim to
555  // be refreshed.
556  //
557  // Returns whether the prim or the subtree rooted at `usdPath` needed to
558  // be resync'd (i.e., removed and repopulated).
559  //
560  bool _RefreshUsdObject(SdfPath const& usdPath,
561  TfTokenVector const& changedPrimInfoFields,
562  _FlattenedDependenciesCacheMap const &cache,
563  UsdImagingIndexProxy* proxy,
564  SdfPathSet* allTrackedVariabilityPaths);
565 
566  // Heavy-weight invalidation of an entire prim subtree. All cached data is
567  // reconstructed for all prims below \p rootPath.
568  //
569  // By default, _ResyncPrim will remove each affected prim and call
570  // Repopulate() on those prims individually. If repopulateFromRoot is
571  // true, Repopulate() will be called on \p rootPath instead. This is slower,
572  // but handles changes in tree topology.
573  void _ResyncUsdPrim(SdfPath const& usdRootPath,
574  _FlattenedDependenciesCacheMap const &cache,
575  UsdImagingIndexProxy* proxy,
576  bool repopulateFromRoot = false);
577 
578  // ---------------------------------------------------------------------- //
579  // Usd Data-Access Helper Methods
580  // ---------------------------------------------------------------------- //
581  UsdPrim _GetUsdPrim(SdfPath const& usdPath) {
582  UsdPrim const& p =
583  _stage->GetPrimAtPath(usdPath.GetAbsoluteRootOrPrimPath());
584  TF_VERIFY(p, "No prim found for id: %s",
585  usdPath.GetAbsoluteRootOrPrimPath().GetText());
586  return p;
587  }
588 
589  void _UpdateSingleValue(SdfPath const& cachePath, int dirtyFlags);
590 
591  // ---------------------------------------------------------------------- //
592  // Cache structures and related methods for population.
593  // ---------------------------------------------------------------------- //
594 
595  // Returns true if this delegate can be populated, false otherwise.
596  bool _CanPopulate(UsdPrim const& rootPrim) const;
597 
598  // Set the delegate's state to reflect that it will be populated from
599  // the given root prim with the given excluded paths.
600  void _SetStateForPopulation(UsdPrim const& rootPrim,
601  SdfPathVector const& excludedPaths,
602  SdfPathVector const& invisedPaths);
603 
604  // Populates this delegate's render index from the paths specified
605  // in the given index proxy.
606  void _Populate(class UsdImagingIndexProxy* proxy);
607 
608  // Execute all variability update tasks that have been added to the given
609  // worker.
610  static void _ExecuteWorkForVariabilityUpdate(_Worker* worker);
611 
612  /// Returns true if the given prim is visible, taking into account inherited
613  /// visibility values. Inherited values are strongest, Usd has no notion of
614  /// "super vis/invis".
615  bool _GetVisible(UsdPrim const& prim);
616 
617  /// Helper method for filtering discovered primvar names.
618  TfTokenVector _GetPrimvarNames(SdfPath const& usdPath,
619  TfToken const& interpolation);
620 
621  // ---------------------------------------------------------------------- //
622  // Helper methods for updating the delegate on time changes
623  // ---------------------------------------------------------------------- //
624 
625  // Execute all time update tasks that have been added to the given worker.
626  static void _ExecuteWorkForTimeUpdate(_Worker* worker);
627 
628  // ---------------------------------------------------------------------- //
629  // Core Delegate state
630  // ---------------------------------------------------------------------- //
631 
632  // Usd Prim Type to Adapter lookup table.
634  TfToken::HashFunctor> _AdapterMap;
635  _AdapterMap _adapterMap;
636 
637  // Per-Hydra-Primitive tracking data
638  struct _HdPrimInfo {
639  UsdImagingPrimAdapterSharedPtr adapter; // The adapter to use for the
640  // prim
641  UsdPrim usdPrim; // Reference to the Usd prim
642  HdDirtyBits timeVaryingBits; // Dirty Bits to set when
643  // time changes
644  HdDirtyBits dirtyBits; // Current dirty state of the prim.
646  extraDependencies;// Dependencies that aren't usdPrim.
647  };
648 
649  typedef TfHashMap<SdfPath, _HdPrimInfo, SdfPath::Hash> _HdPrimInfoMap;
650 
651  // Map from cache path to Hydra prim info
652  _HdPrimInfoMap _hdPrimInfoMap;
653 
654  typedef std::multimap<SdfPath, SdfPath> _DependencyMap;
655 
656  // Map from USD path to Hydra path, for tracking USD->hydra dependencies.
657  _DependencyMap _dependencyInfo;
658 
659  // Appends hydra prim cache paths corresponding to the USD subtree
660  // provided by looking up the dependency map (above).
661  void _GatherDependencies(SdfPath const& subtree,
662  SdfPathVector *affectedCachePaths);
663 
664  // Overload that takes an additional cache argument to help speed up the
665  // dependency gathering operation. The onus is on the client to prepopulate
666  // the cache.
667  void
668  _GatherDependencies(SdfPath const &subtree,
669  _FlattenedDependenciesCacheMap const &cache,
670  SdfPathVector *affectedCachePaths);
671 
672  // SdfPath::ReplacePrefix() is used frequently to convert between
673  // cache path and Hydra render index path and is a performance bottleneck.
674  // These maps pre-computes these conversion.
676  SdfPathMap _cache2indexPath;
677  SdfPathMap _index2cachePath;
678 
679  // Only use this method when we think no existing adapter has been
680  // established. For example, during initial Population.
681  UsdImagingPrimAdapterSharedPtr const& _AdapterLookup(
682  UsdPrim const& prim,
683  bool ignoreInstancing = false);
684  UsdImagingPrimAdapterSharedPtr const& _AdapterLookup(
685  TfToken const& adapterKey);
686 
687  // Obtain the prim tracking data for the given cache path.
688  _HdPrimInfo *_GetHdPrimInfo(const SdfPath &cachePath);
689 
690  Usd_PrimFlagsConjunction _GetDisplayPredicate() const;
691  Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes() const;
692 
693  // Mark render tags dirty for all prims.
694  // This is done in response to toggling the purpose-based display settings.
695  void _MarkRenderTagsDirty();
696 
697  typedef TfHashSet<SdfPath, SdfPath::Hash> _DirtySet;
698 
699  // Set of cache paths that are due a Sync()
700  _DirtySet _dirtyCachePaths;
701 
702  /// Refinement level per-USD-prim and fallback.
703  typedef TfHashMap<SdfPath, int, SdfPath::Hash> _RefineLevelMap;
704  /// Map from USD prim path to refine level.
705  _RefineLevelMap _refineLevelMap;
706 
707  /// Cached/pre-fetched primvar descriptors.
708  UsdImagingPrimvarDescCache _primvarDescCache;
709 
710  /// Usd binding.
711  UsdStageRefPtr _stage;
712  SdfPath _rootPrimPath;
713  SdfPathVector _excludedPrimPaths;
714  SdfPathVector _invisedPrimPaths;
715 
716  RigidXformOverridesMap _rigidXformOverrides;
717 
718  // Aspects of the delegate root that apply to all items in the index.
719  SdfPath _compensationPath;
720 
721  GfMatrix4d _rootXf;
722  bool _rootIsVisible;
723  SdfPath _rootInstancerId;
724 
725  /// The current time from which the delegate will read data.
726  UsdTimeCode _time;
727 
728  /// Path to the camera that its shutter will be used for time samples.
729  SdfPath _cameraPathForSampling;
730 
731  int _refineLevelFallback;
732  HdReprSelector _reprFallback;
733  HdCullStyle _cullStyleFallback;
734 
735  // Cache of which prims are time-varying.
736  SdfPathVector _timeVaryingPrimCache;
737  bool _timeVaryingPrimCacheValid;
738 
739  // Change processing
740  TfNotice::Key _objectsChangedNoticeKey;
741  SdfPathVector _usdPathsToResync;
742 
743  // Map from path of Usd object to update to list of changed scene
744  // description fields for that object. This list of fields is only
745  // populated for prim paths.
746  typedef std::unordered_map<SdfPath, TfTokenVector, SdfPath::Hash>
747  _PathsToUpdateMap;
748  _PathsToUpdateMap _usdPathsToUpdate;
749 
750  UsdImaging_XformCache _xformCache;
751  UsdImaging_MaterialBindingImplData _materialBindingImplData;
752  UsdImaging_MaterialBindingCache _materialBindingCache;
753  UsdImaging_CoordSysBindingCache _coordSysBindingCache;
754  UsdImaging_VisCache _visCache;
755  UsdImaging_PurposeCache _purposeCache;
756  UsdImaging_DrawModeCache _drawModeCache;
757  UsdImaging_CollectionCache _collectionCache;
758  UsdImaging_InheritedPrimvarCache _inheritedPrimvarCache;
759  UsdImaging_PointInstancerIndicesCache _pointInstancerIndicesCache;
760  UsdImaging_NonlinearSampleCountCache _nonlinearSampleCountCache;
761  UsdImaging_BlurScaleCache _blurScaleCache;
762 
763  // Purpose-based rendering toggles
764  bool _displayRender;
765  bool _displayProxy;
766  bool _displayGuides;
767  bool _enableUsdDrawModes;
768 
769  const bool _hasDrawModeAdapter;
770 
771  /// Enable custom shading of prims
772  bool _sceneMaterialsEnabled;
773 
774  /// Enable lights found in the usdscene
775  bool _sceneLightsEnabled;
776 
777  CameraUtilConformWindowPolicy _appWindowPolicy;
778 
779  // Enable HdCoordSys tracking
780  const bool _coordSysEnabled;
781 
782  // Display unloaded prims with Bounds adapter
783  bool _displayUnloadedPrimsWithBounds;
784 
785  UsdImagingDelegate() = delete;
786  UsdImagingDelegate(UsdImagingDelegate const &) = delete;
787  UsdImagingDelegate &operator =(UsdImagingDelegate const &) = delete;
788 };
789 
791 
792 #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
hboost::math::policies::policy< hboost::math::policies::domain_error< hboost::math::policies::ignore_error >, hboost::math::policies::pole_error< hboost::math::policies::ignore_error >, hboost::math::policies::overflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::underflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::denorm_error< hboost::math::policies::ignore_error >, hboost::math::policies::rounding_error< hboost::math::policies::ignore_error >, hboost::math::policies::evaluation_error< hboost::math::policies::ignore_error >, hboost::math::policies::indeterminate_result_error< hboost::math::policies::ignore_error > > policy
Definition: SYS_MathCbrt.h:35
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
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:398
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
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:273
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:192
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.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USDIMAGING_API SdfPath ConvertIndexPathToCachePath(SdfPath const &indexPath)
Definition: delegate.h:465
virtual USDIMAGING_API HdDisplayStyle GetDisplayStyle(SdfPath const &id) override
bool GetUsdDrawModesEnabled() const
Definition: delegate.h:226
static constexpr int ALL_INSTANCES
Definition: delegate.h:494
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:441
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:146
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)