PhysicsConstraints.createConstraint:

allow to dynamically create rigid body constraints while disable collision detection between connected bodies, pass as 10th argument the flag 128

PhysiPython KX_ConstraintWrapper, setParam
export setParam(paramIndex,paramValue0,paramValue1) for Physics constraints
paramIndex 0,1,2 are linear limits, 3,4,5 are angular limits, 6,7,8 are linear motors, 9,10,11 are angular motors

For example:
disableConnectedBodies=128
cons = PhysicsConstraints.createConstraint(oid,rid,generic6dof,pivotInAx,pivotInAy,pivotInAz,angleX,angleY,angleZ,disableConnectedBodies)
#params 0,1,2 are linear limits, low,high value. if low > high then disable limit
cons.setParam(0,0,0)

I will provide an example .blend for Blender 2.49
This commit is contained in:
Erwin Coumans 2009-05-24 01:55:24 +00:00
parent 4922dd0339
commit 52b0a2b3db
4 changed files with 56 additions and 14 deletions

@ -54,7 +54,7 @@ PyObject* KX_ConstraintWrapper::PyGetConstraintId(PyObject* args, PyObject* kwds
return PyInt_FromLong(m_constraintId);
}
PyObject* KX_ConstraintWrapper::PySetLimit(PyObject* args, PyObject* kwds)
PyObject* KX_ConstraintWrapper::PySetParam(PyObject* args, PyObject* kwds)
{
int len = PyTuple_Size(args);
int success = 1;
@ -73,11 +73,7 @@ PyObject* KX_ConstraintWrapper::PySetLimit(PyObject* args, PyObject* kwds)
return NULL;
}
PyObject* KX_ConstraintWrapper::PyEnableMotor(PyObject* args, PyObject* kwds)
{
///will add it soon
return PyInt_FromLong(0);
}
//python specific stuff
PyTypeObject KX_ConstraintWrapper::Type = {
@ -130,8 +126,7 @@ int KX_ConstraintWrapper::py_setattro(PyObject *attr,PyObject* value)
PyMethodDef KX_ConstraintWrapper::Methods[] = {
{"getConstraintId",(PyCFunction) KX_ConstraintWrapper::sPyGetConstraintId, METH_VARARGS},
{"setLimit",(PyCFunction) KX_ConstraintWrapper::sPySetLimit, METH_VARARGS},
{"enableMotor",(PyCFunction) KX_ConstraintWrapper::sPyEnableMotor, METH_VARARGS},
{"setParam",(PyCFunction) KX_ConstraintWrapper::sPySetParam, METH_VARARGS},
{NULL,NULL} //Sentinel
};

@ -45,8 +45,7 @@ public:
KX_PYMETHOD(KX_ConstraintWrapper,TestMethod);
KX_PYMETHOD(KX_ConstraintWrapper,GetConstraintId);
KX_PYMETHOD(KX_ConstraintWrapper,SetLimit);
KX_PYMETHOD(KX_ConstraintWrapper,EnableMotor);
KX_PYMETHOD(KX_ConstraintWrapper,SetParam);
private:
int m_constraintId;

@ -405,6 +405,8 @@ static PyObject* gPyCreateConstraint(PyObject* self,
int physicsid=0,physicsid2 = 0,constrainttype=0,extrainfo=0;
int len = PyTuple_Size(args);
int success = 1;
int flag = 0;
float pivotX=1,pivotY=1,pivotZ=1,axisX=0,axisY=0,axisZ=1;
if (len == 3)
{
@ -421,6 +423,11 @@ static PyObject* gPyCreateConstraint(PyObject* self,
success = PyArg_ParseTuple(args,"iiiffffff",&physicsid,&physicsid2,&constrainttype,
&pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ);
}
else if (len == 10)
{
success = PyArg_ParseTuple(args,"iiiffffffi",&physicsid,&physicsid2,&constrainttype,
&pivotX,&pivotY,&pivotZ,&axisX,&axisY,&axisZ,&flag);
}
else if (len==4)
{
success = PyArg_ParseTuple(args,"iiii",&physicsid,&physicsid2,&constrainttype,&extrainfo);
@ -455,7 +462,7 @@ static PyObject* gPyCreateConstraint(PyObject* self,
pivotX,pivotY,pivotZ,
(float)axis0.x(),(float)axis0.y(),(float)axis0.z(),
(float)axis1.x(),(float)axis1.y(),(float)axis1.z(),
(float)axis2.x(),(float)axis2.y(),(float)axis2.z(),0);//dat->flag); //flag?
(float)axis2.x(),(float)axis2.y(),(float)axis2.z(),flag);
} else
{

@ -426,6 +426,13 @@ void CcdPhysicsEnvironment::removeCcdPhysicsController(CcdPhysicsController* ctr
btRigidBody* body = ctrl->GetRigidBody();
if (body)
{
for (int i=body->getNumConstraintRefs()-1;i>=0;i--)
{
btTypedConstraint* con = body->getConstraintRef(i);
m_dynamicsWorld->removeConstraint(con);
body->removeConstraintRef(con);
//delete con; //might be kept by python KX_ConstraintWrapper
}
m_dynamicsWorld->removeRigidBody(ctrl->GetRigidBody());
} else
{
@ -1791,9 +1798,43 @@ void CcdPhysicsEnvironment::setConstraintParam(int constraintId,int param,float
{
case PHY_GENERIC_6DOF_CONSTRAINT:
{
//param = 1..12, min0,max0,min1,max1...min6,max6
btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
genCons->setLimit(param,value0,value1);
switch (param)
{
case 0: case 1: case 2: case 3: case 4: case 5:
{
//param = 0..5 are constraint limits, with low/high limit value
btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
genCons->setLimit(param,value0,value1);
break;
}
case 6: case 7: case 8:
{
//param = 6,7,8 are translational motors, with value0=target velocity, value1 = max motor force
btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
int transMotorIndex = param-6;
btTranslationalLimitMotor* transMotor = genCons->getTranslationalLimitMotor();
transMotor->m_targetVelocity[transMotorIndex]= value0;
transMotor->m_maxMotorForce[transMotorIndex]=value1;
transMotor->m_enableMotor[transMotorIndex] = (value1>0.f);
break;
}
case 9: case 10: case 11:
{
//param = 9,10,11 are rotational motors, with value0=target velocity, value1 = max motor force
btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
int angMotorIndex = param-9;
btRotationalLimitMotor* rotMotor = genCons->getRotationalLimitMotor(angMotorIndex);
rotMotor->m_enableMotor = (value1 > 0.f);
rotMotor->m_targetVelocity = value0;
rotMotor->m_maxMotorForce = value1;
break;
}
default:
{
}
}
break;
};
default: