24 #ifndef PXR_IMAGING_HDX_PICK_TASK_H 25 #define PXR_IMAGING_HDX_PICK_TASK_H 28 #include "pxr/imaging/hdx/api.h" 30 #include "pxr/imaging/hdSt/textureUtils.h" 31 #include "pxr/imaging/hd/dataSource.h" 32 #include "pxr/imaging/hd/enums.h" 33 #include "pxr/imaging/hd/primOriginSchema.h" 34 #include "pxr/imaging/hd/renderPass.h" 35 #include "pxr/imaging/hd/renderPassState.h" 36 #include "pxr/imaging/hd/rprimCollection.h" 37 #include "pxr/imaging/hd/task.h" 46 #include "pxr/usd/sdf/path.h" 51 PXR_NAMESPACE_OPEN_SCOPE
53 #define HDX_PICK_TOKENS \ 58 (pickPrimsAndInstances) \ 64 (resolveNearestToCamera) \ 65 (resolveNearestToCenter) \ 71 class HdStRenderBuffer;
73 using HdStShaderCodeSharedPtr = std::shared_ptr<class HdStShaderCode>;
83 : cullStyle(HdCullStyleNothing)
84 , enableSceneMaterials(
true)
87 HdCullStyle cullStyle;
88 bool enableSceneMaterials;
115 inline bool IsValid()
const {
120 size_t GetHash()
const;
123 using HdxPickHitVector = std::vector<HdxPickHit>;
194 const TfToken &nameInPrimOrigin =
195 HdPrimOriginSchemaTokens->scenePath)
const;
234 using DepthMaskCallback = std::function<void(
void)>;
237 : resolution(128, 128)
238 , pickTarget(HdxPickTokens->pickPrimsAndInstances)
239 , resolveMode(HdxPickTokens->resolveNearestToCamera)
240 , doUnpickablesOcclude(
false)
242 , projectionMatrix(1)
244 , depthMaskCallback(
nullptr)
252 bool doUnpickablesOcclude;
255 std::vector<GfVec4d> clipPlanes;
256 DepthMaskCallback depthMaskCallback;
258 HdxPickHitVector *outHits;
286 HdDirtyBits* dirtyBits)
override;
290 void Prepare(HdTaskContext* ctx,
295 void Execute(HdTaskContext* ctx)
override;
302 return (int32_t(idColor[0] & 0xff) << 0) |
303 (int32_t(idColor[1] & 0xff) << 8) |
304 (int32_t(idColor[2] & 0xff) << 16) |
305 (int32_t(idColor[3] & 0xff) << 24);
318 void _InitIfNeeded();
319 void _CreateAovBindings();
320 void _CleanupAovBindings();
321 void _ResizeOrCreateBufferForAOV(
324 void _ConditionStencilWithGLCallback(
325 HdxPickTaskContextParams::DepthMaskCallback maskCallback,
328 bool _UseOcclusionPass()
const;
329 bool _UseWidgetPass()
const;
332 HdStTextureUtils::AlignedBuffer<T>
333 _ReadAovBuffer(
TfToken const & aovName)
const;
339 HdRenderPassSharedPtr _pickableRenderPass;
340 HdRenderPassSharedPtr _occluderRenderPass;
341 HdRenderPassSharedPtr _widgetRenderPass;
345 HdRenderPassStateSharedPtr _pickableRenderPassState;
346 HdRenderPassStateSharedPtr _occluderRenderPassState;
347 HdRenderPassStateSharedPtr _widgetRenderPassState;
351 std::vector<std::unique_ptr<HdStRenderBuffer>> _pickableAovBuffers;
352 HdRenderPassAovBindingVector _pickableAovBindings;
354 size_t _pickableDepthIndex;
356 std::unique_ptr<HdStRenderBuffer> _widgetDepthStencilBuffer;
357 HdRenderPassAovBindingVector _widgetAovBindings;
387 int const* instanceIds,
388 int const* elementIds,
428 void ResolveAll(HdxPickHitVector* allHits)
const;
436 bool _ResolveHit(
int index,
int x,
int y,
float z,
HdxPickHit* hit)
const;
438 size_t _GetHash(
int index)
const;
439 bool _IsValidHit(
int index)
const;
443 int _GetPrimId(
int index)
const {
444 return _primIds ? _primIds[index] : -1;
446 int _GetInstanceId(
int index)
const {
447 return _instanceIds ? _instanceIds[index] : -1;
449 int _GetElementId(
int index)
const {
450 return _elementIds ? _elementIds[index] : -1;
452 int _GetEdgeId(
int index)
const {
453 return _edgeIds ? _edgeIds[index] : -1;
455 int _GetPointId(
int index)
const {
456 return _pointIds ? _pointIds[index] : -1;
462 GfVec3f _GetNormal(
int index)
const;
465 int const* _instanceIds;
466 int const* _elementIds;
468 int const* _pointIds;
470 float const* _depths;
511 PXR_NAMESPACE_CLOSE_SCOPE
513 #endif // PXR_IMAGING_HDX_PICK_TASK_H Basic type for a vector of 4 int components.
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
HDX_API void ResolveUnique(HdxPickHitVector *allHits) const
Return the set of unique hit points, keeping only the nearest depth value.
HDX_API bool IsValid() const
Return whether the result was given well-formed parameters.
Basic type for a vector of 2 int components.
Standard pointer typedefs.
Pick task context params.
SdfPath objectId
Path computed from scenePath's in primOrigin data source of picked prim and instancers if provided by...
Provide architecture-specific memory-alignment information.
float normalizedDepth
normalizedDepth is in the range [0,1].
Basic type for a vector of 3 float components.
AR_API bool operator!=(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
A set of rendering parameters used among render passes.
AR_API bool operator==(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
Information about an instancer instancing a picked object (or an instancer instancing such an instanc...
Token for efficient comparison, assignment, and hashing of known strings.
HDX_API void ResolveNearestToCenter(HdxPickHitVector *allHits) const
Return the nearest single hit point from the center of the viewport.
int instanceId
Index of the picked instance.
Stores a 4x4 matrix of double elements.
Adapter class providing data exchange with the client scene graph.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
HdContainerDataSourceHandle instancePrimOrigin
The prim origin data source of the picked (implicit) instance.
std::vector< TfToken > TfTokenVector
Convenience types.
A named, semantic collection of objects.
A utility class for resolving ID buffers into hits.
A path value used to locate objects in layers or scenegraphs.
SdfPath delegateId
delegateID of HdSceneDelegate that provided the picked prim.
static int DecodeIDRenderColor(unsigned char const idColor[4])
Utility: Given a UNorm8Vec4 pixel, unpack it into an int32 ID.
HdContainerDataSourceHandle instancerPrimOrigin
The prim origin data source of the instancer.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Hydra Graphics Interface.
SdfPath instancerId
Only supported for scene delegates, see HdxPrimOriginInfo for scene indices.
A renderpass AOV represents a binding of some output of the rendering process to an output buffer.
SdfPath instanceSceneIndexPath
For implicit instancing (native instancing in USD), the path of the picked instance in the scene inde...
HdContainerDataSourceHandle primOrigin
The prim origin data source for the picked prim if provided by the scene index.
A helper to extract information about the picked prim that allows modern applications to identify a p...
Basic type for a vector of 2 float components.
A task for running picking queries against the current scene.
A render buffer is a handle to a data resource that can be rendered into, such as a 2d image for a dr...
static HDX_API HdxPrimOriginInfo FromPickHit(HdRenderIndex *renderIndex, const HdxPickHit &hit)
Query terminal scene index of render index for information about picked prim.
SdfPath instancerSceneIndexPath
The path of the instancer in the scene index.
HDX_API void Execute(HdTaskContext *ctx) override
Execute the pick task.
HDX_API void Sync(HdSceneDelegate *delegate, HdTaskContext *ctx, HdDirtyBits *dirtyBits) override
Sync the render pass resources.
HDX_API void ResolveAll(HdxPickHitVector *allHits) const
Return all hit points.
std::vector< HdxInstancerContext > instancerContexts
Information about the instancers instancing the picked object.
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
HDX_API void ResolveNearestToCamera(HdxPickHitVector *allHits) const
Return the nearest single hit point.
HDX_API SdfPath GetFullPath(const TfToken &nameInPrimOrigin=HdPrimOriginSchemaTokens->scenePath) const
Combines instance scene paths and prim scene path to obtain the full scene path.
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the pick task.