From 748875f765acf3ae0b1ca8968d87f553ff26ae6e Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Tue, 29 Aug 2023 10:41:49 -0700 Subject: [PATCH] enabling shadows on imported lights --- assets/models/inspect.blend | 4 +- assets/models/inspect.blend1 | 4 +- assets/models/inspect.glb | 4 +- bin/editor.rs | 112 +++++++++++++++++++++++------------ 4 files changed, 80 insertions(+), 44 deletions(-) diff --git a/assets/models/inspect.blend b/assets/models/inspect.blend index f55e80f..ba897a9 100644 --- a/assets/models/inspect.blend +++ b/assets/models/inspect.blend @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:93493487e935398def827d4f945e671178b25408e1477c8b9adca177e5969080 -size 1979400 +oid sha256:7d21639a04f73a9c09af9cbe1bbc89570beb49980cb7856bc6360f31ab851387 +size 2092712 diff --git a/assets/models/inspect.blend1 b/assets/models/inspect.blend1 index c62a66f..e57a15f 100644 --- a/assets/models/inspect.blend1 +++ b/assets/models/inspect.blend1 @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:af12822c2d103ec0ebf53cf42e06a9039fc7c150374cd7370aa48a1de6d8960d -size 1979400 +oid sha256:de4ec306f2c1d4d265fd09b166446a1ab796a822f67778b5c796122b571935ed +size 2092712 diff --git a/assets/models/inspect.glb b/assets/models/inspect.glb index f3aa8ce..b96f116 100644 --- a/assets/models/inspect.glb +++ b/assets/models/inspect.glb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:549b7519ba17cd24a010d604b475f9b7b831292c4e0ffda9ad009f9d1cd9b607 -size 1136928 +oid sha256:976d82ec5c0039852a3f7e5991a60536b0c4050f7910bd55ca01e6b73fbdc8c9 +size 1244020 diff --git a/bin/editor.rs b/bin/editor.rs index f35a43b..ec94e74 100644 --- a/bin/editor.rs +++ b/bin/editor.rs @@ -4,9 +4,6 @@ // // BUGS: // * Camera order ambiguity -// * Multi-GLTF UX is bad. -// * Consider GLTF hierarchy (GLTF1 > Scene1a/Scene1b, GlTF2 > Scene2a/Scene2b, etc) -// * Easy despawn when de-selecting gltf // * Load new GLTF -> Despawn all level entities // // TODO: @@ -32,12 +29,11 @@ // * Monologues (done) use bevy::{ - asset::{Asset, Assets}, - asset::{AssetLoader, LoadContext, LoadedAsset}, + asset::{Asset, AssetLoader, Assets, ChangeWatcher, LoadContext, LoadedAsset}, audio::PlaybackMode, gltf::Gltf, prelude::*, - utils::BoxedFuture, + utils::{BoxedFuture, Duration}, }; use monologue_trees::{debug::*, ui}; @@ -57,14 +53,19 @@ const WELCOME_MESSAGES: &'static [&'static str] = &[ fn main() { App::new() .add_plugins(( - DefaultPlugins.set(WindowPlugin { - primary_window: Some(Window { - title: "Monologue Trees Editor".into(), - resolution: (640., 480.).into(), + DefaultPlugins + .set(WindowPlugin { + primary_window: Some(Window { + title: "Monologue Trees Editor".into(), + resolution: (640., 480.).into(), + ..default() + }), + ..default() + }) + .set(AssetPlugin { + watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)), ..default() }), - ..default() - }), DebugInfoPlugin, ui::GameUiPlugin, )) @@ -110,6 +111,14 @@ fn main() { sync_monologue_font, ), ) + .add_systems( + Update, + ( + point_light_force_shadows, + spot_light_force_shadows, + directional_light_force_shadows, + ), + ) .run(); } @@ -233,16 +242,16 @@ fn initialize_ui(mut commands: Commands) { parent, ui::Select::Single, )); - content_containers.push(spawn_tab_container::( - "Animation", - parent, - ui::Select::Multi, - )); content_containers.push(spawn_tab_container::( "Camera", parent, ui::Select::Single, )); + content_containers.push(spawn_tab_container::( + "Animation", + parent, + ui::Select::Multi, + )); }); // Container for tabs that open/close containers @@ -812,34 +821,36 @@ mod animations { // When a scene is de-selected, remove any outdated animation options pub fn remove_animations_ui( - mut events: RemovedComponents>, + mut removed_players: RemovedComponents>, + names: Query<&Name>, current: Query<(Entity, &ui::TargetAsset)>, clips: Res>, targets: Query<(&AnimationPlayer, &Name)>, mut commands: Commands, ) { // For each removed scene - events.iter().for_each(|_| { - info!("Scene despawn!"); + removed_players.iter().for_each(|_| { // Iterate over the current animation buttons - current.iter().for_each(|(_, ui::TargetAsset { handle })| { - info!("Checking button for {:?}", handle); - // If the button points to a valid clip - if let Some(clip) = clips.get(handle) { - // Check if any active animation players are compatible with this clip - let compatible = targets.iter().any(|(_, name)| clip.compatible_with(name)); - // If not, despawn the button - if !compatible { - destroy_asset_button( - ¤t, - &mut commands, - &ui::TargetAsset { - handle: handle.clone(), - }, - ); - } - } - }); + current + .iter() + .filter(|(_, ui::TargetAsset { handle })| { + // Check if this clip is compatible with any remaining entities + // NOTE: We are checking this is *not* compatible with any entities + clips + .get(handle) + .map(|clip| !(targets.iter().any(|(_, name)| clip.compatible_with(name)))) + .unwrap_or(true) + }) + .for_each(|(_, ui::TargetAsset { handle })| { + // Destroy the buton if it is so + destroy_asset_button( + ¤t, + &mut commands, + &ui::TargetAsset { + handle: handle.clone(), + }, + ); + }); }); } @@ -1238,3 +1249,28 @@ mod cameras { }) } } + +use lighting::*; +mod lighting { + use super::*; + + pub fn spot_light_force_shadows(mut spot_lights: Query<&mut SpotLight, Added>) { + spot_lights.iter_mut().for_each(|mut light| { + light.shadows_enabled = true; + }) + } + + pub fn directional_light_force_shadows( + mut directional_lights: Query<&mut DirectionalLight, Added>, + ) { + directional_lights.iter_mut().for_each(|mut light| { + light.shadows_enabled = true; + }) + } + + pub fn point_light_force_shadows(mut point_lights: Query<&mut PointLight, Added>) { + point_lights.iter_mut().for_each(|mut light| { + light.shadows_enabled = true; + }) + } +}