---
name: chop-shop
license: MIT
description: Cut a single-mesh 3D model (a robot, vehicle, turret, machine or piece of furniture from an AI generator or any file Blender imports) into named parts with pivots, give the parts moving clips without a skeleton, and export GLB, optional FBX for Unreal or Unity, and optional STL per part for 3D printing. Use when a 3D model that is one solid piece should get wheels, arms, doors, drawers, antennas or hanging lamps that move on their own, when you need an exploded view of a machine, or when you want a quick motion test of a model. Soft parts such as rope, sack, canopy, hose or sling are cut and marked with a soft role, and a small bundled runtime simulates them in your game or viewer instead of a clip. Not for soft skinned characters that bend at the joints (use an auto-rigger), not for textures or modelling from scratch.
compatibility: Needs Blender 4.2 or newer (free) and Python 3; the soft-part runtime needs a current Node.js, or a browser. Pillow is needed only for the parts sheet. Set CHOP_BLENDER to the Blender executable if it is not on the PATH.
metadata:
  author: "Jakob Christensen"
  source: "https://jakobchristensen.com"
---

# chop-shop

Turn one connected mesh into a machine with rigid moving parts. The result is a glTF node tree (every part is a node with its own pivot), plus clips that rotate, slide or swing those nodes. No skeleton is involved, so the file loads in Unreal, Unity, three.js and any glTF viewer.

