-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathyafaray_ui.py
2880 lines (2377 loc) · 123 KB
/
yafaray_ui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!BPY
"""
Name: 'YafaRay Export 0.1.x'
Blender: 249
Group: 'Render'
Tooltip: 'YafaRay Export'
"""
__author__ = ['Bert Buchholz, Alvaro Luna, Michele Castigliego, Rodrigo Placencia']
__version__ = '0.1.x-GSoC-Ryen'
__url__ = ['http://yafaray.org']
__bpydoc__ = ""
# import order IS important for sys.path.append seemingly
import sys
import os
import platform
import Blender
# Enter the abolsute path to the YafaRay directory or the relative path
# (as seen from Blender.exe)
# If you have a directory structure like this:
#
# ,- Blender (containing Blender.exe)
# +- YafaRay
# + ...
#
# then set dllPath = "..\\YafaRay\\"
# dllPath = "..\\YafaRay\\"
dllPath = ""
pythonPath = ""
haveQt = True
_SYS = platform.system()
if _SYS == 'Windows':
if dllPath == "":
import _winreg
regKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'Software\\YafRay Team\\YafaRay')
dllPath = _winreg.QueryValueEx(regKey, 'InstallDir')[0] + '\\'
if pythonPath == "":
pythonPath = dllPath + 'python\\'
from ctypes import cdll
dlls = ['Iex','Half','IlmThread','IlmImf','mingwm10','libfreetype-6','iconv','libxml2','libtiff3','yafaraycore', 'yafarayplugin', 'libpng14d', 'jpeg62']
qtDlls = ['QtCore4', 'QtGui4', 'yafarayqt']
if os.path.exists(dllPath + 'yafarayqt.dll'):
dlls += qtDlls
else:
haveQt = False
print "WARNING: Qt GUI will NOT be available."
for dll in dlls:
print "Loading DLL: " + dllPath + dll + '.dll'
cdll.LoadLibrary(dllPath + dll + '.dll')
dllPath = str(dllPath + 'plugins\\')
# append a non-empty pythonpath to sys
if pythonPath != "":
pythonPath = os.path.normpath(pythonPath)
sys.path.append(pythonPath)
# assume for all non-windows systems unix-like paths,
# add search paths for the scripts
if _SYS != 'Windows':
if pythonPath == "":
searchPaths = []
searchPaths.append(os.environ['HOME'] + '/.blender/scripts/yafaray/')
searchPaths.append('/usr/local/share/yafaray/blender/')
searchPaths.append('/usr/share/yafaray/blender/')
searchPaths.append(Blender.Get('scriptsdir') + '/yafaray/')
for p in searchPaths:
if os.path.exists(p):
sys.path.append(p)
if haveQt:
try:
import yafqt
except:
haveQt = False
print "WARNING: Importing yafqt failed, Qt GUI will NOT be available."
import string
import math
import yaf_export
from yaf_export import yafrayRender
import yafrayinterface
from Blender import *
yaf_export.haveQt = haveQt
yRender = yafrayRender()
yInterface = yafrayinterface.yafrayInterface_t()
yInterface.loadPlugins(dllPath)
#####################################
#
# Utility functions
#
#####################################
# compare the version of the script against that of the interface _only_
# if we have a release version number (i.e. MAJOR.MINOR.SOMETHING)
def checkVersion(ver):
interfaceVersion = yInterface.getVersion()
verNumbers = interfaceVersion.split('.')
if verNumbers != None:
if len(verNumbers) == 3:
# print "intVer", interfaceVersion, "ver", ver
if interfaceVersion != ver:
return [False, interfaceVersion]
return [True, interfaceVersion]
uniqeCounter = 0
def getUniqueValue():
global uniqeCounter
uniqeCounter += 1
return uniqeCounter
def drawHLine(x, y, width):
BGL.glColor3f(0,0,0)
BGL.glBegin(BGL.GL_LINES)
BGL.glVertex2i(x, y)
BGL.glVertex2i(x + width, y)
BGL.glEnd()
def drawSepLine(x, y, width):
y -= 15
drawHLine(x, y, width)
y -= 25
return y
def drawSepLineText(x, y, width, text):
y -= 15
drawText(x, y - 3, text)
width = width - 5 - Draw.GetStringWidth(text, "small")
drawHLine(x + Draw.GetStringWidth(text, "small") + 5, y, width)
y -= 25
return y
def drawText(x, y, text, size = "small"):
BGL.glRasterPos2i(x, y)
Draw.Text(text, size)
def drawTextLine(x, y, text, size = "small"):
BGL.glRasterPos2i(x, y)
Draw.Text(text, size)
y -= 13;
return y
# draw a complete paragraph, lines will be on wordlength longer than maxWidth
def drawTextParagraph(x, y, maxWidth, text, size = "small"):
BGL.glRasterPos2i(x, y)
words = string.split(text, ' ')
length = 0
line = ""
i = 0
for w in words:
line += w + " "
length = Draw.GetStringWidth(line, size)
if i < len(words)-1:
lenNextWord = Draw.GetStringWidth(words[i+1], size)
else: lenNextWord = 0
if length + lenNextWord > maxWidth:
y = drawTextLine(x, y, line, size)
line = ""
length = 0
if w == '\n':
y = drawTextLine(x, y, line, size)
line = ""
length = 0
i += 1
y = drawTextLine(x, y, line, size)
return y
# create a menu string for blender draw.menu out of a list of strings
def makeMenu(text, list):
i = 0
MenuStr = text + "%t|"
for c in list:
MenuStr += c + " %x" + str(i) + "|"
i = i + 1
return MenuStr
def copyParams(source, target):
for p in source:
if not target.has_key(p):
target[p] = source[p]
def copyParamsOverwrite(source, target):
for p in source:
try:
# print "no problem with: ", source, target, p, source[p], target[p]
target[p] = source[p]
except:
print "problem with: ", source, target, p, source[p]
target[p] = 0.0
def setParam(gui, key, poly, field):
# poly is either a list or the initVal (latter here not needed)
if type(poly) == list:
field[key] = poly[gui.val]
else:
field[key] = gui.val
def setGUIVals(gui, key, poly, field):
# poly is either a list or the initial value (latter here not needed)
# print gui, key, poly, field
if type(poly) == list: # lists (for menus)
if field.has_key(key):
# need this exception handling in case a list item has been set that has been removed in the meantime (for example,
# a material has been renamed or deleted from the Blend file)
try:
gui.val = poly.index(field[key])
except:
gui.val = 0
elif type(poly) == tuple: # color
if field.has_key(key):
gui.val = (field[key][0], field[key][1], field[key][2])
elif type(poly) == str: # string
if field.has_key(key):
gui.val = field[key][:]
else: # ints, floats
if field.has_key(key):
gui.val = field[key]
# checks if key exists in field and if not, create property and assign initial value
def checkParam(gui, key, poly, field):
try:
if not field.has_key(key):
if type(poly) == list: # lists (for menus)
field[key] = poly[0]
else: # ints, floats, strings, colors etc.
field[key] = poly
except:
pass
# A standin function to give to Draw.Number. For some weird reason it does not
# except a simple None
def dummyfunc(*args):
pass
# ### tab material ### #
# TODO: experimental new structure, fubar atm
class BlendMat:
def __init__(self, mat):
#print "init blend mat"
self.matProp = mat.properties['YafRay']
self.evEdit = getUniqueValue()
self.mats = Blender.Material.Get()
self.index = self.mats.index(mat)
#print self.index
self.menuMat1 = Draw.Create(0)
self.material = mat
#print " with mat: ", self.material
#(self.guiMatBlendMat1, "material1", "", matProp),
#(self.guiMatBlendMat2, "material2", "", matProp)]
def draw(self, height, guiWidgetHeight):
height += guiHeightOffset
drawText(10, height + 4, "Absorp. color:")
height += guiHeightOffset
i = 0
matMenuEntries = "Material 1 %t|"
for mat in self.mats:
if mat.lib:
matMenuEntries += "L " + mat.name + " %x" + str(i) + "|"
else:
matMenuEntries += mat.name + " %x" + str(i) + "|"
i = i + 1
self.menuMat1 = Draw.Menu(matMenuEntries,
self.evEdit, 100, height, 150, guiWidgetHeight, self.index + 1, "")
#self.evEdit, 100, height, 150, guiWidgetHeight, self.index, "")
#self.evEdit, 100, height, 150, guiWidgetHeight, self.menuMat1.val, "")
return height
def event(self):
self.matProp['material1'] = self.mats[self.menuMat1.val].name
#self.matProp['material2'] = self.mats[self.menuMat2.val]
class clTabMaterial:
def __init__(self):
# preview image
self.yRender = yafrayRender(isPreview = True)
# Initialize interface
self.yRender.setInterface(yInterface)
self.previewImage = Image.New("yafPrev", 320, 320, 32)
self.previewSize = 100
# events
self.evShow = getUniqueValue()
self.evEdit = getUniqueValue()
self.evChangeMat = getUniqueValue()
self.evRefreshPreview = getUniqueValue()
self.evMatFromObj = getUniqueValue()
self.tabNum = getUniqueValue()
self.matObject = None
self.materialsByMenu = False
#yafDict = Registry.GetKey('YafaRay', True)
#try:
# self.materialsByMenu = yafDict['materialsByMenu']
#except:
# yafDict = {}
# yafDict['materialsByMenu'] = self.materialsByMenu
# Blender.Registry.SetKey('YafaRay', yafDict, True)
# lists
self.connector = []
# class-specific types and lists
self.matTypes = ["shinydiffusemat", "glossy", "coated_glossy", "glass", "Rough Glass", "blend"]
self.BRDFTypes = ["Normal (Lambert)", "Oren-Nayar"]
self.materials = []
self.blenderMat = None # actual blender material currently shown
for mat in Blender.Material.Get():
# Check if this is a linked material
if mat.lib:
self.materials.append("L "+mat.name)
else:
self.materials.append(mat.name)
# properties
self.curMat = {}
# gui elements
self.guiMatShowPreview = Draw.Create(1)
self.guiMatPreviewSize = Draw.Create(self.previewSize)
self.guiMatMenu = Draw.Create(0)
self.guiMatSelectFromObj = Draw.Create(0)
self.guiMatDiffuse = Draw.Create(1.0)
self.guiMatSpecular = Draw.Create(0.0)
self.guiMatColor = Draw.Create(1.0,1.0,1.0)
self.guiMatDiffuseColor = Draw.Create(1.0,1.0,1.0)
self.guiMatMirrorColor = Draw.Create(1.0,1.0,1.0)
self.guiMatTransparency = Draw.Create(0.0)
self.guiMatTranslucency = Draw.Create(0.0)
self.guiMatEmit = Draw.Create(0.0)
self.guiMatFresnel = Draw.Create(0) # Toggle
self.guiMatGlossyReflect = Draw.Create(0.0)
self.guiMatExponent = Draw.Create(0.0)
self.guiMatAlpha = Draw.Create(0.0)
self.guiMatAsDiffuse = Draw.Create(0)
self.guiMatIOR = Draw.Create(1.0) # slider
self.guiMatFilterColor = Draw.Create(1.0,1.0,1.0)
self.guiMatAnisotropy = Draw.Create(0) # toggle
self.guiMatExpU = Draw.Create(50.0) # slider
self.guiMatExpV = Draw.Create(50.0) # slider
self.guiMatAbsorptionColor = Draw.Create(1.0,1.0,1.0)
self.guiMatAbsorptionDist = Draw.Create(1.0)
self.guiMatTransmit = Draw.Create(0.0)
self.guiMatDispersion = Draw.Create(0.0)
self.guiMatFakeShadow = Draw.Create(0) # toggle
self.guiMatAssign = Draw.Create(1)
self.guiMatType = Draw.Create(1) # menu
self.guiMatBlendMat1 = Draw.Create(1) # menu
self.guiMatBlendMat2 = Draw.Create(1) # menu
self.guiMatBlendValue = Draw.Create(0.5) # slider
self.guiMatDiffuseBRDF = Draw.Create(1) # menu
self.guiMatSigma = Draw.Create(0.0) # number
#self.guiMatByMenu = Draw.Create(self.materialsByMenu) # toggle
self.guiShowActiveMat = Draw.Create(0) # toggle
for mat in Blender.Material.Get():
self.setPropertyList(mat)
# call before drawing and once in __init__
def setPropertyList(self, mat = None):
if mat == None:
try:
mat = Blender.Material.Get()[self.guiMatMenu.val]
except:
yInterface.printError("Material doesn't exist!")
self.curMat = {}
return
# print "setProps:", mat
if not mat.properties.has_key("YafRay"):
mat.properties['YafRay'] = {}
self.curMat = mat.properties['YafRay']
matProp = self.curMat
self.blenderMat = mat
self.materials = []
for m in Blender.Material.Get():
self.materials.append(m.name)
# connect gui elements with id properties
# <gui element>, <property name>, <default value or type list>, <property group>
self.connector = [(self.guiMatType, "type", self.matTypes, matProp),
(self.guiMatDiffuse, "diffuse_reflect", 1.0, matProp),
(self.guiMatSpecular, "specular_reflect", 0.0, matProp),
(self.guiMatColor, "color", (1.0, 1.0, 1.0), matProp),
(self.guiMatDiffuseColor, "diffuse_color", (1, 1, 1), matProp),
(self.guiMatMirrorColor, "mirror_color", (1.0, 1.0, 1.0), matProp),
(self.guiMatTransparency, "transparency", 0.0, matProp),
(self.guiMatTranslucency, "translucency", 0.0, matProp),
(self.guiMatEmit, "emit", 0.0, matProp),
(self.guiMatFresnel, "fresnel_effect", False, matProp),
(self.guiMatGlossyReflect, "glossy_reflect", 0.0, matProp),
(self.guiMatExponent, "exponent", 500.0, matProp),
(self.guiMatAlpha, "alpha", 0.2, matProp),
(self.guiMatAsDiffuse, "as_diffuse", False, matProp),
(self.guiMatIOR, "IOR", 1.0, matProp),
(self.guiMatFilterColor, "filter_color", (1.0, 1.0, 1.0), matProp),
(self.guiMatAnisotropy, "anisotropic", False, matProp),
(self.guiMatExpU, "exp_u", 50.0, matProp),
(self.guiMatExpV, "exp_v", 50.0, matProp),
(self.guiMatAbsorptionColor, "absorption", (1.0, 1.0, 1.0), matProp),
(self.guiMatAbsorptionDist, "absorption_dist", 1.0, matProp),
(self.guiMatTransmit, "transmit_filter", 1.0, matProp),
(self.guiMatDispersion, "dispersion_power", 0.0, matProp),
(self.guiMatFakeShadow, "fake_shadows", False, matProp),
(self.guiMatBlendMat1, "material1", self.materials, matProp),
(self.guiMatBlendMat2, "material2", self.materials, matProp),
(self.guiMatBlendValue, "blend_value", 0.5, matProp),
(self.guiMatDiffuseBRDF, "brdfType", self.BRDFTypes, matProp),
(self.guiMatSigma, "sigma", 0.1, matProp)]
#print "mat connecting"
# add missing parameters to the property ID
for el in self.connector:
checkParam(el[0], el[1], el[2], el[3])
#yafDict = {}
#self.materialsByMenu = not self.guiShowActiveMat.val
#yafDict['materialsByMenu'] = self.materialsByMenu
#Blender.Registry.SetKey('YafaRay', yafDict, True)
def draw(self, height):
global libmat, PanelHeight
#print "Current Material",Blender.Material.Get()[self.guiMatMenu.val]
if self.blenderMat.lib:
libmat = True
else:
libmat = False
drawText(10, height, "Material settings", "large")
height = drawSepLineText(10, height, 320, "Material")
try:
Blender.Material.Get()[0]
except:
self.curMat = {}
drawText(10, height, "No materials defined in Blender UI!", "large")
return
self.guiShowActiveMat = Draw.Toggle("Always show active object", self.evChangeMat, 10,
height, 320, guiWidgetHeight, self.guiShowActiveMat.val, "Always show the material of the active object")
height += guiHeightOffset
# always init the menu for the blend mat
i = 0
matMenuEntries = "Materials %t|"
for mat in Blender.Material.Get():
if mat.lib:
matMenuEntries += "L " + mat.name + " %x" + str(i) + "|"
else:
matMenuEntries += mat.name + " %x" + str(i) + "|"
i = i + 1
if not self.guiShowActiveMat.val:
self.guiMatMenu = Draw.Menu(matMenuEntries, self.evChangeMat, 10, height, 150, guiWidgetHeight,
self.guiMatMenu.val, "selects an existing Blender material")
self.guiMatSelectFromObj = Draw.PushButton("From active object", self.evMatFromObj, 180, height,
150, guiWidgetHeight, "Select material from active object")
else:
try:
currentSelection = Object.GetSelected()[0]
except:
currentSelection = None
if currentSelection == None:
drawText(10, height, "Nothing selected", "large")
return
if currentSelection.getType() not in ['Mesh', 'Curve']:
drawText(10, height, "Object is no mesh", "large")
return
num = currentSelection.activeMaterial
mesh = currentSelection.getData()
if len(mesh.materials) == 0:
drawText(10, height, "Object has no material", "large")
return
m = mesh.materials[num - 1]
if m != self.blenderMat:
self.setPropertyList(m)
for el in self.connector:
setGUIVals(el[0], el[1], el[2], el[3])
self.refreshPreview()
drawText(10, height + 4, m.name)
height = drawSepLineText(10, height, 320, "Material Preview")
self.guiMatShowPreview = Draw.Toggle("Show Preview ", 0, 10,
height, 150, guiWidgetHeight, self.guiMatShowPreview.val, "")
if (self.guiMatShowPreview.val == 1):
self.guiMatPreviewSize = Draw.Slider("Size: ", 0, 180,
height, 150, guiWidgetHeight, self.guiMatPreviewSize.val, 100, 320)
height += guiHeightOffset
Draw.Image(self.previewImage, 10, height - self.previewSize + 10, 1, 1, 0, 0, self.previewSize, self.previewSize)
height -= self.previewSize - guiHeightOffset;
self.guiRefreshPreview = Draw.PushButton("Refresh Preview", self.evRefreshPreview, 10, height,
self.previewSize, guiWidgetHeight, "Refresh the preview image.")
height = drawSepLineText(10, height, 320, "Settings")
drawText(10, height + 4, "Material type: ")
self.guiMatType = Draw.Menu(makeMenu("Material type", self.matTypes),
self.evEdit, 100, height, 230, guiWidgetHeight, self.guiMatType.val, "Assign material type")
if self.curMat['type'] == "shinydiffusemat":
height += guiHeightOffset
drawText(10, height + 4, "Color:")
self.guiMatColor = Draw.ColorPicker(self.evEdit, 100,
height, 230, guiWidgetHeight, self.guiMatColor.val, "Base color of diffuse component")
height += guiHeightOffset
drawText(10, height + 4, "Mirror color:")
self.guiMatMirrorColor = Draw.ColorPicker(self.evEdit, 100,
height, 230, guiWidgetHeight, self.guiMatMirrorColor.val , "Color filter for mirrored rays")
height += guiHeightOffset
self.guiMatDiffuse = Draw.Slider("Diffuse reflection: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatDiffuse.val, 0.0, 1.0, 0, "Amount of diffuse reflection")
height += guiHeightOffset
self.guiMatSpecular = Draw.Slider("Mirror strength: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatSpecular.val, 0.0, 1.0, 0, "Amount of perfect specular reflection (mirror)")
height += guiHeightOffset
self.guiMatTransparency = Draw.Slider("Transparency: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatTransparency.val, 0.0, 1.0, 0, "material transparency")
height += guiHeightOffset
self.guiMatTranslucency = Draw.Slider("Translucency: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatTranslucency.val, 0.0, 1.0, 0, "Amount of diffuse transmission (translucency)")
height += guiHeightOffset
self.guiMatTransmit = Draw.Slider("Transmit filter: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatTransmit.val, 0.0, 1.0, 0, "Amount of tinting of light passing through material")
height += guiHeightOffset
self.guiMatEmit = Draw.Number("Emit: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatEmit.val, 0.0, 1000.0, "Amount of light the material emits",
dummyfunc, 10.0, 1.0)
height += guiHeightOffset
self.guiMatFresnel = Draw.Toggle("Fresnel ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatFresnel.val, "Apply fresnel effect to specular components")
if self.guiMatFresnel.val == 1:
height += guiHeightOffset
self.guiMatIOR = Draw.Slider("IOR: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatIOR.val, 1.0, 30.0, 0, "Refraction index for fresnel effect")
height += guiHeightOffset
self.guiMatDiffuseBRDF = Draw.Menu(makeMenu("BRDF type", self.BRDFTypes),
self.evEdit, 10, height, 150, guiWidgetHeight, self.guiMatDiffuseBRDF.val, "")
if (self.BRDFTypes[self.guiMatDiffuseBRDF.val] == 'Oren-Nayar'):
height += guiHeightOffset
self.guiMatSigma = Draw.Number("Sigma", self.evEdit, 10,
height, 150, guiWidgetHeight, self.guiMatSigma.val, 0.0, 1.0, "")
height += guiHeightOffset
height = drawTextLine(10, height, "Mappable texture slots, Yafaray <- Blender:")
height = drawTextLine(10, height, "Bump <- Nor")
height = drawTextLine(10, height, "Diffuse <- Col")
height = drawTextLine(10, height, "Mirror <- RayMir")
height = drawTextLine(10, height, "Transparency <- Alpha")
height = drawTextLine(10, height, "Translucency <- TransLu")
elif self.curMat['type'] == "glossy" or self.curMat['type'] == "coated_glossy": # Glossy material settings
height += guiHeightOffset
drawText(10, height + 4, "Diff. color:")
self.guiMatDiffuseColor = Draw.ColorPicker(self.evEdit, 100,
height, 230, guiWidgetHeight, self.guiMatDiffuseColor.val, "Diffuse Reflection Color")
height += guiHeightOffset
drawText(10, height + 4, "Glossy color:")
self.guiMatColor = Draw.ColorPicker(self.evEdit, 100,
height, 230, guiWidgetHeight, self.guiMatColor.val, "Glossy Color")
height += guiHeightOffset
self.guiMatDiffuse = Draw.Slider("Diffuse reflection: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatDiffuse.val, 0.0, 1.0, 0, "Amount of diffuse reflection")
height += guiHeightOffset
self.guiMatGlossyReflect = Draw.Slider("Glossy reflection: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatGlossyReflect.val, 0.0, 1.0, 0, "Amount of glossy reflection")
height += guiHeightOffset
self.guiMatExponent = Draw.Slider("Exponent: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatExponent.val, 1.0, 10000.0, 0, "Reflection blur, no effect if Anisotropic is on (1 = completely blured)")
height += guiHeightOffset
self.guiMatAsDiffuse = Draw.Toggle("As diffuse ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatAsDiffuse.val, "Treat glossy component as diffuse")
height += guiHeightOffset
self.guiMatAnisotropy = Draw.Toggle("Anisotropic ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatAnisotropy.val, "Use anisotropic reflections")
if (self.guiMatAnisotropy.val == 1):
height += guiHeightOffset
self.guiMatExpU = Draw.Slider("Exponent Horizontal: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatExpU.val, 1.0, 10000.0, 0, "u-exponent for anisotropy")
height += guiHeightOffset
self.guiMatExpV = Draw.Slider("Exponent Vertical: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatExpV.val, 1.0, 10000.0, 0,"v-exponent for anisotropy")
if self.curMat['type'] == "coated_glossy": # extension for coatedGlossy material
height += guiHeightOffset
self.guiMatIOR = Draw.Slider("IOR: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatIOR.val, 1.0, 30.0, 0, "Index of refraction for fresnel effect of the coating top layer")
height += guiHeightOffset
self.guiMatDiffuseBRDF = Draw.Menu(makeMenu("BRDF type", self.BRDFTypes),
self.evEdit, 10, height, 150, guiWidgetHeight, self.guiMatDiffuseBRDF.val, "")
if (self.BRDFTypes[self.guiMatDiffuseBRDF.val] == 'Oren-Nayar'):
height += guiHeightOffset
self.guiMatSigma = Draw.Number("Sigma", self.evEdit, 10,
height, 150, guiWidgetHeight, self.guiMatSigma.val, 0.0, 1.0, "")
height += guiHeightOffset
height = drawTextLine(10, height, "Mappable texture slots, Yafaray <- Blender:")
height = drawTextLine(10, height, "Bump <- Nor")
height = drawTextLine(10, height, "Diffuse <- Col")
height = drawTextLine(10, height, "Glossy Reflection <- Spec")
height = drawTextLine(10, height, "Glossy Color <- Csp")
if self.curMat['type'] == "glass" or self.curMat['type'] == "Rough Glass": # glass material
height += guiHeightOffset
drawText(10, height + 4, "Absorp. color:")
self.guiMatAbsorptionColor = Draw.ColorPicker(self.evEdit, 100, height,
230, guiWidgetHeight, self.guiMatAbsorptionColor.val, "Glass volumetric absorption color. White disables absorption")
height += guiHeightOffset
self.guiMatAbsorptionDist = Draw.Slider("Absorp. Distance:", self.evEdit, 10, height,
320, guiWidgetHeight, self.guiMatAbsorptionDist.val, 0.0, 100.0, True, "Absorption distance scale")
height += guiHeightOffset
drawText(10, height + 4, "Filter color:")
self.guiMatFilterColor = Draw.ColorPicker(self.evEdit, 100, height,
230, guiWidgetHeight, self.guiMatFilterColor.val, "Filter color applied for refracted light")
height += guiHeightOffset
drawText(10, height + 4, "Mirror color:")
self.guiMatMirrorColor = Draw.ColorPicker(self.evEdit, 100, height,
230, guiWidgetHeight, self.guiMatMirrorColor.val, "Filter color applied for reflected light")
height += guiHeightOffset
self.guiMatIOR = Draw.Slider("IOR: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatIOR.val, 1.0, 30.0, 0, "Index of refraction")
if self.curMat['type'] == "Rough Glass":
#height += guiHeightOffset
#self.guiMatExponent = Draw.Slider("Exponent: ", self.evEdit, 10,
# height, 320, guiWidgetHeight, self.guiMatExponent.val, 1.0, 10000.0, 0, "Exponent of glass roughness (lower = rougher)")
height += guiHeightOffset
self.guiMatAlpha = Draw.Slider("Roughtness: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatAlpha.val, 0.0, 1.0, 0, "Roughness factor (higher = rougher)")
height += guiHeightOffset
self.guiMatTransmit = Draw.Slider("Transmit Filter: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatTransmit.val, 0.0, 1.0, 0, "Filter strength applied to refracted light")
height += guiHeightOffset
self.guiMatDispersion = Draw.Slider("Dispersion Power: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatDispersion.val, 0.0, 10000.0, 0, "Strength of dispersion effect, disabled when 0")
height += guiHeightOffset
self.guiMatFakeShadow = Draw.Toggle("Fake shadows ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatFakeShadow.val, "Let light straight through for shadow calculation. Not to be used with dispersion")
height += guiHeightOffset
height = drawTextLine(10, height, "Mappable texture slots, Yafaray <- Blender:")
height = drawTextLine(10, height, "Bump <- Nor")
elif self.curMat['type'] == "blend":
#height = self.matObject.draw(height, guiWidgetHeight)
height += guiHeightOffset
height = drawTextLine(10, height, " ")
height = drawTextParagraph(10, height, 300, "Choose the two materials you wish to blend. " +
"You can weight them with the blend value or texture maps. Use the COL texture channel "+
"of the blending material to blend two materials using a texture map.")
height += guiHeightOffset
self.guiMatBlendMat1 = Draw.Menu(matMenuEntries, self.evEdit, 10, height, 150, guiWidgetHeight, self.guiMatBlendMat1.val, "Material 1")
self.guiMatBlendMat2 = Draw.Menu(matMenuEntries, self.evEdit, 180, height, 150, guiWidgetHeight, self.guiMatBlendMat2.val, "Material 2")
height += guiHeightOffset
self.guiMatBlendValue = Draw.Slider("Blend value: ", self.evEdit, 10,
height, 320, guiWidgetHeight, self.guiMatBlendValue.val, 0.0, 1.0, 0, "The mixing balance, 0 = only material 1 1 = only material 2")
height += guiHeightOffset
PanelHeight = height
def event(self, evt = None):
# print "mat evt", evt
if self.guiShowActiveMat.val:
try:
currentSelection = Object.GetSelected()[0]
except:
currentSelection = None
if currentSelection == None:
return
if currentSelection.getType() not in ['Mesh', 'Curve']:
return
num = currentSelection.activeMaterial
mesh = currentSelection.getData()
if len(mesh.materials) == 0:
return
m = mesh.materials[num - 1]
self.setPropertyList(m)
for el in self.connector:
setParam(el[0],el[1],el[2],el[3])
elif evt == None:
self.setPropertyList()
# set the parameters from the GUI to their respective ID properties
for el in self.connector:
setParam(el[0],el[1],el[2],el[3])
#if self.curMat['type'] == "blend":
# mat = Blender.Material.Get()[self.guiMatMenu.val]
# self.matObject = BlendMat(mat)
elif evt == self.evMatFromObj:
# get material index from current object
try:
activeObject = Blender.Object.GetSelected()[0]
activeMaterialIndex = activeObject.activeMaterial
mat = activeObject.getData().materials[activeMaterialIndex-1]
index = Blender.Material.Get().index(mat)
self.guiMatMenu.val = index
self.changeMat()
except:
yInterface.printWarning("MaterialTab: No object selected")
def changeMat(self):
self.setPropertyList()
for el in self.connector:
setGUIVals(el[0], el[1], el[2], el[3])
def refreshPreview(self):
if not self.guiMatShowPreview.val: return
self.previewSize = int(self.guiMatPreviewSize.val)
imageMem = yafrayinterface.new_floatArray(self.previewSize * self.previewSize * 4)
self.yRender.createPreview(self.blenderMat, self.previewSize, imageMem)
for x in range(self.previewSize):
for y in range(self.previewSize):
# first row is on the bottom, therefor the idx must be reversed
idx = (x + (self.previewSize - 1) * self.previewSize - self.previewSize * y) * 4
col = yafrayinterface.floatArray_getitem(imageMem, idx + 0)
colR = min(255, int(col * 255))
col = yafrayinterface.floatArray_getitem(imageMem, idx + 1)
colG = min(255, int(col * 255))
col = yafrayinterface.floatArray_getitem(imageMem, idx + 2)
colB = min(255, int(col * 255))
# still getting exceptions from time to time about
# values out of range which should be impossible using
# min above
try:
self.previewImage.setPixelI(x, y, (colR, colG, colB, 255))
except:
pass
#print colR, colG, colB
yafrayinterface.delete_floatArray(imageMem)
# ### tab environment ### #
class clTabWorld:
def __init__(self):
# events
self.evShow = getUniqueValue()
self.evEdit = getUniqueValue()
self.tabNum = getUniqueValue()
# Sanne: sunsky, also add "Sunsky" to self.BGTypes
self.evGetSunAngle = getUniqueValue()
self.evGetSunPos = getUniqueValue()
self.evUpdateSun = getUniqueValue()
self.evSunNormalToNumber = getUniqueValue()
self.evSunNumberToNormal = getUniqueValue()
# lists
self.connector = []
# class-specific types
self.BGTypes = ["Single Color", "Gradient", "Texture", "Sunsky", "DarkTide's SunSky"]
self.VolumeIntTypes = ["None", "Single Scatter"]
self.DSSkyColorSpaces = ["CIE (E)", "CIE (D50)", "sRBG (D65)", "sRGB (D50)"]
#self.VolumeIntTypes += ["Sky"]
# properties
self.World = {}
#self.scene = Scene.Get()[0]
#self.scene = Scene.GetCurrent()
# world bg stuff
self.guiRenderBGType = Draw.Create(0) # menu
self.guiRenderBGIBL = Draw.Create(0) # Toggle
self.guiRenderBGDiffP = Draw.Create(1) # Toggle
self.guiRenderBGCausP = Draw.Create(1) # Toggle
self.guiRenderBGIBLSamples = Draw.Create(1) # numberbox
self.guiRenderBGIBLRot = Draw.Create(0.0) # Slider
self.guiRenderBGPower = Draw.Create(1.0) # Slider
self.guiRenderBGColor = Draw.Create(0.0,0.0,0.0) # color
self.guiRenderBGHoriCol = Draw.Create(0.0,0.0,0.0) # color
self.guiRenderBGZeniCol = Draw.Create(0.0,0.0,0.0) # color
self.guiRenderBGHoriGCol = Draw.Create(0.0,0.0,0.0) # color
self.guiRenderBGZeniGCol = Draw.Create(0.0,0.0,0.0) # color
# Sanne: Sunsky
self.guiRenderBGTurbidity = Draw.Create(1.0) # numberbox
self.guiRenderBGAVar = Draw.Create(1.0) # numberbox
self.guiRenderBGBVar = Draw.Create(1.0) # numberbox
self.guiRenderBGCVar = Draw.Create(1.0) # numberbox
self.guiRenderBGDVar = Draw.Create(1.0) # numberbox
self.guiRenderBGEVar = Draw.Create(1.0) # numberbox
self.guiRenderBGFrom = Draw.Create(0.0,0.0,0.0) # normal
self.guiRenderBGFromX = Draw.Create(0.0) # numberbox
self.guiRenderBGFromY = Draw.Create(0.0) # numberbox
self.guiRenderBGFromZ = Draw.Create(0.0) # numberbox
self.guiRenderBGCreateSun = Draw.Create(0) # toggle
self.guiRenderBGSunPower = Draw.Create(0.0) # slider
self.guiRenderBGSkyLight = Draw.Create(0) # toggle
self.guiRenderBGSkySamples = Draw.Create(0) # numberbox
# DarkTide's Sunsky
self.guiRenderDSTurbidity = Draw.Create(2.0) # numberbox
self.guiRenderDSRealSun = Draw.Create(0) # toggle
self.guiRenderDSSunPower = Draw.Create(0.0) # slider
self.guiRenderDSSkyBright = Draw.Create(1.0) # slider
self.guiRenderDSSkyLight = Draw.Create(0) # toggle
self.guiRenderDSSkySamples = Draw.Create(0) # numberbox
self.guiRenderDSA = Draw.Create(1.0) # numberbox
self.guiRenderDSB = Draw.Create(1.0) # numberbox
self.guiRenderDSC = Draw.Create(1.0) # numberbox
self.guiRenderDSD = Draw.Create(1.0) # numberbox
self.guiRenderDSE = Draw.Create(1.0) # numberbox
self.guiRenderDSAltitude = Draw.Create(0.0) # numberbox
self.guiRenderDSNight = Draw.Create(0) # toggle
self.guiRenderDSSkyPower = Draw.Create(1.0) # number
self.guiRenderDSExposure = Draw.Create(1.0) # number
self.guiRenderDSGammaEncoding = Draw.Create(0) # toggle
self.guiRenderDSColorSpace = Draw.Create(0) # menu
# volume integrator
self.guiRenderVolumeIntType = Draw.Create(0) # menu
self.guiRenderVolumeStepSize = Draw.Create(0.0) # numberbox
self.guiRenderVolumeAdaptive = Draw.Create(0) # toggle
self.guiRenderVolumeOptimize = Draw.Create(0) # toggle
self.guiRenderVolumeAttMapScale = Draw.Create(0) # numberbox
self.guiRenderVolumeSkyST = Draw.Create(0.0) # numberbox
self.guiRenderVolumeSkyAlpha = Draw.Create(0.0) # numberbox
self.setPropertyList()
# call once before and once after drawing and once in __init__
def setPropertyList(self):
if Blender.World.GetCurrent():
if not Blender.World.GetCurrent().properties.has_key("YafRay"):
Blender.World.GetCurrent().properties["YafRay"] = {}
self.World = Blender.World.GetCurrent().properties["YafRay"]
else:
self.World = {}
# connect gui elements with id properties
# <gui element>, <property name>, <default value or type list>, <property group>
self.connector = [
# background settings
(self.guiRenderBGType, "bg_type", self.BGTypes, self.World),
(self.guiRenderBGIBL, "ibl", 0, self.World),
(self.guiRenderBGCausP, "with_caustic", 1, self.World),
(self.guiRenderBGDiffP, "with_diffuse", 1, self.World),
(self.guiRenderBGIBLSamples, "ibl_samples", 16, self.World),
(self.guiRenderBGIBLRot, "rotation", 0.0, self.World),
(self.guiRenderBGPower, "power", 1.0, self.World),
(self.guiRenderBGColor, "color", (0.0, 0.0, 0.0), self.World),
(self.guiRenderBGHoriCol, "horizon_color", (1.0, 1.0, 0.5), self.World),
(self.guiRenderBGHoriGCol, "horizon_ground_color", (.65, .6, .45), self.World),
(self.guiRenderBGZeniCol, "zenith_color", (.57, .65, 1.0), self.World),
(self.guiRenderBGZeniGCol, "zenith_ground_color", (.28, .26, .2), self.World),
# Sanne: Sunsky
(self.guiRenderBGTurbidity, "turbidity", 3.0, self.World),
(self.guiRenderBGAVar, "a_var", 1.0, self.World),
(self.guiRenderBGBVar, "b_var", 1.0, self.World),
(self.guiRenderBGCVar, "c_var", 1.0, self.World),
(self.guiRenderBGDVar, "d_var", 1.0, self.World),
(self.guiRenderBGEVar, "e_var", 1.0, self.World),
(self.guiRenderBGFrom, "from", (1.0, 1.0, 1.0), self.World),
(self.guiRenderBGCreateSun, "add_sun", 0, self.World),
(self.guiRenderBGSunPower, "sun_power", 1.0, self.World),
(self.guiRenderBGSkyLight, "background_light", 0, self.World),
(self.guiRenderBGSkySamples, "light_samples", 16, self.World),
# DarkTide's Sunsky
(self.guiRenderDSTurbidity, "dsturbidity", 2.0, self.World),
(self.guiRenderDSAltitude, "dsaltitude", 0.0, self.World),
(self.guiRenderDSA, "dsa", 1.0, self.World),
(self.guiRenderDSB, "dsb", 1.0, self.World),
(self.guiRenderDSC, "dsc", 1.0, self.World),
(self.guiRenderDSD, "dsd", 1.0, self.World),
(self.guiRenderDSE, "dse", 1.0, self.World),
(self.guiRenderDSRealSun, "dsadd_sun", 0, self.World),
(self.guiRenderDSNight, "dsnight", 0, self.World),
(self.guiRenderDSSunPower, "dssun_power", 1.0, self.World),
(self.guiRenderDSSkyBright, "dsbright", 1.0, self.World),
(self.guiRenderDSSkyLight, "dsbackground_light", 0, self.World),
(self.guiRenderDSSkySamples, "dslight_samples", 16, self.World),
(self.guiRenderDSSkyPower, "dspower", 1.0, self.World),
(self.guiRenderDSExposure, "dsexposure", 1.0, self.World),
(self.guiRenderDSGammaEncoding, "dsgammaenc", 1, self.World),
(self.guiRenderDSColorSpace, "dscolorspace", self.DSSkyColorSpaces, self.World),
# volume integrator
(self.guiRenderVolumeIntType, "volType", self.VolumeIntTypes, self.World),
(self.guiRenderVolumeStepSize, "stepSize", 1.0, self.World),
(self.guiRenderVolumeAdaptive, "adaptive", 0, self.World),
(self.guiRenderVolumeOptimize, "optimize", 0, self.World),
(self.guiRenderVolumeAttMapScale, "attgridScale", 1, self.World),
(self.guiRenderVolumeSkyST, "sigma_t", 0.1, self.World),
(self.guiRenderVolumeSkyAlpha, "alpha", 0.5, self.World)]
for el in self.connector:
checkParam(el[0], el[1], el[2], el[3]) # adds missing params as property ID
def drawBGSettings(self, height):
# background settings
height = drawSepLineText(10, height, 320, "Background settings")
self.guiRenderBGType = Draw.Menu(makeMenu("Background ", self.BGTypes), self.evEdit,
10, height, 150, guiWidgetHeight, self.guiRenderBGType.val, "Sets the background type")
height += guiHeightOffset
if self.World['bg_type'] == "Single Color":