Skip to content

Commit

Permalink
Update loader.rs
Browse files Browse the repository at this point in the history
Update load_obj_pnt with latest changes to bevy in mind:
bevyengine/bevy@4645da3

(See AmionSky#1 )
  • Loading branch information
schwarzeszeux committed Nov 1, 2020
1 parent ec51fee commit 6b46cbf
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,17 @@ fn load_obj(bytes: Vec<u8>) -> Result<Mesh, ObjError> {
}

fn load_obj_pnt(obj: obj::Obj<obj::TexturedVertex>, mesh: &mut Mesh) {
mesh.attributes.push(VertexAttribute::position(
obj.vertices.iter().map(|v| v.position).collect(),
));
mesh.attributes.push(VertexAttribute::normal(
obj.vertices.iter().map(|v| v.normal).collect(),
));
mesh.attributes.push(VertexAttribute::uv(
obj.vertices
.iter()
// Flip UV for correct values
.map(|v| [v.texture[0], 1.0 - v.texture[1]])
.collect(),
));
let uvs = VertexAttributeValues::Float3(obj.vertices
.iter()
// Flip UV for correct values
.map(|v| [v.texture[0], 1.0 - v.texture[1], v.texture[2]])
.collect());
let positions = VertexAttributeValues::Float3(obj.vertices.iter().map(|v| v.position).collect());
let normals = VertexAttributeValues::Float3(obj.vertices.iter().map(|v| v.normal).collect());

mesh.attributes.insert(Cow::Borrowed(Mesh::ATTRIBUTE_POSITION), positions);
mesh.attributes.insert(Cow::Borrowed(Mesh::ATTRIBUTE_NORMAL), normals);
mesh.attributes.insert(Cow::Borrowed(Mesh::ATTRIBUTE_UV_0), uvs);

set_mesh_indices(mesh, obj);
}
Expand Down

0 comments on commit 6b46cbf

Please sign in to comment.