More plot generation work

This commit is contained in:
Joshua Barretto 2021-03-01 23:43:26 +00:00
parent 66dc24dab1
commit 7bf62d59fd
3 changed files with 17 additions and 17 deletions

View File

@ -68,8 +68,8 @@ impl Fill {
pub trait Structure { pub trait Structure {
fn render<F: FnMut(Primitive) -> Id<Primitive>, G: FnMut(Fill)>( fn render<F: FnMut(Primitive) -> Id<Primitive>, G: FnMut(Fill)>(
&self, &self,
emit_prim: F, prim: F,
emit_fill: G, fill: G,
) {} ) {}
// Generate a primitive tree and fills for this structure // Generate a primitive tree and fills for this structure

View File

@ -500,7 +500,7 @@ impl Site {
// } // }
// }, // },
// _ => {}, // _ => {},
// } // }
// }); // });
} }
} }

View File

@ -28,32 +28,32 @@ impl House {
impl Structure for House { impl Structure for House {
fn render<F: FnMut(Primitive) -> Id<Primitive>, G: FnMut(Fill)>( fn render<F: FnMut(Primitive) -> Id<Primitive>, G: FnMut(Fill)>(
&self, &self,
mut emit_prim: F, mut prim: F,
mut emit_fill: G, mut fill: G,
) { ) {
let storey = 8; let storey = 8;
let roof = storey * self.levels as i32; let roof = storey * self.levels as i32;
let foundations = 8; let foundations = 8;
// Walls // Walls
let wall = emit_prim(Primitive::Aabb(Aabb { let wall = prim(Primitive::Aabb(Aabb {
min: Vec3::new(self.bounds.min.x, self.bounds.min.y, self.alt - foundations), min: Vec3::new(self.bounds.min.x, self.bounds.min.y, self.alt - foundations),
max: Vec3::new(self.bounds.max.x, self.bounds.max.y, self.alt + roof), max: Vec3::new(self.bounds.max.x, self.bounds.max.y, self.alt + roof),
})); }));
let inner = emit_prim(Primitive::Aabb(Aabb { let inner = prim(Primitive::Aabb(Aabb {
min: Vec3::new(self.bounds.min.x + 1, self.bounds.min.y + 1, self.alt + 0), min: Vec3::new(self.bounds.min.x + 1, self.bounds.min.y + 1, self.alt + 0),
max: Vec3::new(self.bounds.max.x - 1, self.bounds.max.y - 1, self.alt + roof), max: Vec3::new(self.bounds.max.x - 1, self.bounds.max.y - 1, self.alt + roof),
})); }));
emit_fill(Fill { fill(Fill {
prim: emit_prim(Primitive::Xor(wall, inner)), prim: prim(Primitive::Xor(wall, inner)),
block: Block::new(BlockKind::Rock, Rgb::new(181, 170, 148)), block: Block::new(BlockKind::Rock, Rgb::new(181, 170, 148)),
}); });
// Floor // Floor
for i in 0..self.levels + 1 { for i in 0..self.levels + 1 {
let height = storey * i as i32; let height = storey * i as i32;
emit_fill(Fill { fill(Fill {
prim: emit_prim(Primitive::Aabb(Aabb { prim: prim(Primitive::Aabb(Aabb {
min: Vec3::new(self.bounds.min.x, self.bounds.min.y, self.alt + height + 0), min: Vec3::new(self.bounds.min.x, self.bounds.min.y, self.alt + height + 0),
max: Vec3::new(self.bounds.max.x, self.bounds.max.y, self.alt + height + 1), max: Vec3::new(self.bounds.max.x, self.bounds.max.y, self.alt + height + 1),
})), })),
@ -64,8 +64,8 @@ impl Structure for House {
// Corner pillars // Corner pillars
for &rpos in SQUARE_4.iter() { for &rpos in SQUARE_4.iter() {
let pos = self.bounds.min + (self.bounds.max - self.bounds.min) * rpos; let pos = self.bounds.min + (self.bounds.max - self.bounds.min) * rpos;
emit_fill(Fill { fill(Fill {
prim: emit_prim(Primitive::Aabb(Aabb { prim: prim(Primitive::Aabb(Aabb {
min: Vec3::new(pos.x - 1, pos.y - 1, self.alt - foundations), min: Vec3::new(pos.x - 1, pos.y - 1, self.alt - foundations),
max: Vec3::new(pos.x + 1, pos.y + 1, self.alt + roof), max: Vec3::new(pos.x + 1, pos.y + 1, self.alt + roof),
})), })),
@ -78,8 +78,8 @@ impl Structure for House {
let roof_height = (self.bounds.min - self.bounds.max).map(|e| e.abs()).reduce_min() / 2 + roof_lip; let roof_height = (self.bounds.min - self.bounds.max).map(|e| e.abs()).reduce_min() / 2 + roof_lip;
// Roof // Roof
emit_fill(Fill { fill(Fill {
prim: emit_prim(Primitive::Pyramid { prim: prim(Primitive::Pyramid {
aabb: Aabb { aabb: Aabb {
min: Vec3::new(self.bounds.min.x - roof_lip, self.bounds.min.y - roof_lip, self.alt + roof), min: Vec3::new(self.bounds.min.x - roof_lip, self.bounds.min.y - roof_lip, self.alt + roof),
max: Vec3::new(self.bounds.max.x + roof_lip, self.bounds.max.y + roof_lip, self.alt + roof + roof_height), max: Vec3::new(self.bounds.max.x + roof_lip, self.bounds.max.y + roof_lip, self.alt + roof + roof_height),
@ -90,8 +90,8 @@ impl Structure for House {
}); });
// Foundations // Foundations
emit_fill(Fill { fill(Fill {
prim: emit_prim(Primitive::Aabb(Aabb { prim: prim(Primitive::Aabb(Aabb {
min: Vec3::new(self.bounds.min.x - 1, self.bounds.min.y - 1, self.alt - foundations), min: Vec3::new(self.bounds.min.x - 1, self.bounds.min.y - 1, self.alt - foundations),
max: Vec3::new(self.bounds.max.x + 1, self.bounds.max.y + 1, self.alt + 1), max: Vec3::new(self.bounds.max.x + 1, self.bounds.max.y + 1, self.alt + 1),
})), })),