我需要帮助在three.js中用随机粒子制作球体。
我知道如何用粒子制作不同的形状,但不知道如何随机制作它们。
这就是我现在所拥有的,
// point cloud geometry
var geometry = new THREE.SphereGeometry(100, 100, 100);
material = new THREE.PointCloudMaterial({
size: 1,
transparent: true,
opacity: 0.5,
color: 0xffffff
});
// point cloud
var pointCloud = new THREE.PointCloud(geometry, material);
//add to scene
scene.add( pointCloud );
感谢
答案 0 :(得分:0)
评论后编辑
这就是诀窍:它生成两个随机角度,然后使用它们从极坐标(球面)坐标转换为具有固定距离(等于球体半径)的笛卡尔坐标
var distance = 100;
var geometry = new THREE.Geometry();
for (var i = 0; i < 1000; i++) {
var vertex = new THREE.Vector3();
var theta = THREE.Math.randFloatSpread(360);
var phi = THREE.Math.randFloatSpread(360);
vertex.x = distance * Math.sin(theta) * Math.cos(phi);
vertex.y = distance * Math.sin(theta) * Math.sin(phi);
vertex.z = distance * Math.cos(theta);
geometry.vertices.push(vertex);
}
var particles = new THREE.PointCloud(geometry, new THREE.PointCloudMaterial({color: 0xffffff}));
particles.boundingSphere = 50;
scene.add(particles);