2024-01-30 06:38:43 +00:00
|
|
|
use crate::integer::{Planar64Vec3,Planar64Affine3};
|
|
|
|
use crate::gameplay_attributes;
|
|
|
|
|
|
|
|
pub type TextureCoordinate=glam::Vec2;
|
|
|
|
pub type Color4=glam::Vec4;
|
2024-02-01 08:04:07 +00:00
|
|
|
#[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);
|
2024-01-30 06:38:43 +00:00
|
|
|
#[derive(Clone,Hash,PartialEq,Eq)]
|
|
|
|
pub struct IndexedVertex{
|
2024-02-01 08:04:07 +00:00
|
|
|
pub pos:PositionId,
|
|
|
|
pub tex:TextureCoordinateId,
|
|
|
|
pub normal:NormalId,
|
|
|
|
pub color:ColorId,
|
2024-01-30 06:38:43 +00:00
|
|
|
}
|
2024-02-01 08:04:07 +00:00
|
|
|
#[derive(Clone,Copy,Hash,id::Id,PartialEq,Eq)]
|
2024-01-30 06:38:43 +00:00
|
|
|
pub struct VertexId(u32);
|
2024-02-01 08:04:07 +00:00
|
|
|
pub type IndexedVertexList=Vec<VertexId>;
|
|
|
|
pub trait PolygonIter{
|
|
|
|
fn polys(&self)->impl Iterator<Item=&[VertexId]>;
|
2024-01-30 06:38:43 +00:00
|
|
|
}
|
2024-02-01 08:04:07 +00:00
|
|
|
pub trait MapVertexId{
|
|
|
|
fn map_vertex_id<F:Fn(VertexId)->VertexId>(self,f:F)->Self;
|
|
|
|
}
|
|
|
|
pub struct PolygonList(Vec<IndexedVertexList>);
|
|
|
|
impl PolygonList{
|
|
|
|
pub const fn new(list:Vec<IndexedVertexList>)->Self{
|
|
|
|
Self(list)
|
|
|
|
}
|
|
|
|
pub fn extend<T:IntoIterator<Item=IndexedVertexList>>(&mut self,iter:T){
|
|
|
|
self.0.extend(iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl PolygonIter for PolygonList{
|
|
|
|
fn polys(&self)->impl Iterator<Item=&[VertexId]>{
|
|
|
|
self.0.iter().map(|poly|poly.as_slice())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl MapVertexId for PolygonList{
|
|
|
|
fn map_vertex_id<F:Fn(VertexId)->VertexId>(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<Item=&[VertexId]>{
|
|
|
|
// 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<Item=&[VertexId]>{
|
|
|
|
match self{
|
|
|
|
PolygonGroup::PolygonList(list)=>list.polys(),
|
|
|
|
//PolygonGroup::TriangleStrip(strip)=>strip.polys(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl MapVertexId for PolygonGroup{
|
|
|
|
fn map_vertex_id<F:Fn(VertexId)->VertexId>(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<TextureId>,
|
|
|
|
}
|
|
|
|
impl RenderConfig{
|
|
|
|
pub const fn texture(texture:TextureId)->Self{
|
|
|
|
Self{
|
|
|
|
texture:Some(texture),
|
|
|
|
}
|
|
|
|
}
|
2024-01-30 06:38:43 +00:00
|
|
|
}
|
|
|
|
pub struct IndexedGraphicsGroup{
|
|
|
|
//Render pattern material/texture/shader/flat color
|
2024-02-01 08:04:07 +00:00
|
|
|
pub render:RenderConfigId,
|
|
|
|
pub groups:Vec<PolygonGroupId>,
|
2024-01-30 06:38:43 +00:00
|
|
|
}
|
2024-02-01 08:04:07 +00:00
|
|
|
#[derive(Default)]
|
2024-01-30 06:38:43 +00:00
|
|
|
pub struct IndexedPhysicsGroup{
|
|
|
|
//the polygons in this group are guaranteed to make a closed convex shape
|
2024-02-01 08:04:07 +00:00
|
|
|
pub groups:Vec<PolygonGroupId>,
|
2024-01-30 06:38:43 +00:00
|
|
|
}
|
|
|
|
//This is a superset of PhysicsModel and GraphicsModel
|
2024-02-01 08:04:07 +00:00
|
|
|
#[derive(Clone,Copy,Hash,id::Id,Eq,PartialEq)]
|
|
|
|
pub struct MeshId(u32);
|
|
|
|
pub struct Mesh{
|
2024-01-30 06:38:43 +00:00
|
|
|
pub unique_pos:Vec<Planar64Vec3>,//Unit32Vec3
|
|
|
|
pub unique_normal:Vec<Planar64Vec3>,//Unit32Vec3
|
|
|
|
pub unique_tex:Vec<TextureCoordinate>,
|
|
|
|
pub unique_color:Vec<Color4>,
|
|
|
|
pub unique_vertices:Vec<IndexedVertex>,
|
2024-02-01 08:04:07 +00:00
|
|
|
//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<PolygonGroup>,
|
2024-01-30 06:38:43 +00:00
|
|
|
//graphics indexed (by texture)
|
2024-02-01 08:04:07 +00:00
|
|
|
pub graphics_groups:Vec<IndexedGraphicsGroup>,
|
2024-01-30 06:38:43 +00:00
|
|
|
//physics indexed (by convexity)
|
2024-02-01 08:04:07 +00:00
|
|
|
pub physics_groups:Vec<IndexedPhysicsGroup>,
|
2024-01-30 06:38:43 +00:00
|
|
|
}
|
|
|
|
|
2024-02-01 08:04:07 +00:00
|
|
|
#[derive(Debug,Clone,Copy,Hash,id::Id,Eq,PartialEq)]
|
2024-01-30 06:38:43 +00:00
|
|
|
pub struct ModelId(u32);
|
|
|
|
pub struct Model{
|
2024-02-01 08:04:07 +00:00
|
|
|
pub mesh:MeshId,
|
2024-01-30 06:38:43 +00:00
|
|
|
pub attributes:gameplay_attributes::CollisionAttributesId,
|
|
|
|
pub color:Color4,//transparency is in here
|
|
|
|
pub transform:Planar64Affine3,
|
|
|
|
}
|