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);
235 bool GetDisplayRender()
const {
return _displayRender; }
240 bool GetDisplayProxy()
const {
return _displayProxy; }
245 bool GetDisplayGuides()
const {
return _displayGuides; }
250 bool GetUsdDrawModesEnabled()
const {
return _enableUsdDrawModes; }
275 bool GetDisplayUnloadedPrimsWithBounds()
const {
276 return _displayUnloadedPrimsWithBounds;
327 VtIntArray *outIndices)
override;
336 virtual std::vector<VtArray<TfToken>>
339 virtual HdPrimvarDescriptorVector
341 HdInterpolation interpolation)
override;
344 SdfPath const &prototypeId)
override;
363 size_t maxSampleCount,
float *times,
368 size_t maxNumSamples,
float *times,
374 size_t maxNumSamples,
float *times,
375 VtValue *samples, VtIntArray *indices)
override;
382 virtual VtValue GetMaterialResource(
SdfPath const &materialId)
override;
387 TfToken const ¶mName)
override;
391 TfToken const ¶mName)
override;
395 virtual HdVolumeFieldDescriptorVector
396 GetVolumeFieldDescriptors(
SdfPath const &volumeId)
override;
412 HdInstancerContext *instancerContext =
nullptr)
override;
415 virtual SdfPathVector
417 std::vector<int> instanceIndices,
418 std::vector<HdInstancerContext> *instancerContexts =
nullptr)
override;
426 HdExtComputationInputDescriptorVector
430 HdExtComputationOutputDescriptorVector
434 HdExtComputationPrimvarDescriptorVector
436 HdInterpolation interpolation)
override;
440 TfToken const& input)
override;
445 size_t maxSampleCount,
447 VtValue *sampleValues)
override;
460 SdfPathMap::const_iterator it = _cache2indexPath.find(cachePath);
461 if (it != _cache2indexPath.end()) {
484 SdfPathMap::const_iterator it = _index2cachePath.find(indexPath);
485 if (it != _index2cachePath.end()) {
517 HdSelectionSharedPtr
const &result);
528 size_t maxNumSamples,
float *times,
VtValue *samples,
529 VtIntArray *indices);
536 bool _ValidateRefineLevel(
int level) {
537 if (!(0 <= level && level <= 8)) {
539 "expected range is [0,8]",
546 void _AddTask(UsdImagingDelegate::_Worker *worker,
SdfPath const& usdPath);
552 bool _IsDrawModeApplied(
UsdPrim const& prim);
560 UsdStageWeakPtr
const& sender);
565 typedef TfHashMap<SdfPath, SdfPathVector, SdfPath::Hash>
566 _FlattenedDependenciesCacheMap;
578 bool _RefreshUsdObject(
SdfPath const& usdPath,
580 _FlattenedDependenciesCacheMap
const &cache,
582 SdfPathSet* allTrackedVariabilityPaths);
591 void _ResyncUsdPrim(
SdfPath const& usdRootPath,
592 _FlattenedDependenciesCacheMap
const &cache,
594 bool repopulateFromRoot =
false);
610 void _UpdateSingleValue(
SdfPath const& cachePath,
int dirtyFlags);
617 bool _CanPopulate(
UsdPrim const& rootPrim)
const;
621 void _SetStateForPopulation(
UsdPrim const& rootPrim,
622 SdfPathVector
const& excludedPaths,
623 SdfPathVector
const& invisedPaths);
631 static void _ExecuteWorkForVariabilityUpdate(_Worker* worker);
636 bool _GetVisible(
UsdPrim const& prim);
647 static void _ExecuteWorkForTimeUpdate(_Worker* worker);
654 typedef TfHashMap<
TfToken, UsdImagingPrimAdapterSharedPtr,
656 _AdapterMap _adapterMap;
660 UsdImagingPrimAdapterSharedPtr adapter;
663 HdDirtyBits timeVaryingBits;
665 HdDirtyBits dirtyBits;
670 typedef TfHashMap<SdfPath, _HdPrimInfo, SdfPath::Hash> _HdPrimInfoMap;
673 _HdPrimInfoMap _hdPrimInfoMap;
675 typedef std::multimap<SdfPath, SdfPath> _DependencyMap;
678 _DependencyMap _dependencyInfo;
682 void _GatherDependencies(
SdfPath const& subtree,
683 SdfPathVector *affectedCachePaths);
689 _GatherDependencies(
SdfPath const &subtree,
690 _FlattenedDependenciesCacheMap
const &cache,
691 SdfPathVector *affectedCachePaths);
696 typedef TfHashMap<SdfPath, SdfPath, SdfPath::Hash> SdfPathMap;
697 SdfPathMap _cache2indexPath;
698 SdfPathMap _index2cachePath;
702 UsdImagingPrimAdapterSharedPtr
const& _AdapterLookup(
704 bool ignoreInstancing =
false);
705 UsdImagingPrimAdapterSharedPtr
const& _AdapterLookup(
709 _HdPrimInfo *_GetHdPrimInfo(
const SdfPath &cachePath);
711 Usd_PrimFlagsConjunction _GetDisplayPredicate()
const;
712 Usd_PrimFlagsConjunction _GetDisplayPredicateForPrototypes()
const;
716 void _MarkRenderTagsDirty();
718 typedef TfHashSet<SdfPath, SdfPath::Hash> _DirtySet;
721 _DirtySet _dirtyCachePaths;
724 typedef TfHashMap<SdfPath, int, SdfPath::Hash> _RefineLevelMap;
726 _RefineLevelMap _refineLevelMap;
732 UsdStageRefPtr _stage;
734 SdfPathVector _excludedPrimPaths;
735 SdfPathVector _invisedPrimPaths;
737 RigidXformOverridesMap _rigidXformOverrides;
749 SdfPath _cameraPathForSampling;
751 int _refineLevelFallback;
753 HdCullStyle _cullStyleFallback;
756 SdfPathVector _timeVaryingPrimCache;
757 bool _timeVaryingPrimCacheValid;
761 SdfPathVector _usdPathsToResync;
766 typedef std::unordered_map<SdfPath, TfTokenVector, SdfPath::Hash>
768 _PathsToUpdateMap _usdPathsToUpdate;
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;
784 PickabilityMap _pickablesMap;
790 bool _enableUsdDrawModes;
792 const bool _hasDrawModeAdapter;
795 bool _sceneMaterialsEnabled;
798 bool _sceneLightsEnabled;
800 CameraUtilConformWindowPolicy _appWindowPolicy;
803 const bool _coordSysEnabled;
806 bool _displayUnloadedPrimsWithBounds;
813 PXR_NAMESPACE_CLOSE_SCOPE
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().
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()).
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.
USDIMAGING_API void SetRefineLevel(SdfPath const &usdPath, int level)
Sets an explicit refinement level for the given USD prim.