三个JS buffergeometry的球(Three js buffergeometry for

2019-10-20 19:27发布

我试着做了三个JS文件,该文件显示大量球状物体,要做到这一点最快捷的方法是使用buffergeometry。 从这个岗位在这里我才知道,我可以正常几何转换为使用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(); 但是这创造了我不想广场。 任何人有任何想法,为什么这似乎并没有工作? 提前致谢。

Answer 1:

three.js所R71,你可以这样创造球缓冲区几何:

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

R72开发 ,你可以做到这一点简单的是这样的:

// constructor: radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength
var sphereGeo = new THREE.SphereBufferGeometry( 4, 3, 2 ); //r72


文章来源: Three js buffergeometry for spheres