Skip to main content

eulumdat_bevy/photometric/
plugin.rs

1//! PhotometricPlugin for Bevy.
2//!
3//! This plugin provides minimal photometric lighting support without
4//! any scene geometry, camera, or controls.
5
6use super::light::PhotometricPluginState;
7use super::systems::{
8    cleanup_photometric_lights, spawn_photometric_lights, update_photometric_lights,
9};
10use super::PhotometricData;
11use bevy::prelude::*;
12use std::marker::PhantomData;
13
14/// Minimal plugin for photometric lighting.
15///
16/// This plugin handles:
17/// - Spawning Bevy lights from `PhotometricLight` components
18/// - Updating lights when components change
19/// - Managing photometric solid and luminaire model entities
20///
21/// It does NOT provide:
22/// - Scene geometry (bring your own scene)
23/// - Camera (bring your own camera)
24/// - Keyboard controls (implement your own if needed)
25///
26/// # Type Parameters
27/// * `T` - The photometric data type (must implement [`PhotometricData`])
28///
29/// # Example
30/// ```ignore
31/// use bevy::prelude::*;
32/// use eulumdat_bevy::photometric::*;
33///
34/// fn main() {
35///     App::new()
36///         .add_plugins(DefaultPlugins)
37///         .add_plugins(PhotometricPlugin::<MyLightData>::default())
38///         .add_systems(Startup, setup)
39///         .run();
40/// }
41///
42/// fn setup(mut commands: Commands) {
43///     // Spawn a camera
44///     commands.spawn(Camera3dBundle {
45///         transform: Transform::from_xyz(0.0, 5.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
46///         ..default()
47///     });
48///
49///     // Spawn your scene geometry
50///     commands.spawn(PbrBundle {
51///         mesh: meshes.add(Plane3d::default().mesh().size(10.0, 10.0)),
52///         material: materials.add(Color::WHITE),
53///         ..default()
54///     });
55///
56///     // Spawn a photometric light
57///     let light_data = MyLightData::load("light.ldt");
58///     commands.spawn(PhotometricLightBundle::new(light_data)
59///         .with_transform(Transform::from_xyz(0.0, 3.0, 0.0)));
60/// }
61/// ```
62#[derive(Default)]
63pub struct PhotometricPlugin<T: PhotometricData> {
64    _phantom: PhantomData<T>,
65}
66
67impl<T: PhotometricData> PhotometricPlugin<T> {
68    /// Create a new PhotometricPlugin.
69    pub fn new() -> Self {
70        Self {
71            _phantom: PhantomData,
72        }
73    }
74}
75
76impl<T: PhotometricData> Plugin for PhotometricPlugin<T> {
77    fn build(&self, app: &mut App) {
78        app.init_resource::<PhotometricPluginState<T>>()
79            .add_systems(
80                Update,
81                (
82                    spawn_photometric_lights::<T>,
83                    update_photometric_lights::<T>,
84                    cleanup_photometric_lights::<T>,
85                ),
86            );
87    }
88}