honeycomb_render/scene/
mod.rs

1mod camera;
2mod picking;
3
4use bevy::prelude::*;
5use bevy_mod_outline::OutlinePlugin;
6use bevy_mod_picking::DefaultPickingPlugins;
7use bevy_mod_picking::selection::SelectionPluginSettings;
8
9use crate::gui::WindowVisible;
10use crate::systems::{
11    render_dart_enabled, render_darts, render_edge_enabled, render_edges, render_face_enabled,
12    render_faces, render_vertex_enabled, render_vertices,
13};
14
15/// Plugin handling scene setup and updates.
16pub struct ScenePlugin;
17
18impl Plugin for ScenePlugin {
19    fn build(&self, app: &mut App) {
20        // camera
21        app.insert_resource(AmbientLight {
22            color: Color::NONE,
23            brightness: 0.0,
24        })
25        .add_systems(Startup, setup_scene)
26        .add_systems(
27            Update,
28            camera::update_camera.run_if(|window_visible: Res<WindowVisible>| !window_visible.0),
29        );
30
31        // picking
32        app.add_plugins(DefaultPickingPlugins.build())
33            .add_plugins(OutlinePlugin)
34            .insert_resource(SelectionPluginSettings::default())
35            .add_systems(Update, picking::update_picking);
36
37        // content rendering
38        app.add_systems(Update, render_darts.run_if(render_dart_enabled))
39            .add_systems(Update, render_vertices.run_if(render_vertex_enabled))
40            .add_systems(Update, render_edges.run_if(render_edge_enabled))
41            .add_systems(Update, render_faces.run_if(render_face_enabled));
42    }
43}
44/// Scene setup routine.
45pub fn setup_scene(mut commands: Commands) {
46    let camera_transform = Transform::from_xyz(0.0, 0.0, 5.0);
47
48    commands.spawn((
49        camera::PanOrbitCamera {
50            radius: camera_transform.translation.length(),
51            ..Default::default()
52        },
53        Camera3dBundle {
54            transform: camera_transform.looking_at(Vec3::ZERO, Vec3::Y),
55            ..default()
56        },
57    ));
58}