BGE Animations: Lamp and Camera IPOs are now handled like object IPOs, which means...
authorMitchell Stokes <mogurijin@gmail.com>
Wed, 17 Aug 2011 09:38:50 +0000 (09:38 +0000)
committerMitchell Stokes <mogurijin@gmail.com>
Wed, 17 Aug 2011 09:38:50 +0000 (09:38 +0000)
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/KX_IpoConvert.cpp
source/gameengine/Converter/KX_IpoConvert.h
source/gameengine/Ketsji/BL_Action.cpp
source/gameengine/Ketsji/BL_Action.h

index 9bea3f492c919914b3faf765c40f613ad210592e..aa11e78077aecc89582af6dbba9bc0c3a793e4be 100644 (file)
@@ -1682,8 +1682,6 @@ static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int l
 
        gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rendertools,
                lightobj, glslmat);
-
-       BL_ConvertLampIpos(la, gamelight, converter);
        
        return gamelight;
 }
@@ -1696,8 +1694,6 @@ static KX_Camera *gamecamera_from_bcamera(Object *ob, KX_Scene *kxscene, KX_Blen
        gamecamera= new KX_Camera(kxscene, KX_Scene::m_callbacks, camdata);
        gamecamera->SetName(ca->id.name + 2);
        
-       BL_ConvertCameraIpos(ca, gamecamera, converter);
-       
        return gamecamera;
 }
 
@@ -2092,8 +2088,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                        gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz));
                        gameobj->NodeSetLocalScale(scale);
                        gameobj->NodeUpdateGS(0);
-                       
-                       BL_ConvertIpos(blenderobject,gameobj,converter);
+
                        BL_ConvertMaterialIpos(blenderobject, gameobj, converter);
                        
                        sumolist->Add(gameobj->AddRef());
@@ -2282,8 +2277,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie,
                                                        gameobj->NodeSetLocalOrientation(MT_Matrix3x3(eulxyz));
                                                        gameobj->NodeSetLocalScale(scale);
                                                        gameobj->NodeUpdateGS(0);
-                                                       
-                                                       BL_ConvertIpos(blenderobject,gameobj,converter);
+       
                                                        BL_ConvertMaterialIpos(blenderobject,gameobj, converter);       
                                        
                                                        sumolist->Add(gameobj->AddRef());
index 0e526bc818de99fe0c0693ce5010c7f37d368977..2793b8e9fdfa67bd880efa45716eed76a97145b0 100644 (file)
@@ -207,93 +207,108 @@ void BL_ConvertIpos(struct Object* blenderobject,KX_GameObject* gameobj,KX_Blend
        }
 }
 
-void BL_ConvertLampIpos(struct Lamp* blenderlamp, KX_GameObject *lightobj,KX_BlenderSceneConverter *converter)
+SG_Controller *BL_CreateLampIPO(struct bAction *action, KX_GameObject*  lightobj, KX_BlenderSceneConverter *converter)
 {
+       KX_LightIpoSGController* ipocontr = new KX_LightIpoSGController();
 
-       if (blenderlamp->adt) {
+       Lamp *blenderlamp = (Lamp*)lightobj->GetBlenderObject()->data;
 
-               KX_LightIpoSGController* ipocontr = new KX_LightIpoSGController();
-               lightobj->GetSGNode()->AddSGController(ipocontr);
-               ipocontr->SetObject(lightobj->GetSGNode());
-               
-               ipocontr->m_energy = blenderlamp->energy;
-               ipocontr->m_col_rgb[0] = blenderlamp->r;
-               ipocontr->m_col_rgb[1] = blenderlamp->g;
-               ipocontr->m_col_rgb[2] = blenderlamp->b;
-               ipocontr->m_dist = blenderlamp->dist;
+       ipocontr->m_energy = blenderlamp->energy;
+       ipocontr->m_col_rgb[0] = blenderlamp->r;
+       ipocontr->m_col_rgb[1] = blenderlamp->g;
+       ipocontr->m_col_rgb[2] = blenderlamp->b;
+       ipocontr->m_dist = blenderlamp->dist;
 
-               BL_InterpolatorList *adtList= GetAdtList(blenderlamp->adt->action, converter);
+       BL_InterpolatorList *adtList= GetAdtList(action, converter);
 
-               // For each active channel in the adtList add an
-               // interpolator to the game object.
+       // For each active channel in the adtList add an
+       // interpolator to the game object.
                
-               KX_IInterpolator *interpolator;
-               KX_IScalarInterpolator *interp;
+       KX_IInterpolator *interpolator;
+       KX_IScalarInterpolator *interp;
                
-               if ((interp= adtList->GetScalarInterpolator("energy", 0))) {
-                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_energy, interp);
-                       ipocontr->AddInterpolator(interpolator);
-                       ipocontr->SetModifyEnergy(true);
-               }
+       if ((interp= adtList->GetScalarInterpolator("energy", 0))) {
+               interpolator= new KX_ScalarInterpolator(&ipocontr->m_energy, interp);
+               ipocontr->AddInterpolator(interpolator);
+               ipocontr->SetModifyEnergy(true);
+       }
 
-               if ((interp = adtList->GetScalarInterpolator("distance", 0))) {
-                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_dist, interp);
-                       ipocontr->AddInterpolator(interpolator);
-                       ipocontr->SetModifyDist(true);
-               }
+       if ((interp = adtList->GetScalarInterpolator("distance", 0))) {
+               interpolator= new KX_ScalarInterpolator(&ipocontr->m_dist, interp);
+               ipocontr->AddInterpolator(interpolator);
+               ipocontr->SetModifyDist(true);
+       }
                
