demos/plyreader.py
branchpyrit
changeset 69 303583d2fb97
parent 41 c1080cb5bd6d
child 75 20dee9819b17
equal deleted inserted replaced
68:2c154aad7f33 69:303583d2fb97
     1 # Stanford .ply file loader
     1 # Stanford .ply file loader
     2 
     2 
     3 from raytracer import Triangle, NormalVertex
     3 from raytracer import Triangle, NormalVertex
     4 
     4 
     5 def LoadStanfordPlyFile(rt, filename, mat, smooth, scale=(1,1,1), trans=(0,0,0)):
     5 def LoadStanfordPlyFile(rt, filename, mat, scale=(1,1,1), trans=(0,0,0)):
     6 	if (type(scale) == float or type(scale) == int):
     6 	if (type(scale) == float or type(scale) == int):
     7 		scale = (scale,)*3
     7 		scale = (scale,)*3
     8 	vertices = []
     8 	vertices = []
     9 	normals = []
     9 	normals = []
    10 	vertex_face_num = []
    10 	vertex_face_num = []
    42 		n = face.getNormal()
    42 		n = face.getNormal()
    43 		for x in tokens[1:4]:
    43 		for x in tokens[1:4]:
    44 			for i in range(3):
    44 			for i in range(3):
    45 				normals[int(x)][i] += n[i]
    45 				normals[int(x)][i] += n[i]
    46 			vertex_face_num[int(x)] += 1
    46 			vertex_face_num[int(x)] += 1
    47 		if (smooth):
       
    48 			face.setSmooth()
       
    49 		rt.addshape(face)
    47 		rt.addshape(face)
    50 		face_num -= 1
    48 		face_num -= 1
    51 
    49 
    52 	# interpolate normals at vertices
    50 	# interpolate normals at vertices
    53 	num = 0
    51 	num = 0