use crate::integer::{Planar64Vec3,Planar64Affine3}; use crate::gameplay_attributes; pub type TextureCoordinate=glam::Vec2; pub type Color4=glam::Vec4; #[derive(Clone,Copy,Hash,id::Id,PartialEq,Eq)] pub struct PositionId(u32); #[derive(Clone,Copy,Hash,id::Id,PartialEq,Eq)] pub struct TextureCoordinateId(u32); #[derive(Clone,Copy,Hash,id::Id,PartialEq,Eq)] pub struct NormalId(u32); #[derive(Clone,Copy,Hash,id::Id,PartialEq,Eq)] pub struct ColorId(u32); #[derive(Clone,Hash,PartialEq,Eq)] pub struct IndexedVertex{ pub pos:PositionId, pub tex:TextureCoordinateId, pub normal:NormalId, pub color:ColorId, } #[derive(Clone,Copy,Hash,id::Id,PartialEq,Eq)] pub struct VertexId(u32); pub type IndexedVertexList=Vec; pub trait PolygonIter{ fn polys(&self)->impl Iterator; } pub trait MapVertexId{ fn map_vertex_idVertexId>(self,f:F)->Self; } pub struct PolygonList(Vec); impl PolygonList{ pub const fn new(list:Vec)->Self{ Self(list) } pub fn extend>(&mut self,iter:T){ self.0.extend(iter); } } impl PolygonIter for PolygonList{ fn polys(&self)->impl Iterator{ self.0.iter().map(|poly|poly.as_slice()) } } impl MapVertexId for PolygonList{ fn map_vertex_idVertexId>(self,f:F)->Self{ Self(self.0.into_iter().map(|ivl|ivl.into_iter().map(&f).collect()).collect()) } } // pub struct TriangleStrip(IndexedVertexList); // impl PolygonIter for TriangleStrip{ // fn polys(&self)->impl Iterator{ // self.0.vertices.windows(3).enumerate().map(|(i,s)|if i&0!=0{return s.iter().rev()}else{return s.iter()}) // } // } #[derive(Clone,Copy,Hash,id::Id,PartialEq,Eq)] pub struct PolygonGroupId(u32); pub enum PolygonGroup{ PolygonList(PolygonList), //TriangleStrip(TriangleStrip), } impl PolygonIter for PolygonGroup{ fn polys(&self)->impl Iterator{ match self{ PolygonGroup::PolygonList(list)=>list.polys(), //PolygonGroup::TriangleStrip(strip)=>strip.polys(), } } } impl MapVertexId for PolygonGroup{ fn map_vertex_idVertexId>(self,f:F)->Self{ match self{ PolygonGroup::PolygonList(polys)=>Self::PolygonList(polys.map_vertex_id(f)), } } } /// Ah yes, a group of things to render at the same time #[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)] pub struct TextureId(u32); #[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)] pub struct RenderConfigId(u32); #[derive(Default)] pub struct RenderConfig{ pub texture:Option, } impl RenderConfig{ pub const fn texture(texture:TextureId)->Self{ Self{ texture:Some(texture), } } } pub struct IndexedGraphicsGroup{ //Render pattern material/texture/shader/flat color pub render:RenderConfigId, pub groups:Vec, } #[derive(Default)] pub struct IndexedPhysicsGroup{ //the polygons in this group are guaranteed to make a closed convex shape pub groups:Vec, } //This is a superset of PhysicsModel and GraphicsModel #[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)] pub struct MeshId(u32); pub struct Mesh{ pub unique_pos:Vec,//Unit32Vec3 pub unique_normal:Vec,//Unit32Vec3 pub unique_tex:Vec, pub unique_color:Vec, pub unique_vertices:Vec, //polygon groups are constant texture AND convexity slices //note that this may need to be changed to be a list of individual faces //for submeshes to work since face ids need to be consistent across submeshes //so face == polygon_groups[face_id] pub polygon_groups:Vec, //graphics indexed (by texture) pub graphics_groups:Vec, //physics indexed (by convexity) pub physics_groups:Vec, } #[derive(Debug,Clone,Copy,Hash,id::Id,Eq,PartialEq)] pub struct ModelId(u32); pub struct Model{ pub mesh:MeshId, pub attributes:gameplay_attributes::CollisionAttributesId, pub color:Color4,//transparency is in here pub transform:Planar64Affine3, }