99 lines
3.0 KiB
Rust
99 lines
3.0 KiB
Rust
use bevy::{
|
|
core_pipeline::{bloom::Bloom, tonemapping::Tonemapping},
|
|
prelude::*,
|
|
window::WindowMode,
|
|
};
|
|
use bevy_inspector_egui::{bevy_egui::EguiPlugin, quick::WorldInspectorPlugin};
|
|
use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin};
|
|
use solar_sim::InitialState;
|
|
|
|
fn camera(mut commands: Commands) {
|
|
commands.spawn((
|
|
PanOrbitCamera {
|
|
focus: Vec3::new(0., 0.0, 0.0),
|
|
zoom_lower_limit: SCALE,
|
|
radius: Some(SCALE * 10.),
|
|
..default()
|
|
},
|
|
Camera {
|
|
hdr: true,
|
|
clear_color: ClearColorConfig::Custom(Color::BLACK),
|
|
..default()
|
|
},
|
|
Projection::Perspective(PerspectiveProjection {
|
|
near: 1e-9, // Very close near plane for extreme zooming
|
|
..default()
|
|
}),
|
|
Tonemapping::TonyMcMapface,
|
|
Bloom::NATURAL,
|
|
));
|
|
|
|
commands.spawn(DirectionalLight {
|
|
shadows_enabled: true,
|
|
illuminance: 50_000.0,
|
|
..default()
|
|
});
|
|
}
|
|
|
|
const SCALE: f32 = 1.;
|
|
|
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|
// Load initial state from RON file
|
|
let initial_state_content = match std::fs::read_to_string("assets/initial_state.ron") {
|
|
Ok(content) => content,
|
|
Err(err) => {
|
|
error!("Failed to read initial_state.ron: {}", err);
|
|
return;
|
|
}
|
|
};
|
|
|
|
let initial_state: InitialState = match ron::from_str(&initial_state_content) {
|
|
Ok(state) => state,
|
|
Err(err) => {
|
|
error!("Failed to parse initial_state.ron: {}", err);
|
|
return;
|
|
}
|
|
};
|
|
|
|
initial_state
|
|
.bodies
|
|
.iter()
|
|
.enumerate()
|
|
.for_each(|(i, body)| {
|
|
commands
|
|
.spawn(Transform::from_translation(Vec3::new(
|
|
(i) as f32 * SCALE * 10 as f32,
|
|
0.,
|
|
0.,
|
|
)))
|
|
.with_children(|parent| {
|
|
let scene = asset_server.load(format!("models/{}#Scene0", body.model.path));
|
|
parent.spawn((
|
|
SceneRoot(scene),
|
|
Transform::from_scale(Vec3::new(
|
|
body.model.scale.0,
|
|
body.model.scale.1,
|
|
body.model.scale.2,
|
|
)),
|
|
));
|
|
});
|
|
});
|
|
}
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
|
primary_window: Some(Window {
|
|
title: "Solar Sim".to_string(),
|
|
mode: WindowMode::BorderlessFullscreen(MonitorSelection::Primary),
|
|
..default()
|
|
}),
|
|
..default()
|
|
}))
|
|
.add_plugins(EguiPlugin::default())
|
|
.add_plugins(WorldInspectorPlugin::new())
|
|
.add_plugins(PanOrbitCameraPlugin)
|
|
.add_systems(Startup, (camera, setup))
|
|
.run();
|
|
}
|