25
25
* This is a new part of Blender.
27
* Contributor(s): Willian P. Germano
27
* Contributor(s): Willian P. Germano, Nathan Letwory, Stephen Swaney,
29
30
* ***** END GPL/BL DUAL LICENSE BLOCK *****
37
#include <BKE_global.h>
38
#include <BKE_object.h>
39
#include <BKE_library.h>
40
#include <BLI_blenlib.h>
41
#include <BIF_space.h>
42
#include <BSE_editipo.h>
50
#include "gen_utils.h"
52
/*****************************************************************************/
53
/* Python BPy_Lamp defaults: */
54
/*****************************************************************************/
59
these are the same values as LA_* from DNA_lamp_types.h
60
is there some reason we are not simply using those #defines?
64
#define EXPP_LAMP_TYPE_LAMP 0
65
#define EXPP_LAMP_TYPE_SUN 1
66
#define EXPP_LAMP_TYPE_SPOT 2
67
#define EXPP_LAMP_TYPE_HEMI 3
68
#define EXPP_LAMP_TYPE_AREA 4
69
#define EXPP_LAMP_TYPE_YF_PHOTON 5
71
define a constant to keep magic numbers out of the code
72
this value should be equal to the last EXPP_LAMP_TYPE_*
74
#define EXPP_LAMP_TYPE_MAX 5
78
#define EXPP_LAMP_MODE_SHADOWS 1
79
#define EXPP_LAMP_MODE_HALO 2
80
#define EXPP_LAMP_MODE_LAYER 4
81
#define EXPP_LAMP_MODE_QUAD 8
82
#define EXPP_LAMP_MODE_NEGATIVE 16
83
#define EXPP_LAMP_MODE_ONLYSHADOW 32
84
#define EXPP_LAMP_MODE_SPHERE 64
85
#define EXPP_LAMP_MODE_SQUARE 128
86
#define EXPP_LAMP_MODE_TEXTURE 256
87
#define EXPP_LAMP_MODE_OSATEX 512
88
#define EXPP_LAMP_MODE_DEEPSHADOW 1024
89
#define EXPP_LAMP_MODE_NODIFFUSE 2048
90
#define EXPP_LAMP_MODE_NOSPECULAR 4096
91
/* Lamp MIN, MAX values */
93
#define EXPP_LAMP_SAMPLES_MIN 1
94
#define EXPP_LAMP_SAMPLES_MAX 16
95
#define EXPP_LAMP_BUFFERSIZE_MIN 512
96
#define EXPP_LAMP_BUFFERSIZE_MAX 5120
97
#define EXPP_LAMP_ENERGY_MIN 0.0
98
#define EXPP_LAMP_ENERGY_MAX 10.0
99
#define EXPP_LAMP_DIST_MIN 0.1
100
#define EXPP_LAMP_DIST_MAX 5000.0
101
#define EXPP_LAMP_SPOTSIZE_MIN 1.0
102
#define EXPP_LAMP_SPOTSIZE_MAX 180.0
103
#define EXPP_LAMP_SPOTBLEND_MIN 0.00
104
#define EXPP_LAMP_SPOTBLEND_MAX 1.00
105
#define EXPP_LAMP_CLIPSTART_MIN 0.1
106
#define EXPP_LAMP_CLIPSTART_MAX 1000.0
107
#define EXPP_LAMP_CLIPEND_MIN 1.0
108
#define EXPP_LAMP_CLIPEND_MAX 5000.0
109
#define EXPP_LAMP_BIAS_MIN 0.01
110
#define EXPP_LAMP_BIAS_MAX 5.00
111
#define EXPP_LAMP_SOFTNESS_MIN 1.0
112
#define EXPP_LAMP_SOFTNESS_MAX 100.0
113
#define EXPP_LAMP_HALOINT_MIN 0.0
114
#define EXPP_LAMP_HALOINT_MAX 5.0
115
#define EXPP_LAMP_HALOSTEP_MIN 0
116
#define EXPP_LAMP_HALOSTEP_MAX 12
117
#define EXPP_LAMP_QUAD1_MIN 0.0
118
#define EXPP_LAMP_QUAD1_MAX 1.0
119
#define EXPP_LAMP_QUAD2_MIN 0.0
120
#define EXPP_LAMP_QUAD2_MAX 1.0
121
#define EXPP_LAMP_COL_MIN 0.0
122
#define EXPP_LAMP_COL_MAX 1.0
125
#define IPOKEY_ENERGY 1
126
#define IPOKEY_SPOTSIZE 2
127
#define IPOKEY_OFFSET 3
128
#define IPOKEY_SIZE 4
130
/*****************************************************************************/
131
/* Python API function prototypes for the Lamp module. */
132
/*****************************************************************************/
133
static PyObject *M_Lamp_New( PyObject * self, PyObject * args,
134
PyObject * keywords );
135
static PyObject *M_Lamp_Get( PyObject * self, PyObject * args );
137
/*****************************************************************************/
138
/* The following string definitions are used for documentation strings. */
139
/* In Python these will be written to the console when doing a */
140
/* Blender.Lamp.__doc__ */
141
/*****************************************************************************/
142
static char M_Lamp_doc[] = "The Blender Lamp module\n\n\
143
This module provides control over **Lamp Data** objects in Blender.\n\n\
145
from Blender import Lamp\n\
146
l = Lamp.New('Spot') # create new 'Spot' lamp data\n\
147
l.setMode('square', 'shadow') # set these two lamp mode flags\n\
148
ob = Object.New('Lamp') # create new lamp object\n\
149
ob.link(l) # link lamp obj with lamp data\n";
151
static char M_Lamp_New_doc[] = "Lamp.New (type = 'Lamp', name = 'LampData'):\n\
152
Return a new Lamp Data object with the given type and name.";
154
static char M_Lamp_Get_doc[] = "Lamp.Get (name = None):\n\
155
Return the Lamp Data with the given name, None if not found, or\n\
156
Return a list with all Lamp Data objects in the current scene,\n\
157
if no argument was given.";
159
/*****************************************************************************/
160
/* Python method structure definition for Blender.Lamp module: */
161
/*****************************************************************************/
162
struct PyMethodDef M_Lamp_methods[] = {
163
{"New", ( PyCFunction ) M_Lamp_New, METH_VARARGS | METH_KEYWORDS,
165
{"Get", M_Lamp_Get, METH_VARARGS, M_Lamp_Get_doc},
166
{"get", M_Lamp_Get, METH_VARARGS, M_Lamp_Get_doc},
167
{NULL, NULL, 0, NULL}
170
/*****************************************************************************/
171
/* Python BPy_Lamp methods declarations: */
172
/*****************************************************************************/
173
static PyObject *Lamp_getName( BPy_Lamp * self );
174
static PyObject *Lamp_getType( BPy_Lamp * self );
175
static PyObject *Lamp_getMode( BPy_Lamp * self );
176
static PyObject *Lamp_getSamples( BPy_Lamp * self );
177
static PyObject *Lamp_getBufferSize( BPy_Lamp * self );
178
static PyObject *Lamp_getHaloStep( BPy_Lamp * self );
179
static PyObject *Lamp_getEnergy( BPy_Lamp * self );
180
static PyObject *Lamp_getDist( BPy_Lamp * self );
181
static PyObject *Lamp_getSpotSize( BPy_Lamp * self );
182
static PyObject *Lamp_getSpotBlend( BPy_Lamp * self );
183
static PyObject *Lamp_getClipStart( BPy_Lamp * self );
184
static PyObject *Lamp_getClipEnd( BPy_Lamp * self );
185
static PyObject *Lamp_getBias( BPy_Lamp * self );
186
static PyObject *Lamp_getSoftness( BPy_Lamp * self );
187
static PyObject *Lamp_getHaloInt( BPy_Lamp * self );
188
static PyObject *Lamp_getQuad1( BPy_Lamp * self );
189
static PyObject *Lamp_getQuad2( BPy_Lamp * self );
190
static PyObject *Lamp_getCol( BPy_Lamp * self );
191
static PyObject *Lamp_getIpo( BPy_Lamp * self );
192
static PyObject *Lamp_clearIpo( BPy_Lamp * self );
193
static PyObject *Lamp_setIpo( BPy_Lamp * self, PyObject * args );
194
static PyObject *Lamp_insertIpoKey( BPy_Lamp * self, PyObject * args );
195
static PyObject *Lamp_setName( BPy_Lamp * self, PyObject * args );
196
static PyObject *Lamp_setType( BPy_Lamp * self, PyObject * args );
197
static PyObject *Lamp_setIntType( BPy_Lamp * self, PyObject * args );
198
static PyObject *Lamp_setMode( BPy_Lamp * self, PyObject * args );
199
static PyObject *Lamp_setIntMode( BPy_Lamp * self, PyObject * args );
200
static PyObject *Lamp_setSamples( BPy_Lamp * self, PyObject * args );
201
static PyObject *Lamp_setBufferSize( BPy_Lamp * self, PyObject * args );
202
static PyObject *Lamp_setHaloStep( BPy_Lamp * self, PyObject * args );
203
static PyObject *Lamp_setEnergy( BPy_Lamp * self, PyObject * args );
204
static PyObject *Lamp_setDist( BPy_Lamp * self, PyObject * args );
205
static PyObject *Lamp_setSpotSize( BPy_Lamp * self, PyObject * args );
206
static PyObject *Lamp_setSpotBlend( BPy_Lamp * self, PyObject * args );
207
static PyObject *Lamp_setClipStart( BPy_Lamp * self, PyObject * args );
208
static PyObject *Lamp_setClipEnd( BPy_Lamp * self, PyObject * args );
209
static PyObject *Lamp_setBias( BPy_Lamp * self, PyObject * args );
210
static PyObject *Lamp_setSoftness( BPy_Lamp * self, PyObject * args );
211
static PyObject *Lamp_setHaloInt( BPy_Lamp * self, PyObject * args );
212
static PyObject *Lamp_setQuad1( BPy_Lamp * self, PyObject * args );
213
static PyObject *Lamp_setQuad2( BPy_Lamp * self, PyObject * args );
214
static PyObject *Lamp_setCol( BPy_Lamp * self, PyObject * args );
215
static PyObject *Lamp_setColorComponent( BPy_Lamp * self, char *key,
217
static PyObject *Lamp_getScriptLinks( BPy_Lamp * self, PyObject * args );
218
static PyObject *Lamp_addScriptLink( BPy_Lamp * self, PyObject * args );
219
static PyObject *Lamp_clearScriptLinks( BPy_Lamp * self, PyObject * args );
221
/*****************************************************************************/
222
/* Python BPy_Lamp methods table: */
223
/*****************************************************************************/
224
static PyMethodDef BPy_Lamp_methods[] = {
225
/* name, method, flags, doc */
226
{"getName", ( PyCFunction ) Lamp_getName, METH_NOARGS,
227
"() - return Lamp name"},
228
{"getType", ( PyCFunction ) Lamp_getType, METH_NOARGS,
229
"() - return Lamp type - 'Lamp':0, 'Sun':1, 'Spot':2, 'Hemi':3, 'Area':4, 'Photon':5"},
230
{"getMode", ( PyCFunction ) Lamp_getMode, METH_NOARGS,
231
"() - return Lamp mode flags (or'ed value)"},
232
{"getSamples", ( PyCFunction ) Lamp_getSamples, METH_NOARGS,
233
"() - return Lamp samples value"},
234
{"getBufferSize", ( PyCFunction ) Lamp_getBufferSize, METH_NOARGS,
235
"() - return Lamp buffer size value"},
236
{"getHaloStep", ( PyCFunction ) Lamp_getHaloStep, METH_NOARGS,
237
"() - return Lamp halo step value"},
238
{"getEnergy", ( PyCFunction ) Lamp_getEnergy, METH_NOARGS,
239
"() - return Lamp energy value"},
240
{"getDist", ( PyCFunction ) Lamp_getDist, METH_NOARGS,
241
"() - return Lamp clipping distance value"},
242
{"getSpotSize", ( PyCFunction ) Lamp_getSpotSize, METH_NOARGS,
243
"() - return Lamp spot size value"},
244
{"getSpotBlend", ( PyCFunction ) Lamp_getSpotBlend, METH_NOARGS,
245
"() - return Lamp spot blend value"},
246
{"getClipStart", ( PyCFunction ) Lamp_getClipStart, METH_NOARGS,
247
"() - return Lamp clip start value"},
248
{"getClipEnd", ( PyCFunction ) Lamp_getClipEnd, METH_NOARGS,
249
"() - return Lamp clip end value"},
250
{"getBias", ( PyCFunction ) Lamp_getBias, METH_NOARGS,
251
"() - return Lamp bias value"},
252
{"getSoftness", ( PyCFunction ) Lamp_getSoftness, METH_NOARGS,
253
"() - return Lamp softness value"},
254
{"getHaloInt", ( PyCFunction ) Lamp_getHaloInt, METH_NOARGS,
255
"() - return Lamp halo intensity value"},
256
{"getQuad1", ( PyCFunction ) Lamp_getQuad1, METH_NOARGS,
257
"() - return light intensity value #1 for a Quad Lamp"},
258
{"getQuad2", ( PyCFunction ) Lamp_getQuad2, METH_NOARGS,
259
"() - return light intensity value #2 for a Quad Lamp"},
260
{"getCol", ( PyCFunction ) Lamp_getCol, METH_NOARGS,
261
"() - return light rgb color triplet"},
262
{"setName", ( PyCFunction ) Lamp_setName, METH_VARARGS,
263
"(str) - rename Lamp"},
264
{"setType", ( PyCFunction ) Lamp_setType, METH_VARARGS,
265
"(str) - change Lamp type, which can be 'Lamp', 'Sun', 'Spot', 'Hemi', 'Area', 'Photon'"},
266
{"setMode", ( PyCFunction ) Lamp_setMode, METH_VARARGS,
267
"([up to eight str's]) - Set Lamp mode flag(s)"},
268
{"setSamples", ( PyCFunction ) Lamp_setSamples, METH_VARARGS,
269
"(int) - change Lamp samples value"},
270
{"setBufferSize", ( PyCFunction ) Lamp_setBufferSize, METH_VARARGS,
271
"(int) - change Lamp buffer size value"},
272
{"setHaloStep", ( PyCFunction ) Lamp_setHaloStep, METH_VARARGS,
273
"(int) - change Lamp halo step value"},
274
{"setEnergy", ( PyCFunction ) Lamp_setEnergy, METH_VARARGS,
275
"(float) - change Lamp energy value"},
276
{"setDist", ( PyCFunction ) Lamp_setDist, METH_VARARGS,
277
"(float) - change Lamp clipping distance value"},
278
{"setSpotSize", ( PyCFunction ) Lamp_setSpotSize, METH_VARARGS,
279
"(float) - change Lamp spot size value"},
280
{"setSpotBlend", ( PyCFunction ) Lamp_setSpotBlend, METH_VARARGS,
281
"(float) - change Lamp spot blend value"},
282
{"setClipStart", ( PyCFunction ) Lamp_setClipStart, METH_VARARGS,
283
"(float) - change Lamp clip start value"},
284
{"setClipEnd", ( PyCFunction ) Lamp_setClipEnd, METH_VARARGS,
285
"(float) - change Lamp clip end value"},
286
{"setBias", ( PyCFunction ) Lamp_setBias, METH_VARARGS,
287
"(float) - change Lamp draw size value"},
288
{"setSoftness", ( PyCFunction ) Lamp_setSoftness, METH_VARARGS,
289
"(float) - change Lamp softness value"},
290
{"setHaloInt", ( PyCFunction ) Lamp_setHaloInt, METH_VARARGS,
291
"(float) - change Lamp halo intensity value"},
292
{"setQuad1", ( PyCFunction ) Lamp_setQuad1, METH_VARARGS,
293
"(float) - change light intensity value #1 for a Quad Lamp"},
294
{"setQuad2", ( PyCFunction ) Lamp_setQuad2, METH_VARARGS,
295
"(float) - change light intensity value #2 for a Quad Lamp"},
296
{"setCol", ( PyCFunction ) Lamp_setCol, METH_VARARGS,
297
"(f,f,f) or ([f,f,f]) - change light's rgb color triplet"},
298
{"getScriptLinks", ( PyCFunction ) Lamp_getScriptLinks, METH_VARARGS,
299
"(eventname) - Get a list of this lamp's scriptlinks (Text names) "
300
"of the given type\n"
301
"(eventname) - string: FrameChanged, Redraw or Render."},
302
{"addScriptLink", ( PyCFunction ) Lamp_addScriptLink, METH_VARARGS,
303
"(text, evt) - Add a new lamp scriptlink.\n"
304
"(text) - string: an existing Blender Text name;\n"
305
"(evt) string: FrameChanged, Redraw or Render."},
306
{"clearScriptLinks", ( PyCFunction ) Lamp_clearScriptLinks,
308
"() - Delete all scriptlinks from this lamp.\n"
309
"([s1<,s2,s3...>]) - Delete specified scriptlinks from this lamp."},
310
{"getIpo", ( PyCFunction ) Lamp_getIpo, METH_NOARGS,
311
"() - get IPO for this lamp"},
312
{"clearIpo", ( PyCFunction ) Lamp_clearIpo, METH_NOARGS,
313
"() - unlink the IPO for this lamp"},
314
{"setIpo", ( PyCFunction ) Lamp_setIpo, METH_VARARGS,
315
"( lamp-ipo ) - link an IPO to this lamp"},
316
{"insertIpoKey", ( PyCFunction ) Lamp_insertIpoKey, METH_VARARGS,
317
"( Lamp IPO type ) - Inserts a key into IPO"},
319
{NULL, NULL, 0, NULL}
322
/*****************************************************************************/
323
/* Python TypeLamp callback function prototypes: */
324
/*****************************************************************************/
325
static void Lamp_dealloc( BPy_Lamp * lamp );
326
static PyObject *Lamp_getAttr( BPy_Lamp * lamp, char *name );
327
static int Lamp_setAttr( BPy_Lamp * lamp, char *name, PyObject * v );
328
static int Lamp_compare( BPy_Lamp * a, BPy_Lamp * b );
329
static PyObject *Lamp_repr( BPy_Lamp * lamp );
34
332
/*****************************************************************************/
35
333
/* Python TypeLamp structure definition: */
36
334
/*****************************************************************************/
37
PyTypeObject Lamp_Type =
39
PyObject_HEAD_INIT(NULL)
41
"Blender Lamp", /* tp_name */
42
sizeof (BPy_Lamp), /* tp_basicsize */
45
(destructor)Lamp_dealloc, /* tp_dealloc */
47
(getattrfunc)Lamp_getAttr, /* tp_getattr */
48
(setattrfunc)Lamp_setAttr, /* tp_setattr */
49
(cmpfunc)Lamp_compare, /* tp_compare */
50
(reprfunc)Lamp_repr, /* tp_repr */
52
0, /* tp_as_sequence */
53
0, /* tp_as_mapping */
58
BPy_Lamp_methods, /* tp_methods */
335
PyTypeObject Lamp_Type = {
336
PyObject_HEAD_INIT( NULL )
338
"Blender Lamp", /* tp_name */
339
sizeof( BPy_Lamp ), /* tp_basicsize */
342
( destructor ) Lamp_dealloc, /* tp_dealloc */
344
( getattrfunc ) Lamp_getAttr, /* tp_getattr */
345
( setattrfunc ) Lamp_setAttr, /* tp_setattr */
346
( cmpfunc ) Lamp_compare, /* tp_compare */
347
( reprfunc ) Lamp_repr, /* tp_repr */
348
0, /* tp_as_number */
349
0, /* tp_as_sequence */
350
0, /* tp_as_mapping */
355
BPy_Lamp_methods, /* tp_methods */
357
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
62
360
/*****************************************************************************/
63
361
/* Function: M_Lamp_New */
64
362
/* Python equivalent: Blender.Lamp.New */
65
363
/*****************************************************************************/
66
static PyObject *M_Lamp_New(PyObject *self, PyObject *args, PyObject *keywords)
364
static PyObject *M_Lamp_New( PyObject * self, PyObject * args,
365
PyObject * keywords )
68
char *type_str = "Lamp";
69
char *name_str = "LampData";
70
static char *kwlist[] = {"type_str", "name_str", NULL};
71
BPy_Lamp *py_lamp; /* for Lamp Data object wrapper in Python */
72
Lamp *bl_lamp; /* for actual Lamp Data we create in Blender */
75
if (!PyArg_ParseTupleAndKeywords(args, keywords, "|ss", kwlist,
76
&type_str, &name_str))
77
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
78
"expected string(s) or empty argument"));
80
bl_lamp = add_lamp(); /* first create in Blender */
81
if (bl_lamp) /* now create the wrapper obj in Python */
82
py_lamp = (BPy_Lamp *)Lamp_CreatePyObject(bl_lamp);
84
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
85
"couldn't create Lamp Data in Blender"));
367
char *type_str = "Lamp";
368
char *name_str = "LampData";
369
static char *kwlist[] = { "type_str", "name_str", NULL };
370
BPy_Lamp *py_lamp; /* for Lamp Data object wrapper in Python */
371
Lamp *bl_lamp; /* for actual Lamp Data we create in Blender */
374
if( !PyArg_ParseTupleAndKeywords( args, keywords, "|ss", kwlist,
375
&type_str, &name_str ) )
376
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
377
"expected string(s) or empty argument" ) );
379
bl_lamp = add_lamp( ); /* first create in Blender */
380
if( bl_lamp ) /* now create the wrapper obj in Python */
381
py_lamp = ( BPy_Lamp * ) Lamp_CreatePyObject( bl_lamp );
383
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
384
"couldn't create Lamp Data in Blender" ) );
87
386
/* let's return user count to zero, because ... */
88
bl_lamp->id.us = 0; /* ... add_lamp() incref'ed it */
91
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
92
"couldn't create Lamp Data object"));
94
if (strcmp (type_str, "Lamp") == 0)
95
bl_lamp->type = (short)EXPP_LAMP_TYPE_LAMP;
96
else if (strcmp (type_str, "Sun") == 0)
97
bl_lamp->type = (short)EXPP_LAMP_TYPE_SUN;
98
else if (strcmp (type_str, "Spot") == 0)
99
bl_lamp->type = (short)EXPP_LAMP_TYPE_SPOT;
100
else if (strcmp (type_str, "Hemi") == 0)
101
bl_lamp->type = (short)EXPP_LAMP_TYPE_HEMI;
103
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
104
"unknown lamp type"));
106
if (strcmp(name_str, "LampData") == 0)
107
return (PyObject *)py_lamp;
108
else { /* user gave us a name for the lamp, use it */
109
PyOS_snprintf(buf, sizeof(buf), "%s", name_str);
110
rename_id(&bl_lamp->id, buf);
113
return (PyObject *)py_lamp;
387
bl_lamp->id.us = 0; /* ... add_lamp() incref'ed it */
389
if( py_lamp == NULL )
390
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
391
"couldn't create Lamp Data object" ) );
393
if( strcmp( type_str, "Lamp" ) == 0 )
394
bl_lamp->type = ( short ) EXPP_LAMP_TYPE_LAMP;
395
else if( strcmp( type_str, "Sun" ) == 0 )
396
bl_lamp->type = ( short ) EXPP_LAMP_TYPE_SUN;
397
else if( strcmp( type_str, "Spot" ) == 0 )
398
bl_lamp->type = ( short ) EXPP_LAMP_TYPE_SPOT;
399
else if( strcmp( type_str, "Hemi" ) == 0 )
400
bl_lamp->type = ( short ) EXPP_LAMP_TYPE_HEMI;
401
else if( strcmp( type_str, "Area" ) == 0 )
402
bl_lamp->type = ( short ) EXPP_LAMP_TYPE_AREA;
403
else if( strcmp( type_str, "Photon" ) == 0 )
404
bl_lamp->type = ( short ) EXPP_LAMP_TYPE_YF_PHOTON;
406
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
407
"unknown lamp type" ) );
409
if( strcmp( name_str, "LampData" ) == 0 )
410
return ( PyObject * ) py_lamp;
411
else { /* user gave us a name for the lamp, use it */
412
PyOS_snprintf( buf, sizeof( buf ), "%s", name_str );
413
rename_id( &bl_lamp->id, buf );
416
return ( PyObject * ) py_lamp;
116
419
/*****************************************************************************/
121
424
/* passed in, a list of all lamp data names in the */
122
425
/* current scene is returned. */
123
426
/*****************************************************************************/
124
static PyObject *M_Lamp_Get(PyObject *self, PyObject *args)
427
static PyObject *M_Lamp_Get( PyObject * self, PyObject * args )
129
if (!PyArg_ParseTuple(args, "|s", &name))
130
return (EXPP_ReturnPyObjError (PyExc_TypeError,
131
"expected string argument (or nothing)"));
133
lamp_iter = G.main->lamp.first;
135
if (name) { /* (name) - Search lamp by name */
137
BPy_Lamp *wanted_lamp = NULL;
139
while ((lamp_iter) && (wanted_lamp == NULL)) {
141
if (strcmp (name, lamp_iter->id.name+2) == 0)
142
wanted_lamp = (BPy_Lamp *)Lamp_CreatePyObject(lamp_iter);
144
lamp_iter = lamp_iter->id.next;
147
if (wanted_lamp == NULL) { /* Requested lamp doesn't exist */
149
PyOS_snprintf(error_msg, sizeof(error_msg),
150
"Lamp \"%s\" not found", name);
151
return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
154
return (PyObject *)wanted_lamp;
157
else { /* () - return a list of all lamps in the scene */
159
PyObject *lamplist, *pyobj;
161
lamplist = PyList_New (BLI_countlist (&(G.main->lamp)));
163
if (lamplist == NULL)
164
return (PythonReturnErrorObject (PyExc_MemoryError,
165
"couldn't create PyList"));
168
pyobj = Lamp_CreatePyObject (lamp_iter);
171
return (PythonReturnErrorObject (PyExc_MemoryError,
172
"couldn't create PyString"));
174
PyList_SET_ITEM (lamplist, index, pyobj);
176
lamp_iter = lamp_iter->id.next;
184
static PyObject *Lamp_TypesDict (void)
185
{ /* create the Blender.Lamp.Types constant dict */
186
PyObject *Types = M_constant_New();
189
BPy_constant *c = (BPy_constant *)Types;
191
constant_insert (c, "Lamp", PyInt_FromLong (EXPP_LAMP_TYPE_LAMP));
192
constant_insert (c, "Sun", PyInt_FromLong (EXPP_LAMP_TYPE_SUN));
193
constant_insert (c, "Spot", PyInt_FromLong (EXPP_LAMP_TYPE_SPOT));
194
constant_insert (c, "Hemi", PyInt_FromLong (EXPP_LAMP_TYPE_HEMI));
201
static PyObject *Lamp_ModesDict (void)
202
{ /* create the Blender.Lamp.Modes constant dict */
203
PyObject *Modes = M_constant_New();
206
BPy_constant *c = (BPy_constant *)Modes;
208
constant_insert (c, "Shadows", PyInt_FromLong (EXPP_LAMP_MODE_SHADOWS));
209
constant_insert (c, "Halo", PyInt_FromLong (EXPP_LAMP_MODE_HALO));
210
constant_insert (c, "Layer", PyInt_FromLong (EXPP_LAMP_MODE_LAYER));
211
constant_insert (c, "Quad", PyInt_FromLong (EXPP_LAMP_MODE_QUAD));
212
constant_insert (c, "Negative", PyInt_FromLong (EXPP_LAMP_MODE_NEGATIVE));
213
constant_insert (c, "Sphere", PyInt_FromLong (EXPP_LAMP_MODE_SPHERE));
214
constant_insert (c, "Square", PyInt_FromLong (EXPP_LAMP_MODE_SQUARE));
215
constant_insert (c, "OnlyShadow",
216
PyInt_FromLong (EXPP_LAMP_MODE_ONLYSHADOW));
217
constant_insert (c, "NoDiffuse",
218
PyInt_FromLong (EXPP_LAMP_MODE_NODIFFUSE));
219
constant_insert (c, "NoSpecular",
220
PyInt_FromLong (EXPP_LAMP_MODE_NOSPECULAR));
432
if( !PyArg_ParseTuple( args, "|s", &name ) )
433
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
434
"expected string argument (or nothing)" ) );
436
lamp_iter = G.main->lamp.first;
438
if( name ) { /* (name) - Search lamp by name */
440
BPy_Lamp *wanted_lamp = NULL;
442
while( ( lamp_iter ) && ( wanted_lamp == NULL ) ) {
444
if( strcmp( name, lamp_iter->id.name + 2 ) == 0 )
447
Lamp_CreatePyObject( lamp_iter );
449
lamp_iter = lamp_iter->id.next;
452
if( wanted_lamp == NULL ) { /* Requested lamp doesn't exist */
454
PyOS_snprintf( error_msg, sizeof( error_msg ),
455
"Lamp \"%s\" not found", name );
456
return ( EXPP_ReturnPyObjError
457
( PyExc_NameError, error_msg ) );
460
return ( PyObject * ) wanted_lamp;
463
else { /* () - return a list of all lamps in the scene */
465
PyObject *lamplist, *pyobj;
467
lamplist = PyList_New( BLI_countlist( &( G.main->lamp ) ) );
469
if( lamplist == NULL )
470
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
471
"couldn't create PyList" ) );
474
pyobj = Lamp_CreatePyObject( lamp_iter );
477
return ( EXPP_ReturnPyObjError
479
"couldn't create PyString" ) );
481
PyList_SET_ITEM( lamplist, index, pyobj );
483
lamp_iter = lamp_iter->id.next;
491
static PyObject *Lamp_TypesDict( void )
492
{ /* create the Blender.Lamp.Types constant dict */
493
PyObject *Types = M_constant_New( );
496
BPy_constant *c = ( BPy_constant * ) Types;
498
constant_insert( c, "Lamp",
499
PyInt_FromLong( EXPP_LAMP_TYPE_LAMP ) );
500
constant_insert( c, "Sun",
501
PyInt_FromLong( EXPP_LAMP_TYPE_SUN ) );
502
constant_insert( c, "Spot",
503
PyInt_FromLong( EXPP_LAMP_TYPE_SPOT ) );
504
constant_insert( c, "Hemi",
505
PyInt_FromLong( EXPP_LAMP_TYPE_HEMI ) );
506
constant_insert( c, "Area",
507
PyInt_FromLong( EXPP_LAMP_TYPE_AREA ) );
508
constant_insert( c, "Photon",
509
PyInt_FromLong( EXPP_LAMP_TYPE_YF_PHOTON ) );
515
static PyObject *Lamp_ModesDict( void )
516
{ /* create the Blender.Lamp.Modes constant dict */
517
PyObject *Modes = M_constant_New( );
520
BPy_constant *c = ( BPy_constant * ) Modes;
522
constant_insert( c, "Shadows",
523
PyInt_FromLong( EXPP_LAMP_MODE_SHADOWS ) );
524
constant_insert( c, "Halo",
525
PyInt_FromLong( EXPP_LAMP_MODE_HALO ) );
526
constant_insert( c, "Layer",
527
PyInt_FromLong( EXPP_LAMP_MODE_LAYER ) );
528
constant_insert( c, "Quad",
529
PyInt_FromLong( EXPP_LAMP_MODE_QUAD ) );
530
constant_insert( c, "Negative",
531
PyInt_FromLong( EXPP_LAMP_MODE_NEGATIVE ) );
532
constant_insert( c, "Sphere",
533
PyInt_FromLong( EXPP_LAMP_MODE_SPHERE ) );
534
constant_insert( c, "Square",
535
PyInt_FromLong( EXPP_LAMP_MODE_SQUARE ) );
536
constant_insert( c, "OnlyShadow",
537
PyInt_FromLong( EXPP_LAMP_MODE_ONLYSHADOW ) );
538
constant_insert( c, "NoDiffuse",
539
PyInt_FromLong( EXPP_LAMP_MODE_NODIFFUSE ) );
540
constant_insert( c, "NoSpecular",
541
PyInt_FromLong( EXPP_LAMP_MODE_NOSPECULAR ) );
226
547
/*****************************************************************************/
227
548
/* Function: Lamp_Init */
228
549
/*****************************************************************************/
229
550
/* Needed by the Blender module, to register the Blender.Lamp submodule */
230
PyObject *Lamp_Init (void)
551
PyObject *Lamp_Init( void )
232
PyObject *submodule, *Types, *Modes;
234
Lamp_Type.ob_type = &PyType_Type;
236
Types = Lamp_TypesDict ();
237
Modes = Lamp_ModesDict ();
239
submodule = Py_InitModule3("Blender.Lamp", M_Lamp_methods, M_Lamp_doc);
241
if (Types) PyModule_AddObject(submodule, "Types", Types);
242
if (Modes) PyModule_AddObject(submodule, "Modes", Modes);
553
PyObject *submodule, *Types, *Modes;
555
Lamp_Type.ob_type = &PyType_Type;
557
Types = Lamp_TypesDict( );
558
Modes = Lamp_ModesDict( );
561
Py_InitModule3( "Blender.Lamp", M_Lamp_methods, M_Lamp_doc );
564
PyModule_AddObject( submodule, "Types", Types );
566
PyModule_AddObject( submodule, "Modes", Modes );
568
PyModule_AddIntConstant( submodule, "RGB", IPOKEY_RGB );
569
PyModule_AddIntConstant( submodule, "ENERGY", IPOKEY_ENERGY );
570
PyModule_AddIntConstant( submodule, "SPOTSIZE", IPOKEY_SPOTSIZE );
571
PyModule_AddIntConstant( submodule, "OFFSET", IPOKEY_OFFSET );
572
PyModule_AddIntConstant( submodule, "SIZE", IPOKEY_SIZE );
247
577
/* Three Python Lamp_Type helper functions needed by the Object module: */
322
650
/*****************************************************************************/
323
651
/* Python BPy_Lamp methods: */
324
652
/*****************************************************************************/
325
static PyObject *Lamp_getName(BPy_Lamp *self)
327
PyObject *attr = PyString_FromString(self->lamp->id.name+2);
329
if (attr) return attr;
331
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
332
"couldn't get Lamp.name attribute"));
335
static PyObject *Lamp_getType(BPy_Lamp *self)
337
PyObject *attr = PyInt_FromLong(self->lamp->type);
339
if (attr) return attr;
341
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
342
"couldn't get Lamp.type attribute"));
345
static PyObject *Lamp_getMode(BPy_Lamp *self)
347
PyObject *attr = PyInt_FromLong(self->lamp->mode);
349
if (attr) return attr;
351
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
352
"couldn't get Lamp.mode attribute"));
355
static PyObject *Lamp_getSamples(BPy_Lamp *self)
357
PyObject *attr = PyInt_FromLong(self->lamp->samp);
359
if (attr) return attr;
361
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
362
"couldn't get Lamp.samples attribute"));
365
static PyObject *Lamp_getBufferSize(BPy_Lamp *self)
367
PyObject *attr = PyInt_FromLong(self->lamp->bufsize);
369
if (attr) return attr;
371
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
372
"couldn't get Lamp.bufferSize attribute"));
375
static PyObject *Lamp_getHaloStep(BPy_Lamp *self)
377
PyObject *attr = PyInt_FromLong(self->lamp->shadhalostep);
379
if (attr) return attr;
381
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
382
"couldn't get Lamp.haloStep attribute"));
385
static PyObject *Lamp_getEnergy(BPy_Lamp *self)
387
PyObject *attr = PyFloat_FromDouble(self->lamp->energy);
389
if (attr) return attr;
391
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
392
"couldn't get Lamp.energy attribute"));
395
static PyObject *Lamp_getDist(BPy_Lamp *self)
397
PyObject *attr = PyFloat_FromDouble(self->lamp->dist);
399
if (attr) return attr;
401
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
402
"couldn't get Lamp.dist attribute"));
405
static PyObject *Lamp_getSpotSize(BPy_Lamp *self)
407
PyObject *attr = PyFloat_FromDouble(self->lamp->spotsize);
409
if (attr) return attr;
411
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
412
"couldn't get Lamp.spotSize attribute"));
415
static PyObject *Lamp_getSpotBlend(BPy_Lamp *self)
417
PyObject *attr = PyFloat_FromDouble(self->lamp->spotblend);
419
if (attr) return attr;
421
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
422
"couldn't get Lamp.spotBlend attribute"));
425
static PyObject *Lamp_getClipStart(BPy_Lamp *self)
427
PyObject *attr = PyFloat_FromDouble(self->lamp->clipsta);
429
if (attr) return attr;
431
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
432
"couldn't get Lamp.clipStart attribute"));
435
static PyObject *Lamp_getClipEnd(BPy_Lamp *self)
437
PyObject *attr = PyFloat_FromDouble(self->lamp->clipend);
439
if (attr) return attr;
441
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
442
"couldn't get Lamp.clipEnd attribute"));
445
static PyObject *Lamp_getBias(BPy_Lamp *self)
447
PyObject *attr = PyFloat_FromDouble(self->lamp->bias);
449
if (attr) return attr;
451
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
452
"couldn't get Lamp.bias attribute"));
455
static PyObject *Lamp_getSoftness(BPy_Lamp *self)
457
PyObject *attr = PyFloat_FromDouble(self->lamp->soft);
459
if (attr) return attr;
461
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
462
"couldn't get Lamp.softness attribute"));
465
static PyObject *Lamp_getHaloInt(BPy_Lamp *self)
467
PyObject *attr = PyFloat_FromDouble(self->lamp->haint);
469
if (attr) return attr;
471
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
472
"couldn't get Lamp.haloInt attribute"));
475
static PyObject *Lamp_getQuad1(BPy_Lamp *self)
476
{ /* should we complain if Lamp is not of type Quad? */
477
PyObject *attr = PyFloat_FromDouble(self->lamp->att1);
479
if (attr) return attr;
481
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
482
"couldn't get Lamp.quad1 attribute"));
485
static PyObject *Lamp_getQuad2(BPy_Lamp *self)
486
{ /* should we complain if Lamp is not of type Quad? */
487
PyObject *attr = PyFloat_FromDouble(self->lamp->att2);
489
if (attr) return attr;
491
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
492
"couldn't get Lamp.quad2 attribute"));
495
static PyObject *Lamp_getCol(BPy_Lamp *self)
497
return rgbTuple_getCol(self->color);
500
static PyObject *Lamp_setName(BPy_Lamp *self, PyObject *args)
505
if (!PyArg_ParseTuple(args, "s", &name))
506
return (EXPP_ReturnPyObjError (PyExc_TypeError,
507
"expected string argument"));
509
PyOS_snprintf(buf, sizeof(buf), "%s", name);
511
rename_id(&self->lamp->id, buf);
517
static PyObject *Lamp_setType(BPy_Lamp *self, PyObject *args)
521
if (!PyArg_ParseTuple(args, "s", &type))
522
return (EXPP_ReturnPyObjError (PyExc_TypeError,
523
"expected string argument"));
525
if (strcmp (type, "Lamp") == 0)
526
self->lamp->type = (short)EXPP_LAMP_TYPE_LAMP;
527
else if (strcmp (type, "Sun") == 0)
528
self->lamp->type = (short)EXPP_LAMP_TYPE_SUN;
529
else if (strcmp (type, "Spot") == 0)
530
self->lamp->type = (short)EXPP_LAMP_TYPE_SPOT;
531
else if (strcmp (type, "Hemi") == 0)
532
self->lamp->type = (short)EXPP_LAMP_TYPE_HEMI;
534
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
535
"unknown lamp type"));
653
static PyObject *Lamp_getName( BPy_Lamp * self )
655
PyObject *attr = PyString_FromString( self->lamp->id.name + 2 );
660
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
661
"couldn't get Lamp.name attribute" ) );
664
static PyObject *Lamp_getType( BPy_Lamp * self )
666
PyObject *attr = PyInt_FromLong( self->lamp->type );
671
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
672
"couldn't get Lamp.type attribute" ) );
675
static PyObject *Lamp_getMode( BPy_Lamp * self )
677
PyObject *attr = PyInt_FromLong( self->lamp->mode );
682
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
683
"couldn't get Lamp.mode attribute" ) );
686
static PyObject *Lamp_getSamples( BPy_Lamp * self )
688
PyObject *attr = PyInt_FromLong( self->lamp->samp );
693
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
694
"couldn't get Lamp.samples attribute" ) );
697
static PyObject *Lamp_getBufferSize( BPy_Lamp * self )
699
PyObject *attr = PyInt_FromLong( self->lamp->bufsize );
704
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
705
"couldn't get Lamp.bufferSize attribute" ) );
708
static PyObject *Lamp_getHaloStep( BPy_Lamp * self )
710
PyObject *attr = PyInt_FromLong( self->lamp->shadhalostep );
715
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
716
"couldn't get Lamp.haloStep attribute" ) );
719
static PyObject *Lamp_getEnergy( BPy_Lamp * self )
721
PyObject *attr = PyFloat_FromDouble( self->lamp->energy );
726
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
727
"couldn't get Lamp.energy attribute" ) );
730
static PyObject *Lamp_getDist( BPy_Lamp * self )
732
PyObject *attr = PyFloat_FromDouble( self->lamp->dist );
737
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
738
"couldn't get Lamp.dist attribute" ) );
741
static PyObject *Lamp_getSpotSize( BPy_Lamp * self )
743
PyObject *attr = PyFloat_FromDouble( self->lamp->spotsize );
748
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
749
"couldn't get Lamp.spotSize attribute" ) );
752
static PyObject *Lamp_getSpotBlend( BPy_Lamp * self )
754
PyObject *attr = PyFloat_FromDouble( self->lamp->spotblend );
759
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
760
"couldn't get Lamp.spotBlend attribute" ) );
763
static PyObject *Lamp_getClipStart( BPy_Lamp * self )
765
PyObject *attr = PyFloat_FromDouble( self->lamp->clipsta );
770
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
771
"couldn't get Lamp.clipStart attribute" ) );
774
static PyObject *Lamp_getClipEnd( BPy_Lamp * self )
776
PyObject *attr = PyFloat_FromDouble( self->lamp->clipend );
781
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
782
"couldn't get Lamp.clipEnd attribute" ) );
785
static PyObject *Lamp_getBias( BPy_Lamp * self )
787
PyObject *attr = PyFloat_FromDouble( self->lamp->bias );
792
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
793
"couldn't get Lamp.bias attribute" ) );
796
static PyObject *Lamp_getSoftness( BPy_Lamp * self )
798
PyObject *attr = PyFloat_FromDouble( self->lamp->soft );
803
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
804
"couldn't get Lamp.softness attribute" ) );
807
static PyObject *Lamp_getHaloInt( BPy_Lamp * self )
809
PyObject *attr = PyFloat_FromDouble( self->lamp->haint );
814
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
815
"couldn't get Lamp.haloInt attribute" ) );
818
static PyObject *Lamp_getQuad1( BPy_Lamp * self )
819
{ /* should we complain if Lamp is not of type Quad? */
820
PyObject *attr = PyFloat_FromDouble( self->lamp->att1 );
825
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
826
"couldn't get Lamp.quad1 attribute" ) );
829
static PyObject *Lamp_getQuad2( BPy_Lamp * self )
830
{ /* should we complain if Lamp is not of type Quad? */
831
PyObject *attr = PyFloat_FromDouble( self->lamp->att2 );
836
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
837
"couldn't get Lamp.quad2 attribute" ) );
840
static PyObject *Lamp_getCol( BPy_Lamp * self )
842
return rgbTuple_getCol( self->color );
845
static PyObject *Lamp_setName( BPy_Lamp * self, PyObject * args )
850
if( !PyArg_ParseTuple( args, "s", &name ) )
851
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
852
"expected string argument" ) );
854
PyOS_snprintf( buf, sizeof( buf ), "%s", name );
856
rename_id( &self->lamp->id, buf );
858
Py_INCREF( Py_None );
862
static PyObject *Lamp_setType( BPy_Lamp * self, PyObject * args )
866
if( !PyArg_ParseTuple( args, "s", &type ) )
867
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
868
"expected string argument" ) );
870
if( strcmp( type, "Lamp" ) == 0 )
871
self->lamp->type = ( short ) EXPP_LAMP_TYPE_LAMP;
872
else if( strcmp( type, "Sun" ) == 0 )
873
self->lamp->type = ( short ) EXPP_LAMP_TYPE_SUN;
874
else if( strcmp( type, "Spot" ) == 0 )
875
self->lamp->type = ( short ) EXPP_LAMP_TYPE_SPOT;
876
else if( strcmp( type, "Hemi" ) == 0 )
877
self->lamp->type = ( short ) EXPP_LAMP_TYPE_HEMI;
878
else if( strcmp( type, "Area" ) == 0 )
879
self->lamp->type = ( short ) EXPP_LAMP_TYPE_AREA;
880
else if( strcmp( type, "Photon" ) == 0 )
881
self->lamp->type = ( short ) EXPP_LAMP_TYPE_YF_PHOTON;
883
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
884
"unknown lamp type" ) );
886
Py_INCREF( Py_None );
541
890
/* This one is 'private'. It is not really a method, just a helper function for
542
891
* when script writers use Lamp.type = t instead of Lamp.setType(t), since in
543
892
* the first case t shoud be an int and in the second it should be a string. So
544
* while the method setType expects a string ('persp' or 'ortho') or an empty
893
* while the method setType expects a string or an empty
545
894
* argument, this function should receive an int (0 or 1). */
546
static PyObject *Lamp_setIntType(BPy_Lamp *self, PyObject *args)
895
static PyObject *Lamp_setIntType( BPy_Lamp * self, PyObject * args )
550
if (!PyArg_ParseTuple(args, "h", &value))
551
return (EXPP_ReturnPyObjError (PyExc_TypeError,
552
"expected int argument in [0,3]"));
554
if (value >= 0 && value <= 3)
555
self->lamp->type = value;
557
return (EXPP_ReturnPyObjError (PyExc_ValueError,
558
"expected int argument in [0,3]"));
899
if( !PyArg_ParseTuple( args, "h", &value ) )
900
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
901
"expected int argument in [0,5]" ) );
903
if( value >= 0 && value <= EXPP_LAMP_TYPE_MAX )
904
self->lamp->type = value;
906
return ( EXPP_ReturnPyObjError( PyExc_ValueError,
907
"expected int argument in [0,5]" ) );
909
Py_INCREF( Py_None );
564
static PyObject *Lamp_setMode(BPy_Lamp *self, PyObject *args)
913
static PyObject *Lamp_setMode( BPy_Lamp * self, PyObject * args )
566
char *m[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
569
if (!PyArg_ParseTuple(args, "|ssssssss", &m[0], &m[1], &m[2],
570
&m[3], &m[4], &m[5], &m[6], &m[7], &m[8], &m[9]))
571
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
572
"expected from none to 10 string argument(s)"));
574
for (i = 0; i < 10; i++) {
575
if (m[i] == NULL) break;
576
if (strcmp(m[i], "Shadows") == 0)
577
flag |= (short)EXPP_LAMP_MODE_SHADOWS;
578
else if (strcmp(m[i], "Halo") == 0)
579
flag |= (short)EXPP_LAMP_MODE_HALO;
580
else if (strcmp(m[i], "Layer") == 0)
581
flag |= (short)EXPP_LAMP_MODE_LAYER;
582
else if (strcmp(m[i], "Quad") == 0)
583
flag |= (short)EXPP_LAMP_MODE_QUAD;
584
else if (strcmp(m[i], "Negative") == 0)
585
flag |= (short)EXPP_LAMP_MODE_NEGATIVE;
586
else if (strcmp(m[i], "OnlyShadow") == 0)
587
flag |= (short)EXPP_LAMP_MODE_ONLYSHADOW;
588
else if (strcmp(m[i], "Sphere") == 0)
589
flag |= (short)EXPP_LAMP_MODE_SPHERE;
590
else if (strcmp(m[i], "Square") == 0)
591
flag |= (short)EXPP_LAMP_MODE_SQUARE;
592
else if (strcmp(m[i], "NoDiffuse") == 0)
593
flag |= (short)EXPP_LAMP_MODE_NODIFFUSE;
594
else if (strcmp(m[i], "NoSpecular") == 0)
595
flag |= (short)EXPP_LAMP_MODE_NOSPECULAR;
597
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
598
"unknown lamp flag argument"));
601
self->lamp->mode = flag;
916
{ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
919
if( !PyArg_ParseTuple( args, "|ssssssss", &m[0], &m[1], &m[2],
920
&m[3], &m[4], &m[5], &m[6], &m[7], &m[8],
922
return ( EXPP_ReturnPyObjError
923
( PyExc_AttributeError,
924
"expected from none to 10 string argument(s)" ) );
926
for( i = 0; i < 10; i++ ) {
929
if( strcmp( m[i], "Shadows" ) == 0 )
930
flag |= ( short ) EXPP_LAMP_MODE_SHADOWS;
931
else if( strcmp( m[i], "Halo" ) == 0 )
932
flag |= ( short ) EXPP_LAMP_MODE_HALO;
933
else if( strcmp( m[i], "Layer" ) == 0 )
934
flag |= ( short ) EXPP_LAMP_MODE_LAYER;
935
else if( strcmp( m[i], "Quad" ) == 0 )
936
flag |= ( short ) EXPP_LAMP_MODE_QUAD;
937
else if( strcmp( m[i], "Negative" ) == 0 )
938
flag |= ( short ) EXPP_LAMP_MODE_NEGATIVE;
939
else if( strcmp( m[i], "OnlyShadow" ) == 0 )
940
flag |= ( short ) EXPP_LAMP_MODE_ONLYSHADOW;
941
else if( strcmp( m[i], "Sphere" ) == 0 )
942
flag |= ( short ) EXPP_LAMP_MODE_SPHERE;
943
else if( strcmp( m[i], "Square" ) == 0 )
944
flag |= ( short ) EXPP_LAMP_MODE_SQUARE;
945
else if( strcmp( m[i], "NoDiffuse" ) == 0 )
946
flag |= ( short ) EXPP_LAMP_MODE_NODIFFUSE;
947
else if( strcmp( m[i], "NoSpecular" ) == 0 )
948
flag |= ( short ) EXPP_LAMP_MODE_NOSPECULAR;
950
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
951
"unknown lamp flag argument" ) );
954
self->lamp->mode = flag;
956
Py_INCREF( Py_None );
607
960
/* Another helper function, for the same reason.
608
961
* (See comment before Lamp_setIntType above). */
609
static PyObject *Lamp_setIntMode(BPy_Lamp *self, PyObject *args)
962
static PyObject *Lamp_setIntMode( BPy_Lamp * self, PyObject * args )
613
if (!PyArg_ParseTuple(args, "h", &value))
614
return (EXPP_ReturnPyObjError (PyExc_TypeError,
615
"expected int argument"));
966
if( !PyArg_ParseTuple( args, "h", &value ) )
967
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
968
"expected int argument" ) );
617
970
/* well, with so many flag bits, we just accept any short int, no checking */
618
self->lamp->mode = value;
624
static PyObject *Lamp_setSamples(BPy_Lamp *self, PyObject *args)
628
if (!PyArg_ParseTuple(args, "h", &value))
629
return (EXPP_ReturnPyObjError (PyExc_TypeError,
630
"expected int argument in [1,16]"));
632
self->lamp->samp = EXPP_ClampInt (value,
633
EXPP_LAMP_SAMPLES_MIN, EXPP_LAMP_SAMPLES_MAX);
639
static PyObject *Lamp_setBufferSize(BPy_Lamp *self, PyObject *args)
643
if (!PyArg_ParseTuple(args, "h", &value))
644
return (EXPP_ReturnPyObjError (PyExc_TypeError,
645
"expected int argument in [512, 5120]"));
647
self->lamp->bufsize = EXPP_ClampInt (value,
648
EXPP_LAMP_BUFFERSIZE_MIN, EXPP_LAMP_BUFFERSIZE_MAX);
654
static PyObject *Lamp_setHaloStep(BPy_Lamp *self, PyObject *args)
658
if (!PyArg_ParseTuple(args, "h", &value))
659
return (EXPP_ReturnPyObjError (PyExc_TypeError,
660
"expected int argument in [0,12]"));
662
self->lamp->shadhalostep = EXPP_ClampInt (value,
663
EXPP_LAMP_HALOSTEP_MIN, EXPP_LAMP_HALOSTEP_MAX);
669
static PyObject *Lamp_setEnergy(BPy_Lamp *self, PyObject *args)
673
if (!PyArg_ParseTuple(args, "f", &value))
674
return (EXPP_ReturnPyObjError (PyExc_TypeError,
675
"expected float argument"));
677
self->lamp->energy = EXPP_ClampFloat (value,
678
EXPP_LAMP_ENERGY_MIN, EXPP_LAMP_ENERGY_MAX);
684
static PyObject *Lamp_setDist(BPy_Lamp *self, PyObject *args)
688
if (!PyArg_ParseTuple(args, "f", &value))
689
return (EXPP_ReturnPyObjError (PyExc_TypeError,
690
"expected float argument"));
692
self->lamp->dist = EXPP_ClampFloat (value,
693
EXPP_LAMP_DIST_MIN, EXPP_LAMP_DIST_MAX);
699
static PyObject *Lamp_setSpotSize(BPy_Lamp *self, PyObject *args)
703
if (!PyArg_ParseTuple(args, "f", &value))
704
return (EXPP_ReturnPyObjError (PyExc_TypeError,
705
"expected float argument"));
707
self->lamp->spotsize = EXPP_ClampFloat (value,
708
EXPP_LAMP_SPOTSIZE_MIN, EXPP_LAMP_SPOTSIZE_MAX);
714
static PyObject *Lamp_setSpotBlend(BPy_Lamp *self, PyObject *args)
718
if (!PyArg_ParseTuple(args, "f", &value))
719
return (EXPP_ReturnPyObjError (PyExc_TypeError,
720
"expected float argument"));
722
self->lamp->spotblend = EXPP_ClampFloat (value,
723
EXPP_LAMP_SPOTBLEND_MIN, EXPP_LAMP_SPOTBLEND_MAX);
729
static PyObject *Lamp_setClipStart(BPy_Lamp *self, PyObject *args)
733
if (!PyArg_ParseTuple(args, "f", &value))
734
return (EXPP_ReturnPyObjError (PyExc_TypeError,
735
"expected float argument"));
737
self->lamp->clipsta = EXPP_ClampFloat (value,
738
EXPP_LAMP_CLIPSTART_MIN, EXPP_LAMP_CLIPSTART_MAX);
744
static PyObject *Lamp_setClipEnd(BPy_Lamp *self, PyObject *args)
748
if (!PyArg_ParseTuple(args, "f", &value))
749
return (EXPP_ReturnPyObjError (PyExc_TypeError,
750
"expected float argument"));
752
self->lamp->clipend = EXPP_ClampFloat (value,
753
EXPP_LAMP_CLIPEND_MIN, EXPP_LAMP_CLIPEND_MAX);
759
static PyObject *Lamp_setBias(BPy_Lamp *self, PyObject *args)
763
if (!PyArg_ParseTuple(args, "f", &value))
764
return (EXPP_ReturnPyObjError (PyExc_TypeError,
765
"expected float argument"));
767
self->lamp->bias = EXPP_ClampFloat (value,
768
EXPP_LAMP_BIAS_MIN, EXPP_LAMP_BIAS_MAX);
774
static PyObject *Lamp_setSoftness(BPy_Lamp *self, PyObject *args)
778
if (!PyArg_ParseTuple(args, "f", &value))
779
return (EXPP_ReturnPyObjError (PyExc_TypeError,
780
"expected float argument"));
782
self->lamp->soft = EXPP_ClampFloat (value,
783
EXPP_LAMP_SOFTNESS_MIN, EXPP_LAMP_SOFTNESS_MAX);
789
static PyObject *Lamp_setHaloInt(BPy_Lamp *self, PyObject *args)
793
if (!PyArg_ParseTuple(args, "f", &value))
794
return (EXPP_ReturnPyObjError (PyExc_TypeError,
795
"expected float argument"));
797
self->lamp->haint = EXPP_ClampFloat (value,
798
EXPP_LAMP_HALOINT_MIN, EXPP_LAMP_HALOINT_MAX);
804
static PyObject *Lamp_setQuad1(BPy_Lamp *self, PyObject *args)
808
if (!PyArg_ParseTuple(args, "f", &value))
809
return (EXPP_ReturnPyObjError (PyExc_TypeError,
810
"expected float argument"));
812
self->lamp->att1 = EXPP_ClampFloat (value,
813
EXPP_LAMP_QUAD1_MIN, EXPP_LAMP_QUAD1_MAX);
819
static PyObject *Lamp_setQuad2(BPy_Lamp *self, PyObject *args)
823
if (!PyArg_ParseTuple(args, "f", &value))
824
return (EXPP_ReturnPyObjError (PyExc_TypeError,
825
"expected float argument"));
827
self->lamp->att2 = EXPP_ClampFloat (value,
828
EXPP_LAMP_QUAD2_MIN, EXPP_LAMP_QUAD2_MAX);
834
static PyObject *Lamp_setColorComponent(BPy_Lamp *self, char *key,
836
{ /* for compatibility with old bpython */
839
if (!PyArg_ParseTuple(args, "f", &value))
840
return (EXPP_ReturnPyObjError (PyExc_TypeError,
841
"expected float argument in [0.0, 1.0]"));
843
value = EXPP_ClampFloat (value, EXPP_LAMP_COL_MIN,
846
if (!strcmp(key, "R"))
847
self->lamp->r = value;
848
else if (!strcmp(key, "G"))
849
self->lamp->g = value;
850
else if (!strcmp(key, "B"))
851
self->lamp->b = value;
857
static PyObject *Lamp_setCol(BPy_Lamp *self, PyObject *args)
859
return rgbTuple_setCol(self->color, args);
971
self->lamp->mode = value;
973
Py_INCREF( Py_None );
977
static PyObject *Lamp_setSamples( BPy_Lamp * self, PyObject * args )
981
if( !PyArg_ParseTuple( args, "h", &value ) )
982
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
983
"expected int argument in [1,16]" ) );
985
self->lamp->samp = EXPP_ClampInt( value,
986
EXPP_LAMP_SAMPLES_MIN,
987
EXPP_LAMP_SAMPLES_MAX );
989
Py_INCREF( Py_None );
993
static PyObject *Lamp_setBufferSize( BPy_Lamp * self, PyObject * args )
997
if( !PyArg_ParseTuple( args, "h", &value ) )
998
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
999
"expected int argument in [512, 5120]" ) );
1001
self->lamp->bufsize = EXPP_ClampInt( value,
1002
EXPP_LAMP_BUFFERSIZE_MIN,
1003
EXPP_LAMP_BUFFERSIZE_MAX );
1005
Py_INCREF( Py_None );
1009
static PyObject *Lamp_setHaloStep( BPy_Lamp * self, PyObject * args )
1013
if( !PyArg_ParseTuple( args, "h", &value ) )
1014
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
1015
"expected int argument in [0,12]" ) );
1017
self->lamp->shadhalostep = EXPP_ClampInt( value,
1018
EXPP_LAMP_HALOSTEP_MIN,
1019
EXPP_LAMP_HALOSTEP_MAX );
1021
Py_INCREF( Py_None );
1025
static PyObject *Lamp_setEnergy( BPy_Lamp * self, PyObject * args )
1029
if( !PyArg_ParseTuple( args, "f", &value ) )
1030
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
1031
"expected float argument" ) );
1033
self->lamp->energy = EXPP_ClampFloat( value,
1034
EXPP_LAMP_ENERGY_MIN,
1035
EXPP_LAMP_ENERGY_MAX );
1037
Py_INCREF( Py_None );
1041
static PyObject *Lamp_setDist( BPy_Lamp * self, PyObject * args )
1045
if( !PyArg_ParseTuple( args, "f", &value ) )
1046
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
1047
"expected float argument" ) );
1049
self->lamp->dist = EXPP_ClampFloat( value,
1051
EXPP_LAMP_DIST_MAX );
1053
Py_INCREF( Py_None );
1057
static PyObject *Lamp_setSpotSize( BPy_Lamp * self, PyObject * args )
1061
if( !PyArg_ParseTuple( args, "f", &value ) )
1062
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
1063
"expected float argument" ) );
1065
self->lamp->spotsize = EXPP_ClampFloat( value,
1066
EXPP_LAMP_SPOTSIZE_MIN,
1067
EXPP_LAMP_SPOTSIZE_MAX );
1069
Py_INCREF( Py_None );
1073
static PyObject *Lamp_setSpotBlend( BPy_Lamp * self, PyObject * args )
1077
if( !PyArg_ParseTuple( args, "f", &value ) )
1078
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
1079
"expected float argument" ) );
1081
self->lamp->spotblend = EXPP_ClampFloat( value,
1082
EXPP_LAMP_SPOTBLEND_MIN,
1083
EXPP_LAMP_SPOTBLEND_MAX );
1085
Py_INCREF( Py_None );
1089
static PyObject *Lamp_setClipStart( BPy_Lamp * self, PyObject * args )
1093
if( !PyArg_ParseTuple( args, "f", &value ) )
1094
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
1095
"expected float argument" ) );
1097
self->lamp->clipsta = EXPP_ClampFloat( value,
1098
EXPP_LAMP_CLIPSTART_MIN,
1099
EXPP_LAMP_CLIPSTART_MAX );
1101
Py_INCREF( Py_None );
1105
static PyObject *Lamp_setClipEnd( BPy_Lamp * self, PyObject * args )
1109
if( !PyArg_ParseTuple( args, "f", &value ) )
1110
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
1111
"expected float argument" ) );
1113
self->lamp->clipend = EXPP_ClampFloat( value,
1114
EXPP_LAMP_CLIPEND_MIN,
1115
EXPP_LAMP_CLIPEND_MAX );
1117
Py_INCREF( Py_None );
1121
static PyObject *Lamp_setBias( BPy_Lamp * self, PyObject * args )
1125
if( !PyArg_ParseTuple( args, "f", &value ) )
1126
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
1127
"expected float argument" ) );
1129
self->lamp->bias = EXPP_ClampFloat( value,
1131
EXPP_LAMP_BIAS_MAX );
1133
Py_INCREF( Py_None );
1137
static PyObject *Lamp_setSoftness( BPy_Lamp * self, PyObject * args )
1141
if( !PyArg_ParseTuple( args, "f", &value ) )
1142
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
1143
"expected float argument" ) );
1145
self->lamp->soft = EXPP_ClampFloat( value,
1146
EXPP_LAMP_SOFTNESS_MIN,
1147
EXPP_LAMP_SOFTNESS_MAX );
1149
Py_INCREF( Py_None );
1153
static PyObject *Lamp_setHaloInt( BPy_Lamp * self, PyObject * args )
1157
if( !PyArg_ParseTuple( args, "f", &value ) )
1158
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
1159
"expected float argument" ) );
1161
self->lamp->haint = EXPP_ClampFloat( value,
1162
EXPP_LAMP_HALOINT_MIN,
1163
EXPP_LAMP_HALOINT_MAX );
1165
Py_INCREF( Py_None );
1169
static PyObject *Lamp_setQuad1( BPy_Lamp * self, PyObject * args )
1173
if( !PyArg_ParseTuple( args, "f", &value ) )
1174
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
1175
"expected float argument" ) );
1177
self->lamp->att1 = EXPP_ClampFloat( value,
1178
EXPP_LAMP_QUAD1_MIN,
1179
EXPP_LAMP_QUAD1_MAX );
1181
Py_INCREF( Py_None );
1185
static PyObject *Lamp_setQuad2( BPy_Lamp * self, PyObject * args )
1189
if( !PyArg_ParseTuple( args, "f", &value ) )
1190
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
1191
"expected float argument" ) );
1193
self->lamp->att2 = EXPP_ClampFloat( value,
1194
EXPP_LAMP_QUAD2_MIN,
1195
EXPP_LAMP_QUAD2_MAX );
1197
Py_INCREF( Py_None );
1201
static PyObject *Lamp_setColorComponent( BPy_Lamp * self, char *key,
1203
{ /* for compatibility with old bpython */
1206
if( !PyArg_ParseTuple( args, "f", &value ) )
1207
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
1208
"expected float argument in [0.0, 1.0]" ) );
1210
value = EXPP_ClampFloat( value, EXPP_LAMP_COL_MIN, EXPP_LAMP_COL_MAX );
1212
if( !strcmp( key, "R" ) )
1213
self->lamp->r = value;
1214
else if( !strcmp( key, "G" ) )
1215
self->lamp->g = value;
1216
else if( !strcmp( key, "B" ) )
1217
self->lamp->b = value;
1219
Py_INCREF( Py_None );
1223
static PyObject *Lamp_setCol( BPy_Lamp * self, PyObject * args )
1225
return rgbTuple_setCol( self->color, args );
1228
/* lamp.addScriptLink */
1229
static PyObject *Lamp_addScriptLink( BPy_Lamp * self, PyObject * args )
1231
Lamp *lamp = self->lamp;
1232
ScriptLink *slink = NULL;
1234
slink = &( lamp )->scriptlink;
1236
return EXPP_addScriptLink( slink, args, 0 );
1239
/* lamp.clearScriptLinks */
1240
static PyObject *Lamp_clearScriptLinks( BPy_Lamp * self, PyObject * args )
1242
Lamp *lamp = self->lamp;
1243
ScriptLink *slink = NULL;
1245
slink = &( lamp )->scriptlink;
1247
return EXPP_clearScriptLinks( slink, args );
1250
/* mat.getScriptLinks */
1251
static PyObject *Lamp_getScriptLinks( BPy_Lamp * self, PyObject * args )
1253
Lamp *lamp = self->lamp;
1254
ScriptLink *slink = NULL;
1255
PyObject *ret = NULL;
1257
slink = &( lamp )->scriptlink;
1259
ret = EXPP_getScriptLinks( slink, args, 0 );
862
1267
/*****************************************************************************/
876
1281
/* the function that accesses BPy_Lamp member variables and */
878
1283
/*****************************************************************************/
879
static PyObject *Lamp_getAttr (BPy_Lamp *self, char *name)
1284
static PyObject *Lamp_getAttr( BPy_Lamp * self, char *name )
881
PyObject *attr = Py_None;
883
if (strcmp(name, "name") == 0)
884
attr = PyString_FromString(self->lamp->id.name+2);
885
else if (strcmp(name, "type") == 0)
886
attr = PyInt_FromLong(self->lamp->type);
887
else if (strcmp(name, "mode") == 0)
888
attr = PyInt_FromLong(self->lamp->mode);
889
else if (strcmp(name, "samples") == 0)
890
attr = PyInt_FromLong(self->lamp->samp);
891
else if (strcmp(name, "bufferSize") == 0)
892
attr = PyInt_FromLong(self->lamp->bufsize);
893
else if (strcmp(name, "haloStep") == 0)
894
attr = PyInt_FromLong(self->lamp->shadhalostep);
895
else if (strcmp(name, "R") == 0)
896
attr = PyFloat_FromDouble(self->lamp->r);
897
else if (strcmp(name, "G") == 0)
898
attr = PyFloat_FromDouble(self->lamp->g);
899
else if (strcmp(name, "B") == 0)
900
attr = PyFloat_FromDouble(self->lamp->b);
901
else if (strcmp(name, "col") == 0)
902
attr = Lamp_getCol(self);
903
else if (strcmp(name, "energy") == 0)
904
attr = PyFloat_FromDouble(self->lamp->energy);
905
else if (strcmp(name, "dist") == 0)
906
attr = PyFloat_FromDouble(self->lamp->dist);
907
else if (strcmp(name, "spotSize") == 0)
908
attr = PyFloat_FromDouble(self->lamp->spotsize);
909
else if (strcmp(name, "spotBlend") == 0)
910
attr = PyFloat_FromDouble(self->lamp->spotblend);
911
else if (strcmp(name, "clipStart") == 0)
912
attr = PyFloat_FromDouble(self->lamp->clipsta);
913
else if (strcmp(name, "clipEnd") == 0)
914
attr = PyFloat_FromDouble(self->lamp->clipend);
915
else if (strcmp(name, "bias") == 0)
916
attr = PyFloat_FromDouble(self->lamp->bias);
917
else if (strcmp(name, "softness") == 0)
918
attr = PyFloat_FromDouble(self->lamp->soft);
919
else if (strcmp(name, "haloInt") == 0)
920
attr = PyFloat_FromDouble(self->lamp->haint);
921
else if (strcmp(name, "quad1") == 0)
922
attr = PyFloat_FromDouble(self->lamp->att1);
923
else if (strcmp(name, "quad2") == 0)
924
attr = PyFloat_FromDouble(self->lamp->att2);
926
else if (strcmp(name, "Types") == 0) {
927
attr = Py_BuildValue("{s:h,s:h,s:h,s:h}",
928
"Lamp", EXPP_LAMP_TYPE_LAMP,
929
"Sun" , EXPP_LAMP_TYPE_SUN,
930
"Spot", EXPP_LAMP_TYPE_SPOT,
931
"Hemi", EXPP_LAMP_TYPE_HEMI);
934
else if (strcmp(name, "Modes") == 0) {
935
attr = Py_BuildValue("{s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h}",
936
"Shadows", EXPP_LAMP_MODE_SHADOWS,
937
"Halo", EXPP_LAMP_MODE_HALO,
938
"Layer", EXPP_LAMP_MODE_LAYER,
939
"Quad", EXPP_LAMP_MODE_QUAD,
940
"Negative", EXPP_LAMP_MODE_NEGATIVE,
941
"OnlyShadow", EXPP_LAMP_MODE_ONLYSHADOW,
942
"Sphere", EXPP_LAMP_MODE_SPHERE,
943
"Square", EXPP_LAMP_MODE_SQUARE,
944
"NoDiffuse", EXPP_LAMP_MODE_NODIFFUSE,
945
"NoSpecular", EXPP_LAMP_MODE_NOSPECULAR);
948
else if (strcmp(name, "__members__") == 0) {
950
attr = Py_BuildValue("[s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s]",
951
"name", "type", "mode", "samples", "bufferSize",
952
"haloStep", "R", "G", "B", "energy", "dist",
953
"spotSize", "spotBlend", "clipStart", "clipEnd",
954
"bias", "softness", "haloInt", "quad1", "quad2",
955
"Types", "Modes", "col");
959
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
960
"couldn't create PyObject"));
962
if (attr != Py_None) return attr; /* member attribute found, return it */
964
/* not an attribute, search the methods table */
965
return Py_FindMethod(BPy_Lamp_methods, (PyObject *)self, name);
1286
PyObject *attr = Py_None;
1288
if( strcmp( name, "name" ) == 0 )
1289
attr = PyString_FromString( self->lamp->id.name + 2 );
1290
else if( strcmp( name, "type" ) == 0 )
1291
attr = PyInt_FromLong( self->lamp->type );
1292
else if( strcmp( name, "mode" ) == 0 )
1293
attr = PyInt_FromLong( self->lamp->mode );
1294
else if( strcmp( name, "samples" ) == 0 )
1295
attr = PyInt_FromLong( self->lamp->samp );
1296
else if( strcmp( name, "bufferSize" ) == 0 )
1297
attr = PyInt_FromLong( self->lamp->bufsize );
1298
else if( strcmp( name, "haloStep" ) == 0 )
1299
attr = PyInt_FromLong( self->lamp->shadhalostep );
1300
else if( strcmp( name, "R" ) == 0 )
1301
attr = PyFloat_FromDouble( self->lamp->r );
1302
else if( strcmp( name, "G" ) == 0 )
1303
attr = PyFloat_FromDouble( self->lamp->g );
1304
else if( strcmp( name, "B" ) == 0 )
1305
attr = PyFloat_FromDouble( self->lamp->b );
1306
else if( strcmp( name, "col" ) == 0 )
1307
attr = Lamp_getCol( self );
1308
else if( strcmp( name, "energy" ) == 0 )
1309
attr = PyFloat_FromDouble( self->lamp->energy );
1310
else if( strcmp( name, "dist" ) == 0 )
1311
attr = PyFloat_FromDouble( self->lamp->dist );
1312
else if( strcmp( name, "spotSize" ) == 0 )
1313
attr = PyFloat_FromDouble( self->lamp->spotsize );
1314
else if( strcmp( name, "spotBlend" ) == 0 )
1315
attr = PyFloat_FromDouble( self->lamp->spotblend );
1316
else if( strcmp( name, "clipStart" ) == 0 )
1317
attr = PyFloat_FromDouble( self->lamp->clipsta );
1318
else if( strcmp( name, "clipEnd" ) == 0 )
1319
attr = PyFloat_FromDouble( self->lamp->clipend );
1320
else if( strcmp( name, "bias" ) == 0 )
1321
attr = PyFloat_FromDouble( self->lamp->bias );
1322
else if( strcmp( name, "softness" ) == 0 )
1323
attr = PyFloat_FromDouble( self->lamp->soft );
1324
else if( strcmp( name, "haloInt" ) == 0 )
1325
attr = PyFloat_FromDouble( self->lamp->haint );
1326
else if( strcmp( name, "quad1" ) == 0 )
1327
attr = PyFloat_FromDouble( self->lamp->att1 );
1328
else if( strcmp( name, "quad2" ) == 0 )
1329
attr = PyFloat_FromDouble( self->lamp->att2 );
1330
else if( strcmp( name, "users" ) == 0 )
1331
attr = PyInt_FromLong( self->lamp->id.us );
1333
else if( strcmp( name, "Types" ) == 0 ) {
1334
attr = Py_BuildValue( "{s:h,s:h,s:h,s:h,s:h,s:h}",
1335
"Lamp", EXPP_LAMP_TYPE_LAMP,
1336
"Sun", EXPP_LAMP_TYPE_SUN,
1337
"Spot", EXPP_LAMP_TYPE_SPOT,
1338
"Hemi", EXPP_LAMP_TYPE_HEMI,
1339
"Area", EXPP_LAMP_TYPE_AREA,
1340
"Photon", EXPP_LAMP_TYPE_YF_PHOTON
1344
else if( strcmp( name, "Modes" ) == 0 ) {
1345
attr = Py_BuildValue
1346
( "{s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h,s:h}",
1347
"Shadows", EXPP_LAMP_MODE_SHADOWS, "Halo",
1348
EXPP_LAMP_MODE_HALO, "Layer", EXPP_LAMP_MODE_LAYER,
1349
"Quad", EXPP_LAMP_MODE_QUAD, "Negative",
1350
EXPP_LAMP_MODE_NEGATIVE, "OnlyShadow",
1351
EXPP_LAMP_MODE_ONLYSHADOW, "Sphere",
1352
EXPP_LAMP_MODE_SPHERE, "Square",
1353
EXPP_LAMP_MODE_SQUARE, "NoDiffuse",
1354
EXPP_LAMP_MODE_NODIFFUSE, "NoSpecular",
1355
EXPP_LAMP_MODE_NOSPECULAR );
1358
else if( strcmp( name, "__members__" ) == 0 ) {
1360
attr = Py_BuildValue
1361
( "[s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s,s]",
1362
"name", "type", "mode", "samples", "bufferSize",
1363
"haloStep", "R", "G", "B", "energy", "dist",
1364
"spotSize", "spotBlend", "clipStart", "clipEnd",
1365
"bias", "softness", "haloInt", "quad1", "quad2",
1366
"Types", "Modes", "col", "users" );
1370
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
1371
"couldn't create PyObject" ) );
1373
if( attr != Py_None )
1374
return attr; /* member attribute found, return it */
1376
/* not an attribute, search the methods table */
1377
return Py_FindMethod( BPy_Lamp_methods, ( PyObject * ) self, name );
968
1380
/*****************************************************************************/
971
1383
/* function that changes Lamp Data members values. If this */
972
1384
/* data is linked to a Blender Lamp, it also gets updated. */
973
1385
/*****************************************************************************/
974
static int Lamp_setAttr (BPy_Lamp *self, char *name, PyObject *value)
1386
static int Lamp_setAttr( BPy_Lamp * self, char *name, PyObject * value )
977
PyObject *error = NULL;
979
valtuple = Py_BuildValue("(O)", value); /*the set* functions expect a tuple*/
982
return EXPP_ReturnIntError(PyExc_MemoryError,
983
"LampSetAttr: couldn't create tuple");
985
if (strcmp (name, "name") == 0)
986
error = Lamp_setName (self, valtuple);
987
else if (strcmp (name, "type") == 0)
988
error = Lamp_setIntType (self, valtuple); /* special case */
989
else if (strcmp (name, "mode") == 0)
990
error = Lamp_setIntMode (self, valtuple); /* special case */
991
else if (strcmp (name, "samples") == 0)
992
error = Lamp_setSamples (self, valtuple);
993
else if (strcmp (name, "bufferSize") == 0)
994
error = Lamp_setBufferSize (self, valtuple);
995
else if (strcmp (name, "haloStep") == 0)
996
error = Lamp_setHaloStep (self, valtuple);
997
else if (strcmp (name, "R") == 0)
998
error = Lamp_setColorComponent (self, "R", valtuple);
999
else if (strcmp (name, "G") == 0)
1000
error = Lamp_setColorComponent (self, "G", valtuple);
1001
else if (strcmp (name, "B") == 0)
1002
error = Lamp_setColorComponent (self, "B", valtuple);
1003
else if (strcmp (name, "energy") == 0)
1004
error = Lamp_setEnergy (self, valtuple);
1005
else if (strcmp (name, "dist") == 0)
1006
error = Lamp_setDist (self, valtuple);
1007
else if (strcmp (name, "spotSize") == 0)
1008
error = Lamp_setSpotSize (self, valtuple);
1009
else if (strcmp (name, "spotBlend") == 0)
1010
error = Lamp_setSpotBlend (self, valtuple);
1011
else if (strcmp (name, "clipStart") == 0)
1012
error = Lamp_setClipStart (self, valtuple);
1013
else if (strcmp (name, "clipEnd") == 0)
1014
error = Lamp_setClipEnd (self, valtuple);
1015
else if (strcmp (name, "bias") == 0)
1016
error = Lamp_setBias (self, valtuple);
1017
else if (strcmp (name, "softness") == 0)
1018
error = Lamp_setSoftness (self, valtuple);
1019
else if (strcmp (name, "haloInt") == 0)
1020
error = Lamp_setHaloInt (self, valtuple);
1021
else if (strcmp (name, "quad1") == 0)
1022
error = Lamp_setQuad1 (self, valtuple);
1023
else if (strcmp (name, "quad2") == 0)
1024
error = Lamp_setQuad2 (self, valtuple);
1025
else if (strcmp (name, "col") == 0)
1026
error = Lamp_setCol (self, valtuple);
1029
Py_DECREF(valtuple);
1031
if ((strcmp (name, "Types") == 0) || /* user tried to change a */
1032
(strcmp (name, "Modes") == 0)) /* constant dict type ... */
1033
return (EXPP_ReturnIntError (PyExc_AttributeError,
1034
"constant dictionary -- cannot be changed"));
1036
else /* ... or no member with the given name was found */
1037
return (EXPP_ReturnIntError (PyExc_AttributeError,
1038
"attribute not found"));
1041
Py_DECREF(valtuple);
1043
if (error != Py_None) return -1;
1045
Py_DECREF(Py_None); /* was incref'ed by the called Lamp_set* function */
1046
return 0; /* normal exit */
1389
PyObject *error = NULL;
1391
valtuple = Py_BuildValue( "(O)", value ); /*the set* functions expect a tuple */
1394
return EXPP_ReturnIntError( PyExc_MemoryError,
1395
"LampSetAttr: couldn't create tuple" );
1397
if( strcmp( name, "name" ) == 0 )
1398
error = Lamp_setName( self, valtuple );
1399
else if( strcmp( name, "type" ) == 0 )
1400
error = Lamp_setIntType( self, valtuple ); /* special case */
1401
else if( strcmp( name, "mode" ) == 0 )
1402
error = Lamp_setIntMode( self, valtuple ); /* special case */
1403
else if( strcmp( name, "samples" ) == 0 )
1404
error = Lamp_setSamples( self, valtuple );
1405
else if( strcmp( name, "bufferSize" ) == 0 )
1406
error = Lamp_setBufferSize( self, valtuple );
1407
else if( strcmp( name, "haloStep" ) == 0 )
1408
error = Lamp_setHaloStep( self, valtuple );
1409
else if( strcmp( name, "R" ) == 0 )
1410
error = Lamp_setColorComponent( self, "R", valtuple );
1411
else if( strcmp( name, "G" ) == 0 )
1412
error = Lamp_setColorComponent( self, "G", valtuple );
1413
else if( strcmp( name, "B" ) == 0 )
1414
error = Lamp_setColorComponent( self, "B", valtuple );
1415
else if( strcmp( name, "energy" ) == 0 )
1416
error = Lamp_setEnergy( self, valtuple );
1417
else if( strcmp( name, "dist" ) == 0 )
1418
error = Lamp_setDist( self, valtuple );
1419
else if( strcmp( name, "spotSize" ) == 0 )
1420
error = Lamp_setSpotSize( self, valtuple );
1421
else if( strcmp( name, "spotBlend" ) == 0 )
1422
error = Lamp_setSpotBlend( self, valtuple );
1423
else if( strcmp( name, "clipStart" ) == 0 )
1424
error = Lamp_setClipStart( self, valtuple );
1425
else if( strcmp( name, "clipEnd" ) == 0 )
1426
error = Lamp_setClipEnd( self, valtuple );
1427
else if( strcmp( name, "bias" ) == 0 )
1428
error = Lamp_setBias( self, valtuple );
1429
else if( strcmp( name, "softness" ) == 0 )
1430
error = Lamp_setSoftness( self, valtuple );
1431
else if( strcmp( name, "haloInt" ) == 0 )
1432
error = Lamp_setHaloInt( self, valtuple );
1433
else if( strcmp( name, "quad1" ) == 0 )
1434
error = Lamp_setQuad1( self, valtuple );
1435
else if( strcmp( name, "quad2" ) == 0 )
1436
error = Lamp_setQuad2( self, valtuple );
1437
else if( strcmp( name, "col" ) == 0 )
1438
error = Lamp_setCol( self, valtuple );
1441
Py_DECREF( valtuple );
1443
if( ( strcmp( name, "Types" ) == 0 ) || /* user tried to change a */
1444
( strcmp( name, "Modes" ) == 0 ) ) /* constant dict type ... */
1445
return ( EXPP_ReturnIntError( PyExc_AttributeError,
1446
"constant dictionary -- cannot be changed" ) );
1448
else /* ... or no member with the given name was found */
1449
return ( EXPP_ReturnIntError( PyExc_AttributeError,
1450
"attribute not found" ) );
1453
Py_DECREF( valtuple );
1455
if( error != Py_None )
1458
Py_DECREF( Py_None ); /* was incref'ed by the called Lamp_set* function */
1459
return 0; /* normal exit */
1049
1462
/*****************************************************************************/