RustToDust/tools/vehicles/build_jackal.py

405 lines
15 KiB
Python

"""Build the Jackal (Light Wheeled Dune Buggy) chassis GLB, manifest.json, and preview."""
from __future__ import annotations
import math
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
import vehicle_common as vc # noqa: E402
def build_jackal() -> dict:
vc.reset_scene()
vc.ensure_materials()
root = vc.make_empty("JackalRoot")
chassis = vc.make_empty("Chassis", parent=root)
# Dimensions & key coordinates (Blender: -Y forward, +Z up, +X left)
front_y = -1.12
rear_y = 1.08
track_x = 0.84
wheel_r = 0.41
wheel_w = 0.29
axle_z = wheel_r
# --- 1. Belly pan & central backbone ---
vc.make_box("belly_pan", (0.76, 2.24, 0.08), "gunmetal", parent=chassis, location=(0.0, 0.0, 0.34), bevel=0.01)
vc.make_box("front_diff", (0.28, 0.28, 0.20), "gunmetal", parent=chassis, location=(0.0, front_y, 0.42), bevel=0.01)
vc.make_box("rear_transaxle", (0.34, 0.36, 0.24), "gunmetal", parent=chassis, location=(0.0, rear_y, 0.44), bevel=0.01)
# --- 2. Tubular Chromoly Rollcage & Bullbar (Brokkr core.sweep) ---
r_main = 0.025
r_brace = 0.020
for side in (-1.0, 1.0):
tag = "L" if side > 0 else "R"
# Lower sill rail
vc.make_swept_tube(
f"cage_sill_{tag}",
[
[side * 0.30, -1.42, 0.48],
[side * 0.48, -0.78, 0.36],
[side * 0.48, 0.56, 0.36],
[side * 0.42, 1.38, 0.56],
],
r_main,
segments=8,
mat_name="gunmetal",
parent=chassis,
)
# Main A-pillar -> roof rail -> fastback B/C-pillar
vc.make_swept_tube(
f"cage_arch_{tag}",
[
[side * 0.34, -1.24, 0.62],
[side * 0.44, -0.70, 0.82],
[side * 0.39, -0.14, 1.44],
[side * 0.39, 0.44, 1.44],
[side * 0.42, 1.38, 0.82],
[side * 0.42, 1.38, 0.56],
],
r_main,
segments=8,
mat_name="gunmetal",
parent=chassis,
)
# Mid beltline side bar + diagonal door brace
vc.make_swept_tube(
f"cage_belt_{tag}",
[
[side * 0.45, -0.70, 0.78],
[side * 0.48, 0.52, 0.78],
[side * 0.42, 1.36, 0.80],
],
r_brace,
segments=8,
mat_name="gunmetal",
parent=chassis,
)
vc.make_swept_tube(
f"cage_diag_{tag}",
[[side * 0.46, -0.45, 0.42], [side * 0.41, 0.42, 1.42]],
r_brace,
segments=8,
mat_name="gunmetal",
parent=chassis,
)
# Shock tower hoop
vc.make_swept_tube(
f"shock_hoop_{tag}",
[
[side * 0.32, -1.28, 0.54],
[side * 0.38, -1.04, 0.80],
[side * 0.38, -0.78, 0.74],
],
r_brace,
segments=8,
mat_name="gunmetal",
parent=chassis,
)
# Transverse rollcage crossbars & front tubular bullbar
for idx, (y_pos, z_pos, half_w) in enumerate([
(-0.70, 0.82, 0.44),
(-0.14, 1.44, 0.39),
(0.44, 1.44, 0.39),
(0.54, 0.78, 0.46),
(1.38, 0.82, 0.42),
(1.38, 0.56, 0.42),
]):
vc.make_swept_tube(
f"cage_cross_{idx}",
[[-half_w, y_pos, z_pos], [half_w, y_pos, z_pos]],
r_brace,
segments=8,
mat_name="gunmetal",
parent=chassis,
fillet_r=0.0,
)
# Front stinger bullbar + twin headlights
vc.make_swept_tube(
"front_bullbar",
[
[-0.32, -1.40, 0.48],
[-0.24, -1.64, 0.56],
[-0.16, -1.68, 0.68],
[0.16, -1.68, 0.68],
[0.24, -1.64, 0.56],
[0.32, -1.40, 0.48],
],
r_main,
segments=8,
mat_name="gunmetal",
parent=chassis,
)
for side in (-1.0, 1.0):
vc.make_tube_part(
f"headlight_{'L' if side > 0 else 'R'}",
r0=0.045,
r1=0.055,
length=0.08,
segments=12,
mat_name="gunmetal",
parent=chassis,
location=(side * 0.28, -1.46, 0.66),
rotation_deg=(90.0, 0.0, 0.0),
)
# --- 3. Hard Armour Plates (Brokkr plate.v0) ---
plates_doc = {
"schema": "brokkr.plates.v0",
"plates": [
{
"name": "jackal_side",
"mat": "olive_armor",
"bevel": 0.008,
"sides": "both",
"mirror": False,
"slab": {
"at": [0.47, -0.05, 0.58],
"normal": [1.0, 0.0, 0.14],
"up": [0.0, 0.0, 1.0],
"right": [0.0, -1.0, 0.0],
"outline": [[-0.58, -0.16], [0.58, -0.14], [0.68, 0.16], [-0.42, 0.22]],
"thick": 0.04,
"taper": 0.015,
"back": 0.92,
},
"clad": {
"mat": "olive_armor",
"facets": "outer",
"min_area": 0.04,
"lifts": [0.008, 0.012],
"inset": 0.04,
"gap": 0.015,
"split": 0.55,
"seed": 401,
"bolt_r": 0.012,
"bolt_mat": "gunmetal",
"bevel": 0.004,
},
"fits": [
{"kind": "bolts", "inset": 0.02, "spacing": 0.26, "mat": "gunmetal", "params": "r=0.012"},
],
},
{
"name": "jackal_hood",
"mat": "olive_armor",
"bevel": 0.008,
"sides": "one",
"mirror": False,
"slab": {
"at": [0.0, -0.98, 0.73],
"normal": [0.0, -0.32, 0.95],
"up": [0.0, -0.95, -0.32],
"right": [1.0, 0.0, 0.0],
"outline": [[-0.28, 0.30], [0.28, 0.30], [0.38, -0.28], [-0.38, -0.28]],
"thick": 0.045,
"taper": 0.018,
"back": 0.90,
},
"clad": {
"mat": "olive_armor",
"facets": "outer",
"min_area": 0.05,
"lifts": [0.008, 0.014],
"inset": 0.04,
"gap": 0.014,
"split": 0.60,
"seed": 402,
"bolt_r": 0.012,
"bolt_mat": "gunmetal",
"bevel": 0.004,
},
"fits": [
{"kind": "bolts", "inset": 0.02, "spacing": 0.24, "mat": "gunmetal", "params": "r=0.012"},
],
},
{
"name": "jackal_roof",
"mat": "olive_armor",
"bevel": 0.008,
"sides": "one",
"mirror": False,
"slab": {
"at": [0.0, 0.14, 1.455],
"normal": [0.0, 0.0, 1.0],
"up": [0.0, -1.0, 0.0],
"right": [1.0, 0.0, 0.0],
"outline": {"w": 0.74, "h": 0.62, "clip": 0.08},
"thick": 0.036,
"taper": 0.012,
"back": 0.94,
},
"fits": [
{"kind": "bolts", "inset": 0.02, "spacing": 0.22, "mat": "gunmetal", "params": "r=0.012"},
],
},
],
}
vc.make_plates(plates_doc, parent=chassis)
# --- 4. Cockpit Seats & Firewall ---
for side in (-1.0, 1.0):
tag = "L" if side > 0 else "R"
vc.make_box(f"seat_base_{tag}", (0.32, 0.34, 0.08), "rubber_dark", parent=chassis, location=(side * 0.20, 0.08, 0.42), bevel=0.01)
vc.make_box(f"seat_back_{tag}", (0.30, 0.08, 0.48), "rubber_dark", parent=chassis, location=(side * 0.20, 0.24, 0.68), rotation_deg=(14.0, 0.0, 0.0), bevel=0.01)
vc.make_box("rear_firewall", (0.76, 0.04, 0.42), "gunmetal", parent=chassis, location=(0.0, 0.46, 0.60), bevel=0.005)
vc.make_swept_tube("steer_col", [[0.18, -0.58, 0.80], [0.18, -0.34, 0.92]], 0.018, segments=8, mat_name="gunmetal", parent=chassis, fillet_r=0.0)
# --- 5. Double-Wishbone Suspension, Coilovers & 4 Knobby Wheels ---
joints_manifest: list[dict] = []
for is_front, y_ax, prefix in [(True, front_y, "f"), (False, rear_y, "r")]:
for side, s_tag in [(1.0, "l"), (-1.0, "r")]:
j_suffix = f"{prefix}{s_tag}"
in_x = side * 0.24
out_x = side * 0.68
# Upper & lower A-arms (two separate wishbone legs meeting at the ball joint)
for leg_tag, dy in (("a", -0.16), ("b", 0.16)):
vc.make_swept_tube(
f"wishbone_lo_{j_suffix}_{leg_tag}",
[[in_x, y_ax + dy, 0.36], [out_x, y_ax, axle_z - 0.06]],
0.018,
segments=6,
mat_name="gunmetal",
parent=chassis,
fillet_r=0.0,
)
for leg_tag, dy in (("a", -0.14), ("b", 0.14)):
vc.make_swept_tube(
f"wishbone_hi_{j_suffix}_{leg_tag}",
[[in_x, y_ax + dy, 0.52], [out_x, y_ax, axle_z + 0.08]],
0.016,
segments=6,
mat_name="gunmetal",
parent=chassis,
fillet_r=0.0,
)
# Coilover shock strut from knuckle up to shock tower
tower_z = 0.80 if is_front else 0.86
tower_y = y_ax + (0.04 if is_front else -0.06)
vc.make_ram_span(
f"coilover_{j_suffix}",
[side * 0.40, tower_y, tower_z],
[side * 0.62, y_ax, axle_z - 0.02],
body_r=0.028,
rod_r=0.016,
parent=chassis,
mat_barrel="gunmetal",
mat_rod="gunmetal",
coil_rings=6,
)
# Steering knuckle (front only) + wheel hub spin joint
knuckle_loc = (side * track_x, y_ax, axle_z)
if is_front:
steer_id = f"joint.steer_{j_suffix}"
steer_node = vc.make_empty(steer_id, parent=chassis, location=(side * 0.68, y_ax, axle_z))
vc.tag_joint(steer_node, steer_id, [0.0, 1.0, 0.0], -32.0, 32.0)
joints_manifest.append({"id": steer_id, "axis": [0.0, 1.0, 0.0], "min": -32.0, "max": 32.0})
vc.make_box(f"knuckle_{j_suffix}", (0.08, 0.11, 0.18), "gunmetal", parent=steer_node, bevel=0.005)
wheel_parent = steer_node
wheel_loc = (side * (track_x - 0.68), 0.0, 0.0)
else:
vc.make_box(f"hub_carrier_{j_suffix}", (0.10, 0.12, 0.18), "gunmetal", parent=chassis, location=(side * 0.68, y_ax, axle_z), bevel=0.005)
wheel_parent = chassis
wheel_loc = knuckle_loc
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})
# --- 6. Visible Exterior Hardpoint Slots ---
# 1) Roof weapon collar ring
vc.add_hardpoint_slot(
"hp.weapon.roof",
"weapon",
parent=chassis,
location=(0.0, 0.14, 1.47),
rotation_deg=(0.0, 0.0, 0.0),
size=(0.62, 0.62, 0.10),
)
# 2) Open rear engine bay frame + mounting tray + twin exhaust sweeps
vc.make_box("rear_engine_tray", (0.64, 0.74, 0.06), "gunmetal", parent=chassis, location=(0.0, 0.90, 0.51), bevel=0.006)
vc.add_hardpoint_slot(
"hp.engine.rear",
"engine",
parent=chassis,
location=(0.0, 0.90, 0.53),
rotation_deg=(0.0, 0.0, 0.0),
size=(0.62, 0.72, 0.16),
)
for side in (-1.0, 1.0):
vc.make_swept_tube(
f"exhaust_{'L' if side > 0 else 'R'}",
[
[side * 0.24, 0.78, 0.68],
[side * 0.36, 1.12, 0.66],
[side * 0.38, 1.48, 0.74],
],
0.028,
segments=8,
mat_name="copper_rad",
parent=chassis,
)
# 3) Upright rear copper radiator louver bay seated on rear cage shroud
vc.make_box("rear_rad_shroud", (0.60, 0.06, 0.36), "gunmetal", parent=chassis, location=(0.0, 1.36, 0.74), rotation_deg=(28.0, 0.0, 0.0), bevel=0.006)
vc.add_hardpoint_slot(
"hp.radiator.rear",
"radiator",
parent=chassis,
location=(0.0, 1.34, 0.75),
rotation_deg=(-62.0, 0.0, 0.0),
size=(0.58, 0.44, 0.11),
)
vc.make_box("rad_header_tank", (0.58, 0.09, 0.08), "copper_rad", parent=chassis, location=(0.0, 1.44, 0.95), bevel=0.008)
# --- 7. Export GLB, Manifest & 4-Panel Preview ---
glb_path = vc.ASSETS_VEHICLES_DIR / "jackal" / "jackal.glb"
manifest_path = vc.ASSETS_VEHICLES_DIR / "jackal" / "manifest.json"
preview_path = vc.PREVIEWS_DIR / "jackal_preview.png"
tri_count, bounds = vc.export_vehicle_glb(glb_path, root=root)
vc.write_manifest(
manifest_path,
vehicle_id="jackal",
name="Jackal",
vehicle_class="Light Wheeled Dune Buggy",
grid_width=3,
grid_height=4,
mask=[
"###",
"###",
"###",
"###",
],
hardpoints=[
{"id": "hp.weapon.roof", "kind": "weapon", "x": 1, "y": 0, "w": 1, "h": 2, "modelNodeId": "hp.weapon.roof"},
{"id": "hp.engine.rear", "kind": "engine", "x": 1, "y": 2, "w": 1, "h": 2, "modelNodeId": "hp.engine.rear"},
{"id": "hp.radiator.rear", "kind": "radiator", "x": 2, "y": 3, "w": 1, "h": 1, "modelNodeId": "hp.radiator.rear"},
],
joints=joints_manifest,
bounds=bounds,
tri_count=tri_count,
)
vc.render_four_panel_preview(preview_path)
print(f"[jackal] tris={tri_count} bounds={bounds} glb={glb_path}")
return {"id": "jackal", "tris": tri_count, "bounds": bounds}
if __name__ == "__main__":
build_jackal()