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/texture.h"
43 #include "pxr/imaging/hd/version.h"
44 
46 #include "pxr/usd/sdf/path.h"
47 #include "pxr/usd/sdf/pathTable.h"
48 #include "pxr/usd/usd/attribute.h"
49 #include "pxr/usd/usd/notice.h"
50 #include "pxr/usd/usd/prim.h"
51 #include "pxr/usd/usd/stage.h"
52 #include "pxr/usd/usdGeom/cube.h"
53 #include "pxr/usd/usdGeom/sphere.h"
55 #include "pxr/base/vt/value.h"
56 
57 #include "pxr/base/gf/range3d.h"
58 #include "pxr/base/gf/interval.h"
60 #include "pxr/base/tf/hashmap.h"
61 #include "pxr/base/tf/hashset.h"
63 
64 #include <hboost/container/flat_map.hpp>
65 #include <tbb/spin_rw_mutex.h>
66 #include <map>
67 #include <string>
68 
70 
71 
73 typedef std::vector<UsdPrim> UsdPrimVector;
74 
78 
79 typedef hboost::container::flat_map<SdfPath, bool> PickabilityMap;
80 
81 using UsdImagingPrimAdapterSharedPtr = std::shared_ptr<UsdImagingPrimAdapter>;
82 
83 /// \class UsdImagingDelegate
84 ///
85 /// The primary translation layer between the Hydra (Hd) core and the Usd
86 /// scene graph.
87 ///
89  typedef UsdImagingDelegate This;
90 public:
91 
93 
95  UsdImagingDelegate(HdRenderIndex *parentIndex,
96  SdfPath const& delegateID);
97 
99  virtual ~UsdImagingDelegate();
100 
102  virtual void Sync(HdSyncRequestVector* request) override;
103 
104  // Helper for clients who don't want to drive the sync behavior (unit
105  // tests). Note this method is not virtual.
107  void SyncAll(bool includeUnvarying);
108 
109  /// Opportunity for the delegate to clean itself up after
110  /// performing parrellel work during sync phase
112  virtual void PostSyncCleanup() override;
113 
114  /// Populates the rootPrim in the HdRenderIndex.
116  void Populate(UsdPrim const& rootPrim);
117 
118  /// Populates the rootPrim in the HdRenderIndex, excluding all paths in the
119  /// \p excludedPrimPaths, as well as their prim children.
121  void Populate(UsdPrim const& rootPrim,
122  SdfPathVector const& excludedPrimPaths,
123  SdfPathVector const &invisedPrimPaths=SdfPathVector());
124 
125  /// For each delegate in \p delegates, sets the current time from
126  /// which data wil be read to the corresponding time in \p times.
127  ///
128  /// This is equivalent to calling SetTime on each delegate individually.
129  /// However, this method will try to parallelize certain operations,
130  /// making it potentially more efficient.
132  static void SetTimes(const std::vector<UsdImagingDelegate*>& delegates,
133  const std::vector<UsdTimeCode>& times);
134 
135  /// Sets the current time from which data will be read by the delegate.
136  ///
137  /// Changing the current time immediately triggers invalidation in the
138  /// HdChangeTracker. Redundantly setting the time to its existing value is a
139  /// no-op and will not trigger invalidation.
141  void SetTime(UsdTimeCode time);
142 
143  /// Returns the current time.
144  UsdTimeCode GetTime() const { return _time; }
145 
146  /// Apply a relative offset to the current time.
147  /// This has no effect in the case of the default USD timecode.
148  UsdTimeCode GetTimeWithOffset(float offset) const;
149 
150  /// Applies any scene edits which have been queued up by notices from USD.
152  void ApplyPendingUpdates();
153 
154  /// Returns the refinement level that is used when prims have no explicit
155  /// level set.
156  ///
157  /// The refinement level indicates how many iterations to apply when
158  /// subdividing subdivision surfaces or other refinable primitives.
159  ///
160  /// Refinement level is always in the range [0,8].
161  int GetRefineLevelFallback() const { return _refineLevelFallback; }
162 
163  /// Sets the fallback refinement level to \p level, triggers dirty
164  /// refine level bit to be set on all Rprims that don't have explicit refine
165  /// levels set.
166  ///
167  /// Level is expected to be in the range [0,8], where 0 indicates no
168  /// refinement.
170  void SetRefineLevelFallback(int level);
171 
172  /// Removes any explicit refine level set for the given USD prim.
173  /// Marks dirty if a change in level occurs.
175  void ClearRefineLevel(SdfPath const& usdPath);
176 
177  /// Sets an explicit refinement level for the given USD prim.
178  /// If no level is explicitly set, the fallback is used;
179  /// see GetRefineLevelFallback().
180  /// If setting an explicit level does not change the effective level, no
181  /// dirty bit is set.
183  void SetRefineLevel(SdfPath const& usdPath, int level);
184 
185  /// Returns the fallback repr name.
186  HdReprSelector GetReprFallback() const { return _reprFallback; }
187 
188  /// Sets the fallback repr name. Note that currently UsdImagingDelegate
189  /// doesn't support per-prim repr.
191  void SetReprFallback(HdReprSelector const &repr);
192 
193  /// Returns the fallback cull style.
194  HdCullStyle GetCullStyleFallback() const { return _cullStyleFallback; }
195 
196  /// Sets the fallback cull style.
198  void SetCullStyleFallback(HdCullStyle cullStyle);
199 
200  /// Sets the root transform for the entire delegate, which is applied to all
201  /// render prims generated. Settting this value will immediately invalidate
202  /// existing rprim transforms.
204  void SetRootTransform(GfMatrix4d const& xf);
205 
206  /// Returns the root transform for the entire delegate.
207  const GfMatrix4d &GetRootTransform() const { return _rootXf; }
208 
209  /// Sets the root visibility for the entire delegate, which is applied to
210  /// all render prims generated. Settting this value will immediately
211  /// invalidate existing rprim visibility.
213  void SetRootVisibility(bool isVisible);
214 
215  /// Returns the root visibility for the entire delegate.
216  bool GetRootVisibility() const { return _rootIsVisible; }
217 
218  /// Set the list of paths that must be invised.
220  void SetInvisedPrimPaths(SdfPathVector const &invisedPaths);
221 
222  /// Set transform value overrides on a set of paths.
224  void SetRigidXformOverrides(RigidXformOverridesMap const &overrides);
225 
226  /// Returns the root paths of pickable objects.
229 
230  /// Sets pickability for a specific path.
232  void SetPickability(SdfPath const& path, bool pickable);
233 
234  /// Clears any pickability opinions that this delegates might have.
236  void ClearPickabilityMap();
237 
238  /// Sets display of prims with purpose "render"
240  void SetDisplayRender(const bool displayRender);
241  bool GetDisplayRender() const { return _displayRender; }
242 
243  /// Sets display of prims with purpose "proxy"
245  void SetDisplayProxy(const bool displayProxy);
246  bool GetDisplayProxy() const { return _displayProxy; }
247 
248  /// Sets display of prims with purpose "guide"
250  void SetDisplayGuides(const bool displayGuides);
251  bool GetDisplayGuides() const { return _displayGuides; }
252 
253  /// Returns whether draw modes are enabled.
255  void SetUsdDrawModesEnabled(bool enableUsdDrawModes);
256  bool GetUsdDrawModesEnabled() const { return _enableUsdDrawModes; }
257 
258  /// Enables custom shading on prims.
260  void SetSceneMaterialsEnabled(bool enable);
261 
262  /// Set the window policy on all scene cameras. This comes from
263  /// the application.
266 
267  /// Sets display of unloaded prims as bounding boxes.
268  /// Unloaded prims will need to satisfy one of the following set of
269  /// conditions in order to see them:
270  /// 1. The prim is a UsdGeomBoundable with an authored 'extent' attribute.
271  /// 2. The prim is a UsdPrim.IsModel() and has an authored 'extentsHint'
272  /// attribute (see UsdGeomModelAPI::GetExtentsHint).
273  /// Effective only for delegates that support draw modes (see
274  /// GetUsdDrawModesEnabled()).
276  void SetDisplayUnloadedPrimsWithBounds(bool displayUnloaded);
278  return _displayUnloadedPrimsWithBounds;
279  }
280 
281  /// Setup for the shutter open and close to be used for motion sampling.
283  void SetCameraForSampling(SdfPath const& id);
284 
285  /// Returns the current interval that will be used when using the
286  /// sample* API in the scene delegate.
289 
290  // ---------------------------------------------------------------------- //
291  // See HdSceneDelegate for documentation of the following virtual methods.
292  // ---------------------------------------------------------------------- //
294  virtual TfToken GetRenderTag(SdfPath const& id) override;
296  virtual HdMeshTopology GetMeshTopology(SdfPath const& id) override;
299  override;
301 
302  // XXX: animated subdiv tags are not currently supported
303  // XXX: subdiv tags currently fetched on-demand
305  virtual SubdivTags GetSubdivTags(SdfPath const& id) override;
306 
308  virtual GfRange3d GetExtent(SdfPath const & id) override;
310  virtual GfMatrix4d GetTransform(SdfPath const & id) override;
312  virtual bool GetVisible(SdfPath const & id) override;
314  virtual bool GetDoubleSided(SdfPath const & id) override;
316  virtual HdCullStyle GetCullStyle(SdfPath const &id) override;
317 
318  /// Gets the explicit display style for the given prim, if no refine level
319  /// is explicitly set, the fallback is returned; also see
320  /// GetRefineLevelFallback().
322  virtual HdDisplayStyle GetDisplayStyle(SdfPath const& id) override;
323 
325  virtual VtValue Get(SdfPath const& id, TfToken const& key) override;
328  virtual GetCoordSysBindings(SdfPath const& id) override;
330  virtual HdReprSelector GetReprSelector(SdfPath const &id) override;
332  virtual VtArray<TfToken> GetCategories(SdfPath const &id) override;
334  virtual std::vector<VtArray<TfToken>>
335  GetInstanceCategories(SdfPath const &instancerId) override;
338  GetPrimvarDescriptors(SdfPath const& id,
339  HdInterpolation interpolation) override;
341  virtual VtIntArray GetInstanceIndices(SdfPath const &instancerId,
342  SdfPath const &prototypeId) override;
344  virtual GfMatrix4d GetInstancerTransform(SdfPath const &instancerId)
345  override;
346 
347  // Motion samples
349  virtual size_t
350  SampleTransform(SdfPath const & id, size_t maxNumSamples,
351  float *times, GfMatrix4d *samples) override;
353  virtual size_t
354  SampleInstancerTransform(SdfPath const &instancerId,
355  size_t maxSampleCount, float *times,
356  GfMatrix4d *samples) override;
358  virtual size_t
359  SamplePrimvar(SdfPath const& id, TfToken const& key,
360  size_t maxNumSamples, float *times,
361  VtValue *samples) override;
362 
363  // Material Support
365  virtual SdfPath GetMaterialId(SdfPath const &rprimId) override;
366 
368  virtual VtValue GetMaterialResource(SdfPath const &materialId) override;
369 
370  // Texture Support
374  virtual HdTextureResourceSharedPtr GetTextureResource(SdfPath const &id) override;
375 
376  // Light Support
378  virtual VtValue GetLightParamValue(SdfPath const &id,
379  TfToken const &paramName) override;
380  // Camera Support
382  virtual VtValue GetCameraParamValue(SdfPath const &id,
383  TfToken const &paramName) override;
384 
385  // Volume Support
388  GetVolumeFieldDescriptors(SdfPath const &volumeId) override;
389 
390  // Picking path resolution
391  // Resolves a \p rprimId and \p instanceIndex back to the original USD
392  // gprim and instance index. For point-instanced prims, \p instanceContext
393  // returns extra information about which instance this is of which level of
394  // point-instancer. For example:
395  // /World/PI instances /World/PI/proto/PI
396  // /World/PI/proto/PI instances /World/PI/proto/PI/proto/Gprim
397  // instancerContext = [/World/PI, 0], [/World/PI/proto/PI, 1] means that
398  // this instance represents "protoIndex = 0" of /World/PI, etc.
399 
401  virtual SdfPath
402  GetScenePrimPath(SdfPath const& rprimId,
403  int instanceIndex,
404  HdInstancerContext *instancerContext = nullptr) override;
405 
406  // ExtComputation support
409  GetExtComputationSceneInputNames(SdfPath const& computationId) override;
410 
413  GetExtComputationInputDescriptors(SdfPath const& computationId) override;
414 
417  GetExtComputationOutputDescriptors(SdfPath const& computationId) override;
418 
421  GetExtComputationPrimvarDescriptors(SdfPath const& computationId,
422  HdInterpolation interpolation) override;
423 
425  VtValue GetExtComputationInput(SdfPath const& computationId,
426  TfToken const& input) override;
427 
429  std::string GetExtComputationKernel(SdfPath const& computationId) override;
430 
432  void InvokeExtComputation(SdfPath const& computationId,
433  HdExtComputationContext *context) override;
434 
435 public:
436  // Converts a cache path to a path in the render index.
439  SdfPathMap::const_iterator it = _cache2indexPath.find(cachePath);
440  if (it != _cache2indexPath.end()) {
441  return it->second;
442  }
443 
444  // For pure/plain usdImaging, there is no prefix to replace
445  SdfPath const &delegateID = GetDelegateID();
446  if (delegateID == SdfPath::AbsoluteRootPath()) {
447  return cachePath;
448  }
449  if (cachePath.IsEmpty()) {
450  return cachePath;
451  }
452 
453  return cachePath.ReplacePrefix(SdfPath::AbsoluteRootPath(), delegateID);
454  }
455 
456  /// Convert the given Hydra ID to a UsdImaging cache path,
457  /// by stripping the scene delegate prefix.
458  ///
459  /// The UsdImaging cache path is the same as a USD prim path,
460  /// except for instanced prims, which get a name-mangled encoding.
463  SdfPathMap::const_iterator it = _index2cachePath.find(indexPath);
464  if (it != _index2cachePath.end()) {
465  return it->second;
466  }
467 
468  // For pure/plain usdImaging, there is no prefix to replace
469  SdfPath const &delegateID = GetDelegateID();
470  if (delegateID == SdfPath::AbsoluteRootPath()) {
471  return indexPath;
472  }
473 
474  return indexPath.ReplacePrefix(delegateID, SdfPath::AbsoluteRootPath());
475  }
476 
477  /// Populate HdxSelection for given \p path (root) and \p instanceIndex.
478  /// If indexPath is an instancer and instanceIndex is ALL_INSTANCES (-1),
479  /// all instances will be selected.
480  ///
481  /// Note: if usdPath points to a gprim, "instanceIndex" (if provided)
482  /// is assumed to be the hydra-computed instance index returned from
483  /// picking code.
484  ///
485  /// If usdPath points to a point instancer, "instanceIndex" is assumed to
486  /// be the instance of the point instancer to selection highlight (e.g.
487  /// instance N of the protoIndices array). This would correspond to
488  /// returning one of the tuples from GetScenePrimPath's "instancerContext".
489  ///
490  /// In any other case, the interpretation of instanceIndex is undefined.
491  static constexpr int ALL_INSTANCES = -1;
493  bool PopulateSelection(HdSelection::HighlightMode const& highlightMode,
494  const SdfPath &usdPath,
495  int instanceIndex,
497 
498  /// Returns true if \p usdPath is included in invised path list.
500  bool IsInInvisedPaths(const SdfPath &usdPath) const;
501 
502 private:
503  // Internal friend class.
504  class _Worker;
505  friend class UsdImagingIndexProxy;
506  friend class UsdImagingPrimAdapter;
507 
508  bool _ValidateRefineLevel(int level) {
509  if (!(0 <= level && level <= 8)) {
510  TF_CODING_ERROR("Invalid refinement level(%d), "
511  "expected range is [0,8]",
512  level);
513  return false;
514  }
515  return true;
516  }
517 
518  void _AddTask(UsdImagingDelegate::_Worker *worker, SdfPath const& usdPath);
519 
520  // ---------------------------------------------------------------------- //
521  // Draw mode support
522  // ---------------------------------------------------------------------- //
523  // Determine whether to assign a draw mode adapter to the given prim.
524  bool _IsDrawModeApplied(UsdPrim const& prim);
525  // Get the inherited model:drawMode attribute of the given prim.
526  TfToken _GetModelDrawMode(UsdPrim const& prim);
527 
528  // ---------------------------------------------------------------------- //
529  // Usd Change Processing / Notice Handlers
530  // ---------------------------------------------------------------------- //
531  void _OnUsdObjectsChanged(UsdNotice::ObjectsChanged const&,
532  UsdStageWeakPtr const& sender);
533 
534  // The lightest-weight update, it does fine-grained invalidation of
535  // individual properties at the given path (prim or property).
536  //
537  // If \p path is a prim path, changedPrimInfoFields will be populated
538  // with the list of scene description fields that caused this prim to
539  // be refreshed.
540  void _RefreshUsdObject(SdfPath const& usdPath,
541  TfTokenVector const& changedPrimInfoFields,
542  UsdImagingIndexProxy* proxy);
543 
544  // Heavy-weight invalidation of an entire prim subtree. All cached data is
545  // reconstructed for all prims below \p rootPath.
546  //
547  // By default, _ResyncPrim will remove each affected prim and call
548  // Repopulate() on those prims individually. If repopulateFromRoot is
549  // true, Repopulate() will be called on \p rootPath instead. This is slower,
550  // but handles changes in tree topology.
551  void _ResyncUsdPrim(SdfPath const& usdRootPath, UsdImagingIndexProxy* proxy,
552  bool repopulateFromRoot = false);
553 
554  // ---------------------------------------------------------------------- //
555  // Usd Data-Access Helper Methods
556  // ---------------------------------------------------------------------- //
557  UsdPrim _GetUsdPrim(SdfPath const& usdPath) {
558  UsdPrim const& p =
559  _stage->GetPrimAtPath(usdPath.GetAbsoluteRootOrPrimPath());
560  TF_VERIFY(p, "No prim found for id: %s",
561  usdPath.GetAbsoluteRootOrPrimPath().GetText());
562  return p;
563  }
564 
565  VtValue _GetUsdPrimAttribute(SdfPath const& cachePath,
566  TfToken const &attrName);
567 
568  void _UpdateSingleValue(SdfPath const& cachePath, int dirtyFlags);
569 
570  // ---------------------------------------------------------------------- //
571  // Cache structures and related methods for population.
572  // ---------------------------------------------------------------------- //
573 
574  // Returns true if this delegate can be populated, false otherwise.
575  bool _CanPopulate(UsdPrim const& rootPrim) const;
576 
577  // Set the delegate's state to reflect that it will be populated from
578  // the given root prim with the given excluded paths.
579  void _SetStateForPopulation(UsdPrim const& rootPrim,
580  SdfPathVector const& excludedPaths,
581  SdfPathVector const& invisedPaths);
582 
583  // Populates this delegate's render index from the paths specified
584  // in the given index proxy.
585  void _Populate(class UsdImagingIndexProxy* proxy);
586 
587  // Execute all variability update tasks that have been added to the given
588  // worker.
589  static void _ExecuteWorkForVariabilityUpdate(_Worker* worker);
590 
591  /// Returns true if the given prim is visible, taking into account inherited
592  /// visibility values. Inherited values are strongest, Usd has no notion of
593  /// "super vis/invis".
594  bool _GetVisible(UsdPrim const& prim);
595 
596  /// Helper method for filtering discovered primvar names.
597  TfTokenVector _GetPrimvarNames(SdfPath const& usdPath,
598  TfToken const& interpolation);
599 
600  // ---------------------------------------------------------------------- //
601  // Helper methods for updating the delegate on time changes
602  // ---------------------------------------------------------------------- //
603 
604  // Execute all time update tasks that have been added to the given worker.
605  static void _ExecuteWorkForTimeUpdate(_Worker* worker);
606 
607  // ---------------------------------------------------------------------- //
608  // Core Delegate state
609  // ---------------------------------------------------------------------- //
610 
611  // Usd Prim Type to Adapter lookup table.
613  TfToken::HashFunctor> _AdapterMap;
614  _AdapterMap _adapterMap;
615 
616  // Per-Hydra-Primitive tracking data
617  struct _HdPrimInfo {
618  UsdImagingPrimAdapterSharedPtr adapter; // The adapter to use for the
619  // prim
620  UsdPrim usdPrim; // Reference to the Usd prim
621  HdDirtyBits timeVaryingBits; // Dirty Bits to set when
622  // time changes
623  HdDirtyBits dirtyBits; // Current dirty state of the prim.
625  extraDependencies;// Dependencies that aren't usdPrim.
626  };
627 
628  typedef TfHashMap<SdfPath, _HdPrimInfo, SdfPath::Hash> _HdPrimInfoMap;
629 
630  // Map from cache path to Hydra prim info
631  _HdPrimInfoMap _hdPrimInfoMap;
632 
633  typedef std::multimap<SdfPath, SdfPath> _DependencyMap;
634 
635  // Map from USD path to Hydra path, for tracking USD->hydra dependencies.
636  _DependencyMap _dependencyInfo;
637 
638  void _GatherDependencies(SdfPath const& subtree,
639  SdfPathVector *affectedCachePaths);
640 
641  // SdfPath::ReplacePrefix() is used frequently to convert between
642  // cache path and Hydra render index path and is a performance bottleneck.
643  // These maps pre-computes these conversion.
645  SdfPathMap _cache2indexPath;
646  SdfPathMap _index2cachePath;
647 
648  // Only use this method when we think no existing adapter has been
649  // established. For example, during initial Population.
650  UsdImagingPrimAdapterSharedPtr const& _AdapterLookup(
651  UsdPrim const& prim,
652  bool ignoreInstancing = false);
653  UsdImagingPrimAdapterSharedPtr const& _AdapterLookup(
654  TfToken const& adapterKey);
655 
656  // Obtain the prim tracking data for the given cache path.
657  _HdPrimInfo *_GetHdPrimInfo(const SdfPath &cachePath);
658 
659  Usd_PrimFlagsConjunction _GetDisplayPredicate() const;
660 
661  // Mark render tags dirty for all prims.
662  // This is done in response to toggling the purpose-based display settings.
663  void _MarkRenderTagsDirty();
664 
665 
666  typedef TfHashSet<SdfPath, SdfPath::Hash> _InstancerSet;
667 
668  // Set of cache paths representing instancers
669  _InstancerSet _instancerPrimCachePaths;
670 
671  /// Refinement level per-USD-prim and fallback.
672  typedef TfHashMap<SdfPath, int, SdfPath::Hash> _RefineLevelMap;
673  /// Map from USD prim path to refine level.
674  _RefineLevelMap _refineLevelMap;
675 
676  /// Cached/pre-fetched rprim data.
677  UsdImagingValueCache _valueCache;
678 
679  /// Usd binding.
680  UsdStageRefPtr _stage;
681  SdfPath _rootPrimPath;
682  SdfPathVector _excludedPrimPaths;
683  SdfPathVector _invisedPrimPaths;
684 
685  RigidXformOverridesMap _rigidXformOverrides;
686 
687  // Aspects of the delegate root that apply to all items in the index.
688  SdfPath _compensationPath;
689 
690  GfMatrix4d _rootXf;
691  bool _rootIsVisible;
692 
693  /// The current time from which the delegate will read data.
694  UsdTimeCode _time;
695 
696  /// Path to the camera that its shutter will be used for time samples.
697  SdfPath _cameraPathForSampling;
698 
699  int _refineLevelFallback;
700  HdReprSelector _reprFallback;
701  HdCullStyle _cullStyleFallback;
702 
703  // Cache of which prims are time-varying.
704  SdfPathVector _timeVaryingPrimCache;
705  bool _timeVaryingPrimCacheValid;
706 
707  // Change processing
708  TfNotice::Key _objectsChangedNoticeKey;
709  SdfPathVector _usdPathsToResync;
710 
711  // Map from path of Usd object to update to list of changed scene
712  // description fields for that object. This list of fields is only
713  // populated for prim paths.
714  typedef std::unordered_map<SdfPath, TfTokenVector, SdfPath::Hash>
715  _PathsToUpdateMap;
716  _PathsToUpdateMap _usdPathsToUpdate;
717 
718  UsdImaging_XformCache _xformCache;
719  UsdImaging_MaterialBindingImplData _materialBindingImplData;
720  UsdImaging_MaterialBindingCache _materialBindingCache;
721  UsdImaging_CoordSysBindingImplData _coordSysBindingImplData;
722  UsdImaging_CoordSysBindingCache _coordSysBindingCache;
723  UsdImaging_VisCache _visCache;
724  UsdImaging_PurposeCache _purposeCache;
725  UsdImaging_DrawModeCache _drawModeCache;
726  UsdImaging_CollectionCache _collectionCache;
727  UsdImaging_InheritedPrimvarCache _inheritedPrimvarCache;
728  UsdImaging_PointInstancerIndicesCache _pointInstancerIndicesCache;
729 
730  // Pickability
731  PickabilityMap _pickablesMap;
732 
733  // Purpose-based rendering toggles
734  bool _displayRender;
735  bool _displayProxy;
736  bool _displayGuides;
737  bool _enableUsdDrawModes;
738 
739  const bool _hasDrawModeAdapter;
740 
741  /// Enable custom shading of prims
742  bool _sceneMaterialsEnabled;
743 
744  CameraUtilConformWindowPolicy _appWindowPolicy;
745 
746  // Enable HdCoordSys tracking
747  const bool _coordSysEnabled;
748 
749  // Display unloaded prims with Bounds adapter
750  bool _displayUnloadedPrimsWithBounds;
751 
752  UsdImagingDelegate() = delete;
753  UsdImagingDelegate(UsdImagingDelegate const &) = delete;
754  UsdImagingDelegate &operator =(UsdImagingDelegate const &) = delete;
755 };
756 
758 
759 #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
Returns the string representation of this path as a c string.
TfHashMap< SdfPath, GfMatrix4d, SdfPath::Hash > RigidXformOverridesMap
Definition: delegate.h:92
USDIMAGING_API void Populate(UsdPrim const &rootPrim)
Populates the rootPrim in the HdRenderIndex.
PxOsdSubdivTags SubdivTags
Definition: delegate.h:300
GLenum GLenum GLenum input
Definition: glew.h:13879
virtual USDIMAGING_API ~UsdImagingDelegate()
USDIMAGING_API void ClearRefineLevel(SdfPath const &usdPath)
std::shared_ptr< UsdImagingPrimAdapter > UsdImagingPrimAdapterSharedPtr
Definition: delegate.h:81
static SDF_API const SdfPath & AbsoluteRootPath()
USDIMAGING_API void SetDisplayGuides(const bool displayGuides)
Sets display of prims with purpose "guide".
bool GetDisplayGuides() const
Definition: delegate.h:251
HdCullStyle
Definition: enums.h:122
std::shared_ptr< class HdTextureResource > HdTextureResourceSharedPtr
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
USDIMAGING_API void SetTime(UsdTimeCode time)
iterator end()
Definition: hashmap.h:318
uint32_t HdDirtyBits
Definition: types.h:127
static USDIMAGING_API void SetTimes(const std::vector< UsdImagingDelegate * > &delegates, const std::vector< UsdTimeCode > &times)
USDIMAGING_API void SetInvisedPrimPaths(SdfPathVector const &invisedPaths)
Set the list of paths that must be invised.
USDIMAGING_API bool PopulateSelection(HdSelection::HighlightMode const &highlightMode, const SdfPath &usdPath, int instanceIndex, HdSelectionSharedPtr const &result)
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
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:413
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
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:186
USDIMAGING_API HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(SdfPath const &computationId) override
virtual USDIMAGING_API GfRange3d GetExtent(SdfPath const &id) override
USDIMAGING_API GfInterval GetCurrentTimeSamplingInterval()
virtual USDIMAGING_API HdReprSelector GetReprSelector(SdfPath const &id) override
Returns the authored repr (if any) for the given prim.
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 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:277
virtual USDIMAGING_API VtValue GetLightParamValue(SdfPath const &id, TfToken const &paramName) override
Definition: token.h:87
virtual USDIMAGING_API HdCullStyle GetCullStyle(SdfPath const &id) override
Returns the cullstyle for the given prim.
virtual USDIMAGING_API void PostSyncCleanup() override
std::vector< UsdPrim > UsdPrimVector
Definition: delegate.h:73
USDIMAGING_API HdTextureResource::ID GetTextureResourceID(SdfPath const &id) override
Returns the texture resource ID for a given texture ID.
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:194
hboost::container::flat_map< SdfPath, bool > PickabilityMap
Definition: delegate.h:77
USDIMAGING_API void SetRefineLevelFallback(int level)
UsdTimeCode GetTime() const
Returns the current time.
Definition: delegate.h:144
virtual USDIMAGING_API HdMeshTopology GetMeshTopology(SdfPath const &id) override
Gets the topological mesh data for a given prim.
bool GetDisplayRender() const
Definition: delegate.h:241
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:216
Definition: prim.h:132
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_PTRS(UsdImagingDelegate)
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:446
HighlightMode
Selection modes allow differentiation in selection highlight behavior.
Definition: selection.h:55
Definition: path.h:288
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:209
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
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.
USDIMAGING_API void SetPickability(SdfPath const &path, bool pickable)
Sets pickability for a specific path.
GLsizei const GLchar *const * path
Definition: glew.h:6461
CameraUtilConformWindowPolicy
Definition: conformWindow.h:44
SdfPath const & GetDelegateID() const
GLfloat GLfloat p
Definition: glew.h:16321
UsdStagePtr UsdStageWeakPtr
Definition: common.h:55
virtual USDIMAGING_API void Sync(HdSyncRequestVector *request) override
Synchronizes the delegate state for the given request vector.
GLsizei const GLchar *const * string
Definition: glew.h:1844
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:1346
USDIMAGING_API SdfPath ConvertIndexPathToCachePath(SdfPath const &indexPath)
Definition: delegate.h:462
USDIMAGING_API void ClearPickabilityMap()
Clears any pickability opinions that this delegates might have.
virtual USDIMAGING_API HdDisplayStyle GetDisplayStyle(SdfPath const &id) override
virtual USDIMAGING_API HdTextureResourceSharedPtr GetTextureResource(SdfPath const &id) override
Returns the texture resource for a given texture ID.
bool GetUsdDrawModesEnabled() const
Definition: delegate.h:256
static constexpr int ALL_INSTANCES
Definition: delegate.h:491
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:438
USDIMAGING_API void SyncAll(bool includeUnvarying)
USDIMAGING_API std::string GetExtComputationKernel(SdfPath const &computationId) override
GLuint64EXT * result
Definition: glew.h:14007
USDIMAGING_API void ApplyPendingUpdates()
Applies any scene edits which have been queued up by notices from USD.
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:246
GLsizei samples
Definition: glew.h:2998
std::shared_ptr< class HdSelection > HdSelectionSharedPtr
Definition: selection.h:40
virtual USDIMAGING_API SdfPath GetScenePrimPath(SdfPath const &rprimId, int instanceIndex, HdInstancerContext *instancerContext=nullptr) override
GLint level
Definition: glew.h:1252
GLboolean enable
Definition: glew.h:2745
USDIMAGING_API virtual HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id) override
Returns the coordinate system bindings, or a nullptr if none are bound.
Definition: value.h:174
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:207
int GetRefineLevelFallback() const
Definition: delegate.h:161
std::vector< HdExtComputationPrimvarDescriptor > HdExtComputationPrimvarDescriptorVector
USDIMAGING_API void SetReprFallback(HdReprSelector const &repr)
GLintptr offset
Definition: glew.h:1682