-               for(int i=0; i<3; i++) {
-                       if ((interp = adtList->GetScalarInterpolator("color", i))) {
-                               interpolator= new KX_ScalarInterpolator(&ipocontr->m_col_rgb[i], interp);
-                               ipocontr->AddInterpolator(interpolator);
-                               ipocontr->SetModifyColor(true);
-                       }
+       for(int i=0; i<3; i++) {
+               if ((interp = adtList->GetScalarInterpolator("color", i))) {
+                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_col_rgb[i], interp);
+                       ipocontr->AddInterpolator(interpolator);
+                       ipocontr->SetModifyColor(true);
                }
        }
+
+       return ipocontr;
 }
 
+void BL_ConvertLampIpos(struct Lamp* blenderlamp, KX_GameObject *lightobj,KX_BlenderSceneConverter *converter)
+{
 
+       if (blenderlamp->adt) {
 
+               SG_Controller* ipocontr = BL_CreateLampIPO(blenderlamp->adt->action, lightobj, converter);
+               lightobj->GetSGNode()->AddSGController(ipocontr);
+               ipocontr->SetObject(lightobj->GetSGNode());
+               
+               
+       }
+}
 
-void BL_ConvertCameraIpos(struct Camera* blendercamera, KX_GameObject *cameraobj,KX_BlenderSceneConverter *converter)
+SG_Controller *BL_CreateCameraIPO(struct bAction *action, KX_GameObject*  cameraobj, KX_BlenderSceneConverter *converter)
 {
+       KX_CameraIpoSGController* ipocontr = new KX_CameraIpoSGController();
 
-       if (blendercamera->adt) {
+       Camera *blendercamera = (Camera*)cameraobj->GetBlenderObject()->data;
 
-               KX_CameraIpoSGController* ipocontr = new KX_CameraIpoSGController();
-               cameraobj->GetSGNode()->AddSGController(ipocontr);
-               ipocontr->SetObject(cameraobj->GetSGNode());
-               
-               ipocontr->m_lens = blendercamera->lens;
-               ipocontr->m_clipstart = blendercamera->clipsta;
-               ipocontr->m_clipend = blendercamera->clipend;
+       ipocontr->m_lens = blendercamera->lens;
+       ipocontr->m_clipstart = blendercamera->clipsta;
+       ipocontr->m_clipend = blendercamera->clipend;
 
-               BL_InterpolatorList *adtList= GetAdtList(blendercamera->adt->action, converter);
+       BL_InterpolatorList *adtList= GetAdtList(blendercamera->adt->action, converter);
 
-               // For each active channel in the adtList add an
-               // interpolator to the game object.
+       // For each active channel in the adtList add an
+       // interpolator to the game object.
                
-               KX_IInterpolator *interpolator;
-               KX_IScalarInterpolator *interp;
+       KX_IInterpolator *interpolator;
+       KX_IScalarInterpolator *interp;
                
-               if ((interp = adtList->GetScalarInterpolator("lens", 0))) {
-                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_lens, interp);
-                       ipocontr->AddInterpolator(interpolator);
-                       ipocontr->SetModifyLens(true);
-               }
+       if ((interp = adtList->GetScalarInterpolator("lens", 0))) {
+               interpolator= new KX_ScalarInterpolator(&ipocontr->m_lens, interp);
+               ipocontr->AddInterpolator(interpolator);
+               ipocontr->SetModifyLens(true);
+       }
 
-               if ((interp = adtList->GetScalarInterpolator("clip_start", 0))) {
-                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_clipstart, interp);
-                       ipocontr->AddInterpolator(interpolator);
-                       ipocontr->SetModifyClipStart(true);
-               }
+       if ((interp = adtList->GetScalarInterpolator("clip_start", 0))) {
+               interpolator= new KX_ScalarInterpolator(&ipocontr->m_clipstart, interp);
+               ipocontr->AddInterpolator(interpolator);
+               ipocontr->SetModifyClipStart(true);
+       }
 
