wip
This commit is contained in:
parent
957f62f9ea
commit
91f11f20d0
29
src/bsp.rs
29
src/bsp.rs
@ -1,10 +1,10 @@
|
||||
use strafesnet_common::{model,integer};
|
||||
use strafesnet_common::{model,integer,gameplay_attributes};
|
||||
|
||||
const VALVE_SCALE:f32=1.0/16.0;
|
||||
fn valve_transform(v:[f32;3])->integer::Planar64Vec3{
|
||||
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<model::IndexedModelInstances,vbsp::BspError>{
|
||||
pub fn generate_indexed_models<R:std::io::Read+std::io::Seek>(input:&mut R)->Result<model::MeshInstances,vbsp::BspError>{
|
||||
let mut s=Vec::new();
|
||||
|
||||
match input.read_to_end(&mut s){
|
||||
@ -32,7 +32,7 @@ pub fn generate_indexed_models<R:std::io::Read+std::io::Seek>(input:&mut R)->Res
|
||||
let mut spam_normal=Vec::new();
|
||||
let mut spam_vertices=Vec::new();
|
||||
let groups=world_model.faces()
|
||||
.filter(|face| face.is_visible())//TODO: look at this
|
||||
.filter(|face|face.is_visible())//TODO: look at this
|
||||
.map(|face|{
|
||||
let face_texture=face.texture();
|
||||
let face_texture_data=face_texture.texture_data();
|
||||
@ -54,10 +54,11 @@ pub fn generate_indexed_models<R:std::io::Read+std::io::Seek>(input:&mut R)->Res
|
||||
let normal=face.normal();
|
||||
let normal_idx=spam_normal.len() as u32;
|
||||
spam_normal.push(valve_transform(<[f32;3]>::from(normal)));
|
||||
let mut vertices:Vec<u32>=face.vertex_indexes().map(|vertex_index|{
|
||||
let pos=glam::Vec3A::from_array(vertices[vertex_index as usize]);
|
||||
let mut indices:Vec<u32>=face.vertex_positions().map(|vertex_position|{
|
||||
let vertex_xyz=<[f32;3]>::from(vertex_position);
|
||||
let pos=glam::Vec3A::from_array(vertex_xyz);
|
||||
let pos_idx=spam_pos.len();
|
||||
spam_pos.push(valve_transform(vertices[vertex_index as usize]));
|
||||
spam_pos.push(valve_transform(vertex_xyz));
|
||||
|
||||
//calculate texture coordinates
|
||||
let tex=(glam::vec2(pos.dot(texture_u),pos.dot(texture_v))+texture_offset)/texture_size;
|
||||
@ -73,21 +74,19 @@ pub fn generate_indexed_models<R:std::io::Read+std::io::Seek>(input:&mut R)->Res
|
||||
});
|
||||
i
|
||||
}).collect();
|
||||
vertices.reverse();
|
||||
model::IndexedGroup{
|
||||
indices.reverse();
|
||||
texture:Some(texture_id),
|
||||
polys:vec![model::IndexedPolygon{vertices}],
|
||||
}
|
||||
model::IndexedGroup::PolygonList(vec![model::IndexedPolygon{indices}])
|
||||
}).collect();
|
||||
model::IndexedModel{
|
||||
model::Mesh{
|
||||
unique_pos:spam_pos,
|
||||
unique_tex:spam_tex,
|
||||
unique_normal:spam_normal,
|
||||
unique_color:vec![glam::Vec4::ONE],
|
||||
unique_vertices:spam_vertices,
|
||||
groups,
|
||||
instances:vec![model::ModelInstance{
|
||||
attributes:model::CollisionAttributes::Decoration,
|
||||
instances:vec![model::Model{
|
||||
attributes:gameplay_attributes::CollisionAttributes::Decoration,
|
||||
transform:integer::Planar64Affine3::new(
|
||||
integer::Planar64Mat3::default(),
|
||||
valve_transform(<[f32;3]>::from(world_model.origin))
|
||||
@ -146,7 +145,7 @@ pub fn generate_indexed_models<R:std::io::Read+std::io::Seek>(input:&mut R)->Res
|
||||
|
||||
let model_id=prop_models.len();
|
||||
model_map.insert(model_name,model_id);
|
||||
prop_models.push(model::IndexedModel{
|
||||
prop_models.push(model::Mesh{
|
||||
unique_pos:spam_pos,
|
||||
unique_normal:spam_normal,
|
||||
unique_tex:spam_tex,
|
||||
@ -222,7 +221,7 @@ pub fn generate_indexed_models<R:std::io::Read+std::io::Seek>(input:&mut R)->Res
|
||||
//actually add the prop models
|
||||
prop_models.append(&mut models);
|
||||
|
||||
Ok(model::IndexedModelInstances{
|
||||
Ok(model::MeshInstances{
|
||||
textures:name_from_texture_id,
|
||||
models:prop_models,
|
||||
spawn_point,
|
||||
|
Loading…
Reference in New Issue
Block a user