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:
- the outline: you draw the character's left, on your right, and the other side is its mirror. Click out points, click the first to close a shape, drag a point to move it, press an edge to add one;
- cloth mesh: the cloth is cut from an even surface laid over the body (remesh), coarse, medium (the default) or fine (edges about 3, 2 or 1.2 cm), whatever the body's own triangles are; as the body cuts the body's triangles themselves;
- thickness (thicker cloth bridges more of the chest, where the body says where its nipples are);
- made by: cutting the skin (the cloth follows the body), draping cloth (a front and a back piece laid over the body, sewn where the outline runs up and down past its edge and settled under gravity, so it bridges hollows and hangs: dresses, tunics, robes; see cloth drape), or rings (round the outline at each height: skirts, kilts);
- material, name and slot.
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.