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::{
mesh::{Mesh, VertexAttribute, VertexAttributeValues},
mesh::{Mesh, VertexAttribute},
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 mut mesh = Mesh::new(primitive_topology);
if let Some(vertex_attribute) = reader.read_positions().map(|v| VertexAttribute {
name: "Vertex_Position".into(),
values: VertexAttributeValues::Float3(v.collect()),
}) {
if let Some(vertex_attribute) = reader
.read_positions()
.map(|v| VertexAttribute::position(v.collect()))
{
mesh.attributes.push(vertex_attribute);
}
if let Some(vertex_attribute) = reader.read_normals().map(|v| VertexAttribute {
name: "Vertex_Normal".into(),
values: VertexAttributeValues::Float3(v.collect()),
}) {
if let Some(vertex_attribute) = reader
.read_normals()
.map(|v| VertexAttribute::normal(v.collect()))
{
mesh.attributes.push(vertex_attribute);
}
if let Some(vertex_attribute) = reader.read_tex_coords(0).map(|v| VertexAttribute {
name: "Vertex_Uv".into(),
values: VertexAttributeValues::Float2(v.into_f32().collect()),
}) {
if let Some(vertex_attribute) = reader
.read_tex_coords(0)
.map(|v| VertexAttribute::uv(v.into_f32().collect()))
{
mesh.attributes.push(vertex_attribute);
}