All pastes #837320 Raw Edit

SF_exporter.py

public text v1 · immutable
#837320 ·published 2007-12-29 15:22 UTC
rendered paste body
#!BPY
"""
Name: 'SF Shader exporter'
Blender: 245
Group: 'Export'
Tooltip: 'Prototype for ID Properties based SF shader system'
"""

# License: Copyright Olivier Saraja (c) 2007 and GPL v2.0

import Blender
from Blender import Object, Material, Draw, BGL

## global vars ##
global FILE
FILENAME = Blender.Get('filename').replace(".blend", ".sc")

##Default values for buttons##
SHADERNAME=Draw.Create("sfdif")
SHADERTYPE=Draw.Create(1)
DIFFR=Draw.Create(1.000)
DIFFG=Draw.Create(1.000)
DIFFB=Draw.Create(1.000)
REFL=Draw.Create(1.000)
BRIGHTR=Draw.Create(1.000)
BRIGHTG=Draw.Create(1.000)
BRIGHTB=Draw.Create(1.000)
DARKR=Draw.Create(1.000)
DARKG=Draw.Create(1.000)
DARKB=Draw.Create(1.000)
SAMPLESAO=Draw.Create(100)
DIST=Draw.Create(100.0)
SPECR=Draw.Create(1.000)
SPECG=Draw.Create(1.000)
SPECB=Draw.Create(1.000)
HARD=Draw.Create(100)
SAMPLES=Draw.Create(100)
ROUGHX=Draw.Create(10.000)
ROUGHY=Draw.Create(10.000)
REFLR=Draw.Create(1.000)
REFLG=Draw.Create(1.000)
REFLB=Draw.Create(1.000)
TETA=Draw.Create(10.000)
COLR=Draw.Create(1.000)
COLG=Draw.Create(1.000)
COLB=Draw.Create(1.000)
ABSORPTIONDIST=Draw.Create(100.0)
ABSCOLR=Draw.Create(1.000)
ABSCOLG=Draw.Create(1.000)
ABSCOLB=Draw.Create(1.000)

##Buttons Events##
EV_SHADERNAME=1
EV_SHADERTYPE=2
EV_DIFFR=3
EV_DIFFG=4
EV_DIFFB=5
EV_REFL=6
EV_BRIGHTR=7
EV_BRIGHTG=8
EV_BRIGHTB=9
EV_DARKR=10
EV_DARKG=11
EV_DARKB=12
EV_SAMPLESAO=13
EV_DIST=14
EV_SPECR=15
EV_SPECG=16
EV_SPECB=17
EV_HARD=18
EV_SAMPLES=19
EV_ROUGHX=20
EV_ROUGHY=21
EV_REFLR=22
EV_REFLG=23
EV_REFLB=24
EV_COLR=25
EV_COLG=26
EV_COLB=27
EV_TETA=28
EV_ABSORPTIONDIST=29
EV_ABSCOLR=30
EV_ABSCOLG=31
EV_ABSCOLB=32
EV_SAVEID=33
#EV_SHADREDRAW=34
EV_EXPSHAD=35
EV_SELLIST=36
EV_SELSEL=37
EV_SELMAT=38

