generate topological indices

This commit is contained in:
2025-12-16 10:13:54 -08:00
parent 596f15e781
commit d400ff66f8
5 changed files with 51 additions and 17 deletions

1
Cargo.lock generated
View File

@@ -3892,6 +3892,7 @@ dependencies = [
"glam",
"id",
"strafesnet_common",
"strafesnet_physics",
"strafesnet_session",
"strafesnet_settings",
"wgpu",

View File

@@ -9,6 +9,7 @@ ddsfile = "0.5.1"
glam = "0.30.0"
id = { version = "0.1.0", registry = "strafesnet" }
strafesnet_common = { path = "../../lib/common", registry = "strafesnet" }
strafesnet_physics = { path = "../physics", registry = "strafesnet" }
strafesnet_session = { path = "../session", registry = "strafesnet" }
strafesnet_settings = { path = "../settings", registry = "strafesnet" }
wgpu = "28.0.0"

View File

@@ -36,8 +36,13 @@ struct GraphicsModel{
instance_count:u32,
}
struct DebugGraphicsSubmesh{
edges:Vec<Indices>,
faces:Vec<Indices>,
}
struct DebugGraphicsMesh{
indices:Indices,
verts:Indices,
submeshes:Vec<DebugGraphicsSubmesh>,
vertex_buf:wgpu::Buffer,
}
struct DebugGraphicsModel{
@@ -195,30 +200,42 @@ impl GraphicsState{
usage:wgpu::BufferUsages::VERTEX,
});
let mut indices=Vec::new();
for physics_group in &mesh.physics_groups{
for polygon_group_id in &physics_group.groups{
for poly in mesh.polygon_groups[polygon_group_id.get() as usize].polys(){
macro_rules! indices{
($indices:expr)=>{
if (u32::MAX as usize)<vertices.len(){
panic!("Model has too many vertices!");
}else if (u16::MAX as usize)<vertices.len(){
Indices::new(device,&$indices.into_iter().map(|vertex_idx|vertex_idx as u32).collect(),wgpu::IndexFormat::Uint32)
}else{
Indices::new(device,&$indices.into_iter().map(|vertex_idx|vertex_idx as u16).collect(),wgpu::IndexFormat::Uint16)
}
};
}
let submeshes=if let Ok(physics_mesh)=strafesnet_physics::model::PhysicsMesh::try_from(mesh){
physics_mesh.submesh_views().into_iter().map(|submesh_view|DebugGraphicsSubmesh{
edges:submesh_view.edge_vert_ids_iter().map(|edge_verts|indices!(edge_verts)).collect(),
faces:submesh_view.face_vert_ids_iter().map(|face_verts|{
// triangulate
let mut poly_vertices=poly.into_iter().copied();
let mut indices=Vec::new();
let mut poly_vertices=face_verts.into_iter();
if let (Some(a),Some(mut b))=(poly_vertices.next(),poly_vertices.next()){
for c in poly_vertices{
indices.extend([a,b,c]);
b=c;
}
}
}
}
}
indices!(indices)
}).collect(),
}).collect()
}else{
//idc
Vec::new()
};
DebugGraphicsMesh{
indices:if (u32::MAX as usize)<vertices.len(){
panic!("Model has too many vertices!")
}else if (u16::MAX as usize)<vertices.len(){
Indices::new(device,&indices.into_iter().map(|vertex_idx|vertex_idx.get() as u32).collect(),wgpu::IndexFormat::Uint32)
}else{
Indices::new(device,&indices.into_iter().map(|vertex_idx|vertex_idx.get() as u16).collect(),wgpu::IndexFormat::Uint16)
},
verts:indices!(0..vertices.len()),
submeshes,
vertex_buf,
}
}).collect();

View File

@@ -1,6 +1,6 @@
mod body;
mod face_crawler;
mod model;
pub mod model;
mod push_solve;
mod minimum_difference;

View File

@@ -445,6 +445,21 @@ pub struct PhysicsMeshView<'a>{
data:&'a PhysicsMeshData,
topology:&'a PhysicsMeshTopology,
}
impl PhysicsMeshView<'_>{
pub fn edge_vert_ids_iter(&self)->impl Iterator<Item=[u32;2]>+'_{
self.topology.edge_topology.iter().map(|edge|{
edge.verts.map(|vert_id|self.topology.verts[vert_id.get() as usize].get())
})
}
pub fn face_vert_ids_iter(&self)->impl Iterator<Item=impl Iterator<Item=u32>>+'_{
self.topology.face_topology.iter().map(|face|{
face.edges.iter().map(|edge_id|{
let vert_id=self.topology.edge_topology[edge_id.as_undirected().get() as usize].verts[edge_id.parity() as usize];
self.topology.verts[vert_id.get() as usize].get()
})
})
}
}
impl MeshQuery for PhysicsMeshView<'_>{
type Face=SubmeshFaceId;
type Edge=SubmeshDirectedEdgeId;