From 699ad0b3deeb01cc80892cf1b20ff3c340a7d635 Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Wed, 29 Apr 2015 16:28:35 +0100 Subject: [PATCH] CircleBufferGeometry: Clean up. --- src/extras/geometries/CircleBufferGeometry.js | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/extras/geometries/CircleBufferGeometry.js b/src/extras/geometries/CircleBufferGeometry.js index 6ec09dfbd6..d2069f53ae 100644 --- a/src/extras/geometries/CircleBufferGeometry.js +++ b/src/extras/geometries/CircleBufferGeometry.js @@ -21,38 +21,34 @@ THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLengt thetaStart = thetaStart !== undefined ? thetaStart : 0; thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2; - var i; var vertices = segments + 2; - var positions = new Float32Array( 3 * vertices ); - this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) ); - var normals = new Float32Array( 3 * vertices ); - this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) ); - var uvs = new Float32Array( 2 * vertices ); - this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) ); + var positions = new Float32Array( vertices * 3 ); + var normals = new Float32Array( vertices * 3 ); + var uvs = new Float32Array( vertices * 2 ); // center data is already zero, but need to set a few extras normals[3] = 1.0; uvs[0] = 0.5; uvs[1] = 0.5; - for ( s = 0, i = 3, ii = 2 ; s < vertices; s++, i += 3, ii += 2 ) { + for ( var s = 0, i = 3, ii = 2 ; s < vertices; s++, i += 3, ii += 2 ) { var segment = thetaStart + s / segments * thetaLength; - positions[i] = radius * Math.cos( segment ); + positions[i] = radius * Math.cos( segment ); positions[i + 1] = radius * Math.sin( segment ); normals[i + 2] = 1; // normal z - uvs[ii] = ( positions[i] / radius + 1 ) / 2; - uvs[ii + 1] = ( positions[i + 1] / radius + 1 ) / 2; + uvs[ii] = ( positions[i] / radius + 1 ) / 2; + uvs[ii + 1] = ( positions[i + 1] / radius + 1 ) / 2; } var indices = []; - for ( i = 1; i <= segments; i ++ ) { + for ( var i = 1; i <= segments; i ++ ) { indices.push( i ); indices.push( i + 1 ); @@ -61,8 +57,9 @@ THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLengt } this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) ); - - this.computeFaceNormals(); + this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) ); + this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) ); + this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) ); this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius ); -- GitLab