-               if ((interp = adtList->GetScalarInterpolator("clip_end", 0))) {
-                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_clipend, interp);
-                       ipocontr->AddInterpolator(interpolator);
-                       ipocontr->SetModifyClipEnd(true);
-               }
+       if ((interp = adtList->GetScalarInterpolator("clip_end", 0))) {
+               interpolator= new KX_ScalarInterpolator(&ipocontr->m_clipend, interp);
+               ipocontr->AddInterpolator(interpolator);
+               ipocontr->SetModifyClipEnd(true);
+       }
 
+       return ipocontr;
+}
+
+void BL_ConvertCameraIpos(struct Camera* blendercamera, KX_GameObject *cameraobj,KX_BlenderSceneConverter *converter)
+{
+
+       if (blendercamera->adt) {
+               SG_Controller* ipocontr = BL_CreateCameraIPO(blendercamera->adt->action, cameraobj, converter);
+               cameraobj->GetSGNode()->AddSGController(ipocontr);
+               ipocontr->SetObject(cameraobj->GetSGNode());
        }
 }
 
index 914422ba83fbf16bb4bc07cbcdc36855ab1a40df..60e695c68a7f292a91726f9527a80618900b834b 100644 (file)
@@ -44,6 +44,10 @@ void BL_ConvertIpos(struct Object* blenderobject,
        class KX_GameObject* gameobj, 
        class KX_BlenderSceneConverter *converter);
 
+class SG_Controller *BL_CreateLampIPO(struct bAction *action,
+       class KX_GameObject* lightobj,
+       class KX_BlenderSceneConverter *converter);
+
 void BL_ConvertLampIpos(struct Lamp* blenderlight,
        class KX_GameObject* lightobj, 
        class KX_BlenderSceneConverter *converter);
@@ -51,6 +55,10 @@ void BL_ConvertLampIpos(struct Lamp* blenderlight,
 void BL_ConvertWorldIpos(struct World* blenderworld, 
        class KX_BlenderSceneConverter *converter);
 
+class SG_Controller *BL_CreateCameraIPO(struct bAction *action,
+       class KX_GameObject* cameraobj,
+       class KX_BlenderSceneConverter *converter);
+
 void BL_ConvertCameraIpos(struct Camera* blendercamera,
        class KX_GameObject* cameraobj, 
        class KX_BlenderSceneConverter *converter);
index 6682b0cea41dcef749c9765136890ae06b7af252..08794042e374f0ded6bee8616bf233a7e32d4e85 100644 (file)
@@ -54,7 +54,6 @@ BL_Action::BL_Action(class KX_GameObject* gameobj)
        m_blendpose(NULL),
        m_blendinpose(NULL),
        m_ptrrna(NULL),
-       m_sg_contr(NULL),
        m_obj(gameobj),
        m_startframe(0.f),
        m_endframe(0.f),
@@ -98,13 +97,22 @@ BL_Action::~BL_Action()
                game_free_pose(m_blendpose);
        if (m_blendinpose)
                game_free_pose(m_blendinpose);
-       if (m_sg_contr)
-       {
-               m_obj->GetSGNode()->RemoveSGController(m_sg_contr);
-               delete m_sg_contr;
-       }
        if (m_ptrrna)
                delete m_ptrrna;
+       ClearControllerList();
+}
+
+void BL_Action::ClearControllerList()
+{
+       // Clear out the controller list
+       std::vector<SG_Controller*>::iterator it;
+       for (it = m_sg_contr_list.begin(); it != m_sg_contr_list.end(); it++)
+       {
+               m_obj->GetSGNode()->RemoveSGController((*it));
+               delete *it;
+       }
+
+       m_sg_contr_list.clear();
 }
 
 bool BL_Action::Play(const char* name,
@@ -136,10 +144,30 @@ bool BL_Action::Play(const char* name,
 
        if (prev_action != m_action)
        {
+               // First get rid of any old controllers
+               ClearControllerList();
+
                // Create an SG_Controller
-               m_sg_contr = BL_CreateIPO(m_action, m_obj, KX_GetActiveScene()->GetSceneConverter());
-               m_obj->GetSGNode()->AddSGController(m_sg_contr);
-               m_sg_contr->SetObject(m_obj->GetSGNode());
+               SG_Controller *sg_contr = BL_CreateIPO(m_action, m_obj, KX_GetActiveScene()->GetSceneConverter());
+               m_sg_contr_list.push_back(sg_contr);
+               m_obj->GetSGNode()->AddSGController(sg_contr);
+               sg_contr->SetObject(m_obj->GetSGNode());
+
+               // Extra controllers
+               if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_LIGHT)
+               {
+                       sg_contr = BL_CreateLampIPO(m_action, m_obj, KX_GetActiveScene()->GetSceneConverter());
+                       m_sg_contr_list.push_back(sg_contr);
+                       m_obj->GetSGNode()->AddSGController(sg_contr);
+                       sg_contr->SetObject(m_obj->GetSGNode());
+               }
+               else if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_CAMERA)
+               {
+                       sg_contr = BL_CreateCameraIPO(m_action, m_obj, KX_GetActiveScene()->GetSceneConverter());
+                       m_sg_contr_list.push_back(sg_contr);
+                       m_obj->GetSGNode()->AddSGController(sg_contr);
+                       sg_contr->SetObject(m_obj->GetSGNode());
+               }
        }
        
        m_ipo_flags = ipo_flags;
