Skip to main content

graphics3d - Polygon mesh: Compute vertex normals for smooth shading



MeshRegion has a "SmoothShading" PlotTheme which automatically computes the VertexNormals to create a nice smooth rendering. For example:


reg = BoundaryDiscretizeRegion[Ball[], PlotTheme -> "SmoothShading", 
PrecisionGoal -> 1, MaxCellMeasure -> 0.1]

discretized ball with vertex normals


Suppose that the only data I have available is this:


gr = GraphicsComplex[MeshCoordinates[reg], MeshCells[reg, 2]];

It looks like this:


Graphics3D[{EdgeForm[None], gr}]


discretized ball


Is there built-in functionality which will compute the vertex normals for a mesh like this?


I know that I can make a MeshRegion called reg, set "SmoothShading" on it, convert to Graphics3D using Show, then extract the options from the contained GraphicsComplex: Cases[Show[reg], GraphicsComplex[_, _, opt___] :> opt, Infinity]. But this is a hack and probably unreliable. What I am looking for is a built-in and easy way to return the vertex normals in a structured form. I am hoping that this functionality is exposed, I just didn't find it yet.




Comments