Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved picking #494

Merged
merged 8 commits into from
Oct 5, 2024
Merged

Improved picking #494

merged 8 commits into from
Oct 5, 2024

Conversation

asny
Copy link
Owner

@asny asny commented Oct 4, 2024

Alternative to #478 and #479. Closes #467

@asny asny mentioned this pull request Oct 4, 2024
if depth < 1.0 {
Some(position + direction * depth * max_depth)
Some(IntersectionResult {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IDs here are limited by the maximum safe integer a f32 can hold (approximately 24 bits). However, use cases where the IDs ever get that high are probably extremely rare, so it probably isn't worth the additional complexity that fixing that issue would incur (what's currently done in #479). Maybe this limitation should be added to the documentation somewhere?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking 24 bit integer would be enough (16,777,215 instances is probably rare 🙂), but if we also have to output primitive ids, it's probably better to support the whole u32/i32 range. I fixed that in 439261b

pub geometry_id: u32,
/// The index of the intersected instance in the list of instances or 0 if the intersection did not hit an instanced geometry
pub instance_id: u32,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently noticed other 3D rendering libraries that provide this functionality also include the face index in their return result, which would take up the last alpha color slot. I believe this can be obtained from gl_PrimitiveID in the IntersectionMaterial fragment shader. This isn't needed for my use case, but could be beneficial in this hypothetical use case: a button panel, where all the buttons are part of the same model; it is known which triangles make up the buttons, so the face index is used to identify which button was clicked.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point! No reason not to add that to the intersection result as well. Fixed in e390c6a

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out gl_PrimitiveID is not supported on web, so I'm removing it again.

@asny asny merged commit cadff22 into master Oct 5, 2024
5 checks passed
@asny asny deleted the improved-picking branch November 28, 2024 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pick geometry instance from coordinate
2 participants