def translate_shaders():
        ob=Blender.Object.GetSelected()
        obj=ob[0]
        material=obj.getData(mesh=1).materials
        for mat in material:
                if mat.name.startswith("sfdif"):
                        mat.properties['Type']="diffuse"
                elif mat.name.startswith("sfshi"):
                        mat.properties['Type']="shiny"
                elif mat.name.startswith("sfamb"):
                        mat.properties['Type']="amb-occ"
                elif mat.name.startswith("sfpho"):
                        mat.properties['Type']="phong"
                elif mat.name.startswith("sfwar"):
                        mat.properties['Type']="ward"
                elif mat.name.startswith("sfmir"):
                        mat.properties['Type']="mirror"
                elif mat.name.startswith("sfgla"):
                        mat.properties['Type']="glass"
                elif mat.name.startswith("sfshi"):
                        mat.properties['Type']="shiny"
                elif mat.name.startswith("sfcon"):
                        mat.properties['Type']="constant"
                elif mat.name.startswith("sfsss"):
                        mat.properties['Type']="sss"
                elif mat.name.startswith("sfube"):
                        mat.properties['Type']="uber"
                else:
                        mat.properties['Type']="diffuse"
                mat.properties['Shader Name']=mat.name
                diff=mat.getRGBCol()
                #Diffuse for Uber, Diffuse, Shiny, Phong, Ward, SSS
                mat.properties['Diff R']=diff[0]
                mat.properties['Diff G']=diff[1]
                mat.properties['Diff B']=diff[2]
                #Color for Constant, Glass
                mat.properties['Col R']=diff[0]
                mat.properties['Col G']=diff[1]
                mat.properties['Col B']=diff[2]
                #Bright for AMb-Occ
                mat.properties['Bright R']=diff[0]
                mat.properties['Bright G']=diff[1]
                mat.properties['Bright B']=diff[2]
                speccol=mat.getSpecCol()
                #Spec for Phong, Ward
                mat.properties['Spec R']=speccol[0]
                mat.properties['Spec G']=speccol[1]
                mat.properties['Spec B']=speccol[2]
                #Specular for SSS
                mat.properties['Specular R']=speccol[0]
                mat.properties['Specular G']=speccol[1]
                mat.properties['Specular B']=speccol[2]
                #absorption.color for Glass
                mat.properties['Absorption Color R']=speccol[0]
                mat.properties['Absorption Color G']=speccol[1]
                mat.properties['Absorption Color B']=speccol[2]
                #Dark for Amb-Occ
                mat.properties['Dark R']=speccol[0]
                mat.properties['Dark G']=speccol[1]
                mat.properties['Dark B']=speccol[2]
                textures=mat.getTextures()
                reflShiny=mat.getRayMirr()
                #Refl for Shiny
                mat.properties['Refl Shiny']=reflShiny
                hardPhong=mat.hard
                #hard for Phong
                mat.properties['Hard']=hardPhong
                refMirror=mat.getRGBCol()
                #Refl for Mirror
                mat.properties['Refl R']=diff[0]
                mat.properties['Refl G']=diff[1]
                mat.properties['Refl B']=diff[2]
                teta=mat.getIOR()
                #teta for Glass
                mat.properties['Teta']=teta
                #Samples for Amb-Occ
                mat.properties['Samples AO']=32
                #Dist for Amb-Occ
                mat.properties['Dist']=3.0
                #Rough for Ward
                mat.properties['Rough X']=0.2
                mat.properties['Rough Y']=0.01
                #Samples for Phong, Ward
                mat.properties['Samples']=4
                #Absorption Distance for Glass, SSS
                mat.properties['Absorption Distance']=5.0
                #Absoprtion Power for SSS
                mat.properties['Absorption Power']=1.0
                #sssRays for SSS
                mat.properties['SSS Rays']=4
                #Phong Rays for SSS
                mat.properties['Phong Rays']=6
                #thickness for SSS
                mat.properties['thickness']=0.125

