# Modelling Kit

Build realistic objects in TypeScript with Blender-style operations (extrude, bevel, lathe, loft, sweep, subdivision, booleans, SDF blends), a procedural humanoid and a sedan, then hand them to the engine as glTF.

`@motion-sdk/scene/model` is a small modelling kit for agents and scripts. It runs in TypeScript, adds nothing to any engine bundle, and its output is a glTF (a `data:model/gltf-binary;base64,` URI) that [`model` geometry](/docs/features/models) already loads in the CLI and the authoring bundle. `@motion-sdk/scene/kits` builds on it with finished objects.

```ts
import { lathe, extrude, subdivide, box, modelMesh } from "@motion-sdk/scene/model";

const vase = lathe([[0, 0], [0.12, 0], [0.16, 0.1], [0.1, 0.3], [0.06, 0.4], [0.09, 0.45]], { segments: 48 });
nodes.vase = { mesh: modelMesh(vase, { material: "ceramic" }) };
```

## Operations

| Blender | Here |
| --- | --- |
| Extrude, bevel, inset | `extrude(contour, { depth, bevel, holes })`, `extrudeFaces`, `insetFaces`, `selectFaces` |
| Screw / lathe | `lathe(profile, { segments })` |
| Loft between curves | `loft(rings)` with `catmullRom`, `ellipse`, `superellipse`, `roundedRect` rings |
| Curve sweep | `sweep(profile, path)` with rotation-minimising frames |
| Subdivision surface | `subdivide(poly, levels)`: Catmull-Clark with edge creases (`crease`, `creaseHard`) |
| Boolean | `union`, `subtract`, `intersect` (BSP) |
| Metaballs / voxel remesh | `surfaceNets(sdf, ...)` over `sdSphere`, `sdCapsule`, `sdEllipsoid`, `sdBox` with `smin` blends, then `smooth` |
| Auto smooth | `toMesh(poly, { crease: 40 })`: shared normals below the crease angle, hard edges above it |
| Panels on a body | `Surface`, `patch`, `ribbon`: glass, trim and lamps laid along a lofted body's own surface |

A `Poly` has shared vertices and n-gon faces (`measure`, `isWatertight`, `weld`, `mirrorX`, `transform` and `deform` work on it); `toMesh` triangulates it (ear clipping, with holes) into a `Mesh` of typed arrays. `toGlb` writes the file (quantized by default: 16-bit positions, 8-bit normals, about half the bytes), `glbDataUri` wraps it, and `modelMesh` returns a scene mesh that uses it.

## Finished objects

- `sedan({ style: "sedan" | "wagon" })`: a body lofted through cross-sections with wheel arches, glass, window frames, panel gaps, sills, bumpers, lamps, grille, mirrors, plates and four wheels (lathe tyre, rim, spokes, brake disc). It faces -z and sits on y = 0.
- `humanoid({ sex, height, pose, outfit })`: a smooth skin mesh from blended signed-distance limbs, with separate hands, head, eyes, hair, clothes and shoes. `poses.standing`, `poses.seated`, `poses.smoking` and `poses.walking` place the joints with two-bone IK, or give your own `Pose`. It faces +z.

Both return `parts`: meshes with a material *role* (`paint`, `glass`, `skin`, `top`...). `partNodes(parts, { id, materials })` turns them into nodes under one group, `withUv(parts, roles)` gives chosen roles box UVs so a material `map` can detail them, and `partSplatMesh(parts, look)` turns them into a splat model (below).

## Surface detail

`detailTexture("weave" | "pores" | "flake" | "grain")` returns a small seamless PNG data URI of near-white detail to put in `textures` and map onto a material (`map: { texture, repeat }`): cloth weave on a dress, pores on skin, sparkle in car paint. The engine supports base-colour maps; normal and roughness maps are not implemented, so detail is in the colour.

## Importing glTF

`model` geometry reads the triangles of a `.glb` or `.gltf` (Blender's glTF export works: node transforms and skins apply) but not its materials. `readGltf(bytes)` reads them in TypeScript: PBR factors, emissive, clearcoat and base-colour images become scene `materials` and `textures`, and `gltfNodes(import, { id })` makes one mesh node per glTF mesh, shaded with them.

```ts
const imp = readGltf(new Uint8Array(readFileSync("chair.glb")), { src: "chair.glb" });
scene.materials = { ...scene.materials, ...imp.materials };
scene.textures = { ...scene.textures, ...imp.textures };
nodes = { ...nodes, ...gltfNodes(imp, { id: "chair", parent: { transform: { position: [1, 0, 0] } } }) };
```

## Splats

[Splat](/docs/features/splats) clouds sample meshes too: `splats.meshes` takes a glTF `src` and a colour per part, spreads splats over its triangles at the cloud's `spacing`, and bakes the cloud's `light` into them (shadows come from the cloud's SDF shapes). `partSplatMesh` builds the entry from kit parts.

## The rain street

`examples/ts/rain-street.ts` builds the woman on the bench, the parked sedan and the passing wagon with the kits; `rain-street-splats.ts` samples the woman and the sedan into the splat street.
