My current task involves working with a dynamically generated array of cubes, each having its distinct position and color. These cubes are situated on a 5x5 field, where each cube is connected to at least one other cube. Now, I am looking to introduce a new "floating cube feature". This entails randomly incorporating a cube that does not have any other cube above or below it but remains connected to another cube on one side (refer to the image).
Here is the visual representation of what needs to be added: https://i.sstatic.net/ChFxS.png
Below is the array showcasing the cubes on the image:
var cube_arr = [{posX: -2, posY: 0, posZ: 1, color: "red", row: 1},
{posX: -2, posY: 1, posZ: 1, color: "red", row: 1},
{posX: -2, posY: 2, posZ: 1, color: "green", row: 1},
{posX: -2, posY: 3, posZ: 1, color: "purple", row: 1},
...
{posX: 2, posY: 2, posZ: 0, color: "yellow", row: 5}]