This commit is contained in:
Quaternions 2024-07-25 12:38:17 -07:00
parent 320b8726ee
commit 340ddad47e

View File

@ -1,3 +1,5 @@
use strafesnet_common::model::PolygonIter;
use super::integer::{Planar64Vec3,Planar64Affine3};
pub type TextureCoordinate=[f32;2];
@ -11,6 +13,16 @@ pub struct IndexedVertex{
pub normal:u32,
pub color:u32,
}
impl From<strafesnet_common::model::IndexedVertex> for IndexedVertex{
fn from(value:strafesnet_common::model::IndexedVertex)->Self{
Self{
pos:value.pos.get(),
tex:value.tex.get(),
normal:value.normal.get(),
color:value.color.get(),
}
}
}
#[binrw::binrw]
#[brw(little)]
@ -26,6 +38,25 @@ pub struct PolygonGroup{
#[br(count=count)]
pub polys:Vec<Polygon>,
}
impl From<strafesnet_common::model::PolygonGroup> for PolygonGroup{
fn from(value:strafesnet_common::model::PolygonGroup)->Self{
match value{
strafesnet_common::model::PolygonGroup::PolygonList(polygon_list)=>{
let polys:Vec<Polygon>=polygon_list.polys().map(|poly|{
let vertices:Vec<u32>=poly.iter().map(|vert|vert.get()).collect();
Polygon{
count:vertices.len() as u32,
vertices,
}
}).collect();
Self{
count:polys.len() as u32,
polys,
}
}
}
}
}
#[binrw::binrw]
#[brw(little)]
pub struct RenderConfig{
@ -38,6 +69,13 @@ impl Into<strafesnet_common::model::RenderConfig> for RenderConfig{
}
}
}
impl From<strafesnet_common::model::RenderConfig> for RenderConfig{
fn from(value:strafesnet_common::model::RenderConfig)->Self{
Self{
texture:value.texture.map(|texture_id|texture_id.get()),
}
}
}
#[binrw::binrw]
#[brw(little)]
pub struct IndexedGraphicsGroup{
@ -46,6 +84,15 @@ pub struct IndexedGraphicsGroup{
#[br(count=count)]
pub groups:Vec<u32>,
}
impl From<strafesnet_common::model::IndexedGraphicsGroup> for IndexedGraphicsGroup{
fn from(value:strafesnet_common::model::IndexedGraphicsGroup)->Self{
Self{
count:value.groups.len() as u32,
render:value.render.get(),
groups:value.groups.into_iter().map(|group_id|group_id.get()).collect(),
}
}
}
#[binrw::binrw]
#[brw(little)]
pub struct IndexedPhysicsGroup{
@ -53,6 +100,14 @@ pub struct IndexedPhysicsGroup{
#[br(count=count)]
pub groups:Vec<u32>,
}
impl From<strafesnet_common::model::IndexedPhysicsGroup> for IndexedPhysicsGroup{
fn from(value:strafesnet_common::model::IndexedPhysicsGroup)->Self{
Self{
count:value.groups.len() as u32,
groups:value.groups.into_iter().map(|group_id|group_id.get()).collect(),
}
}
}
#[binrw::binrw]
#[brw(little)]
@ -123,6 +178,46 @@ impl Into<strafesnet_common::model::Mesh> for Mesh{
}
}
}
impl From<strafesnet_common::model::Mesh> for Mesh{
fn from(value:strafesnet_common::model::Mesh)->Self{
Self{
header:MeshHeader{
unique_pos:value.unique_pos.len() as u32,
unique_normal:value.unique_normal.len() as u32,
unique_tex:value.unique_tex.len() as u32,
unique_color:value.unique_color.len() as u32,
unique_vertices:value.unique_vertices.len() as u32,
polygon_groups:value.polygon_groups.len() as u32,
graphics_groups:value.graphics_groups.len() as u32,
physics_groups:value.physics_groups.len() as u32,
},
unique_pos:value.unique_pos.into_iter()
.map(|pos|pos.get().to_array())
.collect(),
unique_normal:value.unique_normal.into_iter()
.map(|normal|normal.get().to_array())
.collect(),
unique_tex:value.unique_tex.into_iter()
.map(|tex|tex.to_array())
.collect(),
unique_color:value.unique_color.into_iter()
.map(|color|color.to_array())
.collect(),
unique_vertices:value.unique_vertices.into_iter()
.map(Into::into)
.collect(),
polygon_groups:value.polygon_groups.into_iter()
.map(Into::into)
.collect(),
graphics_groups:value.graphics_groups.into_iter()
.map(Into::into)
.collect(),
physics_groups:value.physics_groups.into_iter()
.map(Into::into)
.collect(),
}
}
}
#[binrw::binrw]
#[brw(little)]
@ -150,3 +245,24 @@ impl Into<strafesnet_common::model::Model> for Model{
}
}
}
impl From<strafesnet_common::model::Model> for Model{
fn from(value:strafesnet_common::model::Model)->Self{
let (
[_0,_1,_2],
[_3,_4,_5],
[_6,_7,_8],
[_9,_a,_b]
)=(
value.transform.matrix3.x_axis.get().to_array(),
value.transform.matrix3.y_axis.get().to_array(),
value.transform.matrix3.z_axis.get().to_array(),
value.transform.translation.get().to_array()
);
Self{
mesh:value.mesh.get(),
attributes:value.attributes.get(),
color:value.color.to_array(),
transform:[_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b],
}
}
}