Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9663: Fix radius bug in CylinderBufferGeometry #9672

Merged
merged 4 commits into from
Sep 13, 2016
Merged

Conversation

Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Sep 12, 2016

See #9663.

The zero comparison does not work in some special cases with radius values very close to zero. Instead we now using a tolerance value (Number.EPSILON).

@@ -153,7 +153,7 @@ function CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments

// handle special case if radiusTop/radiusBottom is zero

if ( ( radiusTop === 0 && y === 0 ) || ( radiusBottom === 0 && y === heightSegments ) ) {
if ( ( radiusTop < Number.EPSILON && y === 0 ) || ( radiusBottom < Number.EPSILON && y === heightSegments ) ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this special case? I'm not sure you do; just don't multiply by radius first?

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Sep 12, 2016

@WestLangley Good point! What do you think about the last commit? No special cases any more...

@WestLangley
Copy link
Collaborator

@Mugen87 Not tested, but something like:

var u = x / radialSegments;

var theta = u * thetaLength + thetaStart;

var sinTheta = Math.sin( theta );
var cosTheta = Math.cos( theta );

// vertex
vertices.setXYZ( index, radius * sinTheta, - v * height + halfHeight, radius * cosTheta );

// normal
normal.set( sinTheta, tanTheta, cosTheta ).normalize(); // tanTheta should be renamed, IMO
normals.setXYZ( index, normal.x, normal.y, normal.z );

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Sep 12, 2016

tanTheta is calculated in this way:

var tanTheta = ( radiusBottom - radiusTop ) / height;

Would be something like incline or slope a better name?

@WestLangley
Copy link
Collaborator

Doesn't matter. It is just not the same theta. I like slope. : - )

@Mugen87
Copy link
Collaborator Author

Mugen87 commented Sep 12, 2016

Done! 😊

@mrdoob
Copy link
Owner

mrdoob commented Sep 13, 2016

@WestLangley all good?

@WestLangley
Copy link
Collaborator

OK. Thanks, @Mugen87.

@mrdoob mrdoob merged commit f6df06c into mrdoob:dev Sep 13, 2016
@mrdoob
Copy link
Owner

mrdoob commented Sep 13, 2016

Yays!

@50Wliu
Copy link

50Wliu commented Sep 13, 2016

Thanks everyone, I really appreciate it! 😄

aardgoose pushed a commit to aardgoose/three.js that referenced this pull request Oct 7, 2016
* mrdoob#9663: Fix radius bug in CylinderBufferGeometry

* CylinderBufferGeometry: simplify normal generation

* CylinderBufferGeometry: Cleanup

* CylinderBufferGeometry: Rename tanTheta variable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants