From d8f3a6e3df66dd89fb7645872544a304bf1fff47 Mon Sep 17 00:00:00 2001 From: CRT Date: Sun, 11 Oct 2026 00:22:23 +0000 Subject: [PATCH] Vehicle Generator 0.1.0 (alpha) Procedural, game-ready vehicles for three.js: 13 body styles, blending, seeded random vehicles, three LODs, colliders, 13 parametric mods, paint and livery, a rig that drives, and GLB export that a game can load and drive. Ships with a studio (browser or Tauri desktop app) and a Play mode. --- .gitattributes | 6 + .gitignore | 20 + LICENSE | 21 + README.md | 339 ++ art/brand/masters/wireframe.png | Bin 0 -> 1572831 bytes assets/src/cagelib.py | 557 +++ assets/src/sedan.py | 79 + bun.lock | 203 + index.html | 17 + media/icon.png | Bin 0 -> 1916666 bytes media/lods.png | Bin 0 -> 62696 bytes media/random.png | Bin 0 -> 297989 bytes media/rig.png | Bin 0 -> 93437 bytes media/sedan.png | Bin 0 -> 137170 bytes media/studio.png | Bin 0 -> 464255 bytes media/styles.png | Bin 0 -> 308105 bytes package.json | 64 + scripts/cages.ts | 76 + scripts/check-docs.ts | 48 + scripts/export-glb.ts | 60 + scripts/glb-node.ts | 23 + scripts/raster.ts | 347 ++ scripts/render.ts | 78 + scripts/verify-glb.ts | 151 + scripts/verify.ts | 409 ++ src-tauri/.gitignore | 2 + src-tauri/Cargo.lock | 4931 +++++++++++++++++++++++++ src-tauri/Cargo.toml | 33 + src-tauri/build.rs | 3 + src-tauri/capabilities/default.json | 18 + src-tauri/icons/128x128.png | Bin 0 -> 34179 bytes src-tauri/icons/128x128@2x.png | Bin 0 -> 119267 bytes src-tauri/icons/32x32.png | Bin 0 -> 2954 bytes src-tauri/icons/64x64.png | Bin 0 -> 9831 bytes src-tauri/icons/Square107x107Logo.png | Bin 0 -> 24861 bytes src-tauri/icons/Square142x142Logo.png | Bin 0 -> 41233 bytes src-tauri/icons/Square150x150Logo.png | Bin 0 -> 45479 bytes src-tauri/icons/Square284x284Logo.png | Bin 0 -> 144171 bytes src-tauri/icons/Square30x30Logo.png | Bin 0 -> 2615 bytes src-tauri/icons/Square310x310Logo.png | Bin 0 -> 169677 bytes src-tauri/icons/Square44x44Logo.png | Bin 0 -> 5115 bytes src-tauri/icons/Square71x71Logo.png | Bin 0 -> 12006 bytes src-tauri/icons/Square89x89Logo.png | Bin 0 -> 17759 bytes src-tauri/icons/StoreLogo.png | Bin 0 -> 6438 bytes src-tauri/icons/icon.icns | Bin 0 -> 2687978 bytes src-tauri/icons/icon.ico | Bin 0 -> 141780 bytes src-tauri/icons/icon.png | Bin 0 -> 432859 bytes src-tauri/src/lib.rs | 49 + src-tauri/src/main.rs | 6 + src-tauri/src/window_mode.rs | 124 + src-tauri/tauri.conf.json | 60 + src-tauri/tauri.linux.conf.json | 5 + src-tauri/tauri.macos.conf.json | 23 + src-tauri/tauri.windows.conf.json | 14 + src/app/about.ts | 43 + src/app/assets/mark.png | Bin 0 -> 139272 bytes src/app/build.ts | 62 + src/app/context.ts | 59 + src/app/customs.ts | 160 + src/app/devlog.ts | 14 + src/app/drive.ts | 752 ++++ src/app/editing.ts | 116 + src/app/exporting.ts | 110 + src/app/garage.ts | 233 ++ src/app/icons.ts | 28 + src/app/inspector.ts | 175 + src/app/keys.ts | 75 + src/app/layout.ts | 25 + src/app/main.ts | 110 + src/app/menubar.ts | 110 + src/app/palette.ts | 44 + src/app/play.ts | 79 + src/app/popovers.ts | 72 + src/app/prefs.ts | 7 + src/app/render.ts | 14 + src/app/resume.ts | 50 + src/app/scene.ts | 332 ++ src/app/showcase.ts | 40 + src/app/status.ts | 19 + src/app/studio.css | 626 ++++ src/app/toolbar.ts | 52 + src/app/ui.ts | 276 ++ src/app/windowbar.ts | 148 + src/generator/bays.ts | 234 ++ src/generator/blend.ts | 167 + src/generator/body.ts | 1037 ++++++ src/generator/cage.ts | 435 +++ src/generator/cageAsset.ts | 279 ++ src/generator/cages/sedan.json | 1 + src/generator/collider.ts | 83 + src/generator/curve.ts | 84 + src/generator/export.ts | 44 + src/generator/index.ts | 26 + src/generator/interior.ts | 109 + src/generator/materials.ts | 172 + src/generator/mesh.ts | 436 +++ src/generator/mods.ts | 542 +++ src/generator/palette.ts | 98 + src/generator/presets.ts | 283 ++ src/generator/random.ts | 42 + src/generator/rig.ts | 262 ++ src/generator/spec.ts | 183 + src/generator/subdiv.ts | 177 + src/generator/vehicle.ts | 448 +++ src/generator/wheel.ts | 283 ++ src/library/format.ts | 131 + src/library/store.ts | 136 + src/library/zip.ts | 77 + tools/brand.py | 94 + tools/brand_mask.py | 58 + tsconfig.json | 17 + vite.config.ts | 49 + 112 files changed, 17584 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 art/brand/masters/wireframe.png create mode 100644 assets/src/cagelib.py create mode 100644 assets/src/sedan.py create mode 100644 bun.lock create mode 100644 index.html create mode 100644 media/icon.png create mode 100644 media/lods.png create mode 100644 media/random.png create mode 100644 media/rig.png create mode 100644 media/sedan.png create mode 100644 media/studio.png create mode 100644 media/styles.png create mode 100644 package.json create mode 100644 scripts/cages.ts create mode 100644 scripts/check-docs.ts create mode 100644 scripts/export-glb.ts create mode 100644 scripts/glb-node.ts create mode 100644 scripts/raster.ts create mode 100644 scripts/render.ts create mode 100644 scripts/verify-glb.ts create mode 100644 scripts/verify.ts create mode 100644 src-tauri/.gitignore create mode 100644 src-tauri/Cargo.lock create mode 100644 src-tauri/Cargo.toml create mode 100644 src-tauri/build.rs create mode 100644 src-tauri/capabilities/default.json create mode 100644 src-tauri/icons/128x128.png create mode 100644 src-tauri/icons/128x128@2x.png create mode 100644 src-tauri/icons/32x32.png create mode 100644 src-tauri/icons/64x64.png create mode 100644 src-tauri/icons/Square107x107Logo.png create mode 100644 src-tauri/icons/Square142x142Logo.png create mode 100644 src-tauri/icons/Square150x150Logo.png create mode 100644 src-tauri/icons/Square284x284Logo.png create mode 100644 src-tauri/icons/Square30x30Logo.png create mode 100644 src-tauri/icons/Square310x310Logo.png create mode 100644 src-tauri/icons/Square44x44Logo.png create mode 100644 src-tauri/icons/Square71x71Logo.png create mode 100644 src-tauri/icons/Square89x89Logo.png create mode 100644 src-tauri/icons/StoreLogo.png create mode 100644 src-tauri/icons/icon.icns create mode 100644 src-tauri/icons/icon.ico create mode 100644 src-tauri/icons/icon.png create mode 100644 src-tauri/src/lib.rs create mode 100644 src-tauri/src/main.rs create mode 100644 src-tauri/src/window_mode.rs create mode 100644 src-tauri/tauri.conf.json create mode 100644 src-tauri/tauri.linux.conf.json create mode 100644 src-tauri/tauri.macos.conf.json create mode 100644 src-tauri/tauri.windows.conf.json create mode 100644 src/app/about.ts create mode 100644 src/app/assets/mark.png create mode 100644 src/app/build.ts create mode 100644 src/app/context.ts create mode 100644 src/app/customs.ts create mode 100644 src/app/devlog.ts create mode 100644 src/app/drive.ts create mode 100644 src/app/editing.ts create mode 100644 src/app/exporting.ts create mode 100644 src/app/garage.ts create mode 100644 src/app/icons.ts create mode 100644 src/app/inspector.ts create mode 100644 src/app/keys.ts create mode 100644 src/app/layout.ts create mode 100644 src/app/main.ts create mode 100644 src/app/menubar.ts create mode 100644 src/app/palette.ts create mode 100644 src/app/play.ts create mode 100644 src/app/popovers.ts create mode 100644 src/app/prefs.ts create mode 100644 src/app/render.ts create mode 100644 src/app/resume.ts create mode 100644 src/app/scene.ts create mode 100644 src/app/showcase.ts create mode 100644 src/app/status.ts create mode 100644 src/app/studio.css create mode 100644 src/app/toolbar.ts create mode 100644 src/app/ui.ts create mode 100644 src/app/windowbar.ts create mode 100644 src/generator/bays.ts create mode 100644 src/generator/blend.ts create mode 100644 src/generator/body.ts create mode 100644 src/generator/cage.ts create mode 100644 src/generator/cageAsset.ts create mode 100644 src/generator/cages/sedan.json create mode 100644 src/generator/collider.ts create mode 100644 src/generator/curve.ts create mode 100644 src/generator/export.ts create mode 100644 src/generator/index.ts create mode 100644 src/generator/interior.ts create mode 100644 src/generator/materials.ts create mode 100644 src/generator/mesh.ts create mode 100644 src/generator/mods.ts create mode 100644 src/generator/palette.ts create mode 100644 src/generator/presets.ts create mode 100644 src/generator/random.ts create mode 100644 src/generator/rig.ts create mode 100644 src/generator/spec.ts create mode 100644 src/generator/subdiv.ts create mode 100644 src/generator/vehicle.ts create mode 100644 src/generator/wheel.ts create mode 100644 src/library/format.ts create mode 100644 src/library/store.ts create mode 100644 src/library/zip.ts create mode 100644 tools/brand.py create mode 100644 tools/brand_mask.py create mode 100644 tsconfig.json create mode 100644 vite.config.ts diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e0849d3 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +* text=auto eol=lf +*.png binary +*.jpg binary +*.glb binary +*.ico binary +*.icns binary diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..702568d --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +node_modules/ +dist/ + +# Regenerated by `bun run render` and `bun run export:glb`. +renders/ +glb/ + +*.log +*.tgz +*.tsbuildinfo +.DS_Store + +# Local tool and agent state. +.omc/ +.claude/ +.scratch/ +__pycache__/ + +# Private working notes, kept off the public repo. +docs/HANDOFF.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2e4bee1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 CRTkafa + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f11d852 --- /dev/null +++ b/README.md @@ -0,0 +1,339 @@ +# vehicle-generator + +**Alpha · in development.** Things work, things change; the spec format and the +API may still move between 0.x releases. + +Procedural, game-ready vehicles for [three.js](https://threejs.org). Give it a +spec (a body style, some proportions, a paint job, a list of mods) and it +builds a rigged car with three levels of detail, a physics collider and a GLB +you can drop into any engine. The same spec always produces the same vertices. + +![A generated sedan](media/sedan.png) + +It ships as a TypeScript library and as **Vehicle Generator**, a studio app for +shaping cars, fitting parts, driving them and exporting them. The studio runs +in a browser or as a desktop app. + +![Every body style](media/styles.png) + +## Status + +Version 0.1.0, alpha. + +**Works today** + +- The library: 13 body styles, blending, seeded random vehicles, three LODs, + colliders, 13 mods, paint and livery, the rig, and GLB export that a game can + load and drive. +- The studio, in a browser or as a desktop app: garage, customs, properties, + export, undo and autosave. +- Play mode: drive any vehicle on a generated circuit or in traffic. + +**In progress** + +- Bodies drawn from authored cages. The sedan is the first: its shape comes + from a control cage subdivided at run time. The other twelve styles still + use the older lofted body and are moving over one by one. + +**Planned** + +- One-click import into Godot, Unity and Unreal (shown as *planned* in the + studio's export menu; today you export GLB or spec JSON). +- Physics values for game engines: mass, centre of mass, springs, dampers, + steering lock and a torque curve, exported with the GLB. +- Interiors with real seats, dashboards and door cards; more part variants per + style; paint slots and finishes; a photo mode; two-wheelers. + +## What you get + +- **13 body styles**: `sedan`, `hatchback`, `coupe`, `wagon`, `suv`, `pickup`, + `van`, `sports`, `supercar`, `muscle`, `kei`, `buggy` and `truck` (a cab-over + with a load box). Each is a preset of the same generator, so any two can be + blended: a hatchback 40 % of the way to an SUV is a crossover. +- **Real proportions.** Every preset is measured off a real vehicle of its + segment: overall dimensions, wheelbase, overhangs, tyre size, and where the + 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. +- **Smooth bodies, not boxes.** The sedan's body is a subdivision surface: + an authored control cage (`assets/src/sedan.py`) is fitted to the spec, + subdivided with creases and split into panels with real gaps. The other + styles are lofted from cross-sections driven by profile curves. Either way, + hard creases sit where a real car has them: the shoulder, + 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 + rolled lips. The glass is flush. Lamps are recessed reflectors behind clear + lenses. The car also gets a grille, mirrors, door handles, wipers, licence + plates, brake discs and calipers. Tyres have sidewalls and tread, and there + are seven rim styles. An interior sits behind tinted, reflective glass. +- **Under the panels.** Open the bonnet and there is an engine bay: firewall, + inner wings, strut towers, an engine with its cam cover and intake, a + radiator and fan, a battery, fluid reservoirs and hoses. The boot has a + carpeted load floor and a spare wheel in its well. Hatchbacks, wagons, + SUVs, vans and kei cars lift a whole tailgate. The supercar is mid-engined: + the engine sits under the rear lid and the bonnet covers a front boot. +- **Levels of detail.** For the default sedan, LOD0 is 56,828 triangles, LOD1 + is 20,720 and LOD2 is 4,364. A `THREE.LOD` switches between them by + distance. Stock vehicles stay under 60k triangles on LOD0, and mods may add + up to 6k more. +- **A rig that drives.** Wheels spin and the front pair steers with Ackermann + geometry. Doors, bonnet and boot (or tailgate) open on hinges, and the + steering wheel turns. The body rolls and pitches on its suspension while the + wheels stay planted. Head-, tail- and brake lights switch on and off. Every + pivot sits at its hinge or axle, so each motion is a single rotation. +- **Collision.** You get a convex hull of the body and a two-box compound, + plus wheel positions and radii for a raycast-vehicle setup. +- **13 composable mods**: `spoiler`, `bodyKit`, `widebody`, `suspension`, + `wheelSet`, `bullBar`, `roofRack`, `snorkel`, `exhaust`, `hoodScoop`, + `lightBar`, `rollCage` and `mudFlaps`. Each is parametric and fits every body + style, because it is placed against the body's own curves. +- **Paint.** Finishes are solid, metallic, pearl and matte, built on + `MeshPhysicalMaterial` clearcoat and iridescence. You also get two-tone + (roof, lower or upper body), twin-stripe, side-stripe and rally liveries, separate rim, trim + and caliper colours, curated palettes, and a seeded random that picks + believable colours. +- **GLB export that round-trips.** Node names, pivots, rig tags, vertex + colours, clearcoat and animation clips all survive the export, and + `createRig()` drives a re-imported GLB the same way it drives the generated + car. + +![Doors, bonnet and tailgate open, wheels steered, lights on](media/rig.png) + +## Quick start + +Requires [Bun](https://bun.sh). + +```sh +bun install +bun run dev # the studio at http://localhost:5173 +``` + +### Use the library + +```ts +import { generateVehicle, preset, randomSpec, exportVehicleGlb } from 'vehicle-generator' + +const car = generateVehicle(preset('hatchback')) +scene.add(car.group) + +// Drive it. +car.rig.setSteer(0.3) // radians, positive is left; also turns the steering wheel +car.rig.update(dt, speed) // rolls the wheels for a car moving at `speed` m/s +car.rig.open('doorFL', 1) // 0 = shut, 1 = open; also 'hood' and 'trunk' +car.rig.setBodyPose(roll, pitch) // lean the sprung body; the wheels stay planted +car.rig.setBrake(true) +car.rig.setHeadlights(true) + +// Physics. +car.collider.hull // convex BufferGeometry of the body +car.wheels // hub positions, radius, width, steer/drive flags + +// Repaint without a rebuild. +car.setPaint({ ...car.spec.paint, primary: '#1f3a5f', finish: 'pearl' }) + +// A random vehicle, and a GLB of it. +const other = generateVehicle(randomSpec(1234)) +const glb = await exportVehicleGlb(other) // ArrayBuffer, LOD0 plus animation clips +``` + +The generator imports plain `three`, so it works with `WebGLRenderer` and with +`WebGPURenderer`. The frame is glTF's: +Y up, the vehicle faces +Z, +X is its +left, and the ground is y = 0. + +### Load a GLB in a game and drive it + +```ts +import { createRig } from 'vehicle-generator' + +const gltf = await new GLTFLoader().loadAsync('hatchback.glb') +const rig = createRig(gltf.scene) // reads the tags stored in glTF extras +rig.setSteer(-0.2) +rig.open('trunk', 1) +``` + +Clips named `open_` and `wheels_roll` come with the file, for engines +that prefer animation clips to code. + +## The spec + +A `VehicleSpec` is plain JSON: + +```jsonc +{ + "style": "pickup", + "seed": 42, + "body": { "length": 5.3, "width": 1.95, "roofHeight": 1.9, "cowl": 0.72, "bed": { "start": 0.02, "end": 0.42, "depth": 0.5 } }, + "wheels": { "radius": 0.4, "width": 0.265, "rim": "spoke", "spokes": 6, "tread": "offroad", "camber": 0 }, + "chassis": { "wheelbase": 3.4, "frontOverhang": 0.9, "track": 0.86, "rideHeight": 0, "drive": "rwd" }, + "cargo": { "type": "none", "length": 0, "height": 0 }, + "paint": { "primary": "#7a1f1f", "finish": "solid", "twoTone": "none", "livery": "none" }, + "mods": [{ "kind": "bullBar", "params": { "height": 0.45 } }, { "kind": "suspension", "params": { "height": 0.1 } }] +} +``` + +Start from `preset(style)` and change what you need. Longitudinal stations +(`cowl`, `roofFront`, `roofRear`, `deck`) are fractions of the body length +measured from the rear, so they stay put when the length changes. +`blendSpecs(a, b, t)` interpolates two specs. `randomSpec(seed, { style })` +draws one. + +### Mods + +A mod is `{ kind, params }`. `MODS[kind].params` describes its controls (number +ranges and option lists), and the studio builds its inspector from that. Some +mods change the spec before the build: `widebody` widens the arches and the +track, `suspension` moves the body, and `wheelSet` swaps the wheels. The rest +add geometry afterwards. Each lands in its own node (`mod_roofRack`, +`mod_spoiler`, and so on). Mods mounted on something that opens are parented to +it: a boot-lid spoiler rides the lid and a hood scoop rides the bonnet. + +## Node layout + +``` +vehicle_