From babbef279add50a2339972e71de459c3a4b1e97f Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 16 Apr 2024 16:40:20 +0200 Subject: [PATCH] implement better scene collider removal --- src/commands.rs | 15 +++++++++++++++ src/shading.rs | 11 +++++++++++ src/world.rs | 12 ------------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index f7cfa86..f00034d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -14,10 +14,13 @@ impl Plugin for CommandsPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, load_defs); app.add_systems(Update, spawn_entities); + app.add_systems(PreUpdate, hide_colliders + .run_if(any_with_component::)); app.add_event::(); } } +#[derive(Component)] pub struct NeedsSceneColliderRemoved; #[derive(Event)] pub struct SpawnEvent(ParserState); #[derive(PartialEq, Clone)] enum DefClass { @@ -508,6 +511,7 @@ fn spawn_entities( .with_layers_for_name("Collider", CollisionLayers::ALL) //.with_density_for_name("Collider", state.density) ); + actor.insert(NeedsSceneColliderRemoved); } else { actor.insert(state.collider.clone()); @@ -611,3 +615,14 @@ fn spawn_entities( } } } + + +pub fn hide_colliders( + mut q_mesh: Query<(&mut Visibility, &Name), (With, With>)>, +) { + for (mut visibility, name) in &mut q_mesh { + if name.as_str() == "Collider" { + *visibility = Visibility::Hidden; + } + } +} diff --git a/src/shading.rs b/src/shading.rs index e1da827..85880b1 100644 --- a/src/shading.rs +++ b/src/shading.rs @@ -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() + } +} + diff --git a/src/world.rs b/src/world.rs index 096a051..ce64583 100644 --- a/src/world.rs +++ b/src/world.rs @@ -48,7 +48,6 @@ 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()); @@ -451,17 +450,6 @@ fn handle_cheats( } } - -pub fn hide_colliders( - mut q_mesh: Query<(&mut Visibility, &Name), With>>, -) { - 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.