I'm working on a code that generates clouds with random positions, rotations, and scales. However, sometimes these clouds can end up clipping together when they are generated close to each other or near another object. I want to set a minimum distance between the clouds, something like
if(cloud position x and z is < 10 FROM ANOTHER CLOUD) then set distance
. How can I achieve this? Here's the current code snippet:
for(let i = 0; i < 10; i+= 1){
loader.load('/clouds/clouds2/scene.gltf', function (clouds2) {
const cloud = clouds2.scene
const child1 = cloud.children[0].children[0].children[0].children[2].children[0]
const child2 = cloud.children[0].children[0].children[0].children[3].children[0]
const child3 = cloud.children[0].children[0].children[0].children[4].children[0]
child1.material = new THREE.MeshStandardMaterial({ emissive: 'white', emissiveIntensity: 0.3})
child2.material = new THREE.MeshStandardMaterial({ emissive: 'white', emissiveIntensity: 0.3})
child3.material = new THREE.MeshStandardMaterial({ emissive: 'white', emissiveIntensity: 0.3})
cloud.scale.x = (Math.random() * (0.06 - 0.04 ) + 0.04)
cloud.scale.y = (Math.random() * (0.06 - 0.04 ) + 0.04)
cloud.scale.z = (Math.random() * (0.06 - 0.04 ) + 0.04)
cloud.position.x = (Math.random() - 0.5) * 500
cloud.position.y = (Math.random() + 80)
cloud.position.z = (Math.random() - 1) * 500
cloud.rotation.x = Math.random()
cloud.rotation.y = Math.random()
cloud.rotation.z = Math.random()
scene.add(cloud)
})
}