| title | cut | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| description | Subtract one or more solid tools from a stock model. | ||||||||||||||||||||||||||||
| sourceReview |
|
||||||||||||||||||||||||||||
| sidebar |
|
||||||||||||||||||||||||||||
| head |
|
Subtract one or more solid tools from a stock model.
import {box, cylinder, cut} from '@code3d/core';
const blank = box(30, 8, 20);
const drill = cylinder(4, 12);
export const drilled = cut(blank, [drill]);Complete example: solid operations.
function cut(
stock: SolidModel<{}>,
tools: readonly SolidModel<{}>[],
): SolidModel;
// SolidModel method:
stock.cut(tools: SolidModel<{}> | readonly SolidModel<{}>[]): SolidModel;Import the functions and named types from @code3d/core.
| Parameter | Meaning |
|---|---|
stock |
Solid model whose volume is retained outside the tools |
tools |
Nonempty readonly array of solid models; the method also accepts a single solid |
All tools must be solids. Empty tool arrays throw. Tools may extend outside the
stock; only their overlap removes material. A tool that does not overlap removes
nothing. The example drills through the full height and leaves volume
4800 - 128 * Math.PI.
The inputs are immutable. Relations between operands are solved together before
geometry is combined. The result retains the first input's local frame,
placement, material and origin; for cut, that input is the stock. The result
is a new SolidModel with canonical references, not a group with named members.
Use group to retain separate parts.
Input arrays describe one operation. They do not apply the operation independently
to each element. Topology inherited one-to-one from an input is prefixed by its
one-based operand position, for example [1, 4]; split, merged and newly generated
topology receives new IDs. Inspect the result before using its edge or surface IDs
in a later operation. See topology IDs.
blank.cut(drill) and blank.cut([drill]) have the same modeling behavior as
cut(blank, [drill]). The free function always takes an array of tools.
None of these forms changes the blank or drill. Keep tool definitions available if you need to
change the cut later; they are not exposed as named members on the result.
Selecting a tool or the tools array previews the consumed tools and their cut volume with
the stock in the background. In blank.cut([box(...).relate(...)]), selecting
box previews that constructor's result; it does not use the later related
tool's placement. Selecting the box dimensions still shows their measurements.
Similarly, selecting tool in blank.cut([tool.relate(...)]) previews the
original tool in its local coordinates.
See custom inspectors for inspection scope and fallback rules.
Boolean construction can fail on coincident or degenerate geometry. Avoid removing the entire stock when subsequent operations require a nonempty solid. Do not assume the output remains connected: a tool can split the stock into parts. For adding volume see union; for keeping shared volume see intersect.
