diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2006-11-30 03:19:27 +0300 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2006-11-30 03:19:27 +0300 |
commit | 2572b9f72c8f10b01de949e59b481ac5a587aca4 (patch) | |
tree | 8500180c02ce6f7e5ace9c1d62f408d62c8be7f2 /source/gameengine/Converter | |
parent | 99d66e1d5e8c9d32c6289cd453ebec3f708aa249 (diff) |
Reserved some Bullet 2.x constraint data.
Although we will delay the main Rigid Body user interface after 2.43 release early 2007, I need some constraint data/UI to make progress with COLLADA Physics.
Added RigidBody constraint UI
LR_ALTKEY+LR_CTRLKEY+LR_SHIFTKEY+ P will bake rigidbody
Contribution by RCRuiz, Ramon Carlos.
Diffstat (limited to 'source/gameengine/Converter')
3 files changed, 153 insertions, 2 deletions
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index b0986aeca50..de20789235d 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -1515,6 +1515,84 @@ static struct Scene *GetSceneForName(struct Main *maggie, const STR_String& scen return (Scene*) maggie->scene.first; } +#include "DNA_constraint_types.h" +#include "BIF_editconstraint.h" + +bPoseChannel *get_active_posechannel2 (Object *ob) +{ + bArmature *arm= (bArmature*)ob->data; + bPoseChannel *pchan; + + /* find active */ + for(pchan= (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan= pchan->next) { + if(pchan->bone && (pchan->bone->flag & BONE_ACTIVE) && (pchan->bone->layer & arm->layer)) + return pchan; + } + + return NULL; +} + +ListBase *get_active_constraints2(Object *ob) +{ + if (!ob) + return NULL; + + if (ob->flag & OB_POSEMODE) { + bPoseChannel *pchan; + + pchan = get_active_posechannel2(ob); + if (pchan) + return &pchan->constraints; + } + else + return &ob->constraints; + + return NULL; +} + + +void RBJconstraints(Object *ob)//not used +{ + ListBase *conlist; + bConstraint *curcon; + + conlist = get_active_constraints2(ob); + + if (conlist) { + for (curcon = (bConstraint *)conlist->first; curcon; curcon=(bConstraint *)curcon->next) { + + printf("%i\n",curcon->type); + } + + + } +} + +#include "PHY_IPhysicsEnvironment.h" +#include "KX_IPhysicsController.h" +#include "PHY_DynamicTypes.h" + +KX_IPhysicsController* getPhId(CListValue* sumolist,STR_String busc){//not used + + for (int j=0;j<sumolist->GetCount();j++) + { + KX_GameObject* gameobje = (KX_GameObject*) sumolist->GetValue(j); + if (gameobje->GetName()==busc) + return gameobje->GetPhysicsController(); + } + +} + +KX_GameObject* getGameOb(STR_String busc,CListValue* sumolist){ + + for (int j=0;j<sumolist->GetCount();j++) + { + KX_GameObject* gameobje = (KX_GameObject*) sumolist->GetValue(j); + if (gameobje->GetName()==busc) + return gameobje; + } + +} // convert blender objects into ketsji gameobjects void BL_ConvertBlenderObjects(struct Main* maggie, @@ -1812,6 +1890,77 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } + // create physics joints + for (i=0;i<sumolist->GetCount();i++) + { + KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i); + struct Object* blenderobject = converter->FindBlenderObject(gameobj); + int nummeshes = gameobj->GetMeshCount(); + RAS_MeshObject* meshobj = 0; + ListBase *conlist; + bConstraint *curcon; + conlist = get_active_constraints2(blenderobject); + if (conlist) { + for (curcon = (bConstraint *)conlist->first; curcon; curcon=(bConstraint *)curcon->next) { + if (curcon->type==CONSTRAINT_TYPE_RIGIDBODYJOINT){ + bRigidBodyJointConstraint *dat=(bRigidBodyJointConstraint *)curcon->data; + if (dat->tar) + if (!dat->child){ + KX_GameObject *gotar=getGameOb(dat->tar->id.name,sumolist); + PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) (int)gameobj->GetPhysicsController()->GetUserData(); + PHY_IPhysicsController* physctr2 = (PHY_IPhysicsController*) (int)gotar->GetPhysicsController()->GetUserData(); + kxscene->GetPhysicsEnvironment()->createConstraint(physctrl,physctr2,(PHY_ConstraintType)dat->type,(float)dat->pivX,(float)dat->pivY,(float)dat->pivZ,(float)dat->axX,(float)dat->axY,(float)dat->axZ); + /*switch(dat->type){ + case CONSTRAINT_RB_BALL: + KX_GameObject *gotar=getGameOb(dat->tar->id.name,sumolist); + PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) (int)gameobj->GetPhysicsController()->GetUserData(); + PHY_IPhysicsController* physctr2 = (PHY_IPhysicsController*) (int)gotar->GetPhysicsController()->GetUserData(); + kxscene->GetPhysicsEnvironment()->createConstraint(physctrl,physctr2,(PHY_ConstraintType)dat->type,(float)dat->pivX,(float)dat->pivY,(float)dat->pivZ,(float)dat->axX,(float)dat->axY,(float)dat->axZ); + break; + case CONSTRAINT_RB_HINGE: + KX_GameObject *gotar=getGameOb(dat->tar->id.name,sumolist); + PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) (int)gameobj->GetPhysicsController()->GetUserData(); + PHY_IPhysicsController* physctr2 = (PHY_IPhysicsController*) (int)gotar->GetPhysicsController()->GetUserData(); + kxscene->GetPhysicsEnvironment()->createConstraint(physctrl,physctr2,(PHY_ConstraintType)dat->type,(float)dat->pivX,(float)dat->pivY,(float)dat->pivZ,(float)dat->axX,(float)dat->axY,(float)dat->axZ); + break; + }*/ + } + } + } + } + + } + + //Intento de actualizar posicion + /*for (i=0;i<sumolist->GetCount();i++) + { + KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i); + struct Object* blenderobject = converter->FindBlenderObject(gameobj); + + MT_Point3 pos = MT_Point3( + blenderobject->loc[0]+blenderobject->dloc[0], + blenderobject->loc[1]+blenderobject->dloc[1], + blenderobject->loc[2]+blenderobject->dloc[2] + ); + MT_Vector3 eulxyz = MT_Vector3( + blenderobject->rot[0], + blenderobject->rot[1], + blenderobject->rot[2] + ); + MT_Vector3 scale = MT_Vector3( + blenderobject->size[0], + blenderobject->size[1], + blenderobject->size[2] + ); + + gameobj->NodeSetLocalPosition(pos); + gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz)); + gameobj->NodeSetLocalScale(scale); + gameobj->NodeUpdateGS(0,true); + }*/ + //rcruiz> + + templist->Release(); sumolist->Release(); diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 83b2a11e606..10f3ea39616 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -576,7 +576,7 @@ Ipo* KX_BlenderSceneConverter::findIpoForName(char* objName) } -void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo() +void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo) { KX_SceneList* scenes = m_ketsjiEngine->CurrentScenes(); @@ -604,6 +604,7 @@ void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo() if (ipo) { //clear the curve data + if (clearIpo){ IpoCurve *icu1; int numCurves = 0; for( icu1 = (IpoCurve*)ipo->curve.first; icu1; ) { @@ -618,6 +619,7 @@ void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo() MEM_freeN( tmpicu ); localDel_ipoCurve( tmpicu ,m_sipo); } + } } else { ipo = add_ipo(blenderObject->id.name+2, ID_OB); diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.h b/source/gameengine/Converter/KX_BlenderSceneConverter.h index db2090aa470..c4447c53930 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.h +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.h @@ -130,7 +130,7 @@ public: void RegisterWorldInfo(KX_WorldInfo *worldinfo); - virtual void ResetPhysicsObjectsAnimationIpo(); + virtual void ResetPhysicsObjectsAnimationIpo(bool clearIpo); ///this generates ipo curves for position, rotation, allowing to use game physics in animation virtual void WritePhysicsObjectToAnimationIpo(int frameNumber); |