use rin_math::{vec2, Vec2, vec3, Vec3, zero};
use color::{Rgba,ToRgba, rgba};
#[cfg(feature="meshopt")]
use meshopt;
#[cfg(any(feature="gl", feature="gles", feature="webgl"))]
use glin::VertexFormat;
#[cfg(feature="serialize")]
use serde_derive::{Serialize, Deserialize};
pub trait Vertex{
type Position;
fn position(&self) -> &Self::Position;
fn position_mut(&mut self) -> &mut Self::Position;
}
pub trait Normal{
type Normal;
fn normal(&self) -> &Self::Normal;
fn normal_mut(&mut self) -> &mut Self::Normal;
}
#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex2D{
pub position: Vec2,
}
pub fn vertex2d(position: Vec2) -> Vertex2D{
Vertex2D{position: position}
}
impl Default for Vertex2D{
fn default() -> Vertex2D{
vertex2d(vec2!(0.))
}
}
impl Vertex for Vertex2D{
type Position = Vec2;
fn position(&self) -> &Vec2 {
&self.position
}
fn position_mut(&mut self) -> &mut Vec2{
&mut self.position
}
}
#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex3D{
pub position: Vec3,
}
pub fn vertex3d(position: Vec3) -> Vertex3D{
Vertex3D{position: position}
}
impl Default for Vertex3D{
fn default() -> Vertex3D{
vertex3d(vec3!(0.))
}
}
impl Vertex for Vertex3D{
type Position = Vec3;
fn position(&self) -> &Vec3 {
&self.position
}
fn position_mut(&mut self) -> &mut Vec3{
&mut self.position
}
}
#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex2DTex{
pub position: Vec2,
pub texcoord: Vec2
}
pub fn vertex2dtex(position: Vec2, texcoord: Vec2) -> Vertex2DTex{
Vertex2DTex{position: position, texcoord: texcoord}
}
impl Default for Vertex2DTex{
fn default() -> Vertex2DTex{
vertex2dtex(vec2!(0.), vec2!(0.))
}
}
impl Vertex for Vertex2DTex{
type Position = Vec2;
fn position(&self) -> &Vec2 {
&self.position
}
fn position_mut(&mut self) -> &mut Vec2{
&mut self.position
}
}
#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex2DTex3D{
pub position: Vec2,
pub texcoord: Vec3
}
pub fn vertex2dtex3d(position: Vec2, texcoord: Vec3) -> Vertex2DTex3D{
Vertex2DTex3D{position: position, texcoord: texcoord}
}
impl Default for Vertex2DTex3D{
fn default() -> Vertex2DTex3D{
vertex2dtex3d(vec2!(0.), vec3!(0.))
}
}
impl Vertex for Vertex2DTex3D{
type Position = Vec2;
fn position(&self) -> &Vec2 {
&self.position
}
fn position_mut(&mut self) -> &mut Vec2{
&mut self.position
}
}
#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex2DColor{
pub position: Vec2,
pub color: Rgba<f32>,
}
pub fn vertex2dcolor<C: ToRgba>(position: Vec2, color: &C) -> Vertex2DColor{
Vertex2DColor{position: position, color: color.to_rgba().to_standard()}
}
impl Default for Vertex2DColor{
fn default() -> Vertex2DColor{
vertex2dcolor(vec2!(0.), &rgba!(1.,1.,1.,1.))
}
}
impl Vertex for Vertex2DColor{
type Position = Vec2;
fn position(&self) -> &Vec2 {
&self.position
}
fn position_mut(&mut self) -> &mut Vec2{
&mut self.position
}
}
#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex2DTexColor{
pub position: Vec2,
pub texcoord: Vec2,
pub color: Rgba<f32>
}
pub fn vertex2dtexcolor<C: ToRgba>(position: Vec2, texcoord: Vec2, color: &C) -> Vertex2DTexColor{
Vertex2DTexColor{position: position, texcoord: texcoord, color: color.to_rgba().to_standard()}
}
impl Default for Vertex2DTexColor{
fn default() -> Vertex2DTexColor{
vertex2dtexcolor(vec2!(0.), vec2!(0.), &rgba!(1.,1.,1.,1.))
}
}
impl Vertex for Vertex2DTexColor{
type Position = Vec2;
fn position(&self) -> &Vec2 {
&self.position
}
fn position_mut(&mut self) -> &mut Vec2{
&mut self.position
}
}
#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex3DTex{
pub position: Vec3,
pub texcoord: Vec2,
pub pad: Vec3
}
pub fn vertex3dtex(position: Vec3, texcoord: Vec2) -> Vertex3DTex{
Vertex3DTex{position: position, texcoord: texcoord, pad: zero()}
}
impl Default for Vertex3DTex{
fn default() -> Vertex3DTex{
vertex3dtex(vec3!(0.), vec2!(0.))
}
}
impl Vertex for Vertex3DTex{
type Position = Vec3;
fn position(&self) -> &Vec3 {
&self.position
}
fn position_mut(&mut self) -> &mut Vec3{
&mut self.position
}
}
#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex3DColor{
pub position: Vec3,
pub color: Rgba<f32>,
pub pad: f32
}
pub fn vertex3dcolor<C: ToRgba>(position: Vec3, color: &C) -> Vertex3DColor{
Vertex3DColor{position: position, color: color.to_rgba().to_standard(), pad: 0f32}
}
impl Default for Vertex3DColor{
fn default() -> Vertex3DColor{
vertex3dcolor(vec3!(0.), &rgba!(1.,1.,1.,1.))
}
}
impl Vertex for Vertex3DColor{
type Position = Vec3;
fn position(&self) -> &Vec3 {
&self.position
}
fn position_mut(&mut self) -> &mut Vec3{
&mut self.position
}
}
#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex3DTexNormal{
pub position: Vec3,
pub texcoord: Vec2,
pub normal: Vec3
}
pub fn vertex3dtexnormal(position: Vec3, texcoord: Vec2, normal: Vec3) -> Vertex3DTexNormal{
Vertex3DTexNormal{position: position, texcoord: texcoord, normal: normal}
}
impl Default for Vertex3DTexNormal{
fn default() -> Vertex3DTexNormal{
vertex3dtexnormal(vec3!(0.), vec2!(0.), vec3!(0.))
}
}
impl Vertex for Vertex3DTexNormal{
type Position = Vec3;
fn position(&self) -> &Vec3 {
&self.position
}
fn position_mut(&mut self) -> &mut Vec3{
&mut self.position
}
}
impl Normal for Vertex3DTexNormal{
type Normal = Vec3;
fn normal(&self) -> &Vec3 {
&self.normal
}
fn normal_mut(&mut self) -> &mut Vec3{
&mut self.normal
}
}
#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex3DNormal{
pub position: Vec3,
pub normal: Vec3,
}
pub fn vertex3dnormal(position: Vec3, normal: Vec3) -> Vertex3DNormal{
Vertex3DNormal{position: position, normal: normal }
}
impl Default for Vertex3DNormal{
fn default() -> Vertex3DNormal{
vertex3dnormal(vec3!(0.), vec3!(0.))
}
}
impl Vertex for Vertex3DNormal{
type Position = Vec3;
fn position(&self) -> &Vec3 {
&self.position
}
fn position_mut(&mut self) -> &mut Vec3{
&mut self.position
}
}
impl Normal for Vertex3DNormal{
type Normal = Vec3;
fn normal(&self) -> &Vec3 {
&self.normal
}
fn normal_mut(&mut self) -> &mut Vec3{
&mut self.normal
}
}
#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex3DColorNormal{
pub position: Vec3,
pub pad0: f32,
pub color: Rgba<f32>,
pub normal: Vec3,
pub pad1: f32,
}
pub fn vertex3dcolornormal<C: ToRgba>(position: Vec3, color: &C, normal: Vec3) -> Vertex3DColorNormal{
Vertex3DColorNormal{
position: position,
pad0: 0.,
color: color.to_rgba().to_standard(),
normal: normal,
pad1: 0.,
}
}
impl Default for Vertex3DColorNormal{
fn default() -> Vertex3DColorNormal{
vertex3dcolornormal(vec3!(0.), &rgba!(1.,1.,1.,1.), vec3!(0.))
}
}
impl Vertex for Vertex3DColorNormal{
type Position = Vec3;
fn position(&self) -> &Vec3 {
&self.position
}
fn position_mut(&mut self) -> &mut Vec3{
&mut self.position
}
}
impl Normal for Vertex3DColorNormal{
type Normal = Vec3;
fn normal(&self) -> &Vec3 {
&self.normal
}
fn normal_mut(&mut self) -> &mut Vec3{
&mut self.normal
}
}
#[derive(Clone,Copy,Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), repr(C))]
#[cfg_attr(any(feature="gl", feature="gles", feature="webgl"), derive(VertexFormat))]
pub struct Vertex3DTexColor{
pub position: Vec3,
pub texcoord: Vec2,
pub color: Rgba<f32>,
pub pad: [f32;7]
}
pub fn vertex3dtexcolor<C: ToRgba>(position: Vec3, texcoord: Vec2, color: &C) -> Vertex3DTexColor{
Vertex3DTexColor{position: position, color: color.to_rgba().to_standard(), texcoord: texcoord, pad: [0f32;7]}
}
impl Default for Vertex3DTexColor{
fn default() -> Vertex3DTexColor{
vertex3dtexcolor(vec3!(0.), vec2!(0.), &rgba!(1.,1.,1.,1.))
}
}
impl Vertex for Vertex3DTexColor{
type Position = Vec3;
fn position(&self) -> &Vec3 {
&self.position
}
fn position_mut(&mut self) -> &mut Vec3{
&mut self.position
}
}
#[cfg(feature="meshopt")]
impl meshopt::DecodePosition for Vertex3D{
fn decode_position(&self) -> [f32;3]{
[self.position.x, self.position.y, self.position.z]
}
}
#[cfg(feature="meshopt")]
impl meshopt::DecodePosition for Vertex3DNormal{
fn decode_position(&self) -> [f32;3]{
[self.position.x, self.position.y, self.position.z]
}
}
#[cfg(feature="meshopt")]
impl meshopt::DecodePosition for Vertex3DTexNormal{
fn decode_position(&self) -> [f32;3]{
[self.position.x, self.position.y, self.position.z]
}
}
#[cfg(feature="meshopt")]
impl meshopt::DecodePosition for Vertex3DColor{
fn decode_position(&self) -> [f32;3]{
[self.position.x, self.position.y, self.position.z]
}
}
#[cfg(feature="meshopt")]
impl meshopt::DecodePosition for Vertex3DColorNormal{
fn decode_position(&self) -> [f32;3]{
[self.position.x, self.position.y, self.position.z]
}
}
#[cfg(feature="meshopt")]
impl meshopt::DecodePosition for Vertex3DTexColor{
fn decode_position(&self) -> [f32;3]{
[self.position.x, self.position.y, self.position.z]
}
}