nightshade 0.37.0

A cross-platform data-oriented game engine.
Documentation
//! Scene-wide wind state and cloth mesh bookkeeping.

use crate::ecs::cloth::components::Cloth;
use nalgebra_glm::Vec3;
use std::collections::HashMap;

/// Global wind affecting every [`Cloth`](super::components::Cloth) in the
/// scene, stored at `world.resources.wind`.
///
/// The cloth simulation samples this each frame: the steady component is
/// `direction * strength`, gusts add a sinusoidal surge of up to
/// `gust_strength` at `gust_frequency` cycles per second, and `turbulence`
/// adds spatially varying swirl. Each cloth scales the result by its own
/// `wind_response`.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Wind {
    /// Direction the wind blows toward. Does not need to be normalized.
    pub direction: Vec3,
    /// Steady wind speed in m/s.
    pub strength: f32,
    /// Peak additional speed of gusts in m/s.
    pub gust_strength: f32,
    /// Gust cycles per second.
    pub gust_frequency: f32,
    /// Magnitude of spatially varying swirl in m/s.
    pub turbulence: f32,
}

impl Default for Wind {
    fn default() -> Self {
        Self {
            direction: Vec3::new(0.42, 0.0, 0.91),
            strength: 3.0,
            gust_strength: 2.0,
            gust_frequency: 0.5,
            turbulence: 1.5,
        }
    }
}

/// Per-entity snapshots of [`Cloth`] components, used by
/// [`sync_cloth_meshes_system`](super::systems::sync_cloth_meshes_system)
/// to detect changes and re-register the grid mesh and bounding volume.
#[derive(Default)]
pub struct ClothMeshSync {
    pub snapshots: HashMap<freecs::Entity, Cloth>,
}