Seeds and fields
A Voronoi pattern is decided by its seeds: where they are, how far apart, and whether that spacing changes across the part. Any list of points will do, and every function in bitbybit.occt.patterns.voronoi takes the seeds as a plain list, so they can come from anywhere: a grid you computed, the vertices of another shape, points read from a file. Most of the time, though, they come from bitbybit.occt.patterns.voronoi.seeds2d, which places them in a planar face, or bitbybit.occt.patterns.voronoi.seeds3d, which places them in a solid. Both are drawn as points when you draw what they return.
The same seed number always gives the same seeds, so a design stays put from one run to the next; change the number for another draw of the same kind.
Three ways to place seeds, and relaxation
method chooses how the seeds are placed:
randomplacescountseeds uniformly at random over the face or the solid. Random seeds clump in places and leave gaps in others, so their cells range from slivers to large ones.gridplaces one seed on each point of a square gridspacingapart, centred on the face or solid, that falls inside it, and moves each at random by up tojittertimes the spacing. A jitter of 0 gives square cells; a little jitter gives cells that are almost square, in rows.poissonplaces seeds as close as they may come without any two being nearer thanmaxSpacing: Poisson-disk sampling. The seeds are irregular but even, with no clumps and no gaps, which is the look of most of the patterns nature makes. With affectors, below, the spacing changes across the part.
relax then evens any of them out by rounds of Lloyd relaxation: each round moves every seed to the centroid of its own cell, so crowded seeds spread and lonely ones move toward the middle of their space. A few rounds take the clumps out of random seeds; many rounds, up to the 100 allowed, push any seeds toward cells of one size. In a face with curved or concave edges, a cell's centroid is that of its part inside the face, and a seed whose centroid would fall outside the face keeps its place. A solid that is not convex is relaxed against its box, so seeds near a concave stretch of its boundary move less than they would in the open.


- Rete
- Blockly
- TypeScript
const { voronoi } = bitbybit.occt.patterns;
const { voronoiSeedMethodEnum, voronoiCells2dOutputEnum } = Bit.Inputs.OCCT;
type Point = Bit.Inputs.Base.Point3;
const square = (center: Point) => bitbybit.occt.shapes.face.createRectangleFace({ width: 50, length: 50, center, direction: [0, 1, 0] });
const randomSquare = await square([-28, 0, 28]);
const gridSquare = await square([28, 0, 28]);
const poissonSquare = await square([-28, 0, -28]);
const relaxedSquare = await square([28, 0, -28]);
const random = await voronoi.seeds2d({ face: randomSquare, method: voronoiSeedMethodEnum.random, count: 40, seed: 1 });
const grid = await voronoi.seeds2d({ face: gridSquare, method: voronoiSeedMethodEnum.grid, spacing: 8, jitter: 0.35, seed: 1 });
const poisson = await voronoi.seeds2d({ face: poissonSquare, method: voronoiSeedMethodEnum.poisson, maxSpacing: 8, seed: 1 });
const relaxed = await voronoi.seeds2d({ face: relaxedSquare, method: voronoiSeedMethodEnum.random, count: 40, relax: 12, seed: 1 });
const pairs: [Bit.Inputs.OCCT.TopoDSFacePointer, Point[]][] = [[randomSquare, random], [gridSquare, grid], [poissonSquare, poisson], [relaxedSquare, relaxed]];
for (const [face, seeds] of pairs) {
await bitbybit.draw.drawAnyAsync({ entity: await voronoi.cells2d({ face, seeds, output: voronoiCells2dOutputEnum.edges }) });
}
for (const [, seeds] of pairs) {
await bitbybit.draw.drawAnyAsync({ entity: seeds });
}
bitbybit.babylon.scene.adjustActiveArcRotateCamera({ position: [30, 130, -95], lookAt: [0, 0, 0] });
Top left are forty random seeds, with the slivers and the crowding that come with them. Top right is the jittered grid, still in its rows. Bottom left are Poisson seeds kept 8 apart. Bottom right are the same forty random seeds as top left, after twelve rounds of relaxation: evened out almost as far as the Poisson seeds, but with exactly forty cells.
Affectors
An affector is a shape whose nearness grades a pattern. bitbybit.occt.patterns.voronoi.affector makes one from any shape: points, given as vertices or a compound of them; curves, as edges or wires; surfaces, as faces or shells; and solids. Its influence is strength (1 unless set) at the shape itself and falls to 0 at the distance radius, the way falloff says:
| Falloff | How the influence falls from the shape to radius |
|---|---|
linear | evenly, the default |
smooth | gently at both ends, steeper in the middle, so the change has no visible edge |
inverse | steeply near the shape, then slowly |
exponential | quickly, then slowly, with a long tail |
Poisson seeds take affectors directly: give seeds2d or seeds3d a list of affectors and set both spacings. Where the affectors' influence is 0, the seeds are maxSpacing apart; where it is 1, minSpacing; between, in proportion. So small cells gather near the affectors and large ones fill the rest. When several affectors are given, combine says how their influences add up at a point:
max, the default, takes the strongest, so each affector draws its own small cells and the strongest wins where they overlap;mintakes the weakest, so cells are small only where every affector reaches;sumadds them, up to 1, so overlapping influences reinforce each other;meanaverages them, counting an affector out of reach as 0.
The sampler reads the affectors' field through a grid of fieldResolution points along the longest side of the face or solid (32 unless set). That is much faster than measuring the exact distance at every candidate seed, and fine enough for spacing; 0 measures it exactly.


