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 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usdImaging/usdImaging/api.h"
31 #include "pxr/usdImaging/usdImaging/version.h"
36 
37 #include "pxr/imaging/cameraUtil/conformWindow.h"
38 
39 #include "pxr/imaging/hd/coordSys.h"
40 #include "pxr/imaging/hd/sceneDelegate.h"
41 #include "pxr/imaging/hd/selection.h"
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"
53 #include "pxr/usd/usdGeom/xformCache.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 <boost/container/flat_map.hpp>
64 #include <tbb/spin_rw_mutex.h>
65 #include <map>
66 #include <string>
67 
68 PXR_NAMESPACE_OPEN_SCOPE
69 
70 
72 typedef std::vector<UsdPrim> UsdPrimVector;
73 
77 
78 typedef boost::container::flat_map<SdfPath, bool> PickabilityMap;
79 
80 using UsdImagingPrimAdapterSharedPtr = std::shared_ptr<UsdImagingPrimAdapter>;
81 
88  typedef UsdImagingDelegate This;
89 public:
90 
91  typedef TfHashMap<SdfPath, GfMatrix4d, SdfPath::Hash> RigidXformOverridesMap;
92 
93  USDIMAGING_API
94  UsdImagingDelegate(HdRenderIndex *parentIndex,
95  SdfPath const& delegateID);
96 
97  USDIMAGING_API
98  virtual ~UsdImagingDelegate();
99 
100  USDIMAGING_API
101  virtual void Sync(HdSyncRequestVector* request) override;
102 
103  // Helper for clients who don't want to drive the sync behavior (unit
104  // tests). Note this method is not virtual.
105  USDIMAGING_API
106  void SyncAll(bool includeUnvarying);
107 
109  USDIMAGING_API
110  void Populate(UsdPrim const& rootPrim);
111 
114  USDIMAGING_API
115  void Populate(UsdPrim const& rootPrim,
116  SdfPathVector const& excludedPrimPaths,
117  SdfPathVector const &invisedPrimPaths=SdfPathVector());
118 
125  USDIMAGING_API
126  static void SetTimes(const std::vector<UsdImagingDelegate*>& delegates,
127  const std::vector<UsdTimeCode>& times);
128 
134  USDIMAGING_API
135  void SetTime(UsdTimeCode time);
136 
138  UsdTimeCode GetTime() const { return _time; }
139 
142  UsdTimeCode GetTimeWithOffset(float offset) const;
143 
145  USDIMAGING_API
146  void ApplyPendingUpdates();
147 
155  int GetRefineLevelFallback() const { return _refineLevelFallback; }
156 
163  USDIMAGING_API
164  void SetRefineLevelFallback(int level);
165 
168  USDIMAGING_API
169  void ClearRefineLevel(SdfPath const& usdPath);
170 
176  USDIMAGING_API
177  void SetRefineLevel(SdfPath const& usdPath, int level);
178 
180  HdReprSelector GetReprFallback() const { return _reprFallback; }
181 
184  USDIMAGING_API
185  void SetReprFallback(HdReprSelector const &repr);
186 
188  HdCullStyle GetCullStyleFallback() const { return _cullStyleFallback; }
189 
191  USDIMAGING_API
192  void SetCullStyleFallback(HdCullStyle cullStyle);
193 
197  USDIMAGING_API
198  void SetRootTransform(GfMatrix4d const& xf);
199 
201  const GfMatrix4d &GetRootTransform() const { return _rootXf; }
202 
206  USDIMAGING_API
207  void SetRootVisibility(bool isVisible);
208 
210  bool GetRootVisibility() const { return _rootIsVisible; }
211 
214  USDIMAGING_API
215  void SetRootInstancerId(SdfPath const& instancerId);
216 
218  SdfPath GetRootInstancerId() const { return _rootInstancerId; }
219 
221  USDIMAGING_API
222  void SetInvisedPrimPaths(SdfPathVector const &invisedPaths);
223 
225  USDIMAGING_API
226  void SetRigidXformOverrides(RigidXformOverridesMap const &overrides);
227 
229  USDIMAGING_API
230  PickabilityMap GetPickabilityMap() const;
231 
233  USDIMAGING_API
234  void SetPickability(SdfPath const& path, bool pickable);
235 
237  USDIMAGING_API
238  void ClearPickabilityMap();
239 
241  USDIMAGING_API
242  void SetDisplayRender(const bool displayRender);
243  bool GetDisplayRender() const { return _displayRender; }
244 
246  USDIMAGING_API
247  void SetDisplayProxy(const bool displayProxy);
248  bool GetDisplayProxy() const { return _displayProxy; }
249 
251  USDIMAGING_API
252  void SetDisplayGuides(const bool displayGuides);
253  bool GetDisplayGuides() const { return _displayGuides; }
254 
256  USDIMAGING_API
257  void SetUsdDrawModesEnabled(bool enableUsdDrawModes);
258  bool GetUsdDrawModesEnabled() const { return _enableUsdDrawModes; }
259 
261  USDIMAGING_API
262  void SetSceneMaterialsEnabled(bool enable);
263 
265  USDIMAGING_API
266  void SetSceneLightsEnabled(bool enable);
267 
270  USDIMAGING_API
271  void SetWindowPolicy(CameraUtilConformWindowPolicy policy);
272 
281  USDIMAGING_API
282  void SetDisplayUnloadedPrimsWithBounds(bool displayUnloaded);
283  bool GetDisplayUnloadedPrimsWithBounds() const {
284  return _displayUnloadedPrimsWithBounds;
285  }
286 
288  USDIMAGING_API
289  void SetCameraForSampling(SdfPath const& id);
290 
293  USDIMAGING_API
295 
296  // ---------------------------------------------------------------------- //
297  // See HdSceneDelegate for documentation of the following virtual methods.
298  // ---------------------------------------------------------------------- //
299  USDIMAGING_API
300  virtual TfToken GetRenderTag(SdfPath const& id) override;
301  USDIMAGING_API
302  virtual HdMeshTopology GetMeshTopology(SdfPath const& id) override;
303  USDIMAGING_API
305  override;
306  typedef PxOsdSubdivTags SubdivTags;
307 
308  // XXX: animated subdiv tags are not currently supported
309  // XXX: subdiv tags currently fetched on-demand
310  USDIMAGING_API
311  virtual SubdivTags GetSubdivTags(SdfPath const& id) override;
312 
313  USDIMAGING_API
314  virtual GfRange3d GetExtent(SdfPath const & id) override;
315  USDIMAGING_API
316  virtual GfMatrix4d GetTransform(SdfPath const & id) override;
317  USDIMAGING_API
318  virtual bool GetVisible(SdfPath const & id) override;
319  USDIMAGING_API
320  virtual bool GetDoubleSided(SdfPath const & id) override;
321  USDIMAGING_API
322  virtual HdCullStyle GetCullStyle(SdfPath const &id) override;
323 
327  USDIMAGING_API
328  virtual HdDisplayStyle GetDisplayStyle(SdfPath const& id) override;
329 
330  USDIMAGING_API
331  virtual VtValue Get(SdfPath const& id, TfToken const& key) override;
332  USDIMAGING_API
333  virtual VtValue GetIndexedPrimvar(SdfPath const& id,
334  TfToken const& key,
335  VtIntArray *outIndices) override;
336  USDIMAGING_API
337  HdIdVectorSharedPtr
338  virtual GetCoordSysBindings(SdfPath const& id) override;
339  USDIMAGING_API
340  virtual HdReprSelector GetReprSelector(SdfPath const &id) override;
341  USDIMAGING_API
342  virtual VtArray<TfToken> GetCategories(SdfPath const &id) override;
343  USDIMAGING_API
344  virtual std::vector<VtArray<TfToken>>
345  GetInstanceCategories(SdfPath const &instancerId) override;
346  USDIMAGING_API
347  virtual HdPrimvarDescriptorVector
348  GetPrimvarDescriptors(SdfPath const& id,
349  HdInterpolation interpolation) override;
350  USDIMAGING_API
351  virtual VtIntArray GetInstanceIndices(SdfPath const &instancerId,
352  SdfPath const &prototypeId) override;
353  USDIMAGING_API
354  virtual GfMatrix4d GetInstancerTransform(SdfPath const &instancerId)
355  override;
356 
357  USDIMAGING_API
358  virtual SdfPath GetInstancerId(SdfPath const &primId) override;
359 
360  USDIMAGING_API
361  virtual SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override;
362 
363  // Motion samples
364  USDIMAGING_API
365  virtual size_t
366  SampleTransform(SdfPath const & id, size_t maxNumSamples,
367  float *times, GfMatrix4d *samples) override;
368  USDIMAGING_API
369  virtual size_t
370  SampleInstancerTransform(SdfPath const &instancerId,
371  size_t maxSampleCount, float *times,
372  GfMatrix4d *samples) override;
373  USDIMAGING_API
374  virtual size_t
375  SamplePrimvar(SdfPath const& id, TfToken const& key,
376  size_t maxNumSamples, float *times,
377  VtValue *samples) override;
378 
379  USDIMAGING_API
380  virtual size_t
381  SampleIndexedPrimvar(SdfPath const& id, TfToken const& key,
382  size_t maxNumSamples, float *times,
383  VtValue *samples, VtIntArray *indices) override;
384 
385  // Material Support
386  USDIMAGING_API
387  virtual SdfPath GetMaterialId(SdfPath const &rprimId) override;
388 
389  USDIMAGING_API
390  virtual VtValue GetMaterialResource(SdfPath const &materialId) override;
391 
392  // Light Support
393  USDIMAGING_API
394  virtual VtValue GetLightParamValue(SdfPath const &id,
395  TfToken const &paramName) override;
396  // Camera Support
397  USDIMAGING_API
398  virtual VtValue GetCameraParamValue(SdfPath const &id,
399  TfToken const &paramName) override;
400 
401  // Volume Support
402  USDIMAGING_API
403  virtual HdVolumeFieldDescriptorVector
404  GetVolumeFieldDescriptors(SdfPath const &volumeId) override;
405 
406  // Picking path resolution
407  // Resolves a \p rprimId and \p instanceIndex back to the original USD
408  // gprim and instance index. For point-instanced prims, \p instanceContext
409  // returns extra information about which instance this is of which level of
410  // point-instancer. For example:
411  // /World/PI instances /World/PI/proto/PI
412  // /World/PI/proto/PI instances /World/PI/proto/PI/proto/Gprim
413  // instancerContext = [/World/PI, 0], [/World/PI/proto/PI, 1] means that
414  // this instance represents "protoIndex = 0" of /World/PI, etc.
415 
416  USDIMAGING_API
417  virtual SdfPath
418  GetScenePrimPath(SdfPath const& rprimId,
419  int instanceIndex,
420  HdInstancerContext *instancerContext = nullptr) override;
421 
422  USDIMAGING_API
423  virtual SdfPathVector
424  GetScenePrimPaths(SdfPath const& rprimId,
425  std::vector<int> instanceIndices,
426  std::vector<HdInstancerContext> *instancerContexts = nullptr) override;
427 
428  // ExtComputation support
429  USDIMAGING_API
431  GetExtComputationSceneInputNames(SdfPath const& computationId) override;
432 
433  USDIMAGING_API
434  HdExtComputationInputDescriptorVector
435  GetExtComputationInputDescriptors(SdfPath const& computationId) override;
436 
437  USDIMAGING_API
438  HdExtComputationOutputDescriptorVector
439  GetExtComputationOutputDescriptors(SdfPath const& computationId) override;
440 
441  USDIMAGING_API
442  HdExtComputationPrimvarDescriptorVector
443  GetExtComputationPrimvarDescriptors(SdfPath const& computationId,
444  HdInterpolation interpolation) override;
445 
446  USDIMAGING_API
447  VtValue GetExtComputationInput(SdfPath const& computationId,
448  TfToken const& input) override;
449 
450  USDIMAGING_API
451  size_t SampleExtComputationInput(SdfPath const& computationId,
452  TfToken const& input,
453  size_t maxSampleCount,
454  float *sampleTimes,
455  VtValue *sampleValues) override;
456 
457  USDIMAGING_API
458  std::string GetExtComputationKernel(SdfPath const& computationId) override;
459 
460  USDIMAGING_API
461  void InvokeExtComputation(SdfPath const& computationId,
462  HdExtComputationContext *context) override;
463 
464 public:
465  // Converts a cache path to a path in the render index.
466  USDIMAGING_API
467  SdfPath ConvertCachePathToIndexPath(SdfPath const& cachePath) {
468  SdfPathMap::const_iterator it = _cache2indexPath.find(cachePath);
469  if (it != _cache2indexPath.end()) {
470  return it->second;
471  }
472 
473  // For pure/plain usdImaging, there is no prefix to replace
474  SdfPath const &delegateID = GetDelegateID();
475  if (delegateID == SdfPath::AbsoluteRootPath()) {
476  return cachePath;
477  }
478  if (cachePath.IsEmpty()) {
479  return cachePath;
480  }
481 
482  return cachePath.ReplacePrefix(SdfPath::AbsoluteRootPath(), delegateID);
483  }
484 
490  USDIMAGING_API
492  SdfPathMap::const_iterator it = _index2cachePath.find(indexPath);
493  if (it != _index2cachePath.end()) {
494  return it->second;
495  }
496 
497  // For pure/plain usdImaging, there is no prefix to replace
498  SdfPath const &delegateID = GetDelegateID();
499  if (delegateID == SdfPath::AbsoluteRootPath()) {
500  return indexPath;
501  }
502 
503  return indexPath.ReplacePrefix(delegateID, SdfPath::AbsoluteRootPath());
504  }
505 
520  static constexpr int ALL_INSTANCES = -1;
521  USDIMAGING_API
522  bool PopulateSelection(HdSelection::HighlightMode const& highlightMode,
523  const SdfPath &usdPath,
524  int instanceIndex,
525  HdSelectionSharedPtr const &result);
526 
528  USDIMAGING_API
529  bool IsInInvisedPaths(const SdfPath &usdPath) const;
530 
531 private:
532  // Internal Get and SamplePrimvar
533  VtValue _Get(SdfPath const& id, TfToken const& key, VtIntArray *outIndices);
534 
535  size_t _SamplePrimvar(SdfPath const& id, TfToken const& key,
536  size_t maxNumSamples, float *times, VtValue *samples,
537  VtIntArray *indices);
538 
539  // Internal friend class.
540  class _Worker;
541  friend class UsdImagingIndexProxy;
542  friend class UsdImagingPrimAdapter;
543 
544  bool _ValidateRefineLevel(int level) {
545  if (!(0 <= level && level <= 8)) {
546  TF_CODING_ERROR("Invalid refinement level(%d), "
547  "expected range is [0,8]",
548  level);
549  return false;
550  }
551  return true;
552  }
553 
554  void _AddTask(UsdImagingDelegate::_Worker *worker, SdfPath const& usdPath);
555 
556  // ---------------------------------------------------------------------- //
557  // Draw mode support
558  // ---------------------------------------------------------------------- //
559  // Determine whether to assign a draw mode adapter to the given prim.
560  bool _IsDrawModeApplied(UsdPrim const& prim);
561  // Get the inherited model:drawMode attribute of the given prim.
562  TfToken _GetModelDrawMode(UsdPrim const& prim);
563 
564  // ---------------------------------------------------------------------- //
565  // Usd Change Processing / Notice Handlers
566  // ---------------------------------------------------------------------- //
567  void _OnUsdObjectsChanged(UsdNotice::ObjectsChanged const&,
568  UsdStageWeakPtr const& sender);
569 
570  // Map holding USD subtree path keys mapped to associated hydra prim cache
571  // paths. This may be prepopulated and provided to the Refresh and Resync
572  // methods below to speed up dependency gathering.
573  typedef TfHashMap<SdfPath, SdfPathVector, SdfPath::Hash>
574  _FlattenedDependenciesCacheMap;
575 
576  // The lightest-weight update, it does fine-grained invalidation of
577  // individual properties at the given path (prim or property).
578  //
579  // If \p path is a prim path, changedPrimInfoFields will be populated
580  // with the list of scene description fields that caused this prim to
581  // be refreshed.
582  //
583  // Returns whether the prim or the subtree rooted at `usdPath` needed to
584  // be resync'd (i.e., removed and repopulated).
585  //
586  bool _RefreshUsdObject(SdfPath const& usdPath,
587  TfTokenVector const& changedPrimInfoFields,
588  _FlattenedDependenciesCacheMap const &cache,
589  UsdImagingIndexProxy* proxy,
590  SdfPathSet* allTrackedVariabilityPaths);
591 
592  // Heavy-weight invalidation of an entire prim subtree. All cached data is
593  // reconstructed for all prims below \p rootPath.
594  //
595  // By default, _ResyncPrim will remove each affected prim and call
596  // Repopulate() on those prims individually. If repopulateFromRoot is
597  // true, Repopulate() will be called on \p rootPath instead. This is slower,
598  // but handles changes in tree topology.
599  void _ResyncUsdPrim(SdfPath const& usdRootPath,
600  _FlattenedDependenciesCacheMap const &cache,
601  UsdImagingIndexProxy* proxy,
602  bool repopulateFromRoot = false);
603 
604  // ---------------------------------------------------------------------- //
605  // Usd Data-Access Helper Methods
606  // ---------------------------------------------------------------------- //
607  UsdPrim _GetUsdPrim(SdfPath const& usdPath) {
608  UsdPrim const& p =
609  _stage->GetPrimAtPath(usdPath.GetAbsoluteRootOrPrimPath());
610  TF_VERIFY(p, "No prim found for id: %s",
611  usdPath.GetAbsoluteRootOrPrimPath().GetText());
612  return p;
613  }
614 
615  VtValue _GetUsdPrimAttribute(SdfPath const& cachePath,
616  TfToken const &attrName);
617 
618  void _UpdateSingleValue(SdfPath const& cachePath, int dirtyFlags);
619 
620  // ---------------------------------------------------------------------- //
621  // Cache structures and related methods for population.
622  // ---------------------------------------------------------------------- //
623 
624  // Returns true if this delegate can be populated, false otherwise.
625  bool _CanPopulate(UsdPrim const& rootPrim) const;
626 
627  // Set the delegate's state to reflect that it will be populated from
628  // the given root prim with the given excluded paths.
629  void _SetStateForPopulation(UsdPrim const& rootPrim,
630  SdfPathVector const& excludedPaths,
631  SdfPathVector const& invisedPaths);
632 
633  // Populates this delegate's render index from the paths specified
634  // in the given index proxy.
635  void _Populate(class UsdImagingIndexProxy* proxy);
636 
637  // Execute all variability update tasks that have been added to the given
638  // worker.
639  static void _ExecuteWorkForVariabilityUpdate(_Worker* worker);
640 
644  bool _GetVisible(UsdPrim const& prim);
645 
647  TfTokenVector _GetPrimvarNames(SdfPath const& usdPath,
648  TfToken const& interpolation);
649 
650  // ---------------------------------------------------------------------- //
651  // Helper methods for updating the delegate on time changes
652  // ---------------------------------------------------------------------- //
653 
654  // Execute all time update tasks that have been added to the given worker.
655  static void _ExecuteWorkForTimeUpdate(_Worker* worker);
656 
657  // ---------------------------------------------------------------------- //
658  // Core Delegate state
659  // ---------------------------------------------------------------------- //
660 
661  // Usd Prim Type to Adapter lookup table.
662  typedef TfHashMap<TfToken, UsdImagingPrimAdapterSharedPtr,
663  TfToken::HashFunctor> _AdapterMap;
664  _AdapterMap _adapterMap;
665 
666  // Per-Hydra-Primitive tracking data
667  struct _HdPrimInfo {
668  UsdImagingPrimAdapterSharedPtr adapter; // The adapter to use for the
669  // prim
670  UsdPrim usdPrim; // Reference to the Usd prim
671  HdDirtyBits timeVaryingBits; // Dirty Bits to set when
672  // time changes
673  HdDirtyBits dirtyBits; // Current dirty state of the prim.
675  extraDependencies;// Dependencies that aren't usdPrim.
676  };
677 
678  typedef TfHashMap<SdfPath, _HdPrimInfo, SdfPath::Hash> _HdPrimInfoMap;
679 
680  // Map from cache path to Hydra prim info
681  _HdPrimInfoMap _hdPrimInfoMap;
682 
683  typedef std::multimap<SdfPath, SdfPath> _DependencyMap;
684 
685  // Map from USD path to Hydra path, for tracking USD->hydra dependencies.
686  _DependencyMap _dependencyInfo;
687 
688  // Appends hydra prim cache paths corresponding to the USD subtree
689  // provided by looking up the dependency map (above).
690  void _GatherDependencies(SdfPath const& subtree,
691  SdfPathVector *affectedCachePaths);
692 
693  // Overload that takes an additional cache argument to help speed up the
694  // dependency gathering operation. The onus is on the client to prepopulate
695  // the cache.
696  void
697  _GatherDependencies(SdfPath const &subtree,
698  _FlattenedDependenciesCacheMap const &cache,
699  SdfPathVector *affectedCachePaths);
700 
701  // SdfPath::ReplacePrefix() is used frequently to convert between
702  // cache path and Hydra render index path and is a performance bottleneck.
703  // These maps pre-computes these conversion.
704  typedef TfHashMap<SdfPath, SdfPath, SdfPath::Hash> SdfPathMap;
705  SdfPathMap _cache2indexPath;
706  SdfPathMap _index2cachePath;
707 
708  // Only use this method when we think no existing adapter has been
709  // established. For example, during initial Population.
710  UsdImagingPrimAdapterSharedPtr const& _AdapterLookup(
711  UsdPrim const& prim,
712  bool ignoreInstancing = false);
713  UsdImagingPrimAdapterSharedPtr const& _AdapterLookup(
714  TfToken const& adapterKey);
715 
716  // Obtain the prim tracking data for the given cache path.
717  _HdPrimInfo *_GetHdPrimInfo(const SdfPath &cachePath);
718 
719  Usd_PrimFlagsConjunction _GetDisplayPredicate() const;
720  Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes() const;
721 
722  // Mark render tags dirty for all prims.
723  // This is done in response to toggling the purpose-based display settings.
724  void _MarkRenderTagsDirty();
725 
726  typedef TfHashSet<SdfPath, SdfPath::Hash> _DirtySet;
727 
728  // Set of cache paths that are due a Sync()
729  _DirtySet _dirtyCachePaths;
730 
732  typedef TfHashMap<SdfPath, int, SdfPath::Hash> _RefineLevelMap;
734  _RefineLevelMap _refineLevelMap;
735 
737  UsdImagingPrimvarDescCache _primvarDescCache;
738 
740  UsdStageRefPtr _stage;
741  SdfPath _rootPrimPath;
742  SdfPathVector _excludedPrimPaths;
743  SdfPathVector _invisedPrimPaths;
744 
745  RigidXformOverridesMap _rigidXformOverrides;
746 
747  // Aspects of the delegate root that apply to all items in the index.
748  SdfPath _compensationPath;
749 
750  GfMatrix4d _rootXf;
751  bool _rootIsVisible;
752  SdfPath _rootInstancerId;
753 
755  UsdTimeCode _time;
756 
758  SdfPath _cameraPathForSampling;
759 
760  int _refineLevelFallback;
761  HdReprSelector _reprFallback;
762  HdCullStyle _cullStyleFallback;
763 
764  // Cache of which prims are time-varying.
765  SdfPathVector _timeVaryingPrimCache;
766  bool _timeVaryingPrimCacheValid;
767 
768  // Change processing
769  TfNotice::Key _objectsChangedNoticeKey;
770  SdfPathVector _usdPathsToResync;
771 
772  // Map from path of Usd object to update to list of changed scene
773  // description fields for that object. This list of fields is only
774  // populated for prim paths.
775  typedef std::unordered_map<SdfPath, TfTokenVector, SdfPath::Hash>
776  _PathsToUpdateMap;
777  _PathsToUpdateMap _usdPathsToUpdate;
778 
779  UsdImaging_XformCache _xformCache;
780  UsdImaging_MaterialBindingImplData _materialBindingImplData;
781  UsdImaging_MaterialBindingCache _materialBindingCache;
782  UsdImaging_CoordSysBindingCache _coordSysBindingCache;
783  UsdImaging_VisCache _visCache;
784  UsdImaging_PurposeCache _purposeCache;
785  UsdImaging_DrawModeCache _drawModeCache;
786  UsdImaging_CollectionCache _collectionCache;
787  UsdImaging_InheritedPrimvarCache _inheritedPrimvarCache;
788  UsdImaging_PointInstancerIndicesCache _pointInstancerIndicesCache;
789  UsdImaging_NonlinearSampleCountCache _nonlinearSampleCountCache;
790  UsdImaging_BlurScaleCache _blurScaleCache;
791 
792  // Pickability
793  PickabilityMap _pickablesMap;
794 
795  // Purpose-based rendering toggles
796  bool _displayRender;
797  bool _displayProxy;
798  bool _displayGuides;
799  bool _enableUsdDrawModes;
800 
801  const bool _hasDrawModeAdapter;
802 
804  bool _sceneMaterialsEnabled;
805 
807  bool _sceneLightsEnabled;
808 
809  CameraUtilConformWindowPolicy _appWindowPolicy;
810 
811  // Enable HdCoordSys tracking
812  const bool _coordSysEnabled;
813 
814  // Display unloaded prims with Bounds adapter
815  bool _displayUnloadedPrimsWithBounds;
816 
817  UsdImagingDelegate() = delete;
818  UsdImagingDelegate(UsdImagingDelegate const &) = delete;
819  UsdImagingDelegate &operator =(UsdImagingDelegate const &) = delete;
820 };
821 
822 PXR_NAMESPACE_CLOSE_SCOPE
823 
824 #endif //PXR_USD_IMAGING_USD_IMAGING_DELEGATE_H
virtual USDIMAGING_API TfToken GetRenderTag(SdfPath const &id) override
Returns the render tag that will be used to bucket prims during render pass bucketing.
Interface class that defines the execution environment for the client to run a computation.
Handle-object returned by TfNotice::Register().
Definition: notice.h:256
Tags for non-hierarchial subdiv surfaces.
Definition: subdivTags.h:43
USDIMAGING_API void SetDisplayUnloadedPrimsWithBounds(bool displayUnloaded)
Sets display of unloaded prims as bounding boxes.
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:120
Basic type: 3-dimensional floating point range.
Definition: range3d.h:63
USDIMAGING_API SdfPath ConvertIndexPathToCachePath(SdfPath const &indexPath)
Convert the given Hydra ID to a UsdImaging cache path, by stripping the scene delegate prefix.
Definition: delegate.h:491
static constexpr int ALL_INSTANCES
Populate HdxSelection for given path (root) and instanceIndex.
Definition: delegate.h:520
USDIMAGING_API void SetPickability(SdfPath const &path, bool pickable)
Sets pickability for a specific path.
#define TF_DECLARE_WEAK_PTRS(type)
Define standard weak pointer types.
Definition: declarePtrs.h:62
Standard pointer typedefs.
USDIMAGING_API void SetRigidXformOverrides(RigidXformOverridesMap const &overrides)
Set transform value overrides on a set of paths.
virtual USDIMAGING_API size_t SampleTransform(SdfPath const &id, size_t maxNumSamples, float *times, GfMatrix4d *samples) override
Store up to maxSampleCount transform samples in *sampleValues.
USDIMAGING_API void SetRefineLevelFallback(int level)
Sets the fallback refinement level to level, triggers dirty refine level bit to be set on all Rprims ...
Describes how the geometry of a prim should be displayed.
Definition: sceneDelegate.h:80
USDIMAGING_API void SetDisplayRender(const bool displayRender)
Sets display of prims with purpose "render".
USDIMAGING_API void SetUsdDrawModesEnabled(bool enableUsdDrawModes)
Returns whether draw modes are enabled.
USDIMAGING_API HdExtComputationPrimvarDescriptorVector GetExtComputationPrimvarDescriptors(SdfPath const &computationId, HdInterpolation interpolation) override
Returns a list of primvar names that should be bound to a generated output from an ExtComputation for...
virtual USDIMAGING_API size_t SamplePrimvar(SdfPath const &id, TfToken const &key, size_t maxNumSamples, float *times, VtValue *samples) override
Store up to maxSampleCount primvar samples in *samplesValues.
virtual USDIMAGING_API GfRange3d GetExtent(SdfPath const &id) override
Gets the axis aligned bounds of a prim.
virtual USDIMAGING_API std::vector< VtArray< TfToken > > GetInstanceCategories(SdfPath const &instancerId) override
Returns the categories for all instances in the instancer.
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Definition: diagnostic.h:85
virtual USDIMAGING_API SubdivTags GetSubdivTags(SdfPath const &id) override
Gets the subdivision surface tags (sharpness, holes, etc).
USDIMAGING_API PickabilityMap GetPickabilityMap() const
Returns the root paths of pickable objects.
virtual USDIMAGING_API bool GetVisible(SdfPath const &id) override
Returns the authored visible state of the prim.
HighlightMode
Selection modes allow differentiation in selection highlight behavior.
Definition: selection.h:56
Functor to use for hash maps from tokens to other things.
Definition: token.h:166
USDIMAGING_API void SetRootTransform(GfMatrix4d const &xf)
Sets the root transform for the entire delegate, which is applied to all render prims generated.
This proxy class exposes a subset of the private Delegate API to PrimAdapters.
Definition: indexProxy.h:47
HdCullStyle GetCullStyleFallback() const
Returns the fallback cull style.
Definition: delegate.h:188
virtual USDIMAGING_API SdfPath GetInstancerId(SdfPath const &primId) override
Returns the parent instancer of the given rprim or instancer.
USDIMAGING_API void SetDisplayGuides(const bool displayGuides)
Sets display of prims with purpose "guide".
UsdTimeCode GetTimeWithOffset(float offset) const
Apply a relative offset to the current time.
SDF_API const char * GetText() const
Returns the string representation of this path as a c string.
SDF_API SdfPath ReplacePrefix(const SdfPath &oldPrefix, const SdfPath &newPrefix, bool fixTargetPaths=true) const
Returns a path with all occurrences of the prefix path oldPrefix replaced with the prefix path newPre...
USDIMAGING_API HdExtComputationInputDescriptorVector GetExtComputationInputDescriptors(SdfPath const &computationId) override
For the given computation id, returns a list of computation input descriptors.
virtual USDIMAGING_API VtArray< TfToken > GetCategories(SdfPath const &id) override
Returns the prim categories.
virtual USDIMAGING_API GfMatrix4d GetInstancerTransform(SdfPath const &instancerId) override
Returns the instancer transform.
SdfPath const & GetDelegateID() const
Returns the ID of this delegate, which is used as a prefix for all objects it creates in the RenderIn...
USDIMAGING_API void SetInvisedPrimPaths(SdfPathVector const &invisedPaths)
Set the list of paths that must be invised.
USDIMAGING_API void ApplyPendingUpdates()
Applies any scene edits which have been queued up by notices from USD.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
USDIMAGING_API GfInterval GetCurrentTimeSamplingInterval()
Returns the current interval that will be used when using the sample* API in the scene delegate.
virtual USDIMAGING_API SdfPathVector GetScenePrimPaths(SdfPath const &rprimId, std::vector< int > instanceIndices, std::vector< HdInstancerContext > *instancerContexts=nullptr) override
A vectorized version of GetScenePrimPath that allows the prim adapter to amortize expensive calculati...
USDIMAGING_API void SetReprFallback(HdReprSelector const &repr)
Sets the fallback repr name.
virtual USDIMAGING_API HdMeshTopology GetMeshTopology(SdfPath const &id) override
Gets the topological mesh data for a given prim.
USDIMAGING_API bool IsInInvisedPaths(const SdfPath &usdPath) const
Returns true if usdPath is included in invised path list.
USDIMAGING_API void SetRootVisibility(bool isVisible)
Sets the root visibility for the entire delegate, which is applied to all render prims generated.
const GfMatrix4d & GetRootTransform() const
Returns the root transform for the entire delegate.
Definition: delegate.h:201
USDIMAGING_API std::string GetExtComputationKernel(SdfPath const &computationId) override
Returns the kernel source assigned to the computation at the path id.
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:87
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Definition: diagnostic.h:283
USDIMAGING_API TfTokenVector GetExtComputationSceneInputNames(SdfPath const &computationId) override
For the given computation id, returns a list of inputs which will be requested from the scene delegat...
HdReprSelector GetReprFallback() const
Returns the fallback repr name.
Definition: delegate.h:180
virtual USDIMAGING_API VtValue Get(SdfPath const &id, TfToken const &key) override
Returns a named value.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
Adapter class providing data exchange with the client scene graph.
Base class for all PrimAdapters.
Definition: primAdapter.h:67
Notice sent in response to authored changes that affect UsdObjects.
Definition: notice.h:107
virtual USDIMAGING_API VtIntArray GetInstanceIndices(SdfPath const &instancerId, SdfPath const &prototypeId) override
Gets the extracted indices array of the prototype id used in the instancer.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:135
virtual USDIMAGING_API VtValue GetCameraParamValue(SdfPath const &id, TfToken const &paramName) override
Returns a single value for a given camera and parameter.
virtual USDIMAGING_API void Sync(HdSyncRequestVector *request) override
Synchronizes the delegate state for the given request vector.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
A basic mathematical interval class.
Definition: interval.h:49
virtual USDIMAGING_API HdBasisCurvesTopology GetBasisCurvesTopology(SdfPath const &id) override
Gets the topological curve data for a given prim.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
USDIMAGING_API void InvokeExtComputation(SdfPath const &computationId, HdExtComputationContext *context) override
Requests the scene delegate run the ExtComputation with the given id.
A cache for primvar descriptors.
Topology data for basisCurves.
virtual USDIMAGING_API HdReprSelector GetReprSelector(SdfPath const &id) override
Returns the authored repr (if any) for the given prim.
USDIMAGING_API void SetTime(UsdTimeCode time)
Sets the current time from which data will be read by the delegate.
UsdTimeCode GetTime() const
Returns the current time.
Definition: delegate.h:138
USDIMAGING_API void SetSceneLightsEnabled(bool enable)
Enables lights found in the usdscene.
static USDIMAGING_API void SetTimes(const std::vector< UsdImagingDelegate * > &delegates, const std::vector< UsdTimeCode > &times)
For each delegate in delegates, sets the current time from which data wil be read to the correspondin...
USDIMAGING_API void SetSceneMaterialsEnabled(bool enable)
Enables custom shading on prims.
virtual USDIMAGING_API SdfPath GetScenePrimPath(SdfPath const &rprimId, int instanceIndex, HdInstancerContext *instancerContext=nullptr) override
Returns the scene address of the prim corresponding to the given rprim/instance index.
USDIMAGING_API void SetCameraForSampling(SdfPath const &id)
Setup for the shutter open and close to be used for motion sampling.
virtual USDIMAGING_API GfMatrix4d GetTransform(SdfPath const &id) override
Returns the object space transform, including all parent transforms.
USDIMAGING_API HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(SdfPath const &computationId) override
For the given computation id, returns a list of computation output descriptors.
USDIMAGING_API VtValue GetExtComputationInput(SdfPath const &computationId, TfToken const &input) override
Returns a single value for a given computation id and input token.
virtual USDIMAGING_API VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key, VtIntArray *outIndices) override
Returns a named primvar value.
static SDF_API const SdfPath & AbsoluteRootPath()
The absolute path representing the top of the namespace hierarchy.
The SceneDelegate is requested to synchronize prims as the result of executing a specific render pass...
Definition: sceneDelegate.h:68
USDIMAGING_API void Populate(UsdPrim const &rootPrim)
Populates the rootPrim in the HdRenderIndex.
virtual USDIMAGING_API HdPrimvarDescriptorVector GetPrimvarDescriptors(SdfPath const &id, HdInterpolation interpolation) override
Returns descriptors for all primvars of the given interpolation type.
Describes one or more authored display representations for an rprim.
Definition: repr.h:48
USDIMAGING_API void ClearPickabilityMap()
Clears any pickability opinions that this delegates might have.
virtual USDIMAGING_API bool GetDoubleSided(SdfPath const &id) override
Returns the doubleSided state for the given prim.
USDIMAGING_API void SetWindowPolicy(CameraUtilConformWindowPolicy policy)
Set the window policy on all scene cameras.
USDIMAGING_API size_t SampleExtComputationInput(SdfPath const &computationId, TfToken const &input, size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues) override
Return up to maxSampleCount samples for a given computation id and input token.
virtual USDIMAGING_API SdfPath GetMaterialId(SdfPath const &rprimId) override
Returns the material ID bound to the rprim rprimId.
virtual USDIMAGING_API size_t SampleInstancerTransform(SdfPath const &instancerId, size_t maxSampleCount, float *times, GfMatrix4d *samples) override
Store up to maxSampleCount transform samples in *sampleValues.
USDIMAGING_API void SetCullStyleFallback(HdCullStyle cullStyle)
Sets the fallback cull style.
Object used by instancer prim adapters to pass along context about the instancer and instance prim to...
Topology data for meshes.
Definition: meshTopology.h:55
virtual USDIMAGING_API HdDisplayStyle GetDisplayStyle(SdfPath const &id) override
Gets the explicit display style for the given prim, if no refine level is explicitly set,...
USDIMAGING_API void ClearRefineLevel(SdfPath const &usdPath)
Removes any explicit refine level set for the given USD prim.
bool GetRootVisibility() const
Returns the root visibility for the entire delegate.
Definition: delegate.h:210
USDIMAGING_API void SetDisplayProxy(const bool displayProxy)
Sets display of prims with purpose "proxy".
The primary translation layer between the Hydra (Hd) core and the Usd scene graph.
Definition: delegate.h:87
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
Definition: path.h:419
USDIMAGING_API void SetRootInstancerId(SdfPath const &instancerId)
Sets the root instancer id for the entire delegate, which is used as a fallback value for GetInstance...
int GetRefineLevelFallback() const
Returns the refinement level that is used when prims have no explicit level set.
Definition: delegate.h:155
Enable a concrete base class for use with TfWeakPtr.
Definition: weakBase.h:141
USDIMAGING_API virtual HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id) override
Returns the coordinate system bindings, or a nullptr if none are bound.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:166
virtual USDIMAGING_API SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override
Returns a list of prototypes of this instancer.
SDF_API SdfPath GetAbsoluteRootOrPrimPath() const
Creates a path by stripping all properties and relational attributes from this path,...
virtual USDIMAGING_API HdCullStyle GetCullStyle(SdfPath const &id) override
Returns the cullstyle for the given prim.
virtual USDIMAGING_API size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key, size_t maxNumSamples, float *times, VtValue *samples, VtIntArray *indices) override
SamplePrimvar() for getting an unflattened primvar and its indices.
SdfPath GetRootInstancerId() const
Returns the root instancer id for the entire delegate.
Definition: delegate.h:218
USDIMAGING_API void SetRefineLevel(SdfPath const &usdPath, int level)
Sets an explicit refinement level for the given USD prim.