diff options
18 files changed, 293 insertions, 233 deletions
diff --git a/source/blender/blenkernel/bad_level_call_stubs/stubs.c b/source/blender/blenkernel/bad_level_call_stubs/stubs.c index d112b60ad27..cf9fc19efbf 100644 --- a/source/blender/blenkernel/bad_level_call_stubs/stubs.c +++ b/source/blender/blenkernel/bad_level_call_stubs/stubs.c @@ -296,3 +296,7 @@ void antialias_tagbuf(int xsize, int ysize, char *rectmove) {} /* imagetexture.c stub */ void ibuf_sample(struct ImBuf *ibuf, float fx, float fy, float dx, float dy, float *result) {} + +void update_for_newframe() +{ +} diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h index 3570a0f7375..2eb1139dd07 100644 --- a/source/blender/makesdna/DNA_constraint_types.h +++ b/source/blender/makesdna/DNA_constraint_types.h @@ -324,6 +324,8 @@ typedef struct bRigidBodyJointConstraint{ #define LIMIT_NOPARENT 0x01 +#define CONSTRAINT_DRAW_PIVOT 0x40 + /* important: these defines need to match up with PHY_DynamicTypes headerfile */ #define CONSTRAINT_RB_BALL 1 #define CONSTRAINT_RB_HINGE 2 diff --git a/source/blender/src/buttons_object.c b/source/blender/src/buttons_object.c index 44ae6421a70..a5eb7f02793 100644 --- a/source/blender/src/buttons_object.c +++ b/source/blender/src/buttons_object.c @@ -1159,14 +1159,16 @@ static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, s { //uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "toObject:", *xco, *yco-50, 130, 18, &data->tar, "Child Object"); + uiDefButBitS(block, TOG, CONSTRAINT_DRAW_PIVOT, B_CONSTRAINT_TEST, "ShowPivot", *xco+135, *yco-50, 130, 18, &data->flag, 0, 24, 0, 0, "Show pivot position and rotation"); //if (data->tar) // uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "Child:", *xco+135, *yco-50, 130, 18, &data->child, "Child2 Object (if this exist then this object will be the pivot Only)"); - uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot X:", *xco, *yco-75, 130, 18, &data->pivX, -10000, 10000, 100.0, 0.0, "Offset Joint"); - uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Y:", *xco, *yco-100, 130, 18, &data->pivY, -10000, 10000, 100.0, 0.0, "Offset Joint"); - uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Z:", *xco, *yco-125, 130, 18, &data->pivZ, -10000, 10000, 100.0, 0.0, "Offset Joint"); - uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax X:", *xco+135, *yco-75, 130, 18, &data->axX, -10000, 10000, 100.0, 0.0, "Offset Joint"); - uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax Y:", *xco+135, *yco-100, 130, 18, &data->axY, -10000, 10000, 100.0, 0.0, "Offset Joint"); - uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax Z:", *xco+135, *yco-125, 130, 18, &data->axZ, -10000, 10000, 100.0, 0.0, "Offset Joint"); + uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot X:", *xco, *yco-75, 130, 18, &data->pivX, -1000, 1000, 0.1, 0.0, "Offset pivot on X"); + uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Y:", *xco, *yco-100, 130, 18, &data->pivY, -1000, 1000, 0.1, 0.0, "Offset pivot on Y"); + uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Z:", *xco, *yco-125, 130, 18, &data->pivZ, -1000, 1000, 0.1, 0.0, "Offset pivot on z"); + + uiDefButF(block, NUM, B_CONSTRAINT_TEST, "AxEX:", *xco+135, *yco-75, 130, 18, &data->axX, -3.141592, 3.141592, 0.1, 0.0, "Rotate pivot on X Axis"); + uiDefButF(block, NUM, B_CONSTRAINT_TEST, "AxEY:", *xco+135, *yco-100, 130, 18, &data->axY, -3.141592, 3.141592, 0.1, 0.0, "Rotate pivot on Y Axis"); + uiDefButF(block, NUM, B_CONSTRAINT_TEST, "AxEZ:", *xco+135, *yco-125, 130, 18, &data->axZ, -3.141592, 3.141592, 0.1, 0.0, "Rotate pivot on Z Axis"); if (data->type==CONSTRAINT_RB_GENERIC6DOF){ /* Draw Pairs of LimitToggle+LimitValue */ diff --git a/source/blender/src/drawobject.c b/source/blender/src/drawobject.c index ec9962ce697..5b7a1b7134e 100644 --- a/source/blender/src/drawobject.c +++ b/source/blender/src/drawobject.c @@ -3636,6 +3636,51 @@ static void draw_hooks(Object *ob) } } +//<rcruiz> +void drawRBpivot(bRigidBodyJointConstraint *data){ + float size=1.0f; + int axis; + float v1[3]= {data->pivX, data->pivY, data->pivZ}; + float eu[3]= {data->axX, data->axY, data->axZ}; + float mat[4][4]; + EulToMat4(eu,mat); + glLineWidth (4.0f); + setlinestyle(2); + for (axis=0; axis<3; axis++) { + float dir[3] = {0,0,0}; + float v[3]= {data->pivX, data->pivY, data->pivZ}; + int arrow_axis= (axis==0)?1:0; + dir[axis] = 1.f; + glBegin(GL_LINES); + Mat4MulVecfl(mat,dir); + v[0] += dir[0]; + v[1] += dir[1]; + v[2] += dir[2]; + glVertex3fv(v1); + glVertex3fv(v); +/* v1[axis]= size*0.8; + v1[arrow_axis]= -size*0.125; + glVertex3fv(v1); + glVertex3fv(v2); + + v1[arrow_axis]= size*0.125; + glVertex3fv(v1); + glVertex3fv(v2); +*/ + glEnd(); + glRasterPos3fv(v); + if (axis==0) + BMF_DrawString(G.font, "px"); + else if (axis==1) + BMF_DrawString(G.font, "py"); + else + BMF_DrawString(G.font, "pz"); + + } + glLineWidth (1.0f); + setlinestyle(0); +} + /* flag can be DRAW_PICKING and/or DRAW_CONSTCOLOR */ void draw_object(Base *base, int flag) { @@ -4001,6 +4046,18 @@ void draw_object(Base *base, int flag) } if(ob->pd && ob->pd->forcefield) draw_forcefield(ob); + { + bConstraint *con; + for(con=ob->constraints.first; con; con= con->next) + { + if(con->type==CONSTRAINT_TYPE_RIGIDBODYJOINT) + { + bRigidBodyJointConstraint *data = (bRigidBodyJointConstraint*)con->data; + if(data->flag&CONSTRAINT_DRAW_PIVOT) + drawRBpivot(data); + } + } + } /* draw extra: after normal draw because of makeDispList */ if(dtx) { diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index f37928fe2d5..91394c8c212 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -83,6 +83,15 @@ #include "DNA_scene_types.h" /***/ +#ifdef __cplusplus +extern "C" { +#endif +#include "BSE_headerbuttons.h" +void update_for_newframe(); +#ifdef __cplusplus +} +#endif + static BlendFileData *load_game_data(char *filename) { BlendReadError error; //this doesn't work anymore for relative paths, so use BLO_read_from_memory instead @@ -310,7 +319,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, // create a scene converter, create and convert the startingscene KX_ISceneConverter* sceneconverter = new KX_BlenderSceneConverter(blenderdata,sipo, ketsjiengine); ketsjiengine->SetSceneConverter(sceneconverter); - + sceneconverter->addInitFromFrame=false; if (always_use_expand_framing) sceneconverter->SetAlwaysUseExpandFraming(true); @@ -452,14 +461,6 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, if (bfd) BLO_blendfiledata_free(bfd); } -#ifdef __cplusplus -extern "C" { -#endif -#include "BSE_headerbuttons.h" -void update_for_newframe(); -#ifdef __cplusplus -} -#endif extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, char* scenename, @@ -481,7 +482,6 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, do { -// View3D *v3d= (View3D*) area->spacedata.first; // get some preferences SYS_SystemHandle syshandle = SYS_GetSystem(); @@ -493,19 +493,6 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, bool displaylists = (SYS_GetCommandLineInt(syshandle, "displaylists", 0) != 0); bool usemat = false; -/* #ifdef GL_ARB_multitexture - if(bgl::RAS_EXT_support._ARB_multitexture && bgl::QueryVersion(1, 1)) { - usemat = (SYS_GetCommandLineInt(syshandle, "blender_material", 0) != 0); - int unitmax=0; - glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, (GLint*)&unitmax); - bgl::max_texture_units = MAXTEX>unitmax?unitmax:MAXTEX; - //std::cout << "using(" << bgl::max_texture_units << ") of(" << unitmax << ") texture units." << std::endl; - } else { - bgl::max_texture_units = 0; - } - #endif - -*/ // create the canvas, rasterizer and rendertools RAS_ICanvas* canvas = new KX_BlenderCanvas(area); //canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE); @@ -544,83 +531,8 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, // create the ketsjiengine KX_KetsjiEngine* ketsjiengine = new KX_KetsjiEngine(kxsystem); -/* // set the devices - ketsjiengine->SetKeyboardDevice(keyboarddevice); - ketsjiengine->SetMouseDevice(mousedevice); - ketsjiengine->SetNetworkDevice(networkdevice); - ketsjiengine->SetCanvas(canvas); - ketsjiengine->SetRenderTools(rendertools); - ketsjiengine->SetRasterizer(rasterizer); - ketsjiengine->SetNetworkDevice(networkdevice); - ketsjiengine->SetAudioDevice(audiodevice); - ketsjiengine->SetUseFixedTime(usefixed); - ketsjiengine->SetTimingDisplay(frameRate, profile, properties); - -*/ - - // some blender stuff - MT_CmMatrix4x4 projmat; - MT_CmMatrix4x4 viewmat; int i; -/* for (i = 0; i < 16; i++) - { - float *viewmat_linear= (float*) v3d->viewmat; - viewmat.setElem(i, viewmat_linear[i]); - } - for (i = 0; i < 16; i++) - { - float *projmat_linear = (float*) area->winmat; - projmat.setElem(i, projmat_linear[i]); - } -*/ -/* float camzoom = (1.41421 + (v3d->camzoom / 50.0)); - camzoom *= camzoom; - camzoom = 4.0 / camzoom; -*/ -// ketsjiengine->SetDrawType(v3d->drawtype); -// ketsjiengine->SetCameraZoom(camzoom); -/* - // if we got an exitcode 3 (KX_EXIT_REQUEST_START_OTHER_GAME) load a different file - if (exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME || exitrequested == KX_EXIT_REQUEST_RESTART_GAME) - { - exitrequested = KX_EXIT_REQUEST_NO_REQUEST; - if (bfd) BLO_blendfiledata_free(bfd); - - char basedpath[160]; - // base the actuator filename with respect - // to the original file working directory - if (exitstring != "") - strcpy(basedpath, exitstring.Ptr()); - - BLI_convertstringcode(basedpath, pathname, 0); - bfd = load_game_data(basedpath); - - // if it wasn't loaded, try it forced relative - if (!bfd) - { - // just add "//" in front of it - char temppath[162]; - strcpy(temppath, "//"); - strcat(temppath, basedpath); - - BLI_convertstringcode(temppath, pathname, 0); - bfd = load_game_data(temppath); - } - - // if we got a loaded blendfile, proceed - if (bfd) - { - blenderdata = bfd->main; - startscenename = bfd->curscene->id.name + 2; - } - // else forget it, we can't find it - else - { - exitrequested = KX_EXIT_REQUEST_QUIT_GAME; - } - } -*/ Scene *blscene = NULL; if (!bfd) { @@ -652,18 +564,11 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, if (exitrequested != KX_EXIT_REQUEST_QUIT_GAME) { - /*if (v3d->persp != 2) - { - ketsjiengine->EnableCameraOverride(startscenename); - ketsjiengine->SetCameraOverrideUseOrtho((v3d->persp == 0)); - ketsjiengine->SetCameraOverrideProjectionMatrix(projmat); - ketsjiengine->SetCameraOverrideViewMatrix(viewmat); - }*/ - // create a scene converter, create and convert the startingscene KX_ISceneConverter* sceneconverter = new KX_BlenderSceneConverter(maggie,sipo, ketsjiengine); ketsjiengine->SetSceneConverter(sceneconverter); - + sceneconverter->addInitFromFrame=true; + if (always_use_expand_framing) sceneconverter->SetAlwaysUseExpandFraming(true); @@ -675,7 +580,6 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, networkdevice, audiodevice, startscenename); - // some python things PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest); ketsjiengine->SetPythonDictionary(dictionaryobject); @@ -696,9 +600,6 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, canvas); ketsjiengine->AddScene(startscene); - // init the rasterizer - //rasterizer->Init(); - // start the engine ketsjiengine->StartEngine(false); @@ -708,38 +609,22 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, printf("frame %i\n",blscene->r.cfra); // first check if we want to exit exitrequested = ketsjiengine->GetExitCode(); - + /*for (int ix=0;i<geobjs->GetCount();ix++){ + KX_GameObject* gameobj = (KX_GameObject*) geobjs->GetValue(ix); + if (!gameobj->IsDynamic()){ + //gameobj->UpdateNonDynas();//UpdateIPO((float)blscene->r.cfra,true, true, true); + struct Object* blenderobject = sceneconverter->FindBlenderObject(gameobj); + } + }*/ + + // kick the engine ketsjiengine->NextFrame(); blscene->r.cfra=blscene->r.cfra+1; update_for_newframe(); - // render the frame - //ketsjiengine->Render(); - - // test for the ESC key - /*while (qtest()) - { - short val; - unsigned short event = extern_qread(&val); - - if (keyboarddevice->ConvertBlenderEvent(event,val)) - exitrequested = KX_EXIT_REQUEST_BLENDER_ESC; - - if (event==MOUSEX) { - val = val - scrarea_get_win_x(area); - } else if (event==MOUSEY) { - val = scrarea_get_win_height(area) - (val - scrarea_get_win_y(area)) - 1; - } - - mousedevice->ConvertBlenderEvent(event,val); - }*/ + } exitstring = ketsjiengine->GetExitString(); - // when exiting the mainloop - //dictionaryClearByHand(gameLogic); - //ketsjiengine->StopEngine(); - //exitGamePythonScripting(); - //networkdevice->Disconnect(); } if (sceneconverter) { @@ -778,21 +663,6 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, delete mousedevice; mousedevice = NULL; } - /*if (rasterizer) - { - delete rasterizer; - rasterizer = NULL; - } - if (rendertools) - { - delete rendertools; - rendertools = NULL; - } - if (canvas) - { - delete canvas; - canvas = NULL; - }*/ SND_DeviceManager::Unsubscribe(); } while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME); diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index a496c60639f..8f4f692eab4 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -167,6 +167,18 @@ #include "BL_ArmatureObject.h" #include "BL_DeformableGameObject.h" +#ifdef __cplusplus +extern "C" { +#endif +#include "BSE_headerbuttons.h" +void update_for_newframe(); +//void scene_update_for_newframe(struct Scene *sce, unsigned int lay); +//#include "BKE_ipo.h" +//void do_all_data_ipos(void); +#ifdef __cplusplus +} +#endif + static int default_face_mode = TF_DYNAMIC; static unsigned int KX_rgbaint2uint_new(unsigned int icol) @@ -1618,7 +1630,7 @@ KX_GameObject* getGameOb(STR_String busc,CListValue* sumolist){ return 0; } - +#include "BLI_arithb.h" // convert blender objects into ketsji gameobjects void BL_ConvertBlenderObjects(struct Main* maggie, const STR_String& scenename, @@ -1642,6 +1654,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, RAS_FrameSettings::RAS_FrameType frame_type; int aspect_width; int aspect_height; + vector<MT_Vector3> inivel,iniang; if (alwaysUseExpandFraming) { frame_type = RAS_FrameSettings::e_frame_extend; @@ -1720,6 +1733,10 @@ void BL_ConvertBlenderObjects(struct Main* maggie, if (gameobj) { + MT_Point3 posPrev; + MT_Matrix3x3 angor; + if (converter->addInitFromFrame) blenderscene->r.cfra=blenderscene->r.sfra; + MT_Point3 pos = MT_Point3( blenderobject->loc[0]+blenderobject->dloc[0], blenderobject->loc[1]+blenderobject->dloc[1], @@ -1735,7 +1752,26 @@ void BL_ConvertBlenderObjects(struct Main* maggie, blenderobject->size[1], blenderobject->size[2] ); - + if (converter->addInitFromFrame){//rcruiz + float eulxyzPrev[3]; + blenderscene->r.cfra=blenderscene->r.sfra-1; + update_for_newframe(); + MT_Vector3 tmp=pos-MT_Point3(blenderobject->loc[0]+blenderobject->dloc[0], + blenderobject->loc[1]+blenderobject->dloc[1], + blenderobject->loc[2]+blenderobject->dloc[2] + ); + eulxyzPrev[0]=blenderobject->rot[0]; + eulxyzPrev[1]=blenderobject->rot[1]; + eulxyzPrev[2]=blenderobject->rot[2]; + tmp.scale((float)blenderscene->r.frs_sec,(float)blenderscene->r.frs_sec,(float)blenderscene->r.frs_sec); + inivel.push_back(tmp); + tmp=eulxyz-eulxyzPrev; + tmp.scale((float)blenderscene->r.frs_sec,(float)blenderscene->r.frs_sec,(float)blenderscene->r.frs_sec); + iniang.push_back(tmp); + blenderscene->r.cfra=blenderscene->r.sfra; + update_for_newframe(); + } + gameobj->NodeSetLocalPosition(pos); gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz)); gameobj->NodeSetLocalScale(scale); @@ -1759,7 +1795,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, templist->Add(gameobj->AddRef()); // update children/parent hierarchy - if (blenderobject->parent != 0) + if ((blenderobject->parent != 0)&&(!converter->addInitFromFrame)) { // blender has an additional 'parentinverse' offset in each object SG_Node* parentinversenode = new SG_Node(NULL,NULL,SG_Callbacks()); @@ -1790,12 +1826,15 @@ void BL_ConvertBlenderObjects(struct Main* maggie, logicmgr->RegisterGameMeshName(gameobj->GetMesh(i)->GetName(), blenderobject); converter->RegisterGameObject(gameobj, blenderobject); - // this was put in rapidly, needs to be looked at more closely // only draw/use objects in active 'blender' layers logicbrick_conversionlist->Add(gameobj->AddRef()); + if (converter->addInitFromFrame){ + posPrev=gameobj->NodeGetWorldPosition(); + angor=gameobj->NodeGetWorldOrientation(); + } if (isInActiveLayer) { objectlist->Add(gameobj->AddRef()); @@ -1805,7 +1844,11 @@ void BL_ConvertBlenderObjects(struct Main* maggie, gameobj->Bucketize(); } - + if (converter->addInitFromFrame){ + gameobj->NodeSetLocalPosition(posPrev); + gameobj->NodeSetLocalOrientation(angor); + } + } base = base->next; @@ -1928,6 +1971,20 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,activeLayerBitInfo,physics_engine,converter,processCompoundChildren); } + + + //set ini linearVel and int angularVel //rcruiz + if (converter->addInitFromFrame) + for (i=0;i<sumolist->GetCount();i++) + { + KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i); + if (gameobj->IsDynamic()){ + gameobj->setLinearVelocity(inivel[i],false); + gameobj->setAngularVelocity(iniang[i],false); + } + + + } // create physics joints for (i=0;i<sumolist->GetCount();i++) @@ -1956,8 +2013,19 @@ void BL_ConvertBlenderObjects(struct Main* maggie, if (gameobj->GetPhysicsController()) { PHY_IPhysicsController* physctrl = (PHY_IPhysicsController*) gameobj->GetPhysicsController()->GetUserData(); + //we need to pass a full constraint frame, not just axis - int constraintId = 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); + //localConstraintFrameBasis + MT_Matrix3x3 localCFrame(MT_Vector3(dat->axX,dat->axY,dat->axZ)); + MT_Vector3 axis0 = localCFrame.getColumn(0); + MT_Vector3 axis1 = localCFrame.getColumn(1); + MT_Vector3 axis2 = localCFrame.getColumn(2); + + int constraintId = kxscene->GetPhysicsEnvironment()->createConstraint(physctrl,physctr2,(PHY_ConstraintType)dat->type,(float)dat->pivX,(float)dat->pivY,(float)dat->pivZ, + (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() + ); //if it is a generic 6DOF constraint, set all the limits accordingly if (dat->type == PHY_GENERIC_6DOF_CONSTRAINT) { @@ -1984,40 +2052,9 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } - //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(); - int executePriority=0; /* incremented by converter routines */ // convert global sound stuff diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 10f3ea39616..75c0e54eb68 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -77,6 +77,8 @@ #include "DNA_world_types.h" #include "BKE_main.h" +#include "BLI_arithb.h" + extern "C" { #include "DNA_object_types.h" @@ -560,7 +562,8 @@ IpoCurve* findIpoCurve(IpoCurve* first,char* searchName) return 0; } -Ipo* KX_BlenderSceneConverter::findIpoForName(char* objName) +// this is not longer necesary //rcruiz +/*Ipo* KX_BlenderSceneConverter::findIpoForName(char* objName) { Ipo* ipo_iter = (Ipo*)m_maggie->ipo.first; @@ -574,7 +577,7 @@ Ipo* KX_BlenderSceneConverter::findIpoForName(char* objName) } return 0; } - +*/ void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo) { @@ -600,29 +603,35 @@ void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo) if (blenderObject) { //erase existing ipo's - Ipo* ipo = findIpoForName(blenderObject->id.name+2); + Ipo* ipo = blenderObject->ipo;//findIpoForName(blenderObject->id.name+2); if (ipo) - { - //clear the curve data - if (clearIpo){ - IpoCurve *icu1; - int numCurves = 0; - for( icu1 = (IpoCurve*)ipo->curve.first; icu1; ) { + { //clear the curve data + if (clearIpo){//rcruiz + IpoCurve *icu1; + + int numCurves = 0; + for( icu1 = (IpoCurve*)ipo->curve.first; icu1; ) { - IpoCurve* tmpicu = icu1; - icu1 = icu1->next; - numCurves++; + IpoCurve* tmpicu = icu1; + + /*int i; + BezTriple *bezt; + for( bezt = tmpicu->bezt, i = 0; i < tmpicu->totvert; i++, bezt++){ + printf("(%f,%f,%f),(%f,%f,%f),(%f,%f,%f)\n",bezt->vec[0][0],bezt->vec[0][1],bezt->vec[0][2],bezt->vec[1][0],bezt->vec[1][1],bezt->vec[1][2],bezt->vec[2][0],bezt->vec[2][1],bezt->vec[2][2]); + }*/ + + icu1 = icu1->next; + numCurves++; - BLI_remlink( &( blenderObject->ipo->curve ), tmpicu ); - if( tmpicu->bezt ) - MEM_freeN( tmpicu->bezt ); - MEM_freeN( tmpicu ); - localDel_ipoCurve( tmpicu ,m_sipo); - } - } + BLI_remlink( &( blenderObject->ipo->curve ), tmpicu ); + if( tmpicu->bezt ) + MEM_freeN( tmpicu->bezt ); + MEM_freeN( tmpicu ); + localDel_ipoCurve( tmpicu ,m_sipo); + } + } } else - { - ipo = add_ipo(blenderObject->id.name+2, ID_OB); + { ipo = add_ipo(blenderObject->id.name+2, ID_OB); blenderObject->ipo = ipo; } @@ -643,6 +652,48 @@ void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo) } +void KX_BlenderSceneConverter::resetNoneDynamicObjectToIpo(){ + + if (addInitFromFrame){ + KX_SceneList* scenes = m_ketsjiEngine->CurrentScenes(); + int numScenes = scenes->size(); + if (numScenes>=0){ + KX_Scene* scene = scenes->at(0); + CListValue* parentList = scene->GetRootParentList(); + for (int ix=0;ix<parentList->GetCount();ix++){ + KX_GameObject* gameobj = (KX_GameObject*)parentList->GetValue(ix); + if (!gameobj->IsDynamic()){ + Object* blenderobject = FindBlenderObject(gameobj); + if (!blenderobject) + continue; + if (blenderobject->type==OB_ARMATURE) + continue; + float eu[3]; + Mat4ToEul(blenderobject->obmat,eu); + MT_Point3 pos = MT_Point3( + blenderobject->obmat[3][0], + blenderobject->obmat[3][1], + blenderobject->obmat[3][2] + ); + MT_Vector3 eulxyz = MT_Vector3( + eu[0], + eu[1], + eu[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); + } + } + } + } +} #define TEST_HANDLES_GAME2IPO 0 @@ -797,9 +848,8 @@ void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber) } - } - - + } + } diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.h b/source/gameengine/Converter/KX_BlenderSceneConverter.h index c4447c53930..a897922d51b 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.h +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.h @@ -76,7 +76,7 @@ class KX_BlenderSceneConverter : public KX_ISceneConverter bool m_usemat; void localDel_ipoCurve ( IpoCurve * icu ,struct SpaceIpo* sipo); - struct Ipo* findIpoForName(char* objName); +// struct Ipo* findIpoForName(char* objName); public: KX_BlenderSceneConverter( @@ -132,6 +132,9 @@ public: virtual void ResetPhysicsObjectsAnimationIpo(bool clearIpo); + ///this is for reseting the position,rotation and scale of the gameobjet that is not dynamic + virtual void resetNoneDynamicObjectToIpo(); + ///this generates ipo curves for position, rotation, allowing to use game physics in animation virtual void WritePhysicsObjectToAnimationIpo(int frameNumber); virtual void TestHandlesPhysicsObjectToAnimationIpo(); diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp index 6785cb957bc..aa5d1f1cec1 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp @@ -86,7 +86,8 @@ void KX_BulletPhysicsController::ApplyForce(const MT_Vector3& force,bool local) MT_Vector3 KX_BulletPhysicsController::GetLinearVelocity() { float angVel[3]; - CcdPhysicsController::GetAngularVelocity(angVel[0],angVel[1],angVel[2]); + //CcdPhysicsController::GetAngularVelocity(angVel[0],angVel[1],angVel[2]); + CcdPhysicsController::GetLinearVelocity(angVel[0],angVel[1],angVel[2]);//rcruiz return MT_Vector3(angVel[0],angVel[1],angVel[2]); } MT_Vector3 KX_BulletPhysicsController::GetVelocity(const MT_Point3& pos) diff --git a/source/gameengine/Ketsji/KX_ISceneConverter.h b/source/gameengine/Ketsji/KX_ISceneConverter.h index 8693eb34d6b..2727ce7746e 100644 --- a/source/gameengine/Ketsji/KX_ISceneConverter.h +++ b/source/gameengine/Ketsji/KX_ISceneConverter.h @@ -59,14 +59,18 @@ public: virtual void SetNewFileName(const STR_String& filename) = 0; virtual bool TryAndLoadNewFile() = 0; - + bool addInitFromFrame;//rcruiz virtual void ResetPhysicsObjectsAnimationIpo(bool clearIpo) = 0; + ///this generates ipo curves for position, rotation, allowing to use game physics in animation virtual void WritePhysicsObjectToAnimationIpo(int frameNumber) = 0; virtual void TestHandlesPhysicsObjectToAnimationIpo() = 0; + ///this is for reseting the position,rotation and scale of the gameobjet that is not dynamic + virtual void resetNoneDynamicObjectToIpo()=0; + // use blender materials virtual void SetMaterials(bool val) =0; virtual bool GetMaterials()=0; diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 2e0c5d713dc..e76e28bcb7b 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -394,6 +394,9 @@ else * the settings for that preceed the logic and physics * update. */ m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true); + + m_sceneconverter->resetNoneDynamicObjectToIpo();//this is for none dynamic objects with ipo + scene->UpdateObjectActivity(); if (!scene->IsSuspended()) @@ -456,7 +459,7 @@ else if (m_game2ipo) - { + { m_sceneconverter->WritePhysicsObjectToAnimationIpo(++m_currentFrame); } diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index edd4c2e2bb4..57fe533825e 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -1002,7 +1002,10 @@ PHY_IPhysicsController* CcdPhysicsEnvironment::CreateSphereController(float radi int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl0,class PHY_IPhysicsController* ctrl1,PHY_ConstraintType type, float pivotX,float pivotY,float pivotZ, - float axisX,float axisY,float axisZ) + float axisX,float axisY,float axisZ, + float axis1X,float axis1Y,float axis1Z, + float axis2X,float axis2Y,float axis2Z + ) { @@ -1066,9 +1069,12 @@ int CcdPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl btTransform frameInA; btTransform frameInB; - btVector3 axis1, axis2; - btPlaneSpace1( axisInA, axis1, axis2 ); - + btVector3 axis1(axis1X,axis1Y,axis1Z), axis2(axis2X,axis2Y,axis2Z); + if (axis1.length() == 0.0) + { + btPlaneSpace1( axisInA, axis1, axis2 ); + } + frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(), axisInA.y(), axis1.y(), axis2.y(), axisInA.z(), axis1.z(), axis2.z() ); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h index 9a8fc3f435d..66a6ed59c17 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h @@ -117,7 +117,10 @@ protected: virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type, float pivotX,float pivotY,float pivotZ, - float axisX,float axisY,float axisZ); + float axisX,float axisY,float axisZ, + float axis1X=0,float axis1Y=0,float axis1Z=0, + float axis2X=0,float axis2Y=0,float axis2Z=0 + ); //Following the COLLADA physics specification for constraints diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp index 0532a9a8cf7..b40d1b430bb 100644 --- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp @@ -93,7 +93,11 @@ void DummyPhysicsEnvironment::setGravity(float x,float y,float z) int DummyPhysicsEnvironment::createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type, - float pivotX,float pivotY,float pivotZ,float axisX,float axisY,float axisZ) + float pivotX,float pivotY,float pivotZ,float axisX,float axisY,float axisZ, + float axis1X,float axis1Y,float axis1Z, + float axis2X,float axis2Y,float axis2Z + + ) { int constraintid = 0; diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h index bd4e00e9fa5..4fc970da699 100644 --- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h +++ b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h @@ -59,7 +59,10 @@ public: virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type, float pivotX,float pivotY,float pivotZ, - float axisX,float axisY,float axisZ); + float axisX,float axisY,float axisZ, + float axis1X=0,float axis1Y=0,float axis1Z=0, + float axis2X=0,float axis2Y=0,float axis2Z=0 + ); virtual void removeConstraint(int constraintid); diff --git a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.cpp b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.cpp index ead6dcc0106..6cdf1d41dc1 100644 --- a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.cpp @@ -111,7 +111,11 @@ int SumoPhysicsEnvironment::createConstraint( class PHY_IPhysicsController* ctrl2, PHY_ConstraintType type, float pivotX,float pivotY,float pivotZ, - float axisX,float axisY,float axisZ) + float axisX,float axisY,float axisZ, + float axis1X,float axis1Y,float axis1Z, + float axis2X,float axis2Y,float axis2Z + + ) { int constraintid = 0; return constraintid; diff --git a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h index 1afb9433500..4d17d0c21fd 100644 --- a/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h +++ b/source/gameengine/Physics/Sumo/SumoPhysicsEnvironment.h @@ -64,7 +64,11 @@ public: virtual void setGravity(float x,float y,float z); virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type, float pivotX,float pivotY,float pivotZ, - float axisX,float axisY,float axisZ); + float axisX,float axisY,float axisZ, + float axis1X=0,float axis1Y=0,float axis1Z=0, + float axis2X=0,float axis2Y=0,float axis2Z=0 + + ); virtual void removeConstraint(int constraintid); diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h index 2716baa0d6d..5e4fd681914 100644 --- a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h +++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h @@ -86,7 +86,10 @@ class PHY_IPhysicsEnvironment virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type, float pivotX,float pivotY,float pivotZ, - float axisX,float axisY,float axisZ)=0; + float axis0X,float axis0Y,float axis0Z, + float axis1X=0,float axis1Y=0,float axis1Z=0, + float axis2X=0,float axis2Y=0,float axis2Z=0 + )=0; virtual void removeConstraint(int constraintid)=0; virtual float getAppliedImpulse(int constraintid){ return 0.f;} |