This commit is contained in:
Danny McGee
2023-11-16 14:47:17 -05:00
parent d7e3503861
commit 1715eb17df
123 changed files with 130289 additions and 31 deletions
+9 -4
View File
@@ -10,7 +10,7 @@ use crate::{
};
#[derive(Resource, Deref, DerefMut)]
pub struct DebugMode(bool);
pub struct DebugMode(pub bool);
pub struct DebugPlugin;
impl Plugin for DebugPlugin {
@@ -28,8 +28,11 @@ impl Plugin for DebugPlugin {
.add_systems(
Update,
(
toggle_debug_mode,
update_debug_picking_mode.run_if(resource_changed::<DebugMode>()),
toggle_debug_mode.run_if(resource_exists::<Events<InputAction>>()),
update_debug_picking_mode.run_if(
resource_exists::<NextState<DebugPickingMode>>()
.and_then(resource_changed::<DebugMode>()),
),
update_gizmo_line_thickness,
draw_world_axes
.after(CameraMotionSystem)
@@ -72,7 +75,9 @@ fn update_gizmo_line_thickness(
}
fn draw_world_axes(mut gizmos: Gizmos, q: Query<&CameraController>) {
let &CameraController { focus, radius, .. } = q.single();
let Ok(&CameraController { focus, radius, .. }) = q.get_single() else {
return;
};
let mut draw_axis = |direction: Vec3, color: Color| {
let end = focus + direction * radius / 15.;
+1 -1
View File
@@ -23,7 +23,7 @@ pub(super) struct TransformGizmoBundle {
scale: NaturalScale,
}
#[derive(Component, Deref, Reflect)]
#[derive(Component, Deref)]
pub(super) struct NaturalScale(pub Vec3);
#[derive(Component, Deref)]
-1
View File
@@ -35,7 +35,6 @@ pub struct GizmoPlugin;
impl Plugin for GizmoPlugin {
fn build(&self, app: &mut App) {
app.register_type::<NaturalScale>();
app.add_event::<RebuildGizmo>();
app.add_systems(Startup, init_resources);
app.add_systems(
+10 -8
View File
@@ -3,22 +3,22 @@
use bevy::prelude::*;
use bevy_mod_picking::DefaultPickingPlugins;
use camera_controller::CameraControllerPlugin;
use debug::DebugPlugin;
pub use debug::{DebugMode, DebugPlugin};
use input::StudioInputPlugin;
use interaction::InteractionPlugin;
use math::InterpolationPlugin;
use scene::ScenePlugin;
use skybox::SkyboxPlugin;
pub use math::InterpolationPlugin;
pub use scene::{ActiveScene, Inspectable, ScenePlugin};
pub use skybox::{SkyboxId, SkyboxPlugin};
use ui::UiLayerPlugin;
use viewport::ViewportSize;
use wasm_bindgen::prelude::*;
mod camera_controller;
mod debug;
mod design_system;
pub mod design_system;
mod input;
mod interaction;
mod math;
pub mod math;
mod scene;
mod skybox;
mod ui;
@@ -27,8 +27,9 @@ mod viewport;
#[cfg(feature = "wasm")]
mod wasm;
#[derive(Component)]
pub(crate) struct MainCamera;
#[derive(Component, Reflect, Default)]
#[reflect(Component)]
pub struct MainCamera;
#[wasm_bindgen]
pub fn init(viewport_size: ViewportSize) {
@@ -36,6 +37,7 @@ pub fn init(viewport_size: ViewportSize) {
console_error_panic_hook::set_once();
let mut app = App::new();
app.register_type::<MainCamera>();
#[cfg(feature = "wasm")]
app.add_plugins(viewport::wasm::ViewportPlugin);
+70 -4
View File
@@ -1,6 +1,8 @@
use bevy::{
asset::LoadState,
core_pipeline::{
bloom::{BloomCompositeMode, BloomPrefilterSettings, BloomSettings},
core_3d::Camera3dDepthTextureUsage,
fxaa::Fxaa,
tonemapping::Tonemapping,
},
@@ -31,11 +33,20 @@ impl Plugin for ScenePlugin {
fn build(&self, app: &mut App) {
app.insert_resource(ClearColor(Color::hsl(0.0, 0.0, 0.25)))
.insert_resource(Msaa::Off)
.register_type::<Camera3dDepthTextureUsage>()
.register_type::<Inspectable>()
.add_plugins(MaterialPlugin::<ProceduralGridMaterial>::default())
.add_systems(Startup, initialize)
.add_systems(
Update,
mark_scene_objects.run_if(resource_exists::<NewScene>().and_then(scene_inst_ready)),
(
mark_scene_objects.run_if(
resource_exists::<NewScene>()
.and_then(scene_loaded)
.and_then(scene_inst_ready),
),
log_asset_paths,
),
)
.add_systems(PostUpdate, move_plane_with_camera.after(CameraMotionSystem));
@@ -52,6 +63,42 @@ impl Plugin for ScenePlugin {
}
}
fn log_asset_paths(
mut l_logged: Local<HashSet<Entity>>,
r_assets: Res<AssetServer>,
mut q_meshes: Query<(Entity, &Name, &Handle<Mesh>, &Handle<StandardMaterial>)>,
) {
for (ent, name, mesh, mat) in q_meshes.iter_mut() {
if l_logged.contains(&ent) {
continue;
}
let mesh_path = if mesh.is_strong() {
r_assets.get_handle_path(mesh.id())
} else {
None
};
let mat_path = if mat.is_strong() {
r_assets.get_handle_path(mat.id())
} else {
None
};
if [&mesh_path, &mat_path]
.iter()
.any(|option| option.is_some())
{
info!("[{ent:?} {name}");
info!(" mesh: {mesh_path:?}");
info!(" material: {mat_path:?}");
l_logged.insert(ent);
} else if mesh.is_strong() && mat.is_strong() {
info!("[{ent:?}] {name} | failed to determine asset paths");
l_logged.insert(ent);
}
}
}
#[derive(Component)]
struct WorldGridPlane;
@@ -65,8 +112,9 @@ struct NewScene {
#[derive(Resource, Deref, DerefMut)]
pub struct ActiveScene(pub Handle<Scene>);
#[derive(Component)]
struct Inspectable;
#[derive(Component, Reflect, Default)]
#[reflect(Component)]
pub struct Inspectable;
fn initialize(
mut cmd: Commands,
@@ -154,12 +202,30 @@ fn initialize(
});
}
fn scene_loaded(r_assets: Res<AssetServer>, r_new_scene: Res<NewScene>) -> bool {
let Some(gltf) = &r_new_scene.gltf else {
return false;
};
if r_assets.get_load_state(gltf) == LoadState::Loaded {
info!("SCENE LOADED");
return true;
}
false
}
fn scene_inst_ready(r_scene_mgr: Res<SceneSpawner>, q_scene_inst: Query<&SceneInstance>) -> bool {
let Ok(scene_inst) = q_scene_inst.get_single() else {
return false;
};
r_scene_mgr.instance_is_ready(**scene_inst)
if r_scene_mgr.instance_is_ready(**scene_inst) {
info!("SCENE SPAWNED");
return true;
}
false
}
fn mark_scene_objects(
+15 -11
View File
@@ -13,22 +13,26 @@ pub struct SkyboxPlugin;
impl Plugin for SkyboxPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
(
load_skybox.run_if(resource_exists_and_changed::<SkyboxId>()),
spawn_skybox
.run_if(resource_exists::<SkyboxAssets>())
.run_if(skybox_assets_loaded),
),
);
app.register_type::<SkyboxId>()
.register_type::<SkyboxAssets>()
.add_systems(
Update,
(
load_skybox.run_if(resource_exists_and_changed::<SkyboxId>()),
spawn_skybox
.run_if(resource_exists::<SkyboxAssets>())
.run_if(skybox_assets_loaded),
),
);
}
}
#[derive(Resource, Deref, DerefMut)]
#[derive(Resource, Deref, DerefMut, Reflect, Default)]
#[reflect(Resource)]
pub struct SkyboxId(pub String);
#[derive(Resource)]
#[derive(Resource, Reflect, Default)]
#[reflect(Resource)]
struct SkyboxAssets {
cubemap: Handle<Image>,
env_diffuse: Handle<Image>,