gameengine: removing addInitFromFrame hack
authorInes Almeida <britalmeida@gmail.com>
Wed, 23 Jul 2014 12:07:01 +0000 (13:07 +0100)
committerInes Almeida <britalmeida@gmail.com>
Sat, 21 Feb 2015 12:16:20 +0000 (12:16 +0000)
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/KX_BlenderSceneConverter.cpp
source/gameengine/Ketsji/KX_ISceneConverter.h

index 6e8c64f3f12cc983deb0812090ce550eea4ce7db..511b61528f8a317dff3fc24017fab5a963a069f6 100644 (file)
@@ -464,7 +464,6 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
                        // create a scene converter, create and convert the startingscene
                        KX_ISceneConverter* sceneconverter = new KX_BlenderSceneConverter(blenderdata, ketsjiengine);
                        ketsjiengine->SetSceneConverter(sceneconverter);
-                       sceneconverter->addInitFromFrame=false;
                        if (always_use_expand_framing)
                                sceneconverter->SetAlwaysUseExpandFraming(true);
 
index a64ab712c06536f795743db1b65e725a60593908..7e0588fc7d0adf0cba03894d09cd828f67ddfa4d 100644 (file)
@@ -1745,8 +1745,7 @@ static KX_GameObject* getGameOb(STR_String busc,CListValue* sumolist)
  * note: all var names match args are passed from the caller */
 static void bl_ConvertBlenderObject_Single(
         KX_BlenderSceneConverter *converter,
-        Scene *blenderscene, Object *blenderobject,
-        vector<MT_Vector3> &inivel, vector<MT_Vector3> &iniang,
+       Object *blenderobject,
         vector<parentChildLink> &vec_parent_child,
         CListValue* logicbrick_conversionlist,
         CListValue* objectlist, CListValue* inactivelist, CListValue*  sumolist,
@@ -1755,10 +1754,6 @@ static void bl_ConvertBlenderObject_Single(
         bool isInActiveLayer
         )
 {
-       MT_Point3 posPrev;
-       MT_Matrix3x3 angor;
-       if (converter->addInitFromFrame) blenderscene->r.cfra=blenderscene->r.sfra;
-
        MT_Point3 pos(
                blenderobject->loc[0]+blenderobject->dloc[0],
                blenderobject->loc[1]+blenderobject->dloc[1],
@@ -1772,35 +1767,6 @@ static void bl_ConvertBlenderObject_Single(
 
        MT_Vector3 scale(blenderobject->size);
 
-       if (converter->addInitFromFrame) {//rcruiz
-               blenderscene->r.cfra=blenderscene->r.sfra-1;
-               //XXX 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]
-                                            );
-
-               float rotmatPrev[3][3];
-               BKE_object_rot_to_mat3(blenderobject, rotmatPrev, false);
-
-               float eulxyz[3], eulxyzPrev[3];
-               mat3_to_eul(eulxyz, rotmat);
-               mat3_to_eul(eulxyzPrev, rotmatPrev);
-
-               double fps = (double) blenderscene->r.frs_sec/
-                       (double) blenderscene->r.frs_sec_base;
-
-               tmp.scale(fps, fps, fps);
-               inivel.push_back(tmp);
-               tmp[0]=eulxyz[0]-eulxyzPrev[0];
-               tmp[1]=eulxyz[1]-eulxyzPrev[1];
-               tmp[2]=eulxyz[2]-eulxyzPrev[2];
-               tmp.scale(fps, fps, fps);
-               iniang.push_back(tmp);
-               blenderscene->r.cfra=blenderscene->r.sfra;
-               //XXX update_for_newframe();
-       }
-
        gameobj->NodeSetLocalPosition(pos);
        gameobj->NodeSetLocalOrientation(rotation);
        gameobj->NodeSetLocalScale(scale);
@@ -1813,7 +1779,7 @@ static void bl_ConvertBlenderObject_Single(
        gameobj->SetName(blenderobject->id.name + 2);
 
        // update children/parent hierarchy
-       if ((blenderobject->parent != 0)&&(!converter->addInitFromFrame))
+       if (blenderobject->parent != 0)
        {
                // blender has an additional 'parentinverse' offset in each object
                SG_Callbacks callback(NULL,NULL,NULL,KX_Scene::KX_ScenegraphUpdateFunc,KX_Scene::KX_ScenegraphRescheduleFunc);
@@ -1872,10 +1838,6 @@ static void bl_ConvertBlenderObject_Single(
 
        logicbrick_conversionlist->Add(gameobj->AddRef());
 
-       if (converter->addInitFromFrame) {
-               posPrev=gameobj->NodeGetWorldPosition();
-               angor=gameobj->NodeGetWorldOrientation();
-       }
        if (isInActiveLayer)
        {
                objectlist->Add(gameobj->AddRef());
@@ -1883,7 +1845,6 @@ static void bl_ConvertBlenderObject_Single(
 
                gameobj->NodeUpdateGS(0);
                gameobj->AddMeshUser();
-
        }
        else
        {
@@ -1891,11 +1852,6 @@ static void bl_ConvertBlenderObject_Single(
                //at the end of this function if it is not a root object
                inactivelist->Add(gameobj->AddRef());
        }
-
-       if (converter->addInitFromFrame) {
-               gameobj->NodeSetLocalPosition(posPrev);
-               gameobj->NodeSetLocalOrientation(angor);
-       }
 }
 
 
@@ -1914,8 +1870,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
 
 #define BL_CONVERTBLENDEROBJECT_SINGLE                                 \
        bl_ConvertBlenderObject_Single(converter,                          \
-                                      blenderscene, blenderobject,        \
-                                      inivel, iniang,                     \
+                                      blenderobject,                      \
                                       vec_parent_child,                   \
                                       logicbrick_conversionlist,          \
                                       objectlist, inactivelist, sumolist, \
@@ -1937,7 +1892,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
        RAS_FrameSettings::RAS_FrameType frame_type;
        int aspect_width;
        int aspect_height;
-       vector<MT_Vector3> inivel,iniang;
        set<Group*> grouplist;  // list of groups to be converted
        set<Object*> allblobj;  // all objects converted
        set<Object*> groupobj;  // objects from groups (never in active layer)
@@ -2024,23 +1978,15 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                                                                rendertools, 
                                                                                converter,
                                                                                libloading);
-                                                                               
-               bool isInActiveLayer = (blenderobject->lay & activeLayerBitInfo) !=0;
-               bool addobj=true;
-               
-               if (converter->addInitFromFrame)
-                       if (!isInActiveLayer)
-                               addobj=false;
 
+               bool isInActiveLayer = (blenderobject->lay & activeLayerBitInfo) !=0;
                if (gameobj)
                {
-                       if (addobj)
-                       {       /* macro calls object conversion funcs */
-                               BL_CONVERTBLENDEROBJECT_SINGLE;
+                       /* macro calls object conversion funcs */
+                       BL_CONVERTBLENDEROBJECT_SINGLE;
 
-                               if (gameobj->IsDupliGroup()) {
-                                       grouplist.insert(blenderobject->dup_group);
-                               }
+                       if (gameobj->IsDupliGroup()) {
+                               grouplist.insert(blenderobject->dup_group);
                        }
 
                        /* Note about memory leak issues:
@@ -2084,22 +2030,12 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                                                                                                rendertools, 
                                                                                                                converter,
                                                                                                                libloading);
-                                                                               
-                                               // this code is copied from above except that
-                                               // object from groups are never in active layer
-                                               bool isInActiveLayer = false;
-                                               bool addobj=true;
-                                               
-                                               if (converter->addInitFromFrame)
-                                                       if (!isInActiveLayer)
-                                                               addobj=false;
 
+                                               bool isInActiveLayer = false;
                                                if (gameobj)
                                                {
-                                                       if (addobj)
-                                                       {       /* macro calls object conversion funcs */
-                                                               BL_CONVERTBLENDEROBJECT_SINGLE;
-                                                       }
+                                                       /* macro calls object conversion funcs */
+                                                       BL_CONVERTBLENDEROBJECT_SINGLE;
 
                                                        if (gameobj->IsDupliGroup())
                                                        {
@@ -2109,7 +2045,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                                                }
                                                        }
 
-
                                                        /* see comment above re: mem leaks */
                                                        gameobj->Release();
                                                }
@@ -2331,18 +2266,6 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                int layerMask = (groupobj.find(blenderobject) == groupobj.end()) ? activeLayerBitInfo : 0;
                BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,layerMask,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++)
index eb4b9a8124a5707588148d30a6cc4192ea17fee9..dc691972738ca03a8ed4cc4856dfa9b9ba9a3cf7 100644 (file)
@@ -599,6 +599,8 @@ void KX_BlenderSceneConverter::RegisterWorldInfo(
 
 void   KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo)
 {
+       //TODO this entire function is deprecated, written for 2.4x
+       //the functionality should be rewritten, currently it does nothing
 
        KX_SceneList* scenes = m_ketsjiEngine->CurrentScenes();
        int numScenes = scenes->size();
@@ -614,7 +616,7 @@ void        KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo)
                {
                        KX_GameObject* gameObj = (KX_GameObject*)parentList->GetValue(g);
                        if (gameObj->IsRecordAnimation()) {
-                               
+
                                Object* blenderObject = gameObj->GetBlenderObject();
                                if (blenderObject)
                                {
@@ -625,21 +627,21 @@ void      KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo)
                                        {       //clear the curve data
                                                if (clearIpo) {//rcruiz
                                                        IpoCurve *icu1;
-                                                                                                               
+
                                                        int numCurves = 0;
                                                        for ( icu1 = (IpoCurve*)ipo->curve.first; icu1;  ) {
-                                                       
+
                                                                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 );
@@ -657,8 +659,8 @@ void        KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo)
                        }
 
                }
-               
-       
+
+
        }
 
 
@@ -667,45 +669,7 @@ 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->IsRecordAnimation()) {
-                                       Object* blenderobject = gameobj->GetBlenderObject();
-                                       if (!blenderobject)
-                                               continue;
-                                       if (blenderobject->type==OB_ARMATURE)
-                                               continue;
-                                       float eu[3];
-                                       mat4_to_eul(eu,blenderobject->obmat);
-                                       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);
-                               }
-                       }
-               }
-       }
+       //TODO the functionality should be rewritten
 }
 
 
index a07d4b2195c6aec73fd7aaf1c4e750d32dc3d1e2..b6647cdf3dc3ff32b76ba1a085183405e368e885 100644 (file)
@@ -45,8 +45,8 @@ class KX_ISceneConverter
 {
 
 public:
-       KX_ISceneConverter() :addInitFromFrame(false) {}//this addInitFromFrame is a back hack, todo remove
-       virtual ~KX_ISceneConverter () {};
+       KX_ISceneConverter() {}
+       virtual ~KX_ISceneConverter () {}
 
        /*
         * scenename: name of the scene to be converted,
@@ -59,7 +59,7 @@ public:
                class RAS_IRasterizer* rendertools,
                class RAS_ICanvas*  canvas,
                bool libloading=false)=0;
-       
+
        virtual void RemoveScene(class KX_Scene *scene)=0;
 
        // handle any pending merges from asynchronous loads
@@ -69,11 +69,9 @@ 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;