Conversation
|
I think we probably don't need a separate crate for this. I'd just add a method to the existing Wherever As far as where to put the |
Having to access the window is a bit inconvenient, but gets the current information. |
How would you? I think right now it's necessary to first query for a |
I was trying to suggest that the size is kept up to date between the |
I mean, right, you have to get the Camera and Windows resources to your system, but then just pass them to the casting method and let the raycaster pull whatever information it wants. |
| } | ||
|
|
||
| pub fn from_mouse_position( | ||
| mouse_position: &Vec2, |
There was a problem hiding this comment.
Window now has .cursor_position() method. We could add:
pub fn from_window(
window: &Window,
camera: &Camera,
camera_transform: &GlobalTransform,
) -> Self {
Self::from_mouse_position(window.cursor_position(), camera, camera_transform)
}
examples/physics/raycast.rs
Outdated
|
|
||
| let hit = if let Some(plane_hit) = plane_hit { | ||
| if let Some(sphere_hit) = sphere_hit { | ||
| if plane_hit.t() < sphere_hit.t() { |
There was a problem hiding this comment.
We have 6 nested (for and if) statements here, that is very complex.
There was a problem hiding this comment.
Although I disagree with 6 nested blocks being inherently complex, I agree that this particular instance is unnecessarily verbose and doesn't get the point across. I'm looking for something more elegant but feel free to propose changes where you see fit.
| use glam::Vec3; | ||
|
|
||
| pub struct RayHit { | ||
| t: f32, |
There was a problem hiding this comment.
Please consider renaming it to something more meaningful.
|
|
||
| impl RayIntersector for Plane { | ||
| fn intersect_ray(&self, ray: &Ray) -> Option<RayHit> { | ||
| let d = self.normal().dot(*ray.direction()); |
There was a problem hiding this comment.
Please describe what is this line doing.
There was a problem hiding this comment.
It assigns the dot product between the plane normal and the ray direction to the variable d (now changed to denominator). I don't think that needs a comment.
| let d = self.normal().dot(*ray.direction()); | ||
| if d.abs() > f32::EPSILON { | ||
| let t = (*self.center() - *ray.origin()).dot(*self.normal()) / d; | ||
| if t > 0.0 { |
There was a problem hiding this comment.
I am guessing the t and d is taken from some formula. We can give it a more verbose name in our code.
There was a problem hiding this comment.
I would agree and have changed the names.
| camera_transform: &GlobalTransform, | ||
| ) -> Self { | ||
| if window.id() != camera.window { | ||
| panic!("Generating Ray from Camera with wrong Window"); |
There was a problem hiding this comment.
Correct me if i'm wrong, this can terminate the program?
There was a problem hiding this comment.
It can, you're right. This is by design. Passing a non-matching window and camera to from_mouse_position(..) would result in undefined behavior and should be checked before calling the method. Do you think a Log Error would be more sensible? I didn't familiarize myself very much with the Diagnostics Plugin, so maybe that could help.
There was a problem hiding this comment.
TBH I don't know the right answer, I am learning here 👍
| impl RayIntersector for Triangle { | ||
| // using the Moeller-Trumbore intersection algorithm | ||
| // Can anyone think of sensible names for theese? | ||
| #[allow(clippy::many_single_char_names)] |
There was a problem hiding this comment.
Is this allow acceptable?
| } | ||
|
|
||
| // Is there a way to reduce the arguments? | ||
| #[allow(clippy::too_many_arguments)] |
There was a problem hiding this comment.
Is this allow acceptable?
|
We have a community crate for this now as well: I definitely think this functionality is useful though, and I'm of the opinion that raycasting probably deserves a home in bevy itself once it matures a bit more and we want to build functionality (like the editor, PBR or convenience functions) on top of raycasting. |
|
I'm not sure merging everything under Bevy umbrella is a sustainable approach. This creates a contract for supporting these things. Maybe it would be better to provide an easy way of adding&integrating 3rd party plugins - like a "plugin store" etc. |
|
Yeah I've been holding off on this because first party raycasting isn't a priority and its a relatively opinionated feature. In the short term, do I think it makes sense to let the community handle raycasting in 3rd party plugins. Eventually I think we'll need to adopt something officially, at least for the editor. But I think that raycasting is a common enough operation that we will want an official general-purpose solution (in the long term). I also agree that a "plugin store" is a good idea. Crates.io isn't great for Bevy plugin discovery and awesome-bevy isn't great at sorting / prioritizing / finding information. I think eventually we should migrate awesome-bevy to a more interactive / informative alternative on bevyengine.org. It would basically be a database of crates.io links with additional metadata (images, category, etc) and a searchable interface. I can't say I will prioritize that in the short term though :) |
|
@cart Looking back on this, I still want to push for having 1st party support for at least the bare-minimum functionality that calculates a ray (position, vector) from screen coordinates and a camera (transform, projection). This math is not trivial and can vary based on how the engine implements cameras. I agree that doing much more than that is probably not a high priority. |
|
@bonsairobo I agree with the need for first-party support. I expect that @aevyrie will be working on a raycasting RFC, following up on the geometric primitives chain of work. |
|
Thanks for the ping. 😄 In short, I agree with:
If you have suggestions for API/features in Until the feature becomes a priority for the engine, we can continue to experiment in external crates without burdening the engine with more code to support. |
|
most of this exist now in Bevy except ray intersection with a sphere or a triangle |
Updates the requirements on [petgraph](https://github.com/petgraph/petgraph) to permit the latest version. <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/petgraph/petgraph/blob/master/RELEASES.rst">petgraph's changelog</a>.</em></p> <blockquote> <h1>Version 0.7.1 (2025-01-08)</h1> <ul> <li>Do not unnecessarily restrict <code>indexmap</code> version (<code>[#714](https://github.com/petgraph/petgraph/issues/714)</code>_)</li> <li>Export <code>UndirectedAdaptor</code> (<code>[#717](https://github.com/petgraph/petgraph/issues/717)</code>_)</li> </ul> <p>.. _<code>[#714](https://github.com/petgraph/petgraph/issues/714)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/714">petgraph/petgraph#714</a> .. _<code>[#717](https://github.com/petgraph/petgraph/issues/717)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/717">petgraph/petgraph#717</a></p> <h1>Version 0.7.0 (2024-12-31)</h1> <ul> <li>Re-released version 0.6.6 with the correct version number, as it included a major update to an exposed crate (<code>[#664](https://github.com/petgraph/petgraph/issues/664)</code>_).</li> </ul> <h1>Version 0.6.6 (2024-12-31 - yanked)</h1> <ul> <li>Add graph6 format encoder and decoder (<code>[#658](https://github.com/petgraph/petgraph/issues/658)</code>_)</li> <li>Dynamic Topological Sort algorithm support (<code>[#675](https://github.com/petgraph/petgraph/issues/675)</code>_)</li> <li>Add <code>UndirectedAdaptor</code> (<code>[#695](https://github.com/petgraph/petgraph/issues/695)</code>_)</li> <li>Add <code>LowerHex</code> and <code>UpperHex</code> implementations for <code>Dot</code> (<code>[#687](https://github.com/petgraph/petgraph/issues/687)</code>_)</li> <li>Make <code>serde</code> support more complete (<code>[#550](https://github.com/petgraph/petgraph/issues/550)</code>_)</li> <li>Process multiple edges in the Floyd-Warshall implementation (<code>[#685](https://github.com/petgraph/petgraph/issues/685)</code>_)</li> <li>Update <code>fixedbitset</code> to 0.5.7 (<code>[#664](https://github.com/petgraph/petgraph/issues/664)</code>_)</li> <li>Fix <code>immediately_dominated_by</code> function called on root of graph returns root itself (<code>[#670](https://github.com/petgraph/petgraph/issues/670)</code>_)</li> <li>Fix adjacency matrix for <code>Csr</code> and <code>List</code> (<code>[#648](https://github.com/petgraph/petgraph/issues/648)</code>_)</li> <li>Fix clippy warnings (<code>[#701](https://github.com/petgraph/petgraph/issues/701)</code>_)</li> <li>Add performance note to the <code>all_simple_paths</code> function documentation (<code>[#693](https://github.com/petgraph/petgraph/issues/693)</code>_)</li> </ul> <p>.. _<code>[#658](https://github.com/petgraph/petgraph/issues/658)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/658">petgraph/petgraph#658</a> .. _<code>[#675](https://github.com/petgraph/petgraph/issues/675)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/675">petgraph/petgraph#675</a> .. _<code>[#695](https://github.com/petgraph/petgraph/issues/695)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/695">petgraph/petgraph#695</a> .. _<code>[#687](https://github.com/petgraph/petgraph/issues/687)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/687">petgraph/petgraph#687</a> .. _<code>[#550](https://github.com/petgraph/petgraph/issues/550)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/550">petgraph/petgraph#550</a> .. _<code>[#685](https://github.com/petgraph/petgraph/issues/685)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/685">petgraph/petgraph#685</a> .. _<code>[#664](https://github.com/petgraph/petgraph/issues/664)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/664">petgraph/petgraph#664</a> .. _<code>[#670](https://github.com/petgraph/petgraph/issues/670)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/670">petgraph/petgraph#670</a> .. _<code>[#648](https://github.com/petgraph/petgraph/issues/648)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/648">petgraph/petgraph#648</a> .. _<code>[#701](https://github.com/petgraph/petgraph/issues/701)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/701">petgraph/petgraph#701</a> .. _<code>[#693](https://github.com/petgraph/petgraph/issues/693)</code>: <a href="https://redirect.github.com/petgraph/petgraph/pull/693">petgraph/petgraph#693</a></p> <h1>Version 0.6.5 (2024-05-06)</h1> <ul> <li>Add rayon support for <code>GraphMap</code> (<code>[#573](https://github.com/petgraph/petgraph/issues/573)</code><em>, <code>[#615](https://github.com/petgraph/petgraph/issues/615)</code></em>)</li> <li>Add <code>Topo::with_initials</code> method (<code>[#585](https://github.com/petgraph/petgraph/issues/585)</code>_)</li> <li>Add logo to the project (<code>[#598](https://github.com/petgraph/petgraph/issues/598)</code>_)</li> <li>Add Ford-Fulkerson algorithm (<code>[#640](https://github.com/petgraph/petgraph/issues/640)</code>_)</li> <li>Update <code>itertools</code> to 0.12.1 (<code>[#628](https://github.com/petgraph/petgraph/issues/628)</code>_)</li> <li>Update <code>GraphMap</code> to allow custom hash functions (<code>[#622](https://github.com/petgraph/petgraph/issues/622)</code>_)</li> </ul> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/petgraph/petgraph/commit/2765d2a55044a35a20d95c50a2f318fbc3bb85f4"><code>2765d2a</code></a> Release 0.7.1 (<a href="https://redirect.github.com/petgraph/petgraph/issues/722">#722</a>)</li> <li><a href="https://github.com/petgraph/petgraph/commit/d341db9d18582cfcffebf320896947e55ecba09c"><code>d341db9</code></a> ci: downgrade hashbrown rather than limiting indexmap (<a href="https://redirect.github.com/petgraph/petgraph/issues/714">#714</a>)</li> <li><a href="https://github.com/petgraph/petgraph/commit/73c64b629f38dc8b0a8edc7550f16a662ed05c25"><code>73c64b6</code></a> Make UndirectedAdaptor & inner G pub (<a href="https://redirect.github.com/petgraph/petgraph/issues/717">#717</a>)</li> <li><a href="https://github.com/petgraph/petgraph/commit/d057429081bc02812d3605d1e7159f0e73361e51"><code>d057429</code></a> Release <code>0.7.0</code> (<a href="https://redirect.github.com/petgraph/petgraph/issues/713">#713</a>)</li> <li><a href="https://github.com/petgraph/petgraph/commit/13ebd7d2ddd4a1ac07a33606c0d4f82d342e5fa6"><code>13ebd7d</code></a> Release <code>0.6.6</code> (<a href="https://redirect.github.com/petgraph/petgraph/issues/706">#706</a>)</li> <li><a href="https://github.com/petgraph/petgraph/commit/159341e4af2a1292d8a1da428d64784e2dfc8ae5"><code>159341e</code></a> Implement DSatur graph coloring algorithm</li> <li><a href="https://github.com/petgraph/petgraph/commit/7fa3aac97168de7fca54644a5b45c464d5245535"><code>7fa3aac</code></a> fix: adjacency matrix for csr and adjacency list (<a href="https://redirect.github.com/petgraph/petgraph/issues/648">#648</a>)</li> <li><a href="https://github.com/petgraph/petgraph/commit/9fda6bbe2e52663d03317083d2623faa4f0d4cd4"><code>9fda6bb</code></a> Update gitignore with possible editor extensions to ensure they do not occur ...</li> <li><a href="https://github.com/petgraph/petgraph/commit/9b5837e395c342e9cb2e5a2b3870fa7ee6650ef4"><code>9b5837e</code></a> Allow clippy::needless_range_loop in benches</li> <li><a href="https://github.com/petgraph/petgraph/commit/ad9f83c2ae237ba6f5832a19f01ef8c3ae14dd19"><code>ad9f83c</code></a> Process warnings in 'test' target</li> <li>Additional commits viewable in <a href="https://github.com/petgraph/petgraph/compare/petgraph@v0.6.0...petgraph@v0.7.1">compare view</a></li> </ul> </details> <br /> Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Adding this as a draft, as I made some assumptions I am unsure of:
bevy_physicsRay::from_mouse_position(..)should be a method ofRayraycast.rsis as simple as possible (e.g. themove mouse.system()could certainly be removed)Looking forward to your guys feedback 😄