enabling shadows on imported lights

main
Elijah Voigt 2 years ago
parent 7549f230bf
commit 748875f765

BIN
assets/models/inspect.blend (Stored with Git LFS)

Binary file not shown.

BIN
assets/models/inspect.blend1 (Stored with Git LFS)

Binary file not shown.

BIN
assets/models/inspect.glb (Stored with Git LFS)

Binary file not shown.

@ -4,9 +4,6 @@
// //
// BUGS: // BUGS:
// * Camera order ambiguity // * 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 // * Load new GLTF -> Despawn all level entities
// //
// TODO: // TODO:
@ -32,12 +29,11 @@
// * Monologues (done) // * Monologues (done)
use bevy::{ use bevy::{
asset::{Asset, Assets}, asset::{Asset, AssetLoader, Assets, ChangeWatcher, LoadContext, LoadedAsset},
asset::{AssetLoader, LoadContext, LoadedAsset},
audio::PlaybackMode, audio::PlaybackMode,
gltf::Gltf, gltf::Gltf,
prelude::*, prelude::*,
utils::BoxedFuture, utils::{BoxedFuture, Duration},
}; };
use monologue_trees::{debug::*, ui}; use monologue_trees::{debug::*, ui};
@ -57,13 +53,18 @@ const WELCOME_MESSAGES: &'static [&'static str] = &[
fn main() { fn main() {
App::new() App::new()
.add_plugins(( .add_plugins((
DefaultPlugins.set(WindowPlugin { DefaultPlugins
.set(WindowPlugin {
primary_window: Some(Window { primary_window: Some(Window {
title: "Monologue Trees Editor".into(), title: "Monologue Trees Editor".into(),
resolution: (640., 480.).into(), resolution: (640., 480.).into(),
..default() ..default()
}), }),
..default() ..default()
})
.set(AssetPlugin {
watch_for_changes: ChangeWatcher::with_delay(Duration::from_millis(200)),
..default()
}), }),
DebugInfoPlugin, DebugInfoPlugin,
ui::GameUiPlugin, ui::GameUiPlugin,
@ -110,6 +111,14 @@ fn main() {
sync_monologue_font, sync_monologue_font,
), ),
) )
.add_systems(
Update,
(
point_light_force_shadows,
spot_light_force_shadows,
directional_light_force_shadows,
),
)
.run(); .run();
} }
@ -233,16 +242,16 @@ fn initialize_ui(mut commands: Commands) {
parent, parent,
ui::Select::Single, ui::Select::Single,
)); ));
content_containers.push(spawn_tab_container::<AnimationWidget>(
"Animation",
parent,
ui::Select::Multi,
));
content_containers.push(spawn_tab_container::<CameraWidget>( content_containers.push(spawn_tab_container::<CameraWidget>(
"Camera", "Camera",
parent, parent,
ui::Select::Single, ui::Select::Single,
)); ));
content_containers.push(spawn_tab_container::<AnimationWidget>(
"Animation",
parent,
ui::Select::Multi,
));
}); });
// Container for tabs that open/close containers // Container for tabs that open/close containers
@ -812,24 +821,28 @@ mod animations {
// When a scene is de-selected, remove any outdated animation options // When a scene is de-selected, remove any outdated animation options
pub fn remove_animations_ui( pub fn remove_animations_ui(
mut events: RemovedComponents<Handle<Scene>>, mut removed_players: RemovedComponents<Handle<Scene>>,
names: Query<&Name>,
current: Query<(Entity, &ui::TargetAsset<AnimationClip>)>, current: Query<(Entity, &ui::TargetAsset<AnimationClip>)>,
clips: Res<Assets<AnimationClip>>, clips: Res<Assets<AnimationClip>>,
targets: Query<(&AnimationPlayer, &Name)>, targets: Query<(&AnimationPlayer, &Name)>,
mut commands: Commands, mut commands: Commands,
) { ) {
// For each removed scene // For each removed scene
events.iter().for_each(|_| { removed_players.iter().for_each(|_| {
info!("Scene despawn!");
// Iterate over the current animation buttons // Iterate over the current animation buttons
current.iter().for_each(|(_, ui::TargetAsset { handle })| { current
info!("Checking button for {:?}", handle); .iter()
// If the button points to a valid clip .filter(|(_, ui::TargetAsset { handle })| {
if let Some(clip) = clips.get(handle) { // Check if this clip is compatible with any remaining entities
// Check if any active animation players are compatible with this clip // NOTE: We are checking this is *not* compatible with any entities
let compatible = targets.iter().any(|(_, name)| clip.compatible_with(name)); clips
// If not, despawn the button .get(handle)
if !compatible { .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( destroy_asset_button(
&current, &current,
&mut commands, &mut commands,
@ -837,8 +850,6 @@ mod animations {
handle: handle.clone(), 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<SpotLight>>) {
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<DirectionalLight>>,
) {
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<PointLight>>) {
point_lights.iter_mut().for_each(|mut light| {
light.shadows_enabled = true;
})
}
}

Loading…
Cancel
Save