Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix-处理server headless模式下的物理碰撞体的问题 #86

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading