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
|
/*
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* This is a new part of Blender.
*
* Contributor(s): Jacques Guignot
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include "Wave.h"
#include "Effect.h"
/*****************************************************************************/
/* Python BPy_Wave methods table: */
/*****************************************************************************/
static PyMethodDef BPy_Wave_methods[] = {
{"getType", (PyCFunction)Effect_getType,
METH_NOARGS,"() - Return Effect type"},
{"setType", (PyCFunction)Effect_setType,
METH_VARARGS,"() - Set Effect type"},
{"getFlag", (PyCFunction)Effect_getFlag,
METH_NOARGS,"() - Return Effect flag"},
{"setFlag", (PyCFunction)Effect_setFlag,
METH_VARARGS,"() - Set Effect flag"},
{"getStartx",(PyCFunction)Wave_getStartx,
METH_NOARGS,"()-Return Wave startx"},
{"setStartx",(PyCFunction)Wave_setStartx, METH_VARARGS,
"()- Sets Wave startx"},
{"getStarty",(PyCFunction)Wave_getStarty,
METH_NOARGS,"()-Return Wave starty"},
{"setStarty",(PyCFunction)Wave_setStarty, METH_VARARGS,
"()- Sets Wave starty"},
{"getHeight",(PyCFunction)Wave_getHeight,
METH_NOARGS,"()-Return Wave height"},
{"setHeight",(PyCFunction)Wave_setHeight, METH_VARARGS,
"()- Sets Wave height"},
{"getWidth",(PyCFunction)Wave_getWidth,
METH_NOARGS,"()-Return Wave width"},
{"setWidth",(PyCFunction)Wave_setWidth, METH_VARARGS,
"()- Sets Wave width"},
{"getNarrow",(PyCFunction)Wave_getNarrow,
METH_NOARGS,"()-Return Wave narrow"},
{"setNarrow",(PyCFunction)Wave_setNarrow, METH_VARARGS,
"()- Sets Wave narrow"},
{"getSpeed",(PyCFunction)Wave_getSpeed,
METH_NOARGS,"()-Return Wave speed"},
{"setSpeed",(PyCFunction)Wave_setSpeed, METH_VARARGS,
"()- Sets Wave speed"},
{"getMinfac",(PyCFunction)Wave_getMinfac,
METH_NOARGS,"()-Return Wave minfac"},
{"setMinfac",(PyCFunction)Wave_setMinfac, METH_VARARGS,
"()- Sets Wave minfac"},
{"getDamp",(PyCFunction)Wave_getDamp,
METH_NOARGS,"()-Return Wave damp"},
{"setDamp",(PyCFunction)Wave_setDamp, METH_VARARGS,
"()- Sets Wave damp"},
{"getTimeoffs",(PyCFunction)Wave_getTimeoffs,
METH_NOARGS,"()-Return Wave timeoffs"},
{"setTimeoffs",(PyCFunction)Wave_setTimeoffs, METH_VARARGS,
"()- Sets Wave timeoffs"},
{"getLifetime",(PyCFunction)Wave_getLifetime,
METH_NOARGS,"()-Return Wave lifetime"},
{"setLifetime",(PyCFunction)Wave_setLifetime, METH_VARARGS,
"()- Sets Wave lifetime"},
{0}
};
/*****************************************************************************/
/* Python Wave_Type structure definition: */
/*****************************************************************************/
PyTypeObject Wave_Type =
{
PyObject_HEAD_INIT(NULL)
0,
"Wave",
sizeof (BPy_Wave),
0,
/* methods */
(destructor)WaveDeAlloc, /* tp_dealloc */
(printfunc)WavePrint, /* tp_print */
(getattrfunc)WaveGetAttr, /* tp_getattr */
(setattrfunc)WaveSetAttr, /* tp_setattr */
0, /* tp_compare */
(reprfunc)WaveRepr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_as_hash */
0,0,0,0,0,0,
0, /* tp_doc */
0,0,0,0,0,0,
BPy_Wave_methods, /* tp_methods */
0, /* tp_members */
};
/*****************************************************************************/
/* The following string definitions are used for documentation strings. */
/* In Python these will be written to the console when doing a */
/* Blender.Wave.__doc__ */
/*****************************************************************************/
static char M_Wave_doc[] = "The Blender Wave module\n\n\
This module provides access to **Object Data** in Blender.\n\
Functions :\n\
New(opt name) : creates a new wave object with the given name (optional)\n\
Get(name) : retreives a wave with the given name (mandatory)\n\
get(name) : same as Get. Kept for compatibility reasons";
static char M_Wave_New_doc[] ="";
static char M_Wave_Get_doc[] ="xxx";
/*****************************************************************************/
/* Python method structure definition for Blender.Wave module: */
/*****************************************************************************/
struct PyMethodDef M_Wave_methods[] = {
{"New",(PyCFunction)M_Wave_New, METH_VARARGS,M_Wave_New_doc},
{"Get", M_Wave_Get, METH_VARARGS, M_Wave_Get_doc},
{"get", M_Wave_Get, METH_VARARGS, M_Wave_Get_doc},
{NULL, NULL, 0, NULL}
};
/* -Sta x et Sta y : là où débute la vague
-X, Y : la vague se propagera dans les directions X et/ou Y
-Cycl : la vague se répétera ou ne se produira qu'une fois
-Speed, Height, Width, Narrow : joues avec ces paramètres, je
te fais confiance. Ils interagissent et s'influencent alors
mieux vaut y aller un à la fois et qu'un peu à la fois.
-Time sta: la frame où l'effet commence à se produire.
-Lifetime: durée en frames de l'effet.
-Damptime: le temps, en frames, que met une vague à mourir.
*/
/*****************************************************************************/
/* Function: M_Wave_New */
/* Python equivalent: Blender.Effect.Wave.New */
/*****************************************************************************/
PyObject *M_Wave_New(PyObject *self, PyObject *args)
{
int type = EFF_WAVE;
BPy_Effect *pyeffect;
Effect *bleffect = 0;
bleffect = add_effect(type);
if (bleffect == NULL)
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
"couldn't create Effect Data in Blender"));
pyeffect = (BPy_Effect *)PyObject_NEW(BPy_Effect, &Effect_Type);
if (pyeffect == NULL) return (EXPP_ReturnPyObjError (PyExc_MemoryError,
"couldn't create Effect Data object"));
pyeffect->effect = bleffect;
return (PyObject *)pyeffect;
return 0;
}
/*****************************************************************************/
/* Function: M_Wave_Get */
/* Python equivalent: Blender.Effect.Wave.Get */
/*****************************************************************************/
PyObject *M_Wave_Get(PyObject *self, PyObject *args)
{
/*arguments : string object name
int : position of effect in the obj's effect list */
char *name = 0;
Object *object_iter;
Effect *eff;
BPy_Wave *wanted_eff;
int num,i;
if (!PyArg_ParseTuple(args, "si", &name, &num ))
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"expected string int argument"));
object_iter = G.main->object.first;
if (!object_iter)return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"Scene contains no object"));
while (object_iter)
{
if (strcmp(name,object_iter->id.name+2))
{
object_iter = object_iter->id.next;
continue;
}
if (object_iter->effect.first != NULL)
{
eff = object_iter->effect.first;
for(i = 0;i<num;i++)
{
if (eff->type != EFF_WAVE)continue;
eff = eff->next;
if (!eff)
return(EXPP_ReturnPyObjError(PyExc_AttributeError,"bject"));
}
wanted_eff = (BPy_Wave *)PyObject_NEW(BPy_Wave, &Wave_Type);
wanted_eff->wave = eff;
return (PyObject*)wanted_eff;
}
object_iter = object_iter->id.next;
}
Py_INCREF(Py_None);
return Py_None;
}
/*****************************************************************************/
/* Function: Wave_Init */
/*****************************************************************************/
PyObject *Wave_Init (void)
{
PyObject *submodule;
Wave_Type.ob_type = &PyType_Type;
submodule = Py_InitModule3("Blender.Wave",M_Wave_methods, M_Wave_doc);
return (submodule);
}
/*****************************************************************************/
/* Python BPy_Wave methods: */
/*****************************************************************************/
PyObject *Wave_getStartx(BPy_Wave *self)
{
WaveEff*ptr = (WaveEff*)self->wave;
return PyFloat_FromDouble(ptr->startx);
}
PyObject *Wave_setStartx(BPy_Wave *self,PyObject *args)
{
WaveEff*ptr = (WaveEff*)self->wave;
float val = 0;
if (!PyArg_ParseTuple(args, "f", &val ))
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"expected float argument"));
ptr->startx = val;
Py_INCREF(Py_None);
return Py_None;
}
PyObject *Wave_getStarty(BPy_Wave *self)
{
WaveEff*ptr = (WaveEff*)self->wave;
return PyFloat_FromDouble(ptr->starty);
}
PyObject *Wave_setStarty(BPy_Wave *self,PyObject *args)
{
WaveEff*ptr = (WaveEff*)self->wave;
float val = 0;
if (!PyArg_ParseTuple(args, "f", &val ))
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"expected float argument"));
ptr->starty = val;
Py_INCREF(Py_None);
return Py_None;
}
PyObject *Wave_getHeight(BPy_Wave *self)
{
WaveEff*ptr = (WaveEff*)self->wave;
return PyFloat_FromDouble(ptr->height);
}
PyObject *Wave_setHeight(BPy_Wave *self,PyObject *args)
{
WaveEff*ptr = (WaveEff*)self->wave;
float val = 0;
if (!PyArg_ParseTuple(args, "f", &val ))
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"expected float argument"));
ptr->height = val;
Py_INCREF(Py_None);
return Py_None;
}
PyObject *Wave_getWidth(BPy_Wave *self)
{
WaveEff*ptr = (WaveEff*)self->wave;
return PyFloat_FromDouble(ptr->width);
}
PyObject *Wave_setWidth(BPy_Wave *self,PyObject *args)
{
float val = 0;
WaveEff*ptr;
if (!PyArg_ParseTuple(args, "f", &val ))
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"expected float argument"));
ptr = (WaveEff*)self->wave;
ptr->width = val;
Py_INCREF(Py_None);
return Py_None;
}
PyObject *Wave_getNarrow(BPy_Wave *self)
{
WaveEff*ptr = (WaveEff*)self->wave;
return PyFloat_FromDouble(ptr->narrow);
}
PyObject *Wave_setNarrow(BPy_Wave *self,PyObject *args)
{
float val = 0;
WaveEff*ptr;
if (!PyArg_ParseTuple(args, "f", &val ))
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"expected float argument"));
ptr = (WaveEff*)self->wave;
ptr->narrow = val;
Py_INCREF(Py_None);
return Py_None;
}
PyObject *Wave_getSpeed(BPy_Wave *self)
{
WaveEff*ptr = (WaveEff*)self->wave;
return PyFloat_FromDouble(ptr->speed);
}
PyObject *Wave_setSpeed(BPy_Wave *self,PyObject *args)
{
float val = 0;
WaveEff*ptr;
if (!PyArg_ParseTuple(args, "f", &val ))
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"expected float argument"));
ptr = (WaveEff*)self->wave;
ptr->speed = val;
Py_INCREF(Py_None);
return Py_None;
}
PyObject *Wave_getMinfac(BPy_Wave *self)
{
WaveEff*ptr = (WaveEff*)self->wave;
return PyFloat_FromDouble(ptr->minfac);
}
PyObject *Wave_setMinfac(BPy_Wave *self,PyObject *args)
{
float val = 0;
WaveEff*ptr;
if (!PyArg_ParseTuple(args, "f", &val ))
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"expected float argument"));
ptr = (WaveEff*)self->wave;
ptr->minfac = val;
Py_INCREF(Py_None);
return Py_None;
}
PyObject *Wave_getDamp(BPy_Wave *self)
{
WaveEff*ptr = (WaveEff*)self->wave;
return PyFloat_FromDouble(ptr->damp);
}
PyObject *Wave_setDamp(BPy_Wave *self,PyObject *args)
{
WaveEff*ptr;
float val = 0;
if (!PyArg_ParseTuple(args, "f", &val ))
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"expected float argument"));
ptr = (WaveEff*)self->wave;
ptr->damp = val;
Py_INCREF(Py_None);
return Py_None;
}
PyObject *Wave_getTimeoffs(BPy_Wave *self)
{
WaveEff*ptr = (WaveEff*)self->wave;
return PyFloat_FromDouble(ptr->timeoffs);
}
PyObject *Wave_setTimeoffs(BPy_Wave *self,PyObject *args)
{
float val = 0;
WaveEff*ptr;
if (!PyArg_ParseTuple(args, "f", &val ))
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"expected float argument"));
ptr = (WaveEff*)self->wave;
ptr->timeoffs = val;
Py_INCREF(Py_None);
return Py_None;
}
PyObject *Wave_getLifetime(BPy_Wave *self)
{
WaveEff*ptr = (WaveEff*)self->wave;
return PyFloat_FromDouble(ptr->lifetime);
}
PyObject *Wave_setLifetime(BPy_Wave *self,PyObject *args)
{
float val = 0;
WaveEff*ptr;
if (!PyArg_ParseTuple(args, "f", &val ))
return(EXPP_ReturnPyObjError(PyExc_AttributeError,\
"expected float argument"));
ptr = (WaveEff*)self->wave;
ptr->lifetime = val;
Py_INCREF(Py_None);
return Py_None;
}
/*****************************************************************************/
/* Function: WaveDeAlloc */
/* Description: This is a callback function for the BPy_Wave type. It is */
/* the destructor function. */
/*****************************************************************************/
void WaveDeAlloc (BPy_Wave *self)
{
WaveEff*ptr = (WaveEff*)self->wave;
PyObject_DEL (ptr);
}
/*****************************************************************************/
/* Function: WaveGetAttr */
/* Description: This is a callback function for the BPy_Wave type. It is */
/* the function that accesses BPy_Wave "member variables" and */
/* methods. */
/*****************************************************************************/
PyObject *WaveGetAttr (BPy_Wave *self, char *name)
{
if (!strcmp(name,"lifetime"))return Wave_getLifetime( self);
else if (!strcmp(name,"timeoffs"))return Wave_getTimeoffs( self);
else if (!strcmp(name,"damp"))return Wave_getDamp( self);
else if (!strcmp(name,"minfac"))return Wave_getMinfac( self);
else if (!strcmp(name,"speed"))return Wave_getSpeed( self);
else if (!strcmp(name,"narrow"))return Wave_getNarrow( self);
else if (!strcmp(name,"width"))return Wave_getWidth( self);
else if (!strcmp(name,"height"))return Wave_getHeight( self);
else if (!strcmp(name,"startx"))return Wave_getStartx( self);
else if (!strcmp(name,"starty"))return Wave_getStarty( self);
return Py_FindMethod(BPy_Wave_methods, (PyObject *)self, name);
}
/*****************************************************************************/
/* Function: WaveSetAttr */
/* Description: This is a callback function for the BPy_Wave type. It is the */
/* function that sets Wave Data attributes (member variables). */
/*****************************************************************************/
int WaveSetAttr (BPy_Wave *self, char *name, PyObject *value)
{
PyObject *valtuple;
PyObject *error = NULL;
valtuple = Py_BuildValue("(N)", value);
if (!valtuple)
return EXPP_ReturnIntError(PyExc_MemoryError,
"ParticleSetAttr: couldn't create PyTuple");
if (!strcmp(name,"lifetime"))error = Wave_setLifetime( self,valtuple);
else if (!strcmp(name,"timeoffs"))error = Wave_setTimeoffs( self,valtuple);
else if (!strcmp(name,"damp")) error = Wave_setDamp( self,valtuple);
else if (!strcmp(name,"minfac")) error = Wave_setMinfac( self,valtuple);
else if (!strcmp(name,"speed")) error = Wave_setSpeed( self,valtuple);
else if (!strcmp(name,"narrow")) error = Wave_setNarrow( self,valtuple);
else if (!strcmp(name,"width")) error = Wave_setWidth( self,valtuple);
else if (!strcmp(name,"height")) error = Wave_setHeight( self,valtuple);
else if (!strcmp(name,"startx")) error = Wave_setStartx( self,valtuple);
else if (!strcmp(name,"starty")) error = Wave_setStarty( self,valtuple);
else {
Py_DECREF(valtuple);
if ((strcmp (name, "Types") == 0) ||
(strcmp (name, "Modes") == 0))
return (EXPP_ReturnIntError (PyExc_AttributeError,
"constant dictionary -- cannot be changed"));
else
return (EXPP_ReturnIntError (PyExc_KeyError,
"attribute not found"));
}
/*Py_DECREF(valtuple);*/
if (error != Py_None) return -1;
Py_DECREF(Py_None);
return 0;
}
/*****************************************************************************/
/* Function: WavePrint */
/* Description: This is a callback function for the BPy_Wave type. It */
/* builds a meaninful string to 'print' wave objects. */
/*****************************************************************************/
int WavePrint(BPy_Wave *self, FILE *fp, int flags)
{
printf("I'm a wave...Cool, no?");
return 0;
}
/*****************************************************************************/
/* Function: WaveRepr */
/* Description: This is a callback function for the BPy_Wave type. It */
/* builds a meaninful string to represent wave objects. */
/*****************************************************************************/
PyObject *WaveRepr (BPy_Wave *self)
{
return 0;
}
PyObject* WaveCreatePyObject (struct Effect *wave)
{
BPy_Wave * blen_object;
blen_object = (BPy_Wave*)PyObject_NEW (BPy_Wave, &Wave_Type);
if (blen_object == NULL)
{
return (NULL);
}
blen_object->wave = wave;
return ((PyObject*)blen_object);
}
int WaveCheckPyObject (PyObject *py_obj)
{
return (py_obj->ob_type == &Wave_Type);
}
struct Wave* WaveFromPyObject (PyObject *py_obj)
{
BPy_Wave * blen_obj;
blen_obj = (BPy_Wave*)py_obj;
return ((struct Wave*)blen_obj->wave);
}
|