function cube(pos, radius) {
const unitCube = [
[0.5, 0.5, 0.5],
[0.5, -0.5, 0.5],
[-0.5, -0.5, 0.5],
[-0.5, 0.5, 0.5],
[0.5, 0.5, -0.5],
[0.5, -0.5, -0.5],
[-0.5, -0.5, -0.5],
[-0.5, 0.5, -0.5]
];
const position = GLVec3.scale([], pos, scaling);
const r = radius * scaling;
const a = (r * 2) / Math.sqrt(3);
const theta = random.range(Math.PI);
const phi = random.range(2 * Math.PI);
const shiftedSquare = unitCube
.map((p) => GLVec3.scale([], p, a / 2))
.map((p) => GLVec3.rotateX([], p, [0, 0, 0], theta))
.map((p) => GLVec3.rotateZ([], p, [0, 0, 0], phi))
.map((p) => GLVec3.add([], p, position));
const [p1, p2, p3, p4, p5, p6, p7, p8] = shiftedSquare;
return [
interpolateBetweenPoints(p1, p2),
interpolateBetweenPoints(p2, p3),
interpolateBetweenPoints(p3, p4),
interpolateBetweenPoints(p4, p1),
interpolateBetweenPoints(p5, p6),
interpolateBetweenPoints(p6, p7),
interpolateBetweenPoints(p7, p8),
interpolateBetweenPoints(p8, p5),
interpolateBetweenPoints(p1, p5),
interpolateBetweenPoints(p2, p6),
interpolateBetweenPoints(p3, p7),
interpolateBetweenPoints(p4, p8)
].flat();
}