Skip to content

Commit

Permalink
content: Allow cornell-box to vary in size.
Browse files Browse the repository at this point in the history
I think I might also want to shrink the default size, but that will
be a separate change.
  • Loading branch information
kpreid committed Jan 22, 2025
1 parent 5616f17 commit 4d67212
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions all-is-cubes-content/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ impl UniverseTemplate {
Dungeon => Some(demo_dungeon(&mut universe, p.take().unwrap(), params).await),
Islands => Some(islands(&mut universe, p.take().unwrap(), params).await),
Atrium => Some(atrium(&mut universe, p.take().unwrap()).await),
CornellBox => Some(cornell_box()),
CornellBox => Some(cornell_box(
params.size.unwrap_or(GridSize::new(57, 57, 57)),
)),
MengerSponge => Some(menger_sponge(&mut universe, 4)),
LightingBench => Some(
all_is_cubes::content::testing::lighting_bench_space(
Expand Down Expand Up @@ -381,12 +383,14 @@ async fn islands(
}

#[rustfmt::skip]
fn cornell_box() -> Result<Space, InGenError> {
// Coordinates are set up based on this dimension because, being blocks, we're not
// going to *exactly* replicate the original data, but we might want to adjust the
// scale to something else entirely.
let box_size: GridSizeCoord = 55;
let box_size_c: GridCoordinate = 55;
fn cornell_box(requested_size: GridSize) -> Result<Space, InGenError> {
let box_size: GridSizeCoord =
(requested_size.width
.min(requested_size.height)
.min(requested_size.depth))
.saturating_sub(2)
.min(64); // TODO: tie this to max light chart size
let box_size_c: GridCoordinate = box_size as GridCoordinate;

// Add one block to all sides for wall thickness.
let bounds = GridAab::from_lower_size(
Expand Down Expand Up @@ -414,15 +418,20 @@ fn cornell_box() -> Result<Space, InGenError> {
let light: Block = Block::builder()
.display_name("Light")
.color(Rgba::new(1.0, 1.0, 1.0, 1.0))
.light_emission(Rgb::ONE * 8.0)
.light_emission(Rgb::ONE * (1.07 * (box_size as f32).sqrt()))
.build();

// Floor.
space.fill_uniform(GridAab::from_lower_size([0, -1, 0], [box_size, 1, box_size]), &white)?;
// Ceiling.
space.fill_uniform(GridAab::from_lower_size([0, box_size_c, 0], [box_size, 1, box_size]), &white)?;
// Light in ceiling.
space.fill_uniform(GridAab::from_lower_upper([21, box_size_c, 23], [34, box_size_c + 1, 33]), &light)?;
space.fill_uniform(
GridAab::from_lower_upper([21, 55, 23], [34, 55, 33])
.multiply(box_size_c).divide(55)
.abut(Face6::PY, 1).unwrap(),
&light,
)?;
// Back wall.
space.fill_uniform(GridAab::from_lower_size([0, 0, -1], [box_size, box_size, 1]), &white)?;
// Right wall (green).
Expand All @@ -431,9 +440,9 @@ fn cornell_box() -> Result<Space, InGenError> {
space.fill_uniform(GridAab::from_lower_size([-1, 0, 0], [1, box_size, box_size]), &red)?;

// Block #1
space.fill_uniform(GridAab::from_lower_size([29, 0, 36], [16, 16, 15]), &white)?;
space.fill_uniform(GridAab::from_lower_size([29, 0, 36], [16, 16, 15]).multiply(box_size_c).divide(55), &white)?;
// Block #2
space.fill_uniform(GridAab::from_lower_size([10, 0, 13], [18, 33, 15]), &white)?;
space.fill_uniform(GridAab::from_lower_size([10, 0, 13], [18, 33, 15]).multiply(box_size_c).divide(55), &white)?;

// This won't figure out the correct light values, but it will reset everything to
// uninitialized, which will help the updater get going faster.
Expand Down

0 comments on commit 4d67212

Please sign in to comment.