erase deletes vertices, edges and faces of a mesh by id, as one undo
step. It is a modeler's Delete, with the ids as operands:
the two run the same code, and erase the same ids to the same result.
import { erase, meshVerbContext } from '@commonplace-technologies/kernel';
const ctx = meshVerbContext(mesh);
const done = await erase(ctx, { ids: [faceId, edgeId, cornerId] });
done.ok; // true
done.value; // { edgesErased, verticesErased, verticesHealed, facesMerged, facesDeleted }
done.removed; // the ids the step removed: drop them from the selection
ctx.commandManager.undo(); // puts every one back, ids included
| Id | What happens |
|---|---|
| A face | The face goes. Its edges and corners stay: on a closed solid, the solid opens. |
| An edge between two flat faces in one plane | The two faces become one (the inverse of drawing the line that split them). A corner left as a straight pass-through heals, so a split then an erase gives the face back. |
| Any other edge of a face's boundary | The faces it bounds go with it; their other edges stay as lines. |
| A line with no face on either side | The line goes; a corner left with no edge goes too. A face the line was drawn into is unchanged. |
| A corner where two straight edges meet in line | It heals: the two edges become one, and the faces stay. |
| Any other corner | Its edges go, as above, and so does the corner. |
An edge id is either half of the edge. Edges are erased first, then corners, then faces, so a face an erased edge already took, or an id named twice, is skipped.
Every id the step does not list in removed survives. An erase makes no
new vertices or faces, but where faces merge, or a face is re-derived
from the lines drawn in it, the kept face's boundary can be rebuilt with
new half-edge ids: those are in created.halfEdges. A host that holds
edge ids reads both lists.
Besides the general codes, erase
refuses with one of its own:
| Code | Meaning |
|---|---|
unknown-entity |
An id names no vertex, edge or face of the mesh. The message names the first. |
ids: [] is invalid-operands. A result the validator would reject is
postcondition-refused, the mesh as it was. canRun(ctx, 'erase', { ids })
answers the same checks without erasing anything, and
erase(ctx, { ids }, { dryRun: true }) reports what the step would remove.