#!BPY
""" Registration info for Blender menus:
Name: 'VirtuaLight 1.4'
Blender: 23x
Group: 'Misc'
---Start cutting here ---
Checked with Blender 2.31~2.36 python 2.23, 2.3
Some tips by Burt.S.
decex@poczta.onet.pl:
1. Download Virtual Light 1.4 with rich documentation from http://www.virtualight.com.
2. Linux and BSD, Uni(x) users should just download CrossoverOffice or wine/x/Cedega recomended/
to launch it![Succesfully tested with Debian, Slackware, FreeBSD 5.0].
3. Explore network, download MS Windows trial versions [win 95/98] to install VLight with it,than
get full registry with keys you need, copy "regedit.exe" and all windows tools from trial and use it with your wine.
4. Use regedit.exe with wine to copy keys or import full *.reg file to your wine.
5. Use Crossover Office *.config files as best source of tricks to configure your self compilated,
more stable wine server. To implement DirectX to your own wine compilation just install DX with your trial
windo(z) and, use emacs to listen and log all changes made by DX setup, and implement all instaled components,
registry and files to your wine, just watch differences inside your trial windows before and after installing DX.
All you need to get them and force to work is emacs.
6. Remember about correct --winver [3.1/95/98/NT] parameter during wineserver launch from your shell
level to match your registry version'. Watch out at your Xterm perrmisions. It should be chowned by root and Xterm's [PID] should have root priviledges.
Check it with "ps aux" [shift+PgUp/PgDn] to rewind listing, or another processes listener f.e."gps".
7. To overcome problems with kernel 2.6.x or 2.6.xx and Nvidia GLX ask me for more bash scripts to launch Virtua Light and another Window(z) only apps with GL support. On below should resolve 90% of your problems:
--------
#! /bin/bash
LD_PRELOAD=/usr/lib/libGL.so.1 yourbin
--------
than
#chmod 777 yourbashscript
than
#ls -s /usr/.../yourbinbashscript /usr/bin/yourbashscript
8. Hit 'alt+p' to run VlightTunnel script from blender text editor.
9. Before exporting save your scene.
10. Touch "r" to export with Raytracing render method as default, touch "O" to export with OpenGL rendering method.
11. Scripts expors scene to separated files with scene *.vib, geometry archive *.vib, and shaders *.vs.
12. For large files use emacs. To get all goods from files that comes with VLight1.4 xplore them.
13. To understand powerfull Render Man standard go to http://www.3delight.com and get all *.pdf books, docs,
everything what you can find and was written by Lary Gritz and Tony Apodaca, than go to http://www.renderman.org
and look for more Siggraph courses'
14. Virtua Light brings to you quality close to Realistic Render Man for free. It's worth to use it if you're fastinated in proffesionall cinematic technologies
used by f.e. Disney's Studios and motion pictures.
15. to make script lighter cut all my comments above.
16. Remind me to bring you exporter version with english, german, russian languages support.
#'DONT EVEN TRY TO PARSE THIS SCRIPT TROUGHT NETWORK TRANSLATORS.IT'LL BE BROKEN IMMEDIATELLY'
#'I KNOW, THAT YOU DID IT OR YOU'LL TRY IT. DOWNLOAD IT AGAIN OR DO RESCUE COPY BEFORE :)'
---Stop cutting here ---
"""
## 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
#linux/BSD/Uni(x) users without time.py module may need to hash it
#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)
# linux/BSD users may need to hash it
#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)/15<len(matListe):nColonne = (haut-80)/15
else:nColonne = len(matListe)
for i in range(nColonne):
pos = haut-25-15*i
if posUp/15>0:i+=posUp/15
try:
if (pos<ySouris<pos+15 and clic):
matListe[i].setSel()
glColor3f(1,0.4,0)
clic = False
elif matListe[i].getSel():glColor3f(0.8,0.5,0.2)
else:glColor3f(0.3+paire/3.,0.3+paire/3.,0.3+paire/3.)
except:pass
paire =not paire
glBegin(GL_QUADS)
glVertex2d(20,pos+10);glVertex2d(400,pos+10)
glVertex2d(400,pos-5);glVertex2d(20,pos-5)
glEnd()
glColor3f(0.8,0.9,1)
glRasterPos2i(20,pos)
try:
tailleS = GetStringWidth(matListe[i].bNom)
if matListe[i].getSel():
Text("\t"+matListe[i].bNom)
glRasterPos2i(50+tailleS,pos)
Text(str(matListe[i].getTransp()))
else:
Text(matListe[i].bNom)
glRasterPos2i(40+tailleS,pos)
Text(str(matListe[i].getTransp()))
except:break
elif affichage == 2.5:
refrSlid = Slider("Refraction: ", 10, max[2]/2-150, max[3]-290, 300, 18, refrSlid.val, 0.5, 2., 0)
reflSlid = Slider("Reflection: ", 15, max[2]/2-150, max[3]-310, 300, 18, reflSlid.val, 0., 1., 0)
if transpBlurToggle.val:
glRasterPos2i(max[2]/2-20,max[3]-55)
Text(":: Flou ::")
refBlurSlid = Slider("Reflection floue: ", 20, max[2]/2-150, max[3]-120, 300, 18, refBlurSlid.val, 0., 1., 0)
transpBlurSlid = Slider("Transparence floue: ", 21, max[2]/2-150, max[3]-100, 300, 18, transpBlurSlid.val, 0., 1., 0)
BlurSample = Number("Echantillons: ", 22, max[2]/2-60, max[3]-80, 120, 18, BlurSample.val, 1, 20,"")
if caustic.val:
glRasterPos2i(max[2]/2-30,max[3]-145)
Text(":: Caustiques ::")
causticSlid = Slider("Densite: ", 30, max[2]/2-150, max[3]-170, 300, 18, causticSlid.val, 0., 1., 0)
if irid.val:
glRasterPos2i(max[2]/2-30,max[3]-195)
Text(":: Iridescence ::")
iridSlid = Slider("Intensite: ", 40, max[2]/2-150, max[3]-220, 300, 18, iridSlid.val, 0., 1., 0)
iridFreqSlid = Slider("Frequence: ", 41, max[2]/2-150, max[3]-240, 300, 18, iridFreqSlid.val, 0., 1., 0)
iridTurbSlid = Slider("Turbulence: ", 42, max[2]/2-150, max[3]-260, 300, 18, iridTurbSlid.val, 1., 2., 0)
elif affichage == 3:
glRasterPos2i(max[2]/2-40,max[3]/2)
Text("Type :")
menuAR = Menu("Type%t|Plat%x1|Sperique%x2|Cylindrique%x3|Torique%x4", 98, max[2]/2,max[3]/2-5, 100, 18, menuAR.val)
else:
zCanal = Toggle("", 1, 5, 40, 10, 18, zCanal.val, "Enregistre la passe de profondeur dans un autre fichier")
glRasterPos2i(20, 45)
if zCanal.val:Text("Alpha separe")
else:Text("pas d'Alpha")
glRasterPos2i(20, max[3]/2)
Text("Exporter ")
menu = Menu('Objets%t|tous les objets%x1|la selection d\'objets%x2',97,75,max[3]/2-5,140,20,menu.val)
dirCouleur = 0
def eVlight(evt,val):
global illuG,affichage,r,g,b,matListe,clic
#~ optMenu = ['O','-']
if (evt == QKEY and not val):del matListe;Exit()
elif (evt == LEFTMOUSE and val):clic =True;Draw()
elif (evt == PADENTER and not val):
if affichage == 2:sauve();affichage=2.5;Draw()
elif affichage == 2.5:valid();affichage=2;Draw()
elif (evt==UPARROWKEY and val): up(5);Draw()
elif (evt==DOWNARROWKEY and val):down(5);Draw()
elif (evt==PAGEUPKEY and val):up(20);Draw()
elif (evt==PAGEDOWNKEY and val):down(20);Draw()
elif (evt==DOWNARROWKEY and not val):Draw()
elif (evt==UPARROWKEY and not val):Draw()
elif (evt==PAGEDOWNKEY and not val):Draw()
elif (evt==PAGEUPKEY and not val):Draw()
elif (evt == RKEY and not val):lanceRendu('')# Rendu Raytracing
elif (evt == OKEY and not val):lanceRendu('-h 1')# Rendu type 'OpenGL'
elif (evt == 3 and not val):affichage = PupMenu("Options%t|"+"Illumination|Materiaux|Arriere plan");Draw()
def bEv(evt):
if evt == 1:Draw();print '1' #Canal Z Toggle
elif evt == 2:Draw();print '2' #GI Toggle
elif evt == 3:HDR.val=0;RadSol.val=0;print '3' #Radiosité Toggle
elif evt == 4:HDR.val=0;Rad.val=0;print '4' #DayLight Toggle
elif evt == 5:RadSol.val=0;Rad.val=0;print '5' #HDRI Toggle
elif evt == 6:Draw();print '6' #Irrad. Max Error Number
elif evt == 7:Draw();print '7' #DayLight Samples Number
elif evt == 8:validHeure(heure.val);Draw();print '8' #Heure String
elif evt == 9:Draw();print '10' #HDR intensité Number
elif evt == 10:Draw();print '11' #Réfraction Slider
elif evt == 11:Draw();print '12' #Flou Toggle
elif evt == 12:Draw();print '13' #Iridescence Toggle
elif evt == 13:Draw();print '14' #Caustique Toggle
elif evt == 14:Blender.Window.FileSelector(HDRep,"*.hdr") #Image HDR PushButton
elif evt == 15:Draw();print '15' #Rélexion Slider
elif evt == 19:Blender.Window.FileSelector(rep,"OK") #RepXport PushButton
elif evt == 20:Draw();print '16' #Rélexion floue Slider
elif evt == 21:Draw();print '17' #Transparence floue Slider
elif evt == 22:Draw();print '18' #Echantillons de flou Number
elif evt == 30:Draw();print '19' #Caustic densité Slider
elif evt == 40:Draw();print '20' #Irrid. Intensité Slider
elif evt == 41:Draw();print '21' #Irrid. Frequence Slider
elif evt == 42:Draw();print '22' #Irrid. Turbulence Slider
elif evt == 80:Draw();print '23' #Photons caustiques Toggle
elif evt == 97:Draw();print '24' #Sélection d'objets Menu
elif evt == 98:Draw();print '25' #Sélection d'arr. plan Menu
elif evt == 457:aide(affichage)
Draw()
def aide(ecr):
if ecr == 1:PupMenu("L'illumination globale%t|%l|VirtuaLight propose plusieurs methodes d'illumination :%x1|%l|- L'irradiance%x2|meme principe que dans Blender%x3|les objets emettent de la lumiere...%x4|%l|- La radiosite solaire%x5|radiosite dependant de la position du soleil%x6|les horaires d'ouverture vont de 6h a 18h ^^%x7|%l|- L'HDRI%x8|illumination basee sur une image HDR...%x9|%l|L'option 'Photons' active le calcul des caustiques%x10|")
elif ecr == 2:PupMenu("Matieres%t|%l|Ici apparait la liste des materiaux de la scene%x1|Selectionner un materiau, puis 'touche pave-entree' pour acceder a ses proprietes%x2|Pour valider les changements appuyer a nouveau sur 'touche pave-entree'%x3|%l|Vous pouvez selectionner plusieurs matieres afin de changer une proprietes communes%x4|Les matieres selectionnes sont decalee legerement sur la droite et sont surlignee en orange clair%x5|Faites 'touche pave-entree' pour acceder a leurs proprietes%x6|Ne bougez que les curseurs qu'elles ont en commun et valider avec 'touche pave-entree'%x7|%l|Les boutons, en bas a gauche, permmettent de rajouter des proprietes supplementaires%x8|Par exemple :%x9|- Pour rajouter des caustiques, enfoncer le bouton caustique%x10|- Selectionner le/les matieres%x11|- Appuyer sur 'touche pave-entree'%x12|- Regler le curseur Densite %x13|- Valider en appuyant sur 'touche pave-entree'%x14|Puis faites un rendu...%x15|Si aucun caustique n'apparait...c'est normal ! ^^%x16|Il faut activer les 'photons' dans les options d'Illumination%x17|ET%x18|Il faut que la matiere puisse en emettre :%x19|Les caustiques n'apparaissent que sur des matieres transparentes et/ou reflechissante !%x20|La matiere doit etre en mode 'OB' et non pas 'ME'%x21|%l|Les seuls textures acceptees sont les textures UV%x22|Il faut mettre la texture en mode 'UV' dans 'MapInput'%x23")
elif ecr == 3:PupMenu("Options de l'arriere plan%t|%l|Vous pouvez regler ici la projection des images d'arriere plan%x1|Pour le moment seul l'HDRi permet d'afficher un arriere plan%x2")
elif ecr == -1:PupMenu("Accueil%t|%l|Trois options apparaissent :%x1|- 'Exporter' qui permet de choisir quels objets doivent etre exporter%x1|(ne pas oublier d'exporter au moins une lampe)%x2|%l|- 'Alpha' permet d'enregistrer dans un tga separe le canal alpha%x3|%l|- 'Repertoire d'export' permet de selectionner un repertoire ou seront mis les fichier .vib et .vs%x4|ne pas oublier de faire le menage dans les .vib%x5|%l|Presser la 'touche o' pour effectuer un rendu de test%x6|La 'touche r' permet de lancer un 'vrai' rendu, l'image sera sauvegarder dans le repertoire d'export au format TGA%x7|%l|Pour acceder a d'autres options : faire un 'clic droit'%x7|Pour revenir a tout moment sur cette page, faire 'clic droit' et deplacer la souris loin du menu%x8|%l|En cas de probleme :%x9|- pour arreter un rendu, il faut fermer la fenetre de rendu 'Rendering Window'%x10|ainsi seul VirtuaLight sera ferme.%x11|- Il est deconseille d'arreter le rendu en faisant un 'break' dans la console%x12|et encore plus de fermer la console (Blender et VirtuaLight se fermeront tous les deux)%x13|%l|%l|Vous pouvez toujours poser vos questions sur :%x14|Le forum du www.Blender.Clan.st%x15|Ou m'envoyer un mail : "+mel()+"%x16|Les nouvelles versions de ce script seront disponibles sur le Blender.Clan, rubrique telechargement.%x17" )
def sauve():
# Juste un test du module Registry
matDict = {"refr":refrSlid.val,
"refl":reflSlid.val,
"refBlur":refBlurSlid.val,
"transpBlur":transpBlurSlid.val,
"caust":causticSlid.val,
"Irid":iridSlid.val,
"IridFreq":iridFreqSlid.val,
"IridTurb":iridTurbSlid.val}
Blender.Registry.SetKey("matieres",matDict)
def valid():
# Juste un test du module Registry
matDict = Blender.Registry.GetKey("matieres")
for mat in matListe:
if mat.getSel():
if round(refrSlid.val,4) != round(matDict["refr"],4):a=round(refrSlid.val,3)
else:a=round(mat.getTransp()[0],3)
if round(reflSlid.val,4) != round(matDict["refl"],4):b=round(reflSlid.val,3)
else:b=round(mat.getTransp()[1],3)
if round(refBlurSlid.val,4) != round(matDict["refBlur"],4):c=round(refBlurSlid.val,3)
else:c=round(mat.getTransp()[2],3)
if round(transpBlurSlid.val,4) != round(matDict["transpBlur"],4):d=round(transpBlurSlid.val,3)
else:d=round(mat.getTransp()[3],3)
mat.setTransp(a,b,c,d)
if round(iridSlid.val,4) != round(matDict["Irid"],4):a=round(iridSlid.val,3)
else:a=round(mat.getIrid()[0],3)
if round(iridFreqSlid.val,4) != round(matDict["IridFreq"],4):b=round(iridFreqSlid.val,3)
else:b=round(mat.getIrid()[1],3)
if round(iridTurbSlid.val,4) != round(matDict["IridTurb"],4):c=round(iridTurbSlid.val,3)
else:c=round(mat.getIrid()[2],3)
mat.setIrid(a,b,c)
if round(causticSlid.val,4) != round(matDict["caust"],4):mat.setCaustic(round(causticSlid.val,3))
else:mat.setCaustic(round(mat.getCaustic(),3))
mat.setSel()
def validHeure(horaire):
if len(horaire) == 4 and horaire[:2].isdigit() and horaire[2:4].isdigit():
heure.val = horaire[:2]+":"+horaire[-2:]
elif len(horaire) == 3 and int(horaire[:2]) > 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<len(matListe)*14+5:posUp+=num
r,g,b=0,0.1*num,0
def nettoie(nom):
propre = ''
for nLettre in range(len(nom)):
if ((ord(nom[nLettre]) > 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)