owl-project / NVISII

Apache License 2.0
319 stars 27 forks source link

Is there anyway to disable face normal computation vis interpolating vertex normals? #174

Closed zhouxian closed 2 months ago

zhouxian commented 2 months ago

For a simple mesh like a cube, face normal from interpolating vertex normal results in undesired effect

natevm commented 2 months ago

Mesh normals are defined in the mesh description, as part of the artist/author’s workflow. Eg in blender, you select edges and mark these as sharp, or mark faces to have smooth shading. Maya and other CAD softwares do something similar.

Perhaps you are importing a mesh whose normals weren’t modeled properly? The built-in cube mesh should be generating shading normals that produce sharp corners.

zhouxian commented 2 months ago

After looking into the built-in box, I realize that it has duplicated vertices at each corner, each using the correct face normal as the vertex normal, so the edge will stay sharp even with smooth shading. However, my input mesh is a box with only 8 vertex, which is causing problems. Is there anyway to disable such smooth shading inside nvisii? If not, is it the only thing i can do to manually duplicate each vertex for each face using them, so that they can store correct face normals? Or there's any smarter way?

Really appreciate your help!

natevm commented 2 months ago

You’ll need to duplicate them, yeah. A “vertex” is defined as a high dimensional value to be interpolated depending on the corresponding indices. This is meant to be general and robust. (OBJ formats define vertices this way too)

In your case, you aren’t duplicating the “vertices”, since vertices are more than just their position.

Rather, you are creating three distinct vertices at the corners of the cube, that yes all share the same positional values, but that have unique normal vectors and/or texture coordinates.

Hope that helps

zhouxian commented 2 months ago

Got it thanks!