How to find intersection of objects in three.js?
I load 20 objects which have random position. I need to make it so that the objects have random position but don't intersect. How to fint the intersection of thee objects and check intersection?
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);