Log inGet started
World

Torque Valley: Driving, Drift and Crash Sandbox

README.md

bodies

The look of every torqueCars car: hands out the generated body mesh for each car kind in each look (lowpoly, toy, real), the tyre-and-rim mesh for each rim style, the paint material for each look and paint, and the wheel material per look. The Car component and any display scene call it.

  • Bodies.body(kind, look) -> { mesh, center: vector, size: vector, tris, head: {vector}, tail: {vector} }: put the body entity at localPosition = center, localScale = size (the mesh is stored in the unit box), in the chassis frame: metres, x right, y up with y = 0 the ground at rest, z = 0 mid-wheelbase, front at -Z. head / tail are lamp centres in the same frame.
  • Bodies.wheel(rim, look) -> { mesh, tris, scale(radius, width) -> vector }: the mesh is radius 1, width 1, axle along X, rim face on +X. Use localScale = scale(wheelRadius, wheelWidth * tyre.widthScale), which is (width, radius, radius), and yaw left-side (-X) wheels 180 degrees.
  • Bodies.wheelScale(radius, width): the same scale function.
  • Bodies.paint(look, paintName) -> material: catalog paintOrder names.
  • Bodies.wheelMaterial(look) -> material.
  • Bodies.rimFor(kind, tyres?) -> rim: the rim style a tyre set (or the kind's default) uses.
  • Bodies.spawnStatic(name, kind, { parent, position, yaw, look, paint, tyres }) -> entity: a static display car (body and four wheels, no physics).

Every body, wheel and paint draws with the carBody shader. Vertex colour rgb is each part's colour, and vertex colour alpha is a part code, so only the painted panels take the paint. Lamps glow: bind or set the named values car.headlights and car.brake (0..1) on the car (or any ancestor of the body entity) to light the headlamps and brake lamps. The assets are generated by torqueCars.bodybake (Bake.all()) from torqueCars.bodygen and torqueCars.wheelgen; the numbers live in the generated torqueCars.bodyData.