Simplify GLTF loader code (#245)

simplify gtlf loader code
This commit is contained in:
Csányi István 2020-08-20 23:06:16 +02:00 committed by GitHub
parent 1ebb7e44ff
commit 268b520105
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
use bevy_render::{ use bevy_render::{
mesh::{Mesh, VertexAttribute, VertexAttributeValues}, mesh::{Mesh, VertexAttribute},
pipeline::PrimitiveTopology, pipeline::PrimitiveTopology,
}; };
@ -76,24 +76,24 @@ fn load_node(buffer_data: &[Vec<u8>], node: &gltf::Node, depth: i32) -> Result<M
let primitive_topology = get_primitive_topology(primitive.mode())?; let primitive_topology = get_primitive_topology(primitive.mode())?;
let mut mesh = Mesh::new(primitive_topology); let mut mesh = Mesh::new(primitive_topology);
if let Some(vertex_attribute) = reader.read_positions().map(|v| VertexAttribute { if let Some(vertex_attribute) = reader
name: "Vertex_Position".into(), .read_positions()
values: VertexAttributeValues::Float3(v.collect()), .map(|v| VertexAttribute::position(v.collect()))
}) { {
mesh.attributes.push(vertex_attribute); mesh.attributes.push(vertex_attribute);
} }
if let Some(vertex_attribute) = reader.read_normals().map(|v| VertexAttribute { if let Some(vertex_attribute) = reader
name: "Vertex_Normal".into(), .read_normals()
values: VertexAttributeValues::Float3(v.collect()), .map(|v| VertexAttribute::normal(v.collect()))
}) { {
mesh.attributes.push(vertex_attribute); mesh.attributes.push(vertex_attribute);
} }
if let Some(vertex_attribute) = reader.read_tex_coords(0).map(|v| VertexAttribute { if let Some(vertex_attribute) = reader
name: "Vertex_Uv".into(), .read_tex_coords(0)
values: VertexAttributeValues::Float2(v.into_f32().collect()), .map(|v| VertexAttribute::uv(v.into_f32().collect()))
}) { {
mesh.attributes.push(vertex_attribute); mesh.attributes.push(vertex_attribute);
} }