-
-
Notifications
You must be signed in to change notification settings - Fork 176
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
Index buffer specialization (Bevy PR #568) #49
Index buffer specialization (Bevy PR #568) #49
Conversation
Thanks for the fix!
Perhaps the entirety of world_triangle construction could be put into a function that accepts any Then the code might look something like: pick_intersection = match indices {
Indices::U16(vector) => ray_mesh_intersection(&pick_ray, &vector),
Indices::U32(vector) => ray_mesh_intersection(&pick_ray, &vector),
} Then, regardless of index type, it can be converted into a for i in 0..3 {
world_vertices[i] = mesh_to_world.transform_point3(Vec3::from(
vertex_positions[index[i] as usize],
));
} The other benefit of this is we could more easily write some unit tests for this function! |
Looking at this code again, I think we could make another improvement (while you're at it!). Every group of three indices is being bounds checked |
Sounds good! Just one thing, we can't use Also, I'm unwrapping the |
Okay!
I think panicking would be better. I'd prefer we crash the plugin instead of sending bad data into the picking algorithm, it will be much easier to debug if it ever fails to convert. As far as I can tell, this will only happen on 16-bit architectures where usize is not large enough to hold a u32. |
Great, changed! |
Bevy PR #568 reworked mesh indices, this PR introduces a fix to deal with that.
There's one thing I don't like of my implementation, because we would now have the same code twice and that's a big no no.
The other option is to use something like this above the
for index in indices.chunks(3)
loop:But as far as I know this would make a copy of the whole indices vector, and that doesn't seem right either.
Any ideas on how to do this in a more idiomatic way I'm not seeing?