2
* $Id: Constraint.c 16519 2008-09-14 12:41:42Z aligorith $
4
* ***** BEGIN GPL LICENSE BLOCK *****
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software Foundation,
18
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21
* All rights reserved.
23
* This is a new part of Blender.
25
* Contributor(s): Joseph Gilbert, Ken Hughes, Joshua Leung
27
* ***** END GPL LICENSE BLOCK *****
30
#include "Constraint.h" /*This must come first*/
32
#include "DNA_armature_types.h"
33
#include "DNA_object_types.h"
34
#include "DNA_effect_types.h"
35
#include "DNA_vec_types.h"
36
#include "DNA_curve_types.h"
37
#include "DNA_text_types.h"
40
#include "BKE_global.h"
41
#include "BKE_library.h"
42
#include "BKE_action.h"
43
#include "BKE_armature.h"
44
#include "BKE_constraint.h"
45
#include "BLI_blenlib.h"
46
#include "BIF_editconstraint.h"
47
#include "BIF_keyframing.h"
48
#include "BIF_poseobject.h"
49
#include "BSE_editipo.h"
50
#include "MEM_guardedalloc.h"
59
#include "gen_utils.h"
61
enum constraint_constants {
65
EXPP_CONSTR_XSIZE = 10,
66
EXPP_CONSTR_YSIZE = 11,
67
EXPP_CONSTR_ZSIZE = 12,
68
EXPP_CONSTR_XLOC = 20,
69
EXPP_CONSTR_YLOC = 21,
70
EXPP_CONSTR_ZLOC = 22,
72
EXPP_CONSTR_MAXX = TRACK_X,
73
EXPP_CONSTR_MAXY = TRACK_Y,
74
EXPP_CONSTR_MAXZ = TRACK_Z,
75
EXPP_CONSTR_MINX = TRACK_nX,
76
EXPP_CONSTR_MINY = TRACK_nY,
77
EXPP_CONSTR_MINZ = TRACK_nZ,
79
EXPP_CONSTR_TARGET = 100,
81
EXPP_CONSTR_ITERATIONS,
84
EXPP_CONSTR_POSWEIGHT,
85
EXPP_CONSTR_ROTWEIGHT,
99
EXPP_CONSTR_RESTLENGTH,
100
EXPP_CONSTR_VOLVARIATION,
101
EXPP_CONSTR_VOLUMEMODE,
119
EXPP_CONSTR_LIMXMIN = LIMIT_XMIN,
120
EXPP_CONSTR_LIMXMAX = LIMIT_XMAX,
121
EXPP_CONSTR_LIMYMIN = LIMIT_YMIN,
122
EXPP_CONSTR_LIMYMAX = LIMIT_YMAX,
123
EXPP_CONSTR_LIMZMIN = LIMIT_ZMIN,
124
EXPP_CONSTR_LIMZMAX = LIMIT_ZMAX,
126
EXPP_CONSTR_LIMXROT = LIMIT_XROT,
127
EXPP_CONSTR_LIMYROT = LIMIT_YROT,
128
EXPP_CONSTR_LIMZROT = LIMIT_ZROT,
130
EXPP_CONSTR_CLAMPCYCLIC,
145
EXPP_CONSTR_FROMMINX,
146
EXPP_CONSTR_FROMMAXX,
147
EXPP_CONSTR_FROMMINY,
148
EXPP_CONSTR_FROMMAXY,
149
EXPP_CONSTR_FROMMINZ,
150
EXPP_CONSTR_FROMMAXZ,
161
EXPP_CONSTR_OWNSPACE,
162
EXPP_CONSTR_TARSPACE,
166
EXPP_CONSTR_RB_HINGE,
167
EXPP_CONSTR_RB_GENERIC6DOF,
168
EXPP_CONSTR_RB_VEHICLE,
175
EXPP_CONSTR_RB_MINLIMIT0,
176
EXPP_CONSTR_RB_MINLIMIT1,
177
EXPP_CONSTR_RB_MINLIMIT2,
178
EXPP_CONSTR_RB_MINLIMIT3,
179
EXPP_CONSTR_RB_MINLIMIT4,
180
EXPP_CONSTR_RB_MINLIMIT5,
181
EXPP_CONSTR_RB_MAXLIMIT0,
182
EXPP_CONSTR_RB_MAXLIMIT1,
183
EXPP_CONSTR_RB_MAXLIMIT2,
184
EXPP_CONSTR_RB_MAXLIMIT3,
185
EXPP_CONSTR_RB_MAXLIMIT4,
186
EXPP_CONSTR_RB_MAXLIMIT5,
187
EXPP_CONSTR_RB_EXTRAFZ,
192
/*****************************************************************************/
193
/* Python BPy_Constraint methods declarations: */
194
/*****************************************************************************/
195
static PyObject *Constraint_getName( BPy_Constraint * self );
196
static int Constraint_setName( BPy_Constraint * self, PyObject *arg );
197
static PyObject *Constraint_getType( BPy_Constraint * self );
198
static PyObject *Constraint_getInfluence( BPy_Constraint * self );
199
static int Constraint_setInfluence( BPy_Constraint * self, PyObject * arg );
201
static PyObject *Constraint_insertKey( BPy_Constraint * self, PyObject * arg );
203
static PyObject *Constraint_getData( BPy_Constraint * self, PyObject * key );
204
static int Constraint_setData( BPy_Constraint * self, PyObject * key,
207
/*****************************************************************************/
208
/* Python BPy_Constraint methods table: */
209
/*****************************************************************************/
210
static PyMethodDef BPy_Constraint_methods[] = {
211
/* name, method, flags, doc */
212
{"insertKey", ( PyCFunction ) Constraint_insertKey, METH_O,
213
"Insert influence keyframe for constraint"},
214
{NULL, NULL, 0, NULL}
217
/*****************************************************************************/
218
/* Python BPy_Constraint attributes get/set structure: */
219
/*****************************************************************************/
220
static PyGetSetDef BPy_Constraint_getseters[] = {
222
(getter)Constraint_getName, (setter)Constraint_setName,
223
"Constraint name", NULL},
225
(getter)Constraint_getType, (setter)NULL,
226
"Constraint type (read only)", NULL},
228
(getter)Constraint_getInfluence, (setter)Constraint_setInfluence,
229
"Constraint influence", NULL},
230
{NULL,NULL,NULL,NULL,NULL} /* Sentinel */
233
/*****************************************************************************/
234
/* Python Constraint_Type Mapping Methods table: */
235
/*****************************************************************************/
236
static PyMappingMethods Constraint_as_mapping = {
237
NULL, /* mp_length */
238
( binaryfunc ) Constraint_getData, /* mp_subscript */
239
( objobjargproc ) Constraint_setData, /* mp_ass_subscript */
242
/*****************************************************************************/
243
/* Python Constraint_Type callback function prototypes: */
244
/*****************************************************************************/
245
static PyObject *Constraint_repr( BPy_Constraint * self );
246
static int Constraint_compare( BPy_Constraint * a, BPy_Constraint * b );
248
/*****************************************************************************/
249
/* Python Constraint_Type structure definition: */
250
/*****************************************************************************/
251
PyTypeObject Constraint_Type = {
252
PyObject_HEAD_INIT( NULL ) /* required py macro */
254
/* For printing, in format "<module>.<name>" */
255
"Blender Constraint", /* char *tp_name; */
256
sizeof( BPy_Constraint ), /* int tp_basicsize; */
257
0, /* tp_itemsize; For allocation */
259
/* Methods to implement standard operations */
261
NULL, /* destructor tp_dealloc; */
262
NULL, /* printfunc tp_print; */
263
NULL, /* getattrfunc tp_getattr; */
264
NULL, /* setattrfunc tp_setattr; */
265
( cmpfunc ) Constraint_compare, /* cmpfunc tp_compare; */
266
( reprfunc ) Constraint_repr, /* reprfunc tp_repr; */
268
/* Method suites for standard classes */
270
NULL, /* PyNumberMethods *tp_as_number; */
271
NULL, /* PySequenceMethods *tp_as_sequence; */
272
&Constraint_as_mapping, /* PyMappingMethods *tp_as_mapping; */
274
/* More standard operations (here for binary compatibility) */
276
NULL, /* hashfunc tp_hash; */
277
NULL, /* ternaryfunc tp_call; */
278
NULL, /* reprfunc tp_str; */
279
NULL, /* getattrofunc tp_getattro; */
280
NULL, /* setattrofunc tp_setattro; */
282
/* Functions to access object as input/output buffer */
283
NULL, /* PyBufferProcs *tp_as_buffer; */
285
/*** Flags to define presence of optional/expanded features ***/
286
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
288
NULL, /* char *tp_doc; Documentation string */
289
/*** Assigned meaning in release 2.0 ***/
290
/* call function for all accessible objects */
291
NULL, /* traverseproc tp_traverse; */
293
/* delete references to contained objects */
294
NULL, /* inquiry tp_clear; */
296
/*** Assigned meaning in release 2.1 ***/
297
/*** rich comparisons ***/
298
NULL, /* richcmpfunc tp_richcompare; */
300
/*** weak reference enabler ***/
301
0, /* long tp_weaklistoffset; */
303
/*** Added in release 2.2 ***/
305
NULL, /* getiterfunc tp_iter; */
306
NULL, /* iternextfunc tp_iternext; */
308
/*** Attribute descriptor and subclassing stuff ***/
309
BPy_Constraint_methods, /* struct PyMethodDef *tp_methods; */
310
NULL, /* struct PyMemberDef *tp_members; */
311
BPy_Constraint_getseters, /* struct PyGetSetDef *tp_getset; */
312
NULL, /* struct _typeobject *tp_base; */
313
NULL, /* PyObject *tp_dict; */
314
NULL, /* descrgetfunc tp_descr_get; */
315
NULL, /* descrsetfunc tp_descr_set; */
316
0, /* long tp_dictoffset; */
317
NULL, /* initproc tp_init; */
318
NULL, /* allocfunc tp_alloc; */
319
NULL, /* newfunc tp_new; */
320
/* Low-level free-memory routine */
321
NULL, /* freefunc tp_free; */
322
/* For PyObject_IS_GC */
323
NULL, /* inquiry tp_is_gc; */
324
NULL, /* PyObject *tp_bases; */
325
/* method resolution order */
326
NULL, /* PyObject *tp_mro; */
327
NULL, /* PyObject *tp_cache; */
328
NULL, /* PyObject *tp_subclasses; */
329
NULL, /* PyObject *tp_weaklist; */
333
/*****************************************************************************/
334
/* Python BPy_Constraint methods: */
335
/*****************************************************************************/
338
* return the name of this constraint
341
static PyObject *Constraint_getName( BPy_Constraint * self )
344
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
345
"This constraint has been removed!" );
347
return PyString_FromString( self->con->name );
351
* set the name of this constraint
354
static int Constraint_setName( BPy_Constraint * self, PyObject * attr )
356
char *name = PyString_AsString( attr );
358
return EXPP_ReturnIntError( PyExc_TypeError, "expected string arg" );
361
return EXPP_ReturnIntError( PyExc_RuntimeError,
362
"This constraint has been removed!" );
364
BLI_strncpy( self->con->name, name, sizeof( self->con->name ) );
370
* return the influence of this constraint
373
static PyObject *Constraint_getInfluence( BPy_Constraint * self )
376
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
377
"This constraint has been removed!" );
379
return PyFloat_FromDouble( (double)self->con->enforce );
383
* set the influence of this constraint
386
static int Constraint_setInfluence( BPy_Constraint * self, PyObject * value )
389
return EXPP_ReturnIntError( PyExc_RuntimeError,
390
"This constraint has been removed!" );
392
return EXPP_setFloatClamped( value, &self->con->enforce, 0.0, 1.0 );
396
* return the type of this constraint
399
static PyObject *Constraint_getType( BPy_Constraint * self )
402
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
403
"This constraint has been removed!" );
405
return PyInt_FromLong( self->con->type );
409
* add keyframe for influence
410
base on code in add_influence_key_to_constraint_func()
412
static PyObject *Constraint_insertKey( BPy_Constraint * self, PyObject * value )
414
bConstraint *con = self->con;
415
Object *ob = self->obj;
416
bPoseChannel *pchan = self->pchan;
418
float cfra = (float)PyFloat_AsDouble(value);
419
char actname[32] = "";
422
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
423
"This constraint has been removed!" );
425
/* get frame for inserting key */
426
if( PyFloat_Check(value) )
427
return EXPP_ReturnPyObjError( PyExc_TypeError,
428
"expected a float argument" );
430
/* find actname for locating that action-channel that a constraint channel should be added to */
433
/* actname is the name of the pchan that this constraint belongs to */
434
BLI_strncpy(actname, pchan->name, 32);
437
/* hardcoded achan name -> "Object" (this may change in future) */
438
strcpy(actname, "Object");
442
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
443
"constraint doesn't belong to anything" );
445
icu= verify_ipocurve((ID *)ob, ID_CO, actname, con->name, NULL, CO_ENFORCE, 1);
448
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
449
"cannot get a curve from this IPO, may be using libdata" );
452
insert_vert_icu( icu, get_action_frame(ob, cfra), con->enforce, 0);
454
insert_vert_icu( icu, cfra, con->enforce, 0);
459
/******************************************************************************/
460
/* Constraint Space Conversion get/set procedures */
461
/* - These are called before/instead of individual constraint */
462
/* get/set procedures when OWNERSPACE or TARGETSPACE are chosen */
463
/* - They are only called from Constraint_g/setData */
464
/******************************************************************************/
466
static PyObject *constspace_getter( BPy_Constraint * self, int type )
468
bConstraint *con= (bConstraint *)(self->con);
470
/* depends on type being asked for
471
* NOTE: not all constraints support all space types
473
if (type == EXPP_CONSTR_OWNSPACE) {
475
/* all of these support this... */
476
case CONSTRAINT_TYPE_PYTHON:
477
case CONSTRAINT_TYPE_LOCLIKE:
478
case CONSTRAINT_TYPE_ROTLIKE:
479
case CONSTRAINT_TYPE_SIZELIKE:
480
case CONSTRAINT_TYPE_TRACKTO:
481
case CONSTRAINT_TYPE_LOCLIMIT:
482
case CONSTRAINT_TYPE_ROTLIMIT:
483
case CONSTRAINT_TYPE_SIZELIMIT:
484
case CONSTRAINT_TYPE_TRANSFORM:
485
return PyInt_FromLong( (long)con->ownspace );
488
else if (type == EXPP_CONSTR_TARSPACE) {
490
/* all of these support this... */
491
case CONSTRAINT_TYPE_PYTHON:
492
case CONSTRAINT_TYPE_ACTION:
493
case CONSTRAINT_TYPE_LOCLIKE:
494
case CONSTRAINT_TYPE_ROTLIKE:
495
case CONSTRAINT_TYPE_SIZELIKE:
496
case CONSTRAINT_TYPE_TRACKTO:
497
case CONSTRAINT_TYPE_TRANSFORM:
499
bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
500
bConstraintTarget *ct;
501
PyObject *tlist=NULL, *val;
504
/* change space of targets */
505
if (cti->get_constraint_targets) {
506
ListBase targets = {NULL, NULL};
509
/* get targets, and create py-list for use temporarily */
510
num_tars= cti->get_constraint_targets(con, &targets);
512
tlist= PyList_New(num_tars);
514
for (ct=targets.first; ct; ct=ct->next, i++) {
515
val= PyInt_FromLong((long)ct->space);
516
PyList_SET_ITEM(tlist, i, val);
520
if (cti->flush_constraint_targets)
521
cti->flush_constraint_targets(con, &targets, 1);
530
/* raise error if failed */
531
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
534
static int constspace_setter( BPy_Constraint *self, int type, PyObject *value )
536
bConstraint *con= (bConstraint *)(self->con);
538
/* depends on type being asked for
539
* NOTE: not all constraints support all space types
541
if (type == EXPP_CONSTR_OWNSPACE) {
543
/* all of these support this... */
544
case CONSTRAINT_TYPE_PYTHON:
545
case CONSTRAINT_TYPE_LOCLIKE:
546
case CONSTRAINT_TYPE_ROTLIKE:
547
case CONSTRAINT_TYPE_SIZELIKE:
548
case CONSTRAINT_TYPE_TRACKTO:
549
case CONSTRAINT_TYPE_LOCLIMIT:
550
case CONSTRAINT_TYPE_ROTLIMIT:
551
case CONSTRAINT_TYPE_SIZELIMIT:
552
case CONSTRAINT_TYPE_TRANSFORM:
554
/* only copy depending on ownertype */
556
return EXPP_setIValueClamped( value, &con->ownspace,
557
CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_PARLOCAL, 'h' );
560
return EXPP_setIValueClamped( value, &con->ownspace,
561
CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL, 'h' );
567
else if (type == EXPP_CONSTR_TARSPACE) {
569
/* all of these support this... */
570
case CONSTRAINT_TYPE_PYTHON:
571
case CONSTRAINT_TYPE_ACTION:
572
case CONSTRAINT_TYPE_LOCLIKE:
573
case CONSTRAINT_TYPE_ROTLIKE:
574
case CONSTRAINT_TYPE_SIZELIKE:
575
case CONSTRAINT_TYPE_TRACKTO:
576
case CONSTRAINT_TYPE_TRANSFORM:
578
bConstraintTypeInfo *cti= constraint_get_typeinfo(con);
579
bConstraintTarget *ct;
583
/* change space of targets */
584
if (cti->get_constraint_targets) {
585
ListBase targets = {NULL, NULL};
588
/* get targets, and extract values from the given list */
589
num_tars= cti->get_constraint_targets(con, &targets);
591
if ((PySequence_Check(value) == 0) || (PySequence_Size(value) != num_tars)) {
593
sprintf(errorstr, "expected sequence of %d integer(s)", num_tars);
594
return EXPP_ReturnIntError(PyExc_TypeError, errorstr);
597
for (ct=targets.first; ct; ct=ct->next, i++) {
598
if (ct->tar && ct->subtarget[0]) {
599
PyObject *val= PySequence_ITEM(value, i);
601
ok += EXPP_setIValueClamped(val, &ct->space,
602
CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_PARLOCAL, 'h' );
607
PyObject *val= PySequence_ITEM(value, i);
609
ok += EXPP_setIValueClamped(val, &ct->space,
610
CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL, 'h' );
617
if (cti->flush_constraint_targets)
618
cti->flush_constraint_targets(con, &targets, 0);
628
/* raise error if failed */
629
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
632
/*****************************************************************************/
633
/* Specific constraint get/set procedures */
634
/*****************************************************************************/
636
static PyObject *kinematic_getter( BPy_Constraint * self, int type )
638
bKinematicConstraint *con = (bKinematicConstraint *)(self->con->data);
641
case EXPP_CONSTR_TARGET:
642
return Object_CreatePyObject( con->tar );
643
case EXPP_CONSTR_BONE:
644
return PyString_FromString( con->subtarget );
645
case EXPP_CONSTR_STRETCH:
646
return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_STRETCH ) ) ;
647
case EXPP_CONSTR_ITERATIONS:
648
return PyInt_FromLong( (long)con->iterations );
649
case EXPP_CONSTR_CHAINLEN:
650
return PyInt_FromLong( (long)con->rootbone );
651
case EXPP_CONSTR_POSWEIGHT:
652
return PyFloat_FromDouble( (double)con->weight );
653
case EXPP_CONSTR_ROTWEIGHT:
654
return PyFloat_FromDouble( (double)con->orientweight );
655
case EXPP_CONSTR_ROTATE:
656
return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_ROT ) ) ;
657
case EXPP_CONSTR_USETIP:
658
return PyBool_FromLong( (long)( con->flag & CONSTRAINT_IK_TIP ) ) ;
660
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
664
static int kinematic_setter( BPy_Constraint *self, int type, PyObject *value )
666
bKinematicConstraint *con = (bKinematicConstraint *)(self->con->data);
669
case EXPP_CONSTR_TARGET: {
670
Object *obj = (( BPy_Object * )value)->object;
671
if( !BPy_Object_Check( value ) )
672
return EXPP_ReturnIntError( PyExc_TypeError,
673
"expected BPy object argument" );
677
case EXPP_CONSTR_BONE: {
678
char *name = PyString_AsString( value );
680
return EXPP_ReturnIntError( PyExc_TypeError,
681
"expected string arg" );
683
BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
687
case EXPP_CONSTR_STRETCH:
688
return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_STRETCH, 'h' );
689
case EXPP_CONSTR_ITERATIONS:
690
return EXPP_setIValueClamped( value, &con->iterations, 1, 10000, 'h' );
691
case EXPP_CONSTR_CHAINLEN:
692
return EXPP_setIValueClamped( value, &con->rootbone, 0, 255, 'i' );
693
case EXPP_CONSTR_POSWEIGHT:
694
return EXPP_setFloatClamped( value, &con->weight, 0.01f, 1.0 );
695
case EXPP_CONSTR_ROTWEIGHT:
696
return EXPP_setFloatClamped( value, &con->orientweight, 0.01f, 1.0 );
697
case EXPP_CONSTR_ROTATE:
698
return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_ROT, 'h' );
699
case EXPP_CONSTR_USETIP:
700
return EXPP_setBitfield( value, &con->flag, CONSTRAINT_IK_TIP, 'h' );
702
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
706
static PyObject *action_getter( BPy_Constraint * self, int type )
708
bActionConstraint *con = (bActionConstraint *)(self->con->data);
711
case EXPP_CONSTR_TARGET:
712
return Object_CreatePyObject( con->tar );
713
case EXPP_CONSTR_BONE:
714
return PyString_FromString( con->subtarget );
715
case EXPP_CONSTR_ACTION:
716
return Action_CreatePyObject( con->act );
717
case EXPP_CONSTR_START:
718
return PyInt_FromLong( (long)con->start );
719
case EXPP_CONSTR_END:
720
return PyInt_FromLong( (long)con->end );
721
case EXPP_CONSTR_MIN:
722
return PyFloat_FromDouble( (double)con->min );
723
case EXPP_CONSTR_MAX:
724
return PyFloat_FromDouble( (double)con->max );
725
case EXPP_CONSTR_KEYON:
726
return PyInt_FromLong( (long)con->type );
728
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
732
static int action_setter( BPy_Constraint *self, int type, PyObject *value )
734
bActionConstraint *con = (bActionConstraint *)(self->con->data);
737
case EXPP_CONSTR_TARGET: {
738
Object *obj = (( BPy_Object * )value)->object;
739
if( !BPy_Object_Check( value ) )
740
return EXPP_ReturnIntError( PyExc_TypeError,
741
"expected BPy object argument" );
745
case EXPP_CONSTR_BONE: {
746
char *name = PyString_AsString( value );
748
return EXPP_ReturnIntError( PyExc_TypeError,
749
"expected string arg" );
751
BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
755
case EXPP_CONSTR_ACTION: {
756
bAction *act = (( BPy_Action * )value)->action;
757
if( !BPy_Action_Check( value ) )
758
return EXPP_ReturnIntError( PyExc_TypeError,
759
"expected BPy action argument" );
763
case EXPP_CONSTR_START:
764
return EXPP_setIValueClamped( value, &con->start, 1, MAXFRAME, 'h' );
765
case EXPP_CONSTR_END:
766
return EXPP_setIValueClamped( value, &con->end, 1, MAXFRAME, 'h' );
767
case EXPP_CONSTR_MIN:
769
return EXPP_setFloatClamped( value, &con->min, -180.0, 180.0 );
770
else if (con->type < 20)
771
return EXPP_setFloatClamped( value, &con->min, 0.0001, 1000.0 );
773
return EXPP_setFloatClamped( value, &con->min, -1000.0, 1000.0 );
774
case EXPP_CONSTR_MAX:
776
return EXPP_setFloatClamped( value, &con->max, -180.0, 180.0 );
777
else if (con->type < 20)
778
return EXPP_setFloatClamped( value, &con->max, 0.0001, 1000.0 );
780
return EXPP_setFloatClamped( value, &con->max, -1000.0, 1000.0 );
781
case EXPP_CONSTR_KEYON:
782
return EXPP_setIValueRange( value, &con->type,
783
EXPP_CONSTR_XROT, EXPP_CONSTR_ZLOC, 'h' );
785
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
789
static PyObject *trackto_getter( BPy_Constraint * self, int type )
791
bTrackToConstraint *con = (bTrackToConstraint *)(self->con->data);
794
case EXPP_CONSTR_TARGET:
795
return Object_CreatePyObject( con->tar );
796
case EXPP_CONSTR_BONE:
797
return PyString_FromString( con->subtarget );
798
case EXPP_CONSTR_TRACK:
799
return PyInt_FromLong( (long)con->reserved1 );
801
return PyInt_FromLong( (long)con->reserved2 );
803
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
807
static int trackto_setter( BPy_Constraint *self, int type, PyObject *value )
809
bTrackToConstraint *con = (bTrackToConstraint *)(self->con->data);
812
case EXPP_CONSTR_TARGET: {
813
Object *obj = (( BPy_Object * )value)->object;
814
if( !BPy_Object_Check( value ) )
815
return EXPP_ReturnIntError( PyExc_TypeError,
816
"expected BPy object argument" );
820
case EXPP_CONSTR_BONE: {
821
char *name = PyString_AsString( value );
823
return EXPP_ReturnIntError( PyExc_TypeError,
824
"expected string arg" );
826
BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
830
case EXPP_CONSTR_TRACK:
831
return EXPP_setIValueRange( value, &con->reserved1,
832
TRACK_X, TRACK_nZ, 'i' );
834
return EXPP_setIValueRange( value, &con->reserved2,
837
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
841
static PyObject *stretchto_getter( BPy_Constraint * self, int type )
843
bStretchToConstraint *con = (bStretchToConstraint *)(self->con->data);
846
case EXPP_CONSTR_TARGET:
847
return Object_CreatePyObject( con->tar );
848
case EXPP_CONSTR_BONE:
849
return PyString_FromString( con->subtarget );
850
case EXPP_CONSTR_RESTLENGTH:
851
return PyFloat_FromDouble( (double)con->orglength );
852
case EXPP_CONSTR_VOLVARIATION:
853
return PyFloat_FromDouble( (double)con->bulge );
854
case EXPP_CONSTR_VOLUMEMODE:
855
return PyInt_FromLong( (long)con->volmode );
856
case EXPP_CONSTR_PLANE:
857
return PyInt_FromLong( (long)con->plane );
859
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
863
static int stretchto_setter( BPy_Constraint *self, int type, PyObject *value )
865
bStretchToConstraint *con = (bStretchToConstraint *)(self->con->data);
868
case EXPP_CONSTR_TARGET: {
869
Object *obj = (( BPy_Object * )value)->object;
870
if( !BPy_Object_Check( value ) )
871
return EXPP_ReturnIntError( PyExc_TypeError,
872
"expected BPy object argument" );
876
case EXPP_CONSTR_BONE: {
877
char *name = PyString_AsString( value );
879
return EXPP_ReturnIntError( PyExc_TypeError,
880
"expected string arg" );
882
BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
886
case EXPP_CONSTR_RESTLENGTH:
887
return EXPP_setFloatClamped( value, &con->orglength, 0.0, 100.0 );
888
case EXPP_CONSTR_VOLVARIATION:
889
return EXPP_setFloatClamped( value, &con->bulge, 0.0, 100.0 );
890
case EXPP_CONSTR_VOLUMEMODE:
891
return EXPP_setIValueRange( value, &con->volmode,
892
VOLUME_XZ, NO_VOLUME, 'h' );
893
case EXPP_CONSTR_PLANE: {
894
int status, oldcode = con->plane;
895
status = EXPP_setIValueRange( value, &con->plane,
896
PLANE_X, PLANE_Z, 'h' );
897
if( !status && con->plane == PLANE_Y ) {
898
con->plane = oldcode;
899
return EXPP_ReturnIntError( PyExc_ValueError,
900
"value must be either PLANEX or PLANEZ" );
905
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
909
static PyObject *distlimit_getter( BPy_Constraint * self, int type )
911
bDistLimitConstraint *con = (bDistLimitConstraint *)(self->con->data);
914
case EXPP_CONSTR_TARGET:
915
return Object_CreatePyObject( con->tar );
916
case EXPP_CONSTR_BONE:
917
return PyString_FromString( con->subtarget );
918
case EXPP_CONSTR_RESTLENGTH:
919
return PyFloat_FromDouble( (double)con->dist );
920
case EXPP_CONSTR_MODE:
921
return PyInt_FromLong( (long)con->mode );
923
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
927
static int distlimit_setter( BPy_Constraint *self, int type, PyObject *value )
929
bDistLimitConstraint *con = (bDistLimitConstraint *)(self->con->data);
932
case EXPP_CONSTR_TARGET: {
933
Object *obj = (( BPy_Object * )value)->object;
934
if( !BPy_Object_Check( value ) )
935
return EXPP_ReturnIntError( PyExc_TypeError,
936
"expected BPy object argument" );
940
case EXPP_CONSTR_BONE: {
941
char *name = PyString_AsString( value );
943
return EXPP_ReturnIntError( PyExc_TypeError,
944
"expected string arg" );
946
BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
950
case EXPP_CONSTR_RESTLENGTH:
951
return EXPP_setFloatClamped( value, &con->dist, 0.0, 100.0 );
952
case EXPP_CONSTR_MODE:
953
return EXPP_setIValueRange( value, &con->mode, LIMITDIST_INSIDE, LIMITDIST_ONSURFACE, 'i' );
955
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
959
static PyObject *followpath_getter( BPy_Constraint * self, int type )
961
bFollowPathConstraint *con = (bFollowPathConstraint *)(self->con->data);
964
case EXPP_CONSTR_TARGET:
965
return Object_CreatePyObject( con->tar );
966
case EXPP_CONSTR_FOLLOW:
967
return PyBool_FromLong( (long)( con->followflag & SELECT ) );
968
case EXPP_CONSTR_OFFSET:
969
return PyFloat_FromDouble( (double)con->offset );
970
case EXPP_CONSTR_FORWARD:
971
return PyInt_FromLong( (long)con->trackflag );
973
return PyInt_FromLong( (long)con->upflag );
975
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
979
static int followpath_setter( BPy_Constraint *self, int type, PyObject *value )
981
bFollowPathConstraint *con = (bFollowPathConstraint *)(self->con->data);
984
case EXPP_CONSTR_TARGET: {
985
Object *obj = (( BPy_Object * )value)->object;
986
if( !BPy_Object_Check( value ) )
987
return EXPP_ReturnIntError( PyExc_TypeError,
988
"expected BPy object argument" );
992
case EXPP_CONSTR_FOLLOW:
993
return EXPP_setBitfield( value, &con->followflag, SELECT, 'i' );
994
case EXPP_CONSTR_OFFSET:
995
return EXPP_setFloatClamped( value, &con->offset,
996
-MAXFRAMEF, MAXFRAMEF );
997
case EXPP_CONSTR_FORWARD:
998
return EXPP_setIValueRange( value, &con->trackflag,
999
TRACK_X, TRACK_nZ, 'i' );
1000
case EXPP_CONSTR_UP:
1001
return EXPP_setIValueRange( value, &con->upflag,
1004
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1008
static PyObject *clampto_getter( BPy_Constraint * self, int type )
1010
bClampToConstraint *con = (bClampToConstraint *)(self->con->data);
1013
case EXPP_CONSTR_TARGET:
1014
return Object_CreatePyObject( con->tar );
1015
case EXPP_CONSTR_CLAMP:
1016
return PyInt_FromLong( (long)con->flag );
1017
case EXPP_CONSTR_CLAMPCYCLIC:
1018
return PyBool_FromLong( (long)(con->flag2 & CLAMPTO_CYCLIC) );
1020
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1024
static int clampto_setter( BPy_Constraint *self, int type, PyObject *value )
1026
bClampToConstraint *con = (bClampToConstraint *)(self->con->data);
1029
case EXPP_CONSTR_TARGET: {
1030
Object *obj = (( BPy_Object * )value)->object;
1031
if( !BPy_Object_Check( value ) )
1032
return EXPP_ReturnIntError( PyExc_TypeError,
1033
"expected BPy object argument" );
1037
case EXPP_CONSTR_CLAMP:
1038
return EXPP_setIValueRange( value, &con->flag,
1039
CLAMPTO_AUTO, CLAMPTO_Z, 'i' );
1040
case EXPP_CONSTR_CLAMPCYCLIC:
1041
return EXPP_setBitfield( value, &con->flag2, CLAMPTO_CYCLIC, 'i' );
1043
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1046
static PyObject *locktrack_getter( BPy_Constraint * self, int type )
1048
bLockTrackConstraint *con = (bLockTrackConstraint *)(self->con->data);
1051
case EXPP_CONSTR_TARGET:
1052
return Object_CreatePyObject( con->tar );
1053
case EXPP_CONSTR_BONE:
1054
return PyString_FromString( con->subtarget );
1055
case EXPP_CONSTR_TRACK:
1056
return PyInt_FromLong( (long)con->trackflag );
1057
case EXPP_CONSTR_LOCK:
1058
return PyInt_FromLong( (long)con->lockflag );
1060
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1064
static int locktrack_setter( BPy_Constraint *self, int type, PyObject *value )
1066
bLockTrackConstraint *con = (bLockTrackConstraint *)(self->con->data);
1069
case EXPP_CONSTR_TARGET: {
1070
Object *obj = (( BPy_Object * )value)->object;
1071
if( !BPy_Object_Check( value ) )
1072
return EXPP_ReturnIntError( PyExc_TypeError,
1073
"expected BPy object argument" );
1077
case EXPP_CONSTR_BONE: {
1078
char *name = PyString_AsString( value );
1080
return EXPP_ReturnIntError( PyExc_TypeError,
1081
"expected string arg" );
1083
BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1087
case EXPP_CONSTR_TRACK:
1088
return EXPP_setIValueRange( value, &con->trackflag,
1089
TRACK_X, TRACK_nZ, 'i' );
1090
case EXPP_CONSTR_LOCK:
1091
return EXPP_setIValueRange( value, &con->lockflag,
1092
LOCK_X, LOCK_Z, 'i' );
1094
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1098
static PyObject *floor_getter( BPy_Constraint * self, int type )
1100
bMinMaxConstraint *con = (bMinMaxConstraint *)(self->con->data);
1103
case EXPP_CONSTR_TARGET:
1104
return Object_CreatePyObject( con->tar );
1105
case EXPP_CONSTR_BONE:
1106
return PyString_FromString( con->subtarget );
1107
case EXPP_CONSTR_MINMAX:
1108
return PyInt_FromLong( (long)con->minmaxflag );
1109
case EXPP_CONSTR_OFFSET:
1110
return PyFloat_FromDouble( (double)con->offset );
1111
case EXPP_CONSTR_STICKY:
1112
return PyBool_FromLong( (long)( con->flag & MINMAX_STICKY ) ) ;
1114
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1118
static int floor_setter( BPy_Constraint *self, int type, PyObject *value )
1120
bMinMaxConstraint *con = (bMinMaxConstraint *)(self->con->data);
1123
case EXPP_CONSTR_TARGET: {
1124
Object *obj = (( BPy_Object * )value)->object;
1125
if( !BPy_Object_Check( value ) )
1126
return EXPP_ReturnIntError( PyExc_TypeError,
1127
"expected BPy object argument" );
1131
case EXPP_CONSTR_BONE: {
1132
char *name = PyString_AsString( value );
1134
return EXPP_ReturnIntError( PyExc_TypeError,
1135
"expected string arg" );
1137
BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1141
case EXPP_CONSTR_MINMAX:
1142
return EXPP_setIValueRange( value, &con->minmaxflag,
1143
EXPP_CONSTR_MAXX, EXPP_CONSTR_MINZ, 'i' );
1144
case EXPP_CONSTR_OFFSET:
1145
return EXPP_setFloatClamped( value, &con->offset, -100.0, 100.0 );
1146
case EXPP_CONSTR_STICKY:
1147
return EXPP_setBitfield( value, &con->flag, MINMAX_STICKY, 'h' );
1149
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1153
static PyObject *locatelike_getter( BPy_Constraint * self, int type )
1155
bLocateLikeConstraint *con = (bLocateLikeConstraint *)(self->con->data);
1158
case EXPP_CONSTR_TARGET:
1159
return Object_CreatePyObject( con->tar );
1160
case EXPP_CONSTR_BONE:
1161
return PyString_FromString( con->subtarget );
1162
case EXPP_CONSTR_COPY:
1163
return PyInt_FromLong( (long)con->flag );
1165
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1169
static int locatelike_setter( BPy_Constraint *self, int type, PyObject *value )
1171
bLocateLikeConstraint *con = (bLocateLikeConstraint *)(self->con->data);
1174
case EXPP_CONSTR_TARGET: {
1175
Object *obj = (( BPy_Object * )value)->object;
1176
if( !BPy_Object_Check( value ) )
1177
return EXPP_ReturnIntError( PyExc_TypeError,
1178
"expected BPy object argument" );
1182
case EXPP_CONSTR_BONE: {
1183
char *name = PyString_AsString( value );
1185
return EXPP_ReturnIntError( PyExc_TypeError,
1186
"expected string arg" );
1188
BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1192
case EXPP_CONSTR_COPY:
1193
return EXPP_setIValueRange( value, &con->flag,
1194
0, LOCLIKE_X | LOCLIKE_Y | LOCLIKE_Z | LOCLIKE_X_INVERT | LOCLIKE_Y_INVERT | LOCLIKE_Z_INVERT, 'i' );
1196
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1200
static PyObject *rotatelike_getter( BPy_Constraint * self, int type )
1202
bRotateLikeConstraint *con = (bRotateLikeConstraint *)(self->con->data);
1205
case EXPP_CONSTR_TARGET:
1206
return Object_CreatePyObject( con->tar );
1207
case EXPP_CONSTR_BONE:
1208
return PyString_FromString( con->subtarget );
1209
case EXPP_CONSTR_COPY:
1210
return PyInt_FromLong( (long)con->flag );
1212
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1216
static int rotatelike_setter( BPy_Constraint *self, int type, PyObject *value )
1218
bRotateLikeConstraint *con = (bRotateLikeConstraint *)(self->con->data);
1221
case EXPP_CONSTR_TARGET: {
1222
Object *obj = (( BPy_Object * )value)->object;
1223
if( !BPy_Object_Check( value ) )
1224
return EXPP_ReturnIntError( PyExc_TypeError,
1225
"expected BPy object argument" );
1229
case EXPP_CONSTR_BONE: {
1230
char *name = PyString_AsString( value );
1232
return EXPP_ReturnIntError( PyExc_TypeError,
1233
"expected string arg" );
1235
BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1239
case EXPP_CONSTR_COPY:
1240
return EXPP_setIValueRange( value, &con->flag,
1241
0, ROTLIKE_X | ROTLIKE_Y | ROTLIKE_Z | ROTLIKE_X_INVERT | ROTLIKE_Y_INVERT | ROTLIKE_Z_INVERT, 'i' );
1243
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1247
static PyObject *sizelike_getter( BPy_Constraint * self, int type )
1249
bSizeLikeConstraint *con = (bSizeLikeConstraint *)(self->con->data);
1252
case EXPP_CONSTR_TARGET:
1253
return Object_CreatePyObject( con->tar );
1254
case EXPP_CONSTR_BONE:
1255
return PyString_FromString( con->subtarget );
1256
case EXPP_CONSTR_COPY:
1257
return PyInt_FromLong( (long)con->flag );
1259
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1263
static int sizelike_setter( BPy_Constraint *self, int type, PyObject *value )
1265
bSizeLikeConstraint *con = (bSizeLikeConstraint *)(self->con->data);
1268
case EXPP_CONSTR_TARGET: {
1269
Object *obj = (( BPy_Object * )value)->object;
1270
if( !BPy_Object_Check( value ) )
1271
return EXPP_ReturnIntError( PyExc_TypeError,
1272
"expected BPy object argument" );
1276
case EXPP_CONSTR_BONE: {
1277
char *name = PyString_AsString( value );
1279
return EXPP_ReturnIntError( PyExc_TypeError,
1280
"expected string arg" );
1282
BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1286
case EXPP_CONSTR_COPY:
1287
return EXPP_setIValueRange( value, &con->flag,
1288
0, SIZELIKE_X | SIZELIKE_Y | SIZELIKE_Z, 'i' );
1290
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1294
static PyObject *loclimit_getter( BPy_Constraint * self, int type)
1296
bLocLimitConstraint *con = (bLocLimitConstraint *)(self->con->data);
1299
case EXPP_CONSTR_LIMIT:
1300
return PyInt_FromLong( (long)con->flag );
1301
case EXPP_CONSTR_XMIN:
1302
return PyFloat_FromDouble( (double)con->xmin );
1303
case EXPP_CONSTR_XMAX:
1304
return PyFloat_FromDouble( (double)con->xmax );
1305
case EXPP_CONSTR_YMIN:
1306
return PyFloat_FromDouble( (double)con->ymin );
1307
case EXPP_CONSTR_YMAX:
1308
return PyFloat_FromDouble( (double)con->ymax );
1309
case EXPP_CONSTR_ZMIN:
1310
return PyFloat_FromDouble( (double)con->zmin );
1311
case EXPP_CONSTR_ZMAX:
1312
return PyFloat_FromDouble( (double)con->zmax );
1314
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1318
static int loclimit_setter( BPy_Constraint *self, int type, PyObject *value )
1320
bLocLimitConstraint *con = (bLocLimitConstraint *)(self->con->data);
1323
case EXPP_CONSTR_LIMIT:
1324
return EXPP_setIValueRange( value, &con->flag, 0,
1325
LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX , 'i' );
1326
case EXPP_CONSTR_XMIN:
1327
return EXPP_setFloatClamped( value, &con->xmin, -1000.0, 1000.0 );
1328
case EXPP_CONSTR_XMAX:
1329
return EXPP_setFloatClamped( value, &con->xmax, -1000.0, 1000.0 );
1330
case EXPP_CONSTR_YMIN:
1331
return EXPP_setFloatClamped( value, &con->ymin, -1000.0, 1000.0 );
1332
case EXPP_CONSTR_YMAX:
1333
return EXPP_setFloatClamped( value, &con->ymax, -1000.0, 1000.0 );
1334
case EXPP_CONSTR_ZMIN:
1335
return EXPP_setFloatClamped( value, &con->zmin, -1000.0, 1000.0 );
1336
case EXPP_CONSTR_ZMAX:
1337
return EXPP_setFloatClamped( value, &con->zmax, -1000.0, 1000.0 );
1339
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1343
static PyObject *rotlimit_getter( BPy_Constraint * self, int type )
1345
bRotLimitConstraint *con = (bRotLimitConstraint *)(self->con->data);
1348
case EXPP_CONSTR_LIMIT:
1349
return PyInt_FromLong( (long)con->flag );
1350
case EXPP_CONSTR_XMIN:
1351
return PyFloat_FromDouble( (double)con->xmin );
1352
case EXPP_CONSTR_XMAX:
1353
return PyFloat_FromDouble( (double)con->xmax );
1354
case EXPP_CONSTR_YMIN:
1355
return PyFloat_FromDouble( (double)con->ymin );
1356
case EXPP_CONSTR_YMAX:
1357
return PyFloat_FromDouble( (double)con->ymax );
1358
case EXPP_CONSTR_ZMIN:
1359
return PyFloat_FromDouble( (double)con->zmin );
1360
case EXPP_CONSTR_ZMAX:
1361
return PyFloat_FromDouble( (double)con->zmax );
1363
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1367
static int rotlimit_setter( BPy_Constraint *self, int type, PyObject *value )
1369
bRotLimitConstraint *con = (bRotLimitConstraint *)(self->con->data);
1372
case EXPP_CONSTR_LIMIT:
1373
return EXPP_setIValueRange( value, &con->flag, 0,
1374
LIMIT_XROT | LIMIT_YROT | LIMIT_ZROT, 'i' );
1375
case EXPP_CONSTR_XMIN:
1376
return EXPP_setFloatClamped( value, &con->xmin, -360.0, 360.0 );
1377
case EXPP_CONSTR_XMAX:
1378
return EXPP_setFloatClamped( value, &con->xmax, -360.0, 360.0 );
1379
case EXPP_CONSTR_YMIN:
1380
return EXPP_setFloatClamped( value, &con->ymin, -360.0, 360.0 );
1381
case EXPP_CONSTR_YMAX:
1382
return EXPP_setFloatClamped( value, &con->ymax, -360.0, 360.0 );
1383
case EXPP_CONSTR_ZMIN:
1384
return EXPP_setFloatClamped( value, &con->zmin, -360.0, 360.0 );
1385
case EXPP_CONSTR_ZMAX:
1386
return EXPP_setFloatClamped( value, &con->zmax, -360.0, 360.0 );
1388
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1392
static PyObject *sizelimit_getter( BPy_Constraint * self, int type)
1394
bSizeLimitConstraint *con = (bSizeLimitConstraint *)(self->con->data);
1397
case EXPP_CONSTR_LIMIT:
1398
return PyInt_FromLong( (long)con->flag );
1399
case EXPP_CONSTR_XMIN:
1400
return PyFloat_FromDouble( (double)con->xmin );
1401
case EXPP_CONSTR_XMAX:
1402
return PyFloat_FromDouble( (double)con->xmax );
1403
case EXPP_CONSTR_YMIN:
1404
return PyFloat_FromDouble( (double)con->ymin );
1405
case EXPP_CONSTR_YMAX:
1406
return PyFloat_FromDouble( (double)con->ymax );
1407
case EXPP_CONSTR_ZMIN:
1408
return PyFloat_FromDouble( (double)con->zmin );
1409
case EXPP_CONSTR_ZMAX:
1410
return PyFloat_FromDouble( (double)con->zmax );
1412
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1416
static int sizelimit_setter( BPy_Constraint *self, int type, PyObject *value )
1418
bSizeLimitConstraint *con = (bSizeLimitConstraint *)(self->con->data);
1421
case EXPP_CONSTR_LIMIT:
1422
return EXPP_setIValueRange( value, &con->flag, 0,
1423
LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX, 'i' );
1424
case EXPP_CONSTR_XMIN:
1425
return EXPP_setFloatClamped( value, &con->xmin, -1000.0, 1000.0 );
1426
case EXPP_CONSTR_XMAX:
1427
return EXPP_setFloatClamped( value, &con->xmax, -1000.0, 1000.0 );
1428
case EXPP_CONSTR_YMIN:
1429
return EXPP_setFloatClamped( value, &con->ymin, -1000.0, 1000.0 );
1430
case EXPP_CONSTR_YMAX:
1431
return EXPP_setFloatClamped( value, &con->ymax, -1000.0, 1000.0 );
1432
case EXPP_CONSTR_ZMIN:
1433
return EXPP_setFloatClamped( value, &con->zmin, -1000.0, 1000.0 );
1434
case EXPP_CONSTR_ZMAX:
1435
return EXPP_setFloatClamped( value, &con->zmax, -1000.0, 1000.0 );
1437
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1441
static PyObject *script_getter( BPy_Constraint * self, int type )
1443
bPythonConstraint *con = (bPythonConstraint *)(self->con->data);
1446
case EXPP_CONSTR_TARGET:
1447
case EXPP_CONSTR_BONE:
1449
bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_PYTHON);
1450
bConstraintTarget *ct;
1451
PyObject *tlist=NULL, *val;
1454
/* change space of targets */
1455
if (cti->get_constraint_targets) {
1456
ListBase targets = {NULL, NULL};
1457
int num_tars=0, i=0;
1459
/* get targets, and create py-list for use temporarily */
1460
num_tars= cti->get_constraint_targets(self->con, &targets);
1462
tlist= PyList_New(num_tars);
1464
for (ct=targets.first; ct; ct=ct->next, i++) {
1465
if (type == EXPP_CONSTR_BONE)
1466
val= PyString_FromString(ct->subtarget);
1468
val= Object_CreatePyObject(ct->tar);
1469
PyList_SET_ITEM(tlist, i, val);
1473
if (cti->flush_constraint_targets)
1474
cti->flush_constraint_targets(self->con, &targets, 1);
1480
case EXPP_CONSTR_SCRIPT:
1481
return Text_CreatePyObject( con->text );
1482
case EXPP_CONSTR_PROPS:
1483
return BPy_Wrap_IDProperty( NULL, con->prop, NULL);
1485
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1489
static int script_setter( BPy_Constraint *self, int type, PyObject *value )
1491
bPythonConstraint *con = (bPythonConstraint *)(self->con->data);
1494
case EXPP_CONSTR_TARGET:
1495
case EXPP_CONSTR_BONE:
1497
bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_PYTHON);
1498
bConstraintTarget *ct;
1502
/* change space of targets */
1503
if (cti->get_constraint_targets) {
1504
ListBase targets = {NULL, NULL};
1505
int num_tars=0, i=0;
1507
/* get targets, and extract values from the given list */
1508
num_tars= cti->get_constraint_targets(self->con, &targets);
1510
if ((PySequence_Check(value) == 0) || (PySequence_Size(value) != num_tars)) {
1512
sprintf(errorstr, "expected sequence of %d integer(s)", num_tars);
1513
return EXPP_ReturnIntError(PyExc_TypeError, errorstr);
1516
for (ct=targets.first; ct; ct=ct->next, i++) {
1517
PyObject *val= PySequence_ITEM(value, i);
1519
if (type == EXPP_CONSTR_BONE) {
1520
char *name = PyString_AsString(val);
1523
// hrm... should we break here instead?
1524
ok = EXPP_ReturnIntError(PyExc_TypeError,
1525
"expected string arg as member of list");
1531
BLI_strncpy(ct->subtarget, name, sizeof(ct->subtarget));
1534
Object *obj = (( BPy_Object * )val)->object;
1536
if ( !BPy_Object_Check(value) ) {
1537
// hrm... should we break here instead?
1538
ok = EXPP_ReturnIntError(PyExc_TypeError,
1539
"expected BPy object argument as member of list");
1552
/* only flush changes to real constraints if all were successful */
1553
if ((cti->flush_constraint_targets) && (ok == 0))
1554
cti->flush_constraint_targets(self->con, &targets, 0);
1561
case EXPP_CONSTR_SCRIPT: {
1562
Text *text = (( BPy_Text * )value)->text;
1563
if( !BPy_Object_Check( value ) )
1564
return EXPP_ReturnIntError( PyExc_TypeError,
1565
"expected BPy text argument" );
1569
case EXPP_CONSTR_PROPS:
1570
return EXPP_ReturnIntError( PyExc_RuntimeError,
1571
"setting ID-Properties of PyConstraints this way is not supported" );
1573
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1578
static PyObject *rigidbody_getter( BPy_Constraint * self, int type)
1580
bRigidBodyJointConstraint *con = (bRigidBodyJointConstraint *)(self->con->data);
1583
case EXPP_CONSTR_TARGET:
1584
return Object_CreatePyObject( con->tar );
1585
case EXPP_CONSTR_RB_PIVX:
1586
return PyFloat_FromDouble( (double)con->pivX );
1587
case EXPP_CONSTR_RB_PIVY:
1588
return PyFloat_FromDouble( (double)con->pivY );
1589
case EXPP_CONSTR_RB_PIVZ:
1590
return PyFloat_FromDouble( (double)con->pivZ );
1591
case EXPP_CONSTR_RB_AXX:
1592
return PyFloat_FromDouble( (double)con->axX );
1593
case EXPP_CONSTR_RB_AXY:
1594
return PyFloat_FromDouble( (double)con->axY );
1595
case EXPP_CONSTR_RB_AXZ:
1596
return PyFloat_FromDouble( (double)con->axZ );
1597
case EXPP_CONSTR_RB_MINLIMIT0:
1598
return PyFloat_FromDouble( (double)con->minLimit[0] );
1599
case EXPP_CONSTR_RB_MINLIMIT1:
1600
return PyFloat_FromDouble( (double)con->minLimit[1] );
1601
case EXPP_CONSTR_RB_MINLIMIT2:
1602
return PyFloat_FromDouble( (double)con->minLimit[2] );
1603
case EXPP_CONSTR_RB_MINLIMIT3:
1604
return PyFloat_FromDouble( (double)con->minLimit[3] );
1605
case EXPP_CONSTR_RB_MINLIMIT4:
1606
return PyFloat_FromDouble( (double)con->minLimit[4] );
1607
case EXPP_CONSTR_RB_MINLIMIT5:
1608
return PyFloat_FromDouble( (double)con->minLimit[5] );
1609
case EXPP_CONSTR_RB_MAXLIMIT0:
1610
return PyFloat_FromDouble( (double)con->maxLimit[0] );
1611
case EXPP_CONSTR_RB_MAXLIMIT1:
1612
return PyFloat_FromDouble( (double)con->maxLimit[1] );
1613
case EXPP_CONSTR_RB_MAXLIMIT2:
1614
return PyFloat_FromDouble( (double)con->maxLimit[2] );
1615
case EXPP_CONSTR_RB_MAXLIMIT3:
1616
return PyFloat_FromDouble( (double)con->maxLimit[3] );
1617
case EXPP_CONSTR_RB_MAXLIMIT4:
1618
return PyFloat_FromDouble( (double)con->maxLimit[4] );
1619
case EXPP_CONSTR_RB_MAXLIMIT5:
1620
return PyFloat_FromDouble( (double)con->maxLimit[5] );
1621
case EXPP_CONSTR_RB_EXTRAFZ:
1622
return PyFloat_FromDouble( (double)con->extraFz );
1623
case EXPP_CONSTR_LIMIT:
1624
return PyInt_FromLong( (int)con->flag );
1626
case EXPP_CONSTR_RB_TYPE:
1627
return PyInt_FromLong( (int)con->type );
1629
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1634
static int rigidbody_setter( BPy_Constraint *self, int type, PyObject *value )
1636
bRigidBodyJointConstraint *con = (bRigidBodyJointConstraint *)(self->con->data);
1639
case EXPP_CONSTR_TARGET: {
1640
Object *obj = (( BPy_Object * )value)->object;
1641
if( !BPy_Object_Check( value ) )
1642
return EXPP_ReturnIntError( PyExc_TypeError,
1643
"expected BPy object argument" );
1647
case EXPP_CONSTR_RB_PIVX:
1648
return EXPP_setFloatClamped( value, &con->pivX , -1000.0, 1000.0 );
1649
case EXPP_CONSTR_RB_PIVY:
1650
return EXPP_setFloatClamped( value, &con->pivY , -1000.0, 1000.0 );
1651
case EXPP_CONSTR_RB_PIVZ:
1652
return EXPP_setFloatClamped( value, &con->pivZ , -1000.0, 1000.0 );
1653
case EXPP_CONSTR_RB_AXX:
1654
return EXPP_setFloatClamped( value, &con->axX , -1000.0, 1000.0 );
1655
case EXPP_CONSTR_RB_AXY:
1656
return EXPP_setFloatClamped( value, &con->axY , -1000.0, 1000.0 );
1657
case EXPP_CONSTR_RB_AXZ:
1658
return EXPP_setFloatClamped( value, &con->axZ , -1000.0, 1000.0 );
1659
case EXPP_CONSTR_RB_MINLIMIT0:
1660
return EXPP_setFloatClamped( value, &con->minLimit[0] , -1000.0, 1000.0 );
1661
case EXPP_CONSTR_RB_MINLIMIT1:
1662
return EXPP_setFloatClamped( value, &con->minLimit[1] , -1000.0, 1000.0 );
1663
case EXPP_CONSTR_RB_MINLIMIT2:
1664
return EXPP_setFloatClamped( value, &con->minLimit[2] , -1000.0, 1000.0 );
1665
case EXPP_CONSTR_RB_MINLIMIT3:
1666
return EXPP_setFloatClamped( value, &con->minLimit[3] , -1000.0, 1000.0 );
1667
case EXPP_CONSTR_RB_MINLIMIT4:
1668
return EXPP_setFloatClamped( value, &con->minLimit[4] , -1000.0, 1000.0 );
1669
case EXPP_CONSTR_RB_MINLIMIT5:
1670
return EXPP_setFloatClamped( value, &con->minLimit[5] , -1000.0, 1000.0 );
1671
case EXPP_CONSTR_RB_MAXLIMIT0:
1672
return EXPP_setFloatClamped( value, &con->maxLimit[0] , -1000.0, 1000.0 );
1673
case EXPP_CONSTR_RB_MAXLIMIT1:
1674
return EXPP_setFloatClamped( value, &con->maxLimit[1] , -1000.0, 1000.0 );
1675
case EXPP_CONSTR_RB_MAXLIMIT2:
1676
return EXPP_setFloatClamped( value, &con->maxLimit[2] , -1000.0, 1000.0 );
1677
case EXPP_CONSTR_RB_MAXLIMIT3:
1678
return EXPP_setFloatClamped( value, &con->maxLimit[3] , -1000.0, 1000.0 );
1679
case EXPP_CONSTR_RB_MAXLIMIT4:
1680
return EXPP_setFloatClamped( value, &con->maxLimit[4] , -1000.0, 1000.0 );
1681
case EXPP_CONSTR_RB_MAXLIMIT5:
1682
return EXPP_setFloatClamped( value, &con->maxLimit[5] , -1000.0, 1000.0 );
1683
case EXPP_CONSTR_RB_EXTRAFZ:
1684
return EXPP_setFloatClamped( value, &con->extraFz , -1000.0, 1000.0 );
1685
case EXPP_CONSTR_LIMIT:
1686
return EXPP_setIValueRange( value, &con->flag, 0,
1687
LIMIT_XMIN | LIMIT_XMAX | LIMIT_YMIN | LIMIT_YMAX | LIMIT_ZMIN | LIMIT_ZMAX, 'i' );
1688
case EXPP_CONSTR_RB_TYPE:
1689
return EXPP_setIValueRange( value, &con->type, 0,
1690
EXPP_CONSTR_RB_BALL | EXPP_CONSTR_RB_HINGE | EXPP_CONSTR_RB_GENERIC6DOF | EXPP_CONSTR_RB_VEHICLE, 'i' );
1692
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1696
static PyObject *childof_getter( BPy_Constraint * self, int type )
1698
bChildOfConstraint *con = (bChildOfConstraint *)(self->con->data);
1701
case EXPP_CONSTR_TARGET:
1702
return Object_CreatePyObject( con->tar );
1703
case EXPP_CONSTR_BONE:
1704
return PyString_FromString( con->subtarget );
1705
case EXPP_CONSTR_COPY:
1706
return PyInt_FromLong( (long)con->flag );
1708
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1712
static int childof_setter( BPy_Constraint *self, int type, PyObject *value )
1714
bChildOfConstraint *con = (bChildOfConstraint *)(self->con->data);
1717
case EXPP_CONSTR_TARGET: {
1718
Object *obj = (( BPy_Object * )value)->object;
1719
if( !BPy_Object_Check( value ) )
1720
return EXPP_ReturnIntError( PyExc_TypeError,
1721
"expected BPy object argument" );
1725
case EXPP_CONSTR_BONE: {
1726
char *name = PyString_AsString( value );
1728
return EXPP_ReturnIntError( PyExc_TypeError,
1729
"expected string arg" );
1731
BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1735
case EXPP_CONSTR_COPY:
1736
return EXPP_setIValueRange( value, &con->flag,
1737
0, CHILDOF_LOCX| CHILDOF_LOCY | CHILDOF_LOCZ | CHILDOF_ROTX | CHILDOF_ROTY | CHILDOF_ROTZ |
1738
CHILDOF_SIZEX |CHILDOF_SIZEY| CHILDOF_SIZEZ, 'i' );
1740
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1744
static PyObject *transf_getter( BPy_Constraint * self, int type )
1746
bTransformConstraint *con = (bTransformConstraint *)(self->con->data);
1749
case EXPP_CONSTR_TARGET:
1750
return Object_CreatePyObject( con->tar );
1751
case EXPP_CONSTR_BONE:
1752
return PyString_FromString( con->subtarget );
1753
case EXPP_CONSTR_FROM:
1754
return PyInt_FromLong( (long)con->from );
1755
case EXPP_CONSTR_TO:
1756
return PyInt_FromLong( (long)con->to );
1757
case EXPP_CONSTR_MAPX:
1758
return PyInt_FromLong( (long)con->map[0] );
1759
case EXPP_CONSTR_MAPY:
1760
return PyInt_FromLong( (long)con->map[1] );
1761
case EXPP_CONSTR_MAPZ:
1762
return PyInt_FromLong( (long)con->map[2] );
1763
case EXPP_CONSTR_FROMMINX:
1764
return PyFloat_FromDouble( (double)con->from_min[0] );
1765
case EXPP_CONSTR_FROMMAXX:
1766
return PyFloat_FromDouble( (double)con->from_max[0] );
1767
case EXPP_CONSTR_FROMMINY:
1768
return PyFloat_FromDouble( (double)con->from_min[1] );
1769
case EXPP_CONSTR_FROMMAXY:
1770
return PyFloat_FromDouble( (double)con->from_max[1] );
1771
case EXPP_CONSTR_FROMMINZ:
1772
return PyFloat_FromDouble( (double)con->from_min[2] );
1773
case EXPP_CONSTR_FROMMAXZ:
1774
return PyFloat_FromDouble( (double)con->from_max[2] );
1775
case EXPP_CONSTR_TOMINX:
1776
return PyFloat_FromDouble( (double)con->to_min[0] );
1777
case EXPP_CONSTR_TOMAXX:
1778
return PyFloat_FromDouble( (double)con->to_max[0] );
1779
case EXPP_CONSTR_TOMINY:
1780
return PyFloat_FromDouble( (double)con->to_min[1] );
1781
case EXPP_CONSTR_TOMAXY:
1782
return PyFloat_FromDouble( (double)con->to_max[1] );
1783
case EXPP_CONSTR_TOMINZ:
1784
return PyFloat_FromDouble( (double)con->to_min[2] );
1785
case EXPP_CONSTR_TOMAXZ:
1786
return PyFloat_FromDouble( (double)con->to_max[2] );
1787
case EXPP_CONSTR_EXPO:
1788
return PyBool_FromLong( (long)con->expo );
1790
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
1794
static int transf_setter( BPy_Constraint *self, int type, PyObject *value )
1796
bTransformConstraint *con = (bTransformConstraint *)(self->con->data);
1797
float fmin, fmax, tmin, tmax;
1799
if (con->from == 2) {
1803
else if (con->from == 1) {
1816
else if (con->to == 1) {
1826
case EXPP_CONSTR_TARGET: {
1827
Object *obj = (( BPy_Object * )value)->object;
1828
if( !BPy_Object_Check( value ) )
1829
return EXPP_ReturnIntError( PyExc_TypeError,
1830
"expected BPy object argument" );
1834
case EXPP_CONSTR_BONE: {
1835
char *name = PyString_AsString( value );
1837
return EXPP_ReturnIntError( PyExc_TypeError,
1838
"expected string arg" );
1840
BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
1844
case EXPP_CONSTR_FROM:
1845
return EXPP_setIValueClamped( value, &con->from, 0, 3, 'h' );
1846
case EXPP_CONSTR_TO:
1847
return EXPP_setIValueClamped( value, &con->to, 0, 3, 'h' );
1848
case EXPP_CONSTR_MAPX:
1849
return EXPP_setIValueClamped( value, &con->map[0], 0, 3, 'h' );
1850
case EXPP_CONSTR_MAPY:
1851
return EXPP_setIValueClamped( value, &con->map[1], 0, 3, 'h' );
1852
case EXPP_CONSTR_MAPZ:
1853
return EXPP_setIValueClamped( value, &con->map[2], 0, 3, 'h' );
1854
case EXPP_CONSTR_FROMMINX:
1855
return EXPP_setFloatClamped( value, &con->from_min[0], fmin, fmax );
1856
case EXPP_CONSTR_FROMMAXX:
1857
return EXPP_setFloatClamped( value, &con->from_max[0], fmin, fmax );
1858
case EXPP_CONSTR_FROMMINY:
1859
return EXPP_setFloatClamped( value, &con->from_min[1], fmin, fmax );
1860
case EXPP_CONSTR_FROMMAXY:
1861
return EXPP_setFloatClamped( value, &con->from_max[1], fmin, fmax );
1862
case EXPP_CONSTR_FROMMINZ:
1863
return EXPP_setFloatClamped( value, &con->from_min[2], fmin, fmax );
1864
case EXPP_CONSTR_FROMMAXZ:
1865
return EXPP_setFloatClamped( value, &con->from_max[2], fmin, fmax );
1866
case EXPP_CONSTR_TOMINX:
1867
return EXPP_setFloatClamped( value, &con->to_min[0], tmin, tmax );
1868
case EXPP_CONSTR_TOMAXX:
1869
return EXPP_setFloatClamped( value, &con->to_max[0], tmin, tmax );
1870
case EXPP_CONSTR_TOMINY:
1871
return EXPP_setFloatClamped( value, &con->to_min[1], tmin, tmax );
1872
case EXPP_CONSTR_TOMAXY:
1873
return EXPP_setFloatClamped( value, &con->to_max[1], tmin, tmax );
1874
case EXPP_CONSTR_TOMINZ:
1875
return EXPP_setFloatClamped( value, &con->to_min[2], tmin, tmax );
1876
case EXPP_CONSTR_TOMAXZ:
1877
return EXPP_setFloatClamped( value, &con->to_max[2], tmin, tmax );
1878
case EXPP_CONSTR_EXPO:
1879
return EXPP_setBitfield( value, &con->expo, 1, 'h' );
1881
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
1886
* get data from a constraint
1889
static PyObject *Constraint_getData( BPy_Constraint * self, PyObject * key )
1893
if( !PyInt_Check( key ) )
1894
return EXPP_ReturnPyObjError( PyExc_TypeError,
1895
"expected an int arg" );
1898
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
1899
"This constraint has been removed!" );
1901
setting = PyInt_AsLong( key );
1903
/* bypass doing settings of individual constraints, if we're just doing
1904
* constraint space access-stuff
1906
if ((setting==EXPP_CONSTR_OWNSPACE) || (setting==EXPP_CONSTR_TARSPACE)) {
1907
return constspace_getter( self, setting );
1909
switch( self->con->type ) {
1910
case CONSTRAINT_TYPE_NULL:
1912
case CONSTRAINT_TYPE_TRACKTO:
1913
return trackto_getter( self, setting );
1914
case CONSTRAINT_TYPE_KINEMATIC:
1915
return kinematic_getter( self, setting );
1916
case CONSTRAINT_TYPE_FOLLOWPATH:
1917
return followpath_getter( self, setting );
1918
case CONSTRAINT_TYPE_ACTION:
1919
return action_getter( self, setting );
1920
case CONSTRAINT_TYPE_LOCKTRACK:
1921
return locktrack_getter( self, setting );
1922
case CONSTRAINT_TYPE_STRETCHTO:
1923
return stretchto_getter( self, setting );
1924
case CONSTRAINT_TYPE_MINMAX:
1925
return floor_getter( self, setting );
1926
case CONSTRAINT_TYPE_LOCLIKE:
1927
return locatelike_getter( self, setting );
1928
case CONSTRAINT_TYPE_ROTLIKE:
1929
return rotatelike_getter( self, setting );
1930
case CONSTRAINT_TYPE_SIZELIKE:
1931
return sizelike_getter( self, setting );
1932
case CONSTRAINT_TYPE_ROTLIMIT:
1933
return rotlimit_getter( self, setting );
1934
case CONSTRAINT_TYPE_LOCLIMIT:
1935
return loclimit_getter( self, setting );
1936
case CONSTRAINT_TYPE_SIZELIMIT:
1937
return sizelimit_getter( self, setting );
1938
case CONSTRAINT_TYPE_DISTLIMIT:
1939
return distlimit_getter( self, setting );
1940
case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1941
return rigidbody_getter( self, setting );
1942
case CONSTRAINT_TYPE_CLAMPTO:
1943
return clampto_getter( self, setting );
1944
case CONSTRAINT_TYPE_PYTHON:
1945
return script_getter( self, setting );
1946
case CONSTRAINT_TYPE_CHILDOF:
1947
return childof_getter( self, setting );
1948
case CONSTRAINT_TYPE_TRANSFORM:
1949
return transf_getter( self, setting );
1951
return EXPP_ReturnPyObjError( PyExc_KeyError,
1952
"unknown constraint type" );
1956
static int Constraint_setData( BPy_Constraint * self, PyObject * key,
1959
int key_int, result;
1961
if( !PyNumber_Check( key ) )
1962
return EXPP_ReturnIntError( PyExc_TypeError,
1963
"expected an int arg" );
1965
return EXPP_ReturnIntError( PyExc_RuntimeError,
1966
"This constraint has been removed!" );
1968
key_int = PyInt_AsLong( key );
1970
/* bypass doing settings of individual constraints, if we're just doing
1971
* constraint space access-stuff
1973
if ((key_int==EXPP_CONSTR_OWNSPACE) || (key_int==EXPP_CONSTR_TARSPACE)) {
1974
result = constspace_setter( self, key_int, arg );
1977
switch( self->con->type ) {
1978
case CONSTRAINT_TYPE_KINEMATIC:
1979
result = kinematic_setter( self, key_int, arg );
1981
case CONSTRAINT_TYPE_ACTION:
1982
result = action_setter( self, key_int, arg );
1984
case CONSTRAINT_TYPE_TRACKTO:
1985
result = trackto_setter( self, key_int, arg );
1987
case CONSTRAINT_TYPE_STRETCHTO:
1988
result = stretchto_setter( self, key_int, arg );
1990
case CONSTRAINT_TYPE_FOLLOWPATH:
1991
result = followpath_setter( self, key_int, arg );
1993
case CONSTRAINT_TYPE_LOCKTRACK:
1994
result = locktrack_setter( self, key_int, arg );
1996
case CONSTRAINT_TYPE_MINMAX:
1997
result = floor_setter( self, key_int, arg );
1999
case CONSTRAINT_TYPE_LOCLIKE:
2000
result = locatelike_setter( self, key_int, arg );
2002
case CONSTRAINT_TYPE_ROTLIKE:
2003
result = rotatelike_setter( self, key_int, arg );
2005
case CONSTRAINT_TYPE_SIZELIKE:
2006
result = sizelike_setter( self, key_int, arg );
2008
case CONSTRAINT_TYPE_ROTLIMIT:
2009
result = rotlimit_setter( self, key_int, arg );
2011
case CONSTRAINT_TYPE_LOCLIMIT:
2012
result = loclimit_setter( self, key_int, arg );
2014
case CONSTRAINT_TYPE_SIZELIMIT:
2015
result = sizelimit_setter( self, key_int, arg);
2017
case CONSTRAINT_TYPE_DISTLIMIT:
2018
result = distlimit_setter( self, key_int, arg);
2020
case CONSTRAINT_TYPE_RIGIDBODYJOINT:
2021
result = rigidbody_setter( self, key_int, arg);
2023
case CONSTRAINT_TYPE_CLAMPTO:
2024
result = clampto_setter( self, key_int, arg);
2026
case CONSTRAINT_TYPE_PYTHON:
2027
result = script_setter( self, key_int, arg);
2029
case CONSTRAINT_TYPE_CHILDOF:
2030
result = childof_setter( self, key_int, arg);
2032
case CONSTRAINT_TYPE_TRANSFORM:
2033
result = transf_setter( self, key_int, arg);
2035
case CONSTRAINT_TYPE_NULL:
2036
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
2038
return EXPP_ReturnIntError( PyExc_RuntimeError,
2039
"unsupported constraint setting" );
2042
if( !result && self->pchan )
2043
update_pose_constraint_flags( self->obj->pose );
2047
/*****************************************************************************/
2048
/* Function: Constraint_compare */
2049
/* Description: This compares 2 constraint python types, == or != only. */
2050
/*****************************************************************************/
2051
static int Constraint_compare( BPy_Constraint * a, BPy_Constraint * b )
2053
return ( a->con == b->con ) ? 0 : -1;
2056
/*****************************************************************************/
2057
/* Function: Constraint_repr */
2058
/* Description: This is a callback function for the BPy_Constraint type. It */
2059
/* builds a meaningful string to represent constraint objects. */
2060
/*****************************************************************************/
2062
static PyObject *Constraint_repr( BPy_Constraint * self )
2064
bConstraintTypeInfo *cti;
2067
return PyString_FromString("[Constraint - Removed]");
2069
cti= constraint_get_typeinfo(self->con);
2072
return PyString_FromFormat("[Constraint \"%s\", Type \"%s\"]",
2073
self->con->name, cti->name);
2076
return PyString_FromString("[Constraint \"%s\", Type \"Unknown\"]");
2080
/* Three Python Constraint_Type helper functions needed by the Object module: */
2082
/*****************************************************************************/
2083
/* Function: Constraint_CreatePyObject */
2084
/* Description: This function will create a new BPy_Constraint from an */
2085
/* existing Blender constraint structure. */
2086
/*****************************************************************************/
2087
PyObject *Constraint_CreatePyObject( bPoseChannel *pchan, Object *obj,
2090
BPy_Constraint *pycon;
2091
pycon = ( BPy_Constraint * ) PyObject_NEW( BPy_Constraint,
2094
return EXPP_ReturnPyObjError( PyExc_MemoryError,
2095
"couldn't create BPy_Constraint object" );
2099
/* one of these two will be NULL */
2101
pycon->pchan = pchan;
2102
return ( PyObject * ) pycon;
2105
/*****************************************************************************/
2106
/* Function: Constraint_FromPyObject */
2107
/* Description: This function returns the Blender constraint from the given */
2109
/*****************************************************************************/
2110
bConstraint *Constraint_FromPyObject( BPy_Constraint * self )
2115
/*****************************************************************************/
2116
/* Constraint Sequence wrapper */
2117
/*****************************************************************************/
2120
* Initialize the interator
2123
static PyObject *ConstraintSeq_getIter( BPy_ConstraintSeq * self )
2126
self->iter = (bConstraint *)self->pchan->constraints.first;
2128
self->iter = (bConstraint *)self->obj->constraints.first;
2129
return EXPP_incr_ret ( (PyObject *) self );
2133
* Get the next Constraint
2136
static PyObject *ConstraintSeq_nextIter( BPy_ConstraintSeq * self )
2138
bConstraint *this = self->iter;
2140
self->iter = this->next;
2141
return Constraint_CreatePyObject( self->pchan, self->obj, this );
2144
return EXPP_ReturnPyObjError( PyExc_StopIteration,
2145
"iterator at end" );
2148
/* return the number of constraints */
2150
static int ConstraintSeq_length( BPy_ConstraintSeq * self )
2152
return BLI_countlist( self->pchan ?
2153
&self->pchan->constraints : &self->obj->constraints );
2156
/* return a constraint */
2158
static PyObject *ConstraintSeq_item( BPy_ConstraintSeq * self, int i )
2160
bConstraint *con = NULL;
2162
/* if index is negative, start counting from the end of the list */
2164
i += ConstraintSeq_length( self );
2166
/* skip through the list until we get the constraint or end of list */
2169
con = self->pchan->constraints.first;
2171
con = self->obj->constraints.first;
2179
return Constraint_CreatePyObject( self->pchan, self->obj, con );
2181
return EXPP_ReturnPyObjError( PyExc_IndexError,
2182
"array index out of range" );
2185
/*****************************************************************************/
2186
/* Python BPy_ConstraintSeq sequence table: */
2187
/*****************************************************************************/
2188
static PySequenceMethods ConstraintSeq_as_sequence = {
2189
( inquiry ) ConstraintSeq_length, /* sq_length */
2190
( binaryfunc ) 0, /* sq_concat */
2191
( intargfunc ) 0, /* sq_repeat */
2192
( intargfunc ) ConstraintSeq_item, /* sq_item */
2193
( intintargfunc ) 0, /* sq_slice */
2194
( intobjargproc ) 0, /* sq_ass_item */
2195
( intintobjargproc ) 0, /* sq_ass_slice */
2196
( objobjproc ) 0, /* sq_contains */
2197
( binaryfunc ) 0, /* sq_inplace_concat */
2198
( intargfunc ) 0, /* sq_inplace_repeat */
2202
* helper function to check for a valid constraint argument
2205
static bConstraint *locate_constr( BPy_ConstraintSeq *self, BPy_Constraint * value )
2209
/* check that argument is a modifier */
2210
if (!BPy_Constraint_Check(value))
2211
return (bConstraint *)EXPP_ReturnPyObjError( PyExc_TypeError,
2212
"expected a constraint as an argument" );
2214
/* check whether constraint has been removed */
2216
return (bConstraint *)EXPP_ReturnPyObjError( PyExc_RuntimeError,
2217
"This constraint has been removed!" );
2219
/* verify the constraint is still exists in the stack */
2221
con = self->pchan->constraints.first;
2223
con = self->obj->constraints.first;
2224
while( con && con != value->con )
2227
/* if we didn't find it, exception */
2229
return (bConstraint *)EXPP_ReturnPyObjError( PyExc_AttributeError,
2230
"This constraint is no longer in the object's stack" );
2236
/* create a new constraint at the end of the list */
2238
static PyObject *ConstraintSeq_append( BPy_ConstraintSeq *self, PyObject *value )
2240
int type = (int)PyInt_AsLong(value);
2243
/* type 0 is CONSTRAINT_TYPE_NULL, should we be able to add one of these?
2244
* if the value is not an int it will be -1 */
2245
if( type < CONSTRAINT_TYPE_NULL || type > CONSTRAINT_TYPE_RIGIDBODYJOINT )
2246
return EXPP_ReturnPyObjError( PyExc_ValueError,
2247
"arg not in int or out of range" );
2249
con = add_new_constraint( type );
2251
BLI_addtail( &self->pchan->constraints, con );
2252
update_pose_constraint_flags( self->obj->pose );
2255
BLI_addtail( &self->obj->constraints, con );
2257
return Constraint_CreatePyObject( self->pchan, self->obj, con );
2260
/* move the constraint up in the stack */
2262
static PyObject *ConstraintSeq_moveUp( BPy_ConstraintSeq *self, BPy_Constraint *value )
2264
bConstraint *con = locate_constr( self, value );
2266
/* if we can't locate the constraint, return (exception already set) */
2268
return (PyObject *)NULL;
2270
const_moveUp( self->obj, con );
2274
/* move the constraint down in the stack */
2276
static PyObject *ConstraintSeq_moveDown( BPy_ConstraintSeq *self, BPy_Constraint *value )
2278
bConstraint *con = locate_constr( self, value );
2280
/* if we can't locate the constraint, return (exception already set) */
2282
return (PyObject *)NULL;
2284
const_moveDown( self->obj, con );
2288
/* remove an existing constraint */
2290
static PyObject *ConstraintSeq_remove( BPy_ConstraintSeq *self, BPy_Constraint *value )
2292
bConstraint *con = locate_constr(self, value);
2293
bPoseChannel *active= NULL;
2295
/* if we can't locate the constraint, return (exception already set) */
2297
return (PyObject *)NULL;
2299
/* check if we need to set temporary 'active' flag for pchan */
2301
active= get_active_posechannel(self->obj);
2303
if (active != self->pchan) {
2304
if (active) active->bone->flag &= ~BONE_ACTIVE;
2305
self->pchan->bone->flag |= BONE_ACTIVE;
2309
/* del_constr_func() frees constraint + its data */
2310
del_constr_func( self->obj, con );
2312
/* reset active pchan (if applicable) */
2313
if (self->pchan && self->pchan!=active) {
2314
if (active) active->bone->flag |= BONE_ACTIVE;
2315
self->pchan->bone->flag &= ~BONE_ACTIVE;
2318
/* erase the link to the constraint */
2324
/*****************************************************************************/
2325
/* Function: ConstraintSeq_dealloc */
2326
/* Description: This is a callback function for the BPy_ConstraintSeq type. */
2327
/* It destroys data when the object is deleted. */
2328
/*****************************************************************************/
2329
static void ConstraintSeq_dealloc( BPy_Constraint * self )
2331
PyObject_DEL( self );
2334
/*****************************************************************************/
2335
/* Python BPy_ConstraintSeq methods table: */
2336
/*****************************************************************************/
2337
static PyMethodDef BPy_ConstraintSeq_methods[] = {
2338
/* name, method, flags, doc */
2339
{"append", ( PyCFunction ) ConstraintSeq_append, METH_O,
2340
"(type) - add a new constraint, where type is the constraint type"},
2341
{"remove", ( PyCFunction ) ConstraintSeq_remove, METH_O,
2342
"(con) - remove an existing constraint, where con is a constraint from this object."},
2343
{"moveUp", ( PyCFunction ) ConstraintSeq_moveUp, METH_O,
2344
"(con) - Move constraint up in stack"},
2345
{"moveDown", ( PyCFunction ) ConstraintSeq_moveDown, METH_O,
2346
"(con) - Move constraint down in stack"},
2347
{NULL, NULL, 0, NULL}
2350
/*****************************************************************************/
2351
/* Python ConstraintSeq_Type structure definition: */
2352
/*****************************************************************************/
2353
PyTypeObject ConstraintSeq_Type = {
2354
PyObject_HEAD_INIT( NULL ) /* required py macro */
2356
/* For printing, in format "<module>.<name>" */
2357
"Blender.Constraints", /* char *tp_name; */
2358
sizeof( BPy_ConstraintSeq ), /* int tp_basicsize; */
2359
0, /* tp_itemsize; For allocation */
2361
/* Methods to implement standard operations */
2363
( destructor ) ConstraintSeq_dealloc,/* destructor tp_dealloc; */
2364
NULL, /* printfunc tp_print; */
2365
NULL, /* getattrfunc tp_getattr; */
2366
NULL, /* setattrfunc tp_setattr; */
2367
NULL, /* cmpfunc tp_compare; */
2368
( reprfunc ) NULL, /* reprfunc tp_repr; */
2370
/* Method suites for standard classes */
2372
NULL, /* PyNumberMethods *tp_as_number; */
2373
&ConstraintSeq_as_sequence, /* PySequenceMethods *tp_as_sequence; */
2374
NULL, /* PyMappingMethods *tp_as_mapping; */
2376
/* More standard operations (here for binary compatibility) */
2378
NULL, /* hashfunc tp_hash; */
2379
NULL, /* ternaryfunc tp_call; */
2380
NULL, /* reprfunc tp_str; */
2381
NULL, /* getattrofunc tp_getattro; */
2382
NULL, /* setattrofunc tp_setattro; */
2384
/* Functions to access object as input/output buffer */
2385
NULL, /* PyBufferProcs *tp_as_buffer; */
2387
/*** Flags to define presence of optional/expanded features ***/
2388
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
2390
NULL, /* char *tp_doc; Documentation string */
2391
/*** Assigned meaning in release 2.0 ***/
2392
/* call function for all accessible objects */
2393
NULL, /* traverseproc tp_traverse; */
2395
/* delete references to contained objects */
2396
NULL, /* inquiry tp_clear; */
2398
/*** Assigned meaning in release 2.1 ***/
2399
/*** rich comparisons ***/
2400
NULL, /* richcmpfunc tp_richcompare; */
2402
/*** weak reference enabler ***/
2403
0, /* long tp_weaklistoffset; */
2405
/*** Added in release 2.2 ***/
2407
( getiterfunc )ConstraintSeq_getIter, /* getiterfunc tp_iter; */
2408
( iternextfunc )ConstraintSeq_nextIter, /* iternextfunc tp_iternext; */
2410
/*** Attribute descriptor and subclassing stuff ***/
2411
BPy_ConstraintSeq_methods, /* struct PyMethodDef *tp_methods; */
2412
NULL, /* struct PyMemberDef *tp_members; */
2413
NULL, /* struct PyGetSetDef *tp_getset; */
2414
NULL, /* struct _typeobject *tp_base; */
2415
NULL, /* PyObject *tp_dict; */
2416
NULL, /* descrgetfunc tp_descr_get; */
2417
NULL, /* descrsetfunc tp_descr_set; */
2418
0, /* long tp_dictoffset; */
2419
NULL, /* initproc tp_init; */
2420
NULL, /* allocfunc tp_alloc; */
2421
NULL, /* newfunc tp_new; */
2422
/* Low-level free-memory routine */
2423
NULL, /* freefunc tp_free; */
2424
/* For PyObject_IS_GC */
2425
NULL, /* inquiry tp_is_gc; */
2426
NULL, /* PyObject *tp_bases; */
2427
/* method resolution order */
2428
NULL, /* PyObject *tp_mro; */
2429
NULL, /* PyObject *tp_cache; */
2430
NULL, /* PyObject *tp_subclasses; */
2431
NULL, /* PyObject *tp_weaklist; */
2435
/*****************************************************************************/
2436
/* Function: PoseConstraintSeq_CreatePyObject */
2437
/* Description: This function will create a new BPy_ConstraintSeq from an */
2438
/* existing ListBase structure. */
2439
/*****************************************************************************/
2440
PyObject *PoseConstraintSeq_CreatePyObject( bPoseChannel *pchan )
2442
BPy_ConstraintSeq *pyseq;
2445
for( ob = G.main->object.first; ob; ob = ob->id.next ) {
2446
if( ob->type == OB_ARMATURE ) {
2447
bPoseChannel *p = ob->pose->chanbase.first;
2450
pyseq = ( BPy_ConstraintSeq * ) PyObject_NEW(
2451
BPy_ConstraintSeq, &ConstraintSeq_Type );
2453
return EXPP_ReturnPyObjError( PyExc_MemoryError,
2454
"couldn't create BPy_ConstraintSeq object" );
2455
pyseq->pchan = pchan;
2457
return ( PyObject * ) pyseq;
2463
return EXPP_ReturnPyObjError( PyExc_RuntimeError,
2464
"couldn't find ANY armature with the pose!" );
2468
/*****************************************************************************/
2469
/* Function: ObConstraintSeq_CreatePyObject */
2470
/* Description: This function will create a new BPy_ConstraintSeq from an */
2471
/* existing ListBase structure. */
2472
/*****************************************************************************/
2473
PyObject *ObConstraintSeq_CreatePyObject( Object *obj )
2475
BPy_ConstraintSeq *pyseq;
2476
pyseq = ( BPy_ConstraintSeq * ) PyObject_NEW( BPy_ConstraintSeq,
2477
&ConstraintSeq_Type );
2479
return EXPP_ReturnPyObjError( PyExc_MemoryError,
2480
"couldn't create BPy_ConstraintSeq object" );
2482
pyseq->pchan = NULL;
2483
return ( PyObject * ) pyseq;
2486
static PyObject *M_Constraint_TypeDict( void )
2488
PyObject *S = PyConstant_New( );
2491
BPy_constant *d = ( BPy_constant * ) S;
2492
PyConstant_Insert( d, "NULL",
2493
PyInt_FromLong( CONSTRAINT_TYPE_NULL ) );
2494
PyConstant_Insert( d, "TRACKTO",
2495
PyInt_FromLong( CONSTRAINT_TYPE_TRACKTO ) );
2496
PyConstant_Insert( d, "IKSOLVER",
2497
PyInt_FromLong( CONSTRAINT_TYPE_KINEMATIC ) );
2498
PyConstant_Insert( d, "FOLLOWPATH",
2499
PyInt_FromLong( CONSTRAINT_TYPE_FOLLOWPATH ) );
2500
PyConstant_Insert( d, "COPYROT",
2501
PyInt_FromLong( CONSTRAINT_TYPE_ROTLIKE ) );
2502
PyConstant_Insert( d, "COPYLOC",
2503
PyInt_FromLong( CONSTRAINT_TYPE_LOCLIKE ) );
2504
PyConstant_Insert( d, "COPYSIZE",
2505
PyInt_FromLong( CONSTRAINT_TYPE_SIZELIKE ) );
2506
PyConstant_Insert( d, "ACTION",
2507
PyInt_FromLong( CONSTRAINT_TYPE_ACTION ) );
2508
PyConstant_Insert( d, "LOCKTRACK",
2509
PyInt_FromLong( CONSTRAINT_TYPE_LOCKTRACK ) );
2510
PyConstant_Insert( d, "STRETCHTO",
2511
PyInt_FromLong( CONSTRAINT_TYPE_STRETCHTO ) );
2512
PyConstant_Insert( d, "FLOOR",
2513
PyInt_FromLong( CONSTRAINT_TYPE_MINMAX ) );
2514
PyConstant_Insert( d, "LIMITLOC",
2515
PyInt_FromLong( CONSTRAINT_TYPE_LOCLIMIT ) );
2516
PyConstant_Insert( d, "LIMITROT",
2517
PyInt_FromLong( CONSTRAINT_TYPE_ROTLIMIT ) );
2518
PyConstant_Insert( d, "LIMITSIZE",
2519
PyInt_FromLong( CONSTRAINT_TYPE_SIZELIMIT ) );
2520
PyConstant_Insert( d, "LIMITDIST",
2521
PyInt_FromLong( CONSTRAINT_TYPE_DISTLIMIT ) );
2522
PyConstant_Insert( d, "RIGIDBODYJOINT",
2523
PyInt_FromLong( CONSTRAINT_TYPE_RIGIDBODYJOINT ) );
2524
PyConstant_Insert( d, "CLAMPTO",
2525
PyInt_FromLong( CONSTRAINT_TYPE_CLAMPTO ) );
2526
PyConstant_Insert( d, "PYTHON",
2527
PyInt_FromLong( CONSTRAINT_TYPE_PYTHON ) );
2528
PyConstant_Insert( d, "CHILDOF",
2529
PyInt_FromLong( CONSTRAINT_TYPE_CHILDOF ) );
2530
PyConstant_Insert( d, "TRANSFORM",
2531
PyInt_FromLong( CONSTRAINT_TYPE_TRANSFORM ) );
2536
static PyObject *M_Constraint_SettingsDict( void )
2538
PyObject *S = PyConstant_New( );
2541
BPy_constant *d = ( BPy_constant * ) S;
2542
PyConstant_Insert( d, "XROT",
2543
PyInt_FromLong( EXPP_CONSTR_XROT ) );
2544
PyConstant_Insert( d, "YROT",
2545
PyInt_FromLong( EXPP_CONSTR_YROT ) );
2546
PyConstant_Insert( d, "ZROT",
2547
PyInt_FromLong( EXPP_CONSTR_ZROT ) );
2548
PyConstant_Insert( d, "XSIZE",
2549
PyInt_FromLong( EXPP_CONSTR_XSIZE ) );
2550
PyConstant_Insert( d, "YSIZE",
2551
PyInt_FromLong( EXPP_CONSTR_YSIZE ) );
2552
PyConstant_Insert( d, "ZSIZE",
2553
PyInt_FromLong( EXPP_CONSTR_ZSIZE ) );
2554
PyConstant_Insert( d, "XLOC",
2555
PyInt_FromLong( EXPP_CONSTR_XLOC ) );
2556
PyConstant_Insert( d, "YLOC",
2557
PyInt_FromLong( EXPP_CONSTR_YLOC ) );
2558
PyConstant_Insert( d, "ZLOC",
2559
PyInt_FromLong( EXPP_CONSTR_ZLOC ) );
2561
PyConstant_Insert( d, "UPX",
2562
PyInt_FromLong( UP_X ) );
2563
PyConstant_Insert( d, "UPY",
2564
PyInt_FromLong( UP_Y ) );
2565
PyConstant_Insert( d, "UPZ",
2566
PyInt_FromLong( UP_Z ) );
2568
PyConstant_Insert( d, "TRACKX",
2569
PyInt_FromLong( TRACK_X ) );
2570
PyConstant_Insert( d, "TRACKY",
2571
PyInt_FromLong( TRACK_Y ) );
2572
PyConstant_Insert( d, "TRACKZ",
2573
PyInt_FromLong( TRACK_Z ) );
2574
PyConstant_Insert( d, "TRACKNEGX",
2575
PyInt_FromLong( TRACK_nX ) );
2576
PyConstant_Insert( d, "TRACKNEGY",
2577
PyInt_FromLong( TRACK_nY ) );
2578
PyConstant_Insert( d, "TRACKNEGZ",
2579
PyInt_FromLong( TRACK_nZ ) );
2581
PyConstant_Insert( d, "VOLUMEXZ",
2582
PyInt_FromLong( VOLUME_XZ ) );
2583
PyConstant_Insert( d, "VOLUMEX",
2584
PyInt_FromLong( VOLUME_X ) );
2585
PyConstant_Insert( d, "VOLUMEZ",
2586
PyInt_FromLong( VOLUME_Z ) );
2587
PyConstant_Insert( d, "VOLUMENONE",
2588
PyInt_FromLong( NO_VOLUME ) );
2590
PyConstant_Insert( d, "PLANEX",
2591
PyInt_FromLong( PLANE_X ) );
2592
PyConstant_Insert( d, "PLANEY",
2593
PyInt_FromLong( PLANE_Y ) );
2594
PyConstant_Insert( d, "PLANEZ",
2595
PyInt_FromLong( PLANE_Z ) );
2597
PyConstant_Insert( d, "LOCKX",
2598
PyInt_FromLong( LOCK_X ) );
2599
PyConstant_Insert( d, "LOCKY",
2600
PyInt_FromLong( LOCK_Y ) );
2601
PyConstant_Insert( d, "LOCKZ",
2602
PyInt_FromLong( LOCK_Z ) );
2604
PyConstant_Insert( d, "MAXX",
2605
PyInt_FromLong( EXPP_CONSTR_MAXX ) );
2606
PyConstant_Insert( d, "MAXY",
2607
PyInt_FromLong( EXPP_CONSTR_MAXY ) );
2608
PyConstant_Insert( d, "MAXZ",
2609
PyInt_FromLong( EXPP_CONSTR_MAXZ ) );
2610
PyConstant_Insert( d, "MINX",
2611
PyInt_FromLong( EXPP_CONSTR_MINX ) );
2612
PyConstant_Insert( d, "MINY",
2613
PyInt_FromLong( EXPP_CONSTR_MINY ) );
2614
PyConstant_Insert( d, "MINZ",
2615
PyInt_FromLong( EXPP_CONSTR_MINZ ) );
2617
PyConstant_Insert( d, "COPYX",
2618
PyInt_FromLong( LOCLIKE_X ) );
2619
PyConstant_Insert( d, "COPYY",
2620
PyInt_FromLong( LOCLIKE_Y ) );
2621
PyConstant_Insert( d, "COPYZ",
2622
PyInt_FromLong( LOCLIKE_Z ) );
2623
PyConstant_Insert( d, "COPYXINVERT",
2624
PyInt_FromLong( LOCLIKE_X_INVERT ) );
2625
PyConstant_Insert( d, "COPYYINVERT",
2626
PyInt_FromLong( LOCLIKE_Y_INVERT ) );
2627
PyConstant_Insert( d, "COPYZINVERT",
2628
PyInt_FromLong( LOCLIKE_Z_INVERT ) );
2630
PyConstant_Insert( d, "PARLOCX",
2631
PyInt_FromLong( CHILDOF_LOCX ) );
2632
PyConstant_Insert( d, "PARLOCY",
2633
PyInt_FromLong( CHILDOF_LOCY ) );
2634
PyConstant_Insert( d, "PARLOCZ",
2635
PyInt_FromLong( CHILDOF_LOCZ ) );
2636
PyConstant_Insert( d, "PARROTX",
2637
PyInt_FromLong( CHILDOF_ROTX ) );
2638
PyConstant_Insert( d, "PARROTY",
2639
PyInt_FromLong( CHILDOF_ROTY ) );
2640
PyConstant_Insert( d, "PARROTZ",
2641
PyInt_FromLong( CHILDOF_ROTZ ) );
2642
PyConstant_Insert( d, "PARSIZEX",
2643
PyInt_FromLong( CHILDOF_LOCX ) );
2644
PyConstant_Insert( d, "PARSIZEY",
2645
PyInt_FromLong( CHILDOF_SIZEY ) );
2646
PyConstant_Insert( d, "PARSIZEZ",
2647
PyInt_FromLong( CHILDOF_SIZEZ ) );
2649
PyConstant_Insert( d, "CLAMPAUTO",
2650
PyInt_FromLong( CLAMPTO_AUTO ) );
2651
PyConstant_Insert( d, "CLAMPX",
2652
PyInt_FromLong( CLAMPTO_X ) );
2653
PyConstant_Insert( d, "CLAMPY",
2654
PyInt_FromLong( CLAMPTO_Y ) );
2655
PyConstant_Insert( d, "CLAMPZ",
2656
PyInt_FromLong( CLAMPTO_Z ) );
2657
PyConstant_Insert( d, "CLAMPCYCLIC",
2658
PyInt_FromLong( EXPP_CONSTR_CLAMPCYCLIC ));
2660
PyConstant_Insert( d, "TARGET",
2661
PyInt_FromLong( EXPP_CONSTR_TARGET ) );
2662
PyConstant_Insert( d, "STRETCH",
2663
PyInt_FromLong( EXPP_CONSTR_STRETCH ) );
2664
PyConstant_Insert( d, "ITERATIONS",
2665
PyInt_FromLong( EXPP_CONSTR_ITERATIONS ) );
2666
PyConstant_Insert( d, "BONE",
2667
PyInt_FromLong( EXPP_CONSTR_BONE ) );
2668
PyConstant_Insert( d, "CHAINLEN",
2669
PyInt_FromLong( EXPP_CONSTR_CHAINLEN ) );
2670
PyConstant_Insert( d, "POSWEIGHT",
2671
PyInt_FromLong( EXPP_CONSTR_POSWEIGHT ) );
2672
PyConstant_Insert( d, "ROTWEIGHT",
2673
PyInt_FromLong( EXPP_CONSTR_ROTWEIGHT ) );
2674
PyConstant_Insert( d, "ROTATE",
2675
PyInt_FromLong( EXPP_CONSTR_ROTATE ) );
2676
PyConstant_Insert( d, "USETIP",
2677
PyInt_FromLong( EXPP_CONSTR_USETIP ) );
2679
PyConstant_Insert( d, "ACTION",
2680
PyInt_FromLong( EXPP_CONSTR_ACTION ) );
2681
PyConstant_Insert( d, "START",
2682
PyInt_FromLong( EXPP_CONSTR_START ) );
2683
PyConstant_Insert( d, "END",
2684
PyInt_FromLong( EXPP_CONSTR_END ) );
2685
PyConstant_Insert( d, "MIN",
2686
PyInt_FromLong( EXPP_CONSTR_MIN ) );
2687
PyConstant_Insert( d, "MAX",
2688
PyInt_FromLong( EXPP_CONSTR_MAX ) );
2689
PyConstant_Insert( d, "KEYON",
2690
PyInt_FromLong( EXPP_CONSTR_KEYON ) );
2692
PyConstant_Insert( d, "TRACK",
2693
PyInt_FromLong( EXPP_CONSTR_TRACK ) );
2694
PyConstant_Insert( d, "UP",
2695
PyInt_FromLong( EXPP_CONSTR_UP ) );
2697
PyConstant_Insert( d, "RESTLENGTH",
2698
PyInt_FromLong( EXPP_CONSTR_RESTLENGTH ) );
2699
PyConstant_Insert( d, "VOLVARIATION",
2700
PyInt_FromLong( EXPP_CONSTR_VOLVARIATION ) );
2701
PyConstant_Insert( d, "VOLUMEMODE",
2702
PyInt_FromLong( EXPP_CONSTR_VOLUMEMODE ) );
2703
PyConstant_Insert( d, "PLANE",
2704
PyInt_FromLong( EXPP_CONSTR_PLANE ) );
2706
PyConstant_Insert( d, "FOLLOW",
2707
PyInt_FromLong( EXPP_CONSTR_FOLLOW ) );
2708
PyConstant_Insert( d, "OFFSET",
2709
PyInt_FromLong( EXPP_CONSTR_OFFSET ) );
2710
PyConstant_Insert( d, "FORWARD",
2711
PyInt_FromLong( EXPP_CONSTR_FORWARD ) );
2713
PyConstant_Insert( d, "LOCK",
2714
PyInt_FromLong( EXPP_CONSTR_LOCK ) );
2716
PyConstant_Insert( d, "LIMITMODE",
2717
PyInt_FromLong( EXPP_CONSTR_MODE ) );
2718
PyConstant_Insert( d, "LIMIT_INSIDE",
2719
PyInt_FromLong( LIMITDIST_INSIDE ) );
2720
PyConstant_Insert( d, "LIMIT_OUTSIDE",
2721
PyInt_FromLong( LIMITDIST_OUTSIDE ) );
2722
PyConstant_Insert( d, "LIMIT_ONSURFACE",
2723
PyInt_FromLong( LIMITDIST_ONSURFACE ) );
2725
PyConstant_Insert( d, "COPY",
2726
PyInt_FromLong( EXPP_CONSTR_COPY ) );
2727
PyConstant_Insert( d, "LIMIT",
2728
PyInt_FromLong( EXPP_CONSTR_LIMIT ) );
2729
PyConstant_Insert( d, "CLAMP",
2730
PyInt_FromLong( EXPP_CONSTR_CLAMP ) );
2732
PyConstant_Insert( d, "LIMIT_XMIN",
2733
PyInt_FromLong( EXPP_CONSTR_LIMXMIN ) );
2734
PyConstant_Insert( d, "LIMIT_XMAX",
2735
PyInt_FromLong( EXPP_CONSTR_LIMXMAX ) );
2736
PyConstant_Insert( d, "LIMIT_YMIN",
2737
PyInt_FromLong( EXPP_CONSTR_LIMYMIN ) );
2738
PyConstant_Insert( d, "LIMIT_YMAX",
2739
PyInt_FromLong( EXPP_CONSTR_LIMYMAX ) );
2740
PyConstant_Insert( d, "LIMIT_ZMIN",
2741
PyInt_FromLong( EXPP_CONSTR_LIMZMIN ) );
2742
PyConstant_Insert( d, "LIMIT_ZMAX",
2743
PyInt_FromLong( EXPP_CONSTR_LIMZMAX ) );
2745
PyConstant_Insert( d, "LIMIT_XROT",
2746
PyInt_FromLong( EXPP_CONSTR_LIMXROT ) );
2747
PyConstant_Insert( d, "LIMIT_YROT",
2748
PyInt_FromLong( EXPP_CONSTR_LIMYROT ) );
2749
PyConstant_Insert( d, "LIMIT_ZROT",
2750
PyInt_FromLong( EXPP_CONSTR_LIMZROT ) );
2752
PyConstant_Insert( d, "XMIN",
2753
PyInt_FromLong( EXPP_CONSTR_XMIN ) );
2754
PyConstant_Insert( d, "XMAX",
2755
PyInt_FromLong( EXPP_CONSTR_XMAX ) );
2756
PyConstant_Insert( d, "YMIN",
2757
PyInt_FromLong( EXPP_CONSTR_YMIN ) );
2758
PyConstant_Insert( d, "YMAX",
2759
PyInt_FromLong( EXPP_CONSTR_YMAX ) );
2760
PyConstant_Insert( d, "ZMIN",
2761
PyInt_FromLong( EXPP_CONSTR_ZMIN ) );
2762
PyConstant_Insert( d, "ZMAX",
2763
PyInt_FromLong( EXPP_CONSTR_ZMAX ) );
2765
PyConstant_Insert( d, "SCRIPT",
2766
PyInt_FromLong( EXPP_CONSTR_SCRIPT ) );
2767
PyConstant_Insert( d, "PROPERTIES",
2768
PyInt_FromLong( EXPP_CONSTR_PROPS ) );
2770
PyConstant_Insert( d, "FROM",
2771
PyInt_FromLong( EXPP_CONSTR_FROM ) );
2772
PyConstant_Insert( d, "TO",
2773
PyInt_FromLong( EXPP_CONSTR_TO ) );
2774
PyConstant_Insert( d, "EXTRAPOLATE",
2775
PyInt_FromLong( EXPP_CONSTR_EXPO ) );
2776
PyConstant_Insert( d, "MAPX",
2777
PyInt_FromLong( EXPP_CONSTR_MAPX ) );
2778
PyConstant_Insert( d, "MAPY",
2779
PyInt_FromLong( EXPP_CONSTR_MAPY ) );
2780
PyConstant_Insert( d, "MAPZ",
2781
PyInt_FromLong( EXPP_CONSTR_MAPZ ) );
2782
PyConstant_Insert( d, "FROM_MINX",
2783
PyInt_FromLong( EXPP_CONSTR_FROMMINX ) );
2784
PyConstant_Insert( d, "FROM_MAXX",
2785
PyInt_FromLong( EXPP_CONSTR_FROMMAXX ) );
2786
PyConstant_Insert( d, "FROM_MINY",
2787
PyInt_FromLong( EXPP_CONSTR_FROMMINY ) );
2788
PyConstant_Insert( d, "FROM_MAXY",
2789
PyInt_FromLong( EXPP_CONSTR_FROMMAXY ) );
2790
PyConstant_Insert( d, "FROM_MINZ",
2791
PyInt_FromLong( EXPP_CONSTR_FROMMINZ ) );
2792
PyConstant_Insert( d, "FROM_MAXZ",
2793
PyInt_FromLong( EXPP_CONSTR_FROMMAXZ ) );
2794
PyConstant_Insert( d, "TO_MINX",
2795
PyInt_FromLong( EXPP_CONSTR_TOMINX ) );
2796
PyConstant_Insert( d, "TO_MAXX",
2797
PyInt_FromLong( EXPP_CONSTR_TOMAXX ) );
2798
PyConstant_Insert( d, "TO_MINY",
2799
PyInt_FromLong( EXPP_CONSTR_TOMINY ) );
2800
PyConstant_Insert( d, "TO_MAXY",
2801
PyInt_FromLong( EXPP_CONSTR_TOMAXY ) );
2802
PyConstant_Insert( d, "TO_MINZ",
2803
PyInt_FromLong( EXPP_CONSTR_TOMINZ ) );
2804
PyConstant_Insert( d, "TO_MAXZ",
2805
PyInt_FromLong( EXPP_CONSTR_TOMAXZ ) );
2807
PyConstant_Insert( d, "LOC",
2808
PyInt_FromLong( 0 ) );
2809
PyConstant_Insert( d, "ROT",
2810
PyInt_FromLong( 1 ) );
2811
PyConstant_Insert( d, "SCALE",
2812
PyInt_FromLong( 2 ) );
2814
PyConstant_Insert( d, "CONSTR_RB_TYPE",
2815
PyInt_FromLong( EXPP_CONSTR_RB_TYPE ) );
2816
PyConstant_Insert( d, "CONSTR_RB_BALL",
2817
PyInt_FromLong( EXPP_CONSTR_RB_BALL ) );
2818
PyConstant_Insert( d, "CONSTR_RB_HINGE",
2819
PyInt_FromLong( EXPP_CONSTR_RB_HINGE ) );
2820
PyConstant_Insert( d, "CONSTR_RB_GENERIC6DOF",
2821
PyInt_FromLong( EXPP_CONSTR_RB_GENERIC6DOF ) );
2822
PyConstant_Insert( d, "CONSTR_RB_VEHICLE",
2823
PyInt_FromLong( EXPP_CONSTR_RB_VEHICLE ) );
2824
PyConstant_Insert( d, "CONSTR_RB_PIVX",
2825
PyInt_FromLong( EXPP_CONSTR_RB_PIVX ) );
2826
PyConstant_Insert( d, "CONSTR_RB_PIVY",
2827
PyInt_FromLong( EXPP_CONSTR_RB_PIVY ) );
2828
PyConstant_Insert( d, "CONSTR_RB_PIVZ",
2829
PyInt_FromLong( EXPP_CONSTR_RB_PIVZ ) );
2830
PyConstant_Insert( d, "CONSTR_RB_AXX",
2831
PyInt_FromLong( EXPP_CONSTR_RB_AXX ) );
2832
PyConstant_Insert( d, "CONSTR_RB_AXY",
2833
PyInt_FromLong( EXPP_CONSTR_RB_AXY ) );
2834
PyConstant_Insert( d, "CONSTR_RB_AXZ",
2835
PyInt_FromLong( EXPP_CONSTR_RB_AXZ ) );
2836
PyConstant_Insert( d, "CONSTR_RB_MINLIMIT0",
2837
PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT0 ) );
2838
PyConstant_Insert( d, "CONSTR_RB_MINLIMIT1",
2839
PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT1 ) );
2840
PyConstant_Insert( d, "CONSTR_RB_MINLIMIT2",
2841
PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT2 ) );
2842
PyConstant_Insert( d, "CONSTR_RB_MINLIMIT3",
2843
PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT3 ) );
2844
PyConstant_Insert( d, "CONSTR_RB_MINLIMIT4",
2845
PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT4 ) );
2846
PyConstant_Insert( d, "CONSTR_RB_MINLIMIT5",
2847
PyInt_FromLong( EXPP_CONSTR_RB_MINLIMIT5 ) );
2848
PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT0",
2849
PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT0 ) );
2850
PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT1",
2851
PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT1 ) );
2852
PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT2",
2853
PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT2 ) );
2854
PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT3",
2855
PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT3 ) );
2856
PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT4",
2857
PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT4 ) );
2858
PyConstant_Insert( d, "CONSTR_RB_MAXLIMIT5",
2859
PyInt_FromLong( EXPP_CONSTR_RB_MAXLIMIT5 ) );
2860
PyConstant_Insert( d, "CONSTR_RB_EXTRAFZ",
2861
PyInt_FromLong( EXPP_CONSTR_RB_EXTRAFZ ) );
2862
PyConstant_Insert( d, "CONSTR_RB_FLAG",
2863
PyInt_FromLong( EXPP_CONSTR_RB_FLAG ) );
2866
PyConstant_Insert( d, "OWNERSPACE",
2867
PyInt_FromLong( EXPP_CONSTR_OWNSPACE ) );
2868
PyConstant_Insert( d, "TARGETSPACE",
2869
PyInt_FromLong( EXPP_CONSTR_TARSPACE ) );
2871
PyConstant_Insert( d, "SPACE_WORLD",
2872
PyInt_FromLong( CONSTRAINT_SPACE_WORLD) );
2873
PyConstant_Insert( d, "SPACE_LOCAL",
2874
PyInt_FromLong( CONSTRAINT_SPACE_LOCAL ) );
2875
PyConstant_Insert( d, "SPACE_POSE",
2876
PyInt_FromLong( CONSTRAINT_SPACE_POSE) );
2877
PyConstant_Insert( d, "SPACE_PARLOCAL",
2878
PyInt_FromLong( CONSTRAINT_SPACE_PARLOCAL ) );
2883
/*****************************************************************************/
2884
/* Function: Constraint_Init */
2885
/*****************************************************************************/
2886
PyObject *Constraint_Init( void )
2888
PyObject *submodule;
2889
PyObject *TypeDict = M_Constraint_TypeDict( );
2890
PyObject *SettingsDict = M_Constraint_SettingsDict( );
2892
if( PyType_Ready( &ConstraintSeq_Type ) < 0
2893
|| PyType_Ready( &Constraint_Type ) < 0 )
2896
submodule = Py_InitModule3( "Blender.Constraint", NULL,
2897
"Constraint module for accessing and creating constraint data" );
2900
PyModule_AddObject( submodule, "Type", TypeDict );
2903
PyModule_AddObject( submodule, "Settings", SettingsDict );