use super::*;
impl Default for SkyscraperConfig {
fn default() -> Self {
Self {
width: 14.0,
depth: 12.0,
floors: 14,
floor_height: 3.2,
has_spire: true,
frame_material: PbrMaterial::metallic(Color::rgb(132, 140, 152), 0.34),
glass_material: PbrMaterial::glass(Color::rgb(112, 168, 212), 0.08)
.with_surface_detail(SurfaceDetailMode::ArchitecturalFacade),
}
}
}
impl Default for CourtyardConfig {
fn default() -> Self {
Self {
width: 20.0,
depth: 20.0,
wall_height: 4.5,
columns_per_side: 5,
stone_material: PbrMaterial::dielectric(Color::rgb(198, 188, 170), 0.78),
floor_material: PbrMaterial::dielectric(Color::rgb(154, 150, 142), 0.84),
}
}
}
impl Default for BridgeConfig {
fn default() -> Self {
Self {
span: 32.0,
width: 8.0,
deck_height: 4.0,
arch_rise: 6.5,
hanger_count: 9,
structure_material: PbrMaterial::metallic(Color::rgb(164, 58, 52), 0.42),
deck_material: PbrMaterial::dielectric(Color::rgb(78, 82, 88), 0.86)
.with_surface_detail(SurfaceDetailMode::RoadSurface),
}
}
}
impl Default for ArchwayConfig {
fn default() -> Self {
Self {
opening_width: 3.6,
spring_height: 3.0,
thickness: 1.1,
pier_width: 0.9,
style: ArchStyle::Roman,
material: PbrMaterial::dielectric(Color::rgb(206, 196, 178), 0.76),
}
}
}
impl Default for StaircaseConfig {
fn default() -> Self {
Self {
steps: 12,
width: 2.2,
step_rise: 0.22,
step_run: 0.34,
is_spiral: false,
spiral_turns_rad: TAU,
step_material: PbrMaterial::dielectric(Color::rgb(184, 176, 164), 0.72),
rail_material: PbrMaterial::metallic(Color::rgb(68, 72, 78), 0.28),
}
}
}
impl Default for ColumnConfig {
fn default() -> Self {
Self {
radius: 0.36,
height: 4.8,
segments: 18,
material: PbrMaterial::dielectric(Color::rgb(224, 218, 206), 0.65),
}
}
}
impl Default for BalconyConfig {
fn default() -> Self {
Self {
width: 4.4,
depth: 1.6,
rail_height: 1.05,
baluster_count: 10,
slab_material: PbrMaterial::dielectric(Color::rgb(192, 186, 176), 0.78),
rail_material: PbrMaterial::metallic(Color::rgb(52, 56, 62), 0.32),
}
}
}
impl Default for VehicleConfig {
fn default() -> Self {
Self::sports_car(PbrMaterial::metallic(Color::rgb(214, 34, 42), 0.16))
}
}
impl VehicleConfig {
#[must_use]
pub fn sports_car(paint: PbrMaterial) -> Self {
Self {
style: VehicleBodyStyle::SportsCar,
length: 4.5,
width: 1.98,
height: 1.18,
wheel_radius: 0.36,
wheel_width: 0.28,
paint,
has_spoiler: true,
}
}
#[must_use]
pub fn sedan(paint: PbrMaterial) -> Self {
Self {
style: VehicleBodyStyle::Sedan,
length: 4.7,
width: 1.86,
height: 1.44,
wheel_radius: 0.35,
wheel_width: 0.24,
paint,
has_spoiler: false,
}
}
#[must_use]
pub fn suv(paint: PbrMaterial) -> Self {
Self {
style: VehicleBodyStyle::Suv,
length: 4.9,
width: 2.02,
height: 1.82,
wheel_radius: 0.42,
wheel_width: 0.28,
paint,
has_spoiler: false,
}
}
#[must_use]
pub fn truck(paint: PbrMaterial) -> Self {
Self {
style: VehicleBodyStyle::Truck,
length: 5.4,
width: 2.04,
height: 1.88,
wheel_radius: 0.44,
wheel_width: 0.3,
paint,
has_spoiler: false,
}
}
}
impl ArchKit {
#[must_use]
pub fn skyscraper(config: &SkyscraperConfig) -> Mesh3D {
let w: f32 = sanitize_scalar(config.get_width(), 14.0).abs().max(4.0);
let d: f32 = sanitize_scalar(config.get_depth(), 12.0).abs().max(4.0);
let floors: u32 = config.get_floors().clamp(3, 80);
let fh: f32 = sanitize_scalar(config.get_floor_height(), 3.2)
.abs()
.max(2.0);
let frame_m: PbrMaterial = config.get_frame_material();
let glass_m: PbrMaterial = config.get_glass_material();
let mut parts: Vec<Mesh3D> = Vec::with_capacity((floors as usize) + 16);
let podium_h: f32 = fh * 1.5;
parts.push(placed_box(
Vec3::new(0.0, podium_h * 0.5, 0.0),
Vec3::new(w * 1.12, podium_h, d * 1.12),
frame_m,
));
parts.push(placed_box(
Vec3::new(0.0, podium_h * 0.65, d * 0.56 + 0.9),
Vec3::new(w * 0.44, 0.32, 2.0),
frame_m,
));
let main_floors: u32 = (floors - 2).max(1);
let main_h: f32 = (main_floors as f32) * fh;
let main_y0: f32 = podium_h;
parts.push(placed_box(
Vec3::new(0.0, main_y0 + main_h * 0.5, 0.0),
Vec3::new(w * 0.94, main_h, d * 0.94),
glass_m,
));
let mullion_w: f32 = (w * 0.045).clamp(0.25, 0.8);
for &(sx, sz) in &[(-1.0_f32, -1.0_f32), (1.0, -1.0), (1.0, 1.0), (-1.0, 1.0)] {
parts.push(placed_box(
Vec3::new(sx * w * 0.48, main_y0 + main_h * 0.5, sz * d * 0.48),
Vec3::new(mullion_w, main_h, mullion_w),
frame_m,
));
}
let ledge_step: u32 = if main_floors > 18 { 2 } else { 1 };
let mut f_idx: u32 = 1;
while f_idx <= main_floors {
let ly: f32 = main_y0 + (f_idx as f32) * fh;
parts.push(placed_box(
Vec3::new(0.0, ly, 0.0),
Vec3::new(w * 1.01, 0.22, d * 1.01),
frame_m,
));
f_idx += ledge_step;
}
let crown_h: f32 = fh * 1.8;
let crown_y0: f32 = main_y0 + main_h;
parts.push(placed_box(
Vec3::new(0.0, crown_y0 + crown_h * 0.5, 0.0),
Vec3::new(w * 0.72, crown_h, d * 0.72),
glass_m,
));
parts.push(placed_box(
Vec3::new(0.0, crown_y0 + crown_h + 0.25, 0.0),
Vec3::new(w * 0.78, 0.5, d * 0.78),
frame_m,
));
let roof_y: f32 = crown_y0 + crown_h + 0.5;
let mech_h: f32 = fh * 0.9;
parts.push(placed_box(
Vec3::new(0.0, roof_y + mech_h * 0.5, 0.0),
Vec3::new(w * 0.42, mech_h, d * 0.42),
frame_m,
));
if config.get_has_spire() {
let spire_h: f32 = (main_h * 0.24).clamp(4.0, 22.0);
parts.push(placed_cylinder(
Vec3::new(0.0, roof_y + mech_h + spire_h * 0.5, 0.0),
(w * 0.05).clamp(0.18, 0.65),
0.04,
spire_h,
12,
frame_m,
));
}
merge_meshes(&parts, ARCH_NAME_SKYSCRAPER)
}
#[must_use]
pub fn column(config: &ColumnConfig) -> Mesh3D {
let r: f32 = sanitize_scalar(config.get_radius(), 0.36).abs().max(0.08);
let h: f32 = sanitize_scalar(config.get_height(), 4.8).abs().max(0.8);
let segs: u32 = config.get_segments().clamp(8, 48);
let mat: PbrMaterial = config.get_material();
let plinth_h: f32 = h * 0.08;
let abacus_h: f32 = h * 0.07;
let shaft_y0: f32 = plinth_h;
let shaft_y1: f32 = h - abacus_h;
let shaft_h: f32 = (shaft_y1 - shaft_y0).max(0.2);
let profile: Vec<Vec2> = vec![
Vec2::new(0.0, shaft_y0),
Vec2::new(r * 1.24, shaft_y0),
Vec2::new(r * 1.26, shaft_y0 + shaft_h * 0.03),
Vec2::new(r * 1.08, shaft_y0 + shaft_h * 0.06),
Vec2::new(r * 1.15, shaft_y0 + shaft_h * 0.09),
Vec2::new(r * 1.0, shaft_y0 + shaft_h * 0.13),
Vec2::new(r * 1.02, shaft_y0 + shaft_h * 0.42),
Vec2::new(r * 0.94, shaft_y0 + shaft_h * 0.72),
Vec2::new(r * 0.86, shaft_y0 + shaft_h * 0.9),
Vec2::new(r * 0.95, shaft_y0 + shaft_h * 0.93),
Vec2::new(r * 1.24, shaft_y1),
Vec2::new(0.0, shaft_y1),
];
let mut shaft: Mesh3D = lathe_revolve(&profile, segs, TAU);
shaft.set_material(mat);
let plinth: Mesh3D = placed_box(
Vec3::new(0.0, plinth_h * 0.5, 0.0),
Vec3::new(r * 2.7, plinth_h, r * 2.7),
mat,
);
let abacus: Mesh3D = placed_box(
Vec3::new(0.0, h - abacus_h * 0.5, 0.0),
Vec3::new(r * 2.65, abacus_h, r * 2.65),
mat,
);
merge_meshes(&[plinth, shaft, abacus], ARCH_NAME_COLUMN)
}
#[must_use]
pub fn archway(config: &ArchwayConfig) -> Mesh3D {
let open_w: f32 = sanitize_scalar(config.get_opening_width(), 3.6)
.abs()
.max(0.8);
let spring_h: f32 = sanitize_scalar(config.get_spring_height(), 3.0)
.abs()
.max(0.8);
let thick: f32 = sanitize_scalar(config.get_thickness(), 1.1).abs().max(0.2);
let pier_w: f32 = sanitize_scalar(config.get_pier_width(), 0.9)
.abs()
.max(0.25);
let mat: PbrMaterial = config.get_material();
let inner_r: f32 = open_w * 0.5;
let outer_r: f32 = inner_r + pier_w;
let pier_x: f32 = inner_r + pier_w * 0.5;
let mut parts: Vec<Mesh3D> = Vec::with_capacity(12);
for sx in [-1.0_f32, 1.0_f32] {
parts.push(placed_box(
Vec3::new(sx * pier_x, 0.2, 0.0),
Vec3::new(pier_w * 1.18, 0.4, thick * 1.18),
mat,
));
parts.push(placed_box(
Vec3::new(sx * pier_x, spring_h * 0.5, 0.0),
Vec3::new(pier_w, spring_h, thick),
mat,
));
parts.push(placed_box(
Vec3::new(sx * pier_x, spring_h - 0.14, 0.0),
Vec3::new(pier_w * 1.16, 0.28, thick * 1.16),
mat,
));
}
let arc_segs: usize = 16;
let gothic_peak: f32 = if matches!(config.get_style(), ArchStyle::Gothic) {
inner_r * 0.35
} else {
0.0
};
let mut arch_poly: Vec<Vec2> = Vec::with_capacity((arc_segs + 1) * 2);
for i in 0..=arc_segs {
let frac: f32 = (i as f32) / (arc_segs as f32);
let ang: f32 = frac * PI;
let peak_factor: f32 = 1.0 - (frac * 2.0 - 1.0).abs();
let x: f32 = outer_r * ang.cos();
let y: f32 = spring_h + outer_r * ang.sin() + gothic_peak * peak_factor;
arch_poly.push(Vec2::new(x, y));
}
for i in (0..=arc_segs).rev() {
let frac: f32 = (i as f32) / (arc_segs as f32);
let ang: f32 = frac * PI;
let peak_factor: f32 = 1.0 - (frac * 2.0 - 1.0).abs();
let x: f32 = inner_r * ang.cos();
let y: f32 = spring_h + inner_r * ang.sin() + gothic_peak * peak_factor;
arch_poly.push(Vec2::new(x, y));
}
let mut arch_ring: Mesh3D = extrude_profile(&arch_poly, thick, 0.04, 2);
arch_ring.set_material(mat);
parts.push(arch_ring);
let apex_y: f32 = spring_h + outer_r + gothic_peak;
parts.push(placed_box(
Vec3::new(0.0, apex_y - pier_w * 0.45, 0.0),
Vec3::new(pier_w * 0.62, pier_w * 1.12, thick * 1.2),
mat,
));
parts.push(placed_box(
Vec3::new(0.0, apex_y + 0.22, 0.0),
Vec3::new(outer_r * 2.15, 0.44, thick * 1.24),
mat,
));
merge_meshes(&parts, ARCH_NAME_ARCHWAY)
}
#[must_use]
pub fn courtyard(config: &CourtyardConfig) -> Mesh3D {
let w: f32 = sanitize_scalar(config.get_width(), 20.0).abs().max(6.0);
let d: f32 = sanitize_scalar(config.get_depth(), 20.0).abs().max(6.0);
let wh: f32 = sanitize_scalar(config.get_wall_height(), 4.5)
.abs()
.max(2.0);
let cols: u32 = config.get_columns_per_side().clamp(2, 12);
let stone: PbrMaterial = config.get_stone_material();
let floor: PbrMaterial = config.get_floor_material();
let mut parts: Vec<Mesh3D> = Vec::with_capacity((cols as usize) * 4 + 16);
parts.push(placed_box(
Vec3::new(0.0, 0.12, 0.0),
Vec3::new(w, 0.24, d),
floor,
));
parts.push(placed_box(
Vec3::new(0.0, 0.36, 0.0),
Vec3::new(w * 0.24, 0.24, d * 0.24),
stone,
));
let col_cfg: ColumnConfig = ColumnConfig {
radius: 0.26,
height: wh - 0.55,
segments: 12,
material: stone,
};
let base_col: Mesh3D = Self::column(&col_cfg);
let hx: f32 = w * 0.46;
let hz: f32 = d * 0.46;
for &(cx, cz) in &[(-hx, -hz), (hx, -hz), (hx, hz), (-hx, hz)] {
parts.push(placed_box(
Vec3::new(cx, wh * 0.5 + 0.12, cz),
Vec3::new(1.5, wh + 0.24, 1.5),
stone,
));
parts.push(placed_box(
Vec3::new(cx, wh + 0.42, cz),
Vec3::new(1.85, 0.36, 1.85),
stone,
));
}
for i in 1..cols {
let frac: f32 = (i as f32) / (cols as f32);
let x_pos: f32 = -hx + frac * (hx * 2.0);
let z_pos: f32 = -hz + frac * (hz * 2.0);
parts.push(place_part(
&base_col,
Vec3::new(x_pos, 0.24, -hz),
Quat::identity(),
Vec3::splat(1.0),
stone,
));
parts.push(place_part(
&base_col,
Vec3::new(x_pos, 0.24, hz),
Quat::identity(),
Vec3::splat(1.0),
stone,
));
parts.push(place_part(
&base_col,
Vec3::new(-hx, 0.24, z_pos),
Quat::identity(),
Vec3::splat(1.0),
stone,
));
parts.push(place_part(
&base_col,
Vec3::new(hx, 0.24, z_pos),
Quat::identity(),
Vec3::splat(1.0),
stone,
));
}
let beam_y: f32 = wh - 0.08;
parts.push(placed_box(
Vec3::new(0.0, beam_y, -hz),
Vec3::new(w * 0.96, 0.48, 0.85),
stone,
));
parts.push(placed_box(
Vec3::new(0.0, beam_y, hz),
Vec3::new(w * 0.96, 0.48, 0.85),
stone,
));
parts.push(placed_box(
Vec3::new(-hx, beam_y, 0.0),
Vec3::new(0.85, 0.48, d * 0.96),
stone,
));
parts.push(placed_box(
Vec3::new(hx, beam_y, 0.0),
Vec3::new(0.85, 0.48, d * 0.96),
stone,
));
merge_meshes(&parts, ARCH_NAME_COURTYARD)
}
#[must_use]
pub fn bridge(config: &BridgeConfig) -> Mesh3D {
let span: f32 = sanitize_scalar(config.get_span(), 32.0).abs().max(8.0);
let width: f32 = sanitize_scalar(config.get_width(), 8.0).abs().max(2.5);
let deck_h: f32 = sanitize_scalar(config.get_deck_height(), 4.0)
.abs()
.max(1.2);
let rise: f32 = sanitize_scalar(config.get_arch_rise(), 6.5).abs().max(1.2);
let hangers: u32 = config.get_hanger_count().clamp(3, 24);
let struct_m: PbrMaterial = config.get_structure_material();
let deck_m: PbrMaterial = config.get_deck_material();
let half_s: f32 = span * 0.5;
let half_w: f32 = width * 0.5;
let mut parts: Vec<Mesh3D> = Vec::with_capacity((hangers as usize) * 2 + 16);
parts.push(placed_box(
Vec3::new(0.0, deck_h, 0.0),
Vec3::new(width, 0.55, span),
deck_m,
));
for sz in [-1.0_f32, 1.0_f32] {
parts.push(placed_box(
Vec3::new(0.0, deck_h * 0.5, sz * (half_s - 0.9)),
Vec3::new(width * 1.06, deck_h, 1.8),
struct_m,
));
}
let rib_profile: Vec<Vec2> = circle_profile_2d(0.28, 8);
for sx in [-1.0_f32, 1.0_f32] {
let x_pos: f32 = sx * (half_w - 0.32);
parts.push(placed_box(
Vec3::new(x_pos, deck_h + 0.72, 0.0),
Vec3::new(0.16, 0.92, span),
struct_m,
));
let mut ctrl: Vec<Vec3> = Vec::with_capacity(9);
for i in 0..=8 {
let u: f32 = (i as f32) / 8.0;
let z: f32 = (u - 0.5) * (span - 1.6);
let parabola: f32 = 4.0 * u * (1.0 - u);
let y: f32 = deck_h + 0.25 + rise * parabola;
ctrl.push(Vec3::new(x_pos, y, z));
}
let arch_spline: Spline3D = Spline3D::catmull_rom(ctrl, false);
let mut rib: Mesh3D = sweep_along_spline(&rib_profile, &arch_spline, 24, &[]);
rib.set_material(struct_m);
parts.push(rib);
for h_idx in 1..=hangers {
let u: f32 = (h_idx as f32) / ((hangers + 1) as f32);
let z: f32 = (u - 0.5) * (span - 1.6);
let arch_y: f32 = deck_h + 0.25 + rise * 4.0 * u * (1.0 - u);
let h_len: f32 = (arch_y - deck_h).max(0.2);
parts.push(placed_cylinder(
Vec3::new(x_pos, deck_h + h_len * 0.5, z),
0.07,
0.07,
h_len,
6,
struct_m,
));
}
}
merge_meshes(&parts, ARCH_NAME_BRIDGE)
}
#[must_use]
pub fn staircase(config: &StaircaseConfig) -> Mesh3D {
let steps: u32 = config.get_steps().clamp(3, 64);
let width: f32 = sanitize_scalar(config.get_width(), 2.2).abs().max(0.6);
let rise: f32 = sanitize_scalar(config.get_step_rise(), 0.22)
.abs()
.max(0.08);
let run: f32 = sanitize_scalar(config.get_step_run(), 0.34).abs().max(0.12);
let step_m: PbrMaterial = config.get_step_material();
let rail_m: PbrMaterial = config.get_rail_material();
let mut parts: Vec<Mesh3D> = Vec::with_capacity((steps as usize) * 3 + 8);
let rail_profile: Vec<Vec2> = circle_profile_2d(0.045, 8);
if config.get_is_spiral() {
let total_h: f32 = (steps as f32) * rise;
let turns: f32 = sanitize_scalar(config.get_spiral_turns_rad(), TAU)
.abs()
.max(1.0);
let pole_r: f32 = (width * 0.14).clamp(0.1, 0.35);
parts.push(placed_cylinder(
Vec3::new(0.0, total_h * 0.5, 0.0),
pole_r,
pole_r,
total_h + 1.0,
14,
rail_m,
));
let mut rail_pts: Vec<Vec3> = Vec::with_capacity((steps as usize) + 1);
let tread_base: Mesh3D =
rounded_box(Vec3::new(width, rise * 0.45, run * 1.1), 0.015, 1);
for i in 0..steps {
let frac: f32 = (i as f32) / (steps as f32);
let ang: f32 = frac * turns;
let y: f32 = ((i as f32) + 0.5) * rise;
let radial_mid: f32 = pole_r + width * 0.5;
let pos: Vec3 = Vec3::new(radial_mid * ang.cos(), y, radial_mid * ang.sin());
let rot: Quat = Quat::from_axis_angle(Vec3::new(0.0, 1.0, 0.0), -ang);
parts.push(place_part(&tread_base, pos, rot, Vec3::splat(1.0), step_m));
let outer_r: f32 = pole_r + width * 0.94;
let post_x: f32 = outer_r * ang.cos();
let post_z: f32 = outer_r * ang.sin();
parts.push(placed_cylinder(
Vec3::new(post_x, y + 0.48, post_z),
0.028,
0.028,
0.96,
6,
rail_m,
));
rail_pts.push(Vec3::new(post_x, y + 0.96, post_z));
}
let rail_spline: Spline3D = Spline3D::catmull_rom(rail_pts, false);
let mut rail: Mesh3D = sweep_along_spline(&rail_profile, &rail_spline, steps * 2, &[]);
rail.set_material(rail_m);
parts.push(rail);
} else {
let half_w: f32 = width * 0.5;
let mut left_pts: Vec<Vec3> = Vec::with_capacity(steps as usize);
let mut right_pts: Vec<Vec3> = Vec::with_capacity(steps as usize);
for i in 0..steps {
let y_top: f32 = ((i + 1) as f32) * rise;
let z_pos: f32 = ((i as f32) + 0.5) * run;
parts.push(placed_box(
Vec3::new(0.0, y_top - rise * 0.5, z_pos),
Vec3::new(width, rise, run),
step_m,
));
if i % 2 == 0 || i + 1 == steps {
for sx in [-1.0_f32, 1.0_f32] {
parts.push(placed_cylinder(
Vec3::new(sx * (half_w - 0.08), y_top + 0.46, z_pos),
0.028,
0.028,
0.92,
6,
rail_m,
));
}
}
left_pts.push(Vec3::new(-(half_w - 0.08), y_top + 0.92, z_pos));
right_pts.push(Vec3::new(half_w - 0.08, y_top + 0.92, z_pos));
}
for pts in [left_pts, right_pts] {
let sp: Spline3D = Spline3D::catmull_rom(pts, false);
let mut rail: Mesh3D = sweep_along_spline(&rail_profile, &sp, steps, &[]);
rail.set_material(rail_m);
parts.push(rail);
}
}
merge_meshes(&parts, ARCH_NAME_STAIRCASE)
}
#[must_use]
pub fn balcony(config: &BalconyConfig) -> Mesh3D {
let w: f32 = sanitize_scalar(config.get_width(), 4.4).abs().max(1.0);
let d: f32 = sanitize_scalar(config.get_depth(), 1.6).abs().max(0.5);
let rh: f32 = sanitize_scalar(config.get_rail_height(), 1.05)
.abs()
.max(0.5);
let bals: u32 = config.get_baluster_count().clamp(2, 24);
let slab_m: PbrMaterial = config.get_slab_material();
let rail_m: PbrMaterial = config.get_rail_material();
let mut parts: Vec<Mesh3D> = Vec::with_capacity((bals as usize) + 14);
parts.push(placed_box(
Vec3::new(0.0, 0.12, d * 0.5),
Vec3::new(w, 0.24, d),
slab_m,
));
let half_w: f32 = w * 0.5;
for sx in [-0.72_f32, 0.0, 0.72] {
parts.push(placed_box(
Vec3::new(sx * half_w, -0.18, d * 0.35),
Vec3::new(0.24, 0.36, d * 0.65),
slab_m,
));
}
let rail_y: f32 = 0.24 + rh;
parts.push(placed_box(
Vec3::new(0.0, rail_y, d - 0.08),
Vec3::new(w, 0.08, 0.12),
rail_m,
));
for sx in [-1.0_f32, 1.0_f32] {
parts.push(placed_box(
Vec3::new(sx * (half_w - 0.06), rail_y, d * 0.5),
Vec3::new(0.12, 0.08, d),
rail_m,
));
parts.push(placed_box(
Vec3::new(sx * (half_w - 0.06), 0.24 + rh * 0.5, d - 0.08),
Vec3::new(0.12, rh, 0.12),
rail_m,
));
}
for i in 1..=bals {
let frac: f32 = (i as f32) / ((bals + 1) as f32);
let x: f32 = -half_w + 0.12 + frac * (w - 0.24);
parts.push(placed_cylinder(
Vec3::new(x, 0.24 + rh * 0.5, d - 0.08),
0.025,
0.025,
rh,
6,
rail_m,
));
}
merge_meshes(&parts, ARCH_NAME_BALCONY)
}
}
impl VehicleKit {
#[must_use]
pub fn build(config: &VehicleConfig) -> Mesh3D {
let len: f32 = sanitize_scalar(config.get_length(), 4.5).abs().max(2.0);
let wid: f32 = sanitize_scalar(config.get_width(), 1.9).abs().max(1.0);
let hgt: f32 = sanitize_scalar(config.get_height(), 1.35).abs().max(0.8);
let wr: f32 = sanitize_scalar(config.get_wheel_radius(), 0.36)
.abs()
.clamp(0.18, hgt * 0.45);
let ww: f32 = sanitize_scalar(config.get_wheel_width(), 0.26)
.abs()
.clamp(0.1, wid * 0.3);
let paint: PbrMaterial = config.get_paint();
let glass_m: PbrMaterial = PbrMaterial::glass(Color::rgb(34, 48, 66), 0.06);
let tire_m: PbrMaterial = PbrMaterial::dielectric(Color::rgb(28, 30, 34), 0.88);
let rim_m: PbrMaterial = PbrMaterial::metallic(Color::rgb(208, 214, 222), 0.18);
let trim_m: PbrMaterial = PbrMaterial::dielectric(Color::rgb(42, 46, 52), 0.62);
let head_m: PbrMaterial = PbrMaterial::neon(Color::rgb(255, 248, 224), 2.2);
let tail_m: PbrMaterial = PbrMaterial::neon(Color::rgb(255, 28, 34), 2.0);
let clearance: f32 = wr * 0.45;
let belt_y: f32 = clearance + (hgt - clearance) * 0.48;
let half_l: f32 = len * 0.5;
let body_profile: Vec<Vec2> = match config.get_style() {
VehicleBodyStyle::SportsCar => vec![
Vec2::new(-half_l, clearance + 0.06),
Vec2::new(half_l, clearance),
Vec2::new(half_l, belt_y * 0.82),
Vec2::new(half_l * 0.32, belt_y * 0.96),
Vec2::new(-half_l * 0.48, belt_y * 1.04),
Vec2::new(-half_l, belt_y * 0.96),
],
VehicleBodyStyle::Sedan => vec![
Vec2::new(-half_l, clearance),
Vec2::new(half_l, clearance),
Vec2::new(half_l, belt_y * 0.86),
Vec2::new(half_l * 0.38, belt_y),
Vec2::new(-half_l * 0.65, belt_y),
Vec2::new(-half_l, belt_y * 0.9),
],
VehicleBodyStyle::Suv => vec![
Vec2::new(-half_l, clearance),
Vec2::new(half_l, clearance),
Vec2::new(half_l, belt_y * 0.92),
Vec2::new(half_l * 0.4, belt_y * 1.04),
Vec2::new(-half_l, belt_y * 1.04),
],
VehicleBodyStyle::Truck => vec![
Vec2::new(-half_l, clearance),
Vec2::new(half_l, clearance),
Vec2::new(half_l, belt_y * 0.92),
Vec2::new(half_l * 0.36, belt_y * 1.02),
Vec2::new(-half_l, belt_y * 0.98),
],
};
let cabin_profile: Vec<Vec2> = match config.get_style() {
VehicleBodyStyle::SportsCar => vec![
Vec2::new(-half_l * 0.58, belt_y * 0.96),
Vec2::new(half_l * 0.34, belt_y * 0.92),
Vec2::new(half_l * 0.04, hgt),
Vec2::new(-half_l * 0.34, hgt * 0.98),
],
VehicleBodyStyle::Sedan => vec![
Vec2::new(-half_l * 0.62, belt_y * 0.96),
Vec2::new(half_l * 0.36, belt_y * 0.96),
Vec2::new(half_l * 0.14, hgt),
Vec2::new(-half_l * 0.42, hgt),
],
VehicleBodyStyle::Suv => vec![
Vec2::new(-half_l * 0.94, belt_y),
Vec2::new(half_l * 0.38, belt_y),
Vec2::new(half_l * 0.16, hgt),
Vec2::new(-half_l * 0.88, hgt),
],
VehicleBodyStyle::Truck => vec![
Vec2::new(-half_l * 0.12, belt_y * 0.98),
Vec2::new(half_l * 0.36, belt_y * 0.98),
Vec2::new(half_l * 0.16, hgt),
Vec2::new(-half_l * 0.1, hgt),
],
};
let side_to_forward: Quat = Quat::from_axis_angle(Vec3::new(0.0, 1.0, 0.0), -FRAC_PI_2);
let raw_body: Mesh3D = extrude_profile(&body_profile, wid * 0.96, 0.08, 2);
let raw_cabin: Mesh3D = extrude_profile(&cabin_profile, wid * 0.8, 0.06, 2);
let mut parts: Vec<Mesh3D> = Vec::with_capacity(28);
parts.push(place_part(
&raw_body,
Vec3::zero(),
side_to_forward,
Vec3::splat(1.0),
paint,
));
parts.push(place_part(
&raw_cabin,
Vec3::zero(),
side_to_forward,
Vec3::splat(1.0),
glass_m,
));
let wheel_rot: Quat = Quat::from_axis_angle(Vec3::new(0.0, 0.0, 1.0), FRAC_PI_2);
let tire_proto: Mesh3D = torus(wr * 0.72, wr * 0.28, 18, 10);
let rim_proto: Mesh3D = cylinder(wr * 0.62, wr * 0.62, ww * 0.85, 14, true);
let track_x: f32 = wid * 0.5 - ww * 0.38;
let front_z: f32 = half_l * 0.62;
let rear_z: f32 = -half_l * 0.62;
for &(wx, wz) in &[
(-track_x, front_z),
(track_x, front_z),
(-track_x, rear_z),
(track_x, rear_z),
] {
let center: Vec3 = Vec3::new(wx, wr, wz);
parts.push(place_part(
&tire_proto,
center,
wheel_rot,
Vec3::new(1.0, ww / (wr * 0.56).max(0.05), 1.0),
tire_m,
));
parts.push(place_part(
&rim_proto,
center,
wheel_rot,
Vec3::splat(1.0),
rim_m,
));
}
parts.push(placed_box(
Vec3::new(0.0, clearance + 0.14, half_l + 0.04),
Vec3::new(wid * 0.92, 0.22, 0.16),
trim_m,
));
parts.push(placed_box(
Vec3::new(0.0, clearance + 0.16, -half_l - 0.04),
Vec3::new(wid * 0.92, 0.24, 0.16),
trim_m,
));
for sx in [-1.0_f32, 1.0_f32] {
parts.push(placed_box(
Vec3::new(sx * wid * 0.34, belt_y * 0.72, half_l + 0.02),
Vec3::new(wid * 0.18, 0.11, 0.08),
head_m,
));
parts.push(placed_box(
Vec3::new(sx * wid * 0.34, belt_y * 0.78, -half_l - 0.02),
Vec3::new(wid * 0.22, 0.1, 0.08),
tail_m,
));
parts.push(placed_box(
Vec3::new(sx * (wid * 0.5 + 0.07), belt_y + 0.08, half_l * 0.22),
Vec3::new(0.14, 0.09, 0.18),
paint,
));
}
if config.get_has_spoiler() {
let wing_y: f32 = belt_y * 1.18;
let wing_z: f32 = -half_l * 0.88;
parts.push(placed_box(
Vec3::new(0.0, wing_y, wing_z),
Vec3::new(wid * 0.96, 0.06, 0.28),
paint,
));
for sx in [-1.0_f32, 1.0_f32] {
parts.push(placed_box(
Vec3::new(sx * wid * 0.32, (belt_y + wing_y) * 0.5, wing_z),
Vec3::new(0.06, (wing_y - belt_y * 0.9).max(0.12), 0.18),
trim_m,
));
}
}
if matches!(config.get_style(), VehicleBodyStyle::Suv) {
for sx in [-1.0_f32, 1.0_f32] {
parts.push(placed_box(
Vec3::new(sx * wid * 0.34, hgt + 0.06, -half_l * 0.28),
Vec3::new(0.06, 0.08, len * 0.48),
trim_m,
));
}
}
if matches!(config.get_style(), VehicleBodyStyle::Truck) {
for sx in [-1.0_f32, 1.0_f32] {
parts.push(placed_box(
Vec3::new(sx * wid * 0.44, belt_y + 0.08, -half_l * 0.56),
Vec3::new(0.1, 0.24, half_l * 0.84),
paint,
));
}
parts.push(placed_box(
Vec3::new(0.0, belt_y + 0.06, -half_l + 0.05),
Vec3::new(wid * 0.92, 0.22, 0.1),
paint,
));
}
let name: &str = match config.get_style() {
VehicleBodyStyle::SportsCar => VEHICLE_NAME_SPORTS,
VehicleBodyStyle::Sedan => VEHICLE_NAME_SEDAN,
VehicleBodyStyle::Suv => VEHICLE_NAME_SUV,
VehicleBodyStyle::Truck => VEHICLE_NAME_TRUCK,
};
merge_meshes(&parts, name)
}
#[must_use]
pub fn sports_car(paint: PbrMaterial) -> Mesh3D {
let cfg: VehicleConfig = VehicleConfig::sports_car(paint);
Self::build(&cfg)
}
#[must_use]
pub fn sedan(paint: PbrMaterial) -> Mesh3D {
let cfg: VehicleConfig = VehicleConfig::sedan(paint);
Self::build(&cfg)
}
#[must_use]
pub fn suv(paint: PbrMaterial) -> Mesh3D {
let cfg: VehicleConfig = VehicleConfig::suv(paint);
Self::build(&cfg)
}
#[must_use]
pub fn truck(paint: PbrMaterial) -> Mesh3D {
let cfg: VehicleConfig = VehicleConfig::truck(paint);
Self::build(&cfg)
}
}