In Blender, I added cubes to a volume (a 3D letter or musical notes in this case, see screenshot). I managed to turn all these cubes into separate meshes, which I now import into Three via gLFT.
Next I extrude the positions of all those cubes and save them to the cubePositions
array. I want to use this array to position a mesh from within (meaning: Blender and gLTF are “only” there to get that positions array).
// Save all the cubes' Vector3 position
const cubePositions = []
let delay = 100;
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
// Add the cubes successively one by one using a promise
const delayedLoop = async() => {
for (var i = 0; i < cubePositions.length; i++) {
addCube( cubePositions[i] ) // function not shown in this script excerpt
await sleep(delay); // wait a bit
}
}
// extract positions of cube and save them to the `cubePositions` array
const gltfLoader = new GLTFLoader()
gltfLoader.load(
'/models/en-3row-with-rotation-anim.gltf',
(gltf) => {
const mesh = gltf
mesh.scene.children.forEach(cube => {
cubePositions.push(cube.position)
})
// now order the array... but how?
// ...?
// Eventually add the cubes
delayedLoop()
},
)
Using an async/await approach I can add cubes to the scene in a staggered manner. This is, where I found out that the ordering of the cubes is rather arbitrary. Therefore I would like to order the Vector3 array. The order should be back-to-front (y-axis in Blender, z-axis in Three – if I am not mistaken) and left-to-right.
Unfortunately I have no idea how to do that…
How can arrays of Vector3 items be ordered that way?