first step to 0.13

This commit is contained in:
rewin
2024-03-14 23:15:30 +03:00
parent 75dcd9b8d9
commit dbf512bb0c
16 changed files with 100 additions and 86 deletions
+1 -4
View File
@@ -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;
+5 -5
View File
@@ -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::<TestBvh>()))
.add_systems(Update, spawn_test_bvh.run_if(resource_exists::<TestBvh>))
.add_systems(
PostUpdate,
(compute_inverse_bindposes, apply_deferred, animate_bvh)
@@ -143,7 +143,7 @@ pub fn animate_bvh(
}
}
fn lerp_frames<T: ReadOnlyWorldQuery>(
fn lerp_frames<T: QueryFilter>(
joint_query: &mut Query<JointQuery, T>,
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,
+2 -2
View File
@@ -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
+19 -22
View File
@@ -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<GizmoConfigStore>| {
let (config, _) = config_store.config_mut::<DefaultGizmoConfigGroup>();
*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::<DebugMode>()),
.run_if(resource_changed::<DebugMode>),
update_gizmo_line_thickness,
(draw_world_axes, draw_debug_points, draw_skeletal_joints)
.after(CameraMotionSystem)
@@ -70,15 +68,13 @@ impl Plugin for DebugPlugin {
.disable::<BottomMenuPlugin>()
.disable::<GizmoToolPlugin>()
.disable::<EditorGizmoConfigPlugin>()
.set(space_editor::prelude::SelectedPlugin {
show_selected_wireframe: false,
}),
.disable::<space_editor::prelude::SelectedPlugin>(),
);
app.add_systems(Update, sync_editor_camera);
app.add_systems(
Update,
update_editor_ui_mode.run_if(resource_changed::<DebugMode>()),
update_editor_ui_mode.run_if(resource_changed::<DebugMode>),
);
}
}
@@ -104,12 +100,12 @@ fn update_editor_ui_mode(
fn update_debug_picking_mode(
r_debug: Res<DebugMode>,
mut s_debug_picking: ResMut<NextState<DebugPickingMode>>,
mut s_debug_picking: ResMut<DebugPickingMode>,
) {
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<DebugMode>) -> bool {
@@ -117,10 +113,11 @@ pub fn is_debug_mode(r_debug: Res<DebugMode>) -> bool {
}
fn update_gizmo_line_thickness(
mut config: ResMut<GizmoConfig>,
mut config_store: ResMut<GizmoConfigStore>,
q_window: Query<&Window, (Changed<Window>, With<PrimaryWindow>)>,
) {
if let Ok(scale_factor) = q_window.get_single().map(|win| win.scale_factor() as f32) {
let (config, _) = config_store.config_mut::<DefaultGizmoConfigGroup>();
config.line_width = 2. * scale_factor;
}
}
+5 -3
View File
@@ -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<EditorEvent>| {
cmd.insert_resource(SkyboxId(skybox.clone()));
cmd.insert_resource(Skybox {
image : skybox.clone(),
brightness: 1.0
});
ew.send(EditorEvent::Load(EditorPrefabPath::File(scene.clone())))
},
);
+1 -2
View File
@@ -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
+13 -13
View File
@@ -90,7 +90,7 @@ impl From<Selection> for Action {
// TODO: Make the bindings of raw device inputs to InputActions configurable
fn translate_selection_events(keyboard: Res<Input<KeyCode>>, mut input: EventWriter<InputAction>) {
fn translate_selection_events(keyboard: Res<ButtonInput<KeyCode>>, mut input: EventWriter<InputAction>) {
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<Input<KeyCode>>, mut input: EventWri
}
}
fn translate_debug_toggle(keyboard: Res<Input<KeyCode>>, mut input: EventWriter<InputAction>) {
fn translate_debug_toggle(keyboard: Res<ButtonInput<KeyCode>>, mut input: EventWriter<InputAction>) {
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<Input<KeyCode>>, mut input: EventWriter<
fn translate_dcc_camera_events(
mouse_motion: Res<LastFrameMouseDelta>,
mouse_buttons: Res<Input<MouseButton>>,
keyboard: Res<Input<KeyCode>>,
mouse_buttons: Res<ButtonInput<MouseButton>>,
keyboard: Res<ButtonInput<KeyCode>>,
mut input: EventWriter<InputAction>,
) {
let delta = mouse_motion.get();
@@ -227,12 +227,12 @@ fn translate_dcc_camera_events(
fn translate_fps_camera_events(
mut mouse_wheel: EventReader<MouseWheel>,
keyboard: Res<Input<KeyCode>>,
keyboard: Res<ButtonInput<KeyCode>>,
mut input: EventWriter<InputAction>,
) {
// 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::<HashSet<_>>();
// 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<UndoRedo>, keyboard: Res<Input<KeyCode>>) {
fn send_undo_event(mut events: EventWriter<UndoRedo>, keyboard: Res<ButtonInput<KeyCode>>) {
if keyboard.pressed(KeyCode::ControlLeft)
&& keyboard.just_pressed(KeyCode::Z)
&& !keyboard.pressed(KeyCode::ShiftLeft)
+2 -3
View File
@@ -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 {
+5 -5
View File
@@ -46,8 +46,8 @@ impl Plugin for GizmoPlugin {
app.add_systems(
PreUpdate,
spawn_gizmo_camera.run_if(
any_with_component::<MainCamera>()
.and_then(not(any_with_component::<GizmoCamera>())),
any_with_component::<MainCamera>
.and_then(not(any_with_component::<GizmoCamera>)),
),
);
app.add_systems(
@@ -55,11 +55,11 @@ impl Plugin for GizmoPlugin {
(
despawn_existing_gizmo.run_if(
resource_changed_or_removed::<Selection>()
.or_else(resource_changed::<TransformMode>()),
.or_else(resource_changed::<TransformMode>),
),
spawn_gizmo.after(despawn_existing_gizmo).run_if(
resource_exists::<Selection>()
.and_then(not(any_with_component::<TransformGizmo>())),
resource_exists::<Selection>
.and_then(not(any_with_component::<TransformGizmo>)),
),
(update_target_global_trasform, sync_gizmo_transform)
.chain()
+1 -1
View File
@@ -12,7 +12,7 @@ impl Plugin for MixamoPlugin {
Update,
(
import_mixamo_scene,
tick_mixamo_import.run_if(resource_exists::<MixamoImport>()),
tick_mixamo_import.run_if(resource_exists::<MixamoImport>),
tick_scene_spawning.run_if(in_state(MixamoState::Spawning)),
start_mixamo_anim.run_if(in_state(MixamoState::Processing)),
),
+24 -4
View File
@@ -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::<SceneState>()
.init_state::<SceneState>()
.add_event::<LoadLibraryObjectEvent>()
.add_event::<LoadSceneEvent>()
.add_event::<ImportSceneEvent>()
@@ -72,6 +72,9 @@ impl Plugin for ScenePlugin {
app.add_systems(Update, tag_scene_elements);
app.init_resource::<SkyboxHolder>();
app.add_systems(Update, attach_skybox);
//Auto loading screen
//Register handles on which we will look to show loading screen
app.init_resource::<LoadingQueue>();
@@ -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::<State<SceneState>>()),
.run_if(resource_changed::<State<SceneState>>),
wasm::notify_loading_queue_changes.map(bevy::utils::error),
),
);
}
}
#[derive(Resource, Default)]
pub struct SkyboxHolder(pub Option<Skybox>);
fn attach_skybox(
mut cmd: Commands,
mut skybox_holder: ResMut<SkyboxHolder>,
mut q_camera: Query<Entity, (With<Camera3d>, Without<Skybox>)>
) {
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,
+4 -4
View File
@@ -51,15 +51,15 @@ impl Plugin for ScreenShotPlugin {
)
//Render Graph Additions
.add_render_graph_node::<ViewNodeRunner<ScreenCaptureNode>>(
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,
],
);
}
+7 -3
View File
@@ -16,9 +16,9 @@ impl Plugin for SkyboxPlugin {
app.add_systems(
Update,
(
load_skybox.run_if(resource_exists_and_changed::<SkyboxId>()),
load_skybox.run_if(resource_exists_and_changed::<SkyboxId>),
spawn_skybox
.run_if(resource_exists::<SkyboxAssets>())
.run_if(resource_exists::<SkyboxAssets>)
.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,
},
));
+4 -4
View File
@@ -38,22 +38,22 @@ fn read_command_system(mut commands: Commands, mut change_event: EventWriter<New
match cmd {
BlockingCommand::Cube => {
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"));
}
};
+5 -5
View File
@@ -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::<DebugMode>()),
update_visibility.run_if(resource_exists_and_changed::<DebugMode>),
);
}
}
@@ -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<DiagnosticsStore>,
mut counter: Query<&mut Text, With<FramerateCounter>>,
) {
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 {
+2 -6
View File
@@ -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::<Transform>();
app.register_inspect::<Name>();
app.register_inspect::<MeshPrimitivePrefab>();
app.register_inspect::<MeshPrimitive3dPrefab>();
//register standart material
{