2015-12-09 121 views
0

閱讀外觀極好問題關於隨機填充一個球體的表面顆粒How to make a sphere made out of random particles in three.js。我如何用隨機生成的粒子填充球體的總體積?我試試看:如何填補隨機粒子的球體在three.js所

var particleCount = 1800, 
    particles = new THREE.Geometry(), 

    pMaterial = new THREE.PointCloudMaterial({ 
    color: 0xFFFFFF, 
    size: 20, 
    map: THREE.ImageUtils.loadTexture(
     "images/particle.png" 
    ), 
    blending: THREE.AdditiveBlending, 
    transparent: true 
    }); 

for (var t = 0; t < particleCount; t++) { 
    var angle3 = Math.random() * Math.PI * 2; 
    var radius3 = Math.random() * 350 + 1; 
    var pX1 = Math.cos(angle3) * radius3, 
    pY1 = Math.random() * 70 - 35, 
    pZ1 = Math.sin(angle3) * radius3, 
    skparticle11 = new THREE.Vector3(pX1, pY1, pZ1); 
    particles.vertices.push(skparticle11); 
} 

var particleSystem = new THREE.PointCloud(
    particles, 
    pMaterial); 

// add it to the scene 
scene.add(particleSystem); 

但我只是得到一個磁盤。如何使球體充滿粒子?

+1

您是否需要將粒子均勻分佈? – andars

+0

[在球形體積內採樣均勻分佈的隨機點]可能的重複(http://stackoverflow.com/questions/5408276/sampling-uniformly-distributed-random-points-inside-a-spherical-volume) –

+0

我是現在去讀它 –

回答

3

一個角度是不夠的,這就是爲什麼你得到一個磁盤

創建一個隨機法線

var randomDirection = new THREE.Vector3(Math.random()-0.5,Math.random()-0.5,Math.random()-0.5).normalize(); 

你之前

var radius3 = Math.random() * 350 + 1; 

隨機點確實創造了隨機距離在原點附近的球體上將會是

var randomParticle = randomDirection.multiplyScalar(radius3); 

爲了更好的分配使用一些比Math.random更好的發生器