def export_shaders(filename):
        FILE=open(filename,"w")
        ob=Blender.Object.GetSelected()
        obj=ob[0]
        material=obj.getData(mesh=1).materials
        for mat in material:
                print "  o exporting diffuse shader "+mat.name+"..."
                FILE.write("\n\nshader {\n")
                FILE.write("\tname \""+mat.name+".shader\"\n")
                FILE.write("\ttype %s \n" % (mat.properties['Type']))
                if mat.properties['Type']=="diffuse":   
                        FILE.write("\tdiff { \"sRGB nonlinear\" %.3f %.3f %.3f }\n" % (mat.properties['Diff R'], mat.properties['Diff G'], mat.properties['Diff B']))
                elif mat.properties['Type']=="shiny":
                        FILE.write("\tdiff { \"sRGB nonlinear\" %.3f %.3f %.3f }\n" % (mat.properties['Diff R'], mat.properties['Diff G'], mat.properties['Diff B']))
                        FILE.write("\trefl %.2f\n" % mat.properties['Refl Shiny'])
                elif mat.properties['Type']=="amb-occ":
                        FILE.write("\tbright %.3f %.3f %.3f\n" % (mat.properties['Bright R'], mat.properties['Bright G'], mat.properties['Bright B']))
                        FILE.write("\tdark %.3f %.3f %.3f\n" % (mat.properties['Dark R'], mat.properties['Dark G'], mat.properties['Dark B']))
                        FILE.write("\tsamples %i \n" % mat.properties['Samples AO'])
                        FILE.write("\tdist %i \n" % mat.properties['Dist'])
                elif mat.properties['Type']=="phong":
                        FILE.write("\tdiff { \"sRGB nonlinear\" %.3f %.3f %.3f }\n" % (mat.properties['Diff R'], mat.properties['Diff G'], mat.properties['Diff B']))
                        FILE.write("\tspec { \"sRGB nonlinear\" %.3f %.3f %.3f } %i\n" %(mat.properties['Spec R'], mat.properties['Spec G'], mat.properties['Spec B'], mat.properties['Hard']))
                        FILE.write("\tsamples %i\n" % mat.properties['Samples'])
                elif mat.properties['Type']=="ward":
                        FILE.write("\tdiff { \"sRGB nonlinear\" %.3f %.3f %.3f }\n" % (mat.properties['Diff R'], mat.properties['Diff G'], mat.properties['Diff B']))
                        FILE.write("\tspec { \"sRGB nonlinear\" %.3f %.3f %.3f } \n" %(mat.properties['Spec R'], mat.properties['Spec G'], mat.properties['Spec B']))
                        FILE.write("\trough %.3f %.3f1\n" % (mat.properties['Rough X'],mat.properties['Rough Y']))
                        FILE.write("\tsamples %i\n" % mat.properties['Samples'])
                elif mat.properties['Type']=="mirror":
                        FILE.write("\trefl { \"sRGB nonlinear\" %.3f %.3f %.3f }\n" %(mat.properties['Refl R'], mat.properties['Refl G'], mat.properties['Refl B']))
                elif mat.properties['Type']=="glass":
                        FILE.write("\teta %.3f \n" % mat.properties['Teta'])
                        FILE.write("\tcolor { \"sRGB nonlinear\" %.3f %.3f %.3f }\n" %(mat.properties['Col R'],mat.properties['Col G'],mat.properties['Col B']))
                        FILE.write("\tabsorbtion.distance %.3f \n" % mat.properties['Absorption Distance'])
                        FILE.write("\tabsorbtion.color { \"sRGB nonlinear\" %.3f %.3f %.3f }\n" %(mat.properties['Absorption Color R'], mat.properties['Absorption Color G'], mat.properties['Absorption Color B']))
                elif mat.properties['Type']=="constant":
                        FILE.write("\tcolor { \"sRGB nonlinear\" %.3f %.3f %.3f }\n" %(mat.properties['Col R'],mat.properties['Col G'],mat.properties['Col B']))
                #elif mat.properties['Type']="sss":
                #       ...
                #elif mat.properties['Type']="uber":
                #       ...
                else:
                        FILE.write("\tdiff { \"sRGB nonlinear\" %.3f %.3f %.3f }\n" % (mat.properties['Diff R'], mat.properties['Diff G'], mat.properties['Diff B']))
                FILE.write("\t}")
        FILE.close
        return()
 
def checkID():
        if id_exists == 1:
                print "ID properties already exist, go to editing..."
                drawGUI()
        elif id_exists ==0:
                print "ID properties don't exist, automatically generate defaults..."
                translate_shaders()
                drawGUI()

