diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2011-08-17 13:38:50 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2011-08-17 13:38:50 +0400 |
commit | db4071d2b6b727857521bd05529fe8141e8bb0a2 (patch) | |
tree | 842eae35db95a4b821297ba51df89320cd1f2919 /source | |
parent | 750e754604eac5048dbb0ec6ee436d6a12156808 (diff) |
BGE Animations: Lamp and Camera IPOs are now handled like object IPOs, which means lamps and cameras are no longer stuck to just their active action. However, the Blender UI seems a little restrictive in this area.
Diffstat (limited to 'source')
-rw-r--r-- | source/gameengine/Converter/BL_BlenderDataConversion.cpp | 10 | ||||
-rw-r--r-- | source/gameengine/Converter/KX_IpoConvert.cpp | 137 | ||||
-rw-r--r-- | source/gameengine/Converter/KX_IpoConvert.h | 8 | ||||
-rw-r--r-- | source/gameengine/Ketsji/BL_Action.cpp | 62 | ||||
-rw-r--r-- | source/gameengine/Ketsji/BL_Action.h | 3 |
5 files changed, 135 insertions, 85 deletions
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 9bea3f492c9..aa11e78077a 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -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()); diff --git a/source/gameengine/Converter/KX_IpoConvert.cpp b/source/gameengine/Converter/KX_IpoConvert.cpp index 0e526bc818d..2793b8e9fdf 100644 --- a/source/gameengine/Converter/KX_IpoConvert.cpp +++ b/source/gameengine/Converter/KX_IpoConvert.cpp @@ -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()); } } diff --git a/source/gameengine/Converter/KX_IpoConvert.h b/source/gameengine/Converter/KX_IpoConvert.h index 914422ba83f..60e695c68a7 100644 --- a/source/gameengine/Converter/KX_IpoConvert.h +++ b/source/gameengine/Converter/KX_IpoConvert.h @@ -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); diff --git a/source/gameengine/Ketsji/BL_Action.cpp b/source/gameengine/Ketsji/BL_Action.cpp index 6682b0cea41..08794042e37 100644 --- a/source/gameengine/Ketsji/BL_Action.cpp +++ b/source/gameengine/Ketsji/BL_Action.cpp @@ -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(); } diff --git a/source/gameengine/Ketsji/BL_Action.h b/source/gameengine/Ketsji/BL_Action.h index 75bda56419a..92fbe95fd54 100644 --- a/source/gameengine/Ketsji/BL_Action.h +++ b/source/gameengine/Ketsji/BL_Action.h @@ -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); |