BGE: Fix T27322: World F-Curve
authorThomas Szepe <HG1_public@gmx.net>
Mon, 23 Mar 2015 20:43:42 +0000 (21:43 +0100)
committerThomas Szepe <HG1_public@gmx.net>
Mon, 23 Mar 2015 20:43:42 +0000 (21:43 +0100)
This patch fixes the world (mist, background, ambient) F-Curve for  for the BGE.

Reviewers: moguri, brecht

Reviewed By: moguri, brecht

Differential Revision: https://developer.blender.org/D150

source/gameengine/Ketsji/BL_Action.cpp
source/gameengine/Ketsji/KX_IpoConvert.cpp
source/gameengine/Ketsji/KX_IpoConvert.h
source/gameengine/Ketsji/KX_WorldIpoController.cpp
source/gameengine/Ketsji/KX_WorldIpoController.h

index a50c07a486aaab74124d1294b010c8b9cf5bdcc1..9bae119107e72934487dd4e40af582da2ccc19f9 100644 (file)
@@ -49,6 +49,7 @@ extern "C" {
 // Needed for material IPOs
 #include "BKE_material.h"
 #include "DNA_material_types.h"
+#include "DNA_scene_types.h"
 }
 
 #include "MEM_guardedalloc.h"
@@ -162,6 +163,14 @@ bool BL_Action::Play(const char* name,
        m_obj->GetSGNode()->AddSGController(sg_contr);
        sg_contr->SetObject(m_obj->GetSGNode());
 
+       // World
+       sg_contr = BL_CreateWorldIPO(m_action, kxscene->GetBlenderScene()->world, kxscene->GetSceneConverter());
+       if (sg_contr) {
+               m_sg_contr_list.push_back(sg_contr);
+               m_obj->GetSGNode()->AddSGController(sg_contr);
+               sg_contr->SetObject(m_obj->GetSGNode());
+       }
+
        // Try obcolor
        sg_contr = BL_CreateObColorIPO(m_action, m_obj, kxscene->GetSceneConverter());
        if (sg_contr) {
index 57130bf57b265386caed755110a33924bfc9c6f3..441c16176aa376538ea3a2c52a09c915f4562abf 100644 (file)
@@ -269,52 +269,80 @@ SG_Controller *BL_CreateCameraIPO(struct bAction *action, KX_GameObject*  camera
        return ipocontr;
 }
 
-void BL_ConvertWorldIpos(struct World* blenderworld,KX_BlenderSceneConverter *converter)
-{
-
-       if (blenderworld->adt) {
 
-               KX_WorldIpoController* ipocontr = new KX_WorldIpoController();
-
-// Erwin, hook up the world ipo controller here
-// Gino: hook it up to what ?
-// is there a userinterface element for that ?
-// for now, we have some new python hooks to access the data, for a work-around
-               
-               ipocontr->m_mist_start  = blenderworld->miststa;
-               ipocontr->m_mist_dist   = blenderworld->mistdist;
-               ipocontr->m_mist_rgb[0] = blenderworld->horr;
-               ipocontr->m_mist_rgb[1] = blenderworld->horg;
-               ipocontr->m_mist_rgb[2] = blenderworld->horb;
+SG_Controller * BL_CreateWorldIPO( bAction *action, struct World *blenderworld, KX_BlenderSceneConverter *converter )
+{
+       KX_WorldIpoController *ipocontr = NULL;
 
-               BL_InterpolatorList *adtList= GetAdtList(blenderworld->adt->action, converter);
+       if (blenderworld) {
+               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;
-               
+
+               for (int i=0; i<3; i++) {
+                       if ((interp = adtList->GetScalarInterpolator("ambient_color", i))) {
+                               if (!ipocontr) {
+                                       ipocontr = new KX_WorldIpoController();
+                               }
+                               interpolator = new KX_ScalarInterpolator(&ipocontr->m_ambi_rgb[i], interp);
+                               ipocontr->AddInterpolator(interpolator);
+                               ipocontr->SetModifyAmbientColor(true);
+                       }
+               }
+
                for (int i=0; i<3; i++) {
                        if ((interp = adtList->GetScalarInterpolator("horizon_color", i))) {
-                               interpolator= new KX_ScalarInterpolator(&ipocontr->m_mist_rgb[i], interp);
+                               if (!ipocontr) {
+                                       ipocontr = new KX_WorldIpoController();
+                               }
+                               interpolator = new KX_ScalarInterpolator(&ipocontr->m_hori_rgb[i], interp);
                                ipocontr->AddInterpolator(interpolator);
-                               ipocontr->SetModifyMistColor(true);
+                               ipocontr->SetModifyHorizonColor(true);
                        }
                }
 
-               if ((interp = adtList->GetScalarInterpolator("mist.depth", 0))) {
-                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_mist_dist, interp);
+               if ((interp = adtList->GetScalarInterpolator("mist_settings.start", 0))) {
+                       if (!ipocontr) {
+                               ipocontr = new KX_WorldIpoController();
+                       }
+                       interpolator = new KX_ScalarInterpolator(&ipocontr->m_mist_start, interp);
+                       ipocontr->AddInterpolator(interpolator);
+                       ipocontr->SetModifyMistStart(true);
+               }
+
+               if ((interp = adtList->GetScalarInterpolator("mist_settings.depth", 0))) {
+                       if (!ipocontr) {
+                               ipocontr = new KX_WorldIpoController();
+                       }
+                       interpolator = new KX_ScalarInterpolator(&ipocontr->m_mist_dist, interp);
                        ipocontr->AddInterpolator(interpolator);
                        ipocontr->SetModifyMistDist(true);
                }
 
-               if ((interp = adtList->GetScalarInterpolator("mist.start", 0))) {
-                       interpolator= new KX_ScalarInterpolator(&ipocontr->m_mist_start, interp);
+               if ((interp = adtList->GetScalarInterpolator("mist_settings.intensity", 0))) {
+                       if (!ipocontr) {
+                               ipocontr = new KX_WorldIpoController();
+                       }
+                       interpolator = new KX_ScalarInterpolator(&ipocontr->m_mist_intensity, interp);
                        ipocontr->AddInterpolator(interpolator);
-                       ipocontr->SetModifyMistStart(true);
+                       ipocontr->SetModifyMistIntensity(true);
+               }
+
+               if (ipocontr) {
+                       ipocontr->m_mist_start = blenderworld->miststa;
+                       ipocontr->m_mist_dist = blenderworld->mistdist;
+                       ipocontr->m_mist_intensity = blenderworld->misi;
+                       ipocontr->m_hori_rgb[0] = blenderworld->horr;
+                       ipocontr->m_hori_rgb[1] = blenderworld->horg;
+                       ipocontr->m_hori_rgb[2] = blenderworld->horb;
+                       ipocontr->m_ambi_rgb[0] = blenderworld->ambr;
+                       ipocontr->m_ambi_rgb[1] = blenderworld->ambg;
+                       ipocontr->m_ambi_rgb[2] = blenderworld->ambb;
                }
        }
+       return ipocontr;
 }
 
 SG_Controller *BL_CreateMaterialIpo(
index a653e4e110b9e8a3da8937a6d2361a1af52a012e..6db43552811422e149c83b25931941f809935631 100644 (file)
@@ -50,7 +50,8 @@ SG_Controller *BL_CreateLampIPO(bAction *action,
        KX_GameObject* lightobj,
        KX_BlenderSceneConverter *converter);
 
-void BL_ConvertWorldIpos(struct World* blenderworld, 
+SG_Controller *BL_CreateWorldIPO(bAction *action,
+       struct World *blenderworld,
        KX_BlenderSceneConverter *converter);
 
 SG_Controller *BL_CreateCameraIPO(bAction *action,
index a30d89284b8125f19a24fb32d25fc1e7d5407e3a..1123e07ebccad0bf330786ec23f23048b4dcf23e 100644 (file)
@@ -33,6 +33,8 @@
 #include "KX_WorldIpoController.h"
 #include "KX_ScalarInterpolator.h"
 #include "KX_WorldInfo.h"
+#include "KX_PythonInit.h"
+#include "KX_Scene.h"
 
 #if defined(_WIN64)
 typedef unsigned __int64 uint_ptr;
@@ -42,29 +44,36 @@ typedef unsigned long uint_ptr;
 
 bool KX_WorldIpoController::Update(double currentTime)
 {
-       if (m_modified)
-       {
+       if (m_modified) {
                T_InterpolatorList::iterator i;
                for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
-                       (*i)->Execute(m_ipotime);//currentTime);
+                       (*i)->Execute(m_ipotime);
                }
 
-               /* TODO, this will crash! */
-               KX_WorldInfo *world = NULL;
+               KX_WorldInfo *world = KX_GetActiveScene()->GetWorldInfo();
 
                if (m_modify_mist_start) {
                        world->setMistStart(m_mist_start);
                }
 
-               if (m_modify_mist_color) {
-                       world->setMistColor(m_mist_rgb[0], m_mist_rgb[1], m_mist_rgb[2]);
-               }
-
                if (m_modify_mist_dist) {
                        world->setMistDistance(m_mist_dist);
                }
 
-               m_modified=false;
+               if (m_modify_mist_intensity) {
+                       world->setMistIntensity(m_mist_intensity);
+               }
+
+               if (m_modify_horizon_color) {
+                       world->setBackColor(m_hori_rgb[0], m_hori_rgb[1], m_hori_rgb[2]);
+                       world->setMistColor(m_hori_rgb[0], m_hori_rgb[1], m_hori_rgb[2]);
+               }
+
+               if (m_modify_ambient_color) {
+                       world->setAmbientColor(m_ambi_rgb[0], m_ambi_rgb[1], m_ambi_rgb[2]);
+               }
+
+               m_modified = false;
        }
        return false;
 }
index 63983b3129b2468879a6d8a1624abc7121a61e58..704f421573e194fc253d9ca50a034c59c604663c 100644 (file)
 class KX_WorldIpoController : public SG_Controller
 {
 public:
-       MT_Scalar           m_mist_rgb[3];
        MT_Scalar           m_mist_start;
        MT_Scalar           m_mist_dist;
+       MT_Scalar           m_mist_intensity;
+       MT_Scalar           m_hori_rgb[3];
+       MT_Scalar           m_ambi_rgb[3];
 
 private:
        T_InterpolatorList      m_interpolators;
-       unsigned short          m_modify_mist_color  : 1;
        unsigned short          m_modify_mist_start      : 1;
        unsigned short          m_modify_mist_dist       : 1;
+       unsigned short          m_modify_mist_intensity : 1;
+       unsigned short          m_modify_horizon_color  : 1;
+       unsigned short          m_modify_ambient_color  : 1;
        bool                            m_modified;
 
        double                  m_ipotime;
 
 public:
        KX_WorldIpoController() : 
-                               m_modify_mist_color(false),
                                m_modify_mist_start(false),
                                m_modify_mist_dist(false),
+                               m_modify_mist_intensity(false),
+                               m_modify_horizon_color(false),
+                               m_modify_ambient_color(false),
                                m_modified(true),
                                m_ipotime(0.0)
                {}
@@ -76,14 +82,22 @@ public:
                m_modify_mist_start = modify;
        }
 
-       void    SetModifyMistColor(bool modify) {
-               m_modify_mist_color = modify;
-       }
-
        void    SetModifyMistDist(bool modify) {
                m_modify_mist_dist = modify;
        }
 
+       void    SetModifyMistIntensity(bool modify) {
+               m_modify_mist_intensity = modify;
+       }
+
+       void    SetModifyHorizonColor(bool modify) {
+               m_modify_horizon_color = modify;
+       }
+
+       void    SetModifyAmbientColor(bool modify) {
+               m_modify_ambient_color = modify;
+       }
+
                void
        SetOption(
                int option,