1

我正在尝试制作一个显示大量球形对象的三个 js 文档,最快的方法是使用 buffergeometry。从这里的这篇文章中,我了解到我可以使用以下方法将普通几何转换为缓冲几何:

    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();但这会创建我不想要的正方形。任何人都知道为什么这似乎不起作用?提前致谢。

4

1 回答 1

5

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

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

r72 dev中,您可以这样做:

// constructor: radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength
var sphereGeo = new THREE.SphereBufferGeometry( 4, 3, 2 ); //r72
于 2015-07-05T10:00:04.990 回答