@@ -16,12 +16,12 @@ THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, p
1616 phiStart : phiStart ,
1717 phiLength : phiLength ,
1818 thetaStart : thetaStart ,
19- thetaLength : thetaLength
19+ thetaLength : thetaLength
2020 } ;
2121
2222 radius = radius || 50 ;
2323
24- widthSegments = Math . max ( 3 , Math . floor ( widthSegments ) || 8 ) ;
24+ widthSegments = Math . max ( 2 , Math . floor ( widthSegments ) || 8 ) ;
2525 heightSegments = Math . max ( 2 , Math . floor ( heightSegments ) || 6 ) ;
2626
2727 phiStart = phiStart !== undefined ? phiStart : 0 ;
@@ -36,25 +36,21 @@ THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, p
3636 var normals = new THREE . BufferAttribute ( new Float32Array ( vertexCount * 3 ) , 3 ) ;
3737 var uvs = new THREE . BufferAttribute ( new Float32Array ( vertexCount * 2 ) , 2 ) ;
3838
39- this . addAttribute ( 'position' , positions ) ;
40- this . addAttribute ( 'normal' , normals ) ;
41- this . addAttribute ( 'uv' , uvs ) ;
42-
43- var x , y , u , v , px , py , pz , index = 0 , vertices = [ ] , normal = new THREE . Vector3 ( ) ;
39+ var index = 0 , vertices = [ ] , normal = new THREE . Vector3 ( ) ;
4440
45- for ( y = 0 ; y <= heightSegments ; y ++ ) {
41+ for ( var y = 0 ; y <= heightSegments ; y ++ ) {
4642
4743 var verticesRow = [ ] ;
4844
49- v = y / heightSegments ;
45+ var v = y / heightSegments ;
5046
51- for ( x = 0 ; x <= widthSegments ; x ++ ) {
47+ for ( var x = 0 ; x <= widthSegments ; x ++ ) {
5248
53- u = x / widthSegments ;
49+ var u = x / widthSegments ;
5450
55- px = - radius * Math . cos ( phiStart + u * phiLength ) * Math . sin ( thetaStart + v * thetaLength ) ;
56- py = radius * Math . cos ( thetaStart + v * thetaLength ) ;
57- pz = radius * Math . sin ( phiStart + u * phiLength ) * Math . sin ( thetaStart + v * thetaLength ) ;
51+ var px = - radius * Math . cos ( phiStart + u * phiLength ) * Math . sin ( thetaStart + v * thetaLength ) ;
52+ var py = radius * Math . cos ( thetaStart + v * thetaLength ) ;
53+ var pz = radius * Math . sin ( phiStart + u * phiLength ) * Math . sin ( thetaStart + v * thetaLength ) ;
5854
5955 normal . set ( px , py , pz ) . normalize ( ) ;
6056
@@ -73,39 +69,31 @@ THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, p
7369 }
7470
7571 var indices = [ ] ;
76- var ul ;
77- for ( y = 0 , ul = heightSegments - 1 ; y < ul ; y ++ ) {
7872
79- for ( x = 0 ; x < widthSegments ; x ++ ) {
73+ for ( var y = 0 ; y < heightSegments ; y ++ ) {
8074
81- var v1 = vertices [ y ] [ x + 1 ] ;
82- var v2 = vertices [ y ] [ x ] ;
83- var v3 = vertices [ y + 1 ] [ x ] ;
84- var v4 = vertices [ y + 1 ] [ x + 1 ] ;
75+ for ( var x = 0 ; x < widthSegments ; x ++ ) {
76+
77+ var v1 = vertices [ y ] [ x + 1 ] ;
78+ var v2 = vertices [ y ] [ x ] ;
79+ var v3 = vertices [ y + 1 ] [ x ] ;
80+ var v4 = vertices [ y + 1 ] [ x + 1 ] ;
8581
8682 if ( y !== 0 ) indices . push ( v1 , v2 , v4 ) ;
87- indices . push ( v2 , v3 , v4 ) ;
83+ if ( y !== heightSegments - 1 ) indices . push ( v2 , v3 , v4 ) ;
8884
8985 }
90- }
91-
92- y = heightSegments ;
93-
94- for ( x = 0 ; x < widthSegments ; x ++ ) {
95-
96- var v2 = vertices [ y ] [ x ] ;
97- var v3 = vertices [ y - 1 ] [ x ] ;
98- var v4 = vertices [ y - 1 ] [ x + 1 ] ;
99-
100- indices . push ( v2 , v4 , v3 ) ;
10186
10287 }
10388
10489 this . addAttribute ( 'index' , new THREE . BufferAttribute ( new Uint16Array ( indices ) , 1 ) ) ;
90+ this . addAttribute ( 'position' , positions ) ;
91+ this . addAttribute ( 'normal' , normals ) ;
92+ this . addAttribute ( 'uv' , uvs ) ;
10593
10694 this . boundingSphere = new THREE . Sphere ( new THREE . Vector3 ( ) , radius ) ;
10795
10896} ;
10997
11098THREE . SphereBufferGeometry . prototype = Object . create ( THREE . BufferGeometry . prototype ) ;
111- THREE . SphereBufferGeometry . prototype . constructor = THREE . SphereBufferGeometry ;
99+ THREE . SphereBufferGeometry . prototype . constructor = THREE . SphereBufferGeometry ;
0 commit comments