RustToDust/tools/vehicles/build_mammoth.py

460 lines
19 KiB
Python

"""Build the Mammoth (Heavy 8x8 Armored Fire Support Rig) chassis GLB, manifest.json, and preview."""
from __future__ import annotations
import math
import sys
from pathlib import Path
import bmesh
from mathutils import Matrix
sys.path.insert(0, str(Path(__file__).resolve().parent))
import vehicle_common as vc # noqa: E402
def build_mammoth() -> dict:
vc.reset_scene()
vc.ensure_materials()
root = vc.make_empty("MammothRoot")
chassis = vc.make_empty("Chassis", parent=root)
# Dimensions (Blender: -Y forward, +Z up, +X left)
axle_ys = [
("f1", -1.90, True),
("f2", -0.74, True),
("r1", 0.74, False),
("r2", 1.90, False),
]
track_x = 1.24
wheel_r = 0.52
wheel_w = 0.38
axle_z = wheel_r
# --- 1. Heavy Armored Lower Tub, Frame Rails, Axles & Suspension ---
vc.make_box("lower_tub", (1.64, 4.94, 0.62), "gunmetal", parent=chassis, location=(0.0, -0.02, 0.82), bevel=0.015)
for side in (-1.0, 1.0):
tag = "L" if side > 0 else "R"
vc.make_box(f"frame_rail_{tag}", (0.14, 5.10, 0.20), "gunmetal", parent=chassis, location=(side * 0.68, -0.04, 0.62), bevel=0.01)
# Side fuel tank / battery box tucked between front and rear tandem wheel pairs
vc.make_box(f"side_stowage_{tag}", (0.42, 0.72, 0.44), "olive_armor", parent=chassis, location=(side * 1.08, 0.0, 0.86), bevel=0.01)
# Crew entry door + boarding ladder step on mid-hull flank
vc.make_box(f"crew_step_{tag}", (0.16, 0.44, 0.06), "gunmetal", parent=chassis, location=(side * 1.32, 0.0, 0.62), bevel=0.006)
vc.make_box(f"crew_door_{tag}", (0.06, 0.56, 0.78), "olive_armor", parent=chassis, location=(side * 1.28, 0.0, 1.24), bevel=0.008)
for idx, (a_tag, y_ax, _) in enumerate(axle_ys):
vc.make_tube_part(
f"axle_tube_{a_tag}",
0.075,
0.075,
track_x * 1.68,
segments=10,
mat_name="gunmetal",
parent=chassis,
location=(-track_x * 0.84, y_ax, axle_z),
rotation_deg=(0.0, 90.0, 0.0),
)
vc.make_box(f"diff_{a_tag}", (0.34, 0.34, 0.28), "gunmetal", parent=chassis, location=(0.0, y_ax, axle_z), bevel=0.012)
for side in (-1.0, 1.0):
s_tag = "L" if side > 0 else "R"
vc.make_ram_span(
f"strut_{a_tag}_{s_tag}",
[side * 0.74, y_ax, 1.02],
[side * 0.98, y_ax, axle_z + 0.02],
body_r=0.040,
rod_r=0.022,
parent=chassis,
mat_barrel="gunmetal",
mat_rod="copper_rad",
coil_rings=0,
)
# --- 2. Faceted 8x8 Armored Hull & Bolted Sponson Plates (Brokkr plate.v0) ---
hull_pts = [
# Lower hull belt above wheel arches (z = 1.14)
[-1.34, -2.26, 1.14], [1.34, -2.26, 1.14],
[-1.36, 2.26, 1.14], [1.36, 2.26, 1.14],
# Lower nose & lower tail bevel
[-1.08, -2.62, 1.02], [1.08, -2.62, 1.02],
[-1.12, 2.64, 1.12], [1.12, 2.64, 1.12],
# Roof deck (z = 1.66)
[-1.14, -1.78, 1.66], [1.14, -1.78, 1.66],
[-1.16, 1.88, 1.66], [1.16, 1.88, 1.66],
]
plates_doc = {
"schema": "brokkr.plates.v0",
"plates": [
{
"name": "mammoth_hull",
"mat": "olive_armor",
"bevel": 0.016,
"sides": "one",
"mirror": False,
"points": hull_pts,
"clad": {
"mat": "olive_armor",
"facets": [{"n": [0.0, -0.55, 0.83], "cos": 0.85}, {"n": [0.0, 0.0, 1.0], "cos": 0.95}],
"min_area": 0.18,
"lifts": [0.008, 0.014],
"inset": 0.06,
"gap": 0.018,
"split": 0.88,
"seed": 801,
"bolt_r": 0.014,
"bolt_mat": "gunmetal",
"bevel": 0.004,
},
},
# Sloped upper side cheek armor with bolted applique panels
{
"name": "mammoth_side_cheek",
"mat": "olive_armor",
"bevel": 0.010,
"sides": "both",
"mirror": False,
"slab": {
"at": [1.26, -0.04, 1.40],
"normal": [0.92, 0.0, 0.38],
"up": [-0.38, 0.0, 0.92],
"right": [0.0, -1.0, 0.0],
"outline": [[-1.92, -0.24], [1.92, -0.24], [1.72, 0.24], [-1.72, 0.24]],
"thick": 0.055,
"taper": 0.015,
"back": 0.92,
},
"clad": {
"mat": "olive_armor",
"facets": "outer",
"min_area": 0.14,
"lifts": [0.008, 0.014],
"inset": 0.05,
"gap": 0.016,
"split": 0.72,
"seed": 802,
"bolt_r": 0.013,
"bolt_mat": "gunmetal",
"bevel": 0.004,
},
"fits": [
{"kind": "bolts", "inset": 0.025, "spacing": 0.36, "mat": "gunmetal", "params": "r=0.013"},
],
},
],
}
vc.make_plates(plates_doc, parent=chassis)
# Heavy flared wheel arches over all 4 wheel stations on each side
for side in (-1.0, 1.0):
tag = "L" if side > 0 else "R"
for a_tag, y_ax, _ in axle_ys:
# Top arch cap + angled front/rear lip flaps
vc.make_box(f"arch_top_{tag}_{a_tag}", (0.44, 0.68, 0.07), "olive_armor", parent=chassis, location=(side * 1.24, y_ax, 1.14), bevel=0.008)
vc.make_box(f"arch_f_{tag}_{a_tag}", (0.44, 0.32, 0.07), "olive_armor", parent=chassis, location=(side * 1.24, y_ax - 0.44, 1.02), rotation_deg=(36.0, 0.0, 0.0), bevel=0.008)
vc.make_box(f"arch_r_{tag}_{a_tag}", (0.44, 0.32, 0.07), "olive_armor", parent=chassis, location=(side * 1.24, y_ax + 0.44, 1.02), rotation_deg=(-36.0, 0.0, 0.0), bevel=0.008)
# Front nose recessed grille, armored headlights, driver slit & rearview mirrors
vc.make_box("front_grille", (1.22, 0.14, 0.34), "socket_bay", parent=chassis, location=(0.0, -2.58, 0.96), bevel=0.008)
for k in range(4):
vc.make_box(f"grille_slat_{k}", (1.16, 0.06, 0.03), "gunmetal", parent=chassis, location=(0.0, -2.64, 0.86 + k * 0.07), bevel=0.003)
vc.make_box("driver_periscope", (0.56, 0.16, 0.10), "smoked_glass", parent=chassis, location=(-0.38, -1.96, 1.60), rotation_deg=(-22.0, 0.0, 0.0), bevel=0.005)
for side in (-1.0, 1.0):
tag = "L" if side > 0 else "R"
vc.make_box(f"headlight_box_{tag}", (0.24, 0.16, 0.16), "gunmetal", parent=chassis, location=(side * 0.88, -2.54, 1.06), bevel=0.008)
vc.make_box(f"headlight_lens_{tag}", (0.16, 0.04, 0.09), "smoked_glass", parent=chassis, location=(side * 0.88, -2.62, 1.06), bevel=0.003)
vc.make_box(f"tow_shackle_{tag}", (0.08, 0.14, 0.14), "signal_orange", parent=chassis, location=(side * 0.48, -2.66, 0.72), bevel=0.006)
# Rear corner tail light housing
vc.make_box(f"taillight_{tag}", (0.18, 0.12, 0.14), "gunmetal", parent=chassis, location=(side * 1.04, 2.58, 1.12), bevel=0.006)
# --- 3. Reinforced Front Dozer Ram Plow ---
plow_root = vc.make_empty("dozer_plow", parent=chassis, location=(0.0, -2.86, 0.56))
def build_plow_blade(bm: bmesh.types.BMesh) -> None:
# Curved multi-segment scoop profile extruded across width X = [-1.34, +1.34]
prof = [
(-0.34, -0.34), # bottom cutting lip
(-0.22, -0.14),
(-0.04, 0.06),
(0.02, 0.26),
(-0.14, 0.42), # upper curved spill lip
(0.04, 0.42),
(0.14, 0.22),
(0.08, -0.12),
(-0.18, -0.34),
]
hw = 1.34
verts_l = [bm.verts.new((hw, y, z)) for (y, z) in prof]
verts_r = [bm.verts.new((-hw, y, z)) for (y, z) in prof]
n = len(prof)
for i in range(n):
j = (i + 1) % n
bm.faces.new([verts_l[i], verts_l[j], verts_r[j], verts_r[i]])
bm.faces.new(verts_l)
bm.faces.new(list(reversed(verts_r)))
vc.make_bmesh_object("plow_moldboard", build_plow_blade, "olive_armor", parent=plow_root, bevel=0.012)
vc.make_box("plow_cutting_edge", (2.72, 0.16, 0.07), "gunmetal", parent=plow_root, location=(0.0, -0.28, -0.32), rotation_deg=(16.0, 0.0, 0.0), bevel=0.006)
for gx in (-0.98, -0.48, 0.0, 0.48, 0.98):
vc.make_box(f"plow_rib_{gx:.2f}", (0.07, 0.18, 0.62), "gunmetal", parent=plow_root, location=(gx, 0.12, 0.06), bevel=0.006)
for side in (-1.0, 1.0):
tag = "L" if side > 0 else "R"
vc.make_box(f"plow_wing_{tag}", (0.12, 0.48, 0.68), "olive_armor", parent=plow_root, location=(side * 1.36, -0.10, 0.04), bevel=0.008)
# Hydraulic push arms + tilt rams
vc.make_box(f"plow_pusharm_{tag}", (0.12, 0.72, 0.14), "gunmetal", parent=chassis, location=(side * 0.66, -2.56, 0.56), bevel=0.008)
vc.make_ram_span(
f"plow_ram_{tag}",
[side * 0.66, -2.42, 0.90],
[side * 0.66, -2.80, 0.76],
body_r=0.042,
rod_r=0.024,
parent=chassis,
mat_barrel="gunmetal",
mat_rod="copper_rad",
)
# --- 4. Rear Diesel Exhaust Stacks ---
for side in (-1.0, 1.0):
tag = "L" if side > 0 else "R"
vc.make_swept_tube(
f"exhaust_stack_{tag}",
[
[side * 1.02, 2.24, 1.36],
[side * 1.06, 2.46, 1.56],
[side * 1.06, 2.46, 2.18],
[side * 1.06, 2.60, 2.30],
],
0.062,
segments=12,
mat_name="gunmetal",
parent=chassis,
fillet_r=0.06,
)
vc.make_tube_part(
f"exhaust_shield_{tag}",
0.09,
0.09,
0.52,
segments=10,
inner0=0.078,
inner1=0.078,
mat_name="copper_rad",
parent=chassis,
location=(side * 1.06, 2.46, 1.62),
)
# --- 5. 8x8 Wheels & Front 4 Steering Knuckles ---
joints_manifest: list[dict] = []
for a_tag, y_ax, steerable in axle_ys:
for side, s_tag in ((1.0, "l"), (-1.0, "r")):
j_suffix = f"{a_tag[0]}{s_tag}{a_tag[1]}" # fl1, fr1, fl2, fr2, rl1, rr1, rl2, rr2
if steerable:
steer_id = f"joint.steer_{j_suffix}"
steer_node = vc.make_empty(steer_id, parent=chassis, location=(side * 0.98, y_ax, axle_z))
vc.tag_joint(steer_node, steer_id, [0.0, 1.0, 0.0], -28.0, 28.0)
joints_manifest.append({"id": steer_id, "axis": [0.0, 1.0, 0.0], "min": -28.0, "max": 28.0})
vc.make_box(f"knuckle_{j_suffix}", (0.10, 0.14, 0.22), "gunmetal", parent=steer_node, bevel=0.006)
wheel_parent = steer_node
wheel_loc = (side * (track_x - 0.98), 0.0, 0.0)
else:
vc.make_box(f"hub_carrier_{j_suffix}", (0.12, 0.16, 0.22), "gunmetal", parent=chassis, location=(side * 0.98, y_ax, axle_z), bevel=0.006)
wheel_parent = chassis
wheel_loc = (side * track_x, y_ax, axle_z)
wheel_id = f"joint.wheel_{j_suffix}"
wheel_pivot = vc.make_knobby_wheel(
wheel_id,
radius=wheel_r,
width=wheel_w,
parent=wheel_parent,
location=wheel_loc,
tread_lugs=14,
rim_segments=16,
side_sign=int(side),
)
wheel_pivot.name = wheel_id
vc.tag_joint(wheel_pivot, wheel_id, [1.0, 0.0, 0.0], -360.0, 360.0)
joints_manifest.append({"id": wheel_id, "axis": [1.0, 0.0, 0.0], "min": -360.0, "max": 360.0})
# --- 6. Broad Angular Central Turret (joint.turret_yaw) ---
turret_pivot = vc.make_empty("joint.turret_yaw", parent=chassis, location=(0.0, -0.18, 1.66))
vc.tag_joint(turret_pivot, "joint.turret_yaw", [0.0, 1.0, 0.0], -180.0, 180.0)
joints_manifest.append({"id": "joint.turret_yaw", "axis": [0.0, 1.0, 0.0], "min": -180.0, "max": 180.0})
vc.make_tube_part("turret_race", 0.74, 0.80, 0.08, segments=24, mat_name="gunmetal", parent=turret_pivot)
turret_pts = [
[-0.64, -0.78, 0.08], [0.64, -0.78, 0.08],
[0.84, -0.22, 0.08], [0.76, 0.94, 0.08],
[-0.76, 0.94, 0.08], [-0.84, -0.22, 0.08],
[-0.50, -0.60, 0.56], [0.50, -0.60, 0.56],
[0.64, -0.14, 0.56], [0.58, 0.78, 0.56],
[-0.58, 0.78, 0.56], [-0.64, -0.14, 0.56],
]
turret_doc = {
"schema": "brokkr.plates.v0",
"plates": [
{
"name": "mammoth_turret_shell",
"mat": "olive_armor",
"bevel": 0.015,
"sides": "one",
"mirror": False,
"points": turret_pts,
},
{
"name": "mammoth_turret_cheek",
"mat": "olive_armor",
"bevel": 0.008,
"sides": "both",
"mirror": False,
"slab": {
"at": [0.74, 0.14, 0.30],
"normal": [0.94, 0.0, 0.34],
"up": [-0.34, 0.0, 0.94],
"right": [0.0, -1.0, 0.0],
"outline": [[-0.52, -0.16], [0.52, -0.16], [0.42, 0.16], [-0.42, 0.16]],
"thick": 0.045,
"taper": 0.012,
"back": 0.92,
},
"fits": [
{"kind": "bolts", "inset": 0.02, "spacing": 0.24, "mat": "gunmetal", "params": "r=0.012"},
],
},
],
}
vc.make_plates(turret_doc, parent=turret_pivot)
# Turret bustle stowage rack, commander hatch, optics & smoke launchers
vc.make_box("turret_bustle", (1.08, 0.42, 0.34), "gunmetal", parent=turret_pivot, location=(0.0, 0.98, 0.34), bevel=0.01)
vc.make_tube_part("commander_cupola", 0.22, 0.24, 0.10, segments=14, mat_name="olive_armor", parent=turret_pivot, location=(-0.28, 0.34, 0.56))
vc.make_box("turret_sight", (0.20, 0.22, 0.14), "smoked_glass", parent=turret_pivot, location=(0.24, -0.38, 0.62), bevel=0.008)
vc.make_box("turret_mantlet_bar", (0.94, 0.18, 0.18), "gunmetal", parent=turret_pivot, location=(0.0, -0.70, 0.30), bevel=0.01)
for side in (-1.0, 1.0):
tag = "L" if side > 0 else "R"
for k in range(3):
vc.make_tube_part(
f"smoke_tube_{tag}_{k}",
0.032,
0.032,
0.18,
segments=8,
mat_name="gunmetal",
parent=turret_pivot,
location=(side * 0.78, 0.42 + k * 0.10, 0.34),
rotation_deg=(-58.0, 0.0, side * 22.0),
)
# --- 7. Visible Exterior Hardpoints (4x6 Dorsal Grid) ---
# 1) hp.armor.glacis (0,0, 4x1)
vc.add_hardpoint_slot(
"hp.armor.glacis",
"armor",
parent=chassis,
location=(0.0, -2.20, 1.36),
rotation_deg=(53.0, 0.0, 0.0),
size=(1.54, 0.38, 0.10),
plinth_depth=0.03,
)
# 2) hp.weapon.bow (0,1, 1x1) on front-left bow deck
vc.make_box("bow_weapon_plinth", (0.48, 0.50, 0.12), "gunmetal", parent=chassis, location=(0.88, -1.48, 1.62), bevel=0.008)
vc.add_hardpoint_slot(
"hp.weapon.bow",
"weapon",
parent=chassis,
location=(0.88, -1.48, 1.68),
rotation_deg=(0.0, 0.0, 0.0),
size=(0.46, 0.46, 0.09),
)
# 3) hp.weapon.turret_l (1,1, 1x2) & 4) hp.weapon.turret_r (2,1, 1x2) on turret roof
vc.add_hardpoint_slot(
"hp.weapon.turret_l",
"weapon",
parent=turret_pivot,
location=(0.36, -0.10, 0.57),
rotation_deg=(0.0, 0.0, 0.0),
size=(0.56, 0.56, 0.10),
)
vc.add_hardpoint_slot(
"hp.weapon.turret_r",
"weapon",
parent=turret_pivot,
location=(-0.36, -0.10, 0.57),
rotation_deg=(0.0, 0.0, 0.0),
size=(0.56, 0.56, 0.10),
)
# 5) hp.armor.flanks (3,1, 1x2) on right (-X) upper cheek
vc.add_hardpoint_slot(
"hp.armor.flanks",
"armor",
parent=chassis,
location=(-1.32, -0.16, 1.38),
rotation_deg=(90.0, 0.0, -90.0),
size=(1.12, 0.32, 0.10),
)
# 6) hp.engine.rear (1,3, 2x2)
vc.add_hardpoint_slot(
"hp.engine.rear",
"engine",
parent=chassis,
location=(0.0, 1.34, 1.66),
rotation_deg=(0.0, 0.0, 0.0),
size=(1.14, 1.04, 0.14),
)
# 7 & 8) hp.radiator.l (0,4, 1x2) & hp.radiator.r (3,4, 1x2)
vc.add_hardpoint_slot(
"hp.radiator.l",
"radiator",
parent=chassis,
location=(1.28, 1.40, 1.38),
rotation_deg=(90.0, 0.0, 90.0),
size=(0.98, 0.44, 0.12),
)
vc.add_hardpoint_slot(
"hp.radiator.r",
"radiator",
parent=chassis,
location=(-1.28, 1.40, 1.38),
rotation_deg=(90.0, 0.0, -90.0),
size=(0.98, 0.44, 0.12),
)
# --- 8. Export GLB, Manifest & Preview ---
glb_path = vc.ASSETS_VEHICLES_DIR / "mammoth" / "mammoth.glb"
manifest_path = vc.ASSETS_VEHICLES_DIR / "mammoth" / "manifest.json"
preview_path = vc.PREVIEWS_DIR / "mammoth_preview.png"
tri_count, bounds = vc.export_vehicle_glb(glb_path, root=root)
vc.write_manifest(
manifest_path,
vehicle_id="mammoth",
name="Mammoth",
vehicle_class="Heavy 8x8 Armored Fire Support Rig",
grid_width=4,
grid_height=6,
mask=[
"####",
"####",
"####",
"####",
"####",
"####",
],
hardpoints=[
{"id": "hp.armor.glacis", "kind": "armor", "x": 0, "y": 0, "w": 4, "h": 1, "modelNodeId": "hp.armor.glacis"},
{"id": "hp.weapon.bow", "kind": "weapon", "x": 0, "y": 1, "w": 1, "h": 1, "modelNodeId": "hp.weapon.bow"},
{"id": "hp.weapon.turret_l", "kind": "weapon", "x": 1, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.weapon.turret_l"},
{"id": "hp.weapon.turret_r", "kind": "weapon", "x": 2, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.weapon.turret_r"},
{"id": "hp.armor.flanks", "kind": "armor", "x": 3, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.armor.flanks"},
{"id": "hp.engine.rear", "kind": "engine", "x": 1, "y": 3, "w": 2, "h": 2, "modelNodeId": "hp.engine.rear"},
{"id": "hp.radiator.l", "kind": "radiator", "x": 0, "y": 4, "w": 1, "h": 2, "modelNodeId": "hp.radiator.l"},
{"id": "hp.radiator.r", "kind": "radiator", "x": 3, "y": 4, "w": 1, "h": 2, "modelNodeId": "hp.radiator.r"},
],
joints=joints_manifest,
bounds=bounds,
tri_count=tri_count,
)
vc.render_four_panel_preview(preview_path)
print(f"[mammoth] tris={tri_count} bounds={bounds} glb={glb_path}")
return {"id": "mammoth", "tris": tri_count, "bounds": bounds}
if __name__ == "__main__":
build_mammoth()