Browse Source

#9663: Fix radius bug in CylinderBufferGeometry (#9672)

* #9663: Fix radius bug in CylinderBufferGeometry

* CylinderBufferGeometry: simplify normal generation

* CylinderBufferGeometry: Cleanup

* CylinderBufferGeometry: Rename tanTheta variable
Michael Herzog 9 years ago
parent
commit
f6df06c2c9
1 changed files with 9 additions and 15 deletions
  1. 9 15
      src/extras/geometries/CylinderBufferGeometry.js

+ 9 - 15
src/extras/geometries/CylinderBufferGeometry.js

@@ -125,7 +125,7 @@ function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments
 		var groupCount = 0;
 		var groupCount = 0;
 
 
 		// this will be used to calculate the normal
 		// this will be used to calculate the normal
-		var tanTheta = ( radiusBottom - radiusTop ) / height;
+		var slope = ( radiusBottom - radiusTop ) / height;
 
 
 		// generate vertices, normals and uvs
 		// generate vertices, normals and uvs
 
 
@@ -142,25 +142,19 @@ function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments
 
 
 				var u = x / radialSegments;
 				var u = x / radialSegments;
 
 
+				var theta = u * thetaLength + thetaStart;
+
+				var sinTheta = Math.sin( theta );
+				var cosTheta = Math.cos( theta );
+
 				// vertex
 				// vertex
-				vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
+				vertex.x = radius * sinTheta;
 				vertex.y = - v * height + halfHeight;
 				vertex.y = - v * height + halfHeight;
-				vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
+				vertex.z = radius * cosTheta;
 				vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
 				vertices.setXYZ( index, vertex.x, vertex.y, vertex.z );
 
 
 				// normal
 				// normal
-				normal.copy( vertex );
-
-				// handle special case if radiusTop/radiusBottom is zero
-
-				if ( ( radiusTop === 0 && y === 0 ) || ( radiusBottom === 0 && y === heightSegments ) ) {
-
-					normal.x = Math.sin( u * thetaLength + thetaStart );
-					normal.z = Math.cos( u * thetaLength + thetaStart );
-
-				}
-
-				normal.setY( Math.sqrt( normal.x * normal.x + normal.z * normal.z ) * tanTheta ).normalize();
+				normal.set( sinTheta, slope, cosTheta ).normalize();
 				normals.setXYZ( index, normal.x, normal.y, normal.z );
 				normals.setXYZ( index, normal.x, normal.y, normal.z );
 
 
 				// uv
 				// uv