use bevy::{color::palettes, math::DVec3, prelude::*};
use big_space::prelude::*;
fn main() {
App::new()
.add_plugins((
DefaultPlugins.build().disable::<TransformPlugin>(),
BigSpaceDefaultPlugins,
))
.add_systems(Startup, setup_scene)
.run();
}
const DISTANT: DVec3 = DVec3::new(1e17, 1e17, 1e17);
const SPHERE_RADIUS: f32 = 1.0;
const NEARBY: Vec3 = Vec3::new(SPHERE_RADIUS * 20.0, SPHERE_RADIUS * 20.0, 0.0);
fn setup_scene(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let mesh_handle = meshes.add(Sphere::new(SPHERE_RADIUS).mesh());
commands.spawn_big_space(Grid::new(SPHERE_RADIUS * 100.0, 0.0), |root_grid| {
root_grid.spawn_spatial((
Mesh3d(mesh_handle.clone()),
MeshMaterial3d(materials.add(Color::from(palettes::css::BLUE))),
Transform::from_translation(NEARBY),
));
let parent = root_grid.grid().translation_to_grid(DISTANT);
root_grid.with_grid(Grid::new(SPHERE_RADIUS * 100.0, 0.0), |parent_grid| {
let child = parent_grid
.grid()
.translation_to_grid(-DISTANT + NEARBY.as_dvec3());
parent_grid.insert((
Mesh3d(mesh_handle.clone()),
MeshMaterial3d(materials.add(Color::from(palettes::css::RED))),
Transform::from_translation(parent.1),
));
parent_grid.insert(parent.0);
parent_grid.spawn((
Mesh3d(mesh_handle),
MeshMaterial3d(materials.add(Color::from(palettes::css::GREEN))),
Transform::from_translation(child.1),
child.0,
));
});
root_grid.spawn_spatial((
DirectionalLight::default(),
Transform::from_xyz(4.0, -10.0, -4.0),
));
root_grid.spawn_spatial((
Camera3d::default(),
Transform::from_translation(NEARBY + Vec3::new(0.0, 0.0, SPHERE_RADIUS * 10.0))
.looking_at(NEARBY, Vec3::Y),
Projection::Perspective(PerspectiveProjection {
near: (SPHERE_RADIUS * 0.1).min(0.1),
..default()
}),
FloatingOrigin,
BigSpaceCameraController::default() .with_speed_bounds([10e-18, 10e35])
.with_smoothness(0.9, 0.8)
.with_speed(1.0),
));
});
}