This commit is contained in:
Quaternions 2024-01-10 19:51:51 -08:00
parent 5e819faf70
commit 0abf467eca

View File

@ -1,6 +1,6 @@
const VALVE_SCALE:f32=1.0/16.0; const VALVE_SCALE:f32=1.0/16.0;
fn valve_transform(v:[f32;3])->crate::integer::Planar64Vec3{ fn valve_transform(v:[f32;3])->crate::integer::Planar64Vec3{
crate::integer::Planar64Vec3::try_from([v[0]*VALVE_SCALE,v[2]*VALVE_SCALE,v[1]*VALVE_SCALE]).unwrap() crate::integer::Planar64Vec3::try_from([v[0]*VALVE_SCALE,v[2]*VALVE_SCALE,-v[1]*VALVE_SCALE]).unwrap()
} }
pub fn generate_indexed_models<R:std::io::Read+std::io::Seek>(input:&mut R)->Result<crate::model::IndexedModelInstances,vbsp::BspError>{ pub fn generate_indexed_models<R:std::io::Read+std::io::Seek>(input:&mut R)->Result<crate::model::IndexedModelInstances,vbsp::BspError>{
let mut s=Vec::new(); let mut s=Vec::new();
@ -52,10 +52,7 @@ pub fn generate_indexed_models<R:std::io::Read+std::io::Seek>(input:&mut R)->Res
let normal=face.normal(); let normal=face.normal();
let normal_idx=spam_normal.len() as u32; let normal_idx=spam_normal.len() as u32;
spam_normal.push(valve_transform(<[f32;3]>::from(normal))); spam_normal.push(valve_transform(<[f32;3]>::from(normal)));
let mut vertices:Vec<u32>=face.vertex_indexes().map(|vertex_index|{
crate::model::IndexedGroup{
texture:Some(texture_id),
polys:vec![crate::model::IndexedPolygon{vertices:face.vertex_indexes().map(|vertex_index|{
let pos=glam::Vec3A::from_array(vertices[vertex_index as usize]); let pos=glam::Vec3A::from_array(vertices[vertex_index as usize]);
let pos_idx=spam_pos.len(); let pos_idx=spam_pos.len();
spam_pos.push(valve_transform(vertices[vertex_index as usize])); spam_pos.push(valve_transform(vertices[vertex_index as usize]));
@ -73,7 +70,11 @@ pub fn generate_indexed_models<R:std::io::Read+std::io::Seek>(input:&mut R)->Res
color: 0, color: 0,
}); });
i i
}).collect()}], }).collect();
vertices.reverse();
crate::model::IndexedGroup{
texture:Some(texture_id),
polys:vec![crate::model::IndexedPolygon{vertices}],
} }
}).collect(); }).collect();
crate::model::IndexedModel{ crate::model::IndexedModel{
@ -174,8 +175,7 @@ pub fn generate_indexed_models<R:std::io::Read+std::io::Seek>(input:&mut R)->Res
//looking at the code, it would seem that the strips are pre-deindexed into triangle lists when calling this function //looking at the code, it would seem that the strips are pre-deindexed into triangle lists when calling this function
mesh.vertex_strip_indices().map(|strip|{ mesh.vertex_strip_indices().map(|strip|{
strip.collect::<Vec<usize>>().chunks(3).map(|tri|{ strip.collect::<Vec<usize>>().chunks(3).map(|tri|{
//tris are ccw, probably because of the quaternion crate::model::IndexedPolygon{vertices:vec![tri[0] as u32,tri[1] as u32,tri[2] as u32]}
crate::model::IndexedPolygon{vertices:vec![tri[1] as u32,tri[0] as u32,tri[2] as u32]}
}).collect::<Vec<crate::model::IndexedPolygon>>() }).collect::<Vec<crate::model::IndexedPolygon>>()
}).flatten().collect() }).flatten().collect()
}, },