Constraints PyAPI:
Added support for Limit Distance constraint
This commit is contained in:
@@ -114,6 +114,8 @@ enum constraint_constants {
|
||||
EXPP_CONSTR_LIMIT,
|
||||
EXPP_CONSTR_CLAMP,
|
||||
|
||||
EXPP_CONSTR_MODE,
|
||||
|
||||
EXPP_CONSTR_LIMXMIN = LIMIT_XMIN,
|
||||
EXPP_CONSTR_LIMXMAX = LIMIT_XMAX,
|
||||
EXPP_CONSTR_LIMYMIN = LIMIT_YMIN,
|
||||
@@ -904,6 +906,56 @@ static int stretchto_setter( BPy_Constraint *self, int type, PyObject *value )
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *distlimit_getter( BPy_Constraint * self, int type )
|
||||
{
|
||||
bDistLimitConstraint *con = (bDistLimitConstraint *)(self->con->data);
|
||||
|
||||
switch( type ) {
|
||||
case EXPP_CONSTR_TARGET:
|
||||
return Object_CreatePyObject( con->tar );
|
||||
case EXPP_CONSTR_BONE:
|
||||
return PyString_FromString( con->subtarget );
|
||||
case EXPP_CONSTR_RESTLENGTH:
|
||||
return PyFloat_FromDouble( (double)con->dist );
|
||||
case EXPP_CONSTR_MODE:
|
||||
return PyInt_FromLong( (long)con->mode );
|
||||
default:
|
||||
return EXPP_ReturnPyObjError( PyExc_KeyError, "key not found" );
|
||||
}
|
||||
}
|
||||
|
||||
static int distlimit_setter( BPy_Constraint *self, int type, PyObject *value )
|
||||
{
|
||||
bDistLimitConstraint *con = (bDistLimitConstraint *)(self->con->data);
|
||||
|
||||
switch( type ) {
|
||||
case EXPP_CONSTR_TARGET: {
|
||||
Object *obj = (( BPy_Object * )value)->object;
|
||||
if( !BPy_Object_Check( value ) )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected BPy object argument" );
|
||||
con->tar = obj;
|
||||
return 0;
|
||||
}
|
||||
case EXPP_CONSTR_BONE: {
|
||||
char *name = PyString_AsString( value );
|
||||
if( !name )
|
||||
return EXPP_ReturnIntError( PyExc_TypeError,
|
||||
"expected string arg" );
|
||||
|
||||
BLI_strncpy( con->subtarget, name, sizeof( con->subtarget ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
case EXPP_CONSTR_RESTLENGTH:
|
||||
return EXPP_setFloatClamped( value, &con->dist, 0.0, 100.0 );
|
||||
case EXPP_CONSTR_MODE:
|
||||
return EXPP_setIValueRange( value, &con->mode, LIMITDIST_INSIDE, LIMITDIST_ONSURFACE, 'i' );
|
||||
default:
|
||||
return EXPP_ReturnIntError( PyExc_KeyError, "key not found" );
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *followpath_getter( BPy_Constraint * self, int type )
|
||||
{
|
||||
bFollowPathConstraint *con = (bFollowPathConstraint *)(self->con->data);
|
||||
@@ -1883,6 +1935,8 @@ static PyObject *Constraint_getData( BPy_Constraint * self, PyObject * key )
|
||||
return loclimit_getter( self, setting );
|
||||
case CONSTRAINT_TYPE_SIZELIMIT:
|
||||
return sizelimit_getter( self, setting );
|
||||
case CONSTRAINT_TYPE_DISTLIMIT:
|
||||
return distlimit_getter( self, setting );
|
||||
case CONSTRAINT_TYPE_RIGIDBODYJOINT:
|
||||
return rigidbody_getter( self, setting );
|
||||
case CONSTRAINT_TYPE_CLAMPTO:
|
||||
@@ -1960,6 +2014,9 @@ static int Constraint_setData( BPy_Constraint * self, PyObject * key,
|
||||
case CONSTRAINT_TYPE_SIZELIMIT:
|
||||
result = sizelimit_setter( self, key_int, arg);
|
||||
break;
|
||||
case CONSTRAINT_TYPE_DISTLIMIT:
|
||||
result = distlimit_setter( self, key_int, arg);
|
||||
break;
|
||||
case CONSTRAINT_TYPE_RIGIDBODYJOINT:
|
||||
result = rigidbody_setter( self, key_int, arg);
|
||||
break;
|
||||
@@ -2447,6 +2504,8 @@ static PyObject *M_Constraint_TypeDict( void )
|
||||
PyInt_FromLong( CONSTRAINT_TYPE_ROTLIMIT ) );
|
||||
PyConstant_Insert( d, "LIMITSIZE",
|
||||
PyInt_FromLong( CONSTRAINT_TYPE_SIZELIMIT ) );
|
||||
PyConstant_Insert( d, "LIMITDIST",
|
||||
PyInt_FromLong( CONSTRAINT_TYPE_DISTLIMIT ) );
|
||||
PyConstant_Insert( d, "RIGIDBODYJOINT",
|
||||
PyInt_FromLong( CONSTRAINT_TYPE_RIGIDBODYJOINT ) );
|
||||
PyConstant_Insert( d, "CLAMPTO",
|
||||
@@ -2640,6 +2699,15 @@ static PyObject *M_Constraint_SettingsDict( void )
|
||||
|
||||
PyConstant_Insert( d, "LOCK",
|
||||
PyInt_FromLong( EXPP_CONSTR_LOCK ) );
|
||||
|
||||
PyConstant_Insert( d, "LIMITMODE",
|
||||
PyInt_FromLong( EXPP_CONSTR_MODE ) );
|
||||
PyConstant_Insert( d, "LIMIT_INSIDE",
|
||||
PyInt_FromLong( LIMITDIST_INSIDE ) );
|
||||
PyConstant_Insert( d, "LIMIT_OUTSIDE",
|
||||
PyInt_FromLong( LIMITDIST_OUTSIDE ) );
|
||||
PyConstant_Insert( d, "LIMIT_ONSURFACE",
|
||||
PyInt_FromLong( LIMITDIST_ONSURFACE ) );
|
||||
|
||||
PyConstant_Insert( d, "COPY",
|
||||
PyInt_FromLong( EXPP_CONSTR_COPY ) );
|
||||
|
||||
@@ -31,13 +31,13 @@ Or to print all the constraints attached to each bone in a pose::
|
||||
@var Type: Constant Constraint dict used by L{Constraints.append()} and
|
||||
for comparison with L{Constraint.type}. Values are
|
||||
TRACKTO, IKSOLVER, FOLLOWPATH, COPYROT, COPYLOC, COPYSIZE, ACTION,
|
||||
LOCKTRACK, STRETCHTO, FLOOR, LIMITLOC, LIMITROT, LIMITSIZE, CLAMPTO,
|
||||
PYTHON, CHILDOF, TRANSFORM, NULL
|
||||
LOCKTRACK, STRETCHTO, FLOOR, LIMITLOC, LIMITROT, LIMITSIZE, LIMITDIST,
|
||||
CLAMPTO, PYTHON, CHILDOF, TRANSFORM, NULL
|
||||
|
||||
@type Settings: readonly dictionary
|
||||
@var Settings: Constant dict used for changing constraint settings.
|
||||
- Used for all single-target constraints
|
||||
(TRACKTO, FOLLOWPATH, COPYROT, COPYLOC, COPYSIZE, ACTION, LOCKTRACK, STRETCHTO, FLOOR, CLAMPTO, CHILDOF, TRANSFORM)
|
||||
(TRACKTO, FOLLOWPATH, COPYROT, COPYLOC, COPYSIZE, ACTION, LOCKTRACK, STRETCHTO, FLOOR, CLAMPTO, CHILDOF, TRANSFORM, LIMITDIST)
|
||||
- TARGET (Object): target object
|
||||
- BONE (string): name of Bone sub-target (for Armature targets), or name of Vertex Group sub-target
|
||||
(for Geometry targets)
|
||||
@@ -127,6 +127,8 @@ Or to print all the constraints attached to each bone in a pose::
|
||||
- YMAX (float): clamped to [0.0001,1000.0]
|
||||
- ZMIN (float): clamped to [0.0001,1000.0]
|
||||
- ZMAX (float): clamped to [0.0001,1000.0]
|
||||
- Used by Limit Distance (LIMITDIST) constraint:
|
||||
- LIMITMODE (int): any one of LIMIT_INSIDE, LIMIT_OUTSIDE, LIMIT_ONSURFACE
|
||||
- Used by Python Script (PYTHON) constraint:
|
||||
- SCRIPT (Text): script to use
|
||||
- PROPERTIES (IDProperties): ID-Properties of constraint
|
||||
|
||||
Reference in New Issue
Block a user