def initGUI():
                SHADERNAME.val=mat.properties['Shader Name']

                if mat.properties['Type']=="diffuse":
                        SHADERTYPE.val=1
                elif mat.properties['Type']=="shiny":
                        SHADERTYPE.val=2
                elif mat.properties['Type']=="amb-occ":
                        SHADERTYPE.val=3
                elif mat.properties['Type']=="phong":
                        SHADERTYPE.val=4
                elif mat.properties['Type']=="ward":
                        SHADERTYPE.val=5
                elif mat.properties['Type']=="mirror":
                        SHADERTYPE.val=6
                elif mat.properties['Type']=="glass":
                        SHADERTYPE.val=7
                elif mat.properties['Type']=="constant":
                        SHADERTYPE.val=8
                else:
                        SHADERTYPE.val=1
                print SHADERTYPE.val

                DIFFR.val=mat.properties['Diff R']
                DIFFG.val=mat.properties['Diff G']
                DIFFB.val=mat.properties['Diff B']
                REFL.val=mat.properties['Refl Shiny']
                BRIGHTR.val=mat.properties['Bright R']
                BRIGHTG.val=mat.properties['Bright G']
                BRIGHTB.val=mat.properties['Bright B']
                DARKR.val=mat.properties['Dark R']
                DARKG.val=mat.properties['Dark G']
                DARKB.val=mat.properties['Dark B']
                SAMPLESAO.val=mat.properties['Samples AO']
                DIST.val=mat.properties['Dist']
                SPECR.val=mat.properties['Spec R']
                SPECG.val=mat.properties['Spec G']
                SPECB.val=mat.properties['Spec B']
                HARD.val=mat.properties['Hard']
                SAMPLES.val=mat.properties['Samples']
                ROUGHX.val=mat.properties['Rough X']
                ROUGHY.val=mat.properties['Rough Y']
                REFLR.val=mat.properties['Refl R']
                REFLG.val=mat.properties['Refl G']
                REFLB.val=mat.properties['Refl B']
                TETA.val=mat.properties['Teta']
                COLR.val=mat.properties['Col R']
                COLG.val=mat.properties['Col G']
                COLB.val=mat.properties['Col B']
                ABSORPTIONDIST.val=mat.properties['Absorption Distance']
                ABSCOLR.val=mat.properties['Absorption Color R']
                ABSCOLG.val=mat.properties['Absorption Color G']
                ABSCOLB.val=mat.properties['Absorption Color B']

def saveID():
                mat.properties['Shader Name']=SHADERNAME.val
 
                if SHADERTYPE.val==1:
                        mat.properties['Type']="diffuse"
                elif SHADERTYPE.val==2:
                        mat.properties['Type']="shiny"
                elif SHADERTYPE.val==3:
                        mat.properties['Type']="amb-occ"
                elif SHADERTYPE.val==4:
                        mat.properties['Type']="phong"
                elif SHADERTYPE.val==5:
                        mat.properties['Type']="ward"
                elif SHADERTYPE.val==6:
                        mat.properties['Type']="mirror"
                elif SHADERTYPE.val==7:
                        mat.properties['Type']="glass"
                elif SHADERTYPE.val==8:
                        mat.properties['Type']="constant"
                else:
                        mat.properties['Type']="diffuse"

                mat.properties['Diff R']=DIFFR.val
                mat.properties['Diff G']=DIFFG.val
                mat.properties['Diff B']=DIFFB.val
                mat.properties['Refl Shiny']=REFL.val
                mat.properties['Bright R']=BRIGHTR.val
                mat.properties['Bright G']=BRIGHTG.val
                mat.properties['Bright B']=BRIGHTB.val
                mat.properties['Dark R']=DARKR.val
                mat.properties['Dark G']=DARKG.val
                mat.properties['Dark B']=DARKB.val
                mat.properties['Samples AO']=SAMPLESAO.val
                mat.properties['Dist']=DIST.val
                mat.properties['Spec R']=SPECR.val
                mat.properties['Spec G']=SPECG.val
                mat.properties['Spec B']=SPECB.val
                mat.properties['Hard']=HARD.val
                mat.properties['Samples']=SAMPLES.val
                mat.properties['Rough X']=ROUGHX.val
                mat.properties['Rough Y']=ROUGHY.val
                mat.properties['Refl R']=REFLR.val
                mat.properties['Refl G']=REFLG.val
                mat.properties['Refl B']=REFLB.val
                mat.properties['Teta']=TETA.val
                mat.properties['Col R']=COLR.val
                mat.properties['Col G']=COLG.val
                mat.properties['Col B']=COLB.val
                mat.properties['Absorption Distance']=ABSORPTIONDIST.val
                mat.properties['Absorption Color R']=ABSCOLR.val
                mat.properties['Absorption Color G']=ABSCOLG.val
                mat.properties['Absorption Color B']=ABSCOLB.val

#def draw_main():
#	col=10; line=570;BGL.glRasterPos2i(col, line); SELLIST=Draw.PushButton("Edit from list", EV_SELLIST,col,line,110,65,"Select object to edit in a list")
#	col=135; line=570;BGL.glRasterPos2i(col, line); SELSEL=Draw.PushButton("Edit from selected", EV_SELSEL,col,line,110,65,"Edit selected object")
#	col=260; line=570;BGL.glRasterPos2i(col, line); SELMAT=Draw.PushButton("Edit from materials", EV_SELMAT,col,line,110,65,"Select shader to edit in a list")

def drawGUI():
                global SHADERNAME, SHADERTYPE, DIFFR, DIFFG, DIFFB, REFL, BRIGHTR, BRIGHTG, BRIGHTB, DARKR, DARKG, DARKB, SAMPLESAO, DIST, SPECR, SPECG, SPECB, HARD, SAMPLES
                global ROUGHX, ROUGHY, REFLR, REFLG, REFLB, COLR, COLG,COLB, TETA, ABSORPTIONDIST, ABSCOLR, ABSCOLG, ABSCOLB
#                draw_main()
		col=10; line=450;BGL.glRasterPos2i(col, line); SHADERNAME=Draw.String("Shader's name: ", EV_SHADERNAME, col, line, 200, 25, SHADERNAME.val,80, "Name of the shader")
                col=10; line=410;BGL.glRasterPos2i(col, line); SHADERTYPE=Draw.Menu("%tShader type|diffuse|shiny|amb-occ|phong|ward|mirror|glass|constant",EV_SHADERTYPE, col, line, 100, 25, SHADERTYPE.val)
