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.
2
src-tauri/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/target/
|
||||
/gen/schemas
|
||||
4931
src-tauri/Cargo.lock
generated
Normal file
33
src-tauri/Cargo.toml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
[package]
|
||||
name = "vehicle-generator"
|
||||
version = "0.1.0"
|
||||
description = "Vehicle Generator — procedural vehicle generator"
|
||||
authors = ["CRTkafa"]
|
||||
license = "MIT"
|
||||
repository = "https://git.crt.fyi/CRT/vehicle-generator"
|
||||
edition = "2021"
|
||||
rust-version = "1.77.2"
|
||||
|
||||
[lib]
|
||||
name = "vehicle_generator_lib"
|
||||
crate-type = ["staticlib", "cdylib", "rlib"]
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "2", features = [] }
|
||||
|
||||
[dependencies]
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
log = "0.4"
|
||||
tauri = { version = "2", features = [] }
|
||||
tauri-plugin-log = "2"
|
||||
|
||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||
tauri-plugin-single-instance = "2"
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
opt-level = "s"
|
||||
panic = "abort"
|
||||
strip = true
|
||||
3
src-tauri/build.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
||||
18
src-tauri/capabilities/default.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Window chrome for the frameless studio window.",
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"core:window:allow-start-dragging",
|
||||
"core:window:allow-minimize",
|
||||
"core:window:allow-toggle-maximize",
|
||||
"core:window:allow-close",
|
||||
"core:window:allow-show",
|
||||
"core:window:allow-set-focus",
|
||||
"core:window:allow-set-fullscreen",
|
||||
"core:window:allow-is-fullscreen",
|
||||
"core:window:allow-is-maximized"
|
||||
]
|
||||
}
|
||||
BIN
src-tauri/icons/128x128.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
src-tauri/icons/128x128@2x.png
Normal file
|
After Width: | Height: | Size: 116 KiB |
BIN
src-tauri/icons/32x32.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
src-tauri/icons/64x64.png
Normal file
|
After Width: | Height: | Size: 9.6 KiB |
BIN
src-tauri/icons/Square107x107Logo.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
src-tauri/icons/Square142x142Logo.png
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
src-tauri/icons/Square150x150Logo.png
Normal file
|
After Width: | Height: | Size: 44 KiB |
BIN
src-tauri/icons/Square284x284Logo.png
Normal file
|
After Width: | Height: | Size: 141 KiB |
BIN
src-tauri/icons/Square30x30Logo.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
src-tauri/icons/Square310x310Logo.png
Normal file
|
After Width: | Height: | Size: 166 KiB |
BIN
src-tauri/icons/Square44x44Logo.png
Normal file
|
After Width: | Height: | Size: 5 KiB |
BIN
src-tauri/icons/Square71x71Logo.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
src-tauri/icons/Square89x89Logo.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
src-tauri/icons/StoreLogo.png
Normal file
|
After Width: | Height: | Size: 6.3 KiB |
BIN
src-tauri/icons/icon.icns
Normal file
BIN
src-tauri/icons/icon.ico
Normal file
|
After Width: | Height: | Size: 138 KiB |
BIN
src-tauri/icons/icon.png
Normal file
|
After Width: | Height: | Size: 423 KiB |
49
src-tauri/src/lib.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
//! Vehicle Generator, the desktop shell.
|
||||
//!
|
||||
//! The studio is the same web app that runs in a browser; this crate only gives it a window.
|
||||
//! The window is frameless (`decorations: false`) and the page draws its own title bar: the
|
||||
//! studio's menubar doubles as the drag region and carries the caption buttons
|
||||
//! (src/app/windowbar.ts). macOS keeps its native traffic lights over an overlay title bar.
|
||||
#[cfg(desktop)]
|
||||
mod window_mode;
|
||||
|
||||
#[cfg(desktop)]
|
||||
use tauri::Manager;
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
let builder = tauri::Builder::default();
|
||||
// First plugin: a second launch focuses the running studio instead of opening another.
|
||||
#[cfg(desktop)]
|
||||
let builder = builder.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
|
||||
if let Some(window) = app.get_webview_window(window_mode::MAIN) {
|
||||
let _ = window.unminimize();
|
||||
let _ = window.show();
|
||||
let _ = window.set_focus();
|
||||
}
|
||||
}));
|
||||
builder
|
||||
.invoke_handler(tauri::generate_handler![vehicle_generator_quit])
|
||||
.setup(|app| {
|
||||
if cfg!(debug_assertions) {
|
||||
app.handle().plugin(tauri_plugin_log::Builder::default().level(log::LevelFilter::Info).build())?;
|
||||
}
|
||||
// `main` is `"create": false` in the config so it is built in one place, sized to the
|
||||
// monitor it opens on.
|
||||
#[cfg(desktop)]
|
||||
window_mode::create_main(app.handle())?;
|
||||
#[cfg(mobile)]
|
||||
if let Some(config) = app.config().app.windows.first().cloned() {
|
||||
tauri::WebviewWindowBuilder::from_config(app.handle(), &config)?.build()?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running Vehicle Generator");
|
||||
}
|
||||
|
||||
/// Quits for real, from the page's File menu.
|
||||
#[tauri::command]
|
||||
fn vehicle_generator_quit(app: tauri::AppHandle) {
|
||||
app.exit(0);
|
||||
}
|
||||
6
src-tauri/src/main.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// Prevents an additional console window on Windows in release builds.
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
vehicle_generator_lib::run();
|
||||
}
|
||||
124
src-tauri/src/window_mode.rs
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
//! The main window: built hidden, sized to the monitor it opens on, then shown — so it never
|
||||
//! flashes at the config size first, and a monitor with different display scaling is not guessed
|
||||
//! at. A fixed 1440x900 is too big for a laptop and small on a wide monitor.
|
||||
use tauri::{AppHandle, Monitor, PhysicalPosition, PhysicalSize, Runtime, WebviewWindow, WebviewWindowBuilder};
|
||||
|
||||
pub const MAIN: &str = "main";
|
||||
|
||||
/// The share of the work area (the monitor minus the taskbar) the window takes.
|
||||
const SHARE: f64 = 0.8;
|
||||
/// The studio's shape, 16:10.
|
||||
const ASPECT: f64 = 1.6;
|
||||
/// The smallest the window opens at, in logical pixels, where the screen has room for it.
|
||||
const OPEN_MIN: (f64, f64) = (1024.0, 640.0);
|
||||
/// The smallest it can be resized to, and at most 90% of the work area.
|
||||
const RESIZE_MIN: (f64, f64) = (960.0, 620.0);
|
||||
|
||||
/// Where a monitor's usable area is, in physical pixels, and its display scaling.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct WorkArea { pub x: i32, pub y: i32, pub width: u32, pub height: u32, pub scale: f64 }
|
||||
|
||||
/// The window's opening size and position and its resize floor, all in physical pixels.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct WindowBounds { pub x: i32, pub y: i32, pub width: u32, pub height: u32, pub min_width: u32, pub min_height: u32 }
|
||||
|
||||
/// The largest 16:10 box within 80% of the work area, never smaller than 1024x640 logical pixels
|
||||
/// unless the work area itself is, never larger than it, centred. Worked in logical pixels so
|
||||
/// 125% and 150% display scaling give the same proportion of the screen as 100%.
|
||||
pub fn window_bounds(area: WorkArea) -> WindowBounds {
|
||||
let scale = if area.scale.is_finite() && area.scale > 0.0 { area.scale } else { 1.0 };
|
||||
let (available_w, available_h) = (area.width as f64 / scale, area.height as f64 / scale);
|
||||
let width = (available_w * SHARE).min(available_h * SHARE * ASPECT);
|
||||
let height = width / ASPECT;
|
||||
let width = width.max(OPEN_MIN.0).min(available_w);
|
||||
let height = height.max(OPEN_MIN.1).min(available_h);
|
||||
let physical = |logical: f64, limit: u32| ((logical * scale).round() as u32).min(limit);
|
||||
let (width_px, height_px) = (physical(width, area.width), physical(height, area.height));
|
||||
WindowBounds {
|
||||
x: area.x + ((area.width - width_px) / 2) as i32,
|
||||
y: area.y + ((area.height - height_px) / 2) as i32,
|
||||
width: width_px,
|
||||
height: height_px,
|
||||
min_width: physical(RESIZE_MIN.0.min(available_w * 0.9), width_px),
|
||||
min_height: physical(RESIZE_MIN.1.min(available_h * 0.9), height_px),
|
||||
}
|
||||
}
|
||||
|
||||
/// The monitor under the pointer (where the studio was just launched from), else the primary.
|
||||
fn launch_monitor<R: Runtime>(app: &AppHandle<R>) -> Option<Monitor> {
|
||||
let under_cursor = app.cursor_position().ok().and_then(|at| app.monitor_from_point(at.x, at.y).ok().flatten());
|
||||
under_cursor.or_else(|| app.primary_monitor().ok().flatten())
|
||||
}
|
||||
|
||||
pub fn create_main<R: Runtime>(app: &AppHandle<R>) -> tauri::Result<WebviewWindow<R>> {
|
||||
let config = app.config().app.windows.iter().find(|window| window.label == MAIN).cloned().ok_or(tauri::Error::WindowNotFound)?;
|
||||
let visible = config.visible;
|
||||
let window = WebviewWindowBuilder::from_config(app, &config)?
|
||||
.visible(false)
|
||||
// The studio's own background, painted before the page loads, instead of WebView2's white.
|
||||
.background_color(tauri::window::Color(12, 14, 17, 255))
|
||||
.build()?;
|
||||
// A monitor reporting no usable area (some remote sessions and VMs) keeps the config size.
|
||||
if let Some(monitor) = launch_monitor(app).filter(|m| m.work_area().size.width >= 2 && m.work_area().size.height >= 2) {
|
||||
let area = monitor.work_area();
|
||||
let bounds = window_bounds(WorkArea { x: area.position.x, y: area.position.y, width: area.size.width, height: area.size.height, scale: monitor.scale_factor() });
|
||||
// Onto the monitor first: Windows rescales a window that crosses to a monitor with other
|
||||
// display scaling, so the physical size is applied once it is there, then centred.
|
||||
let _ = window.set_position(PhysicalPosition::new(bounds.x, bounds.y));
|
||||
let _ = window.set_min_size(Some(PhysicalSize::new(bounds.min_width, bounds.min_height)));
|
||||
let _ = window.set_size(PhysicalSize::new(bounds.width, bounds.height));
|
||||
let _ = window.set_position(PhysicalPosition::new(bounds.x, bounds.y));
|
||||
}
|
||||
if visible {
|
||||
window.show()?;
|
||||
let _ = window.set_focus();
|
||||
}
|
||||
Ok(window)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn screen(width: u32, height: u32, taskbar: u32, scale: f64) -> WorkArea {
|
||||
WorkArea { x: 0, y: 0, width, height: height - taskbar, scale }
|
||||
}
|
||||
|
||||
fn inside(bounds: WindowBounds, area: WorkArea) {
|
||||
assert!(bounds.width <= area.width && bounds.height <= area.height, "{bounds:?} overflows {area:?}");
|
||||
assert!(bounds.x >= area.x && bounds.y >= area.y, "{bounds:?} starts outside {area:?}");
|
||||
assert!(bounds.min_width <= bounds.width && bounds.min_height <= bounds.height);
|
||||
let (left, right) = (bounds.x - area.x, area.x + area.width as i32 - (bounds.x + bounds.width as i32));
|
||||
let (top, bottom) = (bounds.y - area.y, area.y + area.height as i32 - (bounds.y + bounds.height as i32));
|
||||
assert!((left - right).abs() <= 1 && (top - bottom).abs() <= 1, "not centred: {bounds:?} in {area:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_common_screen_at_every_scaling_fits_and_is_centred() {
|
||||
for (width, height) in [(1280, 720), (1366, 768), (1920, 1080), (2560, 1440), (3440, 1440), (3840, 2160)] {
|
||||
for scale in [1.0, 1.25, 1.5, 2.0] {
|
||||
let area = screen(width, height, (48.0 * scale) as u32, scale);
|
||||
inside(window_bounds(area), area);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_the_same_share_of_the_screen_at_any_scaling() {
|
||||
let at_100 = window_bounds(screen(2560, 1440, 48, 1.0));
|
||||
let at_150 = window_bounds(screen(2560, 1440, 48, 1.5));
|
||||
assert_eq!((at_100.width, at_100.height), (at_150.width, at_150.height));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_ultrawide_is_limited_by_its_height() {
|
||||
let bounds = window_bounds(screen(3440, 1440, 48, 1.0));
|
||||
assert!((bounds.width as f64 / bounds.height as f64 - ASPECT).abs() < 0.01);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_monitor_left_of_the_primary_is_centred_on_itself() {
|
||||
let area = WorkArea { x: -1920, y: 120, width: 1920, height: 1040, scale: 1.0 };
|
||||
inside(window_bounds(area), area);
|
||||
}
|
||||
}
|
||||
60
src-tauri/tauri.conf.json
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
{
|
||||
"$schema": "https://schema.tauri.app/config/2",
|
||||
"productName": "Vehicle Generator",
|
||||
"mainBinaryName": "vehicle-generator",
|
||||
"version": "0.1.0",
|
||||
"identifier": "fyi.crt.vehiclegenerator",
|
||||
"build": {
|
||||
"frontendDist": "../dist",
|
||||
"devUrl": "http://localhost:5173",
|
||||
"beforeDevCommand": "bun run dev",
|
||||
"beforeBuildCommand": "bun run build"
|
||||
},
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"label": "main",
|
||||
"create": false,
|
||||
"title": "Vehicle Generator",
|
||||
"width": 1440,
|
||||
"height": 900,
|
||||
"minWidth": 960,
|
||||
"minHeight": 620,
|
||||
"resizable": true,
|
||||
"fullscreen": false,
|
||||
"decorations": false,
|
||||
"transparent": false,
|
||||
"visible": true
|
||||
}
|
||||
],
|
||||
"security": {
|
||||
"csp": {
|
||||
"default-src": "'self'",
|
||||
"script-src": "'self' 'wasm-unsafe-eval'",
|
||||
"style-src": "'self' 'unsafe-inline' https://fonts.googleapis.com",
|
||||
"font-src": "'self' data: https://fonts.gstatic.com",
|
||||
"img-src": "'self' data: blob:",
|
||||
"connect-src": "'self' ipc: http://ipc.localhost blob: data:",
|
||||
"worker-src": "'self' blob:",
|
||||
"frame-src": "'none'",
|
||||
"object-src": "'none'",
|
||||
"base-uri": "'none'"
|
||||
}
|
||||
}
|
||||
},
|
||||
"bundle": {
|
||||
"active": true,
|
||||
"targets": "all",
|
||||
"createUpdaterArtifacts": false,
|
||||
"category": "DeveloperTool",
|
||||
"shortDescription": "Procedural, game-ready vehicle generator",
|
||||
"copyright": "Copyright (c) 2026 CRTkafa. MIT License.",
|
||||
"icon": [
|
||||
"icons/32x32.png",
|
||||
"icons/128x128.png",
|
||||
"icons/128x128@2x.png",
|
||||
"icons/icon.icns",
|
||||
"icons/icon.ico"
|
||||
]
|
||||
}
|
||||
}
|
||||
5
src-tauri/tauri.linux.conf.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"bundle": {
|
||||
"targets": ["appimage", "deb", "rpm"]
|
||||
}
|
||||
}
|
||||
23
src-tauri/tauri.macos.conf.json
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"bundle": {
|
||||
"targets": ["dmg"]
|
||||
},
|
||||
"app": {
|
||||
"windows": [
|
||||
{
|
||||
"label": "main",
|
||||
"create": false,
|
||||
"title": "Vehicle Generator",
|
||||
"width": 1440,
|
||||
"height": 900,
|
||||
"minWidth": 960,
|
||||
"minHeight": 620,
|
||||
"resizable": true,
|
||||
"fullscreen": false,
|
||||
"decorations": true,
|
||||
"titleBarStyle": "Overlay",
|
||||
"hiddenTitle": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
14
src-tauri/tauri.windows.conf.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"bundle": {
|
||||
"targets": ["nsis"],
|
||||
"windows": {
|
||||
"webviewInstallMode": { "type": "downloadBootstrapper", "silent": true },
|
||||
"nsis": {
|
||||
"installMode": "currentUser",
|
||||
"displayLanguageSelector": false,
|
||||
"startMenuFolder": "vehicle-generator",
|
||||
"installerIcon": "icons/icon.ico"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||