#!BPY """ Name: 'Radiance' Blender: 228 Group: 'Export' Tip: 'Export Radiance for Blender 2.27.' """ ########################## # (c) Jan Walter 1999 # # Modified by # # Jacob (ray_theway) # # # # Radiance Export Script # # For Blender 2.27 # ########################## import Blender from math import cos,sin,acos,sqrt,pi import os from Blender import BGL, Draw from Blender.BGL import * from Blender.Draw import * # Enter below the file name of your # base .rad file and .vf file. # I suggest using the same names. -JG fileroot = Create("") # Now, enter the path to store GUI # settings file. This path is also # used for the export path (which can be # further changed in the GUI itself). # Don't include a slash at the end. path = "E:\\Blender\\RADex" meshlist = [] meshnum = 0 exppath = path finpath = exppath exportwin = Create(1) ior = Create(1.52) spec = Create(0.5) rough = Create(0.1) skylight = Create(0) ambient = Create(0) lightR = Create(1.00) lightG = Create(1.00) lightB = Create(1.00) ambbounce = Create(0) ambaccur = Create(0.2) ambres = Create(32) ambdiv = Create(32) ambssam = Create(32) ambval = Create(0.5) exportsky = Create(0) skytype = Create(1) xsize = Create(640) ysize = Create(480) falsecolor = Create(0) glare = Create(0) fscale = Create(1000) mult = Create(179) label = Create("Nits") irrad = Create(0) radpath = "D:\\Radiance\\bin" hdrprobe = "uffizi_probe.hdr" hdr = 0 def loadsettings(): global exppath, hdrprobe global skylight, ambient, lightR, lightG, lightB, ior, ambbounce global ambval, ambres, ambaccur, ambdiv, ambssam, exportsky, skytype global xsize, ysize, fileroot, exppath, falsecolor, glare, fscale global mult, label, irrad, radpath, hdr try: settings = open(os.path.join(exppath, "gui.settings"), 'r') except: settings = 0 print "settings not used" if settings != 0: variables = [] n = 0 for line in settings.readlines(): variables.append(line[:-len("\n")]) try: skylight = Create(variables[0]) ambient = Create(variables[1]) lightR = Create(variables[2]) lightG = Create(variables[3]) lightB = Create(variables[4]) ior = Create(variables[5]) ambbounce = Create(variables[6]) ambval = Create(variables[7]) ambres = Create(variables[8]) ambaccur = Create(variables[9]) ambdiv = Create(variables[10]) ambssam = Create(variables[11]) exportsky = Create(variables[12]) skytype = Create(variables[13]) xsize = Create(variables[14]) ysize = Create(variables[15]) fileroot = Create(variables[16]) exppath = variables[17] falsecolor = Create(variables[18]) glare = Create(variables[19]) fscale = Create(variables[20]) mult = Create(variables[21]) label = Create(variables[22]) irrad = Create(variables[23]) radpath = variables[24] hdrprobe = variables[25] hdr = variables[26] exportsky = skylight print "settings loaded" except: print "settings not used" loadsettings() line = "" matname = "" matnme = "" matstyle = "" material = "" ########################################################### ### The following code is from the vecf.py Vector ### ### Function module written by theeth (Martin Poirier) ### ### and eeshlo (Alfredo de Greef). It is used with ### ### permission. ### def MtxIdentity3x3(): return [[ 1.0, 0.0, 0.0], [ 0.0, 1.0, 0.0], [ 0.0, 0.0, 1.0]] def mulmat(m1, m2, d): r = MtxIdentity3x3() #just for initialisation for i in range(d): for j in range(d): rij = 0.0 for k in range(d): rij += m1[i][k] * m2[k][j] r[i][j] = rij return r def mulmatvec3x3(m, v): r = ZeroVector() r[0] = v[0]*m[0][0] + v[1]*m[1][0] + v[2]*m[2][0] r[1] = v[0]*m[0][1] + v[1]*m[1][1] + v[2]*m[2][1] r[2] = v[0]*m[0][2] + v[1]*m[1][2] + v[2]*m[2][2] return r ### End of theeth/eeshlo's code ### ########################################################### def writeCamera(obj): global fileroot, exppath, xsize, ysize vffile1 = (fileroot.val + ".vf") camfile = open(os.path.join(exppath, vffile1), "w") mat = obj.getInverseMatrix() matx = MtxIdentity3x3() cosx = cos(obj.RotX) sinx = sin(obj.RotX) matx[0] = [1, 0, 0] matx[1] = [0, cosx, -sinx] matx[2] = [0, sinx, cosx] maty = MtxIdentity3x3() cosy = cos(obj.RotY) siny = sin(obj.RotY) maty[0] = [cosy, 0, siny] maty[1] = [0, 1, 0] maty[2] = [-siny, 0, cosy] matz = MtxIdentity3x3() cosz = cos(obj.RotZ) sinz = sin(obj.RotZ) matz[0] = [cosz, -sinz, 0] matz[1] = [sinz, cosz, 0] matz[2] = [0, 0, 1] mat = mulmat(mulmat(matz, maty, 3), matx, 3) yvec = [0, 1, 0] vu = [mat[0][1], mat[1][1], mat[2][1]] zvec = [0, 0, -1] vd = [-1 * mat[0][2], -1 * mat[1][2], -1 * mat[2][2]] cam = Blender.Camera.get("Camera") lens = cam.Lens factor = sqrt(lens * lens + 16 * 16) angle1 = 2 * (180 * acos(lens / factor) / pi) angle2 = (ysize.val * angle1) / xsize.val camfile.write("rview -vp %s %s %s " % (obj.LocX, obj.LocY, obj.LocZ) + "-vd %f %f %f " % (vd[0], vd[1], vd[2]) + "-vu %f %f %f " % (vu[0], vu[1], vu[2]) + "-vh %s -vv %s" % (angle1, angle2)) camfile.close() def writeIdentifier(file, name): file.write("#" * (len(name) + 4) + "\n") file.write("# %s #\n" % name) file.write("#" * (len(name) + 4) + "\n") def writeMatrix(file, obj): # no scaling file.write("\t| xform -rx %s -ry %s -rz %s\\\n" % (180 * obj.RotX / pi, 180 * obj.RotY / pi, 180 * obj.RotZ / pi)) file.write("\t| xform -t %s %s %s\n" % (obj.LocX, obj.LocY, obj.LocZ)) def writeTexture(file, mat, name): file.write("void plastic %s\n" % name) file.write("0\n") file.write("0\n") if mat: file.write("5 %s %s %s %s %s\n" % (mat.R, mat.G, mat.B, 0.1, 0.15)) else: file.write("5 %s %s %s %s %s\n" % (1, 1, 1, 0.1, 0.15)) def export(): r(1) global exppath, meshnum, matstyle, fileroot, skylight global lightR, lightG, lightB, skytype, objs, skytype1 radfile2 = (fileroot.val + ".rad") radfile = (os.path.join(exppath, radfile2)) file = open(radfile, 'w') objs = Blender.Object.get() # first the camera cams = Blender.Object.get("Camera") # all materials file.write("# =============\n") file.write("# = Materials =\n") file.write("# =============\n") for obj in objs: name = obj.getData() if obj.getType() == "Lamp": name = obj.name lamp = obj.getData() writeIdentifier(file, name) file.write("void light %s\n" % name) file.write("0\n") file.write("0\n") file.write("3 %s %s %s\n" % (lamp.energy * lamp.R * 50, lamp.energy * lamp.G * 50, lamp.energy * lamp.B * 50)) for mode in lamp.getMode(): if mode == "halo": file.write("void illum %s\n" % (name + "_illum")) file.write("1 %s\n" % name) file.write("0\n") file.write("3 %s %s %s\n" % (lamp.energy * 50 * lamp.R, lamp.energy * 50 * lamp.G, lamp.energy * 50 * lamp.B)) elif obj.getType() == "Camera": writeCamera(obj) else: name = obj.name try: mat = obj.getData().getMaterials()[0] matname = obj.getData().getMaterials()[0].name mat_id = matname[-5:] except IndexError: mat_id = "" mat = Blender.Material.New() if mat_id == "_DIEL": writeIdentifier(file,name) file.write("void dielectric %s\n" % name) file.write("0\n0\n") file.write("5 %s %s %s %s 0\n" % (mat.R, mat.G, mat.B, (mat.spec * 2))) matstyle = Create("Dielectric") elif mat_id == "_METL": writeIdentifier(file,name) file.write("void metal %s\n" % name) file.write("0\n0\n") file.write("5 %s %s %s .9 .1\n" % (mat.R, mat.G, mat.B)) matstyle = Create("Metal") elif mat_id == "_PANE": writeIdentifier(file,name) file.write("void glass %s\n" % name) file.write("0\n0\n") file.write("3 %s %s %s\n" % (mat.R, mat.G, mat.B)) matstyle = Create("Glass Pane") elif mat_id == "_TRAN": writeIdentifier(file,name) file.write("void trans %s\n" % name) file.write("0\n0\n") file.write("7 %s %s %s %s %s %s %s" % (mat.R, mat.G, mat.B, mat.spec, mat.hard, mat.alpha, mat.sptr)) matstyle = Create("Translucent") else: writeIdentifier(file, name) writeTexture(file, mat, name) matstyle = Create("Plastic") # all lights file.write("# ==========\n") file.write("# = Lights =\n") file.write("# ==========\n") if skylight.val != 0: if skytype.val != 7: if skytype.val == 1: skytype1 = "+s" elif skytype.val == 2: skytype1 = "-s" elif skytype.val == 3: skytype1 = "-c" elif skytype.val == 4: skytype1 = "+i" elif skytype.val == 5: skytype1 = "-i" elif skytype.val == 6: skytype1 = "-u" else: pass skyname = "Sky" writeIdentifier(file, skyname) file.write("!gensky 4 25 11 %s\n\n" % skytype1) file.write("skyfunc glow skyglow\n") file.write("0\n0\n\n") file.write("4 %s %s %s 0\n\n" % (lightR.val, lightG.val, lightB.val)) file.write("skyglow source sky\n") file.write("0\n0\n") file.write("4 0.5 0.5 1 180\n\n") print ("Sky") elif skytype.val == 7: skyname = "HDRIBL" writeIdentifier(file, skyname) file.write("void colorpict HDRIBL\n") file.write("7 red green blue %s angmap.cal sb_u sb_v\n" % hdrprobe) file.write("0\n0\n\n") file.write("HDRIBL glow HDRGLOW\n") file.write("0\n0\n4 1 1 1 0\n\n") file.write("!genbox HDRGLOW boxenv 50 50 50 -i|xform -t -25 -25 -25\n") print ("HDRIBL Box") name = obj.name for obj in objs: if obj.getType() == "Lamp": for mode in lamp.getMode(): if mode == "square": writeIdentifier(file, lamp.name) file.write("%s polygon fixture\n" % lamp.name) file.write("0\n") file.write("0\n") file.write("12 %s %s %s\n" % ((obj.LocX - 1), (obj.LocY * -1 + 1), obj.getLocation()[2])) file.write("\t%s %s %s\n" % ((obj.LocX + 1), (obj.LocY * -1 + 1), obj.getLocation()[2])) file.write("\t%s %s %s\n" % ((obj.LocX + 1), (obj.LocY * -1 - 1), obj.getLocation()[2])) file.write("\t%s %s %s\n" % ((obj.LocX - 1), (obj.LocY * -1 - 1), obj.getLocation()[2])) print (lamp.name + " - Area") break else: writeIdentifier(file, lamp.name) file.write("%s sphere fixture\n" % lamp.name) file.write("0\n") file.write("0\n") file.write("4 %s %s %s %s\n" % (obj.LocX, obj.LocY, obj.LocZ, 0.125)) print (lamp.name + " - Fixture") # rest of scene file.write("# ============\n") file.write("# = Geometry =\n") file.write("# ============\n") for obj in objs: name = obj.name mesh = Blender.NMesh.GetRaw(obj.name) name = obj.name objsize = ((obj.size[0] + obj.size[1] + obj.size[2]) / 8) smooth = 0 name = obj.name objismesh = obj.getType() if obj.getType() == "Mesh": mesh = Blender.NMesh.GetRawFromObject(obj.name) index = 0 writeIdentifier(file, name) planef = open(os.path.join(exppath, (name + ".rad")), "w") newme = Blender.NMesh.GetRaw() for face in mesh.faces: numv = len(face.v) if numv == 3: nf = Blender.NMesh.Face() nf.v.append(face.v[0]) nf.v.append(face.v[1]) nf.v.append(face.v[2]) newme.faces.append(nf) elif numv == 4: nf = Blender.NMesh.Face() nf.v.append(face.v[0]) nf.v.append(face.v[1]) nf.v.append(face.v[2]) newme.faces.append(nf) nf = Blender.NMesh.Face() nf.v.append(face.v[2]) nf.v.append(face.v[3]) nf.v.append(face.v[0]) newme.faces.append(nf) if face.smooth == 1: smooth = 1 tmfile = open(os.path.join(exppath, (obj.name + ".tmesh")), 'w') tmfile.write("o %s\n" % obj.name) for face in newme.faces: it = 0 tmfile.write("m %s " % obj.name) for vert in face.v: it += 1 tmfile.write("v %s %s %s %s" % (it, vert.co[0], vert.co[1], vert.co[2])) tmfile.write("\tn %s %s %s\n" % (vert.no[0], vert.no[1], vert.no[2])) tmfile.write("t %s %s %s\n" % (1, 2, 3)) print (name + " - Polyhedron") file.write("!tmesh2rad -o %s -m %s %s.tmesh|" % (obj.name, obj.name, obj.name)) size = (obj.size[0] + obj.size[1] + obj.size[2]) / 3 file.write("xform -rx %s -ry %s -rz %s -s %6f -t %6f %6f %6f\n" % ((180 * obj.RotX / pi), (180 * obj.RotY / pi), (180 * obj.RotZ / pi), size, obj.LocX, obj.LocY, obj.LocZ)) meshlist.append(name) meshnum = meshnum + 1 file.close() print "Finished!" def showshader(matname, mat_id): global matnme, matstyle, printmat if mat_id == "_DIEL": matstyle = "Dielectric" elif mat_id == "_GLAS": matstyle = "Dielectric" elif mat_id == "_METL": matstyle = "Metal" elif mat_id == "_PANE": matstyle = "Glass Pane" elif mat_id == "_TRAN": matstyle = "Translucent" else: matstyle = "Plastic" printmat = 1 matnme = matname printmat = 0 def setiortocur(matname, ior): global material var = (matname + ".ior") object = Blender.Object.getSelected() print object data = object.getData() material = data.getMaterials()[0] material.spec = ior / 2 def gui(): global exppath, exppath1, fileroot, matnme, matstyle, printmat, ior, spec, rough, material, ambient, skylight global lightR, lightG, lightB, skytype, xsize, ysize, falsecolor, glare, fscale, irrad, mult, label global ambbounce, ambaccur, ambres, ambdiv, ambssam, ambval, radpath, hdr, hdrprobe, hdrprobe1, skytype1 glClearColor(0.5, 0.5, 0.5, 1) glClear(GL_COLOR_BUFFER_BIT) glColor3f(1, 1, 1) glRasterPos2i(75, 360) Text("RADIANCE Export - by Jan Walter") glRasterPos2i(75, 340) Text("Modifications and GUI by ray_theway (Jacob)") glColor3f(0, 0, 0) glRasterPos2i(76, 359) Text("RADIANCE Export - by Jan Walter") if exportwin.val == 1: glRecti(0, 500, 380, 440) Button("Export Window", 10, 25, 450, 150, 20, "Show Export Window") Button("Shader Window", 20, 200, 450, 150, 20, "Show Shader Window") radpath1 = Create(radpath) radpath1 = String("RADIANCE Binary Path: ", 7, 25, 300, 350, 20, radpath1.val, 80, "Path to RADIANCE binaries") radpath = os.path.abspath(radpath1.val) Button("Export", 1, 25, 280, 150, 20, "Export to RADIANCE") exppath1 = Create(exppath) exppath1 = String("Export Path: ", 2, 175, 280, 200, 20, exppath1.val, 40, "Where to save *.rad and *.vf files") exppath = os.path.abspath(exppath1.val) fileroot = String("File Name: ", 3, 175, 260, 200, 20, fileroot.val, 40, "Base file name for exported files") Button("Export Rif File", 4, 25, 260, 150, 20, "Export rif file for compiling octree") glRasterPos2i(25, 240) Text("Press ``Export'' BEFORE ``Export Batch File.''") glRasterPos2i(25, 220) Text("Make sure ``Export Path'' already exists, and make sure there") glRasterPos2i(50, 200) Text("is no `/' after the path.") glRasterPos2i(25, 180) Text("Do not add an extension to ``File Name.''") glRasterPos2i(25, 160) Text("Finally, if you exported a rif file, simply run it") glRasterPos2i(50, 140) Text("at a terminal or prompt with ``rad filename.rif''.") Button("Preview", 5, 25, 90, 150, 20, "Render preview in RVIEW") Button("Render", 6, 175, 90, 150, 20, "Render picture in RPICT") Button("Material Guide", 80, 110, 400, 150, 20) Button("Global Settings", 30, 225, 380, 150, 20) Button("Special Effects", 60, 25, 380, 150, 20) xsize = Number("X Res: ", 7, 25, 110, 150, 20, int(xsize.val), 0, 2048) ysize = Number("Y Res: ", 7, 175, 110, 150, 20, int(ysize.val), 0, 2048) #glColor3f(1, 1, 1) glRasterPos2i(25, 75) Text("Picture will be rendered at %s x %s and resized to %s x %s." % (xsize.val * 2, ysize.val * 2, xsize.val, ysize.val) ) elif exportwin.val == 80: glClearColor(0.5, 0.5, 0.5, 1) glClear(GL_COLOR_BUFFER_BIT) glRecti(0, 500, 380, 440) Button("Export Window", 10, 25, 450, 150, 20, "Show Export Window") Button("Shader Window", 20, 200, 450, 150, 20, "Show Shader Window") Button("Plastic", 81, 25, 400, 150, 20) Button("Glass Pane", 82, 25, 380, 150, 20) Button("Dielectric", 83, 25, 360, 150, 20) Button("Metal", 84, 25, 340, 150, 20) Button("Translucent", 85, 25, 320, 150, 20) if printmat == 1: glColor3f(1, 1, 1) glRasterPos2i(25, 380) Text("%s - %s Material" % (matnme, matstyle)) if matstyle == "Dielectric": glRasterPos2i(200, 340) Text("DIELECTRIC MATERIAL") glRasterPos2i(25, 300) Text("In RADIANCE, the Dielectric material is similar to the glass material") glRasterPos2i(25, 280) Text("in most other raytracers. It takes four arguments - red, green, and") glRasterPos2i(25, 260) Text("blue (which are determined by the Blender material color) and IOR.") glRasterPos2i(25, 240) Text("Append ``_DIEL'' to the material name to use this material.") elif matstyle == "Glass Pane": glRasterPos2i(200, 340) Text("GLASS PANE MATERIAL") glRasterPos2i(25, 300) Text("The glass material has a more specific function in RADIANCE than") glRasterPos2i(25, 280) Text("most renderers. I have called this material glass pane, because") glRasterPos2i(25, 260) Text("the IOR is preset to 1.52 (the IOR of glass). Color is determined") glRasterPos2i(25, 240) Text("by Blender material settings.") glRasterPos2i(25, 220) Text("Append ``_PANE'' to the material name to use this material.") elif matstyle == "Metal": glRasterPos2i(200, 340) Text("METAL MATERIAL") glRasterPos2i(25, 300) Text("This material is a typical metal material. It uses the colors from") glRasterPos2i(25, 280) Text("Blender's material settings, as well as the specular and roughness") glRasterPos2i(25, 260) Text("(roughness is hardness in the Blender window).") glRasterPos2i(25, 240) Text("Append ``_METL'' to the material name to use this material.") elif matstyle == "Translucent": glRasterPos2i(200, 340) Text("TRANSLUCENT MATERIAL") glRasterPos2i(25, 300) Text("This material is currently experimentally exported (I have not been") glRasterPos2i(25, 280) Text("to test values for this material, so you're on your own ;-). Mess") glRasterPos2i(25, 260) Text("with the color, spec, hard, and sptr values in the blender window.") glRasterPos2i(25, 240) Text("Append ``_TRAN'' to the material name to use this material.") elif matstyle == "Plastic": glRasterPos2i(200, 340) Text("PLASTIC MATERIAL") glRasterPos2i(25, 300) Text("Little needs to be explained about this material. Color is determined") glRasterPos2i(25, 280) Text("by the Blender materials, and spec = Blender spec, roughness = Blender") glRasterPos2i(25, 260) Text("hardness.") elif exportwin.val == 20: glClearColor(0.5, 0.5, 0.5, 1) glClear(GL_COLOR_BUFFER_BIT) glRecti(0, 500, 380, 440) Button("Export Window", 10, 25, 450, 150, 20, "Show Export Window") Button("Shader Window", 20, 200, 450, 150, 20, "Show Shader Window") Button("Get Selected", 21, 25, 400, 150, 20, "Get Selected Object") if printmat == 1: glColor3f(1, 1, 1) glRasterPos2i(25, 380) Text("%s - %s Material" % (matnme, matstyle)) if matstyle == "Dielectric": ior = Slider("IOR: ", 22, 25, 290, 150, 20, ior.val, 0.50, 2.00, 1, "Set Index of Refraction" ) glRasterPos2i(25, 360) Text("In RADIANCE, the Dielectric material is similar to the glass material") glRasterPos2i(25, 340) Text("in most other raytracers. It takes four arguments - red, green, and") glRasterPos2i(25, 320) Text("blue (which are determined by the Blender material color) and IOR.") setiortocur(matnme, ior.val) elif matstyle == "Glass Pane": glRasterPos2i(25, 360) Text("The glass material has a more specific function in RADIANCE than") glRasterPos2i(25, 340) Text("most renderers. I have called this material glass pane, because") glRasterPos2i(25, 320) Text("the IOR is preset to 1.52 (the IOR of glass). Color is determined") glRasterPos2i(25, 300) Text("by Blender material settings.") elif matstyle == "Metal": glRasterPos2i(25, 360) Text("This material is a typical metal material. It uses the colors from") glRasterPos2i(25, 340) Text("Blender's material settings, as well as the specular and roughness") glRasterPos2i(25, 320) Text("(roughness is hardness in the Blender window).") elif matstyle == "Translucent": glRasterPos2i(25, 360) Text("This material is currently experimentally exported (I have not been") glRasterPos2i(25, 340) Text("to test values for this material, so you're on your own ;-). Mess") glRasterPos2i(25, 320) Text("with the color, spec, hard, and sptr values in the blender window.") elif matstyle == "Plastic": glRasterPos2i(25, 360) Text("Little needs to be explained about this material. Color is determined") glRasterPos2i(25, 340) Text("by the Blender materials, and spec = Blender spec, roughness = Blender") glRasterPos2i(25, 320) Text("hardness.") elif exportwin.val == 30: glClearColor(0.5, 0.5, 0.5, 1) glClear(GL_COLOR_BUFFER_BIT) glRecti(0, 500, 380, 440) Button("Export Window", 10, 25, 450, 150, 20, "Show Export Window") Button("Shader Window", 20, 200, 450, 150, 20, "Show Shader Window") skylight = Toggle("Sky Light", 31, 25, 400, 150, 20, float(skylight.val)) ambient = Toggle ("Ambient Light", 41, 225, 400, 150, 20, int(ambient.val)) if skylight.val == 1: skytype = Menu("Sky Type%t|Sunny + Sun%x1|Sunny - Sun%x2|Cloudy%x3|Inter. + Sun%x4|Inter. - Sun%x5|Uniform%x6|HDRIBL%x7", 51, 5, 265, 200, 20, int(skytype.val)) if skytype.val != 7: lightR = Slider("Sky R ", 32, 5, 370, 200, 20, float(lightR.val), 0, 1) lightG = Slider("Sky G ", 33, 5, 350, 200, 20, float(lightG.val), 0, 1) lightB = Slider("Sky B ", 34, 5, 330, 200, 20, float(lightB.val), 0, 1) glColor3f(0, 0, 0) glRecti(95, 325, 115, 305) glColor3f(lightR.val, lightG.val, lightB.val) glRecti(100, 320, 110, 310) elif skytype.val == 7: glRasterPos2i(25, 370) Text("NO COLORS FOR HDR IBL") hdrprobe1 = Create(hdrprobe) hdrprobe1 = String("HDR Probe Name: ", 35, 5, 245, 300, 20, str(hdrprobe1.val), 40, "(Please put the probe in the export directory)") hdrprobe = hdrprobe1.val if ambient.val == 1: ambbounce = Slider("Bounces ", 42, 225, 370, 200, 20, int(ambbounce.val), 0, 8) ambaccur = Slider("Accuracy ", 43, 225, 350, 200, 20, float(ambaccur.val), 0, 0.5) ambres = Slider("Resoultion ", 44, 225, 330, 200, 20, int(ambres.val), 0, 128) ambval = Slider("Value ", 47, 225, 310, 200, 20, float(ambval.val), 0, 1) ambdiv = Number("Divisions ", 45, 225, 290, 200, 20, int(ambdiv.val), 0, 4096) ambssam = Number("SuperSamples ", 46, 225, 270, 200, 20, int(ambssam.val), 0, 1024) else: ambbounce = Create(0) elif exportwin.val == 60: glClearColor(0.5, 0.5, 0.5, 1) glClear(GL_COLOR_BUFFER_BIT) glRecti(0, 500, 380, 440) Button("Export Window", 10, 25, 450, 150, 20, "Show Export Window") Button("Shader Window", 20, 200, 450, 150, 20, "Show Shader Window") #falsecolor = Toggle("False Color", 61, 25, 400, 150, 20, int(falsecolor.val)) #glare = Toggle("Glare", 71, 225, 400, 150, 20, int(glare.val)) #if falsecolor.val == 1: # fscale = Number("Scale: ", 62, 5, 370, 200, 20, float(fscale.val), 10, 10000) # mult = Number("Multiplier: ", 63, 5, 350, 200, 20, float(mult.val), 10, 1000) # label = String("Label: ", 64, 5, 330, 200, 20, str(label.val), 15) # irrad = Toggle("Use Irradiance", 65, 5, 310, 200, 20, int(irrad.val)) #else: irrad = Create(0) def event(evt, val): global finpath, exppath1, hdrprobe if evt == ESCKEY: settings = open(os.path.join(finpath, "gui.settings"), 'w') variables = [("skylight", skylight.val), ("ambient", ambient.val), ("lightR", lightR.val), ("lightG", lightG.val), ("lightB", lightB.val), ("ior", ior.val), ("ambbounce", ambbounce.val), ("ambval", ambval.val), ("ambres", ambres.val), ("ambaccur", ambaccur.val), ("ambdiv", ambdiv.val), ("ambssam", ambssam.val), ("exportsky", exportsky.val), ("skytype", skytype.val), ("xsize", xsize.val), ("ysize", ysize.val), ("fileroot", fileroot.val), ("exppath", exppath1.val), ("falsecolor", falsecolor.val), ("glare", glare.val), ("fscale", fscale.val), ("mult", mult.val), ("label", label.val), ("irrad", irrad.val), ("radpath", radpath), ("hdrprobe", hdrprobe), ("hdr", hdr)] for var in variables: settings.write("%s\n" % (var[1])) settings.close() print "settings saved" Exit() def r(win): exportwin.val = win Register(gui,event,bevent) def bevent(evt): global matstyle, skylight, hdr, skytype, skytype1 #exportwin.val = 30 #exportwin.val = 50 #exportwin.val = 1 if evt == 1: export() elif evt == 4: makerif() elif evt == 5: execrif(1) elif evt == 6: execrif(0) elif evt == 10: #matstyle = "" r(1) elif evt == 20: #matstyle = "" r(20) elif evt == 21: obj = Blender.Object.getSelected()[0] data = obj.getData() try: materials = data.getMaterials()[0] except IndexError: materials = Blender.Material.New() mat = obj.name matname = mat material = obj mat_id = matname[-5:] showshader(matname, mat_id) r(20) elif evt == 81: matname = "" mat_id = "" showshader(matname, mat_id) r(80) elif evt == 82: matname = "" mat_id = "_PANE" showshader(matname, mat_id) r(80) elif evt == 83: matname = "" mat_id = "_DIEL" showshader(matname, mat_id) r(80) elif evt == 84: matname = "" mat_id = "_METL" showshader(matname, mat_id) r(80) elif evt == 85: matname = "" mat_id = "_TRAN" showshader(matname, mat_id) r(80) elif (evt >= 20) and (evt < 30): r(20) elif (evt >= 30) and (evt < 60): r(30) elif (evt >= 60) and (evt < 80): r(60) elif (evt >= 80) and (evt < 90): r(80) else: r(1) def makerif(): r(1) global rif, fileroot, meshnum, meshlist, ysize, xsize global ambbounce, ambaccur, ambres, ambdiv, ambssam, ambval global lightR, lightG, lightB, xsize, ysize, falsecolor, glare, irrad, fscale, mult, label ambvalue = float(ambval.val) radfile1 = (fileroot.val + ".rad") vffile1 = (fileroot.val + ".vf") octfile = (fileroot.val + ".oct") rif = open(os.path.join(exppath, (fileroot.val + ".rif")), 'w') rif.write("OCTREE = %s.oct\n" % fileroot.val + "scene = %s.rad\n" % fileroot.val + #"ZONE = E\n" + "view = vw1 -vf %s.vf\n" % fileroot.val + "RESOLUTION = %s %s\n" % (xsize.val * 2, ysize.val * 2) + "PENUMBRAS = TRUE\n" + "PICTURE = %s\n" % fileroot.val + "RAWFILE = %sraw\n" % fileroot.val + "AMBFILE = %s.amb\n" % fileroot.val) if irrad.val == 1: rif.write("render = -i -ps 2 -x %s -y %s -ab %s -aa %s -ar %s -ad %s -as %s -av %s %s %s\n" % (int(xsize.val) * 2, int(ysize.val) * 2, ambbounce.val, ambaccur.val, ambres.val, ambdiv.val, ambssam.val, ambvalue * float(lightR.val), ambvalue * float(lightG.val), ambvalue * float(lightB.val))) else: rif.write("render = -ps 2 -x %s -y %s -ab %s -aa %s -ar %s -ad %s -as %s -av %s %s %s\n" % (int(xsize.val) * 2, int(ysize.val) * 2, ambbounce.val, ambaccur.val, ambres.val, ambdiv.val, ambssam.val, ambvalue * float(lightR.val), ambvalue * float(lightG.val), ambvalue * float(lightB.val))) rif.write("pfilt = -r 1 -x %s -y %s" % (xsize.val, ysize.val)) rif.close() print "RIF file written" def execrif(prev): global rif, fileroot, exppath, radpath makerif() rifname = fileroot.val + ".rif" os.chdir((exppath)) if (prev == 1) and (os.name != "nt"): arg = "-o X11" else: arg = "" if os.name == "nt": cmd = os.path.join(radpath, 'rad.exe') else: cmd = os.path.join(radpath, 'rad') os.spawnl(os.P_NOWAIT, cmd, cmd, arg, rifname) r(1)