bevy/src/render/vertex.rs

66 lines
1.6 KiB
Rust
Raw Normal View History

2019-12-10 07:12:50 +00:00
use std::convert::From;
2020-01-11 10:11:27 +00:00
use zerocopy::{AsBytes, FromBytes};
2019-12-01 01:42:27 +00:00
#[repr(C)]
#[derive(Clone, Copy, AsBytes, FromBytes)]
pub struct Vertex {
2019-12-10 07:12:50 +00:00
pub position: [f32; 4],
pub normal: [f32; 4],
}
impl From<([f32; 4], [f32; 4])> for Vertex {
2020-01-11 10:11:27 +00:00
fn from((position, normal): ([f32; 4], [f32; 4])) -> Self {
2019-12-10 07:12:50 +00:00
Vertex {
position: position,
normal: normal,
}
}
}
impl From<([f32; 3], [f32; 3])> for Vertex {
2020-01-11 10:11:27 +00:00
fn from((position, normal): ([f32; 3], [f32; 3])) -> Self {
2019-12-10 07:12:50 +00:00
Vertex {
2020-01-11 10:11:27 +00:00
position: [
position[0] as f32,
position[1] as f32,
position[2] as f32,
1.0,
],
2019-12-10 07:12:50 +00:00
normal: [normal[0] as f32, normal[1] as f32, normal[2] as f32, 0.0],
}
}
}
impl From<([i8; 4], [i8; 4])> for Vertex {
2020-01-11 10:11:27 +00:00
fn from((position, normal): ([i8; 4], [i8; 4])) -> Self {
2019-12-10 07:12:50 +00:00
Vertex {
2020-01-11 10:11:27 +00:00
position: [
position[0] as f32,
position[1] as f32,
position[2] as f32,
position[3] as f32,
],
normal: [
normal[0] as f32,
normal[1] as f32,
normal[2] as f32,
normal[3] as f32,
],
2019-12-10 07:12:50 +00:00
}
}
}
impl From<([i8; 3], [i8; 3])> for Vertex {
2020-01-11 10:11:27 +00:00
fn from((position, normal): ([i8; 3], [i8; 3])) -> Self {
2019-12-10 07:12:50 +00:00
Vertex {
2020-01-11 10:11:27 +00:00
position: [
position[0] as f32,
position[1] as f32,
position[2] as f32,
1.0,
],
2019-12-10 07:12:50 +00:00
normal: [normal[0] as f32, normal[1] as f32, normal[2] as f32, 0.0],
}
}
2020-01-11 10:11:27 +00:00
}