use glam::IVec3;
use roxlap_render::DebrisSystem;
use roxlap_scene::islands::{detect_islands, FracturePattern, DEFAULT_ISLAND_BUDGET};
use roxlap_scene::{BakeMode, GridTransform, Scene, VoxColor};
const STONE: VoxColor = VoxColor(0x80_8a_7a_5a);
const CRYSTAL: VoxColor = VoxColor(0x80_50_c8_e8);
const CRYSTAL_MATERIAL: u8 = 1;
fn main() {
let mut scene = Scene::new();
let grid = scene.add_grid(GridTransform::identity());
let g = scene.grid_mut(grid).expect("grid just added");
g.set_rect(IVec3::new(0, 0, 200), IVec3::new(63, 63, 255), Some(STONE));
g.set_rect(
IVec3::new(30, 30, 160),
IVec3::new(31, 31, 199),
Some(STONE),
);
g.set_rect(
IVec3::new(32, 30, 158),
IVec3::new(48, 31, 159),
Some(STONE),
);
g.set_rect(
IVec3::new(44, 30, 154),
IVec3::new(47, 31, 157),
Some(CRYSTAL),
);
g.bake(BakeMode::Directional);
let g = scene.grid_mut(grid).expect("grid");
g.set_sphere(IVec3::new(33, 30, 158), 4, None);
let islands = detect_islands(
g,
IVec3::new(29, 26, 154), IVec3::new(37, 34, 162),
DEFAULT_ISLAND_BUDGET,
);
for isl in &islands {
println!(
"island: {} voxels, bbox {:?}..{:?}",
isl.voxels.len(),
isl.bbox.0,
isl.bbox.1
);
}
let mut debris = DebrisSystem::new();
debris.set_fracture_patterns(
&[(CRYSTAL.rgb_part(), CRYSTAL_MATERIAL)],
&[
(0, FracturePattern::Chunks { cell: 6 }),
(CRYSTAL_MATERIAL, FracturePattern::Shards { plates: 3 }),
],
);
for isl in islands {
debris.spawn_island(&mut scene, grid, isl, BakeMode::Directional);
}
println!("falling fragments: {}", debris.debris_count());
for _ in 0..600 {
debris.update(&scene, 1.0 / 60.0);
for hit in debris.drain_impacts() {
println!(
"impact at z={:.1} @ {:.1} u/s -> {} burst sites",
hit.pos.z,
hit.speed,
hit.burst_sites().len(),
);
}
}
assert_eq!(debris.debris_count(), 0, "everything landed");
}