繁体   English   中英

如何在Three.js中制作由随机粒子组成的球体

[英]How to make a sphere made out of random particles in three.js

我需要一些帮助,用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 );

谢谢

评论后编辑

这可以解决问题:生成两个随机角,然后使用它们将极坐标(球面)坐标转换为具有固定距离(等于球体的半径)的笛卡尔坐标。

        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);

工作示例

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM