Face Hexagons Grid
Learn how to create hexagonal face patterns that respond to a control point. Hexagons closer to the control point become larger, while distant ones become smaller, creating organic wave-like effects.
Key Concepts
- Control Point: A point that influences the hexagon sizes based on distance
- Distance Scaling: Hexagons scale up/down based on how far they are from the control point
- UV Coordinates: Position the control point using 0-1 values instead of exact coordinates
- Pattern Filtering: Selectively remove some hexagons to create openings

- Rete
- Blockly
- TypeScript
Script Source (typescript)
// Import required DTOs and types for face hexagon grid creation
const { HexagonsInGridDto, RectangleDto, DataOnUVDto, PinWithLabelDto } = Bit.Inputs.OCCT;
const { HexGridScaledToFitDto } = Bit.Inputs.Point;
const { RemapNumberDto } = Bit.Inputs.Math;
const { HexGridData } = Bit.Models.Point;
type Point3 = Bit.Inputs.Base.Point3;
type Vector3 = Bit.Inputs.Base.Vector3;
type TopoDSFacePointer = Bit.Inputs.OCCT.TopoDSFacePointer;
// Get access to OCCT face, point, and utility functions
const { face } = bitbybit.occt.shapes;
const { point } = bitbybit;
const { math, vector, json, lists } = bitbybit;
const { dimensions } = bitbybit.occt;
// Create advanced hexagon face pattern
// Define grid parameters
const gridWidth = 16.5;
const gridHeight = 9;
const hexagonsInWidth = 29;
const hexagonsInHeight = 29;
const controlPointU = 0; // UV parameter for control point position
const controlPointV = 0.49; // UV parameter for control point position
// Create a reference rectangle face to define the control point
const rectangleOptions = new RectangleDto();
rectangleOptions.width = gridWidth;
rectangleOptions.length = gridHeight;
rectangleOptions.center = [0, 0, 0] as Point3;
rectangleOptions.direction = [0, 1, 0] as Vector3;
const rectangleFace = await face.createRectangleFace(rectangleOptions);
// Create control point on the rectangle face using UV parameters
const pointOnUVOptions = new DataOnUVDto<TopoDSFacePointer>();
pointOnUVOptions.shape = rectangleFace;
pointOnUVOptions.paramU = controlPointU;
pointOnUVOptions.paramV = controlPointV;
const controlPoint = await face.pointOnUV(pointOnUVOptions);
// Generate hexagon grid centers for distance calculation
const hexGridOptions = new HexGridScaledToFitDto();
hexGridOptions.width = gridWidth;
hexGridOptions.height = gridHeight;
hexGridOptions.nrHexagonsInWidth = hexagonsInWidth;
hexGridOptions.nrHexagonsInHeight = hexagonsInHeight;
hexGridOptions.flatTop = true;
hexGridOptions.extendTop = false;
hexGridOptions.extendBottom = false;
hexGridOptions.extendLeft = false;
hexGridOptions.extendRight = false;
hexGridOptions.centerGrid = true;
hexGridOptions.pointsOnGround = true;
const hexGrid = point.hexGridScaledToFit(hexGridOptions);
const hexCenters = hexGrid.centers;
// Calculate distances from control point to all hexagon centers
const distances = point.distancesToPoints({
startPoint: controlPoint,
endPoints: hexCenters
});
// Flatten the distance array and find min/max values
const minDistance = vector.min({ vector: distances });
const maxDistance = vector.max({ vector: distances });
// Remap distances to scale factors (0.211 to 0.9)
const remapOptions = new RemapNumberDto();
remapOptions.fromLow = minDistance;
remapOptions.fromHigh = maxDistance;
remapOptions.toLow = 0.211;
remapOptions.toHigh = 0.9;
const scalePattern = distances.map(x => {
remapOptions.number = x;
return math.remap(remapOptions);
})
// Create inclusion pattern for selective hexagon removal
const inclusionPattern = json.parse({ text: "[true, true, true, true, false]" });
// Create the hexagon faces with advanced patterns
const hexFaceOptions = new HexagonsInGridDto();
hexFaceOptions.width = gridWidth;
hexFaceOptions.height = gridHeight;
hexFaceOptions.nrHexagonsInWidth = hexagonsInWidth;
hexFaceOptions.nrHexagonsInHeight = hexagonsInHeight;
hexFaceOptions.flatTop = true;
hexFaceOptions.extendTop = false;
hexFaceOptions.extendBottom = false;
hexFaceOptions.extendLeft = false;
hexFaceOptions.extendRight = false;
hexFaceOptions.scalePatternWidth = scalePattern;
hexFaceOptions.scalePatternHeight = scalePattern;
hexFaceOptions.inclusionPattern = inclusionPattern;
const hexagonFaces = await face.hexagonsInGrid(hexFaceOptions);
// Create affector point visualization (control point elevated)
const affectorPoint = vector.add({
first: controlPoint,
second: [0, 3, 0] as Vector3
}) as Point3;
// Create pin with label to show the affector point
const pinOptions = new PinWithLabelDto();
pinOptions.startPoint = controlPoint;
pinOptions.endPoint = affectorPoint;
pinOptions.direction = [0, 0, 1] as Vector3;
pinOptions.offsetFromStart = 0.1;
pinOptions.label = "Affector";
pinOptions.labelOffset = 0.3;
pinOptions.labelSize = 0.1;
const pin = await dimensions.pinWithLabel(pinOptions);
// Draw the hexagon faces and affector pin
bitbybit.draw.drawAnyAsync({ entity: hexagonFaces });
bitbybit.draw.drawAnyAsync({ entity: pin });
// Optional: Draw the control point for reference
bitbybit.draw.drawAnyAsync({
entity: controlPoint,
});
How It Works
This example creates hexagonal faces that vary in size based on their distance from a control point, creating natural-looking patterns.
Step-by-Step Process
- Set up the grid parameters - Define width, height, and number of hexagons
- Create a control point - Use UV coordinates (0 to 1) to position it on the grid
- Calculate distances - Measure how far each hexagon center is from the control point
- Scale the hexagons - Closer hexagons become larger, distant ones become smaller
- Apply patterns - Optionally remove some hexagons to create openings
The Math Behind It
The key is remapping distances to scale values:
- Find the shortest and longest distances
- Convert these to scale factors between 0.211 and 0.9
- Apply these scales to make hexagons bigger or smaller
Why Use UV Coordinates?
UV coordinates (from 0 to 1) are better than exact positions because:
- U=0 means left edge, U=1 means right edge
- V=0 means bottom edge, V=1 means top edge
- Works the same regardless of grid size
- Easy to understand and adjust
Pattern Control
The inclusionPattern lets you remove hexagons in a repeating pattern:
[true, true, false]= show 2, skip 1, repeat[true, true, true, true, false]= show 4, skip 1, repeat
Real-World Uses
- Architecture: Building facades that respond to sunlight or wind
- Product Design: Grip patterns, ventilation holes, decorative surfaces
- Interior Design: Ceiling panels, wall textures, lighting patterns
The beauty of this approach is that simple distance calculations create complex, organic-looking patterns that feel natural rather than mechanical.
