Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions crates/bevy_picking/src/mesh_picking/ray_cast/intersections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,26 @@ pub(super) fn ray_intersection_over_mesh(
return None; // ray_mesh_intersection assumes vertices are laid out in a triangle list
}
// Vertex positions are required
let positions = mesh.attribute(Mesh::ATTRIBUTE_POSITION)?.as_float3()?;
let positions = mesh
.try_attribute(Mesh::ATTRIBUTE_POSITION)
.ok()?
.as_float3()?;

// Normals are optional
let normals = mesh
.attribute(Mesh::ATTRIBUTE_NORMAL)
.try_attribute(Mesh::ATTRIBUTE_NORMAL)
.ok()
.and_then(|normal_values| normal_values.as_float3());

let uvs = mesh
.attribute(Mesh::ATTRIBUTE_UV_0)
.try_attribute(Mesh::ATTRIBUTE_UV_0)
.ok()
.and_then(|uvs| match uvs {
VertexAttributeValues::Float32x2(uvs) => Some(uvs.as_slice()),
_ => None,
});

match mesh.indices() {
match mesh.try_indices().ok() {
Some(Indices::U16(indices)) => {
ray_mesh_intersection(ray, transform, positions, normals, Some(indices), uvs, cull)
}
Expand Down