In my current three.js project, I am working with a total of 100 meshes which are organized into 10 different scenes:
// Adding 100 meshes to 10 scenes based on an array containing 100 elements
for (var i = 0; i < data.length; i++) {
mesh = new THREE.Mesh(geometry, material);
// Random positions to prevent overlapping
mesh.position.x = THREE.Math.randInt(-500, 500);
mesh.position.z = THREE.Math.randInt(-500, 500);
These meshes are added using a loop and each one is assigned to a specific scene:
// Assigning 10 meshes per scene
var sceneIndex = Math.floor(i/10);
scenes[sceneIndex].add(mesh);
I have also implemented a feature that allows me to rotate a mesh around the center of its respective scene.
However, I am facing a challenge in applying this rotation functionality to all meshes while keeping them separated within their designated scenes. To clarify, I have created a fiddle containing the relevant code snippets.
If you uncomment the following lines, you will notice that all meshes move to scenes[0]
, and they rotate as intended. Nevertheless, I still need to maintain the division among scenes:
spinningRig.add(mesh);
scenes[0].add(spinningRig);
Could someone guide me on how the code should be structured? What would be the logical approach to resolve this issue?