######################################################### # # # Image Based Lighting for Blender # # # # lightgen2blender v1.1 # # # # by # # # # Kurppa # # # # 2003 # # # # http://members.lycos.co.uk/kurppa/blender/index.html # # # # # # # # needed to work: # # -HDR Shop (http://athens.ict.usc.edu/HDRShop/) # # -lightgen plugin for HDR Shop (same site) # # -a hdr light probe (http://www.debevec.org/Probes/) # # -Python 2.3 (only tested version) # # -Blender :) # # # # before blending: # # -make a textfile of your hdr image with lightgen # # (tutorial found in HDR Shop site) # # hint: number of lightsources = as many as you # # think you can handle :) # # (around 300 is already cool) # # # # usage: # # -clear layer 1 from any other things (otherwise you # # will have a hell of a time selecting anything from # # under 300+ lights..) # # -start script with ALT-P # # -select the text file you just created # # -make necessary changes to values # # -click CREATE --> and there were lights! # # -create an empty in the center # # -hit AKEY twice to select lamps with empty as active # # -CTRL-T to track # # -and here we are! # # # # adjusting the lights: # # -you can modify the lamps as a group by changing the # # parameters in the number buttons and then APPLY # # # # the parameters: # # __Create__ - only work when you create the lamps # # -filename: textfile from lightgen # # -radius: the radius of the generated light sphere # # -limit: the min energy for lamp for it to be created# # __Adjust__ - work with create and apply # # -bright: adjusts the brightnes (works additively: # # apply "Bright: 2.0" 5 times to get 10 times # # brighter illumination) # # -the rest are the standard things found in the # # Blender lamp buttons # # # ######################################################### from Blender import * sce = Scene.GetCurrent() radius = Draw.Create(20.0) bright = Draw.Create(1.0) clipsta = Draw.Create(10.0) clipend = Draw.Create(30.0) samples = Draw.Create(5) soft = Draw.Create(5.0) buffer = Draw.Create(512) limit = Draw.Create(0.01) type = Draw.Create(2) spotsi = Draw.Create(45.0) spotbl = Draw.Create(0.15) created_lamps = 0 total_lamps = 0 created = 0 filename = Draw.Create("C:/Documents and Settings/janne/My Documents/My Pictures/panoramas/room12.txt") def make_lights(): global filename, sce, radius, bright, clipsta, clipend, samples, soft, buffer, created_lamps, total_lamps, created, limit, type, spotsi, spotbi created = 1 created_lamps = 0 total_lamps = 0 skip = 0 file = open(filename.val, 'r') # print "Limit: " + str(limit) ltype = "Spot" if type.val == 2: ltype = "Spot" elif type.val == 1: ltype = "Lamp" elif type.val == 3: ltype = "Sun" elif type.val == 4: ltype = "Hemi" for line in file: # print line if line == "\n": continue elif line[0:5] == "Light": name = "" total_lamps = total_lamps + 1 name = line.rstrip(":\n") name = "IBL_" + name elif line[0:5] == "Color": cols = line.split() # print name + " " + str(cols) colf = (float(cols[1]),float(cols[2]),float(cols[3])) nrg = max(colf[0],colf[1],colf[2]) if nrg * bright.val < limit.val: skip = 1 continue elif line[0:9] == "Direction": if skip: skip = 0 continue l = Lamp.New(ltype,name) l.col = (colf[0]/nrg,colf[1]/nrg,colf[2]/nrg) nrg = nrg * bright.val l.setEnergy(nrg) l.setClipStart(clipsta.val) l.setClipEnd(clipend.val) l.setSamples(samples.val) l.setSoftness(soft.val) l.setBufferSize(buffer.val) l.setSpotSize(spotsi.val) l.setSpotBlend(spotbl.val) ob = Object.New('Lamp',name) ob.name = name loc = line.split() ob.LocX = radius.val*float(loc[1]) ob.LocY = radius.val*float(loc[2]) ob.LocZ = radius.val*float(loc[3]) created_lamps = created_lamps + 1 ob.link(l) sce.link(ob) file.close() def apply_lights(): global radius, bright, clipsta, clipend, samples, soft, buffer, spotsi, spotbl, type ltype = "Spot" if type.val == 2: ltype = "Spot" elif type.val == 1: ltype = "Lamp" elif type.val == 3: ltype = "Sun" elif type.val == 4: ltype = "Hemi" lamplist = Lamp.Get() for l in lamplist: if l.name[0:9] != "IBL_Light": continue l.setEnergy(l.getEnergy()*bright.val) l.setClipStart(clipsta.val) l.setClipEnd(clipend.val) l.setSamples(samples.val) l.setSoftness(soft.val) l.setBufferSize(buffer.val) l.setType(ltype) l.setSpotSize(spotsi.val) l.setSpotBlend(spotbl.val) bright.val = 1.0 def delete_lights(): global created created = 0 oblist = Object.Get() for o in oblist: if o.name[0:9] != "IBL_Light": continue sce.unlink(o) #----------GUI STUFF----------------------------- def gui(): #da gui global filename, filename, radius, bright, clipsta, clipend, samples, soft, buffer, created_lamps, total_lamps, created, limit, type, spotsi, spotbl BGL.glClearColor(0.6,0.6,0.6,1) BGL.glClear(BGL.GL_COLOR_BUFFER_BIT) BGL.glColor3f(1,1,1) Draw.Button("Create IBL",1,10,20,100,20) Draw.Button("Apply",2,120,20,100,20) Draw.Button("Delete IBL",6,230,20,100,20) Draw.Button("Exit",3,340,20,100,20) BGL.glRasterPos2i(10,205) Draw.Text("Filename:") filename = Draw.String("",4,70,200,430,20,filename.val,200) radius = Draw.Number("Radius:",101,70,170,100,20,radius.val,1,5000) limit = Draw.Number("Limit:",101,180,170,100,20,limit.val,0.000,1.000) bright = Draw.Number("Bright:",100,10,90,100,20,bright.val,0.0,100.0) clipsta = Draw.Number("ClipSta:",100,120,90,100,20,clipsta.val,0.1,1000.0) clipend = Draw.Number("ClipEnd:",100,230,90,100,20,clipend.val,1.0,5000.0) samples = Draw.Number("Samples:",100,10,60,100,20,samples.val,1,16) soft = Draw.Number("Soft:",100,120,60,100,20,soft.val,1.0,100.0) buffer = Draw.Number("BufSize:",100,230,60,100,20,buffer.val,512,5120) type = Draw.Menu("Type%t|Lamp%x1|Spot%x2|Sun%x3|Hemi",100,10,120,100,20,type.val) spotsi = Draw.Slider("SpotSi", 100, 340, 90, 150, 20, spotsi.val,1.0,180.0) spotbl = Draw.Slider("SpotBl", 100, 340, 60, 150, 20, spotbl.val,0.0,1.0) BGL.glRasterPos2i(20,280) Draw.Text("Image Based Lighting for Blender") BGL.glRasterPos2i(20,260) Draw.Text("lightgen2Blender v1.0 - by Kurppa - 2003") BGL.glColor3f(1,0,0) BGL.glRasterPos2i(10,230) Draw.Text("1.Create----------------------------------------------------------") BGL.glRasterPos2i(10,150) Draw.Text("2.Adjust----------------------------------------------------------") BGL.glRasterPos2i(10,50) Draw.Text("---------------------------------------------------------------") if created: lights = "Created " + str(created_lamps) + "/" + str(total_lamps) + " lamps." BGL.glColor3f(0,0,0) BGL.glRasterPos2i(290,175) Draw.Text(lights) # def event(evt, val): #key & mouse events if evt == Draw.ESCKEY: Draw.Exit() return else: return Draw.Register(gui, event, but_event) # def but_event(evt): #button events if evt == 1: make_lights() Draw.Draw() if evt == 2: apply_lights() Draw.Draw() if evt == 6: delete_lights() Draw.Draw() if evt == 3: Draw.Exit() return else: Draw.Register(gui, event, but_event) # Draw.Register(gui, event, but_event)