Code archives/3D Graphics - Mesh/NormaliseNormals()

This code has been declared by its author to be Public Domain code.

Download source code

NormaliseNormals() by simonh
(Posted 24 years ago)
Normalises all normals on a particular mesh
Function NormaliseNormals(mesh)

	Local s
	
	For s=1 To CountSurfaces(mesh)
	
		surf=GetSurface(mesh,s)
	
		For v=0 To CountVertices(surf)-1
	
			nx#=VertexNX#(surf,v)
			ny#=VertexNY#(surf,v)
			nz#=VertexNZ#(surf,v)
			
			uv#=Sqr(nx#^2+ny#^2+nz#^2)
	
			nx#=nx#/uv#
			ny#=ny#/uv#
			nz#=nz#/uv#
		
			VertexNormal surf,v,nx#,ny#,nz#
	
		Next
	
	Next

End Function

Comments

Devils Child
(Posted 20 years ago)
how about "UpdateNormals(mesh)"?

Cygnus
(Posted 20 years ago)
Devil, That doesn't do the same as the above code.

UpdateNormals makes a surfaces normals point the way its triangle faces, the above code does not disturb the normals vector, but makes its length = 1.

Code Archives Forum