Skip to content

Commit

Permalink
fix-处理server headless模式下的物理碰撞体的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zzhgithub committed Sep 18, 2023
1 parent 3cff7d2 commit a9dea5c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/server/sp_physics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,15 @@ fn deal_events(
) {
for event in event_reader.iter() {
if let Some(entity) = sp_physics_manager.remove(event.chunk_key, event.index) {
// println!("这里销毁了碰撞体");
commands.entity(entity).despawn();
}
}
}

// 通过mesh生成碰撞体
fn get_collider_by_mesh(mesh: &Mesh) -> Option<Collider> {
let collider_vertices: Vec<Vec3> = mesh
let mut collider_vertices: Vec<Vec3> = mesh
.attribute(Mesh::ATTRIBUTE_POSITION)
.unwrap()
.as_float3()
Expand All @@ -251,6 +252,13 @@ fn get_collider_by_mesh(mesh: &Mesh) -> Option<Collider> {
let collider_indices: Vec<[u32; 3]> = indices.chunks(3).map(|i| [i[0], i[1], i[2]]).collect();
// println!("{:?}", collider_vertices);
// println!("{:?}", collider_indices);
#[cfg(feature = "headless")]
{
collider_vertices = collider_vertices
.iter()
.map(|x| *x * Vec3::splat(1.0 / 32.0))
.collect();
}
let collider = Collider::trimesh(collider_vertices, collider_indices);
Some(collider)
}

0 comments on commit a9dea5c

Please sign in to comment.