From 9a648b892a37ca826c5e6e59d1f1b4653bb5553e Mon Sep 17 00:00:00 2001 From: rewin Date: Fri, 26 Jan 2024 22:08:37 +0300 Subject: [PATCH] fix merge problem --- Cargo.lock | 20 ++++++++++---------- editor.ron | 1 + studio/Cargo.toml | 2 ++ studio/src/camera_controller.rs | 3 +++ studio/src/lib.rs | 16 +++++++++------- studio/src/main.rs | 2 +- studio/src/scene.rs | 30 +++++++++++++++++++++++++----- 7 files changed, 51 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 03dcf67..a5f233e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -177,9 +177,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" [[package]] name = "approx" @@ -2936,9 +2936,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.14" +version = "1.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "295c17e837573c8c821dbaeb3cceb3d745ad082f7572191409e69cbc1b3fd050" +checksum = "037731f5d3aaa87a5675e895b63ddff1a87624bc29f77004ea829809654e48f6" dependencies = [ "cc", "libc", @@ -3466,9 +3466,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.98" +version = "0.9.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1665caf8ab2dc9aef43d1c0023bd904633a6a05cb30b0ad59bec2ae986e57a7" +checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae" dependencies = [ "cc", "libc", @@ -3580,18 +3580,18 @@ dependencies = [ [[package]] name = "pin-project" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fda4ed1c6c173e3fc7a83629421152e01d7b1f9b7f65fb301e490e8cfc656422" +checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" +checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690" dependencies = [ "proc-macro2", "quote", diff --git a/editor.ron b/editor.ron index 40d190b..4a200f3 100644 --- a/editor.ron +++ b/editor.ron @@ -2,4 +2,5 @@ "space_editor_ui::settings::NewWindowSettings": "{\"space_editor_ui::settings::NewWindowSettings\":(new_tab:SameNode)}", "space_editor_core::hotkeys::HotkeySet": "{\"space_editor_core::hotkeys::HotkeySet\":(bindings:{Rotate:[R],Translate:[G],Scale:[S],Multiple:[ShiftLeft],Clone:[AltLeft],Delete:[X]},name:\"GizmoHotkey\")}", "space_persistence::PersistenceSettings": "{\"space_persistence::PersistenceSettings\":(load_on_startup:true,save_on_close:true)}", + "space_undo::ChangeChainSettings": "{\"space_undo::ChangeChainSettings\":(max_change_chain_size:200)}", } \ No newline at end of file diff --git a/studio/Cargo.toml b/studio/Cargo.toml index 5edae9e..4ad8e00 100644 --- a/studio/Cargo.toml +++ b/studio/Cargo.toml @@ -17,6 +17,7 @@ bevy-inspector-egui = "0.22.0" bevy_mod_raycast = "0.16.0" bevy_rapier3d = "0.23.0" bevy_mod_outline = "0.6.0" +bevy_web_asset = "0.7.0" bitflags = "2.4.0" console_error_panic_hook = { version = "0.1.7", optional = true } js-sys = { version = "0.3.65", optional = true } @@ -34,6 +35,7 @@ web-sys = { version = "0.3.65", optional = true, features = [ "Window", ] } space_editor = {git = "https://github.com/rewin123/space_editor", rev = "ce83f86dc902787ab16213f3209276a784654df6"} +anyhow.workspace = true [features] wasm = [ diff --git a/studio/src/camera_controller.rs b/studio/src/camera_controller.rs index 6c94020..5b08239 100644 --- a/studio/src/camera_controller.rs +++ b/studio/src/camera_controller.rs @@ -179,6 +179,9 @@ fn process_focus_inputs( // Zero out any existing camera velocity or interpolation **velocity = Vec3::ZERO; + info!("Setting focus to {:?}", target); + + if q_interp_vel.get(ent).is_ok() { cmd.entity(ent).remove::(); } diff --git a/studio/src/lib.rs b/studio/src/lib.rs index 049b5bc..9c1b28b 100644 --- a/studio/src/lib.rs +++ b/studio/src/lib.rs @@ -3,9 +3,11 @@ use bevy::{app::PluginGroupBuilder, prelude::*}; use bevy_mod_picking::DefaultPickingPlugins; +use bevy_web_asset::WebAssetPlugin; #[cfg(feature = "wasm")] use wasm_bindgen::prelude::*; +mod bvh; mod camera_controller; mod debug; mod design_system; @@ -17,10 +19,10 @@ mod persistance; mod scene; mod skybox; mod ui; -mod viewport; +pub mod viewport; mod world_grid; -use crate::{ +pub use crate::{ camera_controller::CameraControllerPlugin, debug::DebugPlugin, input::StudioInputPlugin, @@ -188,7 +190,7 @@ pub fn start_editor( // TODO: These `start_` functiions should be refactored to better support the // needs of the "reaodnly viewer" vs "full studio editor" use cases. See // notes in `studio-web/src/lib/viewer.element.ts` for more info. -#[cfg_attr(feature = "wasm", wasm_bindgen(js_name = start))] + pub fn start_internal( object_id: &str, skybox_id: &str, @@ -196,7 +198,7 @@ pub fn start_internal( canvas_alt: &str, viewport_size: ViewportSize, studio_mode: StudioMode, -) { +) -> App { #[cfg(feature = "wasm")] console_error_panic_hook::set_once(); @@ -210,6 +212,7 @@ pub fn start_internal( app.add_plugins(( #[cfg(feature = "wasm")] viewport::wasm::ViewportPlugin, + WebAssetPlugin, DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { resolution: viewport_size.into(), @@ -222,8 +225,7 @@ pub fn start_internal( CommonPlugins, )); - if studio_mode == StudioMode::Editor { - info!("Starting in editor mode"); + if matches!(studio_mode, StudioMode::Editor) { app.add_plugins((DefaultPickingPlugins, EditorPlugins)); // Only for registering components for undo @@ -242,5 +244,5 @@ pub fn start_internal( #[cfg(feature = "wasm")] wasm::initialize(); - app.run(); + app } diff --git a/studio/src/main.rs b/studio/src/main.rs index 1c51ae6..073d958 100644 --- a/studio/src/main.rs +++ b/studio/src/main.rs @@ -4,7 +4,7 @@ use studio::{StudioMode, ViewportSize}; fn main() { // Edit the arguments here to change the default startup scene or skybox let mut app = studio::start_internal( - "Mannequin.gltf", + "bookcase.gltf", "gum_trees_4k", "", // ignored for non-WASM "Storyteller Studio", diff --git a/studio/src/scene.rs b/studio/src/scene.rs index 181fca7..917e8bf 100644 --- a/studio/src/scene.rs +++ b/studio/src/scene.rs @@ -6,7 +6,7 @@ use bevy::{ tonemapping::Tonemapping, }, gltf::Gltf, - math::vec2, + math::{vec2, Affine3A}, pbr::ShadowFilteringMethod, prelude::*, render::{mesh::skinning::SkinnedMesh, primitives::Aabb, view::NoFrustumCulling}, @@ -86,6 +86,7 @@ fn minimal_scene_setup(mut cmd: Commands) { cmd.spawn(DirectionalLightBundle { directional_light: DirectionalLight { shadows_enabled: false, + illuminance: 20000.0, ..default() }, transform: Transform::default().looking_at(Vec3::NEG_ONE, Vec3::Y), @@ -176,6 +177,7 @@ pub struct SceneData { #[derive(Component)] pub struct SkeletalJoint(pub Color); +#[derive(Component)] pub struct SceneRoot; #[derive(Resource, Deref, DerefMut)] pub struct TestBvh(pub Handle); // TODO @@ -248,7 +250,7 @@ fn init_scene_loading( cmd.spawn(( SpatialBundle::default(), space_editor::prelude::GltfPrefab { - path: format!("gltf/{}.gltf", id.0), + path: format!("gltf/{}", id.0), scene: "Scene0".to_string(), }, PrefabMarker, @@ -270,6 +272,9 @@ fn tick_scene_spawning( } } +#[derive(Component)] +pub struct NoMeshElement; + fn tag_scene_elements( mut cmd: Commands, // A "glTF mesh" is actually a container for one or more "glTF primitives", @@ -280,18 +285,33 @@ fn tag_scene_elements( // leafy parts of a plant. Here we only want to tag the elements that a user // might want to individually address when arranging or animating a scene. q_named_non_primitives: Query< - Entity, + (Entity, + &Children), ( With, With, Without>, Without, + Without ), >, q_skinned_meshes: Query<(Entity, &SkinnedMesh), Without>, + mut q_xforms: ParamSet<(TransformHelper, Query<&Transform>)>, + mesh_entities: Query>>, ) { - for loaded_part in q_named_non_primitives.iter() { - cmd.entity(loaded_part).insert(SceneElement); + for (e, children) in q_named_non_primitives.iter() { + let mut has_mesh = false; + for child in children { + if mesh_entities.contains(*child) { + has_mesh = true; + break; + } + } + if has_mesh { + cmd.entity(e).insert(SceneElement); + } else { + cmd.entity(e).insert(NoMeshElement); + } } for (ent, skinned_mesh) in q_skinned_meshes.iter()