RustToDust/tools/vehicles/build_mule.py

299 lines
12 KiB
Python

"""Build the Mule (Medium 6x6 Armored Gun Truck) chassis GLB, manifest.json, and preview."""
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import vehicle_common as vc # noqa: E402
def build_mule() -> dict:
vc.reset_scene()
vc.ensure_materials()
root = vc.make_empty("MuleRoot")
chassis = vc.make_empty("Chassis", parent=root)
front_y = -1.52
mid_y = 0.88
rear_y = 1.92
track_x = 0.98
wheel_r = 0.49
wheel_w = 0.34
axle_z = wheel_r
# --- 1. Ladder Frame Rails, Axles, Bumper & Fuel Tanks ---
for side in (-1.0, 1.0):
tag = "L" if side > 0 else "R"
vc.make_box(f"frame_rail_{tag}", (0.12, 4.54, 0.18), "gunmetal", parent=chassis, location=(side * 0.46, 0.0, 0.62), bevel=0.008)
# Side cylindrical fuel tanks (Brokkr mechanical kit tank)
vc.make_kit_part(
f"fuel_tank_{tag}",
"mechanical",
"tank",
{"radius": 0.19, "length": 0.86, "segments": 14},
mat_name="gunmetal",
parent=chassis,
location=(side * 0.78, -0.35, 0.56),
rotation_deg=(90.0, 0.0, 0.0),
)
for idx, y_ax in enumerate((front_y, mid_y, rear_y)):
vc.make_tube_part(
f"axle_tube_{idx}",
0.065,
0.065,
track_x * 1.66,
segments=10,
mat_name="gunmetal",
parent=chassis,
location=(-track_x * 0.83, y_ax, axle_z),
rotation_deg=(0.0, 90.0, 0.0),
)
vc.make_box(f"diff_{idx}", (0.28, 0.28, 0.24), "gunmetal", parent=chassis, location=(0.0, y_ax, axle_z), bevel=0.01)
# Heavy front steel bumper + tow shackles
vc.make_box("front_bumper", (2.16, 0.24, 0.24), "gunmetal", parent=chassis, location=(0.0, -2.26, 0.66), bevel=0.014)
for side in (-1.0, 1.0):
vc.make_box(f"bumper_shackle_{'L' if side > 0 else 'R'}", (0.07, 0.12, 0.14), "signal_orange", parent=chassis, location=(side * 0.52, -2.40, 0.62), bevel=0.006)
vc.make_box(f"headlight_box_{'L' if side > 0 else 'R'}", (0.16, 0.12, 0.14), "gunmetal", parent=chassis, location=(side * 0.78, -2.18, 0.92), bevel=0.008)
# --- 2. Armored Hood & Sloped Armored Cab (Brokkr plate.v0 + faceted cab) ---
# Hood core + front grille frame
vc.make_box("hood_core", (1.36, 1.06, 0.60), "olive_armor", parent=chassis, location=(0.0, -1.66, 1.04), bevel=0.015)
vc.make_box("cab_lower", (1.84, 1.18, 0.68), "olive_armor", parent=chassis, location=(0.0, -0.54, 1.06), bevel=0.015)
# Sloped upper armored cab via plate.v0 convex hull ("faces" / "points")
cab_pts = [
[-0.90, -1.12, 1.34], [0.90, -1.12, 1.34],
[0.90, 0.04, 1.34], [-0.90, 0.04, 1.34],
[-0.78, -0.82, 2.02], [0.78, -0.82, 2.02],
[0.80, 0.02, 2.02], [-0.80, 0.02, 2.02],
]
plates_doc = {
"schema": "brokkr.plates.v0",
"plates": [
{
"name": "mule_cab_upper",
"mat": "olive_armor",
"bevel": 0.016,
"sides": "one",
"mirror": False,
"points": cab_pts,
},
# Flared front wheel fenders
{
"name": "mule_fender_front",
"mat": "olive_armor",
"bevel": 0.008,
"sides": "both",
"mirror": False,
"slab": {
"at": [0.92, -1.52, 1.08],
"normal": [0.18, 0.0, 0.98],
"up": [0.0, -1.0, 0.0],
"right": [0.98, 0.0, -0.18],
"outline": [[-0.24, 0.54], [0.24, 0.54], [0.24, -0.54], [-0.24, -0.54]],
"thick": 0.06,
"taper": 0.015,
"back": 0.92,
},
"fits": [
{"kind": "bolts", "inset": 0.02, "spacing": 0.28, "mat": "gunmetal", "params": "r=0.012"},
],
},
# Armored cab doors with stepped clad panels
{
"name": "mule_door",
"mat": "olive_armor",
"bevel": 0.008,
"sides": "both",
"mirror": False,
"slab": {
"at": [0.93, -0.54, 1.18],
"normal": [1.0, 0.0, 0.0],
"up": [0.0, 0.0, 1.0],
"right": [0.0, -1.0, 0.0],
"outline": [[-0.44, -0.34], [0.44, -0.34], [0.40, 0.36], [-0.44, 0.36]],
"thick": 0.04,
"taper": 0.012,
"back": 0.94,
},
"clad": {
"mat": "olive_armor",
"facets": "outer",
"min_area": 0.06,
"lifts": [0.008, 0.012],
"inset": 0.04,
"gap": 0.014,
"split": 0.65,
"seed": 501,
"bolt_r": 0.012,
"bolt_mat": "gunmetal",
"bevel": 0.004,
},
"fits": [
{"kind": "part", "part": "handle", "at": [0.24, -0.04], "roll": 0.0, "mat": "gunmetal", "params": "length=0.20;lift=0.045;r=0.012"},
],
},
],
}
vc.make_plates(plates_doc, parent=chassis)
# Armored smoked glass windshield slit & side viewports
vc.make_box("windshield_slit", (1.28, 0.08, 0.16), "smoked_glass", parent=chassis, location=(0.0, -0.98, 1.68), rotation_deg=(-22.0, 0.0, 0.0), bevel=0.004)
for side in (-1.0, 1.0):
vc.make_box(f"side_glass_{'L' if side > 0 else 'R'}", (0.06, 0.46, 0.22), "smoked_glass", parent=chassis, location=(side * 0.86, -0.46, 1.66), rotation_deg=(0.0, side * -12.0, 0.0), bevel=0.004)
# --- 3. Open Armored Cargo Bed + Rear Mudguards ---
vc.make_box("bed_floor", (2.06, 2.26, 0.12), "gunmetal", parent=chassis, location=(0.0, 1.24, 0.92), bevel=0.01)
# Bed side walls (stepped armor with ribs & tubular top grab rail)
for side in (-1.0, 1.0):
tag = "L" if side > 0 else "R"
vc.make_box(f"bed_wall_{tag}", (0.10, 2.22, 0.68), "olive_armor", parent=chassis, location=(side * 0.98, 1.24, 1.32), bevel=0.01)
for ry in (0.35, 0.95, 1.55, 2.15):
vc.make_box(f"bed_rib_{tag}_{ry:.2f}", (0.05, 0.08, 0.64), "olive_armor", parent=chassis, location=(side * 1.04, ry, 1.32), bevel=0.004)
vc.make_swept_tube(
f"bed_rail_{tag}",
[[side * 0.98, 0.16, 1.68], [side * 0.98, 0.16, 1.82], [side * 0.98, 2.32, 1.82], [side * 0.98, 2.32, 1.68]],
0.022,
segments=8,
mat_name="gunmetal",
parent=chassis,
fillet_r=0.03,
)
# Rear tandem fender flare
vc.make_box(f"rear_fender_{tag}", (0.38, 1.98, 0.08), "olive_armor", parent=chassis, location=(side * 0.94, 1.40, 1.06), bevel=0.008)
# Tailgate
vc.make_box("bed_tailgate", (1.92, 0.10, 0.62), "olive_armor", parent=chassis, location=(0.0, 2.32, 1.29), bevel=0.01)
# Central turret pedestal drum in cargo bed
vc.make_tube_part("bed_pedestal", 0.44, 0.48, 0.58, segments=16, mat_name="gunmetal", parent=chassis, location=(0.0, 1.36, 0.98))
# --- 4. 6x6 Off-Road Wheels & Front Steering Knuckles ---
joints_manifest: list[dict] = []
for axle_tag, y_ax, steerable in (("f", front_y, True), ("m", mid_y, False), ("r", rear_y, False)):
for side, s_tag in ((1.0, "l"), (-1.0, "r")):
j_suffix = f"{axle_tag}{s_tag}"
if steerable:
steer_id = f"joint.steer_{j_suffix}"
steer_node = vc.make_empty(steer_id, parent=chassis, location=(side * 0.80, y_ax, axle_z))
vc.tag_joint(steer_node, steer_id, [0.0, 1.0, 0.0], -30.0, 30.0)
joints_manifest.append({"id": steer_id, "axis": [0.0, 1.0, 0.0], "min": -30.0, "max": 30.0})
wheel_parent = steer_node
wheel_loc = (side * (track_x - 0.80), 0.0, 0.0)
else:
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=16,
rim_segments=18,
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})
# --- 5. Visible Exterior Hardpoints (3x5 Dorsal Grid) ---
# Front bumper/grille armor rail
vc.add_hardpoint_slot(
"hp.armor.front",
"armor",
parent=chassis,
location=(0.0, -2.18, 1.00),
rotation_deg=(90.0, 0.0, 0.0),
size=(1.32, 0.36, 0.09),
plinth_depth=0.03,
)
# Hood engine bay frame
vc.add_hardpoint_slot(
"hp.engine.front",
"engine",
parent=chassis,
location=(0.0, -1.66, 1.32),
rotation_deg=(0.0, 0.0, 0.0),
size=(0.88, 0.86, 0.14),
)
# Cab roof weapon pintle ring
vc.add_hardpoint_slot(
"hp.weapon.cab",
"weapon",
parent=chassis,
location=(0.0, -0.44, 2.02),
rotation_deg=(0.0, 0.0, 0.0),
size=(0.56, 0.56, 0.09),
)
# Main cargo-bed turret ring
vc.add_hardpoint_slot(
"hp.weapon.bed_main",
"weapon",
parent=chassis,
location=(0.0, 1.36, 1.56),
rotation_deg=(0.0, 0.0, 0.0),
size=(0.98, 0.98, 0.12),
)
# Twin flank radiator louver pods behind cab (horizontal louvers: local +Y = +Z up)
vc.add_hardpoint_slot(
"hp.radiator.left",
"radiator",
parent=chassis,
location=(1.04, 0.56, 1.40),
rotation_deg=(90.0, 0.0, 90.0),
size=(0.78, 0.72, 0.14),
)
vc.add_hardpoint_slot(
"hp.radiator.right",
"radiator",
parent=chassis,
location=(-1.04, 0.56, 1.40),
rotation_deg=(90.0, 0.0, -90.0),
size=(0.78, 0.72, 0.14),
)
# --- 6. Export GLB, Manifest & Preview ---
glb_path = vc.ASSETS_VEHICLES_DIR / "mule" / "mule.glb"
manifest_path = vc.ASSETS_VEHICLES_DIR / "mule" / "manifest.json"
preview_path = vc.PREVIEWS_DIR / "mule_preview.png"
tri_count, bounds = vc.export_vehicle_glb(glb_path, root=root)
vc.write_manifest(
manifest_path,
vehicle_id="mule",
name="Mule",
vehicle_class="Medium 6x6 Armored Gun Truck",
grid_width=3,
grid_height=5,
mask=[
"###",
"###",
"###",
"###",
"###",
],
hardpoints=[
{"id": "hp.armor.front", "kind": "armor", "x": 0, "y": 0, "w": 3, "h": 1, "modelNodeId": "hp.armor.front"},
{"id": "hp.radiator.left", "kind": "radiator", "x": 0, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.radiator.left"},
{"id": "hp.engine.front", "kind": "engine", "x": 1, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.engine.front"},
{"id": "hp.radiator.right", "kind": "radiator", "x": 2, "y": 1, "w": 1, "h": 2, "modelNodeId": "hp.radiator.right"},
{"id": "hp.weapon.cab", "kind": "weapon", "x": 0, "y": 3, "w": 1, "h": 1, "modelNodeId": "hp.weapon.cab"},
{"id": "hp.weapon.bed_main", "kind": "weapon", "x": 1, "y": 3, "w": 2, "h": 2, "modelNodeId": "hp.weapon.bed_main"},
],
joints=joints_manifest,
bounds=bounds,
tri_count=tri_count,
)
vc.render_four_panel_preview(preview_path)
print(f"[mule] tris={tri_count} bounds={bounds} glb={glb_path}")
return {"id": "mule", "tris": tri_count, "bounds": bounds}
if __name__ == "__main__":
build_mule()