diff --git a/Cargo.toml b/Cargo.toml index a9a5a24a..d0007bce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,8 +32,12 @@ bevy = { git = "https://github.com/bevyengine/bevy.git", rev = "a3d406dd49720525 ] } bevy_derive = { git = "https://github.com/bevyengine/bevy.git", rev = "a3d406dd497205253e34ace757ab0076d50eec14" } bevy_macro_utils = { git = "https://github.com/bevyengine/bevy.git", rev = "a3d406dd497205253e34ace757ab0076d50eec14" } +bevy_remote = { git = "https://github.com/bevyengine/bevy.git", rev = "a3d406dd497205253e34ace757ab0076d50eec14" } + thiserror = "2.0" serde = { version = "1", features = ["derive"] } +serde_json = "1.0.140" +ureq = {version = "3.0.12", features = ["json"]} tracing-test = "0.2.5" tracing = "0.1.41" atomicow = "1.1.0" @@ -64,6 +68,8 @@ bevy_toolbar = { path = "bevy_widgets/bevy_toolbar" } bevy_tooltips = { path = "bevy_widgets/bevy_tooltips" } bevy_text_editing = { path = "bevy_widgets/bevy_text_editing" } bevy_field_forms = { path = "bevy_widgets/bevy_field_forms" } +bevy_focus = { path = "bevy_widgets/bevy_focus" } +bevy_transform = { path = "bevy_widgets/bevy_transform" } # general crates bevy_editor_core = { path = "crates/bevy_editor_core" } diff --git a/crates/bevy_editor/Cargo.toml b/crates/bevy_editor/Cargo.toml index b4f863e6..2ae159c1 100644 --- a/crates/bevy_editor/Cargo.toml +++ b/crates/bevy_editor/Cargo.toml @@ -10,6 +10,7 @@ bevy_menu_bar.workspace = true bevy_footer_bar.workspace = true bevy_context_menu.workspace = true bevy_editor_styles.workspace = true +bevy_remote.workspace = true serde.workspace = true ron.workspace = true diff --git a/crates/bevy_editor/src/lib.rs b/crates/bevy_editor/src/lib.rs index 63f8970c..6fdd01b7 100644 --- a/crates/bevy_editor/src/lib.rs +++ b/crates/bevy_editor/src/lib.rs @@ -11,7 +11,11 @@ //! which transforms the user's application into an editor that runs their game. //! - Finally, it will be a standalone application that communicates with a running Bevy game via the Bevy Remote Protocol. +use std::env; + use bevy::app::App as BevyApp; +use bevy::color::palettes::tailwind; +use bevy::math::ops::cos; use bevy::prelude::*; // Re-export Bevy for project use pub use bevy; @@ -24,6 +28,8 @@ use bevy_editor_styles::StylesPlugin; use bevy_2d_viewport::Viewport2dPanePlugin; use bevy_3d_viewport::Viewport3dPanePlugin; use bevy_asset_browser::AssetBrowserPanePlugin; +use bevy_remote::http::RemoteHttpPlugin; +use bevy_remote::RemotePlugin; use crate::load_gltf::LoadGltfPlugin; @@ -48,18 +54,25 @@ impl Plugin for EditorPlugin { // Update/register this project to the editor project list project::update_project_info(); info!("Loading Bevy Editor"); + bevy_app .add_plugins(( + RemotePlugin::default(), + RemoteHttpPlugin::default(), EditorCorePlugin, ContextMenuPlugin, StylesPlugin, Viewport2dPanePlugin, Viewport3dPanePlugin, ui::EditorUIPlugin, - AssetBrowserPanePlugin, LoadGltfPlugin, + AssetBrowserPanePlugin, )) - .add_systems(Startup, dummy_setup); + .add_systems(Startup, setup) + .add_systems(Update, move_cube) + .register_type::() + .register_type::() + .register_type::(); } } @@ -76,7 +89,7 @@ impl App { /// Run the application pub fn run(&self) -> AppExit { - let args = std::env::args().collect::>(); + let args = env::args().collect::>(); let editor_mode = !args.iter().any(|arg| arg == "-game"); let mut bevy_app = BevyApp::new(); @@ -85,35 +98,100 @@ impl App { bevy_app.add_plugins(EditorPlugin); } + info!( + "Running bevy editor in {} mode", + if editor_mode { "editor" } else { "game" } + ); bevy_app.run() } } -/// This is temporary, until we can load maps from the asset browser -fn dummy_setup( +#[derive(Component, Reflect)] +#[reflect(Component)] +struct Cube(f32); + +#[derive(Component, Reflect)] +#[reflect(Component)] +struct MyObject { + vec3: Vec3, + color: Color, +} + +#[derive(Resource, Reflect)] +#[reflect(Resource)] +struct MoveSpeed { + value: f32, +} + +fn setup( mut commands: Commands, mut meshes: ResMut>, - mut materials_2d: ResMut>, - mut materials_3d: ResMut>, + mut materials: ResMut>, ) { + // unnamed object + commands.spawn(( + Name::new("MyObject1"), + MyObject { + vec3: Vec3::new(1.0, 2.0, 3.0), + color: Color::from(tailwind::BLUE_500), + }, + )); + + // cube + let cube_handle = meshes.add(Cuboid::new(1.0, 1.0, 1.0)); commands.spawn(( - Mesh2d(meshes.add(Circle::new(50.0))), - MeshMaterial2d(materials_2d.add(Color::WHITE)), - Name::new("Circle"), + Name::new("Cube"), + Mesh3d(cube_handle.clone()), + MeshMaterial3d(materials.add(Color::from(tailwind::RED_200))), + Transform::from_xyz(0.0, 0.5, 0.0), + Cube(1.0), + children![( + Name::new("Sub-cube"), + Mesh3d(cube_handle.clone()), + MeshMaterial3d(materials.add(Color::from(tailwind::GREEN_500))), + Transform::from_xyz(0.0, 1.5, 0.0), + children![( + Name::new("Sub-sub-cube"), + Mesh3d(cube_handle), + MeshMaterial3d(materials.add(Color::from(tailwind::BLUE_800))), + Transform::from_xyz(1.5, 0.0, 0.0), + )] + )], )); + // circular base commands.spawn(( - Mesh3d(meshes.add(Plane3d::new(Vec3::Y, Vec2::splat(1.5)))), - MeshMaterial3d(materials_3d.add(Color::WHITE)), - Name::new("Plane"), + Name::new("Circular base"), + Mesh3d(meshes.add(Circle::new(4.0))), + MeshMaterial3d(materials.add(Color::from(tailwind::GREEN_300))), + Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)), )); + // light commands.spawn(( - DirectionalLight { + Name::new("Light"), + PointLight { shadows_enabled: true, ..default() }, - Transform::default().looking_to(Vec3::NEG_ONE, Vec3::Y), - Name::new("DirectionalLight"), + Transform::from_xyz(4.0, 8.0, 4.0), + )); + + // camera + commands.spawn(( + Name::new("Camera"), + Camera3d::default(), + Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::Y, Vec3::Y), )); } + +fn move_cube( + mut query: Query<&mut Transform, With>, + time: Res