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