diff options
author | Joshua Leung <aligorith@gmail.com> | 2008-03-08 05:16:37 +0300 |
---|---|---|
committer | Joshua Leung <aligorith@gmail.com> | 2008-03-08 05:16:37 +0300 |
commit | b13cd8226e758c44c4393bb02bdeeaa6e8d36795 (patch) | |
tree | ea9bef5efd47793fd8976a4cace1bb2a576b6afa /source/blender/python | |
parent | 21dd86a159faf0ee3eb0f4629caf434034ff549c (diff) |
Bugfix #8478: Constraints PyApi for setting targetspace non-functional
Finishing off some unfinished business (from the multi-target constraints work), it is now possible to get/set target-space for constraints where this is relevant.
For this to be possible, target-space setting(s) are now always presented as a list of ints, with each int representing the target-space setting for the relevant target.
Constraints C-API note:
get_targets function now needs to return the number of targets the constraint can have
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/api2_2x/Constraint.c | 90 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/Constraint.py | 7 |
2 files changed, 77 insertions, 20 deletions
diff --git a/source/blender/python/api2_2x/Constraint.c b/source/blender/python/api2_2x/Constraint.c index 51dbe6a85f9..491669a7d92 100644 --- a/source/blender/python/api2_2x/Constraint.c +++ b/source/blender/python/api2_2x/Constraint.c @@ -1,5 +1,5 @@ /* - * $Id: Constraint.c 12705 2007-11-28 12:42:36Z ton $ + * $Id$ * * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** * @@ -493,7 +493,35 @@ static PyObject *constspace_getter( BPy_Constraint * self, int type ) case CONSTRAINT_TYPE_SIZELIKE: case CONSTRAINT_TYPE_TRACKTO: case CONSTRAINT_TYPE_TRANSFORM: - return PyInt_FromLong( (long)con->tarspace ); + { + bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + bConstraintTarget *ct; + PyObject *tlist=NULL, *val; + + if (cti) { + /* change space of targets */ + if (cti->get_constraint_targets) { + ListBase targets = {NULL, NULL}; + int num_tars=0, i=0; + + /* get targets, and create py-list for use temporarily */ + num_tars= cti->get_constraint_targets(con, &targets); + if (num_tars) { + tlist= PyList_New(num_tars); + + for (ct=targets.first; ct; ct=ct->next, i++) { + val= PyInt_FromLong((long)ct->space); + PyList_SET_ITEM(tlist, i, val); + } + } + + if (cti->flush_constraint_targets) + cti->flush_constraint_targets(con, &targets, 1); + } + } + + return tlist; + } } } @@ -545,23 +573,51 @@ static int constspace_setter( BPy_Constraint *self, int type, PyObject *value ) case CONSTRAINT_TYPE_TRACKTO: case CONSTRAINT_TYPE_TRANSFORM: { - Object *tar; - char *subtarget; - - // FIXME!!! - //tar= get_constraint_target(con, &subtarget); - tar = NULL; - subtarget = NULL; + bConstraintTypeInfo *cti= constraint_get_typeinfo(con); + bConstraintTarget *ct; + int ok= 0; - /* only copy depending on target-type */ - if (tar && subtarget[0]) { - return EXPP_setIValueClamped( value, &con->tarspace, - CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_PARLOCAL, 'h' ); - } - else if (tar) { - return EXPP_setIValueClamped( value, &con->tarspace, - CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL, 'h' ); + if (cti) { + /* change space of targets */ + if (cti->get_constraint_targets) { + ListBase targets = {NULL, NULL}; + int num_tars=0, i=0; + + /* get targets, and extract values from the given list */ + num_tars= cti->get_constraint_targets(con, &targets); + if (num_tars) { + if ((PySequence_Check(value) == 0) || (PySequence_Size(value) != num_tars)) { + char errorstr[64]; + sprintf(errorstr, "expected sequence of %d integers", num_tars); + return EXPP_ReturnIntError(PyExc_TypeError, errorstr); + } + + for (ct=targets.first; ct; ct=ct->next, i++) { + if (ct->tar && ct->subtarget[0]) { + PyObject *val= PySequence_ITEM(value, i); + + ok += EXPP_setIValueClamped(val, &ct->space, + CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_PARLOCAL, 'h' ); + + Py_DECREF(val); + } + else if (ct->tar) { + PyObject *val= PySequence_ITEM(value, i); + + ok += EXPP_setIValueClamped(val, &ct->space, + CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL, 'h' ); + + Py_DECREF(val); + } + } + } + + if (cti->flush_constraint_targets) + cti->flush_constraint_targets(con, &targets, 0); + } } + + return ok; } break; } diff --git a/source/blender/python/api2_2x/doc/Constraint.py b/source/blender/python/api2_2x/doc/Constraint.py index 4c1981c5238..61ee3c36700 100644 --- a/source/blender/python/api2_2x/doc/Constraint.py +++ b/source/blender/python/api2_2x/doc/Constraint.py @@ -46,9 +46,10 @@ Or to print all the constraints attached to each bone in a pose:: - OWNERSPACE (int): for TRACKTO, COPYLOC, COPYROT, COPYSIZE, LIMITLOC, LIMITROT, LIMITSIZE, PYTHON, TRANSFORM If the owner is an object, values are SPACE_WORLD, SPACE_LOCAL If the owner is a bone, values are SPACE_WORLD, SPACE_POSE, SPACE_PARLOCAL, SPACE_LOCAL - - TARGETSPACE (int): for TRACKTO, COPYLOC, COPYROT, COPYSIZE, PYTHON, TRANSFORM, ACTION - If the owner is an object, values are SPACE_WORLD, SPACE_LOCAL - If the owner is a bone, values are SPACE_WORLD, SPACE_POSE, SPACE_PARLOCAL, SPACE_LOCAL + - TARGETSPACE (list of ints): for TRACKTO, COPYLOC, COPYROT, COPYSIZE, PYTHON, TRANSFORM, ACTION + For every target that the Constraint can have, the target space can be set + If the target is an object, values are SPACE_WORLD, SPACE_LOCAL + If the target is a bone, values are SPACE_WORLD, SPACE_POSE, SPACE_PARLOCAL, SPACE_LOCAL - Used by IK Solver (IKSOLVER) constraint: - TOLERANCE (float): clamped to [0.0001:1.0] - ITERATIONS (int): clamped to [1,10000] |