going to make entity spawning a little easier
This commit is contained in:
@@ -1,24 +1,32 @@
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use nalgebra::Vector4;
|
||||
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Vertex {
|
||||
_pos: [f32; 4],
|
||||
_normal: [f32; 4],
|
||||
pos: [f32; 4],
|
||||
normal: [f32; 4],
|
||||
}
|
||||
|
||||
unsafe impl Pod for Vertex {}
|
||||
|
||||
unsafe impl Zeroable for Vertex {}
|
||||
|
||||
pub fn vertex(pos: [f32; 3], nor: [f32; 3]) -> Vertex {
|
||||
Vertex {
|
||||
_pos: [pos[0], pos[1], pos[2], 1.0],
|
||||
_normal: [nor[0], nor[1], nor[2], 0.0],
|
||||
impl Vertex {
|
||||
pub fn position(&self) -> Vector4<f32> {
|
||||
Vector4::new(self.pos[0], self.pos[1], self.pos[2], self.pos[3])
|
||||
}
|
||||
pub fn from(pos: [f32; 3], nor: [f32; 3]) -> Vertex {
|
||||
Vertex {
|
||||
pos: [pos[0], pos[1], pos[2], 1.0],
|
||||
normal: [nor[0], nor[1], nor[2], 0.0],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn import_mesh(mesh_path: &str) -> (Vec<Vertex>, Vec<u32>) {
|
||||
unsafe impl Pod for Vertex {}
|
||||
unsafe impl Zeroable for Vertex {}
|
||||
|
||||
|
||||
|
||||
pub fn load_obj(mesh_path: &str) -> (Vec<Vertex>, Vec<u32>) {
|
||||
|
||||
let (models, materials) = tobj::load_obj(mesh_path, false).expect("Failed to load file");
|
||||
|
||||
@@ -46,7 +54,7 @@ pub fn import_mesh(mesh_path: &str) -> (Vec<Vertex>, Vec<u32>) {
|
||||
|
||||
for v in 0..mesh.positions.len() / 3 {
|
||||
vertex_data.push(
|
||||
vertex([
|
||||
Vertex::from([
|
||||
mesh.positions[3 * v],
|
||||
mesh.positions[3 * v + 1],
|
||||
mesh.positions[3 * v + 2]
|
||||
|
||||
Reference in New Issue
Block a user