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 (rete)
{
"id": "rete-v2-json",
"nodes": {
"width": {
"id": "width",
"name": "bitbybit.math.numberSlider",
"customName": "number slider",
"async": false,
"drawable": false,
"data": {
"options": {
"min": 5,
"max": 20,
"step": 0.1,
"width": 350,
"updateOnDrag": false
},
"number": 16.5
},
"inputs": {},
"position": [
429,
1082
]
},
"heigt": {
"id": "heigt",
"name": "bitbybit.math.numberSlider",
"customName": "number slider",
"async": false,
"drawable": false,
"data": {
"options": {},
"number": 9
},
"inputs": {},
"position": [
425,
1237
]
},
"subdivisionsW": {
"id": "subdivisionsW",
"name": "bitbybit.math.numberSlider",
"customName": "number slider",
"async": false,
"drawable": false,
"data": {
"options": {
"min": 5,
"max": 40,
"step": 1,
"width": 350,
"updateOnDrag": false
},
"number": 29
},
"inputs": {},
"position": [
419,
1401
]
},
"subdivisionsH": {
"id": "subdivisionsH",
"name": "bitbybit.math.numberSlider",
"customName": "number slider",
"async": false,
"drawable": false,
"data": {
"options": {
"min": 0,
"max": 40,
"step": 0.1,
"width": 350,
"updateOnDrag": false
},
"number": 29
},
"inputs": {},
"position": [
421,
1554
]
},
"hexGridScaledToFit": {
"id": "hexGridScaledToFit",
"name": "bitbybit.point.hexGridScaledToFit",
"customName": "hex grid scaled to fit",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"width": 10,
"height": 10,
"nrHexagonsInWidth": 10,
"nrHexagonsInHeight": 10,
"flatTop": true,
"extendTop": false,
"extendBottom": false,
"extendLeft": false,
"extendRight": false,
"centerGrid": true,
"pointsOnGround": true
},
"inputs": {
"width": {
"connections": [
{
"node": "width",
"output": "result",
"data": {}
}
]
},
"height": {
"connections": [
{
"node": "heigt",
"output": "result",
"data": {}
}
]
},
"nrHexagonsInWidth": {
"connections": [
{
"node": "subdivisionsW",
"output": "result",
"data": {}
}
]
},
"nrHexagonsInHeight": {
"connections": [
{
"node": "subdivisionsH",
"output": "result",
"data": {}
}
]
}
},
"position": [
1229,
465
]
},
"getValueOnProp": {
"id": "getValueOnProp",
"name": "bitbybit.json.getValueOnProp",
"customName": "get value on prop",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"property": "centers"
},
"inputs": {
"json": {
"connections": [
{
"node": "hexGridScaledToFit",
"output": "result",
"data": {}
}
]
}
},
"position": [
1631,
465
]
},
"distancesToPoints": {
"id": "distancesToPoints",
"name": "bitbybit.point.distancesToPoints",
"customName": "distances to points",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"startPoint": {
"connections": [
{
"node": "pointOnUv",
"output": "result",
"data": {}
}
]
},
"endPoints": {
"connections": [
{
"node": "getValueOnProp",
"output": "result",
"data": {}
}
]
}
},
"position": [
2466,
224
]
},
"max": {
"id": "max",
"name": "bitbybit.vector.max",
"customName": "max",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"vector": {
"connections": [
{
"node": "distancesToPoints",
"output": "result",
"data": {}
}
]
}
},
"position": [
2933,
487
]
},
"min": {
"id": "min",
"name": "bitbybit.vector.min",
"customName": "min",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"vector": {
"connections": [
{
"node": "distancesToPoints",
"output": "result",
"data": {}
}
]
}
},
"position": [
2936,
225
]
},
"remap": {
"id": "remap",
"name": "bitbybit.math.remap",
"customName": "remap",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"number": 0.5,
"fromLow": 0,
"fromHigh": 1,
"toLow": 0.211,
"toHigh": 0.9
},
"inputs": {
"fromHigh": {
"connections": [
{
"node": "max",
"output": "result",
"data": {}
}
]
},
"fromLow": {
"connections": [
{
"node": "min",
"output": "result",
"data": {}
}
]
},
"number": {
"connections": [
{
"node": "flatten",
"output": "result",
"data": {}
}
]
}
},
"position": [
3388,
182
]
},
"flatten": {
"id": "flatten",
"name": "bitbybit.lists.flatten",
"customName": "flatten",
"async": false,
"drawable": false,
"data": {
"nrLevels": 1
},
"inputs": {
"list": {
"connections": [
{
"node": "distancesToPoints",
"output": "result",
"data": {}
}
]
}
},
"position": [
2938,
14
]
},
"parse": {
"id": "parse",
"name": "bitbybit.json.parse",
"customName": "parse",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"text": "[true, true, true, true, false]"
},
"inputs": {},
"position": [
4182,
1698
]
},
"hexagonsInGrid": {
"id": "hexagonsInGrid",
"name": "bitbybit.occt.shapes.face.hexagonsInGrid",
"customName": "hexagons in grid",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"width": 10,
"height": 10,
"nrHexagonsInWidth": 10,
"nrHexagonsInHeight": 10,
"flatTop": true,
"extendTop": false,
"extendBottom": false,
"extendLeft": false,
"extendRight": false
},
"inputs": {
"width": {
"connections": [
{
"node": "width",
"output": "result",
"data": {}
}
]
},
"height": {
"connections": [
{
"node": "heigt",
"output": "result",
"data": {}
}
]
},
"nrHexagonsInWidth": {
"connections": [
{
"node": "subdivisionsW",
"output": "result",
"data": {}
}
]
},
"nrHexagonsInHeight": {
"connections": [
{
"node": "subdivisionsH",
"output": "result",
"data": {}
}
]
},
"scalePatternWidth": {
"connections": [
{
"node": "createList",
"output": "list",
"data": {}
}
]
},
"scalePatternHeight": {
"connections": [
{
"node": "createList",
"output": "list",
"data": {}
}
]
},
"inclusionPattern": {
"connections": [
{
"node": "parse",
"output": "result",
"data": {}
}
]
}
},
"position": [
4602,
1180
]
},
"rectangleFace": {
"id": "rectangleFace",
"name": "bitbybit.occt.shapes.face.createRectangleFace",
"customName": "rectangle face",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"width": 1,
"length": 2,
"center": [
0,
0,
0
],
"direction": [
0,
1,
0
]
},
"inputs": {
"width": {
"connections": [
{
"node": "width",
"output": "result",
"data": {}
}
]
},
"length": {
"connections": [
{
"node": "heigt",
"output": "result",
"data": {}
}
]
}
},
"position": [
1233,
67
]
},
"pointOnUv": {
"id": "pointOnUv",
"name": "bitbybit.occt.shapes.face.pointOnUV",
"customName": "point on uv",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"paramU": 0.5,
"paramV": 0.5
},
"inputs": {
"shape": {
"connections": [
{
"node": "rectangleFace",
"output": "result",
"data": {}
}
]
},
"paramU": {
"connections": [
{
"node": "u1",
"output": "result",
"data": {}
}
]
},
"paramV": {
"connections": [
{
"node": "v1",
"output": "result",
"data": {}
}
]
}
},
"position": [
1805,
-345
]
},
"u1": {
"id": "u1",
"name": "bitbybit.math.numberSlider",
"customName": "number slider",
"async": false,
"drawable": false,
"data": {
"options": {
"min": 0,
"max": 1,
"step": 0.01,
"width": 350,
"updateOnDrag": false
},
"number": 0
},
"inputs": {},
"position": [
482,
-303
]
},
"v1": {
"id": "v1",
"name": "bitbybit.math.numberSlider",
"customName": "number slider",
"async": false,
"drawable": false,
"data": {
"options": {
"min": 0,
"max": 1,
"step": 0.01,
"width": 350,
"updateOnDrag": false
},
"number": 0.49
},
"inputs": {},
"position": [
478,
-143
]
},
"createList": {
"id": "createList",
"name": "bitbybit.lists.createList",
"customName": "create list",
"async": false,
"drawable": false,
"data": {},
"inputs": {
"listElements": {
"connections": [
{
"node": "remap",
"output": "result",
"data": {}
}
]
}
},
"position": [
3774,
222
]
},
"add": {
"id": "add",
"name": "bitbybit.vector.add",
"customName": "add",
"async": false,
"drawable": false,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
}
},
"inputs": {
"first": {
"connections": [
{
"node": "pointOnUv",
"output": "result",
"data": {}
}
]
},
"second": {
"connections": [
{
"node": "vectorXyz",
"output": "result",
"data": {}
}
]
}
},
"position": [
2809,
-470
]
},
"vectorXyz": {
"id": "vectorXyz",
"name": "bitbybit.vector.vectorXYZ",
"customName": "vector xyz",
"async": false,
"drawable": true,
"data": {
"genericNodeData": {
"hide": true,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"x": 0,
"y": 3,
"z": 0
},
"inputs": {},
"position": [
2408,
-248
]
},
"pinWithLabel": {
"id": "pinWithLabel",
"name": "bitbybit.occt.dimensions.pinWithLabel",
"customName": "pin with label",
"async": true,
"drawable": true,
"data": {
"genericNodeData": {
"hide": false,
"oneOnOne": false,
"flatten": 0,
"forceExecution": false
},
"startPoint": [
0,
0,
0
],
"endPoint": [
0,
5,
2
],
"direction": [
0,
0,
1
],
"offsetFromStart": 0.1,
"label": "Affector",
"labelOffset": 0.3,
"labelSize": 0.1,
"endType": "none",
"arrowSize": 0.3,
"arrowAngle": 30,
"arrowsFlipped": false,
"labelRotation": 0,
"labelFlipHorizontal": false,
"labelFlipVertical": false
},
"inputs": {
"endPoint": {
"connections": [
{
"node": "add",
"output": "result",
"data": {}
}
]
},
"startPoint": {
"connections": [
{
"node": "pointOnUv",
"output": "result",
"data": {}
}
]
}
},
"position": [
3232,
-754
]
}
},
"modules": {}
}
Script Source (blockly)
<xml xmlns="https://developers.google.com/blockly/xml"><variables><variable id="gridWidth">gridWidth</variable><variable id="gridHeight">gridHeight</variable><variable id="hexagonsInWidth">hexagonsInWidth</variable><variable id="hexagonsInHeight">hexagonsInHeight</variable><variable id="controlPointU">controlPointU</variable><variable id="controlPointV">controlPointV</variable><variable id="rectangleFace">rectangleFace</variable><variable id="controlPoint">controlPoint</variable><variable id="hexGrid">hexGrid</variable><variable id="hexCenters">hexCenters</variable><variable id="distances">distances</variable><variable id="minDistance">minDistance</variable><variable id="maxDistance">maxDistance</variable><variable id="scalePattern">scalePattern</variable><variable id="distance">distance</variable><variable id="scaledValue">scaledValue</variable><variable id="inclusionPattern">inclusionPattern</variable><variable id="hexagonFaces">hexagonFaces</variable><variable id="affectorPoint">affectorPoint</variable><variable id="pin">pin</variable></variables><block type="variables_set" x="-500" y="-500"><field name="VAR" id="gridWidth">gridWidth</field><value name="VALUE"><block type="math_number"><field name="NUM">16.5</field></block></value><next><block type="variables_set"><field name="VAR" id="gridHeight">gridHeight</field><value name="VALUE"><block type="math_number"><field name="NUM">9</field></block></value><next><block type="variables_set"><field name="VAR" id="hexagonsInWidth">hexagonsInWidth</field><value name="VALUE"><block type="math_number"><field name="NUM">29</field></block></value><next><block type="variables_set"><field name="VAR" id="hexagonsInHeight">hexagonsInHeight</field><value name="VALUE"><block type="math_number"><field name="NUM">29</field></block></value><next><block type="variables_set"><field name="VAR" id="controlPointU">controlPointU</field><value name="VALUE"><block type="math_number"><field name="NUM">0</field></block></value><next><block type="variables_set"><field name="VAR" id="controlPointV">controlPointV</field><value name="VALUE"><block type="math_number"><field name="NUM">0.49</field></block></value><next><block type="variables_set"><field name="VAR" id="rectangleFace">rectangleFace</field><value name="VALUE"><block type="base_time_await_return"><value name="Promise"><block type="bitbybit.occt.shapes.face.createRectangleFace"><value name="Width"><block type="variables_get"><field name="VAR" id="gridWidth">gridWidth</field></block></value><value name="Length"><block type="variables_get"><field name="VAR" id="gridHeight">gridHeight</field></block></value><value name="Center"><block type="bitbybit.point.pointXYZ"><value name="X"><block type="math_number"><field name="NUM">0</field></block></value><value name="Y"><block type="math_number"><field name="NUM">0</field></block></value><value name="Z"><block type="math_number"><field name="NUM">0</field></block></value></block></value><value name="Direction"><block type="bitbybit.vector.vectorXYZ"><value name="X"><block type="math_number"><field name="NUM">0</field></block></value><value name="Y"><block type="math_number"><field name="NUM">1</field></block></value><value name="Z"><block type="math_number"><field name="NUM">0</field></block></value></block></value></block></value></block></value><next><block type="variables_set"><field name="VAR" id="controlPoint">controlPoint</field><value name="VALUE"><block type="base_time_await_return"><value name="Promise"><block type="bitbybit.occt.shapes.face.pointOnUV"><value name="Shape"><block type="variables_get"><field name="VAR" id="rectangleFace">rectangleFace</field></block></value><value name="ParamU"><block type="variables_get"><field name="VAR" id="controlPointU">controlPointU</field></block></value><value name="ParamV"><block type="variables_get"><field name="VAR" id="controlPointV">controlPointV</field></block></value></block></value></block></value><next><block type="variables_set"><field name="VAR" id="hexGrid">hexGrid</field><value name="VALUE"><block type="bitbybit.point.hexGridScaledToFit"><value name="Width"><block type="variables_get"><field name="VAR" id="gridWidth">gridWidth</field></block></value><value name="Height"><block type="variables_get"><field name="VAR" id="gridHeight">gridHeight</field></block></value><value name="NrHexagonsInWidth"><block type="variables_get"><field name="VAR" id="hexagonsInWidth">hexagonsInWidth</field></block></value><value name="NrHexagonsInHeight"><block type="variables_get"><field name="VAR" id="hexagonsInHeight">hexagonsInHeight</field></block></value><value name="FlatTop"><block type="logic_boolean"><field name="BOOL">TRUE</field></block></value><value name="ExtendTop"><block type="logic_boolean"><field name="BOOL">FALSE</field></block></value><value name="ExtendBottom"><block type="logic_boolean"><field name="BOOL">FALSE</field></block></value><value name="ExtendLeft"><block type="logic_boolean"><field name="BOOL">FALSE</field></block></value><value name="ExtendRight"><block type="logic_boolean"><field name="BOOL">FALSE</field></block></value><value name="CenterGrid"><block type="logic_boolean"><field name="BOOL">TRUE</field></block></value><value name="PointsOnGround"><block type="logic_boolean"><field name="BOOL">TRUE</field></block></value></block></value><next><block type="variables_set"><field name="VAR" id="hexCenters">hexCenters</field><value name="VALUE"><block type="bitbybit.json.getValueOnProp"><value name="Json"><block type="variables_get"><field name="VAR" id="hexGrid">hexGrid</field></block></value><value name="Property"><block type="text"><field name="TEXT">centers</field></block></value></block></value><next><block type="variables_set"><field name="VAR" id="distances">distances</field><value name="VALUE"><block type="bitbybit.point.distancesToPoints"><value name="StartPoint"><block type="variables_get"><field name="VAR" id="controlPoint">controlPoint</field></block></value><value name="EndPoints"><block type="variables_get"><field name="VAR" id="hexCenters">hexCenters</field></block></value></block></value><next><block type="variables_set"><field name="VAR" id="minDistance">minDistance</field><value name="VALUE"><block type="bitbybit.vector.min"><value name="Vector"><block type="variables_get"><field name="VAR" id="distances">distances</field></block></value></block></value><next><block type="variables_set"><field name="VAR" id="maxDistance">maxDistance</field><value name="VALUE"><block type="bitbybit.vector.max"><value name="Vector"><block type="variables_get"><field name="VAR" id="distances">distances</field></block></value></block></value><next><block type="variables_set"><field name="VAR" id="scalePattern">scalePattern</field><value name="VALUE"><block type="lists_create_with"><mutation items="0"></mutation></block></value><next><block type="controls_forEach"><field name="VAR" id="distance">distance</field><value name="LIST"><block type="variables_get"><field name="VAR" id="distances">distances</field></block></value><statement name="DO"><block type="variables_set"><field name="VAR" id="scaledValue">scaledValue</field><value name="VALUE"><block type="bitbybit.math.remap"><value name="Number"><block type="variables_get"><field name="VAR" id="distance">distance</field></block></value><value name="FromLow"><block type="variables_get"><field name="VAR" id="minDistance">minDistance</field></block></value><value name="FromHigh"><block type="variables_get"><field name="VAR" id="maxDistance">maxDistance</field></block></value><value name="ToLow"><block type="math_number"><field name="NUM">0.211</field></block></value><value name="ToHigh"><block type="math_number"><field name="NUM">0.9</field></block></value></block></value><next><block type="lists_setIndex"><mutation at="false"></mutation><field name="MODE">INSERT</field><field name="WHERE">LAST</field><value name="LIST"><block type="variables_get"><field name="VAR" id="scalePattern">scalePattern</field></block></value><value name="TO"><block type="variables_get"><field name="VAR" id="scaledValue">scaledValue</field></block></value></block></next></block></statement><next><block type="variables_set"><field name="VAR" id="inclusionPattern">inclusionPattern</field><value name="VALUE"><block type="bitbybit.json.parse"><value name="Text"><block type="text"><field name="TEXT">[true, true, true, true, false]</field></block></value></block></value><next><block type="variables_set"><field name="VAR" id="hexagonFaces">hexagonFaces</field><value name="VALUE"><block type="base_time_await_return"><value name="Promise"><block type="bitbybit.occt.shapes.face.hexagonsInGrid"><value name="Width"><block type="variables_get"><field name="VAR" id="gridWidth">gridWidth</field></block></value><value name="Height"><block type="variables_get"><field name="VAR" id="gridHeight">gridHeight</field></block></value><value name="NrHexagonsInWidth"><block type="variables_get"><field name="VAR" id="hexagonsInWidth">hexagonsInWidth</field></block></value><value name="NrHexagonsInHeight"><block type="variables_get"><field name="VAR" id="hexagonsInHeight">hexagonsInHeight</field></block></value><value name="FlatTop"><block type="logic_boolean"><field name="BOOL">TRUE</field></block></value><value name="ExtendTop"><block type="logic_boolean"><field name="BOOL">FALSE</field></block></value><value name="ExtendBottom"><block type="logic_boolean"><field name="BOOL">FALSE</field></block></value><value name="ExtendLeft"><block type="logic_boolean"><field name="BOOL">FALSE</field></block></value><value name="ExtendRight"><block type="logic_boolean"><field name="BOOL">FALSE</field></block></value><value name="ScalePatternWidth"><block type="variables_get"><field name="VAR" id="scalePattern">scalePattern</field></block></value><value name="ScalePatternHeight"><block type="variables_get"><field name="VAR" id="scalePattern">scalePattern</field></block></value><value name="InclusionPattern"><block type="variables_get"><field name="VAR" id="inclusionPattern">inclusionPattern</field></block></value></block></value></block></value><next><block type="variables_set"><field name="VAR" id="affectorPoint">affectorPoint</field><value name="VALUE"><block type="bitbybit.vector.add"><value name="First"><block type="variables_get"><field name="VAR" id="controlPoint">controlPoint</field></block></value><value name="Second"><block type="bitbybit.vector.vectorXYZ"><value name="X"><block type="math_number"><field name="NUM">0</field></block></value><value name="Y"><block type="math_number"><field name="NUM">3</field></block></value><value name="Z"><block type="math_number"><field name="NUM">0</field></block></value></block></value></block></value><next><block type="variables_set"><field name="VAR" id="pin">pin</field><value name="VALUE"><block type="base_time_await_return"><value name="Promise"><block type="bitbybit.occt.dimensions.pinWithLabel"><value name="StartPoint"><block type="variables_get"><field name="VAR" id="controlPoint">controlPoint</field></block></value><value name="EndPoint"><block type="variables_get"><field name="VAR" id="affectorPoint">affectorPoint</field></block></value><value name="Direction"><block type="bitbybit.vector.vectorXYZ"><value name="X"><block type="math_number"><field name="NUM">0</field></block></value><value name="Y"><block type="math_number"><field name="NUM">0</field></block></value><value name="Z"><block type="math_number"><field name="NUM">1</field></block></value></block></value><value name="OffsetFromStart"><block type="math_number"><field name="NUM">0.1</field></block></value><value name="Label"><block type="text"><field name="TEXT">Affector</field></block></value><value name="LabelOffset"><block type="math_number"><field name="NUM">0.3</field></block></value><value name="LabelSize"><block type="math_number"><field name="NUM">0.1</field></block></value></block></value></block></value><next><block type="bitbybit.draw.drawAnyAsyncNoReturn"><value name="Entity"><block type="variables_get"><field name="VAR" id="hexagonFaces">hexagonFaces</field></block></value><next><block type="bitbybit.draw.drawAnyAsyncNoReturn"><value name="Entity"><block type="variables_get"><field name="VAR" id="pin">pin</field></block></value><next><block type="bitbybit.draw.drawAnyAsyncNoReturn"><value name="Entity"><block type="variables_get"><field name="VAR" id="controlPoint">controlPoint</field></block></value></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></next></block></xml>
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.



