Skip to content

Commit

Permalink
load pca files, store ellipsoid
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-tennert committed Oct 3, 2024
1 parent 03e74df commit 1771e67
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 93 deletions.
2 changes: 1 addition & 1 deletion scenarios/voyager_1.sim
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"bodies":[{"children":[{"children":[],"data":{"mass":5.97219e24,"starting_position":{"x":-140968752.6119205,"y":42678857.74469588,"z":-25254.74791200459},"starting_velocity":{"x":-9.120162775175537,"y":-28.61319460879634,"z":-0.001164064214398408},"name":"Earth","model_path":"earth.glb","diameter":12742.0,"rotation_speed":1436.0,"axial_tilt":23.439281,"simulate":true,"naif_id":-1,"light_source":null}},{"children":[],"data":{"mass":721.0,"starting_position":{"x":-478755881.5606613,"y":626054143.9714329,"z":8162617.640802503},"starting_velocity":{"x":-13.59995211599172,"y":7.453842974225971,"z":-0.06438163739849133},"name":"Voyager-1","model_path":"voyager.glb","diameter":0.34,"rotation_speed":0.0,"axial_tilt":0.0,"simulate":true,"naif_id":-1,"light_source":null}},{"children":[{"children":[],"data":{"mass":8.931938e22,"starting_position":{"x":-493605925.879685,"y":575473831.0733274,"z":265175719.89332935},"starting_velocity":{"x":-9.978391983021908,"y":-3.7823007484817617,"z":-2.279987471012407},"name":"Io","model_path":"io.glb","diameter":3643.2,"rotation_speed":2547.36,"axial_tilt":0.0,"simulate":true,"naif_id":55501,"light_source":null}},{"children":[],"data":{"mass":4.799844e22,"starting_position":{"x":-477194029.517708,"y":556538490.081504,"z":249403655.71783304},"starting_velocity":{"x":-12.757436408817693,"y":-7.563126779474686,"z":-4.3494285120587115},"name":"Europa","model_path":"europa.glb","diameter":1560.8,"rotation_speed":5113.70064,"axial_tilt":0.0,"simulate":true,"naif_id":55502,"light_source":null}},{"children":[],"data":{"mass":1.4819e23,"starting_position":{"x":-486818965.27222335,"y":547266799.9050096,"z":253312203.97226703},"starting_velocity":{"x":-12.338585855725498,"y":-6.213844491167524,"z":-2.2017724479586405},"name":"Ganymede","model_path":"ganymede.glb","diameter":5268.2,"rotation_speed":10303.2,"axial_tilt":0.0,"simulate":true,"naif_id":55503,"light_source":null}},{"children":[],"data":{"mass":1.075938e23,"starting_position":{"x":-485964054.4773958,"y":595772805.8749864,"z":262952504.4681254},"starting_velocity":{"x":-8.30759289228536,"y":-6.896388751529391,"z":-2.180655899725101},"name":"Callisto","model_path":"callisto.glb","diameter":4820.6,"rotation_speed":24032.16,"axial_tilt":0.0,"simulate":true,"naif_id":55504,"light_source":null}}],"data":{"mass":1.8981999999999999e27,"starting_position":{"x":-479848914.5271239,"y":572958028.2936275,"z":257301363.24801183},"starting_velocity":{"x":-10.530416675065974,"y":-6.83225142804572,"z":-2.672213707159385},"name":"Jupiter","model_path":"jupiter.glb","diameter":139822.0,"rotation_speed":595.0,"axial_tilt":3.13,"simulate":true,"naif_id":5,"light_source":null}},{"children":[{"children":[],"data":{"mass":1.3452e23,"starting_position":{"x":-1317155945.9130914,"y":401685520.2661368,"z":221893876.7955563},"starting_velocity":{"x":-9.109829090037053,"y":-7.800989933081476,"z":-2.9359612621322944},"name":"Titan","model_path":"titan.glb","diameter":5149.46,"rotation_speed":22920.0,"axial_tilt":0.0,"simulate":true,"naif_id":606,"light_source":null}},{"children":[],"data":{"mass":2.3064854e21,"starting_position":{"x":-1317382065.4602823,"y":400972997.6578921,"z":221961663.9500768},"starting_velocity":{"x":-11.964844277122554,"y":-10.124933789839565,"z":-2.5597577939355545},"name":"Rhea","model_path":"rhea.glb","diameter":763.5,"rotation_speed":6480.0,"axial_tilt":0.0,"simulate":true,"naif_id":605,"light_source":null}},{"children":[],"data":{"mass":1.8056591e21,"starting_position":{"x":-1318561544.5943272,"y":397100581.45783347,"z":221666433.0104799},"starting_velocity":{"x":-0.7035327859354465,"y":-9.49338661268315,"z":-4.117463427766138},"name":"Iapetus","model_path":"iapetus.glb","diameter":1470.0,"rotation_speed":113760.0,"axial_tilt":0.0,"simulate":true,"naif_id":608,"light_source":null}},{"children":[],"data":{"mass":1.0954868e21,"starting_position":{"x":-1316974778.9178972,"y":400233150.94101655,"z":221978521.7508267},"starting_velocity":{"x":2.1798879595542897,"y":-0.45446507747606546,"z":-4.45063449430418},"name":"Dione","model_path":"dione.glb","diameter":1123.0,"rotation_speed":3941.1576,"axial_tilt":0.0,"simulate":true,"naif_id":604,"light_source":null}},{"children":[],"data":{"mass":6.174959e20,"starting_position":{"x":-1317564624.039431,"y":400392597.6125812,"z":222023174.2808789},"starting_velocity":{"x":-1.1379697756912446,"y":-19.56390177319556,"z":-2.790506179151342},"name":"Tethys","model_path":"tethys.glb","diameter":1062.0,"rotation_speed":2718.0,"axial_tilt":0.0,"simulate":true,"naif_id":603,"light_source":null}},{"children":[],"data":{"mass":3.75094e19,"starting_position":{"x":-1317457696.975204,"y":400423814.833281,"z":222004140.48551643},"starting_velocity":{"x":-0.8831812142331659,"y":-22.805919749933615,"z":-2.919858165732254},"name":"Mimas","model_path":"mimas.glb","diameter":396.0,"rotation_speed":1356.0,"axial_tilt":0.0,"simulate":true,"naif_id":601,"light_source":null}},{"children":[],"data":{"mass":1.080318e20,"starting_position":{"x":-1317091549.573697,"y":400602202.1932426,"z":221961416.07156047},"starting_velocity":{"x":-11.380791737588428,"y":1.433197828984678,"z":-3.42730656043974},"name":"Enceladus","model_path":"enceladus.glb","diameter":504.0,"rotation_speed":1973.11392,"axial_tilt":0.0,"simulate":true,"naif_id":602,"light_source":null}}],"data":{"mass":5.6834e26,"starting_position":{"x":-1317279006.668406,"y":400456460.90597373,"z":221988296.4282521},"starting_velocity":{"x":-3.677373856296947,"y":-8.517486004011271,"z":-3.358977485433484},"name":"Saturn","model_path":"saturn.glb","diameter":116464.0,"rotation_speed":633.0,"axial_tilt":26.73,"simulate":true,"naif_id":699,"light_source":null}}],"data":{"mass":1.9885e30,"starting_position":{"x":961232.2255364412,"y":-409638.1359710687,"z":-26920.33308127907},"starting_velocity":{"x":0.01057748426413201,"y":0.01000902911669899,"z":-0.0003291835695185871},"name":"Sol","model_path":"sun.glb","diameter":1392000.0,"rotation_speed":38880.0,"axial_tilt":7.25,"simulate":true,"naif_id":-1,"light_source":{"intensity":3.75e28,"range":4436820000000.0,"color":"#FFFFFF","enabled":true}}}],"data_sets":["de440s.bsp","sat441.bsp"],"starting_time_millis":289353600000,"title":"Voyager 1 Jupiter Flyby","description":"A scenario showcasing the Jupiter flyby from Voyager-1","scale":1e-7,"timestep":20}
{"bodies":[{"children":[{"children":[],"data":{"mass":5.97219e24,"starting_position":{"x":-140968752.6119205,"y":42678857.74469588,"z":-25254.74791200459},"starting_velocity":{"x":-9.120162775175537,"y":-28.61319460879634,"z":-0.001164064214398408},"name":"Earth","model_path":"earth.glb","diameter":12742.0,"rotation_speed":1436.0,"axial_tilt":23.439281,"simulate":true,"naif_id":-1,"light_source":null}},{"children":[],"data":{"mass":721.0,"starting_position":{"x":-478755881.5606613,"y":626054143.9714329,"z":8162617.640802503},"starting_velocity":{"x":-13.59995211599172,"y":7.453842974225971,"z":-0.06438163739849133},"name":"Voyager-1","model_path":"voyager.glb","diameter":0.34,"rotation_speed":0.0,"axial_tilt":0.0,"simulate":true,"naif_id":-1,"light_source":null}},{"children":[{"children":[],"data":{"mass":8.931938e22,"starting_position":{"x":-493605925.879685,"y":575473831.0733274,"z":265175719.89332935},"starting_velocity":{"x":-9.978391983021908,"y":-3.7823007484817617,"z":-2.279987471012407},"name":"Io","model_path":"io.glb","diameter":3643.2,"rotation_speed":2547.36,"axial_tilt":0.0,"simulate":true,"naif_id":55501,"light_source":null}},{"children":[],"data":{"mass":4.799844e22,"starting_position":{"x":-477194029.517708,"y":556538490.081504,"z":249403655.71783304},"starting_velocity":{"x":-12.757436408817693,"y":-7.563126779474686,"z":-4.3494285120587115},"name":"Europa","model_path":"europa.glb","diameter":1560.8,"rotation_speed":5113.70064,"axial_tilt":0.0,"simulate":true,"naif_id":55502,"light_source":null}},{"children":[],"data":{"mass":1.4819e23,"starting_position":{"x":-486818965.27222335,"y":547266799.9050096,"z":253312203.97226703},"starting_velocity":{"x":-12.338585855725498,"y":-6.213844491167524,"z":-2.2017724479586405},"name":"Ganymede","model_path":"ganymede.glb","diameter":5268.2,"rotation_speed":10303.2,"axial_tilt":0.0,"simulate":true,"naif_id":55503,"light_source":null}},{"children":[],"data":{"mass":1.075938e23,"starting_position":{"x":-485964054.4773958,"y":595772805.8749864,"z":262952504.4681254},"starting_velocity":{"x":-8.30759289228536,"y":-6.896388751529391,"z":-2.180655899725101},"name":"Callisto","model_path":"callisto.glb","diameter":4820.6,"rotation_speed":24032.16,"axial_tilt":0.0,"simulate":true,"naif_id":55504,"light_source":null}}],"data":{"mass":1.8982e27,"starting_position":{"x":-479848914.5271239,"y":572958028.2936275,"z":257301363.24801183},"starting_velocity":{"x":-10.530416675065974,"y":-6.83225142804572,"z":-2.672213707159385},"name":"Jupiter","model_path":"jupiter.glb","diameter":139822.0,"rotation_speed":595.0,"axial_tilt":3.13,"simulate":true,"naif_id":5,"light_source":null}},{"children":[{"children":[],"data":{"mass":1.3452e23,"starting_position":{"x":-1317155945.9130914,"y":401685520.2661368,"z":221893876.7955563},"starting_velocity":{"x":-9.109829090037053,"y":-7.800989933081476,"z":-2.9359612621322944},"name":"Titan","model_path":"titan.glb","diameter":5149.46,"rotation_speed":22920.0,"axial_tilt":0.0,"simulate":true,"naif_id":606,"light_source":null}},{"children":[],"data":{"mass":2.3064854e21,"starting_position":{"x":-1317382065.4602823,"y":400972997.6578921,"z":221961663.9500768},"starting_velocity":{"x":-11.964844277122554,"y":-10.124933789839565,"z":-2.5597577939355545},"name":"Rhea","model_path":"rhea.glb","diameter":763.5,"rotation_speed":6480.0,"axial_tilt":0.0,"simulate":true,"naif_id":605,"light_source":null}},{"children":[],"data":{"mass":1.8056591e21,"starting_position":{"x":-1318561544.5943272,"y":397100581.45783347,"z":221666433.0104799},"starting_velocity":{"x":-0.7035327859354465,"y":-9.49338661268315,"z":-4.117463427766138},"name":"Iapetus","model_path":"iapetus.glb","diameter":1470.0,"rotation_speed":113760.0,"axial_tilt":0.0,"simulate":true,"naif_id":608,"light_source":null}},{"children":[],"data":{"mass":1.0954868e21,"starting_position":{"x":-1316974778.9178972,"y":400233150.94101655,"z":221978521.7508267},"starting_velocity":{"x":2.1798879595542897,"y":-0.45446507747606546,"z":-4.45063449430418},"name":"Dione","model_path":"dione.glb","diameter":1123.0,"rotation_speed":3941.1576,"axial_tilt":0.0,"simulate":true,"naif_id":604,"light_source":null}},{"children":[],"data":{"mass":6.174959e20,"starting_position":{"x":-1317564624.039431,"y":400392597.6125812,"z":222023174.2808789},"starting_velocity":{"x":-1.1379697756912446,"y":-19.56390177319556,"z":-2.790506179151342},"name":"Tethys","model_path":"tethys.glb","diameter":1062.0,"rotation_speed":2718.0,"axial_tilt":0.0,"simulate":true,"naif_id":603,"light_source":null}},{"children":[],"data":{"mass":3.75094e19,"starting_position":{"x":-1317457696.975204,"y":400423814.833281,"z":222004140.48551643},"starting_velocity":{"x":-0.8831812142331659,"y":-22.805919749933615,"z":-2.919858165732254},"name":"Mimas","model_path":"mimas.glb","diameter":396.0,"rotation_speed":1356.0,"axial_tilt":0.0,"simulate":true,"naif_id":601,"light_source":null}},{"children":[],"data":{"mass":1.080318e20,"starting_position":{"x":-1317091549.573697,"y":400602202.1932426,"z":221961416.07156047},"starting_velocity":{"x":-11.380791737588428,"y":1.433197828984678,"z":-3.42730656043974},"name":"Enceladus","model_path":"enceladus.glb","diameter":504.0,"rotation_speed":1973.11392,"axial_tilt":0.0,"simulate":true,"naif_id":602,"light_source":null}}],"data":{"mass":5.6834e26,"starting_position":{"x":-1317279006.668406,"y":400456460.90597373,"z":221988296.4282521},"starting_velocity":{"x":-3.677373856296947,"y":-8.517486004011271,"z":-3.358977485433484},"name":"Saturn","model_path":"saturn.glb","diameter":116464.0,"rotation_speed":633.0,"axial_tilt":26.73,"simulate":true,"naif_id":699,"light_source":null}}],"data":{"mass":1.9885e30,"starting_position":{"x":961232.2255364412,"y":-409638.1359710687,"z":-26920.33308127907},"starting_velocity":{"x":0.01057748426413201,"y":0.01000902911669899,"z":-0.0003291835695185871},"name":"Sol","model_path":"sun.glb","diameter":1392000.0,"rotation_speed":38880.0,"axial_tilt":7.25,"simulate":true,"naif_id":-1,"light_source":{"intensity":3.75e28,"range":4436820000000.0,"color":"#FFFFFF","enabled":true}}}],"data_sets":["de440s.bsp","sat441.bsp","pck11.pca"],"starting_time_millis":289353600000,"title":"Voyager 1 Jupiter Flyby","description":"A scenario showcasing the Jupiter flyby from Voyager-1","scale":1e-7,"timestep":20}
9 changes: 9 additions & 0 deletions src/simulation/asset/serialization.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anise::structure::planetocentric::ellipsoid::Ellipsoid;
use bevy::asset::io::file::FileAssetReader;
use bevy::asset::io::{AssetSource, AssetSourceBuilder, AssetSourceId, Reader};
use bevy::asset::AsyncReadExt;
Expand Down Expand Up @@ -67,6 +68,10 @@ pub struct SerializedBodyData {
pub simulate: bool,
#[serde(default = "default_id")]
pub naif_id: i32,
#[serde(default = "default_id")]
pub orientation_id: i32,
#[serde(default = "default_ellipsoid")]
pub ellipsoid: Ellipsoid,
pub light_source: Option<SerializedLightSource>
}

