Code Vonc

Calcul des normales

CommentairesComments


Normale d'un polygone


Calcul de la normale N d'un polygone :


def CalculeNormalesPolys(obj) :
	
	polys = obj.GetAllPolygons()
	pts = obj.GetAllPoints()
	nbPolys = obj.GetPolygonCount()
	
	norPolys = [Vector()] * nbPolys
	
	for i, poly in enumerate(polys) :
		
		normale = (pts[poly.a] - pts[poly.c]).Cross(pts[poly.b] - pts[poly.d])
		normale.Normalize()
		
		norPolys[i] = normale
	
	return norPolys



Normale d'un sommet


Calcul de la normale NP du sommet adjacent aux polygones 1, 2, 3 et 4, ayant respectivement les normales N1, N2, N3 et N4 :


NP = (N1 + N2 + N3 + N4).GetNormalized()


Calcul de la normale des sommets :


def CalculeNormalesPoints(obj) :
	
	polys = obj.GetAllPolygons()
	pts = obj.GetAllPoints()
	nbPoints = obj.GetPointCount()
	
	norPts = [Vector()] * nbPoints
	
	for i, poly in enumerate(polys) :
		
		normale = (pts[poly.a] - pts[poly.c]).Cross(pts[poly.b] - pts[poly.d])
		normale.Normalize()
		
		norPts[poly.a] += normale
		norPts[poly.b] += normale
		norPts[poly.c] += normale
		if (poly.c != poly.d) : norPts[poly.d] += normale
	
	for i in xrange(nbPoints) :
		norPts[i].Normalize()
	
	return norPts