IES lights possible?

Sorry, have spent the weekend battling with matrix multiplication on graphics cards. Still am really.

Pushy? No! I said I’d do this in april, asking politely months later is not sounding pushy :smiley:

edit - have switch vim buffers, will post results later today

edit (tadaa)
Version 0.0.0.1 (alpha)
Largely wrong. I’m not sure about the matrix stuff at the bottom or the edges, but they were hastily done. Doesn’t care about symmetry, or do any interpolation. Really is just a reader atm :slight_smile:

The file should read in and give you a 2d array (called data) which you can use.

Oh, I had to edit the files posted here, as they needed some things on single lines. The parser complies with the specs posted and linked to, but the files are slightly different.


from Blender import *
import bpy
from Blender import Mathutils
from Blender.Mathutils import *

class IESData:
	def __init__(self,filename=""):
		self.data=[]
		self.vertAngles=[]
		self.horizAngles=[]
		self.numVertAngles=0
		self.numHorizAngles=0
		self.multiplier=0
		self.ratedLumens=-1
		if (filename):
			self.read(filename)

	def read(self,filename):
		f=open(filename,'r')
		# Ugly, but it's the quickest way I know...
		s=f.readline().replace("
","").replace("\r","")
		while (s[0]!="1" and s!=""):
			s=f.readline().replace("
","").replace("\r","")

		s=f.readline().replace("
","").replace("\r","")
		self.ratedLumens = float(s)

		s=f.readline().replace("
","").replace("\r","")
		self.multiplier = float(s)

		s=f.readline().replace("
","").replace("\r","")
		self.numVertAngles = int(s)
		s=f.readline().replace("
","").replace("\r","")
		self.numHorizAngles = int(s)
	

		# always 1
		s=f.readline()
		#luminous opening
		s=f.readline()
		#luminous opening dimensions
		s=f.readline()
		#1 1 0
		s=f.readline()

		#Keep reading angles until have enough
		while (len(self.vertAngles)<self.numVertAngles):
			s=f.readline().replace("
","").replace("\r","")
			angles=s.split(" ")
			for angle in angles:
				self.vertAngles.append(float(angle))	

		while (len(self.horizAngles)<self.numHorizAngles):
			s=f.readline().replace("
","").replace("\r","")
			angles=s.split(" ")
			for angle in angles:
				self.horizAngles.append(float(angle))
				self.data.append([])
				for i in range(self.numVertAngles):
					self.data[-1].append(0.)
		print self.numHorizAngles
		count=0
		while (s!=""):
			s=f.readline().replace("
","").replace("\r","")
			values=s.split(" ")
			for intensity in values[:-1]:
				self.data[count%self.numHorizAngles][count/self.numHorizAngles]=float(intensity)
				count+=1
		


def convertToMesh(iesClass):
	verts=[]
	edges=[]
	for i, xAngle in enumerate(iesClass.horizAngles):
		matX=RotationMatrix(xAngle,4,'z')
		for j, yAngle in enumerate(iesClass.vertAngles):
			matY=RotationMatrix(yAngle,4,'y')
			#matT=TranslationMatrix(Vector([0.,1.,0.]))
			matT=TranslationMatrix(Vector([iesClass.data[i][j]/100.,0,0.]))
			matTotal=matT*matX*matY
			verts.append(Vector(0.,0.,0.)*matTotal)
			if i<(iesClass.numHorizAngles-1):
				edges.append([i*iesClass.numVertAngles + j, (i+1)*iesClass.numVertAngles + j])
	return [verts,edges]
						

			

infile = "/home/ian/IES/testsymmet.ies"

iesExample=IESData(infile)

verts,edges=convertToMesh(iesExample)

me = bpy.data.meshes.new('iesWeb') 
me.verts.extend(verts)
me.edges.extend(edges)
scn = bpy.data.scenes.active
ob = scn.objects.new(me, 'myObj')