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
|
|
|
|
2020-03-22 01:12:30 +00:00
|
|
|
use bevy_derive::Uniforms;
|
|
|
|
|
2019-12-01 01:42:27 +00:00
|
|
|
#[repr(C)]
|
2020-03-22 01:12:30 +00:00
|
|
|
#[derive(Clone, Copy, AsBytes, FromBytes, Uniforms)]
|
2020-04-01 01:04:54 +00:00
|
|
|
#[uniform(bevy_path="crate")]
|
2019-12-01 01:42:27 +00:00
|
|
|
pub struct Vertex {
|
2020-03-22 01:12:30 +00:00
|
|
|
#[uniform(vertex)]
|
2019-12-10 07:12:50 +00:00
|
|
|
pub position: [f32; 4],
|
2020-03-22 01:12:30 +00:00
|
|
|
#[uniform(vertex)]
|
2019-12-10 07:12:50 +00:00
|
|
|
pub normal: [f32; 4],
|
2020-03-22 01:12:30 +00:00
|
|
|
#[uniform(vertex)]
|
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 {
|
2020-02-09 19:43:45 +00:00
|
|
|
position,
|
|
|
|
normal,
|
|
|
|
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-15 06:23:00 +00:00
|
|
|
position: [position[0], position[1], position[2], 1.0],
|
2020-01-14 01:35:30 +00:00
|
|
|
normal: [normal[0], normal[1], normal[2], 0.0],
|
2020-02-09 19:43:45 +00:00
|
|
|
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-15 06:23:00 +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
|
|
|
}
|