nightshade-api 0.47.0

Procedural high level API for the nightshade game engine
Documentation
//! Cloth simulation: a GPU-simulated grid that drapes, swings, and ripples in
//! the wind. Spawn a sheet, pin it, and let the solver run.

use nightshade::ecs::cloth::commands::{
    reset_cloth as engine_reset_cloth, spawn_cloth as engine_spawn_cloth,
};
use nightshade::ecs::cloth::components::{Cloth, ClothPinning};
use nightshade::prelude::*;

/// Spawns a cloth sheet `width` by `height` at `position`, subdivided into a
/// `columns` by `rows` grid and pinned along its top row so it hangs like a
/// banner. Move and rotate the entity to place the sheet; keep its scale at one.
pub fn spawn_cloth(
    world: &mut World,
    position: Vec3,
    width: f32,
    height: f32,
    columns: u32,
    rows: u32,
) -> Entity {
    let cloth = Cloth {
        columns,
        rows,
        width,
        height,
        pinning: ClothPinning::TopRow,
        ..Default::default()
    };
    engine_spawn_cloth(world, cloth, position, "api::cloth".to_string())
}

/// Resets a cloth entity to its flat rest shape, undoing accumulated motion.
pub fn reset_cloth(world: &mut World, entity: Entity) {
    engine_reset_cloth(world, entity);
}

/// Sets the global wind that pushes every cloth: a `direction` and a `strength`.
pub fn set_wind(world: &mut World, direction: Vec3, strength: f32) {
    world.resources.wind.direction = direction;
    world.resources.wind.strength = strength;
}