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 <boost/container/flat_map.hpp>
64 #include <tbb/spin_rw_mutex.h>
68 PXR_NAMESPACE_OPEN_SCOPE
72 typedef std::vector<UsdPrim> UsdPrimVector;
78 typedef boost::container::flat_map<SdfPath, bool> PickabilityMap;
80 using UsdImagingPrimAdapterSharedPtr = std::shared_ptr<UsdImagingPrimAdapter>;
91 typedef TfHashMap<SdfPath, GfMatrix4d, SdfPath::Hash> RigidXformOverridesMap;
98 virtual ~UsdImagingDelegate();
106 void SyncAll(
bool includeUnvarying);
121 SdfPathVector
const& excludedPrimPaths,
122 SdfPathVector
const &invisedPrimPaths=SdfPathVector());
131 static void SetTimes(
const std::vector<UsdImagingDelegate*>& delegates,
132 const std::vector<UsdTimeCode>& times);
240 bool GetDisplayRender()
const {
return _displayRender; }
245 bool GetDisplayProxy()
const {
return _displayProxy; }
250 bool GetDisplayGuides()
const {
return _displayGuides; }
255 bool GetUsdDrawModesEnabled()
const {
return _enableUsdDrawModes; }
280 bool GetDisplayUnloadedPrimsWithBounds()
const {
281 return _displayUnloadedPrimsWithBounds;
332 VtIntArray *outIndices)
override;
341 virtual std::vector<VtArray<TfToken>>
344 virtual HdPrimvarDescriptorVector
346 HdInterpolation interpolation)
override;
349 SdfPath const &prototypeId)
override;
368 size_t maxSampleCount,
float *times,
373 size_t maxNumSamples,
float *times,
379 size_t maxNumSamples,
float *times,
380 VtValue *samples, VtIntArray *indices)
override;
387 virtual VtValue GetMaterialResource(
SdfPath const &materialId)
override;
392 TfToken const ¶mName)
override;
396 TfToken const ¶mName)
override;
400 virtual HdVolumeFieldDescriptorVector
401 GetVolumeFieldDescriptors(
SdfPath const &volumeId)
override;
417 HdInstancerContext *instancerContext =
nullptr)
override;
425 HdExtComputationInputDescriptorVector
429 HdExtComputationOutputDescriptorVector
433 HdExtComputationPrimvarDescriptorVector
435 HdInterpolation interpolation)
override;
439 TfToken const& input)
override;
444 size_t maxSampleCount,
446 VtValue *sampleValues)
override;
459 SdfPathMap::const_iterator it = _cache2indexPath.find(cachePath);
460 if (it != _cache2indexPath.end()) {
483 SdfPathMap::const_iterator it = _index2cachePath.find(indexPath);
484 if (it != _index2cachePath.end()) {
516 HdSelectionSharedPtr
const &result);
527 size_t maxNumSamples,
float *times,
VtValue *samples,
528 VtIntArray *indices);
535 bool _ValidateRefineLevel(
int level) {
536 if (!(0 <= level && level <= 8)) {
538 "expected range is [0,8]",
545 void _AddTask(UsdImagingDelegate::_Worker *worker,
SdfPath const& usdPath);
551 bool _IsDrawModeApplied(
UsdPrim const& prim);
559 UsdStageWeakPtr
const& sender);
567 void _RefreshUsdObject(
SdfPath const& usdPath,
579 bool repopulateFromRoot =
false);
595 void _UpdateSingleValue(
SdfPath const& cachePath,
int dirtyFlags);
602 bool _CanPopulate(
UsdPrim const& rootPrim)
const;
606 void _SetStateForPopulation(
UsdPrim const& rootPrim,
607 SdfPathVector
const& excludedPaths,
608 SdfPathVector
const& invisedPaths);
616 static void _ExecuteWorkForVariabilityUpdate(_Worker* worker);
621 bool _GetVisible(
UsdPrim const& prim);
632 static void _ExecuteWorkForTimeUpdate(_Worker* worker);
639 typedef TfHashMap<
TfToken, UsdImagingPrimAdapterSharedPtr,
641 _AdapterMap _adapterMap;
645 UsdImagingPrimAdapterSharedPtr adapter;
648 HdDirtyBits timeVaryingBits;
650 HdDirtyBits dirtyBits;
655 typedef TfHashMap<SdfPath, _HdPrimInfo, SdfPath::Hash> _HdPrimInfoMap;
658 _HdPrimInfoMap _hdPrimInfoMap;
660 typedef std::multimap<SdfPath, SdfPath> _DependencyMap;
663 _DependencyMap _dependencyInfo;
665 void _GatherDependencies(
SdfPath const& subtree,
666 SdfPathVector *affectedCachePaths);
671 typedef TfHashMap<SdfPath, SdfPath, SdfPath::Hash> SdfPathMap;
672 SdfPathMap _cache2indexPath;
673 SdfPathMap _index2cachePath;
677 UsdImagingPrimAdapterSharedPtr
const& _AdapterLookup(
679 bool ignoreInstancing =
false);
680 UsdImagingPrimAdapterSharedPtr
const& _AdapterLookup(
684 _HdPrimInfo *_GetHdPrimInfo(
const SdfPath &cachePath);
686 Usd_PrimFlagsConjunction _GetDisplayPredicate()
const;
687 Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes()
const;
691 void _MarkRenderTagsDirty();
694 typedef TfHashSet<SdfPath, SdfPath::Hash> _InstancerSet;
697 _InstancerSet _instancerPrimCachePaths;
700 typedef TfHashMap<SdfPath, int, SdfPath::Hash> _RefineLevelMap;
702 _RefineLevelMap _refineLevelMap;
708 UsdStageRefPtr _stage;
710 SdfPathVector _excludedPrimPaths;
711 SdfPathVector _invisedPrimPaths;
713 RigidXformOverridesMap _rigidXformOverrides;
725 SdfPath _cameraPathForSampling;
727 int _refineLevelFallback;
729 HdCullStyle _cullStyleFallback;
732 SdfPathVector _timeVaryingPrimCache;
733 bool _timeVaryingPrimCacheValid;
737 SdfPathVector _usdPathsToResync;
742 typedef std::unordered_map<SdfPath, TfTokenVector, SdfPath::Hash>
744 _PathsToUpdateMap _usdPathsToUpdate;
746 UsdImaging_XformCache _xformCache;
747 UsdImaging_MaterialBindingImplData _materialBindingImplData;
748 UsdImaging_MaterialBindingCache _materialBindingCache;
749 UsdImaging_CoordSysBindingImplData _coordSysBindingImplData;
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;
759 PickabilityMap _pickablesMap;
765 bool _enableUsdDrawModes;
767 const bool _hasDrawModeAdapter;
770 bool _sceneMaterialsEnabled;
773 bool _sceneLightsEnabled;
775 CameraUtilConformWindowPolicy _appWindowPolicy;
778 const bool _coordSysEnabled;
781 bool _displayUnloadedPrimsWithBounds;
783 UsdImagingDelegate() =
delete;
784 UsdImagingDelegate(UsdImagingDelegate
const &) =
delete;
785 UsdImagingDelegate &operator =(UsdImagingDelegate
const &) =
delete;
788 PXR_NAMESPACE_CLOSE_SCOPE
790 #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().
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...
Basic type: 3-dimensional floating point range.
USDIMAGING_API SdfPath ConvertIndexPathToCachePath(SdfPath const &indexPath)
Convert the given Hydra ID to a UsdImaging cache path, by stripping the scene delegate prefix...
static constexpr int ALL_INSTANCES
Populate HdxSelection for given path (root) and instanceIndex.
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.
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.
virtual USDIMAGING_API void PostSyncCleanup() override
Opportunity for the delegate to clean itself up after performing parallel work during sync phase...
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.
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.
const GfMatrix4d & GetRootTransform() const
Returns the root transform 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.
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
virtual USDIMAGING_API SubdivTags GetSubdivTags(SdfPath const &id) override
Gets the subdivision surface tags (sharpness, holes, etc).
HdCullStyle GetCullStyleFallback() const
Returns the fallback cull style.
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.
Functor to use for hash maps from tokens to other things.
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.
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".
USDIMAGING_API PickabilityMap GetPickabilityMap() const
Returns the root paths of pickable objects.
SDF_API SdfPath GetAbsoluteRootOrPrimPath() const
Creates a path by stripping all properties and relational attributes from this path, leaving the path to the containing prim.
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.
UsdTimeCode GetTimeWithOffset(float offset) const
Apply a relative offset to the current time.
virtual USDIMAGING_API GfMatrix4d GetInstancerTransform(SdfPath const &instancerId) override
Returns the instancer transform.
USDIMAGING_API void SetInvisedPrimPaths(SdfPathVector const &invisedPaths)
Set the list of paths that must be invised.
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 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.
USDIMAGING_API GfInterval GetCurrentTimeSamplingInterval()
Returns the current interval that will be used when using the sample* API in the scene delegate...
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 void SetRootVisibility(bool isVisible)
Sets the root visibility for the entire delegate, which is applied to all render prims generated...
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.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
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...
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...
Adapter class providing data exchange with the client scene graph.
Base class for all PrimAdapters.
HdReprSelector GetReprFallback() const
Returns the fallback repr name.
Notice sent in response to authored changes that affect UsdObjects.
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 ...
virtual USDIMAGING_API VtValue GetCameraParamValue(SdfPath const &id, TfToken const ¶mName) 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.
A basic mathematical interval class.
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.
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.
bool GetRootVisibility() const
Returns the root visibility for the entire delegate.
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 > ×)
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.
UsdTimeCode GetTime() const
Returns the current time.
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...
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.
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.
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.
USDIMAGING_API void SetDisplayProxy(const bool displayProxy)
Sets display of prims with purpose "proxy".
SdfPath const & GetDelegateID() const
Returns the ID of this delegate, which is used as a prefix for all objects it creates in the RenderIn...
The primary translation layer between the Hydra (Hd) core and the Usd scene graph.
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
Enable a concrete base class for use with TfWeakPtr.
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...
virtual USDIMAGING_API SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId) override
Returns a list of prototypes of this instancer.
SDF_API const char * GetText() const
Returns the string representation of this path as a c string.
USDIMAGING_API bool IsInInvisedPaths(const SdfPath &usdPath) const
Returns true if usdPath is included in invised path list.
int GetRefineLevelFallback() const
Returns the refinement level that is used when prims have no explicit level set.
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.