question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

geometry.computeVertexNormals() not working for extruded geometry

See original GitHub issue
Description of the problem

geometry.computeVertexNormals() not working for extruded geometry created using absarc.

Best explained with pictures and fiddle.

image

image

https://jsfiddle.net/k2r4cqnh/2/

I have also tried geometry.computeFaceNormals and shading: SmoothShading but no dice!

You get the same problem with the shape with/without a hole.

Three.js version
  • r81
Browser
  • All of them
OS
  • Windows

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:22 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
henryJackcommented, Oct 18, 2016

@WestLangley - I agree that we shouldn’t modify geometry.computeVertexNormals() directly but there should be a THREE method to achieve smoothing the faces of an extruded shape without artefacts. I am now using a smoothExtrudedGeometry() function based on the discussion in this thread. A nice example of this is the elimination of some bezier scaring on some 3D extruded helical gears. See before and after below…

before smoothExtrudedGeometry() image

after smoothExtrudedGeometry() image

three.js is a rendering engine, not a modeling tool. I think the best solution is for you to develop your model using modeling software, and import it into three.js.

I think the above image of gears shows that THREE.js can be a fantastic direct modelling tool. Given the many parameters used to describe certain geometries (such as gear teeth) it would not be practical to develop templates of such models if you want to dynamically change their attributes based on some user input. Or have I misunderstood something about THREE.js?

3reactions
zz85commented, Oct 17, 2016

@henryJack if you add after geometry.computeVertexNormals();

for ( var i = 0; i < geometry.faces.length; i ++ ) {
    var face = geometry.faces[ i ];
    if (face.materialIndex == 1 ) {
        for ( var j = 0; j < face.vertexNormals.length; j ++ ) {
            face.vertexNormals[ j ].z = 0;
            face.vertexNormals[ j ].normalize();
        }
    }
}

you will see that the ring is smooth. I can’t remember how to make the sides flat though…

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Any better implementation of ExtrudeGeometry? - three.js forum
It all works fine until you want to achieve smooth shading, where using geometry.computeVertexNormals(true) then fails for the obvious reason ...
Read more >
THREE.ExtrudeBufferGeometry has very few polygons
computeVertexNormals() geometry.center() return geometry. I create a geometry and create a 3d mesh out of it. The problem is that the ...
Read more >
Three.js Custom Geometry
computeVertexNormals ();. Unfortunately a cube is not a good candidate for vertex normals since it means each vertex gets its normal from the...
Read more >
Introduction to Computer Graphics, Section 5.2
The computeVertexNormals() method can still be used for a BufferedGeometry that has an index array. To compute a normal vector for a vertex,...
Read more >
Compute Vertex Normals for Buffer Geometry in threejs
In some cases I might have to work this out manually it would seem, however in most cases just calling the compute vertex...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found