forked from StrafesNET/strafe-project
60 lines
1.1 KiB
Rust
60 lines
1.1 KiB
Rust
|
use strafesnet_common::model::MeshId;
|
||
|
|
||
|
//duplicate this code for now
|
||
|
#[derive(Clone)]
|
||
|
pub struct MdlData(Vec<u8>);
|
||
|
impl MdlData{
|
||
|
pub const fn new(value:Vec<u8>)->Self{
|
||
|
Self(value)
|
||
|
}
|
||
|
pub fn get(self)->Vec<u8>{
|
||
|
self.0
|
||
|
}
|
||
|
}
|
||
|
#[derive(Clone)]
|
||
|
pub struct VtxData(Vec<u8>);
|
||
|
impl VtxData{
|
||
|
pub const fn new(value:Vec<u8>)->Self{
|
||
|
Self(value)
|
||
|
}
|
||
|
pub fn get(self)->Vec<u8>{
|
||
|
self.0
|
||
|
}
|
||
|
}
|
||
|
#[derive(Clone)]
|
||
|
pub struct VvdData(Vec<u8>);
|
||
|
impl VvdData{
|
||
|
pub const fn new(value:Vec<u8>)->Self{
|
||
|
Self(value)
|
||
|
}
|
||
|
pub fn get(self)->Vec<u8>{
|
||
|
self.0
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[derive(Clone)]
|
||
|
pub struct ModelData{
|
||
|
pub mdl:MdlData,
|
||
|
pub vtx:VtxData,
|
||
|
pub vvd:VvdData,
|
||
|
}
|
||
|
|
||
|
//meshes is more prone to failure
|
||
|
pub struct Meshes{
|
||
|
meshes:Vec<Option<ModelData>>,
|
||
|
}
|
||
|
impl Meshes{
|
||
|
pub(crate) const fn new(meshes:Vec<Option<ModelData>>)->Self{
|
||
|
Self{
|
||
|
meshes,
|
||
|
}
|
||
|
}
|
||
|
pub fn get_texture(&self,texture_id:MeshId)->Option<&ModelData>{
|
||
|
self.meshes.get(texture_id.get() as usize)?.as_ref()
|
||
|
}
|
||
|
pub fn into_iter(self)->impl Iterator<Item=(MeshId,ModelData)>{
|
||
|
self.meshes.into_iter().enumerate().filter_map(|(mesh_id,maybe_mesh)|
|
||
|
maybe_mesh.map(|mesh|(MeshId::new(mesh_id as u32),mesh))
|
||
|
)
|
||
|
}
|
||
|
}
|