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
|
"""The Blender Lamp module
This module provides control over **Lamp** objects in Blender.
Example::
from Blender import Lamp
l = Lamp.New('Spot')
l.setMode('square', 'shadow')
ob = Object.New('Lamp')
ob.link(l)
"""
import _Blender.Lamp as _Lamp
import shadow
_validBufferSizes = [512, 768, 1024, 1536, 2560]
def _setBufferSize(self, bufsize):
"""Set the lamp's buffersize. This function makes sure that a valid
bufferSize value is set (unlike setting lamp.bufferSize directly)"""
if bufsize not in _validBufferSizes:
print """Buffer size should be one of:
%s
Setting to default 512""" % _validBufferSizes
bufsize = 512
self._object.bufferSize = bufsize
class Lamp(shadow.hasIPO, shadow.hasModes):
"""Wrapper for Blender Lamp DataBlock
Attributes
mode -- Lamp mode value - see EditButtons. Do not access directly
See setMode()
type -- Lamp type value - see EditButtons. No direct access, please.
See setType()
col -- RGB vector (R, G, B) of lamp colour
energy -- Intensity (float)
dist -- clipping distance of a spot lamp or decay range
spotSize -- float angle (in degrees) of spot cone
(between 0.0 and 180.0)
spotBlend -- value defining the blurriness of the spot edge
haloInt -- Halo intensity
clipStart -- shadow buffer clipping start
clipStart -- shadow buffer clipping end
bias -- The bias value for the shadowbuffer routine
softness -- The filter value for the shadow blurring
samples -- Number of samples in shadow calculation - the
larger, the better
bufferSize -- Size of the shadow buffer which should be one of:
[512, 768, 1024, 1536, 2560]
haloStep -- Number of steps in halo calculation - the smaller, the
the better (and slower). A value of 0 disables shadow
halo calculation
"""
_emulation = {'Energ' : "energy",
'SpoSi' : "spotSize",
'SpoBl' : "SpotBlend",
'HaInt' : "haloInt",
'Dist' : "dist",
'Quad1' : "quad1",
'Quad2' : "quad2",
}
_setters = {'bufferSize' : _setBufferSize}
t = _Lamp.Types
Types = {'Lamp' : t.LOCAL,
'Spot' : t.SPOT,
'Sun' : t.SUN,
'Hemi' : t.HEMI,
}
t = _Lamp.Modes
Modes = {'quad' : t.QUAD,
'sphere' : t.SPHERE,
'shadow' : t.SHAD,
'halo' : t.HALO,
'layer' : t.LAYER,
'negative' : t.NEG,
'onlyShadow' : t.ONLYSHADOW,
'square' : t.SQUARE,
}
del t
def __repr__(self):
return "[Lamp \"%s\"]" % self.name
def setType(self, name):
"""Set the Lamp type of Lamp 'self'. 'name' must be a string of:
* 'Lamp': A standard point light source
* 'Spot': A spot light
* 'Sun' : A unidirectional light source, very far away (like a Sun!)
* 'Hemi': A diffuse hemispherical light source (daylight without sun)"""
try:
self._object.type = self.Types[name]
except:
raise TypeError, "type must be one of %s" % self.Types.keys()
def getType(self):
"""Returns the lamp's type as string. See setType()"""
for k in self.Types.keys():
if self.Types[k] == self.type:
return k
def getMode(self):
"""Returns the Lamp modes as a list of strings"""
return shadow._getModeBits(self.Modes, self._object.mode)
def setMode(self, *args):
"""Set the Lamp mode of Lamp 'self'. This function takes a variable number
of string arguments of the types listed in self.Modes.
Example::
l = Lamp.New()
l.setMode('quad', 'shadow')
"""
print args
self._object.mode = shadow._setModeBits(self.Modes, args)
def getBufferSize(self):
return self.bufferSize
def New(type = "Lamp", name = "Lamp"):
"""Returns a new Lamp datablock of type 'type' and optional name 'name'
"""
t = Lamp.Types[type]
rawlamp = _Lamp.New()
rawlamp.type = t
rawlamp.name = name
return Lamp(rawlamp)
def get(name = None):
"""If 'name' given, the Lamp 'name' is returned if existing, 'None' otherwise.
If no name is given, a list of all Lamps is returned"""
if name:
return Lamp(_Lamp.get(name))
else:
return shadow._List(_Lamp.get(), Lamp)
Types = _Lamp.Types
|