From ed6187d99670e5c298f800c60073ade3f30c40b4 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 19 Apr 2024 04:18:45 +0200 Subject: [PATCH] restore jupiter's ring --- src/commands.rs | 27 ++++++++++++++++++++++++++- src/defs.txt | 1 + src/nature.rs | 5 ++++- src/world.rs | 19 ------------------- 4 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 195de2d..5ffcb8e 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -3,7 +3,7 @@ extern crate regex; use bevy::prelude::*; use bevy_xpbd_3d::prelude::*; use bevy::math::DVec3; -use crate::{actor, chat, hud, nature, world}; +use crate::{actor, chat, hud, nature, shading, world}; use regex::Regex; use std::f32::consts::PI; use std::f64::consts::PI as PI64; @@ -55,6 +55,7 @@ struct ParserState { is_targeted_on_startup: bool, is_sun: bool, has_physics: bool, + has_ring: bool, wants_maxrotation: Option, wants_maxvelocity: Option, collider_is_mesh: bool, @@ -101,6 +102,7 @@ impl Default for ParserState { is_targeted_on_startup: false, is_sun: false, has_physics: true, + has_ring: false, wants_maxrotation: None, wants_maxvelocity: None, collider_is_mesh: false, @@ -257,6 +259,9 @@ pub fn load_defs( state.is_sun = true; state.model_scale *= 5.0; } + ["ring", "yes"] => { + state.has_ring = true; + } ["oxygen", amount] => { if let Ok(amount) = amount.parse::() { state.is_lifeform = true; @@ -462,6 +467,7 @@ fn spawn_entities( asset_server: Res, mut meshes: ResMut>, mut materials: ResMut>, + mut materials_jupiter: ResMut>, ) { for state_wrapper in er_spawn.read() { let state = &state_wrapper.0; @@ -644,6 +650,25 @@ fn spawn_entities( }, )); } + + if state.has_ring { + commands.spawn(( + world::DespawnOnPlayerDeath, + MaterialMeshBundle { + mesh: meshes.add(Mesh::from(Cylinder::new(nature::JUPITER_RING_RADIUS as f32, 1.0))), + material: materials_jupiter.add(shading::JupitersRing { + alpha_mode: AlphaMode::Blend, + ring_radius: nature::JUPITER_RING_RADIUS as f32, + jupiter_radius: nature::JUPITER_RADIUS as f32, + }), + transform: Transform::from_translation(state.pos.as_vec3()), + ..default() + }, + Position::new(state.pos), + Rotation::from(Quat::IDENTITY), + //Rotation::from(Quat::from_rotation_x(-0.3f32.to_radians())), + )); + } } } } diff --git a/src/defs.txt b/src/defs.txt index b4956c3..a855cf6 100644 --- a/src/defs.txt +++ b/src/defs.txt @@ -13,6 +13,7 @@ actor 0 0 0 jupiter name Jupiter scale 71492e3 sphere yes + ring yes physics off rotationx -0.50 rotationz -0.28 diff --git a/src/nature.rs b/src/nature.rs index 46bc3ea..f1f3e13 100644 --- a/src/nature.rs +++ b/src/nature.rs @@ -11,7 +11,10 @@ pub const LIGHTYEAR2METER: f64 = 9_460_730_472_580_800.0; pub const PARSEC2METER: f64 = 3.0857e16; pub const DIST_JUPTER_SUN: f64 = 778479.0e6; pub const EARTH_GRAVITY: f32 = 9.81; -pub const SOL_RADIUS: f64 = 696.3e6; + +pub const SOL_RADIUS: f64 = 696_300_000.0; +pub const JUPITER_RADIUS: f64 = 71_492_000.0; +pub const JUPITER_RING_RADIUS: f64 = 229_000_000.0; // Each star's values: (x, y, z, magnitude, color index, distance, name) pub const STARS: &[(f32, f32, f32, f32, f32, f32, &str)] = &include!("data/stars.in"); diff --git a/src/world.rs b/src/world.rs index f38a8f3..991cd9d 100644 --- a/src/world.rs +++ b/src/world.rs @@ -104,7 +104,6 @@ pub fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, - mut materials_jupiter: ResMut>, mut materials_skybox: ResMut>, asset_server: Res, ) { @@ -196,24 +195,6 @@ pub fn setup( ..default() }); } - - // Add shaded ring - let ring_radius = 229_000_000.0; - let jupiter_radius = 71_492_000.0; - commands.spawn(( - MaterialMeshBundle { - mesh: meshes.add(Mesh::from(Cylinder::new(ring_radius, 1.0))), - material: materials_jupiter.add(shading::JupitersRing { - alpha_mode: AlphaMode::Blend, - ring_radius: ring_radius, - jupiter_radius: jupiter_radius, - }), - ..default() - }, - Position::from_xyz(0.0, 0.0, 0.0), - Rotation::from(Quat::IDENTITY), - //Rotation::from(Quat::from_rotation_x(-0.3f32.to_radians())), - )); } fn spawn_despawn_asteroids(