bevy/src/render/vertex.rs

74 lines
1.9 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],
2020-01-14 01:35:30 +00:00
pub uv: [f32; 2],
2019-12-10 07:12:50 +00:00
}
2020-01-14 01:35:30 +00:00
impl From<([f32; 4], [f32; 4], [f32; 2])> for Vertex {
fn from((position, normal, uv): ([f32; 4], [f32; 4], [f32; 2])) -> Self {
2019-12-10 07:12:50 +00:00
Vertex {
position: position,
normal: normal,
2020-01-14 01:35:30 +00:00
uv: uv,
2019-12-10 07:12:50 +00:00
}
}
}
2020-01-14 01:35:30 +00:00
impl From<([f32; 3], [f32; 3], [f32; 2])> for Vertex {
fn from((position, normal, uv): ([f32; 3], [f32; 3], [f32; 2])) -> Self {
2019-12-10 07:12:50 +00:00
Vertex {
2020-01-11 10:11:27 +00:00
position: [
2020-01-14 01:35:30 +00:00
position[0],
position[1],
position[2],
2020-01-11 10:11:27 +00:00
1.0,
],
2020-01-14 01:35:30 +00:00
normal: [normal[0], normal[1], normal[2], 0.0],
uv: uv
2019-12-10 07:12:50 +00:00
}
}
}
2020-01-14 01:35:30 +00:00
impl From<([i8; 4], [i8; 4], [i8; 2])> for Vertex {
fn from((position, normal, uv): ([i8; 4], [i8; 4], [i8; 2])) -> 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,
],
2020-01-14 01:35:30 +00:00
uv: [
uv[0] as f32,
uv[1] as f32,
],
2019-12-10 07:12:50 +00:00
}
}
}
2020-01-14 01:35:30 +00:00
impl From<([i8; 3], [i8; 3], [i8; 2])> for Vertex {
fn from((position, normal, uv): ([i8; 3], [i8; 3], [i8; 2])) -> 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-14 01:35:30 +00:00
uv: [uv[0] as f32, uv[1] as f32],
2019-12-10 07:12:50 +00:00
}
}
2020-01-11 10:11:27 +00:00
}