1

I try to apply a smooth shading to render my object in order to smooth (first image) my faceted shading (last image).

I compute my vertex normal by taking summing all neighboring triangles normal, then normalizing it. For certain area, it looks well but in others, the result is not correct.

For example, as the image below, arrounding the letter "R" (or other flat surface with big triangle) I got something weird.

Smoothed

Faceted

Valimo Ral
  • 381
  • 2
  • 15

1 Answers1

0

If you can open your model in Blender and apply an edge-split mosifier. , That can give good results. Also in THREE there is a geometry.computeFaceNormals() or geometry.computeVertexNormals() method. Check out the documentation for those... they may help.

manthrax
  • 4,918
  • 1
  • 17
  • 16
  • I cannot use any tool because I extract all my triangles from a CAD file and display them immediately. When I use computeVertexNormals() I got my faceted shading like the last image above. – Valimo Ral Jul 16 '19 at 09:57
  • Can you try calling geometry.computeFaceNormals(), then geometry.computeVertexNormals( true ) ? – manthrax Jul 16 '19 at 10:24
  • There is no correct "solution" to computing vertex normals since vertex normals are just an approximation. If you have smooth and flat parts of your model, some parts appearance will be sacrificed depending on whether you chose face or vertex normals. You'll either need to get further information from your CAD file.. like having it export normals, OR extract hard edge information from it somehow. The edge split modifier in blender, separates faces in the geometry based on an angle threshhold. You'll need some kind of equivalent operation. – manthrax Jul 16 '19 at 10:24
  • Calling geometry.computeFaceNormals(), then geometry.computeVertexNormals( true ) result like faceted rendering. – Valimo Ral Jul 16 '19 at 12:16
  • Your geometry is malformed. How are you loading/parsing your CAD file? What format is it? – manthrax Jul 16 '19 at 12:30
  • I read it from step file. I took all triangles vertices and give it to my BufferGeometry as triangles soup (No index). Then I compute my vertex normal and give it as a normal attribute to my buffer geometry.And when I open the original step file using any CAD viewer tool, theirs are smooth but mine are flat. That is why I have tried to compute vertex normal to have it smooth. – Valimo Ral Jul 16 '19 at 12:37
  • How are you determining which triangle edges are shared in your normal computation routine? – manthrax Jul 16 '19 at 14:16
  • This may be relevant/helpful: https://discourse.threejs.org/t/is-there-any-way-to-load-step-file-using-three-js/2842 – manthrax Jul 16 '19 at 14:20
  • For Step conversion into a mesh, I can't use other framework other than opencascade.With this, i can have my topology data structure. Later, I will check next my vertex normal if it is correct. Thanks for your replies. I will make an edit if I resolve this. – Valimo Ral Jul 16 '19 at 14:53