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 
213  USDIMAGING_API
214  void SetInvisedPrimPaths(SdfPathVector const &invisedPaths);
215 
217  USDIMAGING_API
218  void SetRigidXformOverrides(RigidXformOverridesMap const &overrides);
219 
221  USDIMAGING_API
222  PickabilityMap GetPickabilityMap() const;
223 
225  USDIMAGING_API
226  void SetPickability(SdfPath const& path, bool pickable);
227 
229  USDIMAGING_API
230  void ClearPickabilityMap();
231 
233  USDIMAGING_API
234  void SetDisplayRender(const bool displayRender);
235  bool GetDisplayRender() const { return _displayRender; }
236 
238  USDIMAGING_API
239  void SetDisplayProxy(const bool displayProxy);
240  bool GetDisplayProxy() const { return _displayProxy; }
241 
243  USDIMAGING_API
244  void SetDisplayGuides(const bool displayGuides);
245  bool GetDisplayGuides() const { return _displayGuides; }
246 
248  USDIMAGING_API
249  void SetUsdDrawModesEnabled(bool enableUsdDrawModes);
250  bool GetUsdDrawModesEnabled() const { return _enableUsdDrawModes; }
251 
253  USDIMAGING_API
254  void SetSceneMaterialsEnabled(bool enable);
255 
257  USDIMAGING_API
258  void SetSceneLightsEnabled(bool enable);
259 
262  USDIMAGING_API
263  void SetWindowPolicy(CameraUtilConformWindowPolicy policy);
264 
273  USDIMAGING_API
274  void SetDisplayUnloadedPrimsWithBounds(bool displayUnloaded);
275  bool GetDisplayUnloadedPrimsWithBounds() const {
276  return _displayUnloadedPrimsWithBounds;
277  }
278 
280  USDIMAGING_API
281  void SetCameraForSampling(SdfPath const& id);
282 
285  USDIMAGING_API
287 
288  // ---------------------------------------------------------------------- //
289  // See HdSceneDelegate for documentation of the following virtual methods.
290  // ---------------------------------------------------------------------- //
291  USDIMAGING_API
292  virtual TfToken GetRenderTag(SdfPath const& id) override;
293  USDIMAGING_API
294  virtual HdMeshTopology GetMeshTopology(SdfPath const& id) override;
295  USDIMAGING_API
297  override;
298  typedef PxOsdSubdivTags SubdivTags;
299 
300  // XXX: animated subdiv tags are not currently supported
301  // XXX: subdiv tags currently fetched on-demand
302  USDIMAGING_API
303  virtual SubdivTags GetSubdivTags(SdfPath const& id) override;
304 
305  USDIMAGING_API
306  virtual GfRange3d GetExtent(SdfPath const & id) override;
307  USDIMAGING_API
308  virtual GfMatrix4d GetTransform(SdfPath const & id) override;
309  USDIMAGING_API
310  virtual bool GetVisible(SdfPath const & id) override;
311  USDIMAGING_API
312  virtual bool GetDoubleSided(SdfPath const & id) override;
313  USDIMAGING_API
314  virtual HdCullStyle GetCullStyle(SdfPath const &id) override;
315 
319  USDIMAGING_API
320  virtual HdDisplayStyle GetDisplayStyle(SdfPath const& id) override;
321 
322  USDIMAGING_API
323  virtual VtValue Get(SdfPath const& id, TfToken const& key) override;
324  USDIMAGING_API
325  virtual VtValue GetIndexedPrimvar(SdfPath const& id,
326  TfToken const& key,
327  VtIntArray *outIndices) override;
328  USDIMAGING_API
329  HdIdVectorSharedPtr
330  virtual GetCoordSysBindings(SdfPath const& id) override;
331  USDIMAGING_API
332  virtual HdReprSelector GetReprSelector(SdfPath const &id) override;
333  USDIMAGING_API
334  virtual VtArray<TfToken> GetCategories(SdfPath const &id) override;
335  USDIMAGING_API
336  virtual std::vector<VtArray<TfToken>>
337  GetInstanceCategories(SdfPath const &instancerId) override;
338  USDIMAGING_API
339  virtual HdPrimvarDescriptorVector
340  GetPrimvarDescriptors(SdfPath const& id,
341  HdInterpolation interpolation) override;
342  USDIMAGING_API
343  virtual VtIntArray GetInstanceIndices(SdfPath const &instancerId,
344  SdfPath const &prototypeId) override;
345  USDIMAGING_API
346  virtual GfMatrix4d GetInstancerTransform(SdfPath const &instancerId)
347  override;
348 
349  USDIMAGING_API
350  virtual SdfPath GetInstancerId(SdfPath const &primId) override;
351 
352  USDIMAGING_API
353  virtual SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override;
354 
355  // Motion samples
356  USDIMAGING_API
357  virtual size_t
358  SampleTransform(SdfPath const & id, size_t maxNumSamples,
359  float *times, GfMatrix4d *samples) override;
360  USDIMAGING_API
361  virtual size_t
362  SampleInstancerTransform(SdfPath const &instancerId,
363  size_t maxSampleCount, float *times,
364  GfMatrix4d *samples) override;
365  USDIMAGING_API
366  virtual size_t
367  SamplePrimvar(SdfPath const& id, TfToken const& key,
368  size_t maxNumSamples, float *times,
369  VtValue *samples) override;
370 
371  USDIMAGING_API
372  virtual size_t
373  SampleIndexedPrimvar(SdfPath const& id, TfToken const& key,
374  size_t maxNumSamples, float *times,
375  VtValue *samples, VtIntArray *indices) override;
376 
377  // Material Support
378  USDIMAGING_API
379  virtual SdfPath GetMaterialId(SdfPath const &rprimId) override;
380 
381  USDIMAGING_API
382  virtual VtValue GetMaterialResource(SdfPath const &materialId) override;
383 
384  // Light Support
385  USDIMAGING_API
386  virtual VtValue GetLightParamValue(SdfPath const &id,
387  TfToken const &paramName) override;
388  // Camera Support
389  USDIMAGING_API
390  virtual VtValue GetCameraParamValue(SdfPath const &id,
391  TfToken const &paramName) override;
392 
393  // Volume Support
394  USDIMAGING_API
395  virtual HdVolumeFieldDescriptorVector
396  GetVolumeFieldDescriptors(SdfPath const &volumeId) override;
397 
398  // Picking path resolution
399  // Resolves a \p rprimId and \p instanceIndex back to the original USD
400  // gprim and instance index. For point-instanced prims, \p instanceContext
401  // returns extra information about which instance this is of which level of
402  // point-instancer. For example:
403  // /World/PI instances /World/PI/proto/PI
404  // /World/PI/proto/PI instances /World/PI/proto/PI/proto/Gprim
405  // instancerContext = [/World/PI, 0], [/World/PI/proto/PI, 1] means that
406  // this instance represents "protoIndex = 0" of /World/PI, etc.
407 
408  USDIMAGING_API
409  virtual SdfPath
410  GetScenePrimPath(SdfPath const& rprimId,
411  int instanceIndex,
412  HdInstancerContext *instancerContext = nullptr) override;
413 
414  USDIMAGING_API
415  virtual SdfPathVector
416  GetScenePrimPaths(SdfPath const& rprimId,
417  std::vector<int> instanceIndices,
418  std::vector<HdInstancerContext> *instancerContexts = nullptr) override;
419 
420  // ExtComputation support
421  USDIMAGING_API
423  GetExtComputationSceneInputNames(SdfPath const& computationId) override;
424 
425  USDIMAGING_API
426  HdExtComputationInputDescriptorVector
427  GetExtComputationInputDescriptors(SdfPath const& computationId) override;
428 
429  USDIMAGING_API
430  HdExtComputationOutputDescriptorVector
431  GetExtComputationOutputDescriptors(SdfPath const& computationId) override;
432 
433  USDIMAGING_API
434  HdExtComputationPrimvarDescriptorVector
435  GetExtComputationPrimvarDescriptors(SdfPath const& computationId,
436  HdInterpolation interpolation) override;
437 
438  USDIMAGING_API
439  VtValue GetExtComputationInput(SdfPath const& computationId,
440  TfToken const& input) override;
441 
442  USDIMAGING_API
443  size_t SampleExtComputationInput(SdfPath const& computationId,
444  TfToken const& input,
445  size_t maxSampleCount,
446  float *sampleTimes,
447  VtValue *sampleValues) override;
448 
449  USDIMAGING_API
450  std::string GetExtComputationKernel(SdfPath const& computationId) override;
451 
452  USDIMAGING_API
453  void InvokeExtComputation(SdfPath const& computationId,
454  HdExtComputationContext *context) override;
455 
456 public:
457  // Converts a cache path to a path in the render index.
458  USDIMAGING_API
459  SdfPath ConvertCachePathToIndexPath(SdfPath const& cachePath) {
460  SdfPathMap::const_iterator it = _cache2indexPath.find(cachePath);
461  if (it != _cache2indexPath.end()) {
462  return it->second;
463  }
464 
465  // For pure/plain usdImaging, there is no prefix to replace
466  SdfPath const &delegateID = GetDelegateID();
467  if (delegateID == SdfPath::AbsoluteRootPath()) {
468  return cachePath;
469  }
470  if (cachePath.IsEmpty()) {
471  return cachePath;
472  }
473 
474  return cachePath.ReplacePrefix(SdfPath::AbsoluteRootPath(), delegateID);
475  }
476 
482  USDIMAGING_API
484  SdfPathMap::const_iterator it = _index2cachePath.find(indexPath);
485  if (it != _index2cachePath.end()) {
486  return it->second;
487  }
488 
489  // For pure/plain usdImaging, there is no prefix to replace
490  SdfPath const &delegateID = GetDelegateID();
491  if (delegateID == SdfPath::AbsoluteRootPath()) {
492  return indexPath;
493  }
494 
495  return indexPath.ReplacePrefix(delegateID, SdfPath::AbsoluteRootPath());
496  }
497 
512  static constexpr int ALL_INSTANCES = -1;
513  USDIMAGING_API
514  bool PopulateSelection(HdSelection::HighlightMode const& highlightMode,
515  const SdfPath &usdPath,
516  int instanceIndex,
517  HdSelectionSharedPtr const &result);
518 
520  USDIMAGING_API
521  bool IsInInvisedPaths(const SdfPath &usdPath) const;
522 
523 private:
524  // Internal Get and SamplePrimvar
525  VtValue _Get(SdfPath const& id, TfToken const& key, VtIntArray *outIndices);
526 
527  size_t _SamplePrimvar(SdfPath const& id, TfToken const& key,
528  size_t maxNumSamples, float *times, VtValue *samples,
529  VtIntArray *indices);
530 
531  // Internal friend class.
532  class _Worker;
533  friend class UsdImagingIndexProxy;
534  friend class UsdImagingPrimAdapter;
535 
536  bool _ValidateRefineLevel(int level) {
537  if (!(0 <= level && level <= 8)) {
538  TF_CODING_ERROR("Invalid refinement level(%d), "
539  "expected range is [0,8]",
540  level);
541  return false;
542  }
543  return true;
544  }
545 
546  void _AddTask(UsdImagingDelegate::_Worker *worker, SdfPath const& usdPath);
547 
548  // ---------------------------------------------------------------------- //
549  // Draw mode support
550  // ---------------------------------------------------------------------- //
551  // Determine whether to assign a draw mode adapter to the given prim.
552  bool _IsDrawModeApplied(UsdPrim const& prim);
553  // Get the inherited model:drawMode attribute of the given prim.
554  TfToken _GetModelDrawMode(UsdPrim const& prim);
555 
556  // ---------------------------------------------------------------------- //
557  // Usd Change Processing / Notice Handlers
558  // ---------------------------------------------------------------------- //
559  void _OnUsdObjectsChanged(UsdNotice::ObjectsChanged const&,
560  UsdStageWeakPtr const& sender);
561 
562  // Map holding USD subtree path keys mapped to associated hydra prim cache
563  // paths. This may be prepopulated and provided to the Refresh and Resync
564  // methods below to speed up dependency gathering.
565  typedef TfHashMap<SdfPath, SdfPathVector, SdfPath::Hash>
566  _FlattenedDependenciesCacheMap;
567 
568  // The lightest-weight update, it does fine-grained invalidation of
569  // individual properties at the given path (prim or property).
570  //
571  // If \p path is a prim path, changedPrimInfoFields will be populated
572  // with the list of scene description fields that caused this prim to
573  // be refreshed.
574  //
575  // Returns whether the prim or the subtree rooted at `usdPath` needed to
576  // be resync'd (i.e., removed and repopulated).
577  //
578  bool _RefreshUsdObject(SdfPath const& usdPath,
579  TfTokenVector const& changedPrimInfoFields,
580  _FlattenedDependenciesCacheMap const &cache,
581  UsdImagingIndexProxy* proxy,
582  SdfPathSet* allTrackedVariabilityPaths);
583 
584  // Heavy-weight invalidation of an entire prim subtree. All cached data is
585  // reconstructed for all prims below \p rootPath.
586  //
587  // By default, _ResyncPrim will remove each affected prim and call
588  // Repopulate() on those prims individually. If repopulateFromRoot is
589  // true, Repopulate() will be called on \p rootPath instead. This is slower,
590  // but handles changes in tree topology.
591  void _ResyncUsdPrim(SdfPath const& usdRootPath,
592  _FlattenedDependenciesCacheMap const &cache,
593  UsdImagingIndexProxy* proxy,
594  bool repopulateFromRoot = false);
595 
596  // ---------------------------------------------------------------------- //
597  // Usd Data-Access Helper Methods
598  // ---------------------------------------------------------------------- //
599  UsdPrim _GetUsdPrim(SdfPath const& usdPath) {
600  UsdPrim const& p =
601  _stage->GetPrimAtPath(usdPath.GetAbsoluteRootOrPrimPath());
602  TF_VERIFY(p, "No prim found for id: %s",
603  usdPath.GetAbsoluteRootOrPrimPath().GetText());
604  return p;
605  }
606 
607  VtValue _GetUsdPrimAttribute(SdfPath const& cachePath,
608  TfToken const &attrName);
609 
610  void _UpdateSingleValue(SdfPath const& cachePath, int dirtyFlags);
611 
612  // ---------------------------------------------------------------------- //
613  // Cache structures and related methods for population.
614  // ---------------------------------------------------------------------- //
615 
616  // Returns true if this delegate can be populated, false otherwise.
617  bool _CanPopulate(UsdPrim const& rootPrim) const;
618 
619  // Set the delegate's state to reflect that it will be populated from
620  // the given root prim with the given excluded paths.
621  void _SetStateForPopulation(UsdPrim const& rootPrim,
622  SdfPathVector const& excludedPaths,
623  SdfPathVector const& invisedPaths);
624 
625  // Populates this delegate's render index from the paths specified
626  // in the given index proxy.
627  void _Populate(class UsdImagingIndexProxy* proxy);
628 
629  // Execute all variability update tasks that have been added to the given
630  // worker.
631  static void _ExecuteWorkForVariabilityUpdate(_Worker* worker);
632 
636  bool _GetVisible(UsdPrim const& prim);
637 
639  TfTokenVector _GetPrimvarNames(SdfPath const& usdPath,
640  TfToken const& interpolation);
641 
642  // ---------------------------------------------------------------------- //
643  // Helper methods for updating the delegate on time changes
644  // ---------------------------------------------------------------------- //
645 
646  // Execute all time update tasks that have been added to the given worker.
647  static void _ExecuteWorkForTimeUpdate(_Worker* worker);
648 
649  // ---------------------------------------------------------------------- //
650  // Core Delegate state
651  // ---------------------------------------------------------------------- //
652 
653  // Usd Prim Type to Adapter lookup table.
654  typedef TfHashMap<TfToken, UsdImagingPrimAdapterSharedPtr,
655  TfToken::HashFunctor> _AdapterMap;
656  _AdapterMap _adapterMap;
657 
658  // Per-Hydra-Primitive tracking data
659  struct _HdPrimInfo {
660  UsdImagingPrimAdapterSharedPtr adapter; // The adapter to use for the
661  // prim
662  UsdPrim usdPrim; // Reference to the Usd prim
663  HdDirtyBits timeVaryingBits; // Dirty Bits to set when
664  // time changes
665  HdDirtyBits dirtyBits; // Current dirty state of the prim.
667  extraDependencies;// Dependencies that aren't usdPrim.
668  };
669 
670  typedef TfHashMap<SdfPath, _HdPrimInfo, SdfPath::Hash> _HdPrimInfoMap;
671 
672  // Map from cache path to Hydra prim info
673  _HdPrimInfoMap _hdPrimInfoMap;
674 
675  typedef std::multimap<SdfPath, SdfPath> _DependencyMap;
676 
677  // Map from USD path to Hydra path, for tracking USD->hydra dependencies.
678  _DependencyMap _dependencyInfo;
679 
680  // Appends hydra prim cache paths corresponding to the USD subtree
681  // provided by looking up the dependency map (above).
682  void _GatherDependencies(SdfPath const& subtree,
683  SdfPathVector *affectedCachePaths);
684 
685  // Overload that takes an additional cache argument to help speed up the
686  // dependency gathering operation. The onus is on the client to prepopulate
687  // the cache.
688  void
689  _GatherDependencies(SdfPath const &subtree,
690  _FlattenedDependenciesCacheMap const &cache,
691  SdfPathVector *affectedCachePaths);
692 
693  // SdfPath::ReplacePrefix() is used frequently to convert between
694  // cache path and Hydra render index path and is a performance bottleneck.
695  // These maps pre-computes these conversion.
696  typedef TfHashMap<SdfPath, SdfPath, SdfPath::Hash> SdfPathMap;
697  SdfPathMap _cache2indexPath;
698  SdfPathMap _index2cachePath;
699 
700  // Only use this method when we think no existing adapter has been
701  // established. For example, during initial Population.
702  UsdImagingPrimAdapterSharedPtr const& _AdapterLookup(
703  UsdPrim const& prim,
704  bool ignoreInstancing = false);
705  UsdImagingPrimAdapterSharedPtr const& _AdapterLookup(
706  TfToken const& adapterKey);
707 
708  // Obtain the prim tracking data for the given cache path.
709  _HdPrimInfo *_GetHdPrimInfo(const SdfPath &cachePath);
710 
711  Usd_PrimFlagsConjunction _GetDisplayPredicate() const;
712  Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes() const;
713 
714  // Mark render tags dirty for all prims.
715  // This is done in response to toggling the purpose-based display settings.
716  void _MarkRenderTagsDirty();
717 
718  typedef TfHashSet<SdfPath, SdfPath::Hash> _DirtySet;
719 
720  // Set of cache paths that are due a Sync()
721  _DirtySet _dirtyCachePaths;
722 
724  typedef TfHashMap<SdfPath, int, SdfPath::Hash> _RefineLevelMap;
726  _RefineLevelMap _refineLevelMap;
727 
729  UsdImagingPrimvarDescCache _primvarDescCache;
730 
732  UsdStageRefPtr _stage;
733  SdfPath _rootPrimPath;
734  SdfPathVector _excludedPrimPaths;
735  SdfPathVector _invisedPrimPaths;
736 
737  RigidXformOverridesMap _rigidXformOverrides;
738 
739  // Aspects of the delegate root that apply to all items in the index.
740  SdfPath _compensationPath;
741 
742  GfMatrix4d _rootXf;
743  bool _rootIsVisible;
744 
746  UsdTimeCode _time;
747 
749  SdfPath _cameraPathForSampling;
750 
751  int _refineLevelFallback;
752  HdReprSelector _reprFallback;
753  HdCullStyle _cullStyleFallback;
754 
755  // Cache of which prims are time-varying.
756  SdfPathVector _timeVaryingPrimCache;
757  bool _timeVaryingPrimCacheValid;
758 
759  // Change processing
760  TfNotice::Key _objectsChangedNoticeKey;
761  SdfPathVector _usdPathsToResync;
762 
763  // Map from path of Usd object to update to list of changed scene
764  // description fields for that object. This list of fields is only
765  // populated for prim paths.
766  typedef std::unordered_map<SdfPath, TfTokenVector, SdfPath::Hash>
767  _PathsToUpdateMap;
768  _PathsToUpdateMap _usdPathsToUpdate;
769 
770  UsdImaging_XformCache _xformCache;
771  UsdImaging_MaterialBindingImplData _materialBindingImplData;
772  UsdImaging_MaterialBindingCache _materialBindingCache;
773  UsdImaging_CoordSysBindingCache _coordSysBindingCache;
774  UsdImaging_VisCache _visCache;
775  UsdImaging_PurposeCache _purposeCache;
776  UsdImaging_DrawModeCache _drawModeCache;
777  UsdImaging_CollectionCache _collectionCache;
778  UsdImaging_InheritedPrimvarCache _inheritedPrimvarCache;
779  UsdImaging_PointInstancerIndicesCache _pointInstancerIndicesCache;
780  UsdImaging_NonlinearSampleCountCache _nonlinearSampleCountCache;
781  UsdImaging_BlurScaleCache _blurScaleCache;
782 
783  // Pickability
784  PickabilityMap _pickablesMap;
785 
786  // Purpose-based rendering toggles
787  bool _displayRender;
788  bool _displayProxy;
789  bool _displayGuides;
790  bool _enableUsdDrawModes;
791 
792  const bool _hasDrawModeAdapter;
793 
795  bool _sceneMaterialsEnabled;
796 
798  bool _sceneLightsEnabled;
799 
800  CameraUtilConformWindowPolicy _appWindowPolicy;
801 
802  // Enable HdCoordSys tracking
803  const bool _coordSysEnabled;
804 
805  // Display unloaded prims with Bounds adapter
806  bool _displayUnloadedPrimsWithBounds;
807 
808  UsdImagingDelegate() = delete;
809  UsdImagingDelegate(UsdImagingDelegate const &) = delete;
810  UsdImagingDelegate &operator =(UsdImagingDelegate const &) = delete;
811 };
812 
813 PXR_NAMESPACE_CLOSE_SCOPE
814 
815 #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:64
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:483
static constexpr int ALL_INSTANCES
Populate HdxSelection for given path (root) and instanceIndex.
Definition: delegate.h:512
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:88
#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:134
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:50
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
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.
USDIMAGING_API void SetRefineLevel(SdfPath const &usdPath, int level)
Sets an explicit refinement level for the given USD prim.