diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2005-11-06 19:50:22 +0300 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2005-11-06 19:50:22 +0300 |
commit | dfce9d7d9be49d0c2ec95ef765c7a930e2f7d7c7 (patch) | |
tree | caa195bbfcced6292dccfbfb8e4a8032be76b33a | |
parent | d1be55f41c47aead9ba21723633d3ab195f5113d (diff) |
minor cleanup. Todo: Does 'testhandles' need to be called after every single ipo_insert_vert ?
4 files changed, 127 insertions, 434 deletions
diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 6ba96e3a211..34b9b065c12 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -547,7 +547,6 @@ Ipo* KX_BlenderSceneConverter::findIpoForName(char* objName) void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo() { - //todo,before 2.38/2.40 release, Erwin KX_SceneList* scenes = m_ketsjiEngine->CurrentScenes(); int numScenes = scenes->size(); @@ -612,7 +611,7 @@ void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo() } - +#define TEST_HANDLES_GAME2IPO 0 ///this generates ipo curves for position, rotation, allowing to use game physics in animation void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber) @@ -703,42 +702,59 @@ void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber) { float curVal = position.x(); insert_vert_ipo(icu1, frameNumber, curVal); +#ifdef TEST_HANDLES_GAME2IPO testhandles_ipocurve(icu1); +#endif } icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"LocY"); if (icu1) { float curVal = position.y(); insert_vert_ipo(icu1, frameNumber, curVal); +#ifdef TEST_HANDLES_GAME2IPO + testhandles_ipocurve(icu1); +#endif } icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"LocZ"); if (icu1) { float curVal = position.z(); insert_vert_ipo(icu1, frameNumber, curVal); +#ifdef TEST_HANDLES_GAME2IPO testhandles_ipocurve(icu1); +#endif } icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"RotX"); if (icu1) { float curVal = eulerAngles[0]; insert_vert_ipo(icu1, frameNumber, curVal); +#ifdef TEST_HANDLES_GAME2IPO + testhandles_ipocurve(icu1); +#endif } icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"RotY"); if (icu1) { float curVal = eulerAngles[1]; insert_vert_ipo(icu1, frameNumber, curVal); +#ifdef TEST_HANDLES_GAME2IPO + testhandles_ipocurve(icu1); +#endif } icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"RotZ"); if (icu1) { float curVal = eulerAngles[2]; insert_vert_ipo(icu1, frameNumber, curVal); +#ifdef TEST_HANDLES_GAME2IPO + testhandles_ipocurve(icu1); +#endif + } } @@ -751,467 +767,133 @@ void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber) } - //todo, before 2.38/2.40 release, Erwin -#ifdef TURN_THIS_PYTHON_CODE_INTO_CPP - //all stuff needed to bake keyframes into blender objects - //this allows physics simulation of the game engine to be automatically turned into blender ipo curves - //so bullet physics can be used for animations +} +void KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo() +{ + + KX_SceneList* scenes = m_ketsjiEngine->CurrentScenes(); + int numScenes = scenes->size(); + int i; + for (i=0;i<numScenes;i++) + { + KX_Scene* scene = scenes->at(i); + //PHY_IPhysicsEnvironment* physEnv = scene->GetPhysicsEnvironment(); + CListValue* parentList = scene->GetRootParentList(); + int numObjects = parentList->GetCount(); + int g; + for (g=0;g<numObjects;g++) + { + KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g); + if (gameObj->IsDynamic()) + { + KX_IPhysicsController* physCtrl = gameObj->GetPhysicsController(); + + Object* blenderObject = FindBlenderObject(gameObj); + if (blenderObject) + { - static PyObject *Ipo_getCurve( BPy_Ipo * self, PyObject * args ) + const MT_Matrix3x3& orn = gameObj->NodeGetWorldOrientation(); + float eulerAngles[3]; + float tmat[3][3]; + for (int r=0;r<3;r++) + { + for (int c=0;c<3;c++) { - char *str, *str1; - IpoCurve *icu = 0; + tmat[r][c] = orn[c][r]; + } + } + Mat3ToEul(tmat, eulerAngles); + + for(int x = 0; x < 3; x++) { + eulerAngles[x] *= (float) (180 / 3.14159265f); + } - if( !PyArg_ParseTuple( args, "s", &str ) ) - return ( EXPP_ReturnPyObjError - ( PyExc_TypeError, "expected string argument" ) ); + eulerAngles[0]/=10.f; + eulerAngles[1]/=10.f; + eulerAngles[2]/=10.f; - for( icu = self->ipo->curve.first; icu; icu = icu->next ) { - str1 = getIpoCurveName( icu ); - if( !strcmp( str1, str ) ) - return IpoCurve_CreatePyObject( icu ); - } - Py_INCREF( Py_None ); - return Py_None; - } - static PyObject *Ipo_addCurve( BPy_Ipo * self, PyObject * args ) - { - int param = 0; /* numeric curve name constant */ - int ok = 0; - int ipofound = 0; - char *cur_name = 0; /* input arg: curve name */ - Ipo *ipo = 0; - IpoCurve *icu = 0; - Link *link; - - if( !PyArg_ParseTuple( args, "s", &cur_name ) ) - return ( EXPP_ReturnPyObjError - ( PyExc_TypeError, "expected string argument" ) ); - - - /* chase down the ipo list looking for ours */ - link = G.main->ipo.first; - - while( link ) { - ipo = ( Ipo * ) link; - if( ipo == self->ipo ) { - ipofound = 1; - break; - } - link = link->next; - } - - if( ipo && ipofound ) { - /* ok. continue */ - } else { /* runtime error here: our ipo not found */ - return ( EXPP_ReturnPyObjError - ( PyExc_RuntimeError, "Ipo not found" ) ); - } - - - /* - depending on the block type, - check if the input arg curve name is valid - and set param to numeric value. - */ - switch ( ipo->blocktype ) { - case ID_OB: - ok = Ipo_obIcuName( cur_name, ¶m ); - break; - case ID_CA: - ok = Ipo_caIcuName( cur_name, ¶m ); - break; - case ID_LA: - ok = Ipo_laIcuName( cur_name, ¶m ); - break; - case ID_TE: - ok = Ipo_texIcuName( cur_name, ¶m ); - break; - case ID_WO: - ok = Ipo_woIcuName( cur_name, ¶m ); - break; - case ID_MA: - ok = Ipo_maIcuName( cur_name, ¶m ); - break; - case ID_AC: - ok = Ipo_acIcuName( cur_name, ¶m ); - break; - case IPO_CO: - ok = Ipo_coIcuName( cur_name, ¶m ); - break; - case ID_CU: - ok = Ipo_cuIcuName( cur_name, ¶m ); - break; - case ID_KE: - ok = Ipo_keIcuName( cur_name, ¶m ); - break; - case ID_SEQ: - ok = Ipo_seqIcuName( cur_name, ¶m ); - break; - default: - ok = 0; - } - - if( !ok ) /* curve type was invalid */ - return EXPP_ReturnPyObjError - ( PyExc_NameError, "curve name was invalid" ); - - /* ask blender to create the new ipo curve */ - icu = verify_ipocurve( NULL, ipo->blocktype, NULL, NULL, param); - - if( icu == 0 ) /* could not create curve */ - return EXPP_ReturnPyObjError - ( PyExc_RuntimeError, - "blender could not create ipo curve" ); - - allspace( REMAKEIPO, 0 ); - EXPP_allqueue( REDRAWIPO, 0 ); - - /* create a bpy wrapper for the new ipo curve */ - return IpoCurve_CreatePyObject( icu ); - } + const MT_Vector3& scale = gameObj->NodeGetWorldScaling(); + const MT_Point3& position = gameObj->NodeGetWorldPosition(); + + Ipo* ipo = blenderObject->ipo; + if (ipo) + { - static PyObject *Ipo_getNcurves( BPy_Ipo * self ) - { - int i = 0; + //create the curves, if not existing - IpoCurve *icu; - for( icu = self->ipo->curve.first; icu; icu = icu->next ) { - i++; - } + IpoCurve *icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"LocX"); + if (!icu1) + icu1 = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, OB_LOC_X); + + icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"LocY"); + if (!icu1) + icu1 = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, OB_LOC_Y); + + icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"LocZ"); + if (!icu1) + icu1 = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, OB_LOC_Z); - return ( PyInt_FromLong( i ) ); - } + icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"RotX"); + if (!icu1) + icu1 = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, OB_ROT_X); + + icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"RotY"); + if (!icu1) + icu1 = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, OB_ROT_Y); + + icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"RotZ"); + if (!icu1) + icu1 = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, OB_ROT_Z); - static PyObject *Ipo_getNBezPoints( BPy_Ipo * self, PyObject * args ) + + //fill the curves with data + + icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"LocX"); + if (icu1) { - int num = 0, i = 0; - IpoCurve *icu = 0; - if( !PyArg_ParseTuple( args, "i", &num ) ) - return ( EXPP_ReturnPyObjError - ( PyExc_TypeError, "expected int argument" ) ); - icu = self->ipo->curve.first; - if( !icu ) - return ( EXPP_ReturnPyObjError - ( PyExc_TypeError, "No IPO curve" ) ); - for( i = 0; i < num; i++ ) { - if( !icu ) - return ( EXPP_ReturnPyObjError - ( PyExc_TypeError, "Bad curve number" ) ); - icu = icu->next; - - } - return ( PyInt_FromLong( icu->totvert ) ); + testhandles_ipocurve(icu1); } - - static PyObject *Ipo_DeleteBezPoints( BPy_Ipo * self, PyObject * args ) + icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"LocY"); + if (icu1) { - int num = 0, i = 0; - IpoCurve *icu = 0; - if( !PyArg_ParseTuple( args, "i", &num ) ) - return ( EXPP_ReturnPyObjError - ( PyExc_TypeError, "expected int argument" ) ); - icu = self->ipo->curve.first; - if( !icu ) - return ( EXPP_ReturnPyObjError - ( PyExc_TypeError, "No IPO curve" ) ); - for( i = 0; i < num; i++ ) { - if( !icu ) - return ( EXPP_ReturnPyObjError - ( PyExc_TypeError, "Bad curve number" ) ); - icu = icu->next; - - } - icu->totvert--; - return ( PyInt_FromLong( icu->totvert ) ); + testhandles_ipocurve(icu1); } - - /*****************************************************************************/ - /* Function: M_Object_Get */ - /* Python equivalent: Blender.Object.Get */ - /*****************************************************************************/ - PyObject *M_Object_Get( PyObject * self, PyObject * args ) + icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"LocZ"); + if (icu1) { - struct Object *object; - BPy_Object *blen_object; - char *name = NULL; - - PyArg_ParseTuple( args, "|s", &name ); - - if( name != NULL ) { - object = GetObjectByName( name ); - - if( object == NULL ) { - /* No object exists with the name specified in the argument name. */ - return ( EXPP_ReturnPyObjError( PyExc_AttributeError, - "Unknown object specified." ) ); - } - blen_object = - ( BPy_Object * ) PyObject_NEW( BPy_Object, - &Object_Type ); - blen_object->object = object; - - return ( ( PyObject * ) blen_object ); - } else { - /* No argument has been given. Return a list of all objects. */ - PyObject *obj_list; - Link *link; - int index; - - obj_list = PyList_New( BLI_countlist( &( G.main->object ) ) ); - - if( obj_list == NULL ) { - return ( EXPP_ReturnPyObjError( PyExc_SystemError, - "List creation failed." ) ); - } - - link = G.main->object.first; - index = 0; - while( link ) { - object = ( Object * ) link; - blen_object = - ( BPy_Object * ) PyObject_NEW( BPy_Object, - &Object_Type ); - blen_object->object = object; - - PyList_SetItem( obj_list, index, - ( PyObject * ) blen_object ); - index++; - link = link->next; - } - return ( obj_list ); - } + testhandles_ipocurve(icu1); } - - - static PyObject *M_Ipo_New( PyObject * self, PyObject * args ) + icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"RotX"); + if (icu1) { - Ipo *add_ipo( char *name, int idcode ); - char *name = NULL, *code = NULL; - int idcode = -1; - BPy_Ipo *pyipo; - Ipo *blipo; - - if( !PyArg_ParseTuple( args, "ss", &code, &name ) ) - return ( EXPP_ReturnPyObjError - ( PyExc_TypeError, - "expected string string arguments" ) ); - - if( !strcmp( code, "Object" ) ) - idcode = ID_OB; - if( !strcmp( code, "Camera" ) ) - idcode = ID_CA; - if( !strcmp( code, "World" ) ) - idcode = ID_WO; - if( !strcmp( code, "Material" ) ) - idcode = ID_MA; - if( !strcmp( code, "Texture" ) ) - idcode = ID_TE; - if( !strcmp( code, "Lamp" ) ) - idcode = ID_LA; - if( !strcmp( code, "Action" ) ) - idcode = ID_AC; - if( !strcmp( code, "Constraint" ) ) - idcode = IPO_CO; - if( !strcmp( code, "Sequence" ) ) - idcode = ID_SEQ; - if( !strcmp( code, "Curve" ) ) - idcode = ID_CU; - if( !strcmp( code, "Key" ) ) - idcode = ID_KE; - - if( idcode == -1 ) - return ( EXPP_ReturnPyObjError - ( PyExc_TypeError, "Bad code" ) ); - - - blipo = add_ipo( name, idcode ); - - if( blipo ) { - /* return user count to zero because add_ipo() inc'd it */ - blipo->id.us = 0; - /* create python wrapper obj */ - pyipo = ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo, &Ipo_Type ); - } else - return ( EXPP_ReturnPyObjError( PyExc_RuntimeError, - "couldn't create Ipo Data in Blender" ) ); - - if( pyipo == NULL ) - return ( EXPP_ReturnPyObjError( PyExc_MemoryError, - "couldn't create Ipo Data object" ) ); - - pyipo->ipo = blipo; - - return ( PyObject * ) pyipo; + testhandles_ipocurve(icu1); } - - - - static PyObject *Object_setIpo( BPy_Object * self, PyObject * args ) + icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"RotY"); + if (icu1) { - PyObject *pyipo = 0; - Ipo *ipo = NULL; - Ipo *oldipo; - - if( !PyArg_ParseTuple( args, "O!", &Ipo_Type, &pyipo ) ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "expected Ipo as argument" ); - - ipo = Ipo_FromPyObject( pyipo ); - - if( !ipo ) - return EXPP_ReturnPyObjError( PyExc_RuntimeError, - "null ipo!" ); - - if( ipo->blocktype != ID_OB ) - return EXPP_ReturnPyObjError( PyExc_TypeError, - "this ipo is not an object ipo" ); - - oldipo = self->object->ipo; - if( oldipo ) { - ID *id = &oldipo->id; - if( id->us > 0 ) - id->us--; - } - - ( ( ID * ) & ipo->id )->us++; - - self->object->ipo = ipo; - - Py_INCREF( Py_None ); - return Py_None; + testhandles_ipocurve(icu1); } - - - static PyObject *M_Ipo_Get( PyObject * self, PyObject * args ) + icu1 = findIpoCurve((IpoCurve *)ipo->curve.first,"RotZ"); + if (icu1) { - char *name = NULL; - Ipo *ipo_iter; - PyObject *ipolist, *pyobj; - BPy_Ipo *wanted_ipo = NULL; - char error_msg[64]; - - if( !PyArg_ParseTuple( args, "|s", &name ) ) - return ( EXPP_ReturnPyObjError( PyExc_TypeError, - "expected string argument (or nothing)" ) ); - - ipo_iter = G.main->ipo.first; - - if( name ) { /* (name) - Search ipo by name */ - while( ( ipo_iter ) && ( wanted_ipo == NULL ) ) { - if( strcmp( name, ipo_iter->id.name + 2 ) == 0 ) { - wanted_ipo = - ( BPy_Ipo * ) PyObject_NEW( BPy_Ipo, - &Ipo_Type ); - if( wanted_ipo ) - wanted_ipo->ipo = ipo_iter; - } - ipo_iter = ipo_iter->id.next; - } - - if( wanted_ipo == NULL ) { /* Requested ipo doesn't exist */ - PyOS_snprintf( error_msg, sizeof( error_msg ), - "Ipo \"%s\" not found", name ); - return ( EXPP_ReturnPyObjError - ( PyExc_NameError, error_msg ) ); - } - - return ( PyObject * ) wanted_ipo; - } - - else { /* () - return a list with all ipos in the scene */ - int index = 0; - - ipolist = PyList_New( BLI_countlist( &( G.main->ipo ) ) ); - - if( ipolist == NULL ) - return ( EXPP_ReturnPyObjError( PyExc_MemoryError, - "couldn't create PyList" ) ); - - while( ipo_iter ) { - pyobj = Ipo_CreatePyObject( ipo_iter ); - - if( !pyobj ) - return ( EXPP_ReturnPyObjError - ( PyExc_MemoryError, - "couldn't create PyString" ) ); - - PyList_SET_ITEM( ipolist, index, pyobj ); - - ipo_iter = ipo_iter->id.next; - index++; - } - - return ( ipolist ); - } + testhandles_ipocurve(icu1); } + } + } + } - - static PyObject *M_Ipo_Recalc( PyObject * self, PyObject * args ) - { - void testhandles_ipocurve( IpoCurve * icu ); - PyObject *a; - IpoCurve *icu; - if( !PyArg_ParseTuple( args, "O", &a ) ) - return ( EXPP_ReturnPyObjError - ( PyExc_TypeError, "expected ipo argument)" ) ); - icu = IpoCurve_FromPyObject( a ); - testhandles_ipocurve( icu ); - - Py_INCREF( Py_None ); - return Py_None; - - } + } + + + } - static PyObject *IpoCurve_addBezier( C_IpoCurve * self, PyObject * args ) - { - short MEM_freeN( void *vmemh ); - void *MEM_mallocN( unsigned int len, char *str ); - float x, y; - int npoints; - IpoCurve *icu; - BezTriple *bzt, *tmp; - static char name[10] = "mlml"; - PyObject *popo = 0; - if( !PyArg_ParseTuple( args, "O", &popo ) ) - return ( EXPP_ReturnPyObjError - ( PyExc_TypeError, "expected tuple argument" ) ); - - x = (float)PyFloat_AsDouble( PyTuple_GetItem( popo, 0 ) ); - y = (float)PyFloat_AsDouble( PyTuple_GetItem( popo, 1 ) ); - icu = self->ipocurve; - npoints = icu->totvert; - tmp = icu->bezt; - icu->bezt = MEM_mallocN( sizeof( BezTriple ) * ( npoints + 1 ), name ); - if( tmp ) { - memmove( icu->bezt, tmp, sizeof( BezTriple ) * npoints ); - MEM_freeN( tmp ); - } - memmove( icu->bezt + npoints, icu->bezt, sizeof( BezTriple ) ); - icu->totvert++; - bzt = icu->bezt + npoints; - bzt->vec[0][0] = x - 1; - bzt->vec[1][0] = x; - bzt->vec[2][0] = x + 1; - bzt->vec[0][1] = y - 1; - bzt->vec[1][1] = y; - bzt->vec[2][1] = y + 1; - /* set handle type to Auto */ - bzt->h1 = HD_AUTO; - bzt->h2 = HD_AUTO; - - Py_INCREF( Py_None ); - return Py_None; - } -#endif } - diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.h b/source/gameengine/Converter/KX_BlenderSceneConverter.h index dd7c31abee7..bdaa8448f6d 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.h +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.h @@ -129,6 +129,8 @@ public: ///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_ISceneConverter.h b/source/gameengine/Ketsji/KX_ISceneConverter.h index b3422605c87..5cb445a6dc4 100644 --- a/source/gameengine/Ketsji/KX_ISceneConverter.h +++ b/source/gameengine/Ketsji/KX_ISceneConverter.h @@ -65,6 +65,8 @@ public: ///this generates ipo curves for position, rotation, allowing to use game physics in animation virtual void WritePhysicsObjectToAnimationIpo(int frameNumber) = 0; + virtual void TestHandlesPhysicsObjectToAnimationIpo() = 0; + }; diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index a3a4a556956..a163e8fde58 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -845,6 +845,13 @@ void KX_KetsjiEngine::StopEngine() { if (m_bInitialized) { + + if (m_game2ipo) + { +// printf("TestHandlesPhysicsObjectToAnimationIpo\n"); + m_sceneconverter->TestHandlesPhysicsObjectToAnimationIpo(); + } + KX_SceneList::iterator sceneit; for (sceneit = m_scenes.begin();sceneit != m_scenes.end() ; sceneit++) { |