- Rete
- Blockly
- TypeScript
const { voronoi } = bitbybit.occt.patterns;
const { voronoiSeedMethodEnum, voronoiCells2dOutputEnum, voronoiFalloffEnum } = Bit.Inputs.OCCT;
const field = await bitbybit.occt.shapes.face.createRectangleFace({ width: 140, length: 80, center: [0, 0, 0], direction: [0, 1, 0] });
const river = await bitbybit.occt.shapes.wire.interpolatePoints({ points: [[-70, 0, -10], [-35, 0, 22], [0, 0, 0], [35, 0, -24], [70, 0, 8]] });
const spring = await bitbybit.occt.shapes.vertex.vertexFromXYZ({ x: 42, y: 0, z: 24 });
const nearRiver = await voronoi.affector({ shape: river, radius: 20, falloff: voronoiFalloffEnum.smooth });
const nearSpring = await voronoi.affector({ shape: spring, radius: 26, falloff: voronoiFalloffEnum.linear });
const seeds = await voronoi.seeds2d({
face: field,
method: voronoiSeedMethodEnum.poisson,
maxSpacing: 11,
minSpacing: 2.6,
relax: 1,
seed: 2,
affectors: [nearRiver, nearSpring],
});
console.log(`${seeds.length} seeds`);
const cells = await voronoi.cells2d({ face: field, seeds, output: voronoiCells2dOutputEnum.edges });
await bitbybit.draw.drawAnyAsync({ entity: cells });
const tube = await bitbybit.occt.operations.pipeWireCylindrical({ shape: river, radius: 0.6 });
await bitbybit.draw.drawAnyAsync({ entity: tube, options: bitbybit.draw.optionsOcctShapeSimple({ faceColour: "#ff4400", drawEdges: false, drawTwoSided: false }) });
bitbybit.babylon.scene.adjustActiveArcRotateCamera({ position: [45, 175, -125], lookAt: [0, 0, 0] });
The seeds are 11 apart in the open and close to 2.6 apart along the winding curve, drawn as an orange tube, and around the point above it to the right, so the cells shrink there. The curve's falloff is smooth, so the band of small cells fades out softly; the point's is linear, so its cluster has a clearer edge.
Regions and surfaces
A point or a curve can only be near or far. A solid has an inside, and mode says what that inside means:
regiongives full influence everywhere inside the solid, whatever the depth, and the falloff outside it, by the distance to its boundary. Every cell inside is graded the same.surfaceignores inside and outside and measures the distance to the boundary on both sides, so the influence peaks at the solid's skin and fades into it as well as away from it. This is how a part gets fine cells under its skin and coarse ones in its core.auto, the default, takes a solid or a closed shell as a region and measures anything else by distance.
A closed shell counts as a solid here, whichever way its faces point. Asking for a region of a shape that has no inside is refused: "patterns.voronoi.field: affector 0 is not a solid or a closed shell, so it cannot be a region".


