我读到了关于用粒子随机填充球体表面的优秀问题:How to make a sphere made out of random keywords in 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);
Run Code Online (Sandbox Code Playgroud)
但我只得到一张磁盘。如何制作一个充满粒子的球体?
一个角度是不够的,这就是为什么你需要一张磁盘
创建一个随机法线向量
var randomDirection = new THREE.Vector3(Math.random()-0.5,Math.random()-0.5,Math.random()-0.5).normalize();
Run Code Online (Sandbox Code Playgroud)
像以前一样创建随机距离
var radius3 = Math.random() * 350 + 1;
Run Code Online (Sandbox Code Playgroud)
围绕原点的球体中的随机点将是
var randomParticle = randomDirection.multiplyScalar(radius3);
Run Code Online (Sandbox Code Playgroud)
为了获得更好的分布,请使用比 Math.random 更好的生成器
| 归档时间: |
|
| 查看次数: |
1866 次 |
| 最近记录: |