Skip to content

Commit

Permalink
Allowing glTFs to be loaded that don't have uvs and normals (bevyengi…
Browse files Browse the repository at this point in the history
…ne#406)

allowing gltfs to be loaded that don't have uvs and normals, by filling missing attributes them with zeros
  • Loading branch information
julhe authored and mrk-its committed Oct 6, 2020
1 parent e7deec8 commit c7e80f3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions crates/bevy_render/src/mesh/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ impl Mesh {
pub fn get_vertex_buffer_bytes(
&self,
vertex_buffer_descriptor: &VertexBufferDescriptor,
fill_missing_attributes: bool,
) -> Result<Vec<u8>, MeshToVertexBufferError> {
let length = self.attributes.first().map(|a| a.values.len()).unwrap_or(0);
let mut bytes = vec![0; vertex_buffer_descriptor.stride as usize * length];
Expand All @@ -146,9 +147,11 @@ impl Mesh {
}
}
None => {
return Err(MeshToVertexBufferError::MissingVertexAttribute {
attribute_name: vertex_attribute.name.clone(),
})
if !fill_missing_attributes {
return Err(MeshToVertexBufferError::MissingVertexAttribute {
attribute_name: vertex_attribute.name.clone(),
});
}
}
}
}
Expand Down Expand Up @@ -530,7 +533,7 @@ pub fn mesh_resource_provider_system(
for changed_mesh_handle in changed_meshes.iter() {
if let Some(mesh) = meshes.get(changed_mesh_handle) {
let vertex_bytes = mesh
.get_vertex_buffer_bytes(&vertex_buffer_descriptor)
.get_vertex_buffer_bytes(&vertex_buffer_descriptor, true)
.unwrap();
// TODO: use a staging buffer here
let vertex_buffer = render_resource_context.create_buffer_with_data(
Expand Down Expand Up @@ -644,7 +647,7 @@ mod tests {

let descriptor = Vertex::as_vertex_buffer_descriptor();
assert_eq!(
mesh.get_vertex_buffer_bytes(descriptor).unwrap(),
mesh.get_vertex_buffer_bytes(descriptor, true).unwrap(),
expected_vertices.as_bytes(),
"buffer bytes are equal"
);
Expand Down

0 comments on commit c7e80f3

Please sign in to comment.