提交 f6df06c2 编写于 作者: M Michael Herzog 提交者: Mr.doob

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

* #9663: Fix radius bug in CylinderBufferGeometry

* CylinderBufferGeometry: simplify normal generation

* CylinderBufferGeometry: Cleanup

* CylinderBufferGeometry: Rename tanTheta variable
上级 185f4d62
......@@ -125,7 +125,7 @@ function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments
var groupCount = 0;
// this will be used to calculate the normal
var tanTheta = ( radiusBottom - radiusTop ) / height;
var slope = ( radiusBottom - radiusTop ) / height;
// generate vertices, normals and uvs
......@@ -142,25 +142,19 @@ function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments
var u = x / radialSegments;
var theta = u * thetaLength + thetaStart;
var sinTheta = Math.sin( theta );
var cosTheta = Math.cos( theta );
// vertex
vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
vertex.x = radius * sinTheta;
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 );
// 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 );
// uv
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册