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/hd/enums.h"
31 #include "pxr/imaging/hd/renderPass.h"
32 #include "pxr/imaging/hd/renderPassState.h"
33 #include "pxr/imaging/hd/rprimCollection.h"
34 #include "pxr/imaging/hd/task.h"
42 #include "pxr/usd/sdf/path.h"
47 PXR_NAMESPACE_OPEN_SCOPE
49 #define HDX_PICK_TOKENS \
54 (pickPrimsAndInstances) \
60 (resolveNearestToCamera) \
61 (resolveNearestToCenter) \
70 using HdStShaderCodeSharedPtr = std::shared_ptr<class HdStShaderCode>;
78 : cullStyle(HdCullStyleNothing)
79 , enableSceneMaterials(
true)
82 HdCullStyle cullStyle;
83 bool enableSceneMaterials;
99 float normalizedDepth;
101 inline bool IsValid()
const {
106 size_t GetHash()
const;
109 using HdxPickHitVector = std::vector<HdxPickHit>;
140 using DepthMaskCallback = std::function<void(void)>;
143 : resolution(128, 128)
144 , pickTarget(HdxPickTokens->pickPrimsAndInstances)
145 , resolveMode(HdxPickTokens->resolveNearestToCamera)
146 , doUnpickablesOcclude(
false)
148 , projectionMatrix(1)
150 , depthMaskCallback(
nullptr)
158 bool doUnpickablesOcclude;
161 std::vector<GfVec4d> clipPlanes;
162 DepthMaskCallback depthMaskCallback;
164 HdxPickHitVector *outHits;
186 ~HdxPickTask()
override;
192 HdDirtyBits* dirtyBits)
override;
196 void Prepare(HdTaskContext* ctx,
201 void Execute(HdTaskContext* ctx)
override;
208 return (int32_t(idColor[0] & 0xff) << 0) |
209 (int32_t(idColor[1] & 0xff) << 8) |
210 (int32_t(idColor[2] & 0xff) << 16) |
211 (int32_t(idColor[3] & 0xff) << 24);
223 void _InitIfNeeded(
GfVec2i const& widthHeight);
224 void _ConditionStencilWithGLCallback(
225 HdxPickTaskContextParams::DepthMaskCallback maskCallback);
227 bool _UseOcclusionPass()
const;
230 HdRenderPassSharedPtr _pickableRenderPass;
231 HdRenderPassSharedPtr _occluderRenderPass;
235 HdRenderPassStateSharedPtr _pickableRenderPassState;
236 HdRenderPassStateSharedPtr _occluderRenderPassState;
240 GlfDrawTargetRefPtr _drawTarget;
242 HdxPickTask() =
delete;
243 HdxPickTask(
const HdxPickTask &) =
delete;
244 HdxPickTask &operator =(
const HdxPickTask &) =
delete;
270 int const* instanceIds,
271 int const* elementIds,
288 HdxPickResult(HdxPickResult &&);
290 HdxPickResult& operator=(HdxPickResult &&);
311 void ResolveAll(HdxPickHitVector* allHits)
const;
319 bool _ResolveHit(
int index,
int x,
int y,
float z,
HdxPickHit* hit)
const;
320 size_t _GetHash(
int index)
const;
321 bool _IsValidHit(
int index)
const;
325 int _GetPrimId(
int index)
const {
326 return _primIds ? _primIds[index] : -1;
328 int _GetInstanceId(
int index)
const {
329 return _instanceIds ? _instanceIds[index] : -1;
331 int _GetElementId(
int index)
const {
332 return _elementIds ? _elementIds[index] : -1;
334 int _GetEdgeId(
int index)
const {
335 return _edgeIds ? _edgeIds[index] : -1;
337 int _GetPointId(
int index)
const {
338 return _pointIds ? _pointIds[index] : -1;
344 GfVec3f _GetNormal(
int index)
const;
347 int const* _instanceIds;
348 int const* _elementIds;
350 int const* _pointIds;
352 float const* _depths;
393 PXR_NAMESPACE_CLOSE_SCOPE
395 #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 ResolveAll(HdxPickHitVector *allHits) const
Return all hit points.
Basic type for a vector of 2 int components.
Standard pointer typedefs.
Pick task context params.
HDX_API void ResolveUnique(HdxPickHitVector *allHits) const
Return the set of unique hit points, keeping only the nearest depth value.
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)
#define TF_DECLARE_WEAK_AND_REF_PTRS(type)
Define standard weak, ref, and vector pointer types.
A class representing a GL render target with mutliple image attachments.
HDX_API void ResolveNearestToCenter(HdxPickHitVector *allHits) const
Return the nearest single hit point from the center of the viewport.
Token for efficient comparison, assignment, and hashing of known strings.
HDX_API void ResolveNearestToCamera(HdxPickHitVector *allHits) const
Return the nearest single hit point.
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.
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.
HDX_API bool IsValid() const
Return whether the result was given well-formed parameters.
static int DecodeIDRenderColor(unsigned char const idColor[4])
Utility: Given a UNorm8Vec4 pixel, unpack it into an int32 ID.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
Basic type for a vector of 2 float components.
A task for running picking queries against the current scene.
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.
bool IsEmpty() const noexcept
Returns true if this is the empty path (SdfPath::EmptyPath()).
HDX_API void Prepare(HdTaskContext *ctx, HdRenderIndex *renderIndex) override
Prepare the pick task.