phosph-rs 0.4.0

Simple, pretty, multiplatform molecular viewer for chemists.
Documentation
use bevy::prelude::*;

/// Marker component for lights that should follow the camera
#[derive(Component)]
pub struct CameraFollowLight {
    /// Offset from the camera position
    pub offset: Vec3,
}

fn set_ambient_light(mut ambient_light: ResMut<AmbientLight>) {
    ambient_light.brightness = 100.0;
    ambient_light.color = Color::srgb(0.9, 0.95, 1.0); // Slightly bluish
}

fn spawn_lights(mut commands: Commands) {
    // Key light - main directional light that follows the camera
    commands.spawn((
        DirectionalLight {
            shadows_enabled: true,
            illuminance: 2000.0,
            color: Color::srgb(1.0, 0.98, 0.95), // Warm sunlight
            ..default()
        },
        Transform::from_xyz(5.0, 10.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
        CameraFollowLight {
            offset: Vec3::new(5.0, 10.0, 10.0),
        },
    ));

    // Fill light - softer light from the side that follows the camera
    commands.spawn((
        DirectionalLight {
            shadows_enabled: false,
            illuminance: 800.0,
            color: Color::srgb(0.95, 0.97, 1.0), // Cool fill light
            ..default()
        },
        Transform::from_xyz(-5.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
        CameraFollowLight {
            offset: Vec3::new(-5.0, 5.0, 5.0),
        },
    ));

    // Back light - subtle rim lighting from behind (static)
    commands.spawn((
        DirectionalLight {
            shadows_enabled: false,
            illuminance: 500.0,
            color: Color::srgb(1.0, 0.94, 0.80), // Warm back light
            ..default()
        },
        Transform::from_xyz(0.0, 3.0, -10.0).looking_at(Vec3::ZERO, Vec3::Y),
    ));
}

pub struct LightPlugin;

impl Plugin for LightPlugin {
    fn build(&self, app: &mut App) {
        app.insert_resource(ClearColor(Color::srgb_u8(20, 20, 25))); // Dark background
        app.add_systems(Startup, (set_ambient_light, spawn_lights));
    }
}