tailor tool

Cut a garment out of a body, and hand it back. Draw an outline over the body's front view and the skin inside it, front and back, becomes cloth: a rectangle from the waist to the ankles is a pair of trousers. The tool works on any rigged body (MakeHuman's, or a mesh the rig tool bound), previews the cut on the body as it moves, and on done hands your callback the garment. The character builder's tailor… opens it.

import { mountTailorTool } from 'tosijs-3d'

const tailor = mountTailorTool(scene, {
  body, // a RiggedBody: what it cuts from
  built, // the body on screen (buildBody): what the cut is shown on
  slots: ['top', 'bottom', 'outfit'],
  handleDone: ({ garment, name, slot, look, cut }) => wardrobe.add(garment, { name, slot, look, cut }),
  handleCancel: () => {},
})

Its panel is a system panel (scissors, on the bar). A bar pinned to its top carries undo, redo, cancel and done; below it:

Undo and redo (and ⌘Z / ⇧⌘Z through undo() / redo(), which a host's keys call while the tool is open): each settled edit, a point dropped or a slider let go, is a step.

WHAT DONE HANDS BACK is the garment as a mesh at rest, on the body it was cut from (garment: positions, triangles, UVs unwrapped like a sewing pattern), with what it was cut from (cut: the outlines, thickness, how it was made) so it can be opened again, and the name, slot and material recipe. Binding it to a body to wear (bindGarment) is the host's: a garment file carries the same mesh.

A host that keeps the garment itself passes persistent (no cancel or done), its own system panel as panel, and rows of its own above and below (rows: { top, bottom }); the character builder does, so its tailor is always on the bar.

handleChange hears every edit (a work in progress to keep); setBody moves the cut onto a body reshaped while the tool is open; unmount (or done, or cancel) removes everything it added.