32
33
#include "Lattice.h"
34
//***************************************************************************
35
// Function: Lattice_CreatePyObject
36
//***************************************************************************
37
PyObject *Lattice_CreatePyObject (Lattice *lt)
37
#include <BKE_global.h>
38
#include <BKE_library.h>
39
#include <BKE_lattice.h>
40
#include <BKE_utildefines.h>
42
#include <BLI_blenlib.h>
44
#include <DNA_key_types.h>
45
#include <DNA_curve_types.h>
46
#include <DNA_scene_types.h>
47
#include <BIF_editlattice.h>
48
#include <BIF_editkey.h>
52
#include "gen_utils.h"
55
/*****************************************************************************/
56
/* Python API function prototypes for the Lattice module. */
57
/*****************************************************************************/
58
static PyObject *M_Lattice_New( PyObject * self, PyObject * args );
59
static PyObject *M_Lattice_Get( PyObject * self, PyObject * args );
61
/*****************************************************************************/
62
/* Lattice Module strings */
63
/* The following string definitions are used for documentation strings. */
64
/* In Python these will be written to the console when doing a */
65
/* Blender.Lattice.__doc__ */
66
/*****************************************************************************/
67
static char M_Lattice_doc[] = "The Blender Lattice module\n\n";
69
static char M_Lattice_New_doc[] = "() - return a new Lattice object";
71
static char M_Lattice_Get_doc[] = "() - geta a Lattice from blender";
73
/*****************************************************************************/
74
/* Python method structure definition for Blender.Lattice module: */
75
/*****************************************************************************/
76
struct PyMethodDef M_Lattice_methods[] = {
77
{"New", ( PyCFunction ) M_Lattice_New, METH_VARARGS,
79
{"Get", ( PyCFunction ) M_Lattice_Get, METH_VARARGS,
86
/*****************************************************************************/
87
/* Python BPy_Lattice methods declarations: */
88
/*****************************************************************************/
89
static PyObject *Lattice_getName( BPy_Lattice * self );
90
static PyObject *Lattice_setName( BPy_Lattice * self, PyObject * args );
91
static PyObject *Lattice_setPartitions( BPy_Lattice * self, PyObject * args );
92
static PyObject *Lattice_getPartitions( BPy_Lattice * self, PyObject * args );
93
static PyObject *Lattice_setKeyTypes( BPy_Lattice * self, PyObject * args );
94
static PyObject *Lattice_getKeyTypes( BPy_Lattice * self, PyObject * args );
95
static PyObject *Lattice_setMode( BPy_Lattice * self, PyObject * args );
96
static PyObject *Lattice_getMode( BPy_Lattice * self, PyObject * args );
97
static PyObject *Lattice_setPoint( BPy_Lattice * self, PyObject * args );
98
static PyObject *Lattice_getPoint( BPy_Lattice * self, PyObject * args );
99
static PyObject *Lattice_applyDeform( BPy_Lattice * self, PyObject *args );
100
static PyObject *Lattice_insertKey( BPy_Lattice * self, PyObject * args );
102
/*****************************************************************************/
103
/* Lattice Strings */
104
/* The following string definitions are used for documentation strings. */
105
/* In Python these will be written to the console when doing a */
106
/* Blender.Lattice.__doc__ */
107
/*****************************************************************************/
108
static char Lattice_getName_doc[] = "() - Return Lattice Object name";
110
static char Lattice_setName_doc[] = "(str) - Change Lattice Object name";
112
static char Lattice_setPartitions_doc[] =
113
"(str) - Set the number of Partitions in x,y,z";
115
static char Lattice_getPartitions_doc[] =
116
"(str) - Get the number of Partitions in x,y,z";
118
static char Lattice_setKeyTypes_doc[] =
119
"(str) - Set the key types for x,y,z dimensions";
121
static char Lattice_getKeyTypes_doc[] =
122
"(str) - Get the key types for x,y,z dimensions";
124
static char Lattice_setMode_doc[] = "(str) - Make an outside or grid lattice";
126
static char Lattice_getMode_doc[] = "(str) - Get lattice mode type";
128
static char Lattice_setPoint_doc[] =
129
"(str) - Set the coordinates of a point on the lattice";
131
static char Lattice_getPoint_doc[] =
132
"(str) - Get the coordinates of a point on the lattice";
134
static char Lattice_applyDeform_doc[] =
135
"(force = False) - Apply the new lattice deformation to children\n\n\
136
(force = False) - if given and True, children of mesh type are not ignored.\n\
137
Meshes are treated differently in Blender, deformation is stored directly in\n\
138
their vertices when first redrawn (ex: with Blender.Redraw) after getting a\n\
139
Lattice parent, without needing this method (except for command line bg\n\
140
mode). If forced, the deformation will be applied over any previous one(s).";
142
static char Lattice_insertKey_doc[] =
143
"(str) - Set a new key for the lattice at specified frame";
145
/*****************************************************************************/
146
/* Python BPy_Lattice methods table: */
147
/*****************************************************************************/
148
static PyMethodDef BPy_Lattice_methods[] = {
149
/* name, method, flags, doc */
150
{"getName", ( PyCFunction ) Lattice_getName, METH_NOARGS,
151
Lattice_getName_doc},
152
{"setName", ( PyCFunction ) Lattice_setName, METH_VARARGS,
153
Lattice_setName_doc},
154
{"setPartitions", ( PyCFunction ) Lattice_setPartitions, METH_VARARGS,
155
Lattice_setPartitions_doc},
156
{"getPartitions", ( PyCFunction ) Lattice_getPartitions, METH_NOARGS,
157
Lattice_getPartitions_doc},
158
{"setKeyTypes", ( PyCFunction ) Lattice_setKeyTypes, METH_VARARGS,
159
Lattice_setKeyTypes_doc},
160
{"getKeyTypes", ( PyCFunction ) Lattice_getKeyTypes, METH_NOARGS,
161
Lattice_getKeyTypes_doc},
162
{"setMode", ( PyCFunction ) Lattice_setMode, METH_VARARGS,
163
Lattice_setMode_doc},
164
{"getMode", ( PyCFunction ) Lattice_getMode, METH_NOARGS,
165
Lattice_getMode_doc},
166
{"setPoint", ( PyCFunction ) Lattice_setPoint, METH_VARARGS,
167
Lattice_setPoint_doc},
168
{"getPoint", ( PyCFunction ) Lattice_getPoint, METH_VARARGS,
169
Lattice_getPoint_doc},
170
{"applyDeform", ( PyCFunction ) Lattice_applyDeform, METH_VARARGS,
171
Lattice_applyDeform_doc},
172
{"insertKey", ( PyCFunction ) Lattice_insertKey, METH_VARARGS,
173
Lattice_insertKey_doc},
174
{NULL, NULL, 0, NULL}
177
/*****************************************************************************/
178
/* Python Lattice_Type callback function prototypes: */
179
/*****************************************************************************/
180
static void Lattice_dealloc( BPy_Lattice * self );
181
static int Lattice_setAttr( BPy_Lattice * self, char *name, PyObject * v );
182
static PyObject *Lattice_getAttr( BPy_Lattice * self, char *name );
183
static PyObject *Lattice_repr( BPy_Lattice * self );
185
/*****************************************************************************/
186
/* Python Lattice_Type structure definition: */
187
/*****************************************************************************/
188
PyTypeObject Lattice_Type = {
189
PyObject_HEAD_INIT( NULL )
191
"Blender Lattice", /* tp_name */
192
sizeof( BPy_Lattice ), /* tp_basicsize */
195
( destructor ) Lattice_dealloc, /* tp_dealloc */
197
( getattrfunc ) Lattice_getAttr, /* tp_getattr */
198
( setattrfunc ) Lattice_setAttr, /* tp_setattr */
200
( reprfunc ) Lattice_repr, /* tp_repr */
201
0, /* tp_as_number */
202
0, /* tp_as_sequence */
203
0, /* tp_as_mapping */
208
BPy_Lattice_methods, /* tp_methods */
210
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
213
static int Lattice_InLatList( BPy_Lattice * self );
214
static int Lattice_IsLinkedToObject( BPy_Lattice * self );
217
//***************************************************************************
218
// Function: Lattice_CreatePyObject
219
//***************************************************************************
220
PyObject *Lattice_CreatePyObject( Lattice * lt )
39
222
BPy_Lattice *pyLat;
41
pyLat = (BPy_Lattice *)PyObject_NEW (BPy_Lattice, &Lattice_Type);
224
pyLat = ( BPy_Lattice * ) PyObject_NEW( BPy_Lattice, &Lattice_Type );
44
return EXPP_ReturnPyObjError (PyExc_MemoryError,
45
"couldn't create BPy_Lattice PyObject");
227
return EXPP_ReturnPyObjError( PyExc_MemoryError,
228
"couldn't create BPy_Lattice PyObject" );
47
230
pyLat->Lattice = lt;
49
return (PyObject *)pyLat;
52
//***************************************************************************
53
// Function: Lattice_FromPyObject
54
//***************************************************************************
56
Lattice *Lattice_FromPyObject (PyObject *pyobj)
58
return ((BPy_Lattice *)pyobj)->Lattice;
61
//***************************************************************************
62
// Function: Lattice_CheckPyObject
63
//***************************************************************************
64
int Lattice_CheckPyObject (PyObject *pyobj)
66
return (pyobj->ob_type == &Lattice_Type);
69
//***************************************************************************
70
// Function: M_Lattice_New
71
// Python equivalent: Blender.Lattice.New
72
//***************************************************************************
73
static PyObject *M_Lattice_New(PyObject *self, PyObject *args)
232
return ( PyObject * ) pyLat;
235
//***************************************************************************
236
// Function: Lattice_FromPyObject
237
//***************************************************************************
239
Lattice *Lattice_FromPyObject( PyObject * pyobj )
241
return ( ( BPy_Lattice * ) pyobj )->Lattice;
244
//***************************************************************************
245
// Function: Lattice_CheckPyObject
246
//***************************************************************************
247
int Lattice_CheckPyObject( PyObject * pyobj )
249
return ( pyobj->ob_type == &Lattice_Type );
252
//***************************************************************************
253
// Function: M_Lattice_New
254
// Python equivalent: Blender.Lattice.New
255
//***************************************************************************
256
static PyObject *M_Lattice_New( PyObject * self, PyObject * args )
75
258
char *name = NULL;
77
Lattice * bl_Lattice; // blender Lattice object
78
PyObject * py_Lattice; // python wrapper
80
if (!PyArg_ParseTuple(args, "|s", &name))
81
return EXPP_ReturnPyObjError (PyExc_AttributeError,
82
"expected string and int arguments (or nothing)");
84
bl_Lattice = add_lattice();
260
Lattice *bl_Lattice; // blender Lattice object
261
PyObject *py_Lattice; // python wrapper
263
if( !PyArg_ParseTuple( args, "|s", &name ) )
264
return EXPP_ReturnPyObjError( PyExc_AttributeError,
265
"expected string and int arguments (or nothing)" );
267
bl_Lattice = add_lattice( );
85
268
bl_Lattice->id.us = 0;
88
py_Lattice = Lattice_CreatePyObject (bl_Lattice);
271
py_Lattice = Lattice_CreatePyObject( bl_Lattice );
90
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
91
"couldn't create Lattice Object in Blender");
93
return EXPP_ReturnPyObjError (PyExc_MemoryError,
94
"couldn't create Lattice Object wrapper");
273
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
274
"couldn't create Lattice Object in Blender" );
276
return EXPP_ReturnPyObjError( PyExc_MemoryError,
277
"couldn't create Lattice Object wrapper" );
97
PyOS_snprintf(buf, sizeof(buf), "%s", name);
98
rename_id(&bl_Lattice->id, buf);
280
PyOS_snprintf( buf, sizeof( buf ), "%s", name );
281
rename_id( &bl_Lattice->id, buf );
101
284
return py_Lattice;
104
287
//***************************************************************************
105
// Function: M_Lattice_Get
106
// Python equivalent: Blender.Lattice.Get
288
// Function: M_Lattice_Get
289
// Python equivalent: Blender.Lattice.Get
107
290
//***************************************************************************
108
static PyObject *M_Lattice_Get(PyObject *self, PyObject *args)
291
static PyObject *M_Lattice_Get( PyObject * self, PyObject * args )
113
if (!PyArg_ParseTuple(args, "|s", &name))
114
return (EXPP_ReturnPyObjError (PyExc_TypeError,
115
"expected string argument (or nothing)"));
117
lat_iter = G.main->latt.first;
119
if (name) { /* (name) - Search Lattice by name */
121
PyObject *wanted_lat = NULL;
123
while ((lat_iter) && (wanted_lat == NULL)) {
124
if (strcmp (name, lat_iter->id.name+2) == 0) {
125
wanted_lat = Lattice_CreatePyObject (lat_iter);
128
lat_iter = lat_iter->id.next;
131
if (wanted_lat == NULL) { /* Requested Lattice doesn't exist */
133
PyOS_snprintf(error_msg, sizeof(error_msg),
134
"Lattice \"%s\" not found", name);
135
return (EXPP_ReturnPyObjError (PyExc_NameError, error_msg));
141
else { /* () - return a list of all Lattices in the scene */
143
PyObject *latlist, *pyobj;
145
latlist = PyList_New (BLI_countlist (&(G.main->latt)));
148
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
149
"couldn't create PyList"));
152
pyobj = Lattice_CreatePyObject(lat_iter);
155
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
156
"couldn't create PyString"));
158
PyList_SET_ITEM (latlist, index, pyobj);
160
lat_iter = lat_iter->id.next;
296
if( !PyArg_ParseTuple( args, "|s", &name ) )
297
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
298
"expected string argument (or nothing)" ) );
300
lat_iter = G.main->latt.first;
302
if( name ) { /* (name) - Search Lattice by name */
304
PyObject *wanted_lat = NULL;
306
while( ( lat_iter ) && ( wanted_lat == NULL ) ) {
307
if( strcmp( name, lat_iter->id.name + 2 ) == 0 ) {
309
Lattice_CreatePyObject( lat_iter );
312
lat_iter = lat_iter->id.next;
315
if( wanted_lat == NULL ) { /* Requested Lattice doesn't exist */
317
PyOS_snprintf( error_msg, sizeof( error_msg ),
318
"Lattice \"%s\" not found", name );
319
return ( EXPP_ReturnPyObjError
320
( PyExc_NameError, error_msg ) );
326
else { /* () - return a list of all Lattices in the scene */
328
PyObject *latlist, *pyobj;
330
latlist = PyList_New( BLI_countlist( &( G.main->latt ) ) );
332
if( latlist == NULL )
333
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
334
"couldn't create PyList" ) );
337
pyobj = Lattice_CreatePyObject( lat_iter );
340
return ( EXPP_ReturnPyObjError
342
"couldn't create PyString" ) );
344
PyList_SET_ITEM( latlist, index, pyobj );
346
lat_iter = lat_iter->id.next;
167
//***************************************************************************
168
// Function: Lattice_Init
169
//***************************************************************************
170
PyObject *Lattice_Init (void)
354
//***************************************************************************
355
// Function: Lattice_Init
356
//***************************************************************************
357
PyObject *Lattice_Init( void )
172
PyObject *mod= Py_InitModule3("Blender.Lattice", M_Lattice_methods, M_Lattice_doc);
173
PyObject *dict= PyModule_GetDict(mod);
360
Py_InitModule3( "Blender.Lattice", M_Lattice_methods,
362
PyObject *dict = PyModule_GetDict( mod );
175
364
Lattice_Type.ob_type = &PyType_Type;
177
366
//Module dictionary
178
#define EXPP_ADDCONST(x) PyDict_SetItemString(dict, #x, PyInt_FromLong(LT_##x))
180
EXPP_ADDCONST(OUTSIDE);
183
#define EXPP_ADDCONST(x) PyDict_SetItemString(dict, #x, PyInt_FromLong(KEY_##x))
184
EXPP_ADDCONST(LINEAR);
185
EXPP_ADDCONST(CARDINAL);
186
EXPP_ADDCONST(BSPLINE);
367
#define EXPP_ADDCONST(x) PyDict_SetItemString(dict, #x, PyInt_FromLong(LT_##x))
368
EXPP_ADDCONST( GRID );
369
EXPP_ADDCONST( OUTSIDE );
372
#define EXPP_ADDCONST(x) PyDict_SetItemString(dict, #x, PyInt_FromLong(KEY_##x))
373
EXPP_ADDCONST( LINEAR );
374
EXPP_ADDCONST( CARDINAL );
375
EXPP_ADDCONST( BSPLINE );
191
380
//***************************************************************************
192
// Python BPy_Lattice methods:
381
// Python BPy_Lattice methods:
193
382
//***************************************************************************
194
static PyObject *Lattice_getName(BPy_Lattice *self)
383
static PyObject *Lattice_getName( BPy_Lattice * self )
196
PyObject *attr = PyString_FromString(self->Lattice->id.name+2);
198
if (attr) return attr;
200
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
201
"couldn't get Lattice.name attribute");
385
PyObject *attr = PyString_FromString( self->Lattice->id.name + 2 );
390
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
391
"couldn't get Lattice.name attribute" );
204
static PyObject *Lattice_setName(BPy_Lattice *self, PyObject *args)
394
static PyObject *Lattice_setName( BPy_Lattice * self, PyObject * args )
209
if (!PyArg_ParseTuple(args, "s", &name))
210
return (EXPP_ReturnPyObjError (PyExc_TypeError,
211
"expected string argument"));
213
PyOS_snprintf(buf, sizeof(buf), "%s", name);
215
rename_id(&self->Lattice->id, buf);
399
if( !PyArg_ParseTuple( args, "s", &name ) )
400
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
401
"expected string argument" ) );
403
PyOS_snprintf( buf, sizeof( buf ), "%s", name );
405
rename_id( &self->Lattice->id, buf );
407
Py_INCREF( Py_None );
221
static PyObject *Lattice_setPartitions(BPy_Lattice *self, PyObject *args)
411
static PyObject *Lattice_setPartitions( BPy_Lattice * self, PyObject * args )
226
Lattice * bl_Lattice;
228
if (!PyArg_ParseTuple(args, "iii", &x, &y, &z))
229
return (EXPP_ReturnPyObjError (PyExc_TypeError,
230
"expected int,int,int argument"));
418
if( !PyArg_ParseTuple( args, "iii", &x, &y, &z ) )
419
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
420
"expected int,int,int argument" ) );
232
422
bl_Lattice = self->Lattice;
234
if(x <2 || y < 2 || z < 2)
235
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
236
"partition values must be 2 or greater"));
238
bl_Lattice->pntsu = (short)x;
239
bl_Lattice->pntsv = (short)y;
240
bl_Lattice->pntsw = (short)z;
241
resizelattice(bl_Lattice);
424
if( x < 2 || y < 2 || z < 2 )
425
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
426
"partition values must be 2 or greater" ) );
428
bl_Lattice->pntsu = ( short ) x;
429
bl_Lattice->pntsv = ( short ) y;
430
bl_Lattice->pntsw = ( short ) z;
431
resizelattice( bl_Lattice );
433
Py_INCREF( Py_None );
247
static PyObject *Lattice_getPartitions(BPy_Lattice *self, PyObject *args)
437
static PyObject *Lattice_getPartitions( BPy_Lattice * self, PyObject * args )
249
Lattice * bl_Lattice;
250
440
bl_Lattice = self->Lattice;
252
return Py_BuildValue("[i,i,i]", (int)bl_Lattice->pntsu,
253
(int)bl_Lattice->pntsv,
254
(int)bl_Lattice->pntsw);
442
return Py_BuildValue( "[i,i,i]", ( int ) bl_Lattice->pntsu,
443
( int ) bl_Lattice->pntsv,
444
( int ) bl_Lattice->pntsw );
257
static PyObject *Lattice_getKeyTypes(BPy_Lattice *self, PyObject *args)
447
static PyObject *Lattice_getKeyTypes( BPy_Lattice * self, PyObject * args )
259
Lattice * bl_Lattice;
260
450
char *linear = "linear";
261
451
char *cardinal = "cardinal";
262
452
char *bspline = "bspline";
265
455
bl_Lattice = self->Lattice;
267
if ((bl_Lattice->typeu) == KEY_LINEAR)
457
if( ( bl_Lattice->typeu ) == KEY_LINEAR )
269
else if ((bl_Lattice->typeu) == KEY_CARDINAL)
459
else if( ( bl_Lattice->typeu ) == KEY_CARDINAL )
271
else if ((bl_Lattice->typeu) == KEY_BSPLINE)
461
else if( ( bl_Lattice->typeu ) == KEY_BSPLINE )
274
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
464
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
277
if ((bl_Lattice->typev) == KEY_LINEAR)
467
if( ( bl_Lattice->typev ) == KEY_LINEAR )
279
else if ((bl_Lattice->typev) == KEY_CARDINAL)
469
else if( ( bl_Lattice->typev ) == KEY_CARDINAL )
281
else if ((bl_Lattice->typev) == KEY_BSPLINE)
471
else if( ( bl_Lattice->typev ) == KEY_BSPLINE )
284
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
474
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
287
if ((bl_Lattice->typew) == KEY_LINEAR)
477
if( ( bl_Lattice->typew ) == KEY_LINEAR )
289
else if ((bl_Lattice->typew) == KEY_CARDINAL)
479
else if( ( bl_Lattice->typew ) == KEY_CARDINAL )
291
else if ((bl_Lattice->typew) == KEY_BSPLINE)
481
else if( ( bl_Lattice->typew ) == KEY_BSPLINE )
294
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
484
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
297
487
/* we made sure no s_[xyz] is NULL */
298
return Py_BuildValue("[s,s,s]", s_x, s_y, s_z);
488
return Py_BuildValue( "[s,s,s]", s_x, s_y, s_z );
301
static PyObject *Lattice_setKeyTypes(BPy_Lattice *self, PyObject *args)
491
static PyObject *Lattice_setKeyTypes( BPy_Lattice * self, PyObject * args )
306
Lattice * bl_Lattice;
308
if (!PyArg_ParseTuple(args, "iii", &x, &y, &z))
309
return (EXPP_ReturnPyObjError (PyExc_TypeError,
310
"expected int,int,int argument"));
498
if( !PyArg_ParseTuple( args, "iii", &x, &y, &z ) )
499
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
500
"expected int,int,int argument" ) );
312
502
bl_Lattice = self->Lattice;
504
if( x == KEY_LINEAR )
315
505
bl_Lattice->typeu = KEY_LINEAR;
316
else if (x == KEY_CARDINAL)
506
else if( x == KEY_CARDINAL )
317
507
bl_Lattice->typeu = KEY_CARDINAL;
318
else if (x == KEY_BSPLINE)
508
else if( x == KEY_BSPLINE )
319
509
bl_Lattice->typeu = KEY_BSPLINE;
321
return EXPP_ReturnPyObjError (PyExc_TypeError,
322
"type must be LINEAR, CARDINAL OR BSPLINE");
511
return EXPP_ReturnPyObjError( PyExc_TypeError,
512
"type must be LINEAR, CARDINAL OR BSPLINE" );
514
if( y == KEY_LINEAR )
325
515
bl_Lattice->typev = KEY_LINEAR;
326
else if (y == KEY_CARDINAL)
516
else if( y == KEY_CARDINAL )
327
517
bl_Lattice->typev = KEY_CARDINAL;
328
else if (y == KEY_BSPLINE)
518
else if( y == KEY_BSPLINE )
329
519
bl_Lattice->typev = KEY_BSPLINE;
331
return EXPP_ReturnPyObjError (PyExc_TypeError,
332
"type must be LINEAR, CARDINAL OR BSPLINE");
521
return EXPP_ReturnPyObjError( PyExc_TypeError,
522
"type must be LINEAR, CARDINAL OR BSPLINE" );
524
if( z == KEY_LINEAR )
335
525
bl_Lattice->typew = KEY_LINEAR;
336
else if (z == KEY_CARDINAL)
526
else if( z == KEY_CARDINAL )
337
527
bl_Lattice->typew = KEY_CARDINAL;
338
else if (z == KEY_BSPLINE)
528
else if( z == KEY_BSPLINE )
339
529
bl_Lattice->typew = KEY_BSPLINE;
341
return EXPP_ReturnPyObjError (PyExc_TypeError,
342
"type must be LINEAR, CARDINAL OR BSPLINE");
531
return EXPP_ReturnPyObjError( PyExc_TypeError,
532
"type must be LINEAR, CARDINAL OR BSPLINE" );
534
Py_INCREF( Py_None );
348
static PyObject *Lattice_setMode(BPy_Lattice *self, PyObject *args)
538
static PyObject *Lattice_setMode( BPy_Lattice * self, PyObject * args )
351
Lattice * bl_Lattice;
352
542
bl_Lattice = self->Lattice;
354
if (!PyArg_ParseTuple(args, "h", &type))
355
return (EXPP_ReturnPyObjError (PyExc_TypeError,
356
"expected string argument"));
544
if( !PyArg_ParseTuple( args, "h", &type ) )
545
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
546
"expected string argument" ) );
548
if( type == LT_GRID )
359
549
bl_Lattice->flag = LT_GRID;
360
else if (type == LT_OUTSIDE)
550
else if( type == LT_OUTSIDE ) {
362
551
bl_Lattice->flag = LT_OUTSIDE + LT_GRID;
363
outside_lattice(bl_Lattice);
366
return EXPP_ReturnPyObjError (PyExc_TypeError,
367
"type must be either GRID or OUTSIDE");
552
outside_lattice( bl_Lattice );
554
return EXPP_ReturnPyObjError( PyExc_TypeError,
555
"type must be either GRID or OUTSIDE" );
557
Py_INCREF( Py_None );
373
static PyObject *Lattice_getMode(BPy_Lattice *self, PyObject *args)
561
static PyObject *Lattice_getMode( BPy_Lattice * self, PyObject * args )
376
Lattice * bl_Lattice;
377
565
bl_Lattice = self->Lattice;
379
if (bl_Lattice->flag & LT_GRID)
380
sprintf(type, "Grid");
381
else if (bl_Lattice->flag & LT_OUTSIDE)
382
sprintf(type, "Outside");
567
if( bl_Lattice->flag & LT_GRID )
568
sprintf( type, "Grid" );
569
else if( bl_Lattice->flag & LT_OUTSIDE )
570
sprintf( type, "Outside" );
384
return EXPP_ReturnPyObjError (PyExc_TypeError,
387
return Py_BuildValue("s", type);
572
return EXPP_ReturnPyObjError( PyExc_TypeError,
573
"bad mode type..." );
575
return Py_BuildValue( "s", type );
390
static PyObject *Lattice_setPoint(BPy_Lattice *self, PyObject *args)
578
static PyObject *Lattice_setPoint( BPy_Lattice * self, PyObject * args )
392
580
BPoint *bp, *bpoint;
394
Lattice * bl_Lattice;
397
PyObject * listObject;
399
if (!PyArg_ParseTuple(args, "iO!", &index, &PyList_Type, &listObject))
400
return (EXPP_ReturnPyObjError (PyExc_TypeError,
401
"expected int & list argument"));
403
if(!PyList_Check(listObject))
404
return (EXPP_ReturnPyObjError (PyExc_TypeError,
405
"2nd parameter should be a python list"));
407
if (!(PyList_Size(listObject) == 3))
408
return (EXPP_ReturnPyObjError (PyExc_TypeError,
409
"Please pass 3 parameters in the list [x,y,z]"));
585
PyObject *listObject;
587
if( !PyArg_ParseTuple
588
( args, "iO!", &index, &PyList_Type, &listObject ) )
589
return ( EXPP_ReturnPyObjError
590
( PyExc_TypeError, "expected int & list argument" ) );
592
if( !PyList_Check( listObject ) )
593
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
594
"2nd parameter should be a python list" ) );
596
if( !( PyList_Size( listObject ) == 3 ) )
597
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
598
"Please pass 3 parameters in the list [x,y,z]" ) );
413
602
bl_Lattice = self->Lattice;
419
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
420
"no lattice points!"));
605
bp = bl_Lattice->def;
608
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
609
"no lattice points!" ) );
422
611
//calculate size of lattice
423
size= bl_Lattice->pntsu*bl_Lattice->pntsv*bl_Lattice->pntsw;
425
if (index < 0 || index > size)
426
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
427
"index outside of lattice size!"));
612
size = bl_Lattice->pntsu * bl_Lattice->pntsv * bl_Lattice->pntsw;
614
if( index < 0 || index > size )
615
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
616
"index outside of lattice size!" ) );
437
for (x = 0; x < PyList_Size(listObject); x++) {
438
if (!(PyArg_Parse((PyList_GetItem(listObject, x)), "f", &tempInt)))
439
return EXPP_ReturnPyObjError (PyExc_TypeError,
440
"python list integer not parseable");
625
for( x = 0; x < PyList_Size( listObject ); x++ ) {
628
( ( PyList_GetItem( listObject, x ) ), "f",
630
return EXPP_ReturnPyObjError( PyExc_TypeError,
631
"python list integer not parseable" );
441
632
bpoint->vec[x] = tempInt;
635
Py_INCREF( Py_None );
448
static PyObject *Lattice_getPoint(BPy_Lattice *self, PyObject *args)
639
static PyObject *Lattice_getPoint( BPy_Lattice * self, PyObject * args )
450
641
BPoint *bp, *bpoint;
452
Lattice * bl_Lattice;
455
if (!PyArg_ParseTuple(args, "i", &index))
456
return (EXPP_ReturnPyObjError (PyExc_TypeError,
457
"expected int argument"));
646
if( !PyArg_ParseTuple( args, "i", &index ) )
647
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
648
"expected int argument" ) );
461
652
bl_Lattice = self->Lattice;
467
return (EXPP_ReturnPyObjError (PyExc_AttributeError,
468
"no lattice points!"));
655
bp = bl_Lattice->def;
658
return ( EXPP_ReturnPyObjError( PyExc_AttributeError,
659
"no lattice points!" ) );
470
661
//calculate size of lattice
471
size= bl_Lattice->pntsu*bl_Lattice->pntsv*bl_Lattice->pntsw;
473
if (index < 0 || index > size)
474
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
475
"index outside of lattice size!"));
662
size = bl_Lattice->pntsu * bl_Lattice->pntsv * bl_Lattice->pntsw;
664
if( index < 0 || index > size )
665
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
666
"index outside of lattice size!" ) );
486
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
487
"bpoint does not exist"));
676
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
677
"bpoint does not exist" ) );
489
return Py_BuildValue("[f,f,f]", bp->vec[0] ,bp->vec[1] ,bp->vec[2]);
679
return Py_BuildValue( "[f,f,f]", bp->vec[0], bp->vec[1], bp->vec[2] );
492
682
//This function will not do anything if there are no children
493
static PyObject *Lattice_applyDeform(BPy_Lattice *self)
683
static PyObject *Lattice_applyDeform( BPy_Lattice * self, PyObject *args )
495
685
//Object* ob; unused
499
if (!Lattice_IsLinkedToObject(self))
500
return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
501
"Lattice must be linked to an object to apply it's deformation!"));
506
if( (par= base->object->parent) ) {
507
if(par->type==OB_LATTICE) {
508
object_deform(base->object);
690
if( !Lattice_IsLinkedToObject( self ) )
691
return ( EXPP_ReturnPyObjError( PyExc_RuntimeError,
692
"Lattice must be linked to an object to apply it's deformation!" ) );
694
if( !PyArg_ParseTuple( args, "|i", &forced ) )
695
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
696
"expected nothing or True or False argument" ) );
698
/* deform children */
701
if( ( par = base->object->parent ) ) { /* check/assign if ob has parent */
702
/* meshes have their mverts deformed, others ob types use displist,
703
* so we're not doing meshes here (unless forced), or else they get
704
* deformed twice, since parenting a Lattice to an object and redrawing
705
* already applies lattice deformation. 'forced' is useful for
706
* command line background mode, when no redraws occur and so this
707
* method is needed. Or for users who actually want to apply the
708
* deformation n times. */
709
if((self->Lattice == par->data)) {
710
if ((base->object->type != OB_MESH) || forced)
711
object_deform( base->object );
717
Py_INCREF( Py_None );
518
static PyObject *Lattice_insertKey(BPy_Lattice *self, PyObject *args)
721
static PyObject *Lattice_insertKey( BPy_Lattice * self, PyObject * args )
521
724
int frame = -1, oldfra = -1;
523
if (!PyArg_ParseTuple(args, "i", &frame))
524
return (EXPP_ReturnPyObjError (PyExc_TypeError,
525
"expected int argument"));
726
if( !PyArg_ParseTuple( args, "i", &frame ) )
727
return ( EXPP_ReturnPyObjError( PyExc_TypeError,
728
"expected int argument" ) );
527
730
lt = self->Lattice;
529
732
//set the current frame
531
frame = EXPP_ClampInt (frame, 1, 18000);
734
frame = EXPP_ClampInt( frame, 1, MAXFRAME );
532
735
oldfra = G.scene->r.cfra;
533
736
G.scene->r.cfra = frame;
535
// else just use current frame, then
536
// return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
537
// "frame value has to be greater than 0"));
738
// else just use current frame, then
739
// return (EXPP_ReturnPyObjError (PyExc_RuntimeError,
740
// "frame value has to be greater than 0"));
539
742
//insert a keybock for the lattice
542
if (frame > 0) G.scene->r.cfra = oldfra;
743
insert_lattkey( lt );
746
G.scene->r.cfra = oldfra;
748
Py_INCREF( Py_None );
548
752
//***************************************************************************
549
// Function: Lattice_dealloc
550
// Description: This is a callback function for the BPy_Lattice type. It is
551
// the destructor function.
753
// Function: Lattice_dealloc
754
// Description: This is a callback function for the BPy_Lattice type. It is
755
// the destructor function.
552
756
//***************************************************************************
553
static void Lattice_dealloc (BPy_Lattice *self)
757
static void Lattice_dealloc( BPy_Lattice * self )
759
PyObject_DEL( self );
558
762
//***************************************************************************
559
// Function: Lattice_getAttr
560
// Description: This is a callback function for the BPy_Lattice type. It is
561
// the function that accesses BPy_Lattice member variables and
763
// Function: Lattice_getAttr
764
// Description: This is a callback function for the BPy_Lattice type. It is
765
// the function that accesses BPy_Lattice member variables and
563
767
//***************************************************************************
564
static PyObject *Lattice_getAttr (BPy_Lattice *self, char *name)
768
static PyObject *Lattice_getAttr( BPy_Lattice * self, char *name )
566
770
PyObject *attr = Py_None;
568
if (!self->Lattice || !Lattice_InLatList(self))
569
return EXPP_ReturnPyObjError (PyExc_RuntimeError,
570
"Lattice was already deleted!");
572
if (strcmp(name, "name") == 0)
573
attr = PyString_FromString(self->Lattice->id.name+2);
574
else if (strcmp(name, "width") == 0)
575
attr = Py_BuildValue("i",self->Lattice->pntsu);
576
else if (strcmp(name, "height") == 0)
577
attr = Py_BuildValue("i",self->Lattice->pntsv);
578
else if (strcmp(name, "depth") == 0)
579
attr = Py_BuildValue("i",self->Lattice->pntsw);
580
else if (strcmp(name, "widthType") == 0)
582
if(self->Lattice->typeu == 0)
583
attr = Py_BuildValue("s","Linear");
584
else if (self->Lattice->typeu == 1)
585
attr = Py_BuildValue("s","Cardinal");
586
else if (self->Lattice->typeu == 2)
587
attr = Py_BuildValue("s","Bspline");
589
return EXPP_ReturnPyObjError (PyExc_ValueError,
592
else if (strcmp(name, "heightType") == 0)
594
if(self->Lattice->typev == 0)
595
attr = Py_BuildValue("s","Linear");
596
else if (self->Lattice->typev== 1)
597
attr = Py_BuildValue("s","Cardinal");
598
else if (self->Lattice->typev == 2)
599
attr = Py_BuildValue("s","Bspline");
601
return EXPP_ReturnPyObjError (PyExc_ValueError,
604
else if (strcmp(name, "depthType") == 0)
606
if(self->Lattice->typew == 0)
607
attr = Py_BuildValue("s","Linear");
608
else if (self->Lattice->typew == 1)
609
attr = Py_BuildValue("s","Cardinal");
610
else if (self->Lattice->typew == 2)
611
attr = Py_BuildValue("s","Bspline");
613
return EXPP_ReturnPyObjError (PyExc_ValueError,
616
else if (strcmp(name, "mode") == 0)
618
if(self->Lattice->flag == 1)
619
attr = Py_BuildValue("s","Grid");
620
else if (self->Lattice->flag == 3)
621
attr = Py_BuildValue("s","Outside");
623
return EXPP_ReturnPyObjError (PyExc_ValueError,
626
else if (strcmp(name, "latSize") == 0)
628
attr = Py_BuildValue("i",self->Lattice->pntsu *
629
self->Lattice->pntsv *
630
self->Lattice->pntsw);
632
else if (strcmp(name, "__members__") == 0)
633
attr = Py_BuildValue("[s,s,s,s,s,s,s,s,s]", "name","width","height","depth",
634
"widthType","heightType","depthType","mode","latSize");
637
return (EXPP_ReturnPyObjError (PyExc_MemoryError,
638
"couldn't create PyObject"));
640
if (attr != Py_None) return attr; // attribute found, return its value
772
if( !self->Lattice || !Lattice_InLatList( self ) )
773
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
774
"Lattice was already deleted!" );
776
if( strcmp( name, "name" ) == 0 )
777
attr = PyString_FromString( self->Lattice->id.name + 2 );
778
else if( strcmp( name, "width" ) == 0 )
779
attr = Py_BuildValue( "i", self->Lattice->pntsu );
780
else if( strcmp( name, "height" ) == 0 )
781
attr = Py_BuildValue( "i", self->Lattice->pntsv );
782
else if( strcmp( name, "depth" ) == 0 )
783
attr = Py_BuildValue( "i", self->Lattice->pntsw );
784
else if( strcmp( name, "widthType" ) == 0 ) {
785
if( self->Lattice->typeu == 0 )
786
attr = Py_BuildValue( "s", "Linear" );
787
else if( self->Lattice->typeu == 1 )
788
attr = Py_BuildValue( "s", "Cardinal" );
789
else if( self->Lattice->typeu == 2 )
790
attr = Py_BuildValue( "s", "Bspline" );
792
return EXPP_ReturnPyObjError( PyExc_ValueError,
793
"bad widthType..." );
794
} else if( strcmp( name, "heightType" ) == 0 ) {
795
if( self->Lattice->typev == 0 )
796
attr = Py_BuildValue( "s", "Linear" );
797
else if( self->Lattice->typev == 1 )
798
attr = Py_BuildValue( "s", "Cardinal" );
799
else if( self->Lattice->typev == 2 )
800
attr = Py_BuildValue( "s", "Bspline" );
802
return EXPP_ReturnPyObjError( PyExc_ValueError,
803
"bad widthType..." );
804
} else if( strcmp( name, "depthType" ) == 0 ) {
805
if( self->Lattice->typew == 0 )
806
attr = Py_BuildValue( "s", "Linear" );
807
else if( self->Lattice->typew == 1 )
808
attr = Py_BuildValue( "s", "Cardinal" );
809
else if( self->Lattice->typew == 2 )
810
attr = Py_BuildValue( "s", "Bspline" );
812
return EXPP_ReturnPyObjError( PyExc_ValueError,
813
"bad widthType..." );
814
} else if( strcmp( name, "mode" ) == 0 ) {
815
if( self->Lattice->flag == 1 )
816
attr = Py_BuildValue( "s", "Grid" );
817
else if( self->Lattice->flag == 3 )
818
attr = Py_BuildValue( "s", "Outside" );
820
return EXPP_ReturnPyObjError( PyExc_ValueError,
822
} else if( strcmp( name, "latSize" ) == 0 ) {
823
attr = Py_BuildValue( "i", self->Lattice->pntsu *
824
self->Lattice->pntsv *
825
self->Lattice->pntsw );
826
} else if( strcmp( name, "users" ) == 0 ) {
827
attr = PyInt_FromLong( self->Lattice->id.us );
829
} else if( strcmp( name, "__members__" ) == 0 )
830
attr = Py_BuildValue( "[s,s,s,s,s,s,s,s,s]", "name", "width",
831
"height", "depth", "widthType",
832
"heightType", "depthType", "mode",
833
"latSize", "users" );
836
return ( EXPP_ReturnPyObjError( PyExc_MemoryError,
837
"couldn't create PyObject" ) );
839
if( attr != Py_None )
840
return attr; // attribute found, return its value
642
842
// not an attribute, search the methods table
643
return Py_FindMethod(BPy_Lattice_methods, (PyObject *)self, name);
843
return Py_FindMethod( BPy_Lattice_methods, ( PyObject * ) self, name );
646
846
//***************************************************************************
647
// Function: Lattice_setAttr
648
// Description: This is a callback function for the BPy_Lattice type. It is the
649
// function that changes Lattice Data members values. If this
650
// data is linked to a Blender Lattice, it also gets updated.
847
// Function: Lattice_setAttr
848
// Description: This is a callback function for the BPy_Lattice type. It is the
849
// function that changes Lattice Data members values. If this
850
// data is linked to a Blender Lattice, it also gets updated.
651
851
//***************************************************************************
652
static int Lattice_setAttr (BPy_Lattice *self, char *name, PyObject *value)
852
static int Lattice_setAttr( BPy_Lattice * self, char *name, PyObject * value )
655
855
PyObject *error = NULL;
657
if (!self->Lattice || !Lattice_InLatList(self))
658
return EXPP_ReturnIntError (PyExc_RuntimeError,
659
"Lattice was already deleted!");
661
valtuple = Py_BuildValue("(O)", value);// the set* functions expect a tuple
664
return EXPP_ReturnIntError(PyExc_MemoryError,
665
"LatticeSetAttr: couldn't create PyTuple");
667
if (strcmp (name, "name") == 0)
668
error = Lattice_setName (self, valtuple);
669
else { // Error: no such member in the Lattice Data structure
672
return (EXPP_ReturnIntError (PyExc_KeyError,
673
"attribute not found or immutable"));
857
if( !self->Lattice || !Lattice_InLatList( self ) )
858
return EXPP_ReturnIntError( PyExc_RuntimeError,
859
"Lattice was already deleted!" );
861
valtuple = Py_BuildValue( "(O)", value ); // the set* functions expect a tuple
864
return EXPP_ReturnIntError( PyExc_MemoryError,
865
"LatticeSetAttr: couldn't create PyTuple" );
867
if( strcmp( name, "name" ) == 0 )
868
error = Lattice_setName( self, valtuple );
869
else { // Error: no such member in the Lattice Data structure
871
Py_DECREF( valtuple );
872
return ( EXPP_ReturnIntError( PyExc_KeyError,
873
"attribute not found or immutable" ) );
677
if (error != Py_None) return -1;
679
return 0; // normal exit
875
Py_DECREF( valtuple );
877
if( error != Py_None )
880
return 0; // normal exit
682
883
//***************************************************************************
683
// Function: Lattice_repr
684
// Description: This is a callback function for the BPy_Lattice type. It
685
// builds a meaninful string to represent Lattice objects.
884
// Function: Lattice_repr
885
// Description: This is a callback function for the BPy_Lattice type. It
886
// builds a meaninful string to represent Lattice objects.
686
887
//***************************************************************************
687
static PyObject *Lattice_repr (BPy_Lattice *self)
888
static PyObject *Lattice_repr( BPy_Lattice * self )
689
if (self->Lattice && Lattice_InLatList(self))
690
return PyString_FromFormat("[Lattice \"%s\"]", self->Lattice->id.name+2);
890
if( self->Lattice && Lattice_InLatList( self ) )
891
return PyString_FromFormat( "[Lattice \"%s\"]",
892
self->Lattice->id.name + 2 );
692
return PyString_FromString("[Lattice <deleted>]");
894
return PyString_FromString( "[Lattice <deleted>]" );
695
897
//***************************************************************************
696
// Function: Internal Lattice functions
898
// Function: Internal Lattice functions
697
899
//***************************************************************************
698
900
// Internal function to confirm if a Lattice wasn't unlinked from main.
699
static int Lattice_InLatList(BPy_Lattice *self)
901
static int Lattice_InLatList( BPy_Lattice * self )
701
903
Lattice *lat_iter = G.main->latt.first;
704
if (self->Lattice == lat_iter) return 1; // ok, still linked
906
if( self->Lattice == lat_iter )
907
return 1; // ok, still linked
706
909
lat_iter = lat_iter->id.next;
708
911
// uh-oh, it was already deleted
709
self->Lattice = NULL; // so we invalidate the pointer
912
self->Lattice = NULL; // so we invalidate the pointer
713
916
// Internal function to confirm if a Lattice has an object it's linked to.
714
static int Lattice_IsLinkedToObject(BPy_Lattice *self)
917
static int Lattice_IsLinkedToObject( BPy_Lattice * self )
716
919
//check to see if lattice is linked to an object
717
Object * ob= G.main->object.first;
719
if(ob->type==OB_LATTICE){
720
if(self->Lattice == ob->data){
920
Object *ob = G.main->object.first;
922
if( ob->type == OB_LATTICE ) {
923
if( self->Lattice == ob->data ) {
724
927
ob = ob->id.next;