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