24#ifndef PXR_USD_IMAGING_USD_IMAGING_DELEGATE_H
25#define PXR_USD_IMAGING_USD_IMAGING_DELEGATE_H
30#include "pxr/usdImaging/usdImaging/api.h"
31#include "pxr/usdImaging/usdImaging/version.h"
37#include "pxr/imaging/cameraUtil/conformWindow.h"
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"
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"
53#include "pxr/usd/usdGeom/xformCache.h"
54#include "pxr/base/vt/value.h"
59#include "pxr/base/tf/hashmap.h"
60#include "pxr/base/tf/hashset.h"
63#include <tbb/spin_rw_mutex.h>
67PXR_NAMESPACE_OPEN_SCOPE
71typedef std::vector<UsdPrim> UsdPrimVector;
77using UsdImagingPrimAdapterSharedPtr = std::shared_ptr<UsdImagingPrimAdapter>;
88 typedef TfHashMap<SdfPath, GfMatrix4d, SdfPath::Hash> RigidXformOverridesMap;
103 void SyncAll(
bool includeUnvarying);
113 SdfPathVector
const& excludedPrimPaths,
114 SdfPathVector
const &invisedPrimPaths=SdfPathVector());
123 static void SetTimes(
const std::vector<UsdImagingDelegate*>& delegates,
124 const std::vector<UsdTimeCode>& times);
228 bool GetDisplayRender()
const {
return _displayRender; }
233 bool GetDisplayProxy()
const {
return _displayProxy; }
238 bool GetDisplayGuides()
const {
return _displayGuides; }
243 bool GetUsdDrawModesEnabled()
const {
return _enableUsdDrawModes; }
268 bool GetDisplayUnloadedPrimsWithBounds()
const {
269 return _displayUnloadedPrimsWithBounds;
323 VtIntArray *outIndices)
override;
332 virtual std::vector<VtArray<TfToken>>
335 virtual HdPrimvarDescriptorVector
337 HdInterpolation interpolation)
override;
340 SdfPath const &prototypeId)
override;
359 size_t maxSampleCount,
float *times,
364 size_t maxNumSamples,
float *times,
370 size_t maxNumSamples,
float *times,
371 VtValue *samples, VtIntArray *indices)
override;
378 virtual VtValue GetMaterialResource(
SdfPath const &materialId)
override;
383 TfToken const ¶mName)
override;
387 TfToken const ¶mName)
override;
391 virtual HdVolumeFieldDescriptorVector
392 GetVolumeFieldDescriptors(
SdfPath const &volumeId)
override;
408 HdInstancerContext *instancerContext =
nullptr)
override;
411 virtual SdfPathVector
413 std::vector<int> instanceIndices,
414 std::vector<HdInstancerContext> *instancerContexts =
nullptr)
override;
422 HdExtComputationInputDescriptorVector
426 HdExtComputationOutputDescriptorVector
430 HdExtComputationPrimvarDescriptorVector
432 HdInterpolation interpolation)
override;
436 TfToken const& input)
override;
441 size_t maxSampleCount,
443 VtValue *sampleValues)
override;
456 SdfPathMap::const_iterator it = _cache2indexPath.find(cachePath);
457 if (it != _cache2indexPath.end()) {
480 SdfPathMap::const_iterator it = _index2cachePath.find(indexPath);
481 if (it != _index2cachePath.end()) {
513 HdSelectionSharedPtr
const &result);
524 size_t maxNumSamples,
float *times,
VtValue *samples,
525 VtIntArray *indices);
532 bool _ValidateRefineLevel(
int level) {
533 if (!(0 <= level && level <= 8)) {
535 "expected range is [0,8]",
542 void _AddTask(UsdImagingDelegate::_Worker *worker,
SdfPath const& usdPath);
548 bool _IsDrawModeApplied(
UsdPrim const& prim);
556 UsdStageWeakPtr
const& sender);
561 typedef TfHashMap<SdfPath, SdfPathVector, SdfPath::Hash>
562 _FlattenedDependenciesCacheMap;
574 bool _RefreshUsdObject(
SdfPath const& usdPath,
576 _FlattenedDependenciesCacheMap
const &cache,
578 SdfPathSet* allTrackedVariabilityPaths);
587 void _ResyncUsdPrim(
SdfPath const& usdRootPath,
588 _FlattenedDependenciesCacheMap
const &cache,
590 bool repopulateFromRoot =
false);
603 void _UpdateSingleValue(
SdfPath const& cachePath,
int dirtyFlags);
610 bool _CanPopulate(
UsdPrim const& rootPrim)
const;
614 void _SetStateForPopulation(
UsdPrim const& rootPrim,
615 SdfPathVector
const& excludedPaths,
616 SdfPathVector
const& invisedPaths);
624 static void _ExecuteWorkForVariabilityUpdate(_Worker* worker);
629 bool _GetVisible(
UsdPrim const& prim);
640 static void _ExecuteWorkForTimeUpdate(_Worker* worker);
647 typedef TfHashMap<
TfToken, UsdImagingPrimAdapterSharedPtr,
649 _AdapterMap _adapterMap;
653 UsdImagingPrimAdapterSharedPtr adapter;
656 HdDirtyBits timeVaryingBits;
658 HdDirtyBits dirtyBits;
663 typedef TfHashMap<SdfPath, _HdPrimInfo, SdfPath::Hash> _HdPrimInfoMap;
666 _HdPrimInfoMap _hdPrimInfoMap;
668 typedef std::multimap<SdfPath, SdfPath> _DependencyMap;
671 _DependencyMap _dependencyInfo;
675 void _GatherDependencies(
SdfPath const& subtree,
676 SdfPathVector *affectedCachePaths);
682 _GatherDependencies(
SdfPath const &subtree,
683 _FlattenedDependenciesCacheMap
const &cache,
684 SdfPathVector *affectedCachePaths);
689 typedef TfHashMap<SdfPath, SdfPath, SdfPath::Hash> SdfPathMap;
690 SdfPathMap _cache2indexPath;
691 SdfPathMap _index2cachePath;
695 UsdImagingPrimAdapterSharedPtr
const& _AdapterLookup(
697 bool ignoreInstancing =
false);
698 UsdImagingPrimAdapterSharedPtr
const& _AdapterLookup(
702 _HdPrimInfo *_GetHdPrimInfo(
const SdfPath &cachePath);
704 Usd_PrimFlagsConjunction _GetDisplayPredicate()
const;
705 Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes()
const;
709 void _MarkRenderTagsDirty();
711 typedef TfHashSet<SdfPath, SdfPath::Hash> _DirtySet;
714 _DirtySet _dirtyCachePaths;
717 typedef TfHashMap<SdfPath, int, SdfPath::Hash> _RefineLevelMap;
719 _RefineLevelMap _refineLevelMap;
725 UsdStageRefPtr _stage;
727 SdfPathVector _excludedPrimPaths;
728 SdfPathVector _invisedPrimPaths;
730 RigidXformOverridesMap _rigidXformOverrides;
743 SdfPath _cameraPathForSampling;
745 int _refineLevelFallback;
747 HdCullStyle _cullStyleFallback;
750 SdfPathVector _timeVaryingPrimCache;
751 bool _timeVaryingPrimCacheValid;
755 SdfPathVector _usdPathsToResync;
760 typedef std::unordered_map<SdfPath, TfTokenVector, SdfPath::Hash>
762 _PathsToUpdateMap _usdPathsToUpdate;
764 UsdImaging_XformCache _xformCache;
765 UsdImaging_MaterialBindingImplData _materialBindingImplData;
766 UsdImaging_MaterialBindingCache _materialBindingCache;
767 UsdImaging_CoordSysBindingCache _coordSysBindingCache;
768 UsdImaging_VisCache _visCache;
769 UsdImaging_PurposeCache _purposeCache;
770 UsdImaging_DrawModeCache _drawModeCache;
771 UsdImaging_CollectionCache _collectionCache;
772 UsdImaging_InheritedPrimvarCache _inheritedPrimvarCache;
773 UsdImaging_PointInstancerIndicesCache _pointInstancerIndicesCache;
774 UsdImaging_NonlinearSampleCountCache _nonlinearSampleCountCache;
775 UsdImaging_BlurScaleCache _blurScaleCache;
781 bool _enableUsdDrawModes;
783 const bool _hasDrawModeAdapter;
786 bool _sceneMaterialsEnabled;
789 bool _sceneLightsEnabled;
791 CameraUtilConformWindowPolicy _appWindowPolicy;
794 const bool _coordSysEnabled;
797 bool _displayUnloadedPrimsWithBounds;
804PXR_NAMESPACE_CLOSE_SCOPE
A basic mathematical interval class.
Stores a 4x4 matrix of double elements.
Basic type: 3-dimensional floating point range.
Topology data for basisCurves.
Interface class that defines the execution environment for the client to run a computation.
Topology data for meshes.
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Describes one or more authored display representations for an rprim.
Adapter class providing data exchange with the client scene graph.
SdfPath const & GetDelegateID() const
Returns the ID of this delegate, which is used as a prefix for all objects it creates in the RenderIn...
HighlightMode
Selection modes allow differentiation in selection highlight behavior.
A path value used to locate objects in layers or scenegraphs.
static SDF_API const SdfPath & AbsoluteRootPath()
The absolute path representing the top of the namespace hierarchy.
SDF_API const char * GetText() const
Returns the string representation of this path as a c string.
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
SDF_API SdfPath GetAbsoluteRootOrPrimPath() const
Creates a path by stripping all properties and relational attributes from this path,...
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...
This is a space efficient container that mimics the TfHashSet API that uses a vector for storage when...
Handle-object returned by TfNotice::Register().
Token for efficient comparison, assignment, and hashing of known strings.
Enable a concrete base class for use with TfWeakPtr.
The primary translation layer between the Hydra (Hd) core and the Usd scene graph.
USDIMAGING_API void ClearRefineLevel(SdfPath const &usdPath)
Removes any explicit refine level set for the given USD prim.
USDIMAGING_API void Populate(UsdPrim const &rootPrim, SdfPathVector const &excludedPrimPaths, SdfPathVector const &invisedPrimPaths=SdfPathVector())
Populates the rootPrim in the HdRenderIndex, excluding all paths in the excludedPrimPaths,...
USDIMAGING_API void SetRootVisibility(bool isVisible)
Sets the root visibility for the entire delegate, which is applied to all render prims generated.
HdReprSelector GetReprFallback() const
Returns the fallback repr name.
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...
static constexpr int ALL_INSTANCES
Populate HdxSelection for given path (root) and instanceIndex.
UsdTimeCode GetTimeWithOffset(float offset) const
Apply a relative offset to the current time.
USDIMAGING_API void SetRefineLevelFallback(int level)
Sets the fallback refinement level to level, triggers dirty refine level bit to be set on all Rprims ...
virtual USDIMAGING_API bool GetDoubleSided(SdfPath const &id) override
Returns the doubleSided state for the given prim.
USDIMAGING_API void SetSceneMaterialsEnabled(bool enable)
Enables custom shading on prims.
USDIMAGING_API void SetSceneLightsEnabled(bool enable)
Enables lights found in the usdscene.
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 SetUsdDrawModesEnabled(bool enableUsdDrawModes)
Returns whether draw modes are enabled.
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 SetWindowPolicy(CameraUtilConformWindowPolicy policy)
Set the window policy on all scene cameras.
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.
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.
static USDIMAGING_API void SetTimes(const std::vector< UsdImagingDelegate * > &delegates, const std::vector< UsdTimeCode > ×)
For each delegate in delegates, sets the current time from which data wil be read to the correspondin...
bool GetRootVisibility() const
Returns the root visibility for the entire delegate.
USDIMAGING_API GfInterval GetCurrentTimeSamplingInterval()
Returns the current interval that will be used when using the sample* API in the scene delegate.
USDIMAGING_API HdModelDrawMode GetModelDrawMode(SdfPath const &id) override
Returns the model draw mode object for the given prim.
SdfPath GetRootInstancerId() const
Returns the root instancer id for the entire delegate.
virtual USDIMAGING_API std::vector< VtArray< TfToken > > GetInstanceCategories(SdfPath const &instancerId) override
Returns the categories for all instances in the instancer.
virtual USDIMAGING_API HdReprSelector GetReprSelector(SdfPath const &id) override
Returns the authored repr (if any) for the given prim.
virtual USDIMAGING_API SdfPath GetMaterialId(SdfPath const &rprimId) override
Returns the material ID bound to the rprim rprimId.
USDIMAGING_API HdExtComputationInputDescriptorVector GetExtComputationInputDescriptors(SdfPath const &computationId) override
For the given computation id, returns a list of computation input descriptors.
virtual USDIMAGING_API SubdivTags GetSubdivTags(SdfPath const &id) override
Gets the subdivision surface tags (sharpness, holes, etc).
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 SetDisplayGuides(const bool displayGuides)
Sets display of prims with purpose "guide".
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.
USDIMAGING_API void SetTime(UsdTimeCode time)
Sets the current time from which data will be read by the delegate.
const GfMatrix4d & GetRootTransform() const
Returns the root transform for the entire delegate.
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 SdfPath ConvertIndexPathToCachePath(SdfPath const &indexPath)
Convert the given Hydra ID to a UsdImaging cache path, by stripping the scene delegate prefix.
UsdTimeCode GetTime() const
Returns the current time.
virtual USDIMAGING_API TfToken GetRenderTag(SdfPath const &id) override
Returns the render tag that will be used to bucket prims during render pass bucketing.
USDIMAGING_API HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(SdfPath const &computationId) override
For the given computation id, returns a list of computation output descriptors.
virtual USDIMAGING_API HdCullStyle GetCullStyle(SdfPath const &id) override
Returns the cullstyle for the given prim.
USDIMAGING_API void SetRootTransform(GfMatrix4d const &xf)
Sets the root transform for the entire delegate, which is applied to all render prims generated.
virtual USDIMAGING_API HdBasisCurvesTopology GetBasisCurvesTopology(SdfPath const &id) override
Gets the topological curve data for a given prim.
USDIMAGING_API void SetReprFallback(HdReprSelector const &repr)
Sets the fallback repr name.
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.
USDIMAGING_API void SetRigidXformOverrides(RigidXformOverridesMap const &overrides)
Set transform value overrides on a set of paths.
virtual USDIMAGING_API void Sync(HdSyncRequestVector *request) override
Synchronizes the delegate state for the given request vector.
USDIMAGING_API std::string GetExtComputationKernel(SdfPath const &computationId) override
Returns the kernel source assigned to the computation at the path id.
USDIMAGING_API bool IsInInvisedPaths(const SdfPath &usdPath) const
Returns true if usdPath is included in invised path list.
virtual USDIMAGING_API SdfPath GetInstancerId(SdfPath const &primId) override
Returns the parent instancer of the given rprim or instancer.
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...
USDIMAGING_API void InvokeExtComputation(SdfPath const &computationId, HdExtComputationContext *context) override
Requests the scene delegate run the ExtComputation with the given id.
virtual USDIMAGING_API VtArray< TfToken > GetCategories(SdfPath const &id) override
Returns the prim categories.
USDIMAGING_API void SetInvisedPrimPaths(SdfPathVector const &invisedPaths)
Set the list of paths that must be invised.
virtual USDIMAGING_API bool GetVisible(SdfPath const &id) override
Returns the authored visible state of the prim.
virtual USDIMAGING_API GfMatrix4d GetInstancerTransform(SdfPath const &instancerId) override
Returns the instancer transform.
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.
HdCullStyle GetCullStyleFallback() const
Returns the fallback cull style.
USDIMAGING_API void SetCullStyleFallback(HdCullStyle cullStyle)
Sets the fallback cull style.
USDIMAGING_API void SetCameraForSampling(SdfPath const &id)
Setup for the shutter open and close to be used for motion sampling.
USDIMAGING_API void SetRefineLevel(SdfPath const &usdPath, int level)
Sets an explicit refinement level for the given USD prim.
virtual USDIMAGING_API VtValue Get(SdfPath const &id, TfToken const &key) override
Returns a named value.
USDIMAGING_API virtual HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id) override
Returns the coordinate system bindings, or a nullptr if none are bound.
int GetRefineLevelFallback() const
Returns the refinement level that is used when prims have no explicit level set.
virtual USDIMAGING_API GfRange3d GetExtent(SdfPath const &id) override
Gets the axis aligned bounds of a prim.
virtual USDIMAGING_API VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key, VtIntArray *outIndices) override
Returns a named primvar value.
virtual USDIMAGING_API SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override
Returns a list of prototypes of this instancer.
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...
USDIMAGING_API void ApplyPendingUpdates()
Applies any scene edits which have been queued up by notices from USD.
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.
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 HdMeshTopology GetMeshTopology(SdfPath const &id) override
Gets the topological mesh data for a given prim.
USDIMAGING_API void SetDisplayProxy(const bool displayProxy)
Sets display of prims with purpose "proxy".
USDIMAGING_API void SetDisplayRender(const bool displayRender)
Sets display of prims with purpose "render".
virtual USDIMAGING_API GfMatrix4d GetTransform(SdfPath const &id) override
Returns the object space transform, including all parent transforms.
USDIMAGING_API void SetDisplayUnloadedPrimsWithBounds(bool displayUnloaded)
Sets display of unloaded prims as bounding boxes.
virtual USDIMAGING_API VtValue GetCameraParamValue(SdfPath const &id, TfToken const ¶mName) override
Returns a single value for a given camera and parameter.
This proxy class exposes a subset of the private Delegate API to PrimAdapters.
Base class for all PrimAdapters.
A cache for primvar descriptors.
Notice sent in response to authored changes that affect UsdObjects.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Represents an arbitrary dimensional rectangular container class.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Standard pointer typedefs.
#define TF_DECLARE_WEAK_PTRS(type)
Define standard weak pointer types.
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
Object used by instancer prim adapters to pass along context about the instancer and instance prim to...
Describes how the geometry of a prim should be displayed.
Describes optional alternative imaging behavior for prims.
The SceneDelegate is requested to synchronize prims as the result of executing a specific render pass...
Functor to use for hash maps from tokens to other things.
std::vector< TfToken > TfTokenVector
Convenience types.