@@ -197,11 +225,15 @@ bool BL_Action::IsDone()
 
 void BL_Action::InitIPO()
 {
-               // Initialize the IPO
-               m_sg_contr->SetOption(SG_Controller::SG_CONTR_IPO_RESET, true);
-               m_sg_contr->SetOption(SG_Controller::SG_CONTR_IPO_IPO_AS_FORCE, m_ipo_flags & ACT_IPOFLAG_FORCE);
-               m_sg_contr->SetOption(SG_Controller::SG_CONTR_IPO_IPO_ADD, m_ipo_flags & ACT_IPOFLAG_ADD);
-               m_sg_contr->SetOption(SG_Controller::SG_CONTR_IPO_LOCAL, m_ipo_flags & ACT_IPOFLAG_LOCAL);
+       // Initialize the IPOs
+       std::vector<SG_Controller*>::iterator it;
+       for (it = m_sg_contr_list.begin(); it != m_sg_contr_list.end(); it++)
+       {
+               (*it)->SetOption(SG_Controller::SG_CONTR_IPO_RESET, true);
+               (*it)->SetOption(SG_Controller::SG_CONTR_IPO_IPO_AS_FORCE, m_ipo_flags & ACT_IPOFLAG_FORCE);
+               (*it)->SetOption(SG_Controller::SG_CONTR_IPO_IPO_ADD, m_ipo_flags & ACT_IPOFLAG_ADD);
+               (*it)->SetOption(SG_Controller::SG_CONTR_IPO_LOCAL, m_ipo_flags & ACT_IPOFLAG_LOCAL);
+       }
 }
 
 bAction *BL_Action::GetAction()
@@ -330,7 +362,7 @@ void BL_Action::Update(float curtime)
                        break;
                }
 
-               if (!m_done && m_sg_contr)
+               if (!m_done)
                        InitIPO();
        }
 
index 75bda56419a3a6bb406ca1bc1b18ec04c956925d..92fbe95fd54027fbd09e2989ea6676aff87bb368 100644 (file)
@@ -45,7 +45,7 @@ private:
        struct bPose* m_blendpose;
        struct bPose* m_blendinpose;
        struct PointerRNA *m_ptrrna;
-       class SG_Controller *m_sg_contr;
+       std::vector<class SG_Controller*> m_sg_contr_list;
        class KX_GameObject* m_obj;
        std::vector<float>      m_blendshape;
        std::vector<float>      m_blendinshape;
@@ -73,6 +73,7 @@ private:
        bool m_done;
        bool m_calc_localtime;
 
+       void ClearControllerList();
        void InitIPO();
        void SetLocalTime(float curtime);
        void ResetStartTime(float curtime);