demos/lworeader.py
branchpyrit
changeset 72 7c3f38dff082
parent 69 303583d2fb97
child 75 20dee9819b17
equal deleted inserted replaced
71:4fedf7290929 72:7c3f38dff082
     1 # LightWave .lwo file loader
     1 # LightWave .lwo file loader
     2 
     2 
     3 from math import *
     3 from math import *
     4 from struct import *
     4 from struct import *
     5 from raytracer import Triangle, NormalVertex, Material
     5 from raytracer import Triangle, NormalVertex, Material
       
     6 from vector import dot
     6 
     7 
     7 def read_int4(f):
     8 def read_int4(f):
     8 	return unpack('>i', f.read(4))[0]
     9 	return unpack('>i', f.read(4))[0]
     9 
    10 
    10 def read_int2(f):
    11 def read_int2(f):
   150 		else:
   151 		else:
   151 			print "Warning: chunk", ID,"("+str(size),"B) ignored"
   152 			print "Warning: chunk", ID,"("+str(size),"B) ignored"
   152 			f.read(size)
   153 			f.read(size)
   153 		(ID,size) = read_chunk(f)
   154 		(ID,size) = read_chunk(f)
   154 	return (points, faces, tags, surfaces)
   155 	return (points, faces, tags, surfaces)
   155 
       
   156 def dot(a,b):
       
   157 	sum = 0
       
   158 	for i in range(min(len(a),len(b))):
       
   159 		sum += a[i]*b[i]
       
   160 	return sum
       
   161 
   156 
   162 def LoadLightwaveLwoFile(rt, filename, scale=(1,1,1), trans=(0,0,0)):
   157 def LoadLightwaveLwoFile(rt, filename, scale=(1,1,1), trans=(0,0,0)):
   163 	if (type(scale) == float or type(scale) == int):
   158 	if (type(scale) == float or type(scale) == int):
   164 		scale = (scale,)*3
   159 		scale = (scale,)*3
   165 	(points, faces, tags, surfaces) = read_lwo(filename)
   160 	(points, faces, tags, surfaces) = read_lwo(filename)