- Rete
- Blockly
- TypeScript
const { voronoi } = bitbybit.occt.patterns;
const { voronoiSeedMethodEnum, voronoiCells2dOutputEnum, voronoiFalloffEnum, voronoiAffectorModeEnum } = Bit.Inputs.OCCT;
const { face, solid, wire } = bitbybit.occt.shapes;
const left = await face.createRectangleFace({ width: 70, length: 70, center: [-38, 0, 0], direction: [0, 1, 0] });
const right = await face.createRectangleFace({ width: 70, length: 70, center: [38, 0, 0], direction: [0, 1, 0] });
const leftDisc = await solid.createCylinder({ radius: 22, height: 20, center: [-38, -10, 0], direction: [0, 1, 0] });
const rightDisc = await solid.createCylinder({ radius: 22, height: 20, center: [38, -10, 0], direction: [0, 1, 0] });
const region = await voronoi.affector({ shape: leftDisc, radius: 7, falloff: voronoiFalloffEnum.smooth, mode: voronoiAffectorModeEnum.region });
const surface = await voronoi.affector({ shape: rightDisc, radius: 7, falloff: voronoiFalloffEnum.smooth, mode: voronoiAffectorModeEnum.surface });
const leftSeeds = await voronoi.seeds2d({ face: left, method: voronoiSeedMethodEnum.poisson, maxSpacing: 9, minSpacing: 2.4, relax: 1, seed: 6, affectors: [region] });
const rightSeeds = await voronoi.seeds2d({ face: right, method: voronoiSeedMethodEnum.poisson, maxSpacing: 9, minSpacing: 2.4, relax: 1, seed: 6, affectors: [surface] });
await bitbybit.draw.drawAnyAsync({ entity: await voronoi.cells2d({ face: left, seeds: leftSeeds, output: voronoiCells2dOutputEnum.edges }) });
await bitbybit.draw.drawAnyAsync({ entity: await voronoi.cells2d({ face: right, seeds: rightSeeds, output: voronoiCells2dOutputEnum.edges }) });
const rims = [
await wire.createCircleWire({ radius: 22, center: [-38, 0, 0], direction: [0, 1, 0] }),
await wire.createCircleWire({ radius: 22, center: [38, 0, 0], direction: [0, 1, 0] }),
];
const tubes = await bitbybit.occt.operations.pipeWiresCylindrical({ shapes: rims, radius: 0.5 });
await bitbybit.draw.drawAnyAsync({ entity: tubes, options: bitbybit.draw.optionsOcctShapeSimple({ faceColour: "#ff4400", drawEdges: false, drawTwoSided: false }) });
bitbybit.babylon.scene.adjustActiveArcRotateCamera({ position: [40, 150, -105], lookAt: [0, 0, 0] });
Both squares are crossed by a cylinder of radius 22, its outline drawn as an orange ring, with the same radius of influence, 7, and the same falloff. On the left, as a region, the cells are small all through the disc and grow within 7 outside it. On the right, as a surface, they are small in a band along the cylinder's wall, 7 deep on either side of it, and the middle of the disc is as coarse as the open square.
Grading anything with a field
Seeds are only one thing an affector can grade. bitbybit.occt.patterns.voronoi.field gives the affectors' combined influence at any list of points, mapped from the range 0 to 1 onto from and to: a point out of every affector's reach gets from, a point at full influence gets to, and the values between follow in a straight line. Read the field at the seeds and you have one number a seed, which every structure on these pages takes in place of a single setting:
weights, in every function that builds cells, for weighted cells;factors, in perforated faces, each hole's own scale or inset;sizes, in frames and foam, each window's or void's own scale or inset, and in beams, each cell's beam radius.
For openings there is one convention to remember: with shrink set to scale, 0 means solid and 1 means most open. A value of 0.001 or less keeps a cell closed, 0.999 or more opens it as far as allowed, and anything between scales it. So from: 0, to: 0.85 opens the holes near an affector and closes them away from it, and from: 0.75, to: 0 does the opposite.
The outputs never take the affectors themselves, only the numbers, so one field can grade seeds, weights and openings alike, and numbers from anywhere else, such as a simulation or a spreadsheet, work the same way.
Weighted cells
Weights work the other way round from openings: the heavier a seed, the larger its cell grows at its neighbours' expense. Read the field at evenly spaced seeds and pass the values as weights:


- Rete
- Blockly
- TypeScript
const { voronoi } = bitbybit.occt.patterns;
const { voronoiSeedMethodEnum, voronoiCells2dOutputEnum, voronoiFalloffEnum } = Bit.Inputs.OCCT;
const field = await bitbybit.occt.shapes.face.createRectangleFace({ width: 120, length: 70, center: [0, 0, 0], direction: [0, 1, 0] });
const seeds = await voronoi.seeds2d({ face: field, method: voronoiSeedMethodEnum.poisson, maxSpacing: 8, relax: 3, seed: 8 });
const sun = await bitbybit.occt.shapes.vertex.vertexFromXYZ({ x: -20, y: 0, z: 5 });
const nearSun = await voronoi.affector({ shape: sun, radius: 14, falloff: voronoiFalloffEnum.smooth });
const weights = await voronoi.field({ points: seeds, affectors: [nearSun], from: 0, to: 400 });
const { shape: cells, report } = await voronoi.cells2dWithReport({ face: field, seeds, weights, output: voronoiCells2dOutputEnum.edges });
const empty = report.cells.filter((cell) => cell.state === "empty").length;
console.log(`${seeds.length} seeds, ${empty} of them left with no cell`);
await bitbybit.draw.drawAnyAsync({ entity: cells });
await bitbybit.draw.drawAnyAsync({ entity: seeds });
bitbybit.babylon.scene.adjustActiveArcRotateCamera({ position: [40, 150, -100], lookAt: [0, 0, 0] });
The point affector sits left of the middle. The seeds there are no closer together than anywhere else; their weights rise to 400 at the point and fall smoothly to 0 fourteen away, so the cell at the point swells over its neighbours and the lighter cells around it are squeezed into slivers. The TypeScript tab prints how many seeds were left with no cell at all, empty in the report, outweighed so far that their whole cell went to their neighbours.
