===Python API===
New Constraint API. Constraints are accessible through a "constraints" attribute in poses and objects. Would be REALLY NICE for armature users to pound on this code.
This commit is contained in:
@@ -64,6 +64,7 @@ struct ID; /*keep me up here */
|
||||
#include "Armature.h"
|
||||
#include "BezTriple.h"
|
||||
#include "Camera.h"
|
||||
#include "Constraint.h"
|
||||
#include "Curve.h"
|
||||
#include "CurNurb.h"
|
||||
#include "Draw.h"
|
||||
@@ -928,6 +929,7 @@ void M_Blender_Init(void)
|
||||
PyDict_SetItemString(dict, "BezTriple", BezTriple_Init());
|
||||
PyDict_SetItemString(dict, "BGL", BGL_Init());
|
||||
PyDict_SetItemString(dict, "CurNurb", CurNurb_Init());
|
||||
PyDict_SetItemString(dict, "Constraint", Constraint_Init());
|
||||
PyDict_SetItemString(dict, "Curve", Curve_Init());
|
||||
PyDict_SetItemString(dict, "Camera", Camera_Init());
|
||||
PyDict_SetItemString(dict, "Draw", Draw_Init());
|
||||
|
||||
1657
source/blender/python/api2_2x/Constraint.c
Normal file
1657
source/blender/python/api2_2x/Constraint.c
Normal file
File diff suppressed because it is too large
Load Diff
77
source/blender/python/api2_2x/Constraint.h
Normal file
77
source/blender/python/api2_2x/Constraint.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version. The Blender
|
||||
* Foundation also sells licenses for use in proprietary software under
|
||||
* the Blender License. See http://www.blender.org/BL/ for information
|
||||
* about this.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This is a new part of Blender.
|
||||
*
|
||||
* Contributor(s): Joseph Gilbert, Ken Hughes
|
||||
*
|
||||
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#ifndef EXPP_CONSTRAINT_H
|
||||
#define EXPP_CONSTRAINT_H
|
||||
|
||||
#include <Python.h>
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_action_types.h"
|
||||
#include "DNA_constraint_types.h"
|
||||
#include "DNA_listBase.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Python BPy_Modifier structure definition: */
|
||||
/*****************************************************************************/
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required macro */
|
||||
Object *obj; /* "parent" object */
|
||||
bPoseChannel *pchan;/* "parent" pose channel */
|
||||
/* if con this is null, the constraint has been removed and we need to
|
||||
* raise an error when its data is accessed */
|
||||
bConstraint *con;
|
||||
} BPy_Constraint;
|
||||
|
||||
extern PyTypeObject Constraint_Type;
|
||||
|
||||
#define BPy_Constraint_Check(v) ((v)->ob_type == &Constraint_Type) /* for type checking */
|
||||
typedef struct {
|
||||
PyObject_HEAD /* required macro */
|
||||
Object *obj; /* "parent" object */
|
||||
bPoseChannel *pchan;/* "parent" pose channel */
|
||||
bConstraint *iter;
|
||||
} BPy_ConstraintSeq;
|
||||
|
||||
/*
|
||||
* prototypes
|
||||
*/
|
||||
|
||||
PyObject *Constraint_Init( void );
|
||||
PyObject *Constraint_CreatePyObject( bPoseChannel *pchan, Object *obj,
|
||||
bConstraint *con );
|
||||
bConstraint *Constraint_FromPyObject( BPy_Constraint * obj );
|
||||
int Constraint_CheckPyObject( PyObject * py_obj );
|
||||
|
||||
PyObject *PoseConstraintSeq_CreatePyObject( bPoseChannel *pchan );
|
||||
PyObject *ObConstraintSeq_CreatePyObject( Object *obj );
|
||||
|
||||
#endif /* EXPP_CONSTRAINT_H */
|
||||
@@ -109,6 +109,7 @@ struct rctf;
|
||||
#include "Pose.h"
|
||||
#include "Group.h"
|
||||
#include "Modifier.h"
|
||||
#include "Constraint.h"
|
||||
#include "gen_utils.h"
|
||||
#include "EXPP_interface.h"
|
||||
#include "BIF_editkey.h"
|
||||
@@ -3594,7 +3595,9 @@ static PyObject *Object_getAttr( BPy_Object * obj, char *name )
|
||||
if( StringEqual( name, "drawSize" ) )
|
||||
return ( PyFloat_FromDouble( object->empty_drawsize ) );
|
||||
if( StringEqual( name, "modifiers" ) )
|
||||
return ModSeq_CreatePyObject( obj->object );
|
||||
return ModSeq_CreatePyObject( object );
|
||||
if( StringEqual( name, "constraints" ) )
|
||||
return ObConstraintSeq_CreatePyObject( object );
|
||||
|
||||
/* not an attribute, search the methods table */
|
||||
return Py_FindMethod( BPy_Object_methods, ( PyObject * ) obj, name );
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include "BLI_arithb.h"
|
||||
#include "Mathutils.h"
|
||||
#include "Object.h"
|
||||
#include "Constraint.h"
|
||||
#include "NLA.h"
|
||||
#include "gen_utils.h"
|
||||
|
||||
@@ -705,30 +706,12 @@ static int PoseBone_setPoseMatrix(BPy_PoseBone *self, PyObject *value, void *clo
|
||||
return EXPP_intError(PyExc_AttributeError, "%s%s%s",
|
||||
sPoseBoneError, ".poseMatrix: ", "not able to set this property");
|
||||
}
|
||||
////------------------------PoseBone.constraints (getter)
|
||||
////Gets the constraints list
|
||||
//static PyObject *PoseBone_getConstraints(BPy_PoseBone *self, void *closure)
|
||||
//{
|
||||
// PyObject *list = NULL, *py_constraint = NULL;
|
||||
// bConstraint *constraint = NULL;
|
||||
//
|
||||
// list = PyList_New(0);
|
||||
// for (constraint = self->posechannel->constraints.first; constraint; constraint = constraint->next){
|
||||
// py_constraint = PyConstraint_FromConstraint(constraint);
|
||||
// if (!py_constraint)
|
||||
// return NULL;
|
||||
// if (PyList_Append(list, py_constraint) == -1){
|
||||
// Py_DECREF(py_constraint);
|
||||
// goto RuntimeError;
|
||||
// }
|
||||
// Py_DECREF(py_constraint);
|
||||
// }
|
||||
// return list;
|
||||
//
|
||||
//RuntimeError:
|
||||
// return EXPP_objError(PyExc_RuntimeError, "%s%s%s",
|
||||
// sPoseBoneError, ".constraints: ", "unable to build constraint list");
|
||||
//}
|
||||
//------------------------PoseBone.constraints (getter)
|
||||
//Gets the constraints sequence
|
||||
static PyObject *PoseBone_getConstraints(BPy_PoseBone *self, void *closure)
|
||||
{
|
||||
return PoseConstraintSeq_CreatePyObject( self->posechannel );
|
||||
}
|
||||
////------------------------PoseBone.constraints (setter)
|
||||
////Sets the constraints list
|
||||
//static int PoseBone_setConstraints(BPy_PoseBone *self, PyObject *value, void *closure)
|
||||
@@ -782,8 +765,8 @@ static PyGetSetDef BPy_PoseBone_getset[] = {
|
||||
"The pose bone's head positon", NULL},
|
||||
{"tail", (getter)PoseBone_getTail, (setter)PoseBone_setTail,
|
||||
"The pose bone's tail positon", NULL},
|
||||
//{"constraints", (getter)PoseBone_getConstraints, (setter)PoseBone_setConstraints,
|
||||
// "The list of contraints that pertain to this pose bone", NULL},
|
||||
{"constraints", (getter)PoseBone_getConstraints, (setter)NULL,
|
||||
"The list of contraints that pertain to this pose bone", NULL},
|
||||
{NULL, NULL, NULL, NULL, NULL}
|
||||
};
|
||||
//------------------------tp_dealloc
|
||||
|
||||
@@ -38,6 +38,7 @@ The Blender Python API Reference
|
||||
- L{Noise}
|
||||
- L{Object} (*)
|
||||
- L{Pose}
|
||||
- L{Constraint} (*)
|
||||
- L{Registry}
|
||||
- L{Scene}
|
||||
- L{Radio}
|
||||
|
||||
224
source/blender/python/api2_2x/doc/Constraint.py
Normal file
224
source/blender/python/api2_2x/doc/Constraint.py
Normal file
@@ -0,0 +1,224 @@
|
||||
# Blender.Constraint module and the Constraint PyType object
|
||||
|
||||
"""
|
||||
The Blender.Constraint submodule
|
||||
|
||||
B{New}:
|
||||
- provides access to Blender's constraint stack
|
||||
|
||||
This module provides access to the Constraint Data in Blender.
|
||||
|
||||
Examples::
|
||||
from Blender import *
|
||||
|
||||
ob = Object.Get('Cube')
|
||||
if len(ob.constraints) > 0:
|
||||
const = ob.constraints[0]
|
||||
if const.type == Constraint.Type.FLOOR:
|
||||
offs = const[Constrint.Settings.OFFSET]
|
||||
|
||||
Or to print all the constraints attached to each bone in a pose::
|
||||
from Blender import *
|
||||
|
||||
ob = Object.Get('Armature')
|
||||
for bonename in pose.bones.keys():
|
||||
bone = pose.bones[bonename]
|
||||
for const in bone.constraints:
|
||||
print bone.name,'=>'const
|
||||
|
||||
@type Type: readonly dictionary
|
||||
@var Type: Constant Constraint dict used by L{ConstraintSeq.append()} and
|
||||
for comparison with L{Constraint.type}. Values are
|
||||
TRACKTO, IKSOLVER, FOLLOWPATH, COPYROT, COPYLOC, COPYSIZE, ACTION,
|
||||
LOCKTRACK, STRETCHTO, FLOOR
|
||||
|
||||
@type Settings: readonly dictionary
|
||||
@var Settings: Constant dict used for changing constraint settings.
|
||||
- Used for all constraints
|
||||
- TARGET (Object)
|
||||
- BONE (string): name of Bone subtarget (for armature targets) (Note: not
|
||||
used by Stretch To (STRETCHTO))
|
||||
- Used by IK Solver (IKSOLVER) constraint:
|
||||
- TOLERANCE (float): clamped to [0.0001:1.0]
|
||||
- ITERATIONS (int): clamped to [1,10000]
|
||||
- CHAINLEN (int): clamped to [0,255]
|
||||
- POSWEIGHT (float): clamped to [0.01,1.0]
|
||||
- ROTWEIGHT (float): clamped to [0.01,1.0]
|
||||
- ROTATE (bool)
|
||||
- USETIP (bool)
|
||||
- Used by Action (ACTION) constraint:
|
||||
- ACTION (Action Object)
|
||||
- LOCAL (bool)
|
||||
- START (int): clamped to [1,maxframe]
|
||||
- END (int): clamped to [1,maxframe]
|
||||
- MIN (float): clamped to [-180.0,180.0]
|
||||
- MAX (float): clamped to [-180.0,180.0]
|
||||
- KEYON (int): values are XROT, YROT, ZROT
|
||||
- Used by Track To (TRACKTO) constraint:
|
||||
- TRACK (int): values are TRACKX, TRACKY, TRACKZ, TRACKNEGX,
|
||||
TRACKNEGY, TRACKNEGZ
|
||||
- UP (int): values are UPX, UPY, UPZ
|
||||
- Used by Stretch To (STRETCHTO) constraint:
|
||||
- RESTLENGTH (float): clamped to [0.0:100.0]
|
||||
- VOLVARIATION (float): clamped to [0.0:100.0]
|
||||
- VOLUMEMODE (int): values are VOLUMEXZ, VOLUMEX, VOLUMEZ,
|
||||
VOLUMENONE
|
||||
- PLANE (int): values are PLANEX, PLANEZ
|
||||
- Used by Follow Path (FOLLOWPATH) constraint:
|
||||
- FOLLOW (bool)
|
||||
- OFFSET (float): clamped to [-maxframe:maxframe]
|
||||
- FORWARD (int): values are TRACKX, TRACKY, TRACKZ, TRACKNEGX,
|
||||
TRACKNEGY, TRACKNEGZ
|
||||
- UP (int): values are UPX, UPY, UPZ
|
||||
- Used by Lock Track (FOLLOWPATH) constraint:
|
||||
- TRACK (int): values are TRACKX, TRACKY, TRACKZ, TRACKNEGX,
|
||||
TRACKNEGY, TRACKNEGZ
|
||||
- LOCK (int): values are LOCKX, LOCKY, LOCKZ
|
||||
- Used by Floor (FLOOR) constraint:
|
||||
- MINMAX (int): values are MINX, MINY, MINZ, MAXX, MAXY, MAXZ
|
||||
- OFFSET (float): clamped to [-100.0,100.0]
|
||||
- STICKY (bool)
|
||||
- Used by Copy Location (COPYLOC), Copy Rotation (COPYROT), and Copy Size
|
||||
(COPYSIZE) constraint:
|
||||
- COPY (bitfield): any combination of COPYX, COPYY and COPYZ
|
||||
|
||||
"""
|
||||
|
||||
class ConstraintSeq:
|
||||
"""
|
||||
The ConstraintSeq object
|
||||
========================
|
||||
This object provides access to sequence of
|
||||
L{constraints<Constraint.Constraint>} for a particular object.
|
||||
They can be accessed from L{Object.constraints<Object.Object.constraints>}.
|
||||
or L{PoseBone.constraints<Pose.PoseBone.constraints>}.
|
||||
"""
|
||||
|
||||
def __getitem__(index):
|
||||
"""
|
||||
This operator returns one of the constraints in the stack.
|
||||
@type index: int
|
||||
@return: an Constraint object
|
||||
@rtype: Constraint
|
||||
@raise KeyError: index was out of range
|
||||
"""
|
||||
|
||||
def __len__():
|
||||
"""
|
||||
Returns the number of constraints in the constraint stack.
|
||||
@return: number of Constraints
|
||||
@rtype: int
|
||||
"""
|
||||
|
||||
def append(type):
|
||||
"""
|
||||
Appends a new constraint to the end of the constraint stack.
|
||||
@type type: a constant specifying the type of constraint to create. as from L{Type}
|
||||
@rtype: Constraint
|
||||
@return: the new Constraint
|
||||
"""
|
||||
|
||||
def remove(constraint):
|
||||
"""
|
||||
Remove a constraint from this objects constraint sequence.
|
||||
@type constraint: a constraint from this sequence to remove.
|
||||
@note: Accessing attributes of the constraint after it is removed will
|
||||
throw an exception.
|
||||
"""
|
||||
|
||||
class Constraint:
|
||||
"""
|
||||
The Constraint object
|
||||
=====================
|
||||
This object provides access to a constraint for a particular object
|
||||
accessed from L{ConstraintSeq}.
|
||||
@ivar name: The name of this constraint. 29 chars max.
|
||||
@type name: string
|
||||
@ivar type: The type of this constraint. Read-only. The returned value
|
||||
matches the types in L{Type}.
|
||||
@type type: int
|
||||
@ivar influence: The influence value of the constraint. Valid values
|
||||
are in the range [0.0,1.0].
|
||||
@type influence: float
|
||||
"""
|
||||
|
||||
def __getitem__(key):
|
||||
"""
|
||||
This operator returns one of the constraint's data attributes.
|
||||
@type key: value from constraint's L{Constraint.Settings} constant
|
||||
@return: the requested data
|
||||
@rtype: varies
|
||||
@raise KeyError: the key does not exist for the constraint
|
||||
"""
|
||||
|
||||
def __setitem__(key):
|
||||
"""
|
||||
This operator changes one of the constraint's data attributes.
|
||||
@type key: value from constraint's L{Constraint.Settings} constant
|
||||
@raise KeyError: the key does not exist for the constraint
|
||||
"""
|
||||
|
||||
def up():
|
||||
"""
|
||||
Moves the constraint up in the object's constraint stack.
|
||||
@rtype: PyNone
|
||||
"""
|
||||
|
||||
def down():
|
||||
"""
|
||||
Moves the constraint down in the object's constraint stack.
|
||||
@rtype: PyNone
|
||||
"""
|
||||
|
||||
def insertKey(frame):
|
||||
"""
|
||||
Adds an influence keyframe for the constraint Ipo.
|
||||
@rtype: PyNone
|
||||
@type frame: float
|
||||
@param frame: the frame number at which to insert the key.
|
||||
"""
|
||||
|
||||
|
||||
|
||||
class ConstraintSeq:
|
||||
"""
|
||||
The ConstraintSeq object
|
||||
========================
|
||||
This object provides access to sequence of
|
||||
L{constraints<Constraint.Constraint>} for a particular object.
|
||||
They can be accessed from L{Object.constraints<Object.Object.constraints>}.
|
||||
or L{PoseBone.constraints<Pose.PoseBone.constraints>}.
|
||||
"""
|
||||
|
||||
def __getitem__(index):
|
||||
"""
|
||||
This operator returns one of the constraints in the stack.
|
||||
@type index: int
|
||||
@return: an Constraint object
|
||||
@rtype: Constraint
|
||||
@raise KeyError: index was out of range
|
||||
"""
|
||||
|
||||
def __len__():
|
||||
"""
|
||||
Returns the number of constraints in the constraint stack.
|
||||
@return: number of Constraints
|
||||
@rtype: int
|
||||
"""
|
||||
|
||||
def append(type):
|
||||
"""
|
||||
Appends a new constraint to the end of the constraint stack.
|
||||
@type type: a constant specifying the type of constraint to create. as from L{Type}
|
||||
@rtype: Constraint
|
||||
@return: the new Constraint
|
||||
"""
|
||||
|
||||
def remove(constraint):
|
||||
"""
|
||||
Remove a constraint from this objects constraint sequence.
|
||||
@type constraint: a constraint from this sequence to remove.
|
||||
@note: Accessing attributes of the constraint after removing will
|
||||
throw an exception.
|
||||
"""
|
||||
|
||||
@@ -138,7 +138,6 @@ def Duplicate (mesh=0, surface=0, curve=0, text=0, metaball=0, armature=0, lamp=
|
||||
@param texture: When non-zero, texture data used by the object's materials will be duplicated with the objects.
|
||||
@type ipo: bool
|
||||
@param ipo: When non-zero, Ipo data linked to the object will be duplicated with the objects.
|
||||
@return: None
|
||||
|
||||
I{B{Example:}}
|
||||
|
||||
@@ -328,6 +327,9 @@ class Object:
|
||||
@type drawSize: float
|
||||
@ivar modifiers: The modifiers for this object.
|
||||
@type modifiers: ModSeq L{Modifier.ModSeq}
|
||||
@type constraints: BPy_ConstraintSeq
|
||||
@ivar constraints: a L{sequence<Constraint.ConstraintSeq>} of
|
||||
L{constraints<Constraint.Constraint>} for the object.
|
||||
"""
|
||||
|
||||
def buildParts():
|
||||
|
||||
@@ -85,6 +85,9 @@ class PoseBone:
|
||||
@type localMatrix: Matrix object
|
||||
@ivar poseMatrix: The total transformation of this PoseBone including constraints. (not settable)
|
||||
@type poseMatrix: Matrix object
|
||||
@type constraints: BPy_ConstraintSeq
|
||||
@ivar constraints: a sequence of constraints for the object
|
||||
|
||||
"""
|
||||
|
||||
def insertKey(parentObject, frameNumber, type):
|
||||
|
||||
Reference in New Issue
Block a user