Make planet view (and 3d everything) optional
This commit is contained in:
parent
329acb37f0
commit
7ae8dba296
3 changed files with 65 additions and 51 deletions
|
@ -6,6 +6,7 @@ resolver = "2"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
debug = ["save/debug"]
|
debug = ["save/debug"]
|
||||||
|
planet_view = ["render"]
|
||||||
render = ["bevy/bevy_asset", "bevy/bevy_winit", "bevy/render", "save/render", "dep:bevy_pancam"]
|
render = ["bevy/bevy_asset", "bevy/bevy_winit", "bevy/render", "save/render", "dep:bevy_pancam"]
|
||||||
default = ["render", "debug"]
|
default = ["render", "debug"]
|
||||||
|
|
||||||
|
|
104
src/main.rs
104
src/main.rs
|
@ -42,25 +42,30 @@ use bevy::{
|
||||||
log::LogSettings,
|
log::LogSettings,
|
||||||
utils::{default, tracing::Level},
|
utils::{default, tracing::Level},
|
||||||
};
|
};
|
||||||
|
#[cfg(all(feature = "render", feature = "planet_view"))]
|
||||||
|
use bevy::{
|
||||||
|
asset::Handle,
|
||||||
|
core_pipeline::core_3d::Camera3dBundle,
|
||||||
|
pbr::{PbrBundle, PointLight, PointLightBundle, StandardMaterial},
|
||||||
|
prelude::Vec3,
|
||||||
|
render::camera::OrthographicProjection,
|
||||||
|
render::mesh::{shape::Icosphere, Mesh},
|
||||||
|
transform::components::Transform,
|
||||||
|
};
|
||||||
#[cfg(feature = "render")]
|
#[cfg(feature = "render")]
|
||||||
use bevy::{
|
use bevy::{
|
||||||
asset::{AssetServer, Assets, Handle},
|
asset::{AssetServer, Assets},
|
||||||
core_pipeline::{
|
core_pipeline::core_2d::{Camera2d, Camera2dBundle},
|
||||||
core_2d::{Camera2d, Camera2dBundle},
|
|
||||||
core_3d::Camera3dBundle,
|
|
||||||
},
|
|
||||||
ecs::{
|
ecs::{
|
||||||
change_detection::ResMut,
|
change_detection::ResMut,
|
||||||
query::{Changed, With},
|
query::{Changed, With},
|
||||||
system::{Commands, Query, Res},
|
system::{Commands, Query, Res},
|
||||||
},
|
},
|
||||||
hierarchy::BuildChildren,
|
hierarchy::BuildChildren,
|
||||||
pbr::{PbrBundle, PointLight, PointLightBundle, StandardMaterial},
|
prelude::Vec2,
|
||||||
prelude::{Vec2, Vec3},
|
|
||||||
render::{
|
render::{
|
||||||
camera::{Camera, OrthographicProjection, RenderTarget},
|
camera::{Camera, RenderTarget},
|
||||||
color::Color,
|
color::Color,
|
||||||
mesh::{shape::Icosphere, Mesh},
|
|
||||||
render_resource::{
|
render_resource::{
|
||||||
Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages,
|
Extent3d, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages,
|
||||||
},
|
},
|
||||||
|
@ -68,7 +73,7 @@ use bevy::{
|
||||||
},
|
},
|
||||||
sprite::{Sprite, SpriteBundle},
|
sprite::{Sprite, SpriteBundle},
|
||||||
text::Text,
|
text::Text,
|
||||||
transform::components::{GlobalTransform, Transform},
|
transform::components::GlobalTransform,
|
||||||
ui::{
|
ui::{
|
||||||
entity::{NodeBundle, TextBundle},
|
entity::{NodeBundle, TextBundle},
|
||||||
AlignSelf, FocusPolicy, Interaction, JustifyContent, PositionType, Size, Style, UiColor,
|
AlignSelf, FocusPolicy, Interaction, JustifyContent, PositionType, Size, Style, UiColor,
|
||||||
|
@ -77,6 +82,7 @@ use bevy::{
|
||||||
window::{CursorIcon, WindowDescriptor, Windows},
|
window::{CursorIcon, WindowDescriptor, Windows},
|
||||||
winit::WinitSettings,
|
winit::WinitSettings,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(all(feature = "debug", feature = "render"))]
|
#[cfg(all(feature = "debug", feature = "render"))]
|
||||||
use bevy::{
|
use bevy::{
|
||||||
diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin},
|
diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin},
|
||||||
|
@ -189,9 +195,9 @@ fn update_cursor_map_position(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "render")]
|
#[cfg(all(feature = "render", feature = "planet_view"))]
|
||||||
const ROTATION_SPEED: f32 = 0.002;
|
const ROTATION_SPEED: f32 = 0.002;
|
||||||
#[cfg(feature = "render")]
|
#[cfg(all(feature = "render", feature = "planet_view"))]
|
||||||
fn rotate_planet(mut planet_transform: Query<'_, '_, &mut Transform, With<Handle<Mesh>>>) {
|
fn rotate_planet(mut planet_transform: Query<'_, '_, &mut Transform, With<Handle<Mesh>>>) {
|
||||||
planet_transform.single_mut().rotate_y(ROTATION_SPEED);
|
planet_transform.single_mut().rotate_y(ROTATION_SPEED);
|
||||||
}
|
}
|
||||||
|
@ -240,8 +246,8 @@ fn update_info_panel(
|
||||||
fn generate_graphics(
|
fn generate_graphics(
|
||||||
mut commands: Commands<'_, '_>,
|
mut commands: Commands<'_, '_>,
|
||||||
mut images: ResMut<'_, Assets<Image>>,
|
mut images: ResMut<'_, Assets<Image>>,
|
||||||
mut materials: ResMut<'_, Assets<StandardMaterial>>,
|
#[cfg(feature = "planet_view")] mut materials: ResMut<'_, Assets<StandardMaterial>>,
|
||||||
mut meshes: ResMut<'_, Assets<Mesh>>,
|
#[cfg(feature = "planet_view")] mut meshes: ResMut<'_, Assets<Mesh>>,
|
||||||
mut world_manager: ResMut<'_, WorldManager>,
|
mut world_manager: ResMut<'_, WorldManager>,
|
||||||
asset_server: Res<'_, AssetServer>,
|
asset_server: Res<'_, AssetServer>,
|
||||||
) {
|
) {
|
||||||
|
@ -270,42 +276,43 @@ fn generate_graphics(
|
||||||
});
|
});
|
||||||
world_manager.image_handle_id = image_handle.id;
|
world_manager.image_handle_id = image_handle.id;
|
||||||
|
|
||||||
_ = commands.spawn_bundle(Camera3dBundle {
|
#[cfg(feature = "planet_view")]
|
||||||
transform: Transform::from_xyz(0.0, 0.0, 8.0).looking_at(default(), Vec3::Y),
|
{
|
||||||
projection: OrthographicProjection {
|
_ = commands.spawn_bundle(Camera3dBundle {
|
||||||
scale: 0.01,
|
|
||||||
..default()
|
|
||||||
}
|
|
||||||
.into(),
|
|
||||||
..default()
|
|
||||||
});
|
|
||||||
_ = commands.spawn_bundle(PbrBundle {
|
|
||||||
mesh: meshes.add(Mesh::from(Icosphere {
|
|
||||||
radius: 2.0,
|
|
||||||
subdivisions: 9,
|
|
||||||
})),
|
|
||||||
material: materials.add(images.get_handle(world_manager.image_handle_id).into()),
|
|
||||||
transform: Transform::from_translation(default()),
|
|
||||||
..default()
|
|
||||||
});
|
|
||||||
_ = commands.spawn_bundle(PointLightBundle {
|
|
||||||
transform: Transform::from_xyz(-20.0, 20.0, 50.0),
|
|
||||||
point_light: PointLight {
|
|
||||||
intensity: 600000.,
|
|
||||||
range: 100.,
|
|
||||||
..default()
|
|
||||||
},
|
|
||||||
..default()
|
|
||||||
});
|
|
||||||
|
|
||||||
_ = commands
|
|
||||||
.spawn_bundle(Camera2dBundle {
|
|
||||||
camera: Camera {
|
camera: Camera {
|
||||||
is_active: false,
|
is_active: false,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
transform: Transform::from_xyz(0.0, 0.0, 8.0).looking_at(default(), Vec3::Y),
|
||||||
|
projection: OrthographicProjection {
|
||||||
|
scale: 0.01,
|
||||||
|
..default()
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
..default()
|
..default()
|
||||||
})
|
});
|
||||||
|
_ = commands.spawn_bundle(PbrBundle {
|
||||||
|
mesh: meshes.add(Mesh::from(Icosphere {
|
||||||
|
radius: 2.0,
|
||||||
|
subdivisions: 9,
|
||||||
|
})),
|
||||||
|
material: materials.add(images.get_handle(world_manager.image_handle_id).into()),
|
||||||
|
transform: Transform::from_translation(default()),
|
||||||
|
..default()
|
||||||
|
});
|
||||||
|
_ = commands.spawn_bundle(PointLightBundle {
|
||||||
|
transform: Transform::from_xyz(-20.0, 20.0, 50.0),
|
||||||
|
point_light: PointLight {
|
||||||
|
intensity: 600000.,
|
||||||
|
range: 100.,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
..default()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = commands
|
||||||
|
.spawn_bundle(Camera2dBundle { ..default() })
|
||||||
.insert(PanCam::default());
|
.insert(PanCam::default());
|
||||||
_ = commands.spawn_bundle(SpriteBundle {
|
_ = commands.spawn_bundle(SpriteBundle {
|
||||||
texture: images.get_handle(world_manager.image_handle_id),
|
texture: images.get_handle(world_manager.image_handle_id),
|
||||||
|
@ -419,8 +426,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
.add_startup_system(generate_graphics)
|
.add_startup_system(generate_graphics)
|
||||||
.add_system(handle_toolbar_button)
|
.add_system(handle_toolbar_button)
|
||||||
.add_system(update_cursor_map_position)
|
.add_system(update_cursor_map_position)
|
||||||
.add_system(update_info_panel)
|
.add_system(update_info_panel);
|
||||||
.add_system(rotate_planet);
|
#[cfg(all(feature = "render", feature = "planet_view"))]
|
||||||
|
{
|
||||||
|
_ = app.add_system(rotate_planet);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "render"))]
|
#[cfg(not(feature = "render"))]
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,9 +19,8 @@ impl PluginGroup for WorldPlugins {
|
||||||
{
|
{
|
||||||
use bevy::{
|
use bevy::{
|
||||||
asset::AssetPlugin, core_pipeline::CorePipelinePlugin, hierarchy::HierarchyPlugin,
|
asset::AssetPlugin, core_pipeline::CorePipelinePlugin, hierarchy::HierarchyPlugin,
|
||||||
input::InputPlugin, pbr::PbrPlugin, render::RenderPlugin, sprite::SpritePlugin,
|
input::InputPlugin, render::RenderPlugin, sprite::SpritePlugin, text::TextPlugin,
|
||||||
text::TextPlugin, transform::TransformPlugin, ui::UiPlugin, window::WindowPlugin,
|
transform::TransformPlugin, ui::UiPlugin, window::WindowPlugin, winit::WinitPlugin,
|
||||||
winit::WinitPlugin,
|
|
||||||
};
|
};
|
||||||
use bevy_pancam::PanCamPlugin;
|
use bevy_pancam::PanCamPlugin;
|
||||||
|
|
||||||
|
@ -38,8 +37,12 @@ impl PluginGroup for WorldPlugins {
|
||||||
.add(SpritePlugin::default())
|
.add(SpritePlugin::default())
|
||||||
.add(TextPlugin::default())
|
.add(TextPlugin::default())
|
||||||
.add(UiPlugin::default())
|
.add(UiPlugin::default())
|
||||||
.add(PbrPlugin::default())
|
|
||||||
.add(PanCamPlugin::default());
|
.add(PanCamPlugin::default());
|
||||||
|
#[cfg(feature = "planet_view")]
|
||||||
|
{
|
||||||
|
use bevy::pbr::PbrPlugin;
|
||||||
|
_ = group.add(PbrPlugin::default())
|
||||||
|
}
|
||||||
#[cfg(feature = "debug")]
|
#[cfg(feature = "debug")]
|
||||||
{
|
{
|
||||||
_ = group.add(FrameTimeDiagnosticsPlugin::default());
|
_ = group.add(FrameTimeDiagnosticsPlugin::default());
|
||||||
|
|
Loading…
Reference in a new issue