-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.rs
69 lines (59 loc) · 1.99 KB
/
generate.rs
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use std::fs::File;
use bevy::math::{IVec3, Vec3};
use bevy::utils::{default, HashMap};
use morningstar::data::*;
use nalgebra::Vector3;
use prism::shape::*;
use prism::*;
use smallvec::SmallVec;
fn main() {
let volume = Cuboid::new(Vector3::new(100.0, 100.0, 2.5));
let points = volume.packed_points(PackedSettings {
particle_settings: 0.5.into(),
max_iters: 500,
cutoff: 0.01,
density: 1.1,
});
println!("Iters: {}", points.iters);
println!("Penetration: {}", points.max_penetration);
let mut particles = points
.iter()
.map(|&p| Particle {
position: p.into(),
..default()
})
.collect::<Vec<_>>();
let bond_radius = 1.5;
let mut bonds = vec![];
let mut grid: HashMap<IVec3, SmallVec<[(u32, Vec3); 8]>> = HashMap::new();
for (i, p) in particles.iter().enumerate() {
let ix = (p.position / bond_radius).as_ivec3();
grid.entry(ix).or_default().push((i as u32, p.position));
}
for (i, p) in particles.iter_mut().enumerate() {
let ix = (p.position / bond_radius).as_ivec3();
p.bond_start = bonds.len() as u32;
for x in -1..=1 {
for y in -1..=1 {
for z in -1..=1 {
let ix = ix + IVec3::new(x, y, z);
if let Some(neighbors) = grid.get(&ix) {
for &(n, pos) in neighbors {
if n != i as u32 && (pos - p.position).length() < bond_radius {
bonds.push(Bond { other_particle: n });
p.bond_count += 1;
}
}
}
}
}
}
}
for p in &mut particles {
if p.position.x.abs() > 93.0 {
p.fixed = true;
}
}
let file = File::create("scenes/panel-big.pts").unwrap();
ron::ser::to_writer(file, &Particles { particles, bonds }).unwrap();
}