Build every body style from an authored cage

- assets/src/archetype.py turns the sedan's hand-drawn shapes into rules
  (nose, bonnet, windscreen, roof peak, notch, hatch or cab rear) so each style
  script is a handful of measurements on a shared topology.
- cagelib: open bodies (the buggy), tubs that drop to a floor (the pickup's
  bed, the buggy's cockpit), full-height tailgates, a per-style station merge.
- Twelve new cages: hatchback, coupe, wagon, SUV, pickup, van, sports,
  supercar, muscle, kei, buggy and the truck's cab. The morph ignores axles
  outside the cage (the truck's rear axle sits under its load box).
- Presets take their roof height from their cage; README images regenerated.
- cages:build and cages:watch treat archetype.py as a shared module.
This commit is contained in:
CRTkafa 2026-10-11 08:53:30 +08:00
parent 6b394bcbfc
commit 02e8854cc4
35 changed files with 553 additions and 38 deletions

View file

@ -31,9 +31,10 @@ Version 0.1.0, alpha.
**In progress** **In progress**
- Bodies drawn from authored cages. The sedan is the first: its shape comes - Shaping the authored bodies further: every style now comes from its own
from a control cage subdivided at run time. The other twelve styles still control cage, and the cages are being refined style by style.
use the older lofted body and are moving over one by one. - Blending two styles currently morphs the first style's cage to the blended
proportions; blending the cages themselves comes later.
**Planned** **Planned**
@ -54,11 +55,10 @@ Version 0.1.0, alpha.
segment: overall dimensions, wheelbase, overhangs, tyre size, and where the segment: overall dimensions, wheelbase, overhangs, tyre size, and where the
windshield, roof and rear glass start and end. The default sedan is windshield, roof and rear glass start and end. The default sedan is
4.85 m long and 1.86 m wide on a 2.84 m wheelbase and 0.69 m tyres. 4.85 m long and 1.86 m wide on a 2.84 m wheelbase and 0.69 m tyres.
- **Smooth bodies, not boxes.** The sedan's body is a subdivision surface: - **Smooth bodies, not boxes.** Every body is a subdivision surface: an
an authored control cage (`assets/src/sedan.py`) is fitted to the spec, authored control cage per style (`assets/src/<style>.py`) is fitted to the
subdivided with creases and split into panels with real gaps. The other spec, subdivided with creases and split into panels with real gaps. Hard
styles are lofted from cross-sections driven by profile curves. Either way, creases sit where a real car has them: the shoulder,
hard creases sit where a real car has them: the shoulder,
a character line along the flank, the rocker and the windshield base. Panel a character line along the flank, the rocker and the windshield base. Panel
gaps are real grooves, and the wheel arches are cut into the sills with gaps are real grooves, and the wheel arches are cut into the sills with
rolled lips. The glass is flush. Lamps are recessed reflectors behind clear rolled lips. The glass is flush. Lamps are recessed reflectors behind clear

146
assets/src/archetype.py Normal file
View file

@ -0,0 +1,146 @@
"""
A body archetype's profile tables from a handful of measurements.
The sedan's tables were drawn by hand; this turns the same shapes into rules so
every style shares them: the nose rounding into a bonnet that climbs to the
cowl, a windscreen that bows slightly, a roof that peaks just behind its middle,
and a rear that is a notch (a deck behind the rear window), a hatch (the glass
runs down to a tailgate) or a cab (a flat back). Plan-view widths follow the
sedan's rounding, scaled by how blunt the nose and tail are.
All z are metres along the car (+forward, centred), all y metres above the
ground. A style script fills these in and hands the result to cagelib.main.
"""
def _ease(t):
# A slight bow: the windscreen and rear glass curve outward a little.
return t * (1.15 - 0.15 * t)
def _lerp(a, b, t):
return a + (b - a) * t
def design(
style, *, length, width, wheelbase, front_overhang, wheel_radius, track=1.6,
# Heights of the top surface at its edge.
nose, hood, roof, deck_height, tail,
# Stations (z): windscreen base, roof front and rear, rear-glass base.
cowl, roof_front, roof_rear, deck,
rear='notch', sill=0.25, nose_sill=None, tail_sill=None,
belt_front=None, belt_rear=None, tumblehome=0.27, crown=0.05, hood_crown=0.03,
nose_round=0.3, tail_round=0.25, nose_blunt=0.0, tail_blunt=0.0, nose_rake=0.06, shoulder_roll=0.05,
flare=0.022, arch_gap=0.022, doors=2, hood_end=None, trunk=None, extra=None,
):
front, back = length / 2, -length / 2
fa = front - front_overhang
ra = fa - wheelbase
hw = width / 2 - flare
peak = roof
# --- side profile: the top surface at its edge
top = [(front, nose), (front - 0.025, nose + 0.07), (front - 0.085, nose + 0.11)]
hood_start = (front - 0.085, nose + 0.11)
for t in (0.3, 0.6):
top.append((_lerp(hood_start[0], cowl, t), _lerp(hood_start[1], hood, t)))
top.append((cowl, hood))
if roof_front < cowl - 0.05:
for t in (0.26, 0.55, 0.83):
top.append((_lerp(cowl, roof_front, t), _lerp(hood, peak - 0.055, _ease(t))))
top.append((roof_front, peak - 0.055))
top.append((_lerp(roof_front, roof_rear, 0.18), peak - 0.015))
top.append((_lerp(roof_front, roof_rear, 0.5), peak))
top.append((roof_rear, peak - 0.04))
if rear == 'notch':
for t in (0.33, 0.69):
top.append((_lerp(roof_rear, deck, t), _lerp(peak - 0.04, deck_height, t)))
top.append((deck, deck_height))
span = deck - back
top += [(deck - 0.3 * span, deck_height - 0.015), (back + 0.175, deck_height - 0.02),
(back + 0.085, deck_height - 0.035), (back + 0.025, deck_height - 0.09), (back, tail)]
elif rear == 'hatch':
# The glass leans in to a short spoiler lip, then the tailgate drops.
top.append((_lerp(roof_rear, deck, 0.5), _lerp(peak - 0.04, deck_height, 0.45)))
top.append((deck, deck_height))
top += [(back + 0.02, tail + 0.03), (back, tail)]
else: # 'cab': a flat back straight down from the roof
top += [(back + 0.03, tail + 0.01), (back, tail)]
# Plan view: how round the nose and tail are, 0 = the sedan's rounding.
nb, tb = nose_blunt, tail_blunt
half_width = [
(front, hw * (0.54 + 0.4 * nb)), (front - 0.025, hw * (0.69 + 0.27 * nb)), (front - 0.085, hw * (0.81 + 0.17 * nb)),
(front - 0.225, hw * (0.90 + 0.09 * nb)), (front - 0.475, hw * (0.962 + 0.03 * nb)), (front - 0.925, hw * 0.984),
(_lerp(front - 0.925, back + 0.525, 0.5), hw * 0.99), (back + 0.525, hw * (0.968 + 0.02 * tb)), (back + 0.225, hw * (0.925 + 0.06 * tb)),
(back + 0.065, hw * (0.84 + 0.13 * tb)), (back, hw * (0.67 + 0.28 * tb)),
]
roof_ratio = 0.95 - tumblehome
top_half_width = [
(front, hw * (0.47 + 0.35 * nb)), (front - 0.125, hw * (0.62 + 0.25 * nb)), (_lerp(front, cowl, 0.5), hw * 0.73),
(cowl, hw * 0.774),
]
if roof_front < cowl - 0.05:
top_half_width += [(_lerp(cowl, roof_front, 0.25), hw * _lerp(0.774, roof_ratio, 0.3)),
(roof_front, hw * roof_ratio), (roof_rear, hw * (roof_ratio - 0.01))]
if rear == 'notch':
top_half_width += [(_lerp(roof_rear, deck, 0.4), hw * (roof_ratio + 0.035)), (_lerp(roof_rear, deck, 0.75), hw * 0.774),
(deck, hw * 0.839), (back + 0.125, hw * 0.796), (back, hw * (0.602 + 0.3 * tb))]
else:
if roof_rear > back + 0.1:
top_half_width.append((back + 0.06, hw * (roof_ratio + 0.02)))
top_half_width.append((back, hw * (roof_ratio - 0.04 + 0.1 * tb)))
belt_front = hood if belt_front is None else belt_front
belt_rear = deck_height if belt_rear is None else belt_rear
belt = [(cowl, belt_front), (roof_front, belt_front + 0.02), (roof_rear, _lerp(belt_front, belt_rear, 0.8)), (deck, belt_rear)]
ns = sill + 0.09 if nose_sill is None else nose_sill
ts = sill + 0.13 if tail_sill is None else tail_sill
sill_table = [(front, ns), (front - 0.225, sill + 0.02), (front - 0.525, sill), (back + 0.725, sill),
(back + 0.325, sill + 0.04), (back, ts)]
crown_table = [(front, 0.0), (front - 0.225, hood_crown * 0.8), (cowl, hood_crown)]
if roof_front < cowl - 0.05:
crown_table += [(roof_front, crown), (roof_rear, crown)]
crown_table += [(deck, hood_crown + 0.005), (back, 0.0)]
# Doors: the front door's leading edge just behind the cowl; two doors
# split at the B-pillar over the roof's front third.
if doors == 2:
b_pillar = _lerp(roof_front, roof_rear, 0.18)
door_edges = [cowl + 0.04, b_pillar, _lerp(b_pillar, deck, 0.62)]
elif doors == 1:
b_pillar = None
door_edges = [cowl + 0.04, _lerp(roof_front, roof_rear, 0.6)]
else:
b_pillar = None
door_edges = []
side_front = _lerp(cowl, roof_front, 0.3)
side_rear = _lerp(roof_rear, deck, 0.45) if rear == 'notch' else _lerp(roof_rear, deck, 0.3)
d = {
'style': style,
'length': length, 'width': width, 'height': roof + crown, 'wheelbase': wheelbase,
'frontOverhang': front_overhang, 'wheelRadius': wheel_radius, 'track': track,
'axles': [{'z': fa, 'radius': wheel_radius}, {'z': ra, 'radius': wheel_radius}],
'archGap': arch_gap, 'flare': flare, 'noseRound': nose_round, 'tailRound': tail_round,
'noseRake': nose_rake, 'shoulderRoll': shoulder_roll, 'spacing': 0.38,
'cowl': cowl, 'roofFront': roof_front, 'roofRear': roof_rear, 'deck': deck,
'sideWindowFront': side_front, 'sideWindowRear': side_rear,
'doorEdges': door_edges, 'bPillar': b_pillar,
'hood': [cowl + 0.05, hood_end if hood_end is not None else front - 0.105] if hood_end != 0 else None,
'trunk': trunk,
'bumperDepth': [0.45, 0.4], 'headWrap': 0.26, 'tailWrap': 0.18,
'top': top, 'crown': crown_table, 'belt': belt, 'sill': sill_table,
'halfWidth': half_width, 'topHalfWidth': top_half_width,
'anchors': {
'spoiler': [0, deck_height, back + 0.09], 'roof': [0, roof + crown, _lerp(roof_front, roof_rear, 0.5)],
'exhaust': [hw * 0.5, ts * 0.85, back + 0.005], 'plateFront': [0, ns + 0.12, front],
'plateRear': [0, _lerp(ts, tail, 0.45), back], 'mirrorL': [hw, belt_front + 0.035, cowl - 0.14],
'mirrorR': [-hw, belt_front + 0.035, cowl - 0.14],
},
}
if extra:
d.update(extra)
return d

27
assets/src/buggy.py Normal file
View file

@ -0,0 +1,27 @@
"""
Buggy cage: an off-road buggy, 3.6 x 1.8 m on a 2.45 m wheelbase, 33-inch tyres.
An open body: no roof or glass, a cockpit tub, a sloping nose and an engine
deck; the roll cage is a mod.
python3 assets/src/buggy.py -- --out src/generator/cages/buggy.json
(or `bun run cages:build buggy`; Blender only for --render)
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import archetype # noqa: E402
import cagelib # noqa: E402
L = 3.6
DESIGN = archetype.design(
'buggy', length=L, width=1.8, wheelbase=2.45, front_overhang=0.62, wheel_radius=0.42,
nose=0.72, hood=0.92, roof=0.92, deck_height=0.96, tail=0.9,
cowl=0.55, roof_front=0.53, roof_rear=-0.6, deck=-0.65, rear='notch',
sill=0.46, nose_sill=0.55, tail_sill=0.55, belt_front=0.92, belt_rear=0.96, tumblehome=0.0, crown=0.0,
hood_crown=0.02, nose_round=0.3, tail_round=0.2, nose_blunt=0.2, nose_rake=0.08, shoulder_roll=0.03,
flare=0.0, arch_gap=0.09, doors=0,
extra={'open': True, 'tub': {'front': 0.5, 'rear': -0.62, 'floor': 0.55, 'inset': 0.12}},
)
cagelib.main(DESIGN)

View file

@ -96,6 +96,9 @@ class Design:
def cabin(self, z): def cabin(self, z):
# 0 on bonnet and boot, 1 under the roof; a short ramp at each end. # 0 on bonnet and boot, 1 under the roof; a short ramp at each end.
# An open body (a buggy) has no roof or glass anywhere.
if self.d.get('open'):
return 0.0
return smoothstep(self.deck - 0.02, self.deck + 0.08, z) * (1 - smoothstep(self.cowl - 0.08, self.cowl + 0.02, z)) return smoothstep(self.deck - 0.02, self.deck + 0.08, z) * (1 - smoothstep(self.cowl - 0.08, self.cowl + 0.02, z))
def belt(self, z): def belt(self, z):
@ -121,6 +124,14 @@ class Design:
f = max(f, math.cos(dz * math.pi / 2) ** 2) f = max(f, math.cos(dz * math.pi / 2) ** 2)
return f * self.d['flare'] return f * self.d['flare']
def tub(self, z):
"""1 inside an open tub (a pickup bed, a buggy's cockpit), 0 outside,
with walls a few centimetres thick at each end."""
t = self.d.get('tub')
if not t:
return 0.0
return smoothstep(t['rear'] - 0.02, t['rear'] + 0.03, z) * (1 - smoothstep(t['front'] - 0.03, t['front'] + 0.02, z))
def surface(self, z, x): def surface(self, z, x):
"""Height of the top surface at lateral offset x.""" """Height of the top surface at lateral offset x."""
w = max(1e-6, self.thw(z)) w = max(1e-6, self.thw(z))
@ -158,9 +169,24 @@ class Design:
(hw * 0.995, min(lamp, bt - 0.012) - roll), (hw * 0.995, min(lamp, bt - 0.012) - roll),
(sx, bt - roll), (sx, bt - roll),
(k8x, max(k8y - roll * 0.3, bt - roll + 0.005)), (k8x, max(k8y - roll * 0.3, bt - roll + 0.005)),
(thw, max(tp, bt + 0.01)), ] + self.top_points(z, hw, thw, tp, bt)
(thw * 0.5, self.surface(z, thw * 0.5)),
(0.0, self.surface(z, 0.0)), def top_points(self, z, hw, thw, tp, bt):
"""The roof or bonnet middle and centre line; inside a tub they drop to
its floor behind a rail `inset` wide."""
w = self.tub(z)
edge = (thw, max(tp, bt + 0.01))
mid = (thw * 0.5, self.surface(z, thw * 0.5))
centre = (0.0, self.surface(z, 0.0))
if w <= 0:
return [edge, mid, centre]
t = self.d['tub']
rail = hw - t['inset']
lerp = lambda a, b: a + (b - a) * w
return [
(lerp(edge[0], rail), edge[1]),
(lerp(mid[0], rail - 0.02), lerp(mid[1], t['floor'])),
(0.0, lerp(centre[1], t['floor'])),
] ]
def rake(self, z, y): def rake(self, z, y):
@ -189,6 +215,9 @@ class Design:
must += list(d['hood']) must += list(d['hood'])
if d.get('trunk'): if d.get('trunk'):
must += [d['trunk']['front'], d['trunk']['rear']] must += [d['trunk']['front'], d['trunk']['rear']]
if d.get('tub'):
for e in (d['tub']['front'], d['tub']['rear']):
must += [e - 0.035, e, e + 0.035]
if d.get('bPillar') is not None: if d.get('bPillar') is not None:
must += [d['bPillar'] - 0.05, d['bPillar'] + 0.05] must += [d['bPillar'] - 0.05, d['bPillar'] + 0.05]
must += [self.front - 0.18, self.rear + 0.15] must += [self.front - 0.18, self.rear + 0.15]
@ -199,7 +228,7 @@ class Design:
pts = [self.rear] + pts + [self.front] pts = [self.rear] + pts + [self.front]
merged = [] merged = []
for z in pts: for z in pts:
if merged and z - merged[-1] < 0.025 and z not in (self.front,): if merged and z - merged[-1] < d.get('merge', 0.025) and z not in (self.front,):
continue continue
merged.append(z) merged.append(z)
if merged[-1] != self.front: if merged[-1] != self.front:
@ -258,6 +287,9 @@ def tag_side(des, z, seg, side, z0, z1):
if seg == 8 and in_lid: if seg == 8 and in_lid:
return 'trunk|paint' return 'trunk|paint'
return 'body|paint' return 'body|paint'
tub = d.get('tub')
if tub and seg >= 9 and tub['rear'] + 0.01 < z < tub['front'] - 0.01:
return 'body|trim'
if in_hood: if in_hood:
return 'hood|paint' return 'hood|paint'
if in_lid: if in_lid:
@ -290,13 +322,14 @@ def tag_end(des, row, column, direction):
return 'body|lightHead' if column == 'outer' else 'body|trim' return 'body|lightHead' if column == 'outer' else 'body|trim'
return 'hood|paint' if d.get('hood') and row >= 8 else 'body|paint' return 'hood|paint' if d.get('hood') and row >= 8 else 'body|paint'
lid = tr is not None lid = tr is not None
gate = tr is not None and tr['kind'] == 'tailgate'
if row == 3: if row == 3:
return 'body|trim' if column == 'mid' else 'body|bumper' return 'body|trim' if column == 'mid' else 'body|bumper'
if row == 4: if row == 4:
return 'body|bumper' return 'body|bumper'
if row == 6: if row == 6:
return ('trunk' if lid else 'body') + '|lightTail' return ('trunk' if lid else 'body') + '|lightTail'
if lid and row >= 7: if (lid and row >= 7) or (gate and row == 5):
return 'trunk|paint' return 'trunk|paint'
return 'body|paint' return 'body|paint'

24
assets/src/coupe.py Normal file
View file

@ -0,0 +1,24 @@
"""
Coupe cage: a two-door, 4.6 x 1.85 x 1.35 m on a 2.75 m wheelbase. Long doors,
a low fastback roof and a short deck with a boot lid.
python3 assets/src/coupe.py -- --out src/generator/cages/coupe.json
(or `bun run cages:build coupe`; Blender only for --render)
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import archetype # noqa: E402
import cagelib # noqa: E402
L = 4.6
DESIGN = archetype.design(
'coupe', length=L, width=1.85, wheelbase=2.75, front_overhang=0.95, wheel_radius=0.335,
nose=0.68, hood=0.93, roof=1.31, deck_height=1.03, tail=0.95,
cowl=0.88, roof_front=-0.05, roof_rear=-0.95, deck=-1.62, rear='notch',
sill=0.18, tumblehome=0.24, crown=0.04, nose_round=0.26, tail_round=0.22, doors=1,
trunk={'kind': 'lid', 'front': -1.66, 'rear': -L / 2 + 0.045},
)
cagelib.main(DESIGN)

25
assets/src/hatchback.py Normal file
View file

@ -0,0 +1,25 @@
"""
Hatchback cage: a C-segment five-door, 4.28 x 1.79 x 1.45 m on a 2.63 m wheelbase,
225/45 R17. Short bonnet, a long roof and a steep glass hatch over a full
tailgate.
python3 assets/src/hatchback.py -- --out src/generator/cages/hatchback.json
(or `bun run cages:build hatchback`; Blender only for --render)
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import archetype # noqa: E402
import cagelib # noqa: E402
L = 4.28
DESIGN = archetype.design(
'hatchback', length=L, width=1.79, wheelbase=2.63, front_overhang=0.88, wheel_radius=0.317,
nose=0.72, hood=0.95, roof=1.41, deck_height=1.13, tail=1.02,
cowl=0.85, roof_front=0.05, roof_rear=-1.62, deck=-1.99, rear='hatch',
sill=0.24, belt_rear=1.05, tumblehome=0.18, crown=0.04, nose_round=0.24, tail_round=0.12, tail_blunt=0.35,
trunk={'kind': 'tailgate', 'front': -1.64, 'rear': -L / 2},
)
cagelib.main(DESIGN)

25
assets/src/kei.py Normal file
View file

@ -0,0 +1,25 @@
"""
Kei cage: at the legal maximum, 3.4 x 1.48 x 1.75 m on a 2.52 m wheelbase,
155/65 R14. A stubby nose, a tall box cabin and a vertical tailgate.
python3 assets/src/kei.py -- --out src/generator/cages/kei.json
(or `bun run cages:build kei`; Blender only for --render)
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import archetype # noqa: E402
import cagelib # noqa: E402
L = 3.395
DESIGN = archetype.design(
'kei', length=L, width=1.475, wheelbase=2.52, front_overhang=0.46, wheel_radius=0.279,
nose=0.78, hood=0.93, roof=1.72, deck_height=1.3, tail=1.12,
cowl=1.0, roof_front=0.66, roof_rear=-1.5, deck=-1.6, rear='hatch',
sill=0.19, belt_front=0.95, belt_rear=0.98, tumblehome=0.06, crown=0.03,
nose_round=0.16, tail_round=0.08, nose_blunt=0.5, tail_blunt=0.8,
trunk={'kind': 'tailgate', 'front': -1.52, 'rear': -L / 2},
)
cagelib.main(DESIGN)

25
assets/src/muscle.py Normal file
View file

@ -0,0 +1,25 @@
"""
Muscle cage: a classic fastback, 4.8 x 1.9 x 1.31 m on a 2.78 m wheelbase. A long
flat bonnet over a blunt nose, two long doors, a short deck.
python3 assets/src/muscle.py -- --out src/generator/cages/muscle.json
(or `bun run cages:build muscle`; Blender only for --render)
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import archetype # noqa: E402
import cagelib # noqa: E402
L = 4.8
DESIGN = archetype.design(
'muscle', length=L, width=1.9, wheelbase=2.78, front_overhang=0.98, wheel_radius=0.345,
nose=0.82, hood=0.96, roof=1.28, deck_height=1.02, tail=1.0,
cowl=0.5, roof_front=-0.3, roof_rear=-1.0, deck=-1.75, rear='notch',
sill=0.18, tumblehome=0.2, crown=0.03, hood_crown=0.02, nose_round=0.12, tail_round=0.1,
nose_blunt=0.5, tail_blunt=0.5, nose_rake=0.0, doors=1,
trunk={'kind': 'lid', 'front': -1.79, 'rear': -L / 2 + 0.045},
)
cagelib.main(DESIGN)

26
assets/src/pickup.py Normal file
View file

@ -0,0 +1,26 @@
"""
Pickup cage: a full-size crew cab, 5.4 x 2.0 x 1.88 m on a 3.3 m wheelbase,
265/70 R17. A tall blunt nose, a four-door cab and an open bed behind it.
python3 assets/src/pickup.py -- --out src/generator/cages/pickup.json
(or `bun run cages:build pickup`; Blender only for --render)
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import archetype # noqa: E402
import cagelib # noqa: E402
L = 5.4
DESIGN = archetype.design(
'pickup', length=L, width=2.0, wheelbase=3.3, front_overhang=0.95, wheel_radius=0.4,
nose=1.1, hood=1.3, roof=1.85, deck_height=1.3, tail=1.27,
cowl=1.2, roof_front=0.62, roof_rear=-0.3, deck=-0.42, rear='notch',
sill=0.5, nose_sill=0.58, tail_sill=0.55, belt_front=1.3, belt_rear=1.33, tumblehome=0.1, crown=0.03,
nose_round=0.16, tail_round=0.06, nose_blunt=0.6, tail_blunt=0.7, nose_rake=0.03, arch_gap=0.07, flare=0.02,
# The bed: rails 8 cm wide, a floor 52 cm below them.
extra={'tub': {'front': -0.48, 'rear': -L / 2 + 0.08, 'floor': 0.78, 'inset': 0.08}},
)
cagelib.main(DESIGN)

24
assets/src/sports.py Normal file
View file

@ -0,0 +1,24 @@
"""
Sports cage: a front-engined two-seater, 4.25 x 1.78 x 1.28 m on a 2.57 m
wheelbase, 215/45 R17. A long bonnet, the cabin set back, a short deck.
python3 assets/src/sports.py -- --out src/generator/cages/sports.json
(or `bun run cages:build sports`; Blender only for --render)
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import archetype # noqa: E402
import cagelib # noqa: E402
L = 4.25
DESIGN = archetype.design(
'sports', length=L, width=1.78, wheelbase=2.57, front_overhang=0.85, wheel_radius=0.315,
nose=0.62, hood=0.86, roof=1.25, deck_height=0.97, tail=0.9,
cowl=0.6, roof_front=-0.2, roof_rear=-0.9, deck=-1.45, rear='notch',
sill=0.14, tumblehome=0.24, crown=0.03, nose_round=0.24, tail_round=0.2, doors=1, flare=0.02,
trunk={'kind': 'lid', 'front': -1.49, 'rear': -L / 2 + 0.045},
)
cagelib.main(DESIGN)

26
assets/src/supercar.py Normal file
View file

@ -0,0 +1,26 @@
"""
Supercar cage: mid-engined, 4.5 x 1.93 x 1.15 m on a 2.62 m wheelbase, 305/30 R20.
A low wedge nose over a front boot, the cabin forward, the engine under a
rear lid.
python3 assets/src/supercar.py -- --out src/generator/cages/supercar.json
(or `bun run cages:build supercar`; Blender only for --render)
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import archetype # noqa: E402
import cagelib # noqa: E402
L = 4.5
DESIGN = archetype.design(
'supercar', length=L, width=1.93, wheelbase=2.62, front_overhang=1.02, wheel_radius=0.345,
nose=0.55, hood=0.78, roof=1.12, deck_height=0.99, tail=0.93,
cowl=0.9, roof_front=0.36, roof_rear=-0.54, deck=-0.99, rear='notch',
sill=0.12, tumblehome=0.28, crown=0.03, hood_crown=0.02, nose_round=0.3, tail_round=0.16,
nose_rake=0.03, shoulder_roll=0.04, doors=1, flare=0.03,
trunk={'kind': 'lid', 'front': -1.03, 'rear': -L / 2 + 0.045},
)
cagelib.main(DESIGN)

26
assets/src/suv.py Normal file
View file

@ -0,0 +1,26 @@
"""
SUV cage: a compact crossover, 4.6 x 1.86 x 1.67 m on a 2.69 m wheelbase,
225/60 R18. High bonnet and sills, an upright glasshouse, a squared tail
with a full tailgate.
python3 assets/src/suv.py -- --out src/generator/cages/suv.json
(or `bun run cages:build suv`; Blender only for --render)
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import archetype # noqa: E402
import cagelib # noqa: E402
L = 4.6
DESIGN = archetype.design(
'suv', length=L, width=1.86, wheelbase=2.69, front_overhang=0.92, wheel_radius=0.365,
nose=0.92, hood=1.12, roof=1.63, deck_height=1.3, tail=1.2,
cowl=0.95, roof_front=0.08, roof_rear=-1.86, deck=-2.12, rear='hatch',
sill=0.34, belt_front=1.12, belt_rear=1.22, tumblehome=0.15, crown=0.035,
nose_round=0.2, tail_round=0.12, nose_blunt=0.3, tail_blunt=0.3, arch_gap=0.06, flare=0.02,
trunk={'kind': 'tailgate', 'front': -1.88, 'rear': -L / 2},
)
cagelib.main(DESIGN)

25
assets/src/truck.py Normal file
View file

@ -0,0 +1,25 @@
"""
Truck cab cage: a light cab-over, the cab 2.0 x 2.0 x 2.27 m, 215/75 R17.5. A flat
face, an upright windscreen, one door a side; the load box is built apart.
python3 assets/src/truck.py -- --out src/generator/cages/truck.json
(or `bun run cages:build truck`; Blender only for --render)
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import archetype # noqa: E402
import cagelib # noqa: E402
L = 2.0
DESIGN = archetype.design(
'truck', length=L, width=2.0, wheelbase=3.4, front_overhang=1.05, wheel_radius=0.385,
nose=1.2, hood=1.38, roof=2.24, deck_height=2.2, tail=2.18,
cowl=0.8, roof_front=0.64, roof_rear=-0.94, deck=-0.97, rear='cab',
sill=0.56, nose_sill=0.7, tail_sill=0.6, belt_front=1.38, belt_rear=1.45, tumblehome=0.05, crown=0.03,
nose_round=0.14, tail_round=0.06, nose_blunt=0.7, tail_blunt=1.0, nose_rake=0.02, doors=1, hood_end=0,
arch_gap=0.08,
)
cagelib.main(DESIGN)

27
assets/src/van.py Normal file
View file

@ -0,0 +1,27 @@
"""
Van cage: a mid-size panel van, 5.0 x 1.99 x 1.94 m on a 2.93 m wheelbase,
215/65 R16. A short sloping nose, a tall box and a full-height tailgate.
python3 assets/src/van.py -- --out src/generator/cages/van.json
(or `bun run cages:build van`; Blender only for --render)
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import archetype # noqa: E402
import cagelib # noqa: E402
L = 5.0
DESIGN = archetype.design(
'van', length=L, width=1.99, wheelbase=2.93, front_overhang=0.93, wheel_radius=0.345,
nose=0.84, hood=1.1, roof=1.9, deck_height=1.86, tail=1.84,
cowl=1.75, roof_front=1.3, roof_rear=-2.4, deck=-2.45, rear='cab',
sill=0.32, belt_front=1.1, belt_rear=1.12, tumblehome=0.06, crown=0.04,
nose_round=0.2, tail_round=0.08, nose_blunt=0.4, tail_blunt=0.9,
# A long body: stations a little further apart keep LOD0 inside its budget.
extra={'spacing': 0.4},
trunk={'kind': 'tailgate', 'front': -2.42, 'rear': -L / 2},
)
cagelib.main(DESIGN)

26
assets/src/wagon.py Normal file
View file

@ -0,0 +1,26 @@
"""
Wagon cage: an estate, 4.8 x 1.84 x 1.47 m on a 2.85 m wheelbase. The sedan's front
with the roof carried back to a near-vertical tailgate.
python3 assets/src/wagon.py -- --out src/generator/cages/wagon.json
(or `bun run cages:build wagon`; Blender only for --render)
"""
import os
import sys
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import archetype # noqa: E402
import cagelib # noqa: E402
L = 4.8
DESIGN = archetype.design(
'wagon', length=L, width=1.84, wheelbase=2.85, front_overhang=0.95, wheel_radius=0.334,
nose=0.72, hood=0.96, roof=1.43, deck_height=1.13, tail=1.02,
cowl=1.0, roof_front=0.12, roof_rear=-2.0, deck=-2.22, rear='hatch',
sill=0.24, belt_rear=1.06, tumblehome=0.2, crown=0.04, nose_round=0.28, tail_round=0.12, tail_blunt=0.3,
# A long body: stations a little further apart keep LOD0 inside its budget.
extra={'spacing': 0.42, 'merge': 0.07},
trunk={'kind': 'tailgate', 'front': -2.02, 'rear': -L / 2},
)
cagelib.main(DESIGN)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 66 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 291 KiB

After

Width:  |  Height:  |  Size: 292 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 91 KiB

After

Width:  |  Height:  |  Size: 94 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 301 KiB

After

Width:  |  Height:  |  Size: 306 KiB

Before After
Before After

View file

@ -32,7 +32,10 @@ const args = process.argv.slice(2)
const renderAt = args.indexOf('--render') const renderAt = args.indexOf('--render')
const render = renderAt >= 0 ? ['--render', args[renderAt + 1]!] : [] const render = renderAt >= 0 ? ['--render', args[renderAt + 1]!] : []
const names = args.filter((a, i) => !a.startsWith('--') && i !== renderAt + 1) const names = args.filter((a, i) => !a.startsWith('--') && i !== renderAt + 1)
const styles = names.length ? names : readdirSync('assets/src').filter((f) => f.endsWith('.py') && f !== 'cagelib.py').map((f) => f.slice(0, -3)) // Shared modules, not archetypes: a change to one rebuilds every cage.
const SHARED = new Set(['cagelib.py', 'archetype.py'])
const archetypes = (): string[] => readdirSync('assets/src').filter((f) => f.endsWith('.py') && !SHARED.has(f)).map((f) => f.slice(0, -3))
const styles = names.length ? names : archetypes()
function build(list: readonly string[]): boolean { function build(list: readonly string[]): boolean {
for (const style of list) { for (const style of list) {
@ -40,12 +43,12 @@ function build(list: readonly string[]): boolean {
// Written beside, then moved over the checked-in JSON only when it changed, // Written beside, then moved over the checked-in JSON only when it changed,
// so an unchanged save does not reload the studio. // so an unchanged save does not reload the studio.
const out = `src/generator/cages/${style}.json` const out = `src/generator/cages/${style}.json`
const fresh = join(tmpdir(), `vehicle-generator-cage-${style}.json`) const fresh = join(tmpdir(), `vehicle-generator-cage-${style}-${process.pid}.json`)
const script = [`assets/src/${style}.py`, '--', '--out', fresh, ...render] const script = [`assets/src/${style}.py`, '--', '--out', fresh, ...render]
const run = render.length || !python ? spawnSync(blender, ['-b', '--factory-startup', '--python', ...script], { encoding: 'utf8' }) : spawnSync(python, script, { encoding: 'utf8' }) const run = render.length || !python ? spawnSync(blender, ['-b', '--factory-startup', '--python', ...script], { encoding: 'utf8' }) : spawnSync(python, script, { encoding: 'utf8' })
const lines = `${run.stdout}\n${run.stderr}`.split('\n').filter((l) => /^cage:|renders in|Error|Traceback|line \d+/.test(l)).map((l) => l.replace(fresh, out)) const lines = `${run.stdout}\n${run.stderr}`.split('\n').filter((l) => /^cage:|renders in|Error|Traceback|line \d+/.test(l)).map((l) => l.replace(fresh, out))
console.log(`${lines.join('\n')}${watching ? ` (${Math.round(performance.now() - t0)} ms)` : ''}`) console.log(`${lines.join('\n')}${watching ? ` (${Math.round(performance.now() - t0)} ms)` : ''}`)
if (run.status !== 0) return false if (run.status !== 0 || !existsSync(fresh)) return false
if (!existsSync(out) || readFileSync(out, 'utf8') !== readFileSync(fresh, 'utf8')) copyFileSync(fresh, out) if (!existsSync(out) || readFileSync(out, 'utf8') !== readFileSync(fresh, 'utf8')) copyFileSync(fresh, out)
rmSync(fresh) rmSync(fresh)
} }
@ -59,12 +62,11 @@ if (!watching) {
// A save to one archetype rebuilds it; a save to the shared library rebuilds // A save to one archetype rebuilds it; a save to the shared library rebuilds
// them all. Vite picks up the new JSON and the studio reloads in place. // them all. Vite picks up the new JSON and the studio reloads in place.
build(styles) build(styles)
const all = (): string[] => readdirSync('assets/src').filter((f) => f.endsWith('.py') && f !== 'cagelib.py').map((f) => f.slice(0, -3))
let pending = new Set<string>() let pending = new Set<string>()
let timer: ReturnType<typeof setTimeout> | null = null let timer: ReturnType<typeof setTimeout> | null = null
watch('assets/src', (_event, file) => { watch('assets/src', (_event, file) => {
if (!file || !file.endsWith('.py')) return if (!file || !file.endsWith('.py')) return
for (const style of file === 'cagelib.py' ? all() : [file.slice(0, -3)]) pending.add(style) for (const style of SHARED.has(file) ? archetypes() : [file.slice(0, -3)]) pending.add(style)
if (timer) clearTimeout(timer) if (timer) clearTimeout(timer)
timer = setTimeout(() => { timer = setTimeout(() => {
const list = [...pending].filter((s) => existsSync(`assets/src/${s}.py`)) const list = [...pending].filter((s) => existsSync(`assets/src/${s}.py`))

View file

@ -1,6 +1,18 @@
import type { Axle, BodyChannel } from './body.ts' import type { Axle, BodyChannel } from './body.ts'
import { emitSubdivided } from './cage.ts' import { emitSubdivided } from './cage.ts'
import sedan from './cages/sedan.json' import sedan from './cages/sedan.json'
import hatchback from './cages/hatchback.json'
import coupe from './cages/coupe.json'
import wagon from './cages/wagon.json'
import suv from './cages/suv.json'
import pickup from './cages/pickup.json'
import van from './cages/van.json'
import sports from './cages/sports.json'
import supercar from './cages/supercar.json'
import muscle from './cages/muscle.json'
import kei from './cages/kei.json'
import buggy from './cages/buggy.json'
import truck from './cages/truck.json'
import type { SinkSet } from './mesh.ts' import type { SinkSet } from './mesh.ts'
import type { BodySpec, LodLevel, PaintSpec } from './spec.ts' import type { BodySpec, LodLevel, PaintSpec } from './spec.ts'
import { edgeKey, type PolyMesh, subdivideTimes } from './subdiv.ts' import { edgeKey, type PolyMesh, subdivideTimes } from './subdiv.ts'
@ -37,7 +49,9 @@ export interface CageAsset {
readonly frame: { readonly columns: readonly string[]; readonly rows: readonly (readonly number[])[] } readonly frame: { readonly columns: readonly string[]; readonly rows: readonly (readonly number[])[] }
} }
const CAGES: Readonly<Record<string, CageAsset>> = { sedan: sedan as unknown as CageAsset } const CAGES: Readonly<Record<string, CageAsset>> = Object.fromEntries(
Object.entries({ sedan, hatchback, coupe, wagon, suv, pickup, van, sports, supercar, muscle, kei, buggy, truck }).map(([style, json]) => [style, json as unknown as CageAsset]),
)
export function cageFor(style: string): CageAsset | null { export function cageFor(style: string): CageAsset | null {
return CAGES[style] ?? null return CAGES[style] ?? null
@ -80,9 +94,13 @@ export function fitCage(asset: CageAsset, body: BodySpec, axles: readonly { read
const b = asset.base const b = asset.base
const L = body.length const L = body.length
// Authored anchors along Z, and where the spec wants them. // Authored anchors along Z, and where the spec wants them.
const from = [-b.length / 2, ...asset.axles.map((a) => a.z).sort((p, q) => p - q), b.length / 2] // Only axles under the body anchor the morph: a cab-over truck's rear axle
const specAxles = axles.map((a) => a.s).sort((p, q) => p - q) // sits under its load box, behind the cab the cage describes.
const to = [-L / 2, ...(specAxles.length === asset.axles.length ? specAxles : asset.axles.map((a) => a.z * L / b.length).sort((p, q) => p - q)), L / 2] const inside = (z: number, half: number): boolean => z > -half + 0.05 && z < half - 0.05
const cageAxles = asset.axles.map((a) => a.z).filter((z) => inside(z, b.length / 2)).sort((p, q) => p - q)
const from = [-b.length / 2, ...cageAxles, b.length / 2]
const specAxles = axles.map((a) => a.s).filter((z) => inside(z, L / 2)).sort((p, q) => p - q)
const to = [-L / 2, ...(specAxles.length === cageAxles.length ? specAxles : cageAxles.map((z) => z * L / b.length)), L / 2]
const piecewise = (xs: readonly number[], ys: readonly number[]) => (v: number): number => { const piecewise = (xs: readonly number[], ys: readonly number[]) => (v: number): number => {
let k = 0 let k = 0
while (k < xs.length - 2 && v > xs[k + 1]!) k += 1 while (k < xs.length - 2 && v > xs[k + 1]!) k += 1

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -117,7 +117,7 @@ const PRESETS: Readonly<Record<BodyStyle, Preset>> = {
hatchback: { hatchback: {
label: 'Hatchback', label: 'Hatchback',
body: { body: {
length: 4.28, width: 1.79, noseHeight: 0.79, hoodHeight: 0.98, roofHeight: 1.42, deckHeight: 1.13, length: 4.28, width: 1.79, noseHeight: 0.79, hoodHeight: 0.98, roofHeight: 1.41, deckHeight: 1.13,
tailHeight: 1.02, cowl: 0.66, roofFront: 0.49, roofRear: 0.1, deck: 0.035, noseRound: 0.2, tailRound: 0.12, tailHeight: 1.02, cowl: 0.66, roofFront: 0.49, roofRear: 0.1, deck: 0.035, noseRound: 0.2, tailRound: 0.12,
tumblehome: 0.18, tumblehome: 0.18,
}, },
@ -129,7 +129,7 @@ const PRESETS: Readonly<Record<BodyStyle, Preset>> = {
coupe: { coupe: {
label: 'Coupe', label: 'Coupe',
body: { body: {
length: 4.6, width: 1.85, sill: 0.18, noseHeight: 0.76, hoodHeight: 0.95, roofHeight: 1.33, deckHeight: 1.03, length: 4.6, width: 1.85, sill: 0.18, noseHeight: 0.76, hoodHeight: 0.95, roofHeight: 1.31, deckHeight: 1.03,
tailHeight: 0.99, cowl: 0.63, roofFront: 0.47, roofRear: 0.29, deck: 0.15, doors: 1, tumblehome: 0.24, sideBulge: 0.55, tailHeight: 0.99, cowl: 0.63, roofFront: 0.47, roofRear: 0.29, deck: 0.15, doors: 1, tumblehome: 0.24, sideBulge: 0.55,
}, },
wheels: { radius: 0.335, width: 0.245, rim: 'multispoke', spokes: 10, rimRatio: 0.7 }, wheels: { radius: 0.335, width: 0.245, rim: 'multispoke', spokes: 10, rimRatio: 0.7 },
@ -140,7 +140,7 @@ const PRESETS: Readonly<Record<BodyStyle, Preset>> = {
wagon: { wagon: {
label: 'Wagon', label: 'Wagon',
body: { body: {
length: 4.8, roofHeight: 1.46, roofRear: 0.06, deck: 0.03, deckHeight: 1.13, tailHeight: 1.03, tailRound: 0.12, length: 4.8, roofHeight: 1.43, roofRear: 0.06, deck: 0.03, deckHeight: 1.13, tailHeight: 1.03, tailRound: 0.12,
roofFront: 0.49, cowl: 0.65, roofFront: 0.49, cowl: 0.65,
}, },
wheels: { rim: 'mesh', spokes: 8 }, wheels: { rim: 'mesh', spokes: 8 },
@ -151,7 +151,7 @@ const PRESETS: Readonly<Record<BodyStyle, Preset>> = {
suv: { suv: {
label: 'SUV', label: 'SUV',
body: { body: {
length: 4.6, width: 1.86, sill: 0.34, noseHeight: 0.96, hoodHeight: 1.13, roofHeight: 1.66, deckHeight: 1.3, length: 4.6, width: 1.86, sill: 0.34, noseHeight: 0.96, hoodHeight: 1.13, roofHeight: 1.63, deckHeight: 1.3,
tailHeight: 1.17, cowl: 0.64, roofFront: 0.5, roofRear: 0.08, deck: 0.03, noseRound: 0.2, tailRound: 0.12, tailHeight: 1.17, cowl: 0.64, roofFront: 0.5, roofRear: 0.08, deck: 0.03, noseRound: 0.2, tailRound: 0.12,
tumblehome: 0.15, bumpers: 'black', flare: 0.02, archGap: 0.06, noseTaper: 0.04, tumblehome: 0.15, bumpers: 'black', flare: 0.02, archGap: 0.06, noseTaper: 0.04,
}, },
@ -163,7 +163,7 @@ const PRESETS: Readonly<Record<BodyStyle, Preset>> = {
pickup: { pickup: {
label: 'Pickup', label: 'Pickup',
body: { body: {
length: 5.4, width: 2.0, sill: 0.5, noseHeight: 1.16, hoodHeight: 1.3, roofHeight: 1.88, deckHeight: 1.3, length: 5.4, width: 2.0, sill: 0.5, noseHeight: 1.16, hoodHeight: 1.3, roofHeight: 1.85, deckHeight: 1.3,
tailHeight: 1.3, cowl: 0.73, roofFront: 0.63, roofRear: 0.46, deck: 0.44, noseRound: 0.16, tailRound: 0.06, tailHeight: 1.3, cowl: 0.73, roofFront: 0.63, roofRear: 0.46, deck: 0.44, noseRound: 0.16, tailRound: 0.06,
tumblehome: 0.1, bed: { start: 0.02, end: 0.42, depth: 0.52 }, bumpers: 'chrome', flare: 0.02, archGap: 0.07, tumblehome: 0.1, bed: { start: 0.02, end: 0.42, depth: 0.52 }, bumpers: 'chrome', flare: 0.02, archGap: 0.07,
noseTaper: 0.02, tailTaper: 0, hoodCrown: 0.02, noseTaper: 0.02, tailTaper: 0, hoodCrown: 0.02,
@ -176,7 +176,7 @@ const PRESETS: Readonly<Record<BodyStyle, Preset>> = {
van: { van: {
label: 'Van', label: 'Van',
body: { body: {
length: 5.0, width: 1.99, sill: 0.32, noseHeight: 0.88, hoodHeight: 1.1, roofHeight: 1.93, deckHeight: 1.88, length: 5.0, width: 1.99, sill: 0.32, noseHeight: 0.88, hoodHeight: 1.1, roofHeight: 1.9, deckHeight: 1.88,
tailHeight: 1.84, cowl: 0.85, roofFront: 0.76, roofRear: 0.02, deck: 0.01, noseRound: 0.2, tailRound: 0.08, tailHeight: 1.84, cowl: 0.85, roofFront: 0.76, roofRear: 0.02, deck: 0.01, noseRound: 0.2, tailRound: 0.08,
tumblehome: 0.06, greenhouseWidth: 0.95, bumpers: 'black', roofCrown: 0.04, sideBulge: 0.2, tumblehome: 0.06, greenhouseWidth: 0.95, bumpers: 'black', roofCrown: 0.04, sideBulge: 0.2,
}, },
@ -188,7 +188,7 @@ const PRESETS: Readonly<Record<BodyStyle, Preset>> = {
sports: { sports: {
label: 'Sports', label: 'Sports',
body: { body: {
length: 4.25, width: 1.78, sill: 0.14, noseHeight: 0.66, hoodHeight: 0.87, roofHeight: 1.27, deckHeight: 0.97, length: 4.25, width: 1.78, sill: 0.14, noseHeight: 0.66, hoodHeight: 0.87, roofHeight: 1.25, deckHeight: 0.97,
tailHeight: 0.93, cowl: 0.62, roofFront: 0.47, roofRear: 0.3, deck: 0.18, doors: 1, tumblehome: 0.24, sideBulge: 0.65, tailHeight: 0.93, cowl: 0.62, roofFront: 0.47, roofRear: 0.3, deck: 0.18, doors: 1, tumblehome: 0.24, sideBulge: 0.65,
flare: 0.02, noseRound: 0.24, roofCrown: 0.03, flare: 0.02, noseRound: 0.24, roofCrown: 0.03,
}, },
@ -200,7 +200,7 @@ const PRESETS: Readonly<Record<BodyStyle, Preset>> = {
supercar: { supercar: {
label: 'Supercar', label: 'Supercar',
body: { body: {
length: 4.5, width: 1.93, sill: 0.12, noseHeight: 0.56, hoodHeight: 0.8, roofHeight: 1.14, deckHeight: 0.99, length: 4.5, width: 1.93, sill: 0.12, noseHeight: 0.56, hoodHeight: 0.8, roofHeight: 1.12, deckHeight: 0.99,
tailHeight: 0.97, cowl: 0.7, roofFront: 0.58, roofRear: 0.38, deck: 0.28, noseRound: 0.3, tailRound: 0.16, tailHeight: 0.97, cowl: 0.7, roofFront: 0.58, roofRear: 0.38, deck: 0.28, noseRound: 0.3, tailRound: 0.16,
doors: 1, tumblehome: 0.28, sideBulge: 0.8, flare: 0.03, hoodCrown: 0.02, roofCrown: 0.03, noseTaper: 0.08, doors: 1, tumblehome: 0.28, sideBulge: 0.8, flare: 0.03, hoodCrown: 0.02, roofCrown: 0.03, noseTaper: 0.08,
}, },
@ -212,7 +212,7 @@ const PRESETS: Readonly<Record<BodyStyle, Preset>> = {
muscle: { muscle: {
label: 'Muscle', label: 'Muscle',
body: { body: {
length: 4.8, width: 1.9, sill: 0.18, noseHeight: 0.84, hoodHeight: 0.97, roofHeight: 1.3, deckHeight: 1.02, length: 4.8, width: 1.9, sill: 0.18, noseHeight: 0.84, hoodHeight: 0.97, roofHeight: 1.28, deckHeight: 1.02,
tailHeight: 1.0, cowl: 0.58, roofFront: 0.45, roofRear: 0.3, deck: 0.13, noseRound: 0.1, tailRound: 0.1, tailHeight: 1.0, cowl: 0.58, roofFront: 0.45, roofRear: 0.3, deck: 0.13, noseRound: 0.1, tailRound: 0.1,
doors: 1, bumpers: 'chrome', noseTaper: 0.02, tailTaper: 0.01, sideBulge: 0.35, hoodCrown: 0.02, doors: 1, bumpers: 'chrome', noseTaper: 0.02, tailTaper: 0.01, sideBulge: 0.35, hoodCrown: 0.02,
}, },
@ -224,7 +224,7 @@ const PRESETS: Readonly<Record<BodyStyle, Preset>> = {
kei: { kei: {
label: 'Kei car', label: 'Kei car',
body: { body: {
length: 3.395, width: 1.475, sill: 0.19, noseHeight: 0.8, hoodHeight: 0.94, roofHeight: 1.75, deckHeight: 1.3, length: 3.395, width: 1.475, sill: 0.19, noseHeight: 0.8, hoodHeight: 0.94, roofHeight: 1.72, deckHeight: 1.3,
tailHeight: 1.12, cowl: 0.8, roofFront: 0.7, roofRear: 0.06, deck: 0.03, noseRound: 0.16, tailRound: 0.08, tailHeight: 1.12, cowl: 0.8, roofFront: 0.7, roofRear: 0.06, deck: 0.03, noseRound: 0.16, tailRound: 0.08,
tumblehome: 0.06, greenhouseWidth: 0.94, bumpers: 'black', sideBulge: 0.2, noseTaper: 0.03, tailTaper: 0.01, tumblehome: 0.06, greenhouseWidth: 0.94, bumpers: 'black', sideBulge: 0.2, noseTaper: 0.03, tailTaper: 0.01,
}, },
@ -236,7 +236,7 @@ const PRESETS: Readonly<Record<BodyStyle, Preset>> = {
buggy: { buggy: {
label: 'Buggy', label: 'Buggy',
body: { body: {
length: 3.6, width: 1.8, sill: 0.46, noseHeight: 0.72, hoodHeight: 0.92, roofHeight: 0.92, deckHeight: 0.96, length: 3.6, width: 1.8, sill: 0.46, noseHeight: 0.72, hoodHeight: 0.92, roofHeight: 0.96, deckHeight: 0.96,
tailHeight: 0.9, cowl: 0.62, roofFront: 0.56, roofRear: 0.36, deck: 0.3, noseRound: 0.3, tailRound: 0.2, tailHeight: 0.9, cowl: 0.62, roofFront: 0.56, roofRear: 0.36, deck: 0.3, noseRound: 0.3, tailRound: 0.2,
doors: 0, bumpers: 'black', flare: 0, archGap: 0.09, tumblehome: 0, greenhouseWidth: 0.92, noseTaper: 0.2, doors: 0, bumpers: 'black', flare: 0, archGap: 0.09, tumblehome: 0, greenhouseWidth: 0.92, noseTaper: 0.2,
}, },
@ -249,7 +249,7 @@ const PRESETS: Readonly<Record<BodyStyle, Preset>> = {
truck: { truck: {
label: 'Truck cab', label: 'Truck cab',
body: { body: {
length: 2.0, width: 2.0, sill: 0.56, noseHeight: 1.2, hoodHeight: 1.38, roofHeight: 2.26, deckHeight: 2.22, length: 2.0, width: 2.0, sill: 0.56, noseHeight: 1.2, hoodHeight: 1.38, roofHeight: 2.24, deckHeight: 2.22,
tailHeight: 2.18, cowl: 0.9, roofFront: 0.82, roofRear: 0.03, deck: 0.015, noseRound: 0.14, tailRound: 0.06, tailHeight: 2.18, cowl: 0.9, roofFront: 0.82, roofRear: 0.03, deck: 0.015, noseRound: 0.14, tailRound: 0.06,
tumblehome: 0.05, greenhouseWidth: 0.97, bumpers: 'black', sideBulge: 0.1, doors: 1, noseTaper: 0.02, tailTaper: 0, tumblehome: 0.05, greenhouseWidth: 0.97, bumpers: 'black', sideBulge: 0.1, doors: 1, noseTaper: 0.02, tailTaper: 0,
archGap: 0.08, roofCrown: 0.04, archGap: 0.08, roofCrown: 0.04,

View file

@ -12,6 +12,7 @@ import {
} from 'three' } from 'three'
import { type BodyFrame, buildBody, type Openable } from './body.ts' import { type BodyFrame, buildBody, type Openable } from './body.ts'
import { cageFor } from './cageAsset.ts'
import { buildCollider, type VehicleCollider } from './collider.ts' import { buildCollider, type VehicleCollider } from './collider.ts'
import { clamp } from './curve.ts' import { clamp } from './curve.ts'
import { buildBays } from './bays.ts' import { buildBays } from './bays.ts'
@ -132,9 +133,6 @@ interface NodeInfo {
} }
/** Generates a vehicle. Pure: the same spec gives the same geometry, byte for byte. */ /** Generates a vehicle. Pure: the same spec gives the same geometry, byte for byte. */
/** Styles whose skin is built as a subdivision surface. */
const CAGE_STYLES = new Set<string>(['sedan'])
export function generateVehicle(source: VehicleSpec, options: GenerateOptions = {}): Vehicle { export function generateVehicle(source: VehicleSpec, options: GenerateOptions = {}): Vehicle {
const spec = sanitizeSpec(applyModSpecs(source)) const spec = sanitizeSpec(applyModSpecs(source))
const levels = [...new Set(options.lods ?? [0, 1, 2])].sort() as LodLevel[] const levels = [...new Set(options.lods ?? [0, 1, 2])].sort() as LodLevel[]
@ -251,7 +249,7 @@ export function generateVehicle(source: VehicleSpec, options: GenerateOptions =
ride: spec.chassis.rideHeight, ride: spec.chassis.rideHeight,
lod: level, lod: level,
flare: 0, flare: 0,
skin: options.skin ?? (CAGE_STYLES.has(spec.style) ? 'cage' : 'loft'), skin: options.skin ?? (cageFor(spec.style) ? 'cage' : 'loft'),
style: spec.style, style: spec.style,
}, sinks) }, sinks)