Skip to content

Commit

Permalink
allowing gltfs to be loaded that don't have uvs and normals, by filli…
Browse files Browse the repository at this point in the history
…ng missing attributes them with zeros
  • Loading branch information
Julian Heinken committed Aug 31, 2020
1 parent 8106f77 commit e16ddb3
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,31 @@ fn load_node(buffer_data: &[Vec<u8>], node: &gltf::Node, depth: i32) -> Result<M
let primitive_topology = get_primitive_topology(primitive.mode())?;
let mut mesh = Mesh::new(primitive_topology);

if let Some(vertex_attribute) = reader
.read_positions()
.map(|v| VertexAttribute::position(v.collect()))
{
mesh.attributes.push(vertex_attribute);
}
let vertex_attribute = match reader.read_positions().map(|v| VertexAttribute::position(v.collect())){
Some(x) => x,
None => return Err(GltfError::BufferFormatUnsupported) //TODO: return proper error message
};

let total_vertices = vertex_attribute.values.len();
mesh.attributes.push(vertex_attribute);


if let Some(vertex_attribute) = reader
.read_normals()
.map(|v| VertexAttribute::normal(v.collect()))
{
mesh.attributes.push(vertex_attribute);
} else {
mesh.attributes.push(VertexAttribute::normal(vec![[0.0, 0.0, 0.0]; total_vertices]));
}

if let Some(vertex_attribute) = reader
.read_tex_coords(0)
.map(|v| VertexAttribute::uv(v.into_f32().collect()))
{
mesh.attributes.push(vertex_attribute);
} else {
mesh.attributes.push(VertexAttribute::uv(vec![[0.0, 0.0]; total_vertices]));
}

if let Some(indices) = reader.read_indices() {
Expand Down

0 comments on commit e16ddb3

Please sign in to comment.