From dbf512bb0c94d72b3c7dfa9030f115fb53265f6d Mon Sep 17 00:00:00 2001 From: rewin Date: Thu, 14 Mar 2024 23:15:30 +0300 Subject: [PATCH] first step to 0.13 --- studio/src/anim/mod.rs | 5 +-- studio/src/bvh/mod.rs | 10 +++--- studio/src/camera_controller.rs | 4 +-- studio/src/debug.rs | 41 ++++++++++++------------- studio/src/headless.rs | 8 +++-- studio/src/hierarchy.rs | 3 +- studio/src/input.rs | 26 ++++++++-------- studio/src/interaction/gizmos/camera.rs | 5 ++- studio/src/interaction/gizmos/mod.rs | 10 +++--- studio/src/mixamo.rs | 2 +- studio/src/scene.rs | 28 ++++++++++++++--- studio/src/screenshot.rs | 8 ++--- studio/src/skybox.rs | 10 ++++-- studio/src/ui/blocking.rs | 8 ++--- studio/src/ui/fps.rs | 10 +++--- studio/src/ui/inspector.rs | 8 ++--- 16 files changed, 100 insertions(+), 86 deletions(-) diff --git a/studio/src/anim/mod.rs b/studio/src/anim/mod.rs index ce98564..e9b87be 100644 --- a/studio/src/anim/mod.rs +++ b/studio/src/anim/mod.rs @@ -1,8 +1,5 @@ use bevy::{ - math::Affine3A, - prelude::*, - render::{mesh::skinning::SkinnedMesh, view::NoFrustumCulling}, - utils::{EntityHashMap, EntityHashSet}, + ecs::entity::{EntityHashMap, EntityHashSet}, math::Affine3A, prelude::*, render::{mesh::skinning::SkinnedMesh, view::NoFrustumCulling} }; use space_editor::space_prefab::editor_registry::EditorRegistryExt; diff --git a/studio/src/bvh/mod.rs b/studio/src/bvh/mod.rs index fc50fe1..888dc02 100644 --- a/studio/src/bvh/mod.rs +++ b/studio/src/bvh/mod.rs @@ -1,6 +1,6 @@ use bevy::{ ecs::{ - query::{ReadOnlyWorldQuery, WorldQuery}, + query::{QueryData, QueryFilter, WorldQuery}, system::Command, }, prelude::*, @@ -30,7 +30,7 @@ impl Plugin for BvhPlugin { // module's `SceneState`) to manage the order/frequency at // which these systems run instead of just running them all // every frame - .add_systems(Update, spawn_test_bvh.run_if(resource_exists::())) + .add_systems(Update, spawn_test_bvh.run_if(resource_exists::)) .add_systems( PostUpdate, (compute_inverse_bindposes, apply_deferred, animate_bvh) @@ -143,7 +143,7 @@ pub fn animate_bvh( } } -fn lerp_frames( +fn lerp_frames( joint_query: &mut Query, current_joint: Entity, bvh: &studio_bvh::Bvh, @@ -226,8 +226,8 @@ pub struct BvhAnimCompleteEvent; #[derive(Debug, Component, Reflect)] pub struct BvhJoint(usize); -#[derive(Debug, WorldQuery)] -#[world_query(mutable)] +#[derive(Debug, QueryData)] +#[query_data(mutable)] pub struct JointQuery { pub name: &'static Name, pub joint: &'static BvhJoint, diff --git a/studio/src/camera_controller.rs b/studio/src/camera_controller.rs index 66d4ae4..67d4d74 100644 --- a/studio/src/camera_controller.rs +++ b/studio/src/camera_controller.rs @@ -309,8 +309,8 @@ fn do_pan( }; // Pan along local XY plane, with the distance scaled by the radius - let up = xform.up(); - let left = xform.left(); + let up = xform.up().xyz(); + let left = xform.left().xyz(); let delta = (pan.y * up + pan.x * left) * controller.radius; // Update camera translation and focus point diff --git a/studio/src/debug.rs b/studio/src/debug.rs index 117a1bd..9223d6d 100644 --- a/studio/src/debug.rs +++ b/studio/src/debug.rs @@ -4,12 +4,7 @@ use bevy::{prelude::*, window::PrimaryWindow}; use bevy_inspector_egui::{bevy_egui::EguiPlugin, DefaultInspectorConfigPlugin}; use bevy_mod_picking::debug::DebugPickingMode; use space_editor::{ - prelude::EditorCameraMarker, - space_editor_ui::{ - bottom_menu::BottomMenuPlugin, tools::gizmo::GizmoToolPlugin, EditorDefaultCameraPlugin, - EditorGizmoConfigPlugin, EditorPickingPlugin, EditorPluginGroup, EditorUiCore, - ShowEditorUi, - }, + prelude::*, space_editor_ui::{tools::gizmo::GizmoToolPlugin, EditorGizmoConfigPlugin, EditorPluginGroup} }; use crate::{ @@ -32,13 +27,16 @@ pub struct DebugPlugin; impl Plugin for DebugPlugin { fn build(&self, app: &mut App) { app.insert_resource(DebugMode(false)) - .insert_resource(State::new(DebugPickingMode::Disabled)) - .insert_resource(GizmoConfig { - enabled: true, - depth_bias: -0.1, - line_perspective: false, - line_width: 2., - ..default() + .insert_resource(DebugPickingMode::Disabled) + .add_systems(Startup, |mut config_store: ResMut| { + let (config, _) = config_store.config_mut::(); + *config = GizmoConfig { + enabled: true, + depth_bias: -0.1, + line_perspective: false, + line_width: 2., + ..default() + }; }) .add_systems( Update, @@ -46,7 +44,7 @@ impl Plugin for DebugPlugin { toggle_debug_mode, update_debug_picking_mode .run_if(is_editor) - .run_if(resource_changed::()), + .run_if(resource_changed::), update_gizmo_line_thickness, (draw_world_axes, draw_debug_points, draw_skeletal_joints) .after(CameraMotionSystem) @@ -70,15 +68,13 @@ impl Plugin for DebugPlugin { .disable::() .disable::() .disable::() - .set(space_editor::prelude::SelectedPlugin { - show_selected_wireframe: false, - }), + .disable::(), ); app.add_systems(Update, sync_editor_camera); app.add_systems( Update, - update_editor_ui_mode.run_if(resource_changed::()), + update_editor_ui_mode.run_if(resource_changed::), ); } } @@ -104,12 +100,12 @@ fn update_editor_ui_mode( fn update_debug_picking_mode( r_debug: Res, - mut s_debug_picking: ResMut>, + mut s_debug_picking: ResMut, ) { - s_debug_picking.set(match **r_debug { + *s_debug_picking = match **r_debug { true => DebugPickingMode::Normal, false => DebugPickingMode::Disabled, - }); + }; } pub fn is_debug_mode(r_debug: Res) -> bool { @@ -117,10 +113,11 @@ pub fn is_debug_mode(r_debug: Res) -> bool { } fn update_gizmo_line_thickness( - mut config: ResMut, + mut config_store: ResMut, q_window: Query<&Window, (Changed, With)>, ) { if let Ok(scale_factor) = q_window.get_single().map(|win| win.scale_factor() as f32) { + let (config, _) = config_store.config_mut::(); config.line_width = 2. * scale_factor; } } diff --git a/studio/src/headless.rs b/studio/src/headless.rs index 0130553..f71a638 100644 --- a/studio/src/headless.rs +++ b/studio/src/headless.rs @@ -1,8 +1,7 @@ use std::time::Duration; use bevy::{ - app::{AppExit, ScheduleRunnerPlugin}, - prelude::*, + app::{AppExit, ScheduleRunnerPlugin}, core_pipeline::Skybox, prelude::* }; use space_editor::prelude::{EditorEvent, EditorPrefabPath}; use wgpu::Extent3d; @@ -74,7 +73,10 @@ pub fn start_headless( app.add_systems( Startup, move |mut cmd: Commands, mut ew: EventWriter| { - cmd.insert_resource(SkyboxId(skybox.clone())); + cmd.insert_resource(Skybox { + image : skybox.clone(), + brightness: 1.0 + }); ew.send(EditorEvent::Load(EditorPrefabPath::File(scene.clone()))) }, ); diff --git a/studio/src/hierarchy.rs b/studio/src/hierarchy.rs index 0131ce6..01a5235 100644 --- a/studio/src/hierarchy.rs +++ b/studio/src/hierarchy.rs @@ -1,6 +1,5 @@ use bevy::{ - prelude::*, - utils::{EntityHashMap, EntityHashSet}, + ecs::entity::{EntityHashMap, EntityHashSet}, prelude::* }; /// Find the parent entity of `target`. Returns `None` if `target` has no diff --git a/studio/src/input.rs b/studio/src/input.rs index 8e415de..72b800f 100644 --- a/studio/src/input.rs +++ b/studio/src/input.rs @@ -90,7 +90,7 @@ impl From for Action { // TODO: Make the bindings of raw device inputs to InputActions configurable -fn translate_selection_events(keyboard: Res>, mut input: EventWriter) { +fn translate_selection_events(keyboard: Res>, mut input: EventWriter) { if keyboard.just_pressed(KeyCode::Escape) { input.send(InputAction(Lifecycle::Start, Selection::Clear.into())); } else if keyboard.just_released(KeyCode::Escape) { @@ -110,7 +110,7 @@ fn translate_selection_events(keyboard: Res>, mut input: EventWri } } -fn translate_debug_toggle(keyboard: Res>, mut input: EventWriter) { +fn translate_debug_toggle(keyboard: Res>, mut input: EventWriter) { if keyboard.pressed(KeyCode::ControlLeft) || keyboard.pressed(KeyCode::ControlRight) { if keyboard.just_pressed(KeyCode::Grave) { input.send(InputAction(Lifecycle::Start, Action::ToggleDebug)); @@ -122,8 +122,8 @@ fn translate_debug_toggle(keyboard: Res>, mut input: EventWriter< fn translate_dcc_camera_events( mouse_motion: Res, - mouse_buttons: Res>, - keyboard: Res>, + mouse_buttons: Res>, + keyboard: Res>, mut input: EventWriter, ) { let delta = mouse_motion.get(); @@ -227,12 +227,12 @@ fn translate_dcc_camera_events( fn translate_fps_camera_events( mut mouse_wheel: EventReader, - keyboard: Res>, + keyboard: Res>, mut input: EventWriter, ) { // Camera Translation (FPS-like) use KeyCode::*; - let wasd_keys = [W, A, S, D, E, Q]; + let wasd_keys = [KeyCode::W, KeyCode::A, KeyCode::S, KeyCode::D, KeyCode::E, KeyCode::Q]; let wasd_keys_set = wasd_keys.into_iter().collect::>(); // A little unfortunate that `get_pressed()` doesn't just return a reference @@ -247,12 +247,12 @@ fn translate_fps_camera_events( let mut mvmt = Vec3::ZERO; #[rustfmt::skip] { - if wasd_keys_pressed.contains(&W) { mvmt.z -= 1.; } - if wasd_keys_pressed.contains(&A) { mvmt.x -= 1.; } - if wasd_keys_pressed.contains(&S) { mvmt.z += 1.; } - if wasd_keys_pressed.contains(&D) { mvmt.x += 1.; } - if wasd_keys_pressed.contains(&E) { mvmt.y += 1.; } - if wasd_keys_pressed.contains(&Q) { mvmt.y -= 1.; } + if wasd_keys_pressed.contains(&KeyCode::W) { mvmt.z -= 1.; } + if wasd_keys_pressed.contains(&KeyCode::A) { mvmt.x -= 1.; } + if wasd_keys_pressed.contains(&KeyCode::S) { mvmt.z += 1.; } + if wasd_keys_pressed.contains(&KeyCode::D) { mvmt.x += 1.; } + if wasd_keys_pressed.contains(&KeyCode::E) { mvmt.y += 1.; } + if wasd_keys_pressed.contains(&KeyCode::Q) { mvmt.y -= 1.; } }; let mvmt = mvmt.normalize_or_zero(); @@ -333,7 +333,7 @@ fn read_mouse_delta( } // TODO: Make it configurable -fn send_undo_event(mut events: EventWriter, keyboard: Res>) { +fn send_undo_event(mut events: EventWriter, keyboard: Res>) { if keyboard.pressed(KeyCode::ControlLeft) && keyboard.just_pressed(KeyCode::Z) && !keyboard.pressed(KeyCode::ShiftLeft) diff --git a/studio/src/interaction/gizmos/camera.rs b/studio/src/interaction/gizmos/camera.rs index 4b6fde6..2683141 100644 --- a/studio/src/interaction/gizmos/camera.rs +++ b/studio/src/interaction/gizmos/camera.rs @@ -1,9 +1,9 @@ use bevy::{ - core_pipeline::{clear_color::ClearColorConfig, fxaa::Fxaa}, + core_pipeline::fxaa::Fxaa, prelude::*, render::view::RenderLayers, }; -use space_editor::space_editor_ui::NotShowCamera; +use space_editor::space_editor_ui::camera_plugin::NotShowCamera; use crate::MainCamera; @@ -24,7 +24,6 @@ pub(super) fn spawn_gizmo_camera( GizmoCamera, Camera3dBundle { camera_3d: Camera3d { - clear_color: ClearColorConfig::None, ..default() }, camera: Camera { diff --git a/studio/src/interaction/gizmos/mod.rs b/studio/src/interaction/gizmos/mod.rs index 929721d..0ee538c 100644 --- a/studio/src/interaction/gizmos/mod.rs +++ b/studio/src/interaction/gizmos/mod.rs @@ -46,8 +46,8 @@ impl Plugin for GizmoPlugin { app.add_systems( PreUpdate, spawn_gizmo_camera.run_if( - any_with_component::() - .and_then(not(any_with_component::())), + any_with_component:: + .and_then(not(any_with_component::)), ), ); app.add_systems( @@ -55,11 +55,11 @@ impl Plugin for GizmoPlugin { ( despawn_existing_gizmo.run_if( resource_changed_or_removed::() - .or_else(resource_changed::()), + .or_else(resource_changed::), ), spawn_gizmo.after(despawn_existing_gizmo).run_if( - resource_exists::() - .and_then(not(any_with_component::())), + resource_exists:: + .and_then(not(any_with_component::)), ), (update_target_global_trasform, sync_gizmo_transform) .chain() diff --git a/studio/src/mixamo.rs b/studio/src/mixamo.rs index 4534d7f..e47009c 100644 --- a/studio/src/mixamo.rs +++ b/studio/src/mixamo.rs @@ -12,7 +12,7 @@ impl Plugin for MixamoPlugin { Update, ( import_mixamo_scene, - tick_mixamo_import.run_if(resource_exists::()), + tick_mixamo_import.run_if(resource_exists::), tick_scene_spawning.run_if(in_state(MixamoState::Spawning)), start_mixamo_anim.run_if(in_state(MixamoState::Processing)), ), diff --git a/studio/src/scene.rs b/studio/src/scene.rs index ebd3c9c..c6140e9 100644 --- a/studio/src/scene.rs +++ b/studio/src/scene.rs @@ -3,7 +3,7 @@ use bevy::{ core_pipeline::{ bloom::{BloomCompositeMode, BloomPrefilterSettings, BloomSettings}, fxaa::Fxaa, - tonemapping::Tonemapping, + tonemapping::Tonemapping, Skybox, }, gltf::Gltf, math::vec2, @@ -43,7 +43,7 @@ impl Plugin for ScenePlugin { app.insert_resource(ClearColor(Color::hsl(0.0, 0.0, 0.25))) .insert_resource(Msaa::Off) - .add_state::() + .init_state::() .add_event::() .add_event::() .add_event::() @@ -72,6 +72,9 @@ impl Plugin for ScenePlugin { app.add_systems(Update, tag_scene_elements); + app.init_resource::(); + app.add_systems(Update, attach_skybox); + //Auto loading screen //Register handles on which we will look to show loading screen app.init_resource::(); @@ -95,13 +98,30 @@ impl Plugin for ScenePlugin { wasm::dispatch_object_load_request, wasm::notify_state_changes .map(bevy::utils::error) - .run_if(resource_changed::>()), + .run_if(resource_changed::>), wasm::notify_loading_queue_changes.map(bevy::utils::error), ), ); } } +#[derive(Resource, Default)] +pub struct SkyboxHolder(pub Option); + +fn attach_skybox( + mut cmd: Commands, + mut skybox_holder: ResMut, + mut q_camera: Query, Without)> +) { + let Some(skybox) = skybox_holder.0.as_ref() else { + return; + }; + + for entity in q_camera.iter_mut() { + cmd.entity(entity).insert(skybox.clone()); + } +} + fn minimal_scene_setup(mut cmd: Commands) { cmd.spawn(( Name::new("Directional Light"), @@ -436,7 +456,7 @@ fn frame_scene_in_view( // Project each corner onto the camera plane let v = p - plane_origin; - let proj = p - v.project_onto_normalized(plane_normal); + let proj = p - v.project_onto_normalized(plane_normal.xyz()); cmd.spawn(DebugPoint { point: proj, diff --git a/studio/src/screenshot.rs b/studio/src/screenshot.rs index 849db65..3b730e4 100644 --- a/studio/src/screenshot.rs +++ b/studio/src/screenshot.rs @@ -51,15 +51,15 @@ impl Plugin for ScreenShotPlugin { ) //Render Graph Additions .add_render_graph_node::>( - core_3d::graph::NAME, + core_3d::graph::Core3d, ScreenCaptureNode::NAME, ) .add_render_graph_edges( - core_3d::graph::NAME, + core_3d::graph::Core3d, &[ - core_3d::graph::node::TONEMAPPING, + core_3d::graph::Node3d::Tonemapping, ScreenCaptureNode::NAME, - core_3d::graph::node::END_MAIN_PASS_POST_PROCESSING, + core_3d::graph::Node3d::EndMainPassPostProcessing, ], ); } diff --git a/studio/src/skybox.rs b/studio/src/skybox.rs index 55aa0b6..d98213e 100644 --- a/studio/src/skybox.rs +++ b/studio/src/skybox.rs @@ -16,9 +16,9 @@ impl Plugin for SkyboxPlugin { app.add_systems( Update, ( - load_skybox.run_if(resource_exists_and_changed::()), + load_skybox.run_if(resource_exists_and_changed::), spawn_skybox - .run_if(resource_exists::()) + .run_if(resource_exists::) .run_if(skybox_assets_loaded), ), ); @@ -98,10 +98,14 @@ fn spawn_skybox( // Add components to the scene camera cmd.entity(q_camera.single()).insert(( - Skybox(skybox_assets.cubemap.clone()), + Skybox { + image : skybox_assets.cubemap.clone(), + brightness: 1.0 + }, EnvironmentMapLight { diffuse_map: skybox_assets.env_diffuse.clone(), specular_map: skybox_assets.env_specular.clone(), + intensity: 1.0, }, )); diff --git a/studio/src/ui/blocking.rs b/studio/src/ui/blocking.rs index b32a766..846cded 100644 --- a/studio/src/ui/blocking.rs +++ b/studio/src/ui/blocking.rs @@ -38,22 +38,22 @@ fn read_command_system(mut commands: Commands, mut change_event: EventWriter { new_entity - .insert(MeshPrimitivePrefab::Cube(1.0)) + .insert(MeshPrimitive3dPrefab::Cube(1.0)) .insert(Name::new("Cube")); } BlockingCommand::Sphere => { new_entity - .insert(MeshPrimitivePrefab::Sphere(SpherePrefab { r: 1.0 })) + .insert(MeshPrimitive3dPrefab::Sphere(SpherePrefab { r: 1.0 })) .insert(Name::new("Sphere")); } BlockingCommand::Torus => { new_entity - .insert(MeshPrimitivePrefab::Torus(TorusPrefab::default())) + .insert(MeshPrimitive3dPrefab::Torus(TorusPrefab::default())) .insert(Name::new("Torus")); } BlockingCommand::Cylinder => { new_entity - .insert(MeshPrimitivePrefab::Cylinder(CylinderPrefab::default())) + .insert(MeshPrimitive3dPrefab::Cylinder(CylinderPrefab::default())) .insert(Name::new("Cylinder")); } }; diff --git a/studio/src/ui/fps.rs b/studio/src/ui/fps.rs index 4c6799d..76e2ff1 100644 --- a/studio/src/ui/fps.rs +++ b/studio/src/ui/fps.rs @@ -1,6 +1,5 @@ use bevy::{ - diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}, - prelude::*, + a11y::accesskit::TextAlign, diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}, prelude::* }; use crate::debug::DebugMode; @@ -14,7 +13,7 @@ impl Plugin for FpsCounterPlugin { .add_systems(Update, update) .add_systems( Update, - update_visibility.run_if(resource_exists_and_changed::()), + update_visibility.run_if(resource_exists_and_changed::), ); } } @@ -31,11 +30,12 @@ fn layout(mut cmd: Commands) { ..default() }, ) - .with_text_alignment(TextAlignment::Right) + .with_text_justify(JustifyText::Right) .with_style(Style { position_type: PositionType::Absolute, right: Val::Px(16.), bottom: Val::Px(16.), + ..default() }); @@ -53,7 +53,7 @@ fn update( diag: Res, mut counter: Query<&mut Text, With>, ) { - if let Some(fps_diag) = diag.get(FrameTimeDiagnosticsPlugin::FPS) { + if let Some(fps_diag) = diag.get(&FrameTimeDiagnosticsPlugin::FPS) { let fps = if let Some(fps_smoothed) = fps_diag.smoothed() { fps_smoothed } else { diff --git a/studio/src/ui/inspector.rs b/studio/src/ui/inspector.rs index 851a4bf..be29778 100644 --- a/studio/src/ui/inspector.rs +++ b/studio/src/ui/inspector.rs @@ -10,11 +10,7 @@ use bevy::{ use serde::{Deserialize, Serialize}; use serde_json::*; use space_editor::{ - space_editor_ui::{ - editor_tab::{EditorTab, EditorTabName}, - EditorUiAppExt, - }, - space_prefab::component::MeshPrimitivePrefab, + space_editor_ui::{editor_tab::{EditorTab, EditorTabName}, ui_plugin::EditorUiAppExt}, space_prefab::component::MeshPrimitive3dPrefab, }; use wasm_bindgen::prelude::*; @@ -60,7 +56,7 @@ impl Plugin for InspectorPlugin { app.register_inspect::(); app.register_inspect::(); - app.register_inspect::(); + app.register_inspect::(); //register standart material {