1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! 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;
}