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