-
-
Notifications
You must be signed in to change notification settings - Fork 262
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
Rework AsyncCollider and add AsyncSceneCollider #160
Conversation
I also think we probably should use |
Yeah, that would be more ergonomic. Though in that case, the name
Good idea. |
And pass it into from_bevy_mesh()
@sebcrozet done! |
25eebc1
to
01bc40e
Compare
01bc40e
to
4d3504b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR! It looks nice. All mentions of "recursive children" should be replaced by descendant
since that’s what they are called in a tree-like data structure.
This doesn’t handle changes of Transform
properly when a collider if down the hierarchy. But fixing this can be considered out of the scope of this PR.
src/plugin/systems.rs
Outdated
) { | ||
for (entity, async_collider) in async_colliders.iter() { | ||
if scenes.get(&async_collider.handle).is_some() { | ||
for child in get_children_recursively(entity, &children) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of building a LinkedList
with all the descendants, I think it would be more efficient and versatile to replace get_children_recursively
by a traverse_descendants
function that would look like this:
fn traverse_descendants(entity: Entity, children: &Query<&Children>, f: &mut impl FnMut(Entity)) {
if let Ok(entity_children) = children.get(entity) {
for child in entity_children.iter() {
f(child);
let mut children = get_children_recursively(*child, children);
all_children.append(&mut children, f);
}
}
}
So this for child in get_children_recursively(entity, &children)
would simply call traverse_descendants
and provide a closure.
src/plugin/systems.rs
Outdated
.get(name.as_str()) | ||
.unwrap_or(&async_collider.shape); | ||
if let Some(shape) = shape { | ||
let mesh = meshes.get(handle).unwrap(); // SAFETY: Mesh is already loaded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know the SAFETY
comments are for unsafe
blocks instead of unwraps.
let mesh = meshes.get(handle).unwrap(); // SAFETY: Mesh is already loaded | |
let mesh = meshes.get(handle).unwrap(); // NOTE: Mesh is already loaded |
src/plugin/systems.rs
Outdated
Some(collider) => { | ||
commands.entity(child).insert(collider); | ||
} | ||
None => panic!("Unable to generate collider from mesh"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s just print an error instead of panicking, and specify the name of the mesh that failed:
None => panic!("Unable to generate collider from mesh"), | |
None => error!("AsyncSceneCollider: unable to generate collider from mesh `{}`", name), |
Thanks! Applied the suggestions and fixed conflicts in changelog with the latest master. |
Looks great, thanks! |
Closes #144.
I turned
AsyncCollider
into a struct and moved collision shape into a separate enum to reuse it forAsyncSceneCollider
. This also allows to check if mesh is loaded without expanding the enum.Maybe we should replace bevy_mesh, bevy_mesh_convex_decomposition and bevy_mesh_convex_decomposition_with_params with a single function which accepts
AsyncColliderShape
(if yes, how would you will rename it)?This will make things more clear and allow to get rid of matches in
init_asyc_*
systems.