Created
March 6, 2024 05:18
-
-
Save pcwalton/32e876794a23fbc08416af10b8a123b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/crates/bevy_pbr/src/meshlet/from_mesh.rs b/crates/bevy_pbr/src/meshlet/from_mesh.rs | |
index 36af9c445..c6f8c6cff 100644 | |
--- a/crates/bevy_pbr/src/meshlet/from_mesh.rs | |
+++ b/crates/bevy_pbr/src/meshlet/from_mesh.rs | |
@@ -23,14 +23,14 @@ impl MeshletMesh { | |
if mesh.primitive_topology() != PrimitiveTopology::TriangleList { | |
return Err(MeshToMeshletMeshConversionError::WrongMeshPrimitiveTopology); | |
} | |
- let vertex_buffer_layout = &mesh.get_mesh_vertex_buffer_layout(); | |
- if vertex_buffer_layout.attribute_ids() | |
- != [ | |
- Mesh::ATTRIBUTE_POSITION.id, | |
- Mesh::ATTRIBUTE_NORMAL.id, | |
- Mesh::ATTRIBUTE_UV_0.id, | |
- Mesh::ATTRIBUTE_TANGENT.id, | |
- ] | |
+ if mesh.attributes().map(|(id, _)| id).eq([ | |
+ Mesh::ATTRIBUTE_POSITION.id, | |
+ Mesh::ATTRIBUTE_NORMAL.id, | |
+ Mesh::ATTRIBUTE_UV_0.id, | |
+ Mesh::ATTRIBUTE_TANGENT.id, | |
+ ] | |
+ .iter() | |
+ .cloned()) | |
{ | |
return Err(MeshToMeshletMeshConversionError::WrongMeshVertexAttributes); | |
} | |
@@ -40,12 +40,9 @@ impl MeshletMesh { | |
_ => return Err(MeshToMeshletMeshConversionError::MeshMissingIndices), | |
}; | |
let vertex_buffer = mesh.get_vertex_buffer_data(); | |
- let vertices = VertexDataAdapter::new( | |
- &vertex_buffer, | |
- vertex_buffer_layout.layout().array_stride as usize, | |
- 0, | |
- ) | |
- .unwrap(); | |
+ let vertices = | |
+ VertexDataAdapter::new(&vertex_buffer, mesh.get_mesh_vertex_size() as usize, 0) | |
+ .unwrap(); | |
// Split the mesh into meshlets | |
let meshopt_meshlets = build_meshlets(&indices, &vertices, 64, 64, 0.0); | |
diff --git a/crates/bevy_render/src/mesh/mesh/mod.rs b/crates/bevy_render/src/mesh/mesh/mod.rs | |
index 33a21e62d..baebb1e5c 100644 | |
--- a/crates/bevy_render/src/mesh/mesh/mod.rs | |
+++ b/crates/bevy_render/src/mesh/mesh/mod.rs | |
@@ -370,6 +370,14 @@ impl Mesh { | |
self | |
} | |
+ /// Returns the size of a vertex in bytes. | |
+ pub fn get_mesh_vertex_size(&self) -> u64 { | |
+ self.attributes | |
+ .values() | |
+ .map(|data| data.attribute.format.get_size()) | |
+ .sum() | |
+ } | |
+ | |
/// Computes and returns the index data of the mesh as bytes. | |
/// This is used to transform the index data into a GPU friendly format. | |
pub fn get_index_buffer_bytes(&self) -> Option<&[u8]> { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment