#!BPY """ Registration info for Blender menus: Name: 'VirtuaLight 1.4' Blender: 234 Group: 'Misc' Tip: 'Touche R pour un rendu Raytracing, touche O pour un rendu OpenGL' """ ## Par Kaal_le_Saint, octobre 2004 ## # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #~ En cours : (pour la version 0.2 Beta) #~ - Amélioration de la 'ProgressBar' (plus de "détails") #~ - Amélioration de l'interface des matériaux : #~ - Sélection automatique du matériau avec la sélection d'un objet #~ - Rafraichissement du nom des matériaux #~ - Pré-visualisation des matériaux #~ - Ajout des options de Vlight inutilisées (absorption...) #~ - Empécher l'export d'objet "Vide" #~ - Utilisation de ".vib temporaires" au choix #~ - Prise en charge du flou de profondeur (DoF) #~ - Prise en charge améliorée des lumières de type AreaLight et Spot #~ - Enregistrement des paramètres dans les .Blend #~ - Mise à jour sélective (soit les meshs, soit la scène... Enregistrement de la sélection d'objets à exporter) #~ - Réglages avancés #~ - Une documentation #~ A faire : (pour une version future... peut-être) #~ - Améliorer le code #~ - Améliorer la transition Blender/VirtuaLight #~ - Gestion de l'auto-smooth #~ - Gestion des subdivisions de surface #~ - Import/export des fichier .vib (TriPatch, Poly et Nurbs) dans Blender #~ - Animations import Blender#,math from os import system from time import localtime from Blender.Draw import * from Blender.BGL import * matListe=[] menu = Create(1) IOR = REF = Create(0.) repXport = Blender.sys.dirname(Blender.Get('filename')) illuG = 0 refrSlid = Create(1.0003) reflSlid = Create(0.) refBlurSlid = Create(0.) zCanal = Create(0) caustic = Create(0) causticSlid = Create(0.) irid = Create(0) iridSlid = Create (0.) transpBlurToggle = Create(0) transpBlurSlid = Create(0.) irrad = Create(3) irSamp = Create(100) affichage = -1 posUp = 0 dirCouleur = 0 clic = False GI = Create(0) GIsamples = Create(70) heure = Create(("%s:%s"%(localtime()[3],localtime()[4]))) HDR = Create(0) HDRint = Create(1.) HDRimg = "groveC.hdr" irradMaxError = Create(20.) Rad = Create(0) RadSol = Create(0) BlurSample = Create(4) iridFreqSlid = Create(0.0) iridTurbSlid = Create(1.0) photons = Create(0) menuAR = Create(1) print print"------------------------------------" def interVlight(): global menu,dirCouleur,posUp,matListe,max global clic,refrSlid,reflSlid,refBlurSlid,zCanal global caustic,transpBlurSlid,transpBlurToggle global causticSlid,irid,iridSlid,GI,GIsamples global heure,HDR,HDRint,irradMaxError,Rad global RadSol,BlurSample,iridFreqSlid,iridTurbSlid global photons,menuAR,irrad max = Buffer(GL_INT,4) # à mettre à jour glGetIntegerv(GL_VIEWPORT,max) # à mettre à jour glClearColor( 0.33, 0.33, 0.33, 0) glClear(GL_COLOR_BUFFER_BIT) glColor3f(0,0.6,1) glRasterPos2i(max[2]/2-75,max[3]-30) Text("VLighTunnel v0.1 Beta") glRasterPos2i(20, 20) rX = "Repertoire d'export : %s"% repXport Text(rX) PushButton('',19,5,15,10,18,"Choisir un nouveau repertoire d'export") PushButton("?",457,max[2]-20,max[3]-20,20,18) if affichage == 1: # Option de rendu GI = Toggle(":: Activer GI ::", 2, max[2]/2-100, 130, 200, 18, GI.val,"") photons = Toggle("Photons", 80, max[2]/2-30, 150, 60, 18, photons.val,"") if GI.val: Rad = Toggle(":: Radiosite ::", 3, max[2]/2-160, 150, 120, 18, Rad.val,"") RadSol = Toggle(":: Radiosite Solaire ::", 4, max[2]/2+40, 150, 120, 18, RadSol.val,"") HDR = Toggle(":: HDRi ::", 5, max[2]/2-60, 170, 120, 18, HDR.val,"") if Rad.val: irradMaxError = Number("Irrad. Max :", 6, max[2]/2-60, 80, 120, 18, irradMaxError.val, 1., 100.,"") irrad = Menu("Grille%t|2%x1|4%x2|8%x3|16%x4|32%x5",98,max[2]/2-60,60,120,18,irrad.val) if RadSol.val: GIsamples = Number("Samples :", 7, max[2]/2-50, 90, 100, 18, GIsamples.val, 1, 9000,"") heure = String("", 8, max[2]/2-20, 70, 40, 18, heure.val, 5, "" ) if HDR.val: GIsamples = Number("Samples :", 7, max[2]/2-120, 90, 120, 18, GIsamples.val, 1, 9000,"") irradMaxError = Number("Irrad. Max :", 6, max[2]/2, 90, 120, 18, irradMaxError.val, 1., 100.,"") HDRint = Number("Intensite :", 9, max[2]/2-50, 70, 100, 18, HDRint.val, 0.1, 5.,"") PushButton("Image HDR",14,max[2]/2-40,50,80,18,"") textLong = GetStringWidth(HDRimg)/2 glRasterPos2i(max[2]/2-textLong,38) Text(HDRimg) elif affichage == 2: # Interface Matériaux majvMAt() transpBlurToggle = Toggle(":: Flou ::", 11, 5, 60, 100, 18, transpBlurToggle.val,"") irid = Toggle(":: Iridescence ::", 12, 5, 40, 100, 18, irid.val,"") caustic = Toggle(":: Caustiques ::", 13, 5, 80, 100, 18, caustic.val,"") haut = max[3]-50 # Fleche vers le haut if dirCouleur==1:rup,gup,bup=r,g,b else:rup,gup,bup=0.8,0.75,0.67 glColor3f(rup,gup,bup) glBegin(GL_TRIANGLES) glVertex2d(200,haut);glVertex2d(205,haut+10);glVertex2d(210,haut) glEnd() glBegin(GL_QUADS) glVertex2d(202.5,haut);glVertex2d(207.5,haut) glVertex2d(207.5,haut-10);glVertex2d(202.5,haut-10) glEnd() # Fleche vers le bas if dirCouleur==2:rdo,gdo,bdo=r,g,b else:rdo,gdo,bdo=0.8,0.75,0.67 glColor3f(rdo,gdo,bdo) glBegin(GL_TRIANGLES) glVertex2d(200,50);glVertex2d(205,40);glVertex2d(210,50) glEnd() glBegin(GL_QUADS) glVertex2d(202.5,50);glVertex2d(207.5,50) glVertex2d(207.5,60);glVertex2d(202.5,60) glEnd() # Colonnes et textes paire = False ySouris = Blender.Window.GetMouseCoords()[1]-max[1] if (haut-80)/150:i+=posUp/15 try: if (pos 12 and int(horaire[-2:]) < 60: heure.val = "0"+horaire[:1]+":"+horaire[-2:] else: heure.val = ("%s:%s"%(localtime()[3],localtime()[4])) def rep(fic): global repXport repXport = Blender.sys.dirname(fic) def HDRep(fic): global HDRimg HDRimg = fic def up(num): global posUp,r,g,b,dirCouleur dirCouleur = 1 if posUp>0:posUp-=num r,g,b=0,0.1*num,0 def down(num): global posUp,r,g,b,dirCouleur dirCouleur = 2 if posUp 47) and (ord(nom[nLettre]))<58) or ((ord(nom[nLettre])>64) and (ord(nom[nLettre]))<91)or((ord(nom[nLettre])>96) and (ord(nom[nLettre]))<123):propre=propre+nom[nLettre] else:propre=propre+"_" return propre def lanceRendu(mode): global affichage Blender.Window.WaitCursor(True) #~ tempsGen = Blender.sys.time() majvMAt() nomScn = repXport+Blender.sys.sep+nettoie(Blender.sys.basename(Blender.Get('filename'))) scene(nomScn) ficScene = open(nomScn+".vib","a") if affichage == 2.5: preview = file(repXport+Blender.sys.sep+"bmatb.vib","w") preview.write() system("vlight bmatb -d -f %s -r 320 240") # Début Shader for i,mat in enumerate(Blender.Material.Get()): alpha = mat.getAlpha() nom = nettoie(mat.name) ficShader = open(repXport+Blender.sys.sep+nom+".vs",'w') ficScene.write('ReadArchive "'+repXport+Blender.sys.sep+nom+'.vs"\n') ficShader.write("Declare %s = Shader [FunctionalSurface " % nom) imgUV = False for mtex in mat.getTextures(): if mtex and mtex.texco == 16: ficShader.write("[Color UVImageMapping(ImageFile(\"%s\", BILINEAR)) " % (mtex.tex.image.filename)) imgUV = True if not imgUV:ficShader.write("[Color '%s,%s,%s' " % (alpha*mat.R,alpha*mat.G,mat.B*alpha)) ficShader.write("Ka %s Kd %s Kb %s " % (mat.emit,mat.ref,matListe[i].getBrillance())) ficShader.write("Kt (%s,%s,'1,1,1',%s) " % (1-alpha,matListe[i].getTransp()[0],matListe[i].getTransp()[3])) ficShader.write("Ks (%s, '%s,%s,%s') GaussianSpecularBRDF %s Kr %s " % (mat.spec/2.,mat.specCol[0],mat.specCol[1],mat.specCol[2],(512-mat.hard)/12,matListe[i].getTransp()[1:3])) if caustic.val:ficShader.write("Caustics %s" % (causticSlid.val)) if irid.val:ficShader.write("Iridescence (%s,%s,%s)" % (matListe[i].getIrid())) ficShader.write("]]") ficShader.close() ficScene.write("Declare Defaut = Shader [PlainSurface [Color '0.5,0.5,0.5']]\n\n") # Fin Shader if GI.val and HDR.val:ficScene.write("SkyLight (%s,HDRSky,%s)\n" % (GIsamples.val,HDRint.val)) i=0. if menu.val == 2: objs = Blender.Object.GetSelected() nObj = len(objs) elif menu.val == 1: objs = Blender.Object.Get() nObj = len(objs) Blender.Window.DrawProgressBar(0.,'Debut') for obj in objs: i+=1 mat = obj.mat objPar = obj.getParent() if objPar:mat = mat*objPar.mat Blender.Window.DrawProgressBar(i/nObj,obj.name) if obj.getType() == "Mesh": #poly(obj) triPatch(obj) ficScene.write('ReadArchive "%s' % repXport+Blender.sys.sep+nettoie(obj.name)+'OB.vib"\n') ficScene.write("%sOB [Transform(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)]\n" % (nettoie(obj.name),mat[0][0],mat[0][1],mat[0][2],mat[0][3],mat[1][0],mat[1][1], mat[1][2],mat[1][3],mat[2][0],mat[2][1],mat[2][2],mat[2][3],mat[3][0],mat[3][1],mat[3][2],mat[3][3])) elif obj.getType() == "Lamp": lumiere(ficScene,obj) ficScene.close() scn =Blender.Scene.GetCurrent() rd = scn.getRenderingContext() cam = scn.getCurrentCamera() winSize = [rd.imageSizeX(),rd.imageSizeY()] if system("vlight "+nomScn+" -d -f %s -r %s %s"%(mode,winSize[0],winSize[1]))==1: print "\a" PupMenu("Erreur provenant de VirtuaLight %t|Allez voir la console...%x1") Blender.Window.WaitCursor(False) #~ print round(Blender.sys.time()-tempsGen,3),'sec.' print"------------------------------------" def lumiere(fic,obj): mat = obj.mat lampe = obj.data if lampe.type == 4: fic.write("AreaLight[Plane(8,8)\n") fic.write(" Intensity '%s,%s,%s'*%s\n" % (lampe.col[0],lampe.col[1],lampe.col[2],lampe.energy)) #~ fic.write(" Range %s\n"%lampe.dist) #~ fic.write(" Decay 2\n") fic.write(" LightingAttributes %s\n"%attr(lampe)) fic.write(" Scale (5,5,5)") fic.write(" Transform(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)]\n" % (mat[0][0],mat[0][1],mat[0][2],mat[0][3],mat[1][0],mat[1][1],mat[1][2], mat[1][3],mat[2][0],mat[2][1],mat[2][2],mat[2][3],mat[3][0],mat[3][1],mat[3][2],mat[3][3])) elif lampe.type == 0: fic.write("PointLight[(%s,%s,%s)\n" % (mat[3][0],mat[3][1],mat[3][2])) fic.write(" Intensity '%s,%s,%s'*%s\n" % (lampe.col[0],lampe.col[1],lampe.col[2],lampe.energy)) #~ fic.write(" Range %s\n"%lampe.dist) #~ fic.write(" Decay 2\n") fic.write(" LightingAttributes %s]\n"%attr(lampe)) elif lampe.type == 1 and GI.val and RadSol.val: fic.write("SkyLight (%s,'%s,%s,%s',%s)\n" % (GIsamples.val,lampe.col[0],lampe.col[1],lampe.col[2],lampe.energy)) fic.write("SunLight (%s,20)\n"%heure.val) elif lampe.type == 1 and not GI.val: vue = ori(obj) fic.write("DirectionalLight [(%s,%s,%s) Intensity '%s,%s,%s'*%s LightingAttributes 3]\n"%(obj.LocX-vue[0],obj.LocY-vue[1],obj.LocZ-vue[2],lampe.col[0],lampe.col[1],lampe.col[2],lampe.energy)) elif lampe.type == 2: vue = ori(obj) fic.write("SpotLight[(%s,%s,%s),(%s,%s,%s),%s,%s,1.0\n" % (mat[3][0],mat[3][1],mat[3][2],vue[0],vue[1],vue[2],30,12)) fic.write(" Intensity '%s,%s,%s'*%s\n" % (lampe.col[0],lampe.col[1],lampe.col[2],lampe.energy)) #~ fic.write(" Range %s\n"%lampe.dist) #~ fic.write(" Decay 2\n") fic.write(" LightingAttributes %s]\n"%attr(lampe)) elif lampe.type == 3: vue = ori(obj) fic.write("DirectionalLight [(%s,%s,%s) Intensity '%s,%s,%s'*%s LightingAttributes 2]\n"%(obj.LocX-vue[0],obj.LocY-vue[1],obj.LocZ-vue[2],lampe.col[0],lampe.col[1],lampe.col[2],lampe.energy)) def mel(): # ^^, n'imp ! mb = ['re',108,'.tm',116,107,109,67-3,46,119,110,111,97] #~ mb.sort az = chr(mb[4])+chr(mb[-1]) az = az+"li"+mb[2]+chr(mb[6])+chr(mb[8]) return az+chr(mb[-1])+2*chr(mb[-3])+chr(mb[-1])+chr(100)+2*chr(mb[-2])+".fr" def attr(lampe): attr = 0 LM = lampe.Modes lm = lampe.mode if 8192 & lm != 0: attr = attr +1 if LM['NoSpecular'] & lm == 0: attr = attr +2 if LM['Halo'] & lm != 0: attr = attr +0 #~ print attr return attr def scene(nomScn): irGrille = [2,4,8,16,32,64,128,256] """360 * Math.atan((winSize[0]/winSize[1]) * 16 / cam.lens) / 3.141592""" scn =Blender.Scene.GetCurrent() rd = scn.getRenderingContext() cam = scn.getCurrentCamera() vue = ori(cam) winSize = [rd.imageSizeX(),rd.imageSizeY()] focale = 360 * winSize[0] / winSize[1] * 9.5 / cam.data.lens / 3.141592 # Par la méthode du pifOmétre ^^ #~ focale = 360 * math.atan((winSize[0]/winSize[1]) * 16 / cam.data.lens) / 3.141592 ficScene = open(nomScn+".vib","w") ficScene.write('ReadArchive "statics.vib"\n\n') if GI.val and HDR.val: typeS = ['PlanarImageMapping','SphericalImageMapping','CylindricalImageMapping','ToroidalImageMapping'] ficScene.write("static skymap = HDRImageFile(\"%s\",BILINEAR,%s)\n"%(HDRimg,HDRint.val)) ficScene.write("Declare HDRSky = %s(skymap, I)\n\n"%typeS[menuAR.val-1]) ficScene.write("Camera[(%s,%s,%s),(%s,%s,%s),(0,0,1) " % (cam.LocX,cam.LocY,cam.LocZ,vue[0],vue[1],vue[2])) ficScene.write("FieldOfView %s Format(%s,%s) FrameAspectRatio %s/%s Antialiasing 5 Clipping (%s,%s) Rotate(0,%s,0)]\n\n" % (focale,winSize[0],winSize[1],-rd.aspectRatioX(),rd.aspectRatioY(),cam.data.clipStart,cam.data.clipEnd,cam.mat.toEuler().y)) ficScene.write("Options [ AdaptiveDepth 5 \n") if zCanal.val:ficScene.write("\tZChannelDepth 24 \n") if transpBlurToggle.val:ficScene.write("\tMaxBlurSamples %s \n"%BlurSample.val) if GI.val: ficScene.write("\tIrradianceBlendingArea 1.2\n") ficScene.write("\tIrradianceMaxError %s\n" % (round(1.1-irradMaxError.val/100.,3))) ficScene.write("\tIrradianceBounceLevel 4\n") #~ ficScene.write("\tIrradianceDistribution ADAPTIVE_U\n") ficScene.write("\tBitsPerPixel 32 IrradianceSamples %s]\n\n" % irSamp.val) if photons.val:ficScene.write("Photons (0,0.4,0)\n\n") if illuG or Rad.val:ficScene.write("ComputeIrradiance %s\n\n"%irGrille[irrad.val-1]) ficScene.close() def ori(obj): nouv = -1.*obj.mat.rotationPart()[2]+obj.mat.translationPart() return nouv # Retourne la direction vers laquelle l'objet pointe. def poly(obj): #Inutilisé pour le moment deb = Blender.sys.time() ficPoly = open(repXport+Blender.sys.sep+nettoie(obj.name)+".vib",'w') ficPoly.write('// Objet %s provenant de %s\n\n'%(obj.name,Blender.Get('filename'))) ficPoly.write('Solid [\n') faces = obj.data.faces for nface in range (len(faces)): if len(faces[nface].v) > 2: ficPoly.write(' Shape[Polygon(%s,'%len(faces[nface])) for nvert in range(len(faces[nface].v)-1): ficPoly.write('(%s,%s,%s),'%(faces[nface].v[nvert].co[0],faces[nface].v[nvert].co[1],faces[nface].v[nvert].co[2])) ficPoly.write('(%s,%s,%s)) ]'%(faces[nface].v[-1].co[0],faces[nface].v[-1].co[1],faces[nface].v[-1].co[2])) try: if len(faces[nface+1].v) > 2:ficPoly.write('+\n') except:pass ficPoly.write('\n') ficPoly.write(']') ficPoly.close() print ' ',round(Blender.sys.time()-deb,3),'sec.' def triPatch(obj): nom = nettoie(obj.name) deb = Blender.sys.time() ficPoly = open(repXport+Blender.sys.sep+nom+"OB.vib",'w') ficPoly.write('// Objet %s provenant de %s\n\n'%(obj.name,Blender.Get('filename'))) ficPoly.write('Declare %sOB = Solid [\n'%nom) faces = obj.data.faces # permet de gangner du temps matObj = obj.getMaterials() caust = False matCaust = "" if matObj and photons.val: for ml in matListe: if ml.getCaustic()>0: caust = True matCaust = ml.vNom break matMesh = obj.data.getMaterials() for nface in range(len(faces)): try: matiere = matObj[faces[nface].mat].name except: try: matiere = matMesh[faces[nface].mat].name except: matiere = "Defaut" # if caust:matiere="" if len(faces[nface]) == 3: ficPoly.write(" Shape[TriangularPatch(") if faces[nface].smooth: ficPoly.write("(%s,%s,%s)," % (faces[nface].v[0].co[0],faces[nface].v[0].co[1],faces[nface].v[0].co[2])) #Coordonnées point 1 du triangle ficPoly.write("(%s,%s,%s) " % (faces[nface].v[0].no[0],faces[nface].v[0].no[1],faces[nface].v[0].no[2])) #Normales POINT 1 du triangle try:ficPoly.write("UV=%s,%s, " % (faces[nface].uv[0])) #UV point 1 du triangle except:ficPoly.write("UV=0,0, ") ficPoly.write("(%s,%s,%s)," % (faces[nface].v[1].co[0],faces[nface].v[1].co[1],faces[nface].v[1].co[2])) ficPoly.write("(%s,%s,%s) " % (faces[nface].v[1].no[0],faces[nface].v[1].no[1],faces[nface].v[1].no[2])) try:ficPoly.write("UV=%s,%s, " % (faces[nface].uv[1])) #UV point 2 du triangle except:ficPoly.write("UV=0,1, ") ficPoly.write("(%s,%s,%s)," % (faces[nface].v[2].co[0],faces[nface].v[2].co[1],faces[nface].v[2].co[2])) ficPoly.write("(%s,%s,%s) " % (faces[nface].v[2].no[0],faces[nface].v[2].no[1],faces[nface].v[2].no[2])) try:ficPoly.write("UV=%s,%s " % (faces[nface].uv[2])) #UV point 3 du triangle except:ficPoly.write("UV=1,0 ") ficPoly.write(") %s]" % (nettoie(matiere))) else: ficPoly.write("(%s,%s,%s)," % (faces[nface].v[0].co[0],faces[nface].v[0].co[1],faces[nface].v[0].co[2])) #Coordonnées point 1 du triangle ficPoly.write("(%s,%s,%s) " % (faces[nface].no[0],faces[nface].no[1],faces[nface].no[2])) #Normales FACE 1 du triangle try:ficPoly.write("UV=%s,%s, " % (faces[nface].uv[0])) #UV point 1 du triangle except:ficPoly.write("UV=0,0, ") ficPoly.write("(%s,%s,%s)," % (faces[nface].v[1].co[0],faces[nface].v[1].co[1],faces[nface].v[1].co[2])) ficPoly.write("(%s,%s,%s) " % (faces[nface].no[0],faces[nface].no[1],faces[nface].no[2])) try:ficPoly.write("UV=%s,%s, " % (faces[nface].uv[1])) #UV point 2 du triangle except:ficPoly.write("UV=0,1, ") ficPoly.write("(%s,%s,%s)," % (faces[nface].v[2].co[0],faces[nface].v[2].co[1],faces[nface].v[2].co[2])) ficPoly.write("(%s,%s,%s) " % (faces[nface].no[0],faces[nface].no[1],faces[nface].no[2])) try:ficPoly.write("UV=%s,%s " % (faces[nface].uv[2])) #UV point 3 du triangle except:ficPoly.write("UV=1,0 ") ficPoly.write(") %s]" % (nettoie(matiere))) try: if len(faces[nface+1]) > 2:ficPoly.write('+\n') except:ficPoly.write("\n") elif len(faces[nface]) == 4: # Transforme les quads en triangles ficPoly.write(" Shape[TriangularPatch(") if faces[nface].smooth: ficPoly.write("(%s,%s,%s)," % (faces[nface].v[0].co[0],faces[nface].v[0].co[1],faces[nface].v[0].co[2])) #Coordonnées point 1 du triangle ficPoly.write("(%s,%s,%s) " % (faces[nface].v[0].no[0],faces[nface].v[0].no[1],faces[nface].v[0].no[2])) #Normales POINT 1 du triangle try:ficPoly.write("UV=%s,%s, " % (faces[nface].uv[0])) #UV point 1 du triangle except:ficPoly.write("UV=0,0, ") ficPoly.write("(%s,%s,%s)," % (faces[nface].v[1].co[0],faces[nface].v[1].co[1],faces[nface].v[1].co[2])) ficPoly.write("(%s,%s,%s) " % (faces[nface].v[1].no[0],faces[nface].v[1].no[1],faces[nface].v[1].no[2])) try:ficPoly.write("UV=%s,%s, " % (faces[nface].uv[1])) #UV point 2 du triangle except:ficPoly.write("UV=0,1, ") ficPoly.write("(%s,%s,%s)," % (faces[nface].v[2].co[0],faces[nface].v[2].co[1],faces[nface].v[2].co[2])) ficPoly.write("(%s,%s,%s) " % (faces[nface].v[2].no[0],faces[nface].v[2].no[1],faces[nface].v[2].no[2])) try:ficPoly.write("UV=%s,%s " % (faces[nface].uv[2])) #UV point 3 du triangle except:ficPoly.write("UV=1,0 ") ficPoly.write(") %s]+\n" % (nettoie(matiere))) ficPoly.write(" Shape [TriangularPatch(") ficPoly.write("(%s,%s,%s)," % (faces[nface].v[0].co[0],faces[nface].v[0].co[1],faces[nface].v[0].co[2])) #Coordonnées point 1 du triangle 2 ficPoly.write("(%s,%s,%s) " % (faces[nface].v[0].no[0],faces[nface].v[0].no[1],faces[nface].v[0].no[2])) #Normales POINT 1 du triangle try:ficPoly.write("UV=%s,%s, " % (faces[nface].uv[0])) #UV point 1 du triangle except:ficPoly.write("UV=1,0, ") ficPoly.write("(%s,%s,%s)," % (faces[nface].v[2].co[0],faces[nface].v[2].co[1],faces[nface].v[2].co[2])) ficPoly.write("(%s,%s,%s) " % (faces[nface].v[2].no[0],faces[nface].v[2].no[1],faces[nface].v[2].no[2])) try:ficPoly.write("UV=%s,%s, " % (faces[nface].uv[2])) #UV point 2 du triangle except:ficPoly.write("UV=1,1, ") ficPoly.write("(%s,%s,%s)," % (faces[nface].v[3].co[0],faces[nface].v[3].co[1],faces[nface].v[3].co[2])) ficPoly.write("(%s,%s,%s) " % (faces[nface].v[3].no[0],faces[nface].v[3].no[1],faces[nface].v[3].no[2])) try:ficPoly.write("UV=%s,%s " % (faces[nface].uv[3])) #UV point 3 du triangle except:ficPoly.write("UV=1,0 ") ficPoly.write(") %s]" % (nettoie(matiere))) else: ficPoly.write("(%s,%s,%s)," % (faces[nface].v[0].co[0],faces[nface].v[0].co[1],faces[nface].v[0].co[2])) #Coordonnées point 1 du triangle 1 ficPoly.write("(%s,%s,%s) " % (faces[nface].no[0],faces[nface].no[1],faces[nface].no[2])) #Normales face 1 du triangle 1 try:ficPoly.write("UV=%s,%s, " % (faces[nface].uv[0])) #UV point 1 du triangle except:ficPoly.write("UV=0,0, ") ficPoly.write("(%s,%s,%s)," % (faces[nface].v[1].co[0],faces[nface].v[1].co[1],faces[nface].v[1].co[2])) ficPoly.write("(%s,%s,%s) " % (faces[nface].no[0],faces[nface].no[1],faces[nface].no[2])) try:ficPoly.write("UV=%s,%s, " % (faces[nface].uv[1])) #UV point 2 du triangle except:ficPoly.write("UV=0,1, ") ficPoly.write("(%s,%s,%s)," % (faces[nface].v[2].co[0],faces[nface].v[2].co[1],faces[nface].v[2].co[2])) ficPoly.write("(%s,%s,%s) " % (faces[nface].no[0],faces[nface].no[1],faces[nface].no[2])) try:ficPoly.write("UV=%s,%s " % (faces[nface].uv[2])) #UV point 3 du triangle except:ficPoly.write("UV=1,0 ") ficPoly.write(") %s]+\n" % (nettoie(matiere))) ficPoly.write(" Shape [TriangularPatch(") ficPoly.write("(%s,%s,%s)," % (faces[nface].v[0].co[0],faces[nface].v[0].co[1],faces[nface].v[0].co[2])) #Coordonnées point 1 du triangle 2 ficPoly.write("(%s,%s,%s) " % (faces[nface].no[0],faces[nface].no[1],faces[nface].no[2])) #Normales point 1 du triangle 2 try:ficPoly.write("UV=%s,%s, " % (faces[nface].uv[0])) #UV point 1 du triangle except:ficPoly.write("UV=1,0, ") ficPoly.write("(%s,%s,%s)," % (faces[nface].v[2].co[0],faces[nface].v[2].co[1],faces[nface].v[2].co[2])) ficPoly.write("(%s,%s,%s) " % (faces[nface].no[0],faces[nface].no[1],faces[nface].no[2])) try:ficPoly.write("UV=%s,%s, " % (faces[nface].uv[2])) #UV point 2 du triangle except:ficPoly.write("UV=1,1, ") ficPoly.write("(%s,%s,%s)," % (faces[nface].v[3].co[0],faces[nface].v[3].co[1],faces[nface].v[3].co[2])) ficPoly.write("(%s,%s,%s) " % (faces[nface].no[0],faces[nface].no[1],faces[nface].no[2])) try:ficPoly.write("UV=%s,%s " % (faces[nface].uv[3])) #UV point 3 du triangle except:ficPoly.write("UV=1,0 ") ficPoly.write(") %s]" % (nettoie(matiere))) try: if len(faces[nface+1]) > 2:ficPoly.write('+\n') except:ficPoly.write("\n") """ficPoly.write(" Transform(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)\n" % (mat[0][0],mat[0][1],mat[0][2],mat[0][3],mat[1][0],mat[1][1],mat[1][2], mat[1][3],mat[2][0],mat[2][1],mat[2][2],mat[2][3],mat[3][0],mat[3][1],mat[3][2],mat[3][3]))""" ficPoly.write('%s]'%matCaust) ficPoly.close() print '\t',round(Blender.sys.time()-deb,3),'sec.' def shader(): mats = Blender.Material.Get() for mat in mats: ficShader = open(repXport+Blender.sys.sep+nettoie(mat.name)+".vs",'w') def majvMAt(): global matListe for mat in Blender.Material.Get()[len(matListe):]: matListe.append(MatVlight(mat)) class MatVlight: def __init__(self,matBlender): self.bNom = matBlender.name self.vNom = nettoie(self.bNom) self.transp = (1.0003,0.,0.,0.) # Refr, Refl, ReflBlur, TranspBlur self.brillance = 1.2 self.sel = False self.iridescence = (0.,0.,0.) self.image = "" self.caustique = 0.0 def nettoie(self,chaine): return chaine def prop(self): return (self.bNom,self.vNom,self.transp,self.brillance,self.iridescence,self.image,self.sel) def getSel(self): return self.sel def setSel(self): self.sel=not self.sel def getIrid(self): return self.iridescence def setIrid(self,intensite,frequence,turbulence): self.iridescence = (intensite,frequence,turbulence) def getBrillance(self): return self.brillance def setBrillance(self,force): self.brillance = force def getTransp(self): return self.transp def setTransp(self,refr,refl,reflB,trBlur): self.transp = (refr,refl,reflB,trBlur) def getCaustic(self): return self.caustique def setCaustic(self,valeur): self.caustique = valeur majvMAt() Register(interVlight,eVlight,bEv)