-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
New LatheBufferGeometry #8334
New LatheBufferGeometry #8334
Conversation
this.computeVertexNormals(); | ||
|
||
// if the geometry is closed, we need to merge the first and last normal of a vertex row | ||
// because the corresponding vertices are identical (but still have different UVs). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// if the geometry is closed, we need to average the normals along the seam.
I think the way you have handled normals along the seam is fine. |
For future reference, that should probably have been in a separate PR. In any event, why were you getting zero vectors? |
I've discovered this problem with my mentioned jsfiddle example. The algorithm in pA.fromArray( positions, vA ); // zero vector
pB.fromArray( positions, vB ); // zero vector
pC.fromArray( positions, vC ); The result looks then quite faulty (see example screenshot). I think this is caused by the first point of the |
Ok, i will keep that in mind! 👍 |
The geometry could form a point at the top, like a spear. Is that problematic? Also, I llke your goblet. : - ) |
I have the points data from the three.js editor 😉. Indeed, it's a really cool shape!
Um, i'm afraid that i can't imagine what it is about. Do you mean i need to adjust my |
Sorry, I could have stated that better. I was wondering if there is a problem with the normals at the tip of a cone-shaped lathe geometry. In hindsight, I do not think that is an issue. |
BTW, where does the term |
I know it from 3D Studio. Not sure where they got it from. |
Yes, that was my understanding. |
Is this good to merge now? |
I think there are no outstanding issues to resolve. Should be ready for merge... |
Didn't you ever get to use a lathe in both wood working and/or metal shop? Great fun! https://en.wikipedia.org/wiki/Lathe?wprov=sfla1 |
The changes to |
Hmmm, maybe it would be better to understand first why the normals have |
Sorry, i hope this is more clear. I mean it like this... From x = normals[ i ]; // 0
y = normals[ i + 1 ]; // 0
z = normals[ i + 2 ]; // 0
n = 1.0 / Math.sqrt( x * x + y * y + z * z ); // n = Infinity
normals[ i ] *= n; // NaN
normals[ i + 1 ] *= n; // NaN
normals[ i + 2 ] *= n; // NaN The normal with zero values occurs, because pA.fromArray( positions, vA ); // zero vector
pB.fromArray( positions, vB ); // zero vector
pC.fromArray( positions, vC );
cb.subVectors( pC, pB );
ab.subVectors( pA, pB );
cb.cross( ab );
normals[ i ] = cb.x; // 0
normals[ i + 1 ] = cb.y; // 0
normals[ i + 2 ] = cb.z; // 0 |
Exactly. And since this was a user error, I do not think the check is needed. We assume the geometry is a valid one. |
So if I understand it correctly, it was a temporal error that is no longer there? |
No. If i remove the fix from If you set a breakpoint to I thought, we can avoid this problem by adding the mentioned fix. But if you think that the geometry isn't valid, we maybe need to adjust I used the following points array to produce the var points = [
new THREE.Vector2( 0, 0 ),
new THREE.Vector2( 4, 0 ),
new THREE.Vector2( 3.5, 0.5 ),
new THREE.Vector2( 1, 0.75 ),
new THREE.Vector2( 0.8, 1 ),
new THREE.Vector2( 0.8, 4 ),
new THREE.Vector2( 1, 4.2 ),
new THREE.Vector2( 1.4, 4.8 ),
new THREE.Vector2( 2, 5 ),
new THREE.Vector2( 2.5, 5.4 ),
new THREE.Vector2( 3, 12 )
]; The former version of |
This is caused by the problem I was concerned about above. You are creating degenerate triangles in the base. The cross-product will be problematic in that case. Try changing the first point and inspect the geometry in wireframe. var points = [
new THREE.Vector2( 1, 0 ), This modification will produce a hole in the bottom of the base of the goblet. In production, you could use var points = [
new THREE.Vector2( 0.001, 0 ), // avoid zero value in turned radius |
@WestLangley Yeah, this approach works. Ok, i will undo the commit, so there will be no changes to Besides, do you think there is a way to avoid the generation of degenerate triangles in |
This reverts commit 8d5203f.
The x-coordinate of each point must be greater than zero. Perhaps that should be noted in the docs. (Or allow zero, if you can figure out a way. Experiment with a cone shape.) It is unfortunate that the function is defined with the y-axis as the abscissa, and x-axis as the ordinate. I think it would be more natural to rotate around the x-axis -- as a lathe does, but it is probably not worth changing at this point. |
I see!
That's a good point! I will put this into the docu... |
Great! Thanks guys! |
This PR introduces
LatheBufferGeometry
. Here's the test fiddleBufferGeometry.normalizeNormals
to avoid NaN values with zero vectors. This is done in a separate commit..computeVertexNormals
. If the geometry is closed, the implementation ofLatheBufferGeometry
must manually merge some normals to avoid a faulty seam (see screenshot). Duplicated vertices (which are necessary because of their unique UV coordinates) are causing this effect. Does anyone know an alternative approach to generate the normals of the geometry?