#                col=125; line=410;BGL.glRasterPos2i(col, line); SHADREDRAW=Draw.PushButton("Redraw", EV_SHADREDRAW,col,line,150,25,"Redraw GUI after shader type change")
                col=10; line=330;BGL.glRasterPos2i(col, line); SAVEID=Draw.PushButton("Save changes", EV_SAVEID,col,line,100,65,"Save ID Properties to Material")
                col=10; line=250;BGL.glRasterPos2i(col, line); EXPSHAD=Draw.PushButton("Export all shaders", EV_EXPSHAD,col,line,100,65,"Export shaders to .sc file")
                if mat.properties['Type']=="diffuse":
                        col=125;line=410;BGL.glRasterPos2i(col, line); DIFFR=Draw.Slider("Diff R: ", EV_DIFFR, col,line, 150, 25, DIFFR.val, 0.000, 1.000, 1, "Diffuse color component R")
                        col=290;line=410;BGL.glRasterPos2i(col, line); DIFFG=Draw.Slider("Diff G: ", EV_DIFFG, col,line, 150, 25, DIFFG.val, 0.000, 1.000, 1, "Diffuse color component G")
                        col=455;line=410;BGL.glRasterPos2i(col, line); DIFFB=Draw.Slider("Diff B: ", EV_DIFFB, col,line, 150, 25, DIFFB.val, 0.000, 1.000, 1, "Diffuse color component B")
                elif mat.properties['Type']=="shiny":
                        col=125;line=410;BGL.glRasterPos2i(col, line); DIFFR=Draw.Slider("Diff R: ", EV_DIFFR, col,line, 150, 25, DIFFR.val, 0.000, 1.000, 1, "Diffuse color component R")
                        col=290;line=410;BGL.glRasterPos2i(col, line); DIFFG=Draw.Slider("Diff G: ", EV_DIFFG, col,line, 150, 25, DIFFG.val, 0.000, 1.000, 1, "Diffuse color component G")
                        col=455;line=410;BGL.glRasterPos2i(col, line); DIFFB=Draw.Slider("Diff B: ", EV_DIFFB, col,line, 150, 25, DIFFB.val, 0.000, 1.000, 1, "Diffuse color component B")
                        col=125;line=370;BGL.glRasterPos2i(col, line); REFL=Draw.Number("Refl: ", EV_REFL, col,line, 150, 25, REFL.val, 0.000, 1.000, "Reflection value")
                elif mat.properties['Type']=="amb-occ":
                        col=125;line=410;BGL.glRasterPos2i(col, line); BRIGHTR=Draw.Slider("Bright R: ", EV_BRIGHTR, col,line, 150, 25, BRIGHTR.val, 0.000, 1.000, 1, "Brightness color component R")
                        col=290;line=410;BGL.glRasterPos2i(col, line); BRIGHTG=Draw.Slider("Bright G: ", EV_BRIGHTG, col,line, 150, 25, BRIGHTG.val, 0.000, 1.000, 1, "Brightness color component G")
                        col=455;line=410;BGL.glRasterPos2i(col, line); BRIGHTB=Draw.Slider("Bright B: ", EV_BRIGHTB, col,line, 150, 25, BRIGHTB.val, 0.000, 1.000, 1, "Brightness color component B")
                        col=125;line=370;BGL.glRasterPos2i(col, line); DARKR=Draw.Slider("Dark R: ", EV_DARKR, col,line, 150, 25, DARKR.val, 0.000, 1.000, 1, "Darkness color component R")
                        col=290;line=370;BGL.glRasterPos2i(col, line); DARKG=Draw.Slider("Dark G: ", EV_DARKG, col,line, 150, 25, DARKG.val, 0.000, 1.000, 1, "Darkness color component G")
                        col=455;line=370;BGL.glRasterPos2i(col, line); DARKB=Draw.Slider("Dark B: ", EV_DARKB, col,line, 150, 25, DARKB.val, 0.000, 1.000, 1, "Darkness color component B")
                        col=125;line=330;BGL.glRasterPos2i(col, line); SAMPLESAO=Draw.Number("Samples AO: ", EV_SAMPLESAO, col,line, 150, 25, SAMPLESAO.val, 0.000, 1.000, "Ambiant Occlusion Samples")
                        col=290;line=330;BGL.glRasterPos2i(col, line); DIST=Draw.Number("Dist: ", EV_DIST, col,line, 150, 25, DIST.val, 0.000, 1.000, "Ambiant Occlusion Distance")
                elif mat.properties['Type']=="phong":
                        col=125;line=410;BGL.glRasterPos2i(col, line); DIFFR=Draw.Slider("Diff R: ", EV_DIFFR, col,line, 150, 25, DIFFR.val, 0.000, 1.000, 1, "Diffuse color component R")
                        col=290;line=410;BGL.glRasterPos2i(col, line); DIFFG=Draw.Slider("Diff G: ", EV_DIFFG, col,line, 150, 25, DIFFG.val, 0.000, 1.000, 1, "Diffuse color component G")
                        col=455;line=410;BGL.glRasterPos2i(col, line); DIFFB=Draw.Slider("Diff B: ", EV_DIFFB, col,line, 150, 25, DIFFB.val, 0.000, 1.000, 1, "Diffuse color component B")
                        col=125;line=370;BGL.glRasterPos2i(col, line); SPECR=Draw.Slider("Spec R: ", EV_SPECR, col,line, 150, 25, SPECR.val, 0.000, 1.000, 1, "Specular color component R")
                        col=290;line=370;BGL.glRasterPos2i(col, line); SPECG=Draw.Slider("Spec G: ", EV_SPECG, col,line, 150, 25, SPECG.val, 0.000, 1.000, 1, "Specular color component G")
                        col=455;line=370;BGL.glRasterPos2i(col, line); SPECB=Draw.Slider("Spec B: ", EV_SPECB, col,line, 150, 25, SPECB.val, 0.000, 1.000, 1, "Specular color component B")
                        col=125;line=330;BGL.glRasterPos2i(col, line); HARD=Draw.Number("Hard: ", EV_HARD, col,line, 150, 25, HARD.val, 0.000, 1.000, "Hardness of the specular")
                        col=125;line=270;BGL.glRasterPos2i(col, line); SAMPLES=Draw.Number("Samples: ", EV_SAMPLES, col,line, 150, 25, SAMPLES.val, 0.000, 1.000, "Samples of the specular")
                elif mat.properties['Type']=="ward":
                        col=125;line=410;BGL.glRasterPos2i(col, line); DIFFR=Draw.Slider("Diff R: ", EV_DIFFR, col,line, 150, 25, DIFFR.val, 0.000, 1.000, 1, "Diffuse color component R")
                        col=290;line=410;BGL.glRasterPos2i(col, line); DIFFG=Draw.Slider("Diff G: ", EV_DIFFG, col,line, 150, 25, DIFFG.val, 0.000, 1.000, 1, "Diffuse color component G")
                        col=455;line=410;BGL.glRasterPos2i(col, line); DIFFB=Draw.Slider("Diff B: ", EV_DIFFB, col,line, 150, 25, DIFFB.val, 0.000, 1.000, 1, "Diffuse color component B")
                        col=125;line=370;BGL.glRasterPos2i(col, line); SPECR=Draw.Slider("Spec R: ", EV_SPECR, col,line, 150, 25, SPECR.val, 0.000, 1.000, 1, "Specular color component R")
                        col=290;line=370;BGL.glRasterPos2i(col, line); SPECG=Draw.Slider("Spec G: ", EV_SPECG, col,line, 150, 25, SPECG.val, 0.000, 1.000, 1, "Specular color component G")
                        col=455;line=370;BGL.glRasterPos2i(col, line); SPECB=Draw.Slider("Spec B: ", EV_SPECB, col,line, 150, 25, SPECB.val, 0.000, 1.000, 1, "Specular color component B")
                        col=125;line=330;BGL.glRasterPos2i(col, line); ROUGHX=Draw.Number("Rough X: ", EV_ROUGHX, col,line, 150, 25, ROUGHX.val, 0.000, 1.000, "Roughness in the X direction")
                        col=290;line=330;BGL.glRasterPos2i(col, line); ROUGHY=Draw.Number("Rough Y: ", EV_ROUGHY, col,line, 150, 25, ROUGHY.val, 0.000, 1.000, "Roughness in the Y direction")
                        col=125;line=290;BGL.glRasterPos2i(col, line); SAMPLES=Draw.Number("Samples: ", EV_SAMPLES, col,line, 150, 25, SAMPLES.val, 0.000, 1.000, "Samples")
                elif mat.properties['Type']=="mirror":
                        col=125;line=410;BGL.glRasterPos2i(col, line); REFLR=Draw.Slider("Refl R: ", EV_REFLR, col,line, 150, 25, REFLR.val, 0.000, 1.000, 1, "Reflection color component R")
                        col=290;line=410;BGL.glRasterPos2i(col, line); REFLG=Draw.Slider("Refl G: ", EV_REFLG, col,line, 150, 25, REFLG.val, 0.000, 1.000, 1, "Reflection color component G")
                        col=455;line=410;BGL.glRasterPos2i(col, line); REFLB=Draw.Slider("Refl B: ", EV_REFLB, col,line, 150, 25, REFLB.val, 0.000, 1.000, 1, "Reflection color component B")
                elif mat.properties['Type']=="glass":
                        col=125;line=410;BGL.glRasterPos2i(col, line); COLR=Draw.Slider("Col R: ", EV_COLR, col,line, 150, 25, COLR.val, 0.000, 1.000, 1, "Color component R")
                        col=290;line=410;BGL.glRasterPos2i(col, line); COLG=Draw.Slider("Col G: ", EV_COLG, col,line, 150, 25, COLG.val, 0.000, 1.000, 1, "Color component G")
                        col=455;line=410;BGL.glRasterPos2i(col, line); COLB=Draw.Slider("Col B: ", EV_COLB, col,line, 150, 25, COLB.val, 0.000, 1.000, 1, "Color component B")
                        col=125;line=370;BGL.glRasterPos2i(col, line); TETA=Draw.Number("Teta: ", EV_TETA, col,line, 150, 25, TETA.val, 0.000, 1.000, "Index of refraction")
                        col=125;line=330;BGL.glRasterPos2i(col, line); ABSORPTIONDIST=Draw.Number("Absorption Distance: ", EV_ABSORPTIONDIST, col,line, 150, 25, ABSORPTIONDIST.val, 0.000, 1.000, "Absorption distance of light")
                        col=125;line=290;BGL.glRasterPos2i(col, line); ABSCOLR=Draw.Slider("Absorption Color R: ", EV_ABSCOLR, col,line, 150, 25, ABSCOLR.val, 0.000, 1.000, 1, "Absorption Color component R")
                        col=290;line=290;BGL.glRasterPos2i(col, line); ABSCOLG=Draw.Slider("Absorption Color G: ", EV_ABSCOLG, col,line, 150, 25, ABSCOLG.val, 0.000, 1.000, 1, "Absorption Color component G")
                        col=455;line=290;BGL.glRasterPos2i(col, line); ABSCOLB=Draw.Slider("Absorption Color B: ", EV_ABSCOLB, col,line, 150, 25, ABSCOLB.val, 0.000, 1.000, 1, "Absorption Color component B")
                elif mat.properties['Type']=="constant":
                        col=125;line=410;BGL.glRasterPos2i(col, line); COLR=Draw.Slider("Col R: ", EV_COLR, col,line, 150, 25, COLR.val, 0.000, 1.000, 1, "Color component R")
                        col=290;line=410;BGL.glRasterPos2i(col, line); COLG=Draw.Slider("Col G: ", EV_COLG, col,line, 150, 25, COLG.val, 0.000, 1.000, 1, "Color component G")
                        col=455;line=410;BGL.glRasterPos2i(col, line); COLB=Draw.Slider("Col B: ", EV_COLB, col,line, 150, 25, COLB.val, 0.000, 1.000, 1, "Color component B")