Expand All @@ -78,6 +83,10 @@ fn default_spk() -> Vec<String> {
Vec::new()
}

fn default_ellipsoid() -> Ellipsoid {
Ellipsoid::from_sphere(1.0)
}

#[derive(Debug, Serialize, Deserialize, TypePath, Clone)]
pub struct SerializedLightSource {
pub intensity: f32,
Expand Down
41 changes: 24 additions & 17 deletions src/simulation/components/anise.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::simulation::components::horizons::NaifIdComponent;
use crate::simulation::components::horizons::AniseMetadata;
use crate::simulation::components::selection::SelectedEntity;
use crate::simulation::scenario::loading::LoadingState;
use crate::simulation::scenario::setup::ScenarioData;
use crate::simulation::ui::editor_body_panel::EditorPanelState;
use crate::simulation::ui::toast::{error_toast, success_toast, ToastContainer};
use crate::simulation::SimState;
use anise::constants::frames::{JUPITER_BARYCENTER_J2000, SSB_J2000};
use anise::constants::orientations::J2000;
use crate::simulation::{SimState, SimStateType};
use anise::constants::frames::{IAU_EARTH_FRAME, JUPITER_BARYCENTER_J2000, SSB_J2000};
use anise::constants::orientations::{IAU_EARTH, J2000};
use anise::math::Vector3;
use anise::prelude::{Almanac, Epoch, Frame, SPK};
use bevy::app::Plugin;
use bevy::math::DVec3;
use bevy::prelude::{in_state, IntoSystemConfigs, OnEnter, Query, Res, ResMut, Resource, Update};
use bevy::prelude::{in_state, IntoSystemConfigs, OnEnter, Query, Res, ResMut, Resource, State, Update};
use reqwest::get;

pub struct AnisePlugin;
Expand All @@ -35,31 +35,39 @@ impl Default for AlmanacHolder {

pub fn retrieve_starting_data(
selected_entity: Res<SelectedEntity>,
bodies: Query<&NaifIdComponent>,
mut bodies: Query<&mut AniseMetadata>,
almanac: Res<AlmanacHolder>,
mut e_state: ResMut<EditorPanelState>,
scenario: Res<ScenarioData>,
mut toasts: ResMut<ToastContainer>
) {
// Define an Epoch in the dynamical barycentric time scale
let epoch = Epoch::from_unix_milliseconds(scenario.starting_time_millis as f64);
let id = selected_entity.entity.map(|e| bodies.get(e).ok()).flatten().unwrap();
let mut metadata = selected_entity.entity.map(|e| bodies.get_mut(e).ok()).flatten().unwrap();
let state = almanac.0
.translate(
Frame::new(id.0, J2000), // Target
Frame::new(metadata.target_id, J2000), // Target
SSB_J2000, // Observer
epoch,
None,
);

if let Ok(s) = state {
toasts.0.add(success_toast(&format!("Retrieved data for {}", id.0)));
toasts.0.add(success_toast(&format!("Retrieved data for {}", metadata.target_id)));
e_state.new_velocity = vector3_to_dvec3(s.velocity_km_s);
e_state.new_position = vector3_to_dvec3(s.radius_km);
} else {
println!("{:?}", state);
toasts.0.add(error_toast(format!("Error: {:?}", state.unwrap_err()).as_str()));
}

let full_frame = almanac.0.frame_from_uid(Frame::new(metadata.target_id, metadata.orientation_id));

if let Ok(f) = full_frame {
e_state.ellipsoid = f.shape.unwrap();
} else {
toasts.0.add(error_toast(format!("Error: {:?}", full_frame.unwrap_err()).as_str()));
}
}

fn vector3_to_dvec3(v: Vector3) -> DVec3 {
Expand All @@ -70,32 +78,31 @@ fn spk_file_loading(
mut almanac: ResMut<AlmanacHolder>,
mut toasts: ResMut<ToastContainer>,
mut scenario_data: ResMut<ScenarioData>,
mut loading_state: ResMut<LoadingState>
mut loading_state: ResMut<LoadingState>,
sim_type: Res<SimStateType>
) {
if loading_state.loaded_spk_files || !loading_state.spawned_bodies {
if loading_state.loaded_spk_files || !loading_state.spawned_bodies || *sim_type == SimStateType::Simulation {
return;
}
load_spk_files(scenario_data.spk_files.clone(), &mut almanac, &mut toasts);
load_spice_files(scenario_data.spice_files.clone(), &mut almanac, &mut toasts);
loading_state.loaded_spk_files = true;
}

pub fn load_spk_files(
pub fn load_spice_files(
paths: Vec<String>,
almanac: &mut AlmanacHolder,
toasts: &mut ToastContainer
) {
let mut missing_paths = Vec::new();
for path in paths {
let spk = SPK::load(format!("data/{}", path).as_str()).unwrap();
if let Ok(a) = almanac.0.with_spk(spk) {
if let Ok(a) = almanac.0.load(format!("data/{}", path).as_str()) {
almanac.0 = a;
// get_target_frames(&almanac.0);
} else {
missing_paths.push(path);
}
}
if !missing_paths.is_empty() {
toasts.0.add(error_toast(format!("Couldn't load the following SPK files: {}", missing_paths.join(", ")).as_str()));
toasts.0.add(error_toast(format!("Couldn't load the following SPICE files: {}", missing_paths.join(", ")).as_str()));
}
}

Expand Down
25 changes: 20 additions & 5 deletions src/simulation/components/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use bevy::math::{DVec3, Vec3};
use bevy::prelude::{default, Bundle, Component, Entity, Handle, Reflect, Scene, Srgba, Transform};
use bevy::render::primitives::Aabb;
use std::collections::VecDeque;
use crate::simulation::components::horizons::NaifIdComponent;
use anise::structure::planetocentric::ellipsoid::Ellipsoid;
use crate::simulation::components::horizons::AniseMetadata;

#[derive(Component, Clone, Default, Reflect, Copy)]
pub struct Mass(pub f64);
Expand Down Expand Up @@ -82,12 +83,21 @@ impl Default for OrbitSettings {
#[derive(Component, Reflect, Clone, Default)]
pub struct SimPosition(pub DVec3);

#[derive(Component, Reflect, Clone, Default)]
#[derive(Component, Reflect, Clone)]
pub struct Diameter {

pub num: f32,
pub applied: bool,
pub aabb: Option<Aabb>
pub ellipsoid: Ellipsoid,
pub path: String,

}

impl Default for Diameter {

fn default() -> Self {
Diameter { num: 0.0, applied: false, ellipsoid: Ellipsoid::from_sphere(1.0), path: "".to_string() }
}

}

Expand Down Expand Up @@ -130,7 +140,7 @@ pub struct BodyBundle {
pub axial_tilt: AxialTilt,
pub diameter: Diameter,
pub billboard_visible: BillboardVisible,
pub naif_id: NaifIdComponent,
pub naif_id: AniseMetadata,

}

Expand All @@ -145,14 +155,19 @@ impl From<SerializedBody> for BodyBundle {
model_path: ModelPath(format!("models/{}#Scene0", value.data.model_path)),
diameter: Diameter {
num: (value.data.diameter * 1000.0) as f32,
path: value.data.model_path,
ellipsoid: value.data.ellipsoid,
..default()
},
axial_tilt: AxialTilt {
num: value.data.axial_tilt,
..default()
},
rotation_speed: RotationSpeed(value.data.rotation_speed),
naif_id: NaifIdComponent(value.data.naif_id),
naif_id: AniseMetadata {
target_id: value.data.naif_id,
orientation_id: value.data.orientation_id,
},
..default()
}
}
Expand Down
Loading

0 comments on commit 1771e67

Please sign in to comment.