Skip to content

Commit f9f6a8c

Browse files
IceSentrynicopap
andauthored
Update crates/bevy_render/src/picking.rs
Co-authored-by: Nicola Papale <[email protected]>
1 parent 5b2820d commit f9f6a8c

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

crates/bevy_render/src/picking.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,17 @@ impl GpuPickingCamera {
139139
}
140140

141141
// TODO This is currently a constant, but could be user configurable
142-
let entity = match MESH_ID_TEXTURE_FORMAT {
142+
let texture_bytes = &self.data.mesh_id_buffer[start..end];
143+
let index = match MESH_ID_TEXTURE_FORMAT {
143144
TextureFormat::R16Uint => {
144-
let index =
145-
u16::from_ne_bytes(self.data.mesh_id_buffer[start..end].try_into().ok()?);
146-
self.data.visible_mesh_entities[index as usize]
145+
u16::from_ne_bytes(texture_bytes.try_into().ok()?) as usize
147146
}
148147
TextureFormat::R32Uint => {
149-
let index =
150-
u32::from_ne_bytes(self.data.mesh_id_buffer[start..end].try_into().ok()?);
151-
self.data.visible_mesh_entities[index as usize]
148+
u32::from_ne_bytes(texture_bytes.try_into().ok()?) as usize
152149
}
153150
_ => panic!("Unsupported mesh id texture format"),
154151
};
152+
let entity = self.data.visible_mesh_entities[index];
155153

156154
if entity != Entity::PLACEHOLDER {
157155
Some(entity)

0 commit comments

Comments
 (0)