ob=Blender.Object.GetSelected()
print "Selected Objects:"
i=0
for o in ob:
	i=i+1	
if ob==[] or i==0:
	col=10; line=450;BGL.glRasterPos2i(col, line); Draw.Text("Warning: no object selected!","small")
else:
	obj=ob[0]
	col=10; line=450;BGL.glRasterPos2i(col, line); Draw.Text("There are %i object(s) selected" % i,"small")
	col=10; line=410;BGL.glRasterPos2i(col, line); Draw.Text("Active object is: %s" % obj.name,"small")
	matlist=obj.getData(mesh=1).materials
	if matlist==[]:
		col=10; line=370;BGL.glRasterPos2i(col, line); Draw.Text("No material for: %s. Please add one before!" % obj.name,"small")
	else:
		mat=matlist[0]
try:
	print mat.properties['Shader Name']
	id_exists=1
	col=10; line=370;BGL.glRasterPos2i(col, line); Draw.Text("Material exists, and ID Properties are already set","small")
except KeyError:
	id_exists=0
	col=10; line=370;BGL.glRasterPos2i(col, line); Draw.Text("Material exists, but no ID Properties are set","small")
initGUI()
checkID()
drawGUI()
 
def event(evt, val):
        if evt == Draw.ESCKEY:
                print "quitting exporter..."
                Draw.Exit()
 
def buttonEvent(evt):
        if evt == EV_SAVEID:
                saveID()
        if evt == EV_SHADERTYPE:
		saveID()
		Blender.Redraw()
        if evt == EV_EXPSHAD:
                export_shaders("test.sc")
		if evt == EV_SELSEL:
			sel_objects()
 
Draw.Register(drawGUI,event,buttonEvent)