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;
106 void SyncAll(
bool includeUnvarying);
116 SdfPathVector
const& excludedPrimPaths,
117 SdfPathVector
const &invisedPrimPaths=SdfPathVector());
126 static void SetTimes(
const std::vector<UsdImagingDelegate*>& delegates,
127 const std::vector<UsdTimeCode>& times);
243 bool GetDisplayRender()
const {
return _displayRender; }
248 bool GetDisplayProxy()
const {
return _displayProxy; }
253 bool GetDisplayGuides()
const {
return _displayGuides; }
258 bool GetUsdDrawModesEnabled()
const {
return _enableUsdDrawModes; }
283 bool GetDisplayUnloadedPrimsWithBounds()
const {
284 return _displayUnloadedPrimsWithBounds;
335 VtIntArray *outIndices)
override;
344 virtual std::vector<VtArray<TfToken>>
347 virtual HdPrimvarDescriptorVector
349 HdInterpolation interpolation)
override;
352 SdfPath const &prototypeId)
override;
371 size_t maxSampleCount,
float *times,
376 size_t maxNumSamples,
float *times,
382 size_t maxNumSamples,
float *times,
383 VtValue *samples, VtIntArray *indices)
override;
390 virtual VtValue GetMaterialResource(
SdfPath const &materialId)
override;
395 TfToken const ¶mName)
override;
399 TfToken const ¶mName)
override;
403 virtual HdVolumeFieldDescriptorVector
404 GetVolumeFieldDescriptors(
SdfPath const &volumeId)
override;
420 HdInstancerContext *instancerContext =
nullptr)
override;
423 virtual SdfPathVector
425 std::vector<int> instanceIndices,
426 std::vector<HdInstancerContext> *instancerContexts =
nullptr)
override;
434 HdExtComputationInputDescriptorVector
438 HdExtComputationOutputDescriptorVector
442 HdExtComputationPrimvarDescriptorVector
444 HdInterpolation interpolation)
override;
448 TfToken const& input)
override;
453 size_t maxSampleCount,
455 VtValue *sampleValues)
override;
468 SdfPathMap::const_iterator it = _cache2indexPath.find(cachePath);
469 if (it != _cache2indexPath.end()) {
492 SdfPathMap::const_iterator it = _index2cachePath.find(indexPath);
493 if (it != _index2cachePath.end()) {
525 HdSelectionSharedPtr
const &result);
536 size_t maxNumSamples,
float *times,
VtValue *samples,
537 VtIntArray *indices);
544 bool _ValidateRefineLevel(
int level) {
545 if (!(0 <= level && level <= 8)) {
547 "expected range is [0,8]",
554 void _AddTask(UsdImagingDelegate::_Worker *worker,
SdfPath const& usdPath);
560 bool _IsDrawModeApplied(
UsdPrim const& prim);
568 UsdStageWeakPtr
const& sender);
573 typedef TfHashMap<SdfPath, SdfPathVector, SdfPath::Hash>
574 _FlattenedDependenciesCacheMap;
586 bool _RefreshUsdObject(
SdfPath const& usdPath,
588 _FlattenedDependenciesCacheMap
const &cache,
590 SdfPathSet* allTrackedVariabilityPaths);
599 void _ResyncUsdPrim(
SdfPath const& usdRootPath,
600 _FlattenedDependenciesCacheMap
const &cache,
602 bool repopulateFromRoot =
false);
618 void _UpdateSingleValue(
SdfPath const& cachePath,
int dirtyFlags);
625 bool _CanPopulate(
UsdPrim const& rootPrim)
const;
629 void _SetStateForPopulation(
UsdPrim const& rootPrim,
630 SdfPathVector
const& excludedPaths,
631 SdfPathVector
const& invisedPaths);
639 static void _ExecuteWorkForVariabilityUpdate(_Worker* worker);
644 bool _GetVisible(
UsdPrim const& prim);
655 static void _ExecuteWorkForTimeUpdate(_Worker* worker);
662 typedef TfHashMap<
TfToken, UsdImagingPrimAdapterSharedPtr,
664 _AdapterMap _adapterMap;
668 UsdImagingPrimAdapterSharedPtr adapter;
671 HdDirtyBits timeVaryingBits;
673 HdDirtyBits dirtyBits;
678 typedef TfHashMap<SdfPath, _HdPrimInfo, SdfPath::Hash> _HdPrimInfoMap;
681 _HdPrimInfoMap _hdPrimInfoMap;
683 typedef std::multimap<SdfPath, SdfPath> _DependencyMap;
686 _DependencyMap _dependencyInfo;
690 void _GatherDependencies(
SdfPath const& subtree,
691 SdfPathVector *affectedCachePaths);
697 _GatherDependencies(
SdfPath const &subtree,
698 _FlattenedDependenciesCacheMap
const &cache,
699 SdfPathVector *affectedCachePaths);
704 typedef TfHashMap<SdfPath, SdfPath, SdfPath::Hash> SdfPathMap;
705 SdfPathMap _cache2indexPath;
706 SdfPathMap _index2cachePath;
710 UsdImagingPrimAdapterSharedPtr
const& _AdapterLookup(
712 bool ignoreInstancing =
false);
713 UsdImagingPrimAdapterSharedPtr
const& _AdapterLookup(
717 _HdPrimInfo *_GetHdPrimInfo(
const SdfPath &cachePath);
719 Usd_PrimFlagsConjunction _GetDisplayPredicate()
const;
720 Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes()
const;
724 void _MarkRenderTagsDirty();
726 typedef TfHashSet<SdfPath, SdfPath::Hash> _DirtySet;
729 _DirtySet _dirtyCachePaths;
732 typedef TfHashMap<SdfPath, int, SdfPath::Hash> _RefineLevelMap;
734 _RefineLevelMap _refineLevelMap;
740 UsdStageRefPtr _stage;
742 SdfPathVector _excludedPrimPaths;
743 SdfPathVector _invisedPrimPaths;
745 RigidXformOverridesMap _rigidXformOverrides;
758 SdfPath _cameraPathForSampling;
760 int _refineLevelFallback;
762 HdCullStyle _cullStyleFallback;
765 SdfPathVector _timeVaryingPrimCache;
766 bool _timeVaryingPrimCacheValid;
770 SdfPathVector _usdPathsToResync;
775 typedef std::unordered_map<SdfPath, TfTokenVector, SdfPath::Hash>
777 _PathsToUpdateMap _usdPathsToUpdate;
779 UsdImaging_XformCache _xformCache;
780 UsdImaging_MaterialBindingImplData _materialBindingImplData;
781 UsdImaging_MaterialBindingCache _materialBindingCache;
782 UsdImaging_CoordSysBindingCache _coordSysBindingCache;
783 UsdImaging_VisCache _visCache;
784 UsdImaging_PurposeCache _purposeCache;
785 UsdImaging_DrawModeCache _drawModeCache;
786 UsdImaging_CollectionCache _collectionCache;
787 UsdImaging_InheritedPrimvarCache _inheritedPrimvarCache;
788 UsdImaging_PointInstancerIndicesCache _pointInstancerIndicesCache;
789 UsdImaging_NonlinearSampleCountCache _nonlinearSampleCountCache;
790 UsdImaging_BlurScaleCache _blurScaleCache;
793 PickabilityMap _pickablesMap;
799 bool _enableUsdDrawModes;
801 const bool _hasDrawModeAdapter;
804 bool _sceneMaterialsEnabled;
807 bool _sceneLightsEnabled;
809 CameraUtilConformWindowPolicy _appWindowPolicy;
812 const bool _coordSysEnabled;
815 bool _displayUnloadedPrimsWithBounds;
822 PXR_NAMESPACE_CLOSE_SCOPE
824 #endif //PXR_USD_IMAGING_USD_IMAGING_DELEGATE_H virtual USDIMAGING_API TfToken GetRenderTag(SdfPath const &id) override
Returns the render tag that will be used to bucket prims during render pass bucketing.
Interface class that defines the execution environment for the client to run a computation.
Handle-object returned by TfNotice::Register().
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.
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.
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).
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.
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.
HdCullStyle GetCullStyleFallback() const
Returns the fallback cull style.
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.
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.
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...
HdReprSelector GetReprFallback() const
Returns the fallback repr name.
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.
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.
UsdTimeCode GetTime() const
Returns the current time.
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.
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.
bool GetRootVisibility() const
Returns the root visibility for the entire delegate.
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.
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
USDIMAGING_API void SetRootInstancerId(SdfPath const &instancerId)
Sets the root instancer id for the entire delegate, which is used as a fallback value for GetInstance...
int GetRefineLevelFallback() const
Returns the refinement level that is used when prims have no explicit level set.
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 SdfPath GetAbsoluteRootOrPrimPath() const
Creates a path by stripping all properties and relational attributes from this path,...
virtual USDIMAGING_API HdCullStyle GetCullStyle(SdfPath const &id) override
Returns the cullstyle for the given prim.
virtual USDIMAGING_API size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key, size_t maxNumSamples, float *times, VtValue *samples, VtIntArray *indices) override
SamplePrimvar() for getting an unflattened primvar and its indices.
SdfPath GetRootInstancerId() const
Returns the root instancer id for the entire delegate.
USDIMAGING_API void SetRefineLevel(SdfPath const &usdPath, int level)
Sets an explicit refinement level for the given USD prim.