library: render: mesh: from_slice to build Vector

This commit is contained in:
Antoine Martin 2020-03-27 12:08:17 +01:00 committed by Bruno BELANYI
parent f0d36c7d7b
commit cca40bcb8e

View file

@ -1,7 +1,7 @@
use std::convert::TryFrom; use std::convert::TryFrom;
use std::path::PathBuf; use std::path::PathBuf;
use nalgebra::{Similarity3, Unit}; use nalgebra::{Similarity3, Unit, VectorSlice3};
use serde::Deserialize; use serde::Deserialize;
@ -69,27 +69,18 @@ impl TryFrom<Wavefront> for Mesh {
// We apply the (arguably useless) scaling to the vectors in case it is // We apply the (arguably useless) scaling to the vectors in case it is
// negative, which would invert their direction // negative, which would invert their direction
let norm_a = { let norm_a = {
let vec = Vector::new( let vec: Vector =
mesh.normals[a * 3], VectorSlice3::from_slice(&mesh.normals[(a * 3)..(a * 3 + 3)]).into();
mesh.normals[a * 3 + 1],
mesh.normals[a * 3 + 2],
);
Unit::new_normalize(transform * vec) Unit::new_normalize(transform * vec)
}; };
let norm_b = { let norm_b = {
let vec = Vector::new( let vec: Vector =
mesh.normals[b * 3], VectorSlice3::from_slice(&mesh.normals[(b * 3)..(b * 3 + 3)]).into();
mesh.normals[b * 3 + 1],
mesh.normals[b * 3 + 2],
);
Unit::new_normalize(transform * vec) Unit::new_normalize(transform * vec)
}; };
let norm_c = { let norm_c = {
let vec = Vector::new( let vec: Vector =
mesh.normals[c * 3], VectorSlice3::from_slice(&mesh.normals[(c * 3)..(c * 3 + 3)]).into();
mesh.normals[c * 3 + 1],
mesh.normals[c * 3 + 2],
);
Unit::new_normalize(transform * vec) Unit::new_normalize(transform * vec)
}; };