Skip to content

Commit

Permalink
Update crates/bevy_render/src/picking.rs
Browse files Browse the repository at this point in the history
Co-authored-by: Nicola Papale <nicopap@users.noreply.github.com>
  • Loading branch information
IceSentry and nicopap authored Aug 3, 2023
1 parent 5b2820d commit f9f6a8c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions crates/bevy_render/src/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,17 @@ impl GpuPickingCamera {
}

// TODO This is currently a constant, but could be user configurable
let entity = match MESH_ID_TEXTURE_FORMAT {
let texture_bytes = &self.data.mesh_id_buffer[start..end];
let index = match MESH_ID_TEXTURE_FORMAT {
TextureFormat::R16Uint => {
let index =
u16::from_ne_bytes(self.data.mesh_id_buffer[start..end].try_into().ok()?);
self.data.visible_mesh_entities[index as usize]
u16::from_ne_bytes(texture_bytes.try_into().ok()?) as usize
}
TextureFormat::R32Uint => {
let index =
u32::from_ne_bytes(self.data.mesh_id_buffer[start..end].try_into().ok()?);
self.data.visible_mesh_entities[index as usize]
u32::from_ne_bytes(texture_bytes.try_into().ok()?) as usize
}
_ => panic!("Unsupported mesh id texture format"),
};
let entity = self.data.visible_mesh_entities[index];

if entity != Entity::PLACEHOLDER {
Some(entity)
Expand Down

0 comments on commit f9f6a8c

Please sign in to comment.