My goal is to load 20 objects with random positions in a way that they do not intersect. How can I detect and check for intersections between these objects?
for (var i = 0; i < 20; i++) {
// Create a material
var textureLoader = new THREE.TextureLoader();
var map = textureLoader.load('./models/test_2.png');
var material = new THREE.MeshPhongMaterial({ map: map });
var shipMtl = new MTLLoader();
var loader = new this.THREE.OBJLoader();
shipMtl.load('./models/test.mtl', function(materials) {
materials.preload();
loader.setMaterials(materials);
loader.load('./models/test.obj', function(object) {
object.traverse(function(node) {
if (node.isMesh) node.material = material;
});
object.position.x = Math.random() * 500 - 250;
object.position.y = Math.random() * 500 - 250;
object.position.z = Math.random() * 500 - 250;
object.scale.x = Math.random() * 2 + 40;
object.scale.y = Math.random() * 2 + 40;
object.scale.z = Math.random() * 2 + 40;
object.rotation.x = Math.random() * 2 * Math.PI;
object.rotation.y = Math.random() * 2 * Math.PI;
object.rotation.z = Math.random() * 2 * Math.PI;
var obj = object; // put your object as global
scene.add(obj);
});
});
}
raycaster = new THREE.Raycaster();
mouse = new THREE.Vector2();
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
this.refs.figure.appendChild(renderer.domElement);