veloren_world/site/settlement/building/
mod.rs1pub mod archetype;
2pub mod skeleton;
3
4pub use self::{
6 archetype::{Archetype, house::House, keep::Keep},
7 skeleton::*,
8};
9
10use crate::IndexRef;
11use common::{calendar::Calendar, terrain::Block};
12use rand::prelude::*;
13use serde::Deserialize;
14use vek::*;
15
16#[derive(Deserialize)]
17pub struct Colors {
18 pub archetype: archetype::Colors,
19}
20
21pub struct Building<A: Archetype> {
22 skel: Skeleton<A::Attr>,
23 archetype: A,
24 origin: Vec3<i32>,
25}
26
27impl<A: Archetype> Building<A> {
28 pub fn generate(rng: &mut impl Rng, origin: Vec3<i32>, calendar: Option<&Calendar>) -> Self
29 where
30 A: Sized,
31 {
32 let (archetype, skel) = A::generate(rng, calendar);
33 Self {
34 skel,
35 archetype,
36 origin,
37 }
38 }
39
40 pub fn bounds_2d(&self) -> Aabr<i32> {
41 let b = self.skel.bounds();
42 Aabr {
43 min: Vec2::from(self.origin) + b.min,
44 max: Vec2::from(self.origin) + b.max,
45 }
46 }
47
48 pub fn bounds(&self) -> Aabb<i32> {
49 let aabr = self.bounds_2d();
50 Aabb {
51 min: Vec3::from(aabr.min) + Vec3::unit_z() * (self.origin.z - 8),
52 max: Vec3::from(aabr.max) + Vec3::unit_z() * (self.origin.z + 48),
53 }
54 }
55
56 pub fn sample(&self, index: IndexRef, pos: Vec3<i32>) -> Option<Block> {
57 let rpos = pos - self.origin;
58 self.skel
59 .sample_closest(
60 rpos,
61 |pos, dist, bound_offset, center_offset, ori, branch| {
62 self.archetype.draw(
63 index,
64 pos,
65 dist,
66 bound_offset,
67 center_offset,
68 rpos.z,
69 ori,
70 branch.locus,
71 branch.len,
72 &branch.attr,
73 )
74 },
75 )
76 .finish()
77 }
78}