Everything runs through one launcher: `python -I scripts/chop.py <command> ...` (paths here are relative to this skill's folder). It finds Blender on its own (`CHOP_BLENDER`, then `blender` on the PATH, then the usual install folders) and always starts Blender with `-b --factory-startup`. Run `python -I scripts/chop.py where` first: it prints the Blender it will use, or says there is none.

Every output gets a new file name. The scripts refuse to overwrite an existing file, so the raw model and every earlier cut stay as they are.

Axes after the cut: +X front, +Y up, +Z right.

## What it is good for

- Vehicles, mechs, turrets and robots from an AI generator, so wheels turn and arms swing.
- Furniture and props with doors, drawers and lids.
- An exploded view that explains how a machine is put together.
- A moving GLB for a three.js page or a game engine.
- 3D printing a model in parts, with closed cut faces.
- A quick motion test before a model goes into a real rigging pipeline.

Poor fit: a soft skinned figure (a person, an animal that bends). Rigid parts cannot bend. Use an auto-rigger for those.

## Steps

1. **Keep the raw file.** Copy the source into its own folder and never touch it again.
2. **Look.** `python -I scripts/chop.py probe <source>` prints triangles, bounding box, the biggest loose islands and a histogram per axis. A gap in a histogram is a cheap cut. A big island is a part that needs no cut. Then render the views of the raw file with `python -I scripts/chop.py preview <source> <new-folder>` and name what you see: what is the body, what hangs, what turns, what slides.
3. **Write the parts file.** Copy `examples/mule.parts.json` and change it with the numbers from step 2.
   - `name`, `triangles` (target, or `null`), `rotate_z_deg` (turn the model so +X is the front), `consts` (named numbers for the rules).
   - `mode`: `loose` when the model is made of thousands of separate islands, so each island goes to one part. `faces` when it is one connected piece, so you also give `cuts` (planes) and every triangle goes to the first rule that matches.
   - `rules`: a list of `{part, when}`. `when` is a Python expression over `x, y, z` (centre of the face or island), `wx, wy, wz` (its size), `lo, hi` (its bounding box) and `polys`. The first rule that matches wins. `default` takes the rest.
   - `parts`: `name`, `parent`, `pivot` (three numbers, or `center` or `top`), `role` and `empty: true` for a node without mesh.
   - Roles: `root`, `body`, `arm`, `antenna`, `hang`, `flame`, `wheel`, `door`, `turret`, and the soft roles `rope`, `sack`, `canopy`, `hose`, `sling` (see Soft parts below). The role decides which clip channels a part gets, so give every part one; a soft role gets none.
4. **Cut.** `python -I scripts/chop.py cut <parts.json> <source> <cut.glb>`. Read the `OBJ` lines and `TOTAL`. A part with 0 triangles or one part holding almost everything means a rule is wrong. Fix the rule and cut again under a new name.
5. **Parts sheet.** `python -I scripts/chop.py preview <cut.glb> <folder>` renders the colour views and the exploded views, then `python -I scripts/chop.py sheet <folder> <sheet-folder> "<title>"` builds the sheets with a legend (needs Pillow).

## Stop after step 5

Show the parts sheet to the user and ask whether the cuts are right, with one option "cuts are right, build the clips" and one "change these parts". Go on only after a yes. A bad cut costs a whole clip run, a question costs one answer.

6. **Clips.** `python -I scripts/chop.py clips <parts.json> <cut.glb> <clips.glb>`. It writes `<name>_<mood>` for idle, startup, hit, defect, victory, alert, gust, attack, spin and open, plus `<name>_show`: the moods in a row with 0.2 s blends. A mood whose role is missing is skipped and printed (a model without a door gets no `open`). Loops use whole hertz only, so they close without a jump. For other moods or other numbers, copy `scripts/moods.json`, edit the channels (role, path rot/pos/scale, axis, curves sin/kick/keys) and pass it as the last argument. The script itself stays untouched.
7. **Test animation.** `python -I scripts/chop.py preview <clips.glb> <folder> <spread> <clip> <frames>` renders a fixed crop, then `sheet` makes the frame strip and a WebP. Look at the frames: no part leaves its parent and no gap opens at a joint.
8. **Export.**
   - GLB is the result of step 6. It is the file to keep.
   - FBX for Unreal or Unity: `python -I scripts/chop.py export <clips.glb> --fbx <out.fbx>`. Animations are included.
   - STL per part for 3D printing: `python -I scripts/chop.py export <clips.glb> --stl <new-folder> --height-mm 120`. One file per part, scaled so the model is that tall.
9. **Verify.** Open the GLB in a viewer and check that the node tree and the clips are there. Use the viewer page of this skill: serve the folder (`python -m http.server`) and open `viewer/index.html?src=<file>.glb`, or drop the file on the page. It lists the clips and the nodes and plays each clip. Other glTF viewers work too, as long as they show nodes and animations. `python -I scripts/chop.py tree <a.glb> [<b.glb>]` prints the node tree or compares two files (`TREES EQUAL`).

## Engines

Unreal first: import the FBX (animations included) or the GLB through the glTF importer plugin. Then Unity and Godot, which read the GLB. A claim that the file works in a given engine counts only after it was opened there. If the engine is not installed, say "not checked in Unreal" in the report instead of guessing.

## 3D printing honesty

The cut caps close the faces where the model was cut. Holes that were already in the source mesh stay open. The export prints `OPEN <part> <count>` for every part with open edges, after merging vertices. Tell the user these numbers. A part with `OPEN` above 0 needs a repair in the slicer or in Blender before it prints well.

## Optional hint for AI generator models

When the model comes from Tripo, its part-segmentation tool can give a first guess for where the parts are. Treat it only as a hint, check it against the probe numbers and render the sheet to see it. The rules in the parts file decide the cut.

## Soft parts

A rope, a sack, a canopy, a hose or a sling cannot be animated with a fixed clip, because how it moves depends on what happens to it. chop-shop therefore cuts such a part like any other (mesh and pivot) and marks it with a soft role. The movement comes from a small simulation in `runtime/`, which runs in your game or viewer.

- **The roles.** `rope` (a hanging cord), `sack` (a bag with contents), `canopy` (a sheet of cloth such as an umbrella shade), `hose` (a tube held at both ends), `sling` (a leather band with a pouch). Put the pivot where the part is held, for example `"pivot": "top"` for something that hangs.
- **What the scripts do.** `cut` writes the role of every part into its node as glTF extras (`extras.role`), so the runtime finds the soft parts without a name list. `clips` gives these parts no clip channel and prints one line per soft role, so a skipped part is never a silent surprise.
- **The runtime.** `runtime/softrig.js` is plain ES modules with pure maths: no three.js, no DOM, no dependencies. It reads the nodes with a soft role, takes the pivot as the anchor and the parent node as the thing that carries the part, and simulates the part live. Each part is scaled to its cut mesh, so everything you read is in model units.
  - `readSoftSpecs(gltfJson, { roles? })` finds the soft parts (`glbJson(bytes)` gives the JSON of a .glb; with three.js use `gltf.parser.json`). `roles` maps node names to roles for a model cut before the roles existed, for example `{ schlauch: 'hose' }`.
  - `new SoftRig(specs, { ground, rocks, wind, durability })`, then every frame `rig.step(dt)` and `rig.positions(name)`: the particle positions of the part, three numbers each, from the anchor to the free end. Draw them as a line, a ribbon or skin your mesh onto them; the runtime does not draw.
  - `rig.follow(parentName, [dx, dy, dz])` tells the runtime that the host moved, so the parts get dragged along.
  - Optional wear: `rig.hit(name, point, 'enemy' | 'terrain' | 'fire')` frays a rope until it tears, empties a sack, grows a hole in a canopy, makes a hose leak. `rig.status()`, `rig.traces` and `rig.onTrace` report the result, `rig.repair()` resets it. A game that wants no damage never calls `hit`.
  - `node examples/soft-demo.mjs [model.glb]` runs it in Node and prints the free ends, as a quick check.
- **What the skill does not do.** It does not skin your mesh onto the simulated points and ignores rotation and scale on nodes, because cuts carry translations only. The sling's pouch does not lose its load per hit.

## Limits

Hard-surface things plus the five soft roles above, which the runtime simulates. Parts move as rigid pieces unless they carry a soft role. Open source meshes make open STL parts. The default clip moods are a starting point and every number lives in the moods file.
