7#ifndef PXR_USD_IMAGING_USD_IMAGING_DELEGATE_H
8#define PXR_USD_IMAGING_USD_IMAGING_DELEGATE_H
13#include "pxr/usdImaging/usdImaging/api.h"
14#include "pxr/usdImaging/usdImaging/version.h"
20#include "pxr/imaging/cameraUtil/conformWindow.h"
22#include "pxr/imaging/hd/coordSys.h"
23#include "pxr/imaging/hd/sceneDelegate.h"
24#include "pxr/imaging/hd/selection.h"
25#include "pxr/imaging/hd/version.h"
28#include "pxr/usd/sdf/path.h"
29#include "pxr/usd/sdf/pathTable.h"
30#include "pxr/usd/usd/attribute.h"
31#include "pxr/usd/usd/notice.h"
36#include "pxr/usd/usdGeom/xformCache.h"
37#include "pxr/base/vt/value.h"
42#include "pxr/base/tf/hashmap.h"
43#include "pxr/base/tf/hashset.h"
46#include <tbb/spin_rw_mutex.h>
50PXR_NAMESPACE_OPEN_SCOPE
54typedef std::vector<UsdPrim> UsdPrimVector;
60using UsdImagingPrimAdapterSharedPtr = std::shared_ptr<UsdImagingPrimAdapter>;
71 typedef TfHashMap<SdfPath, GfMatrix4d, SdfPath::Hash> RigidXformOverridesMap;
86 void SyncAll(
bool includeUnvarying);
96 SdfPathVector
const& excludedPrimPaths,
97 SdfPathVector
const &invisedPrimPaths=SdfPathVector());
106 static void SetTimes(
const std::vector<UsdImagingDelegate*>& delegates,
107 const std::vector<UsdTimeCode>& times);
211 bool GetDisplayRender()
const {
return _displayRender; }
216 bool GetDisplayProxy()
const {
return _displayProxy; }
221 bool GetDisplayGuides()
const {
return _displayGuides; }
226 bool GetUsdDrawModesEnabled()
const {
return _enableUsdDrawModes; }
251 bool GetDisplayUnloadedPrimsWithBounds()
const {
252 return _displayUnloadedPrimsWithBounds;
306 VtIntArray *outIndices)
override;
315 virtual std::vector<VtArray<TfToken>>
318 virtual HdPrimvarDescriptorVector
320 HdInterpolation interpolation)
override;
323 SdfPath const &prototypeId)
override;
342 size_t maxSampleCount,
float *times,
347 size_t maxNumSamples,
float *times,
353 size_t maxNumSamples,
float *times,
354 VtValue *samples, VtIntArray *indices)
override;
361 virtual VtValue GetMaterialResource(
SdfPath const &materialId)
override;
366 TfToken const ¶mName)
override;
370 TfToken const ¶mName)
override;
374 virtual HdVolumeFieldDescriptorVector
375 GetVolumeFieldDescriptors(
SdfPath const &volumeId)
override;
391 HdInstancerContext *instancerContext =
nullptr)
override;
394 virtual SdfPathVector
396 std::vector<int> instanceIndices,
397 std::vector<HdInstancerContext> *instancerContexts =
nullptr)
override;
405 HdExtComputationInputDescriptorVector
409 HdExtComputationOutputDescriptorVector
413 HdExtComputationPrimvarDescriptorVector
415 HdInterpolation interpolation)
override;
419 TfToken const& input)
override;
424 size_t maxSampleCount,
426 VtValue *sampleValues)
override;
439 SdfPathMap::const_iterator it = _cache2indexPath.find(cachePath);
440 if (it != _cache2indexPath.end()) {
463 SdfPathMap::const_iterator it = _index2cachePath.find(indexPath);
464 if (it != _index2cachePath.end()) {
496 HdSelectionSharedPtr
const &result);
507 size_t maxNumSamples,
float *times,
VtValue *samples,
508 VtIntArray *indices);
515 bool _ValidateRefineLevel(
int level) {
516 if (!(0 <= level && level <= 8)) {
518 "expected range is [0,8]",
525 void _AddTask(UsdImagingDelegate::_Worker *worker,
SdfPath const& usdPath);
531 bool _IsDrawModeApplied(
UsdPrim const& prim);
539 UsdStageWeakPtr
const& sender);
544 typedef TfHashMap<SdfPath, SdfPathVector, SdfPath::Hash>
545 _FlattenedDependenciesCacheMap;
557 bool _RefreshUsdObject(
SdfPath const& usdPath,
559 _FlattenedDependenciesCacheMap
const &cache,
561 SdfPathSet* allTrackedVariabilityPaths);
570 void _ResyncUsdPrim(
SdfPath const& usdRootPath,
571 _FlattenedDependenciesCacheMap
const &cache,
573 bool repopulateFromRoot =
false);
586 void _UpdateSingleValue(
SdfPath const& cachePath,
int dirtyFlags);
593 bool _CanPopulate(
UsdPrim const& rootPrim)
const;
597 void _SetStateForPopulation(
UsdPrim const& rootPrim,
598 SdfPathVector
const& excludedPaths,
599 SdfPathVector
const& invisedPaths);
607 static void _ExecuteWorkForVariabilityUpdate(_Worker* worker);
612 bool _GetVisible(
UsdPrim const& prim);
623 static void _ExecuteWorkForTimeUpdate(_Worker* worker);
630 typedef TfHashMap<
TfToken, UsdImagingPrimAdapterSharedPtr,
632 _AdapterMap _adapterMap;
636 UsdImagingPrimAdapterSharedPtr adapter;
639 HdDirtyBits timeVaryingBits;
641 HdDirtyBits dirtyBits;
646 typedef TfHashMap<SdfPath, _HdPrimInfo, SdfPath::Hash> _HdPrimInfoMap;
649 _HdPrimInfoMap _hdPrimInfoMap;
651 typedef std::multimap<SdfPath, SdfPath> _DependencyMap;
654 _DependencyMap _dependencyInfo;
658 void _GatherDependencies(
SdfPath const& subtree,
659 SdfPathVector *affectedCachePaths);
665 _GatherDependencies(
SdfPath const &subtree,
666 _FlattenedDependenciesCacheMap
const &cache,
667 SdfPathVector *affectedCachePaths);
672 typedef TfHashMap<SdfPath, SdfPath, SdfPath::Hash> SdfPathMap;
673 SdfPathMap _cache2indexPath;
674 SdfPathMap _index2cachePath;
678 UsdImagingPrimAdapterSharedPtr
const& _AdapterLookup(
680 bool ignoreInstancing =
false);
681 UsdImagingPrimAdapterSharedPtr
const& _AdapterLookup(
685 _HdPrimInfo *_GetHdPrimInfo(
const SdfPath &cachePath);
687 Usd_PrimFlagsConjunction _GetDisplayPredicate()
const;
688 Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes()
const;
692 void _MarkRenderTagsDirty();
694 typedef TfHashSet<SdfPath, SdfPath::Hash> _DirtySet;
697 _DirtySet _dirtyCachePaths;
700 typedef TfHashMap<SdfPath, int, SdfPath::Hash> _RefineLevelMap;
702 _RefineLevelMap _refineLevelMap;
708 UsdStageRefPtr _stage;
710 SdfPathVector _excludedPrimPaths;
711 SdfPathVector _invisedPrimPaths;
713 RigidXformOverridesMap _rigidXformOverrides;
726 SdfPath _cameraPathForSampling;
728 int _refineLevelFallback;
730 HdCullStyle _cullStyleFallback;
733 SdfPathVector _timeVaryingPrimCache;
734 bool _timeVaryingPrimCacheValid;
738 SdfPathVector _usdPathsToResync;
743 typedef std::unordered_map<SdfPath, TfTokenVector, SdfPath::Hash>
745 _PathsToUpdateMap _usdPathsToUpdate;
747 UsdImaging_XformCache _xformCache;
748 UsdImaging_MaterialBindingImplData _materialBindingImplData;
749 UsdImaging_MaterialBindingCache _materialBindingCache;
750 UsdImaging_CoordSysBindingCache _coordSysBindingCache;
751 UsdImaging_VisCache _visCache;
752 UsdImaging_PurposeCache _purposeCache;
753 UsdImaging_DrawModeCache _drawModeCache;
754 UsdImaging_CollectionCache _collectionCache;
755 UsdImaging_InheritedPrimvarCache _inheritedPrimvarCache;
756 UsdImaging_PointInstancerIndicesCache _pointInstancerIndicesCache;
757 UsdImaging_NonlinearSampleCountCache _nonlinearSampleCountCache;
758 UsdImaging_BlurScaleCache _blurScaleCache;
764 bool _enableUsdDrawModes;
766 const bool _hasDrawModeAdapter;
769 bool _sceneMaterialsEnabled;
772 bool _sceneLightsEnabled;
774 CameraUtilConformWindowPolicy _appWindowPolicy;
777 const bool _coordSysEnabled;
780 bool _displayUnloadedPrimsWithBounds;
787PXR_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 each of the 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.