nst newFaces = [];

    function midpoint(a, b) {
        const [x1, y1, z1] = vertices[a];
        const [x2, y2, z2] = vertices[b];
        return [(x1 + x2) / 2, (y1 + y2) / 2, (z1 + z2) / 2];
    }

    for (const face of faces) {
        const [a, b, c] = face;
        const ab = newVertices.push(midpoint(a, b)) - 1;
        const bc = newVertices.push(midpoint(b, c)) - 1;
        const ca = newVertices.push(midpoint(c, a)) - 1;

        newFaces.push([a, ab, ca]);
        newFaces.push([b, bc, ab]);
 