Currently delving into the world of Three.js with enthusiasm.
Here's What I Have:
In my exploration, I have implemented a for loop that generates a specific object at random positions within the scene.
Visual Reference: https://i.sstatic.net/VXdXR.png Code Snippet:
//Creating Objects
var geometry = new THREE.CylinderBufferGeometry( 0, 10, 30, 4, 1 );
var material = new THREE.MeshPhongMaterial( { color: 0xffffff, flatShading: true } );
for(var i=0; i<100; i++) {
var mesh = new THREE.Mesh( geometry, material );
mesh.position.x = getRandomInt(-500,500);
mesh.position.y = getRandomInt(10, 100);
mesh.position.z = getRandomInt(-500,500);
mesh.updateMatrix();
mesh.matrixAutoUpdate = false;
scene_Main.add( mesh );
}
The Query at Hand:
I am now pondering over the idea of creating random objects with varying materials and geometries within a for loop.
Is it feasible to utilize an array to store specific geometries/materials? If so, how can I implement this array and make use of it effectively?
Proposed Array Strategy:
var geometryList = [cube, pyramid, sphere, donut, ...];
var materialList = [ .. possibilities abound here .. ];
for(var i=0; i<100; i++) {
var mesh = new THREE.Mesh( geometryList[random[n]], materialList[random[n]] );
....
}