get colliders from scene mesh with name "Collider", hide it in render

This commit is contained in:
yuni 2024-04-16 04:04:22 +02:00
parent efd85e1433
commit 23a85807a5
4 changed files with 31 additions and 11 deletions

Binary file not shown.

View file

@ -482,12 +482,17 @@ fn spawn_entities(
actor.insert(AngularVelocity(state.angular_momentum));
actor.insert(ColliderDensity(state.density));
if state.collider_is_mesh {
actor.insert(AsyncSceneCollider::new(None)
.with_shape_for_name("Collider", ComputedCollider::TriMesh)
.with_layers_for_name("Collider", CollisionLayers::ALL)
//.with_density_for_name("Collider", state.density)
);
actor.insert(MassPropertiesBundle::new_computed(
&Collider::sphere(0.5 * state.model_scale as f64), state.density));
actor.insert(AsyncSceneCollider::new(Some(
ComputedCollider::TriMesh
//actor.insert(AsyncSceneCollider::new(Some(
//ComputedCollider::TriMesh
//ComputedCollider::ConvexDecomposition(VHACDParameters::default())
)));
//)));
}
else {
actor.insert(state.collider.clone());

View file

@ -14,10 +14,11 @@ actor 0 593051 0 suit
player yes
id player
scale 2
density 200
collider mesh
oxygen 0.008
health 0.3
angularmomentum 0 0 0
collider capsule 1 0.5
thrust 1.2 1 1 400 1.5
rotationy 0.65
engine monopropellant
@ -188,7 +189,7 @@ actor -3300 10 0 pizzeria
armodel suit_ar_chefhat
alive yes
scale 2
collider capsule 1 0.5
collider mesh
thrust 1.2 1 1 10 1.5
wants maxrotation 0
wants maxvelocity 0
@ -203,7 +204,7 @@ actor 60 -15 -40 suit
chatid Icarus
alive yes
scale 2
collider capsule 1 0.5
collider mesh
angularmomentum 0.4 0.2 0.1
rotationy 0.6
rotationx 1
@ -219,7 +220,7 @@ actor -300 0 40 suit
chatid Drifter
oxygen 0.08
scale 2
collider capsule 1 0.5
collider mesh
actor 100 -18000 2000 "orb_busstop"
relativeto player

View file

@ -4,7 +4,7 @@ use bevy::render::render_resource::{AsBindGroup, ShaderRef};
use bevy::math::{DVec3, I64Vec3};
use bevy::scene::{InstanceId, SceneInstance};
use bevy_xpbd_3d::prelude::*;
use bevy_xpbd_3d::plugins::sync::SyncConfig;
use bevy_xpbd_3d::plugins::sync;
use std::collections::HashMap;
use std::f32::consts::PI;
use fastrand;
@ -23,7 +23,7 @@ const ASSET_ASTEROID1: &str = "models/asteroid.glb#Scene0";
const ASSET_ASTEROID2: &str = "models/asteroid2.glb#Scene0";
pub fn asset_name_to_path(name: &str) -> &'static str {
match name {
"suit" => "models/suit.glb#Scene0",
"suit" => "models/suit_with_collider.glb#Scene0",
"suit_ar_chefhat" => "models/suit_ar_chefhat.glb#Scene0",
"asteroid1" => ASSET_ASTEROID1,
"asteroid2" => ASSET_ASTEROID2,
@ -48,6 +48,7 @@ impl Plugin for WorldPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, setup);
app.add_systems(Update, handle_cheats);
app.add_systems(PreUpdate, hide_colliders); // gotta do this better
app.add_systems(PostUpdate, handle_despawn);
app.add_systems(Update, spawn_despawn_asteroids);
app.add_plugins(PhysicsPlugins::default());
@ -62,12 +63,14 @@ impl Plugin for WorldPlugin {
if CENTER_WORLD_ON_PLAYER {
// Disable bevy_xpbd's position->transform sync function
app.insert_resource(SyncConfig {
app.insert_resource(sync::SyncConfig {
position_to_transform: true,
transform_to_position: false,
});
// Add own position->transform sync function
app.add_systems(PostUpdate, position_to_transform.after(bevy_xpbd_3d::plugins::sync::position_to_transform).in_set(bevy_xpbd_3d::plugins::sync::SyncSet::PositionToTransform));
app.add_systems(PostUpdate, position_to_transform
.after(sync::position_to_transform)
.in_set(sync::SyncSet::PositionToTransform));
}
}
}
@ -466,6 +469,17 @@ fn handle_cheats(
}
}
pub fn hide_colliders(
mut q_mesh: Query<(&mut Visibility, &Name), With<Handle<Mesh>>>,
) {
for (mut visibility, name) in &mut q_mesh {
if name.as_str() == "Collider" {
*visibility = Visibility::Hidden;
}
}
}
// A variant of bevy_xpbd_3d::plugins::position_to_transform that adjusts
// the rendering position to center entities at the player camera.
// This avoids rendering glitches when very far away from the origin.