implement better scene collider removal

This commit is contained in:
yuni 2024-04-16 16:40:20 +02:00
parent b186b37ffb
commit babbef279a
3 changed files with 26 additions and 12 deletions

View file

@ -14,10 +14,13 @@ impl Plugin for CommandsPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems(Startup, load_defs); app.add_systems(Startup, load_defs);
app.add_systems(Update, spawn_entities); app.add_systems(Update, spawn_entities);
app.add_systems(PreUpdate, hide_colliders
.run_if(any_with_component::<NeedsSceneColliderRemoved>));
app.add_event::<SpawnEvent>(); app.add_event::<SpawnEvent>();
} }
} }
#[derive(Component)] pub struct NeedsSceneColliderRemoved;
#[derive(Event)] pub struct SpawnEvent(ParserState); #[derive(Event)] pub struct SpawnEvent(ParserState);
#[derive(PartialEq, Clone)] #[derive(PartialEq, Clone)]
enum DefClass { enum DefClass {
@ -508,6 +511,7 @@ fn spawn_entities(
.with_layers_for_name("Collider", CollisionLayers::ALL) .with_layers_for_name("Collider", CollisionLayers::ALL)
//.with_density_for_name("Collider", state.density) //.with_density_for_name("Collider", state.density)
); );
actor.insert(NeedsSceneColliderRemoved);
} }
else { else {
actor.insert(state.collider.clone()); actor.insert(state.collider.clone());
@ -611,3 +615,14 @@ fn spawn_entities(
} }
} }
} }
pub fn hide_colliders(
mut q_mesh: Query<(&mut Visibility, &Name), (With<NeedsSceneColliderRemoved>, With<Handle<Mesh>>)>,
) {
for (mut visibility, name) in &mut q_mesh {
if name.as_str() == "Collider" {
*visibility = Visibility::Hidden;
}
}
}

View file

@ -19,3 +19,14 @@ impl Material for JupitersRing {
} }
} }
#[derive(Asset, TypePath, AsBindGroup, Debug, Clone)]
pub struct AsteroidSurface {
}
impl Material for AsteroidSurface {
fn fragment_shader() -> ShaderRef {
"shaders/material_asteroid.wgsl".into()
}
}

View file

@ -48,7 +48,6 @@ impl Plugin for WorldPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems(Startup, setup); app.add_systems(Startup, setup);
app.add_systems(Update, handle_cheats); 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(PostUpdate, handle_despawn);
app.add_systems(Update, spawn_despawn_asteroids); app.add_systems(Update, spawn_despawn_asteroids);
app.add_plugins(PhysicsPlugins::default()); app.add_plugins(PhysicsPlugins::default());
@ -451,17 +450,6 @@ 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 // A variant of bevy_xpbd_3d::plugins::position_to_transform that adjusts
// the rendering position to center entities at the player camera. // the rendering position to center entities at the player camera.
// This avoids rendering glitches when very far away from the origin. // This avoids rendering glitches when very far away from the origin.