Here is the code I have been working on:
var images = ["image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg", "image5.jpg", "image6.jpg", "image7.jpg", "image8.jpg"];
var objects = [];
var geometry;
while(objects.length < images.length) {
var imagesIndex = 0;
var object = [
texture1 = textureLoader.load( "data/"+ images[imagesIndex] ),
material1 = new THREE.MeshBasicMaterial( { map: texture1 } ),
objectMesh = new THREE.Mesh( geometry, material1 ),
location3d = new THREE.Vector3( Math.random()* 500-250, Math.random()* 500-250, Math.random()* 500+120 )
];
var overlapping = false;
for (var j = 0; j < objects.length; j++) {
var projectCubeLoc = objects[j][0][3];
The line
var otherCubesLoc = projectCubeLoc[j];
leads to an error.
var otherCubesLoc = projectCubeLoc[j];
var distance = projectCubeLoc.distanceTo( otherCubesLoc );
console.log(distance);
if (distance < 150) {
overlapping = true;
break;
};
};
I moved the statement outside of the for-loop because if no overlap occurs, at least one object will be added to the array.
if (!overlapping) {
objects.push(object);
imagesIndex++;
};
};
However, now I am encountering a TypeError: Cannot read property '0' of undefined.
When running this code in the browser, it crashes without displaying any error messages. The browser just quits unexpectedly. I suspect there may be an issue with the while loop, but I can't pinpoint the exact problem.
Any assistance or suggestions would be highly appreciated!
If you require more code snippets or would like to see a JSFiddle example, please let me know :)