用于球体的三个js缓冲测量法

时间:2014-08-25 17:18:36

标签: javascript three.js buffer-geometry

我试图制作一个显示大量球形物体的三个js文档,最快的方法是使用缓冲测量法。从这篇文章here我了解到我可以使用以下方法将正常几何转换为缓冲区几何:

    var sphere = new THREE.SphereGeometry( 4, 0.05, 0.025 );
    var geometry = THREE.BufferGeometryUtils.fromGeometry( sphere );

但这对我来说似乎不起作用,创建该对象的其余代码为:

    var positions = new Float32Array( x_GAMA.length * 3 );


    for ( var i = 0; i < x_GAMA.length; i += 1 ) {

                // positions

                positions[ 3*i ]     =  x_GAMA[i]*10000;
                positions[ 3*i + 1 ] =  y_GAMA[i]*10000;
                positions[ 3*i + 2 ] =  z_GAMA[i]*10000;



            }
    geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );

    var material = new THREE.PointCloudMaterial( {size:1,color:0x999999}  );

    geometry.computeBoundingSphere();

    particleSystem = new THREE.PointCloud( geometry, material );


    scene.add( particleSystem );

如果我使用var geometry = new THREE.BufferGeometry();它可以正常工作,但这会创建我不想要的方块。任何人都知道为什么这似乎不起作用?提前谢谢。

1 个答案:

答案 0 :(得分:4)

Three.js r71 中,您可以像这样创建Sphere Buffer Geometry:

json.loads

r72 dev 中,您可以这样做直截了当:

var sphereGeometry = new THREE.SphereGeometry( 4, 3, 2 );
var bufferSphereGeometry = new THREE.BufferGeometry().fromGeometry( sphereGeometry );