fix BGE bug #8869: Added objects are not lit correctly
authorBenoit Bolsee <benoit.bolsee@online.be>
Wed, 30 Apr 2008 19:58:44 +0000 (19:58 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Wed, 30 Apr 2008 19:58:44 +0000 (19:58 +0000)
The current layer information is now stored in KX_GameObject and inherited from the parent object when dynamically added. This information is used during the rendering the select the lamps. As the selected lamps are always coming from active layers, their position and orientation are correct.

source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
source/gameengine/Ketsji/KX_GameObject.cpp
source/gameengine/Ketsji/KX_GameObject.h
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Rasterizer/RAS_IRenderTools.h
source/gameengine/Rasterizer/RAS_MaterialBucket.cpp

index 6b0df44cb1696fa07f3d72c322c51bc4cc9bc7ef..a656c5e5523c0f00dfd46902c6fd7b604cc0488d 100644 (file)
@@ -91,6 +91,10 @@ int  KX_BlenderRenderTools::ProcessLighting(int layer)
        {
                if (m_clientobject)
                {
+                       if (layer == RAS_LIGHT_OBJECT_LAYER)
+                       {
+                               layer = static_cast<KX_GameObject*>(m_clientobject)->GetLayer();
+                       }
                        if (applyLights(layer))
                        {
                                EnableOpenGLLights();
index 3e83ed20840984e22a6f04ac3bf6b8c6c4ac16e5..08e9e36c0483f5411a16da8d046ed11ffb103de7 100644 (file)
@@ -1680,8 +1680,11 @@ static KX_GameObject *gameobject_from_blenderobject(
                break;
        }
        }
-       if (gameobj)
+       if (gameobj) 
+       {
                gameobj->SetPhysicsEnvironment(kxscene->GetPhysicsEnvironment());
+               gameobj->SetLayer(ob->lay);
+       }
        return gameobj;
 }
 
index a5b8d8aacdfc19d6e7006ec26565be00b99f9c7f..edda7657ef950dd3c8fb6b3ba094e5042e049caa 100644 (file)
@@ -137,6 +137,10 @@ int GPC_RenderTools::ProcessLighting(int layer)
        {
                if (m_clientobject)
                {       
+                       if (layer == RAS_LIGHT_OBJECT_LAYER)
+                       {
+                               layer = static_cast<KX_GameObject*>(m_clientobject)->GetLayer();
+                       }
                        if (applyLights(layer))
                        {
                                EnableOpenGLLights();
index cf621e04f999ac1392dae9aca2c6a2969e4ebb5e..301a1413bcd68ab01fdeb1322f06eb6bd318ccc2 100644 (file)
@@ -74,6 +74,7 @@ KX_GameObject::KX_GameObject(
 ) : 
        SCA_IObject(T),
        m_bDyna(false),
+       m_layer(0),
        m_bSuspendDynamics(false),
        m_bUseObjectColor(false),
        m_bVisible(true),
@@ -479,6 +480,22 @@ KX_GameObject::SetVisible(
        m_bVisible = v;
 }
 
+void
+KX_GameObject::SetLayer(
+       int l
+       )
+{
+       m_layer = l;
+}
+
+int
+KX_GameObject::GetLayer(
+       void
+       )
+{
+       return m_layer;
+}
+
 // used by Python, and the actuatorshould _not_ be misused by the
 // scene!
 void 
index 87775e812167b2e346673b83f74776687d12d6bb..da0cd69e129d05c41353cba54457b627b159c5d5 100644 (file)
@@ -70,6 +70,7 @@ protected:
        KX_ClientObjectInfo*                            m_pClient_info;
        STR_String                                                      m_name;
        STR_String                                                      m_text;
+       int                                                                     m_layer;
        std::vector<RAS_MeshObject*>            m_meshes;
        
        bool                                                            m_bSuspendDynamics;
@@ -571,6 +572,22 @@ public:
                bool b
        );
 
+       /**
+        * Change the layer of the object (when it is added in another layer
+        * than the original layer)
+        */
+               void
+       SetLayer(
+               int l
+       );
+
+       /**
+        * Get the object layer
+        */
+               int
+       GetLayer(
+               void
+       );
                
        /**
         * @section Logic bubbling methods.
index 54003284e03d8b0a68b77944b3a710736b7f9070..e4054e07475b97d6b55af7d5acd662e55be248c4 100644 (file)
@@ -650,6 +650,8 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject,
        for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
        {
                (*git)->Relink(&m_map_gameobject_to_replica);
+               // add the object in the layer of the parent
+               (*git)->SetLayer(parentobj->GetLayer());
        }
 
        // now replicate logic
index 30c96d0284732bee24268ab64d6715dfbc422067..16e15653c826e44d66c1a499bd7cb9b3fb50e669 100644 (file)
@@ -61,6 +61,10 @@ public:
                RAS_TEXT_PADDED,
                RAS_TEXT_MAX
        };
+       enum RAS_LIGHT_MODE {
+               RAS_LIGHT_NONE = -1,
+               RAS_LIGHT_OBJECT_LAYER = 0
+       };
 
        RAS_IRenderTools(
        ) :
index 4642ffbaeb89cf1ad2675dfa4850fc2e0faeecef..02e84f8a243d29edc64570441d5e5665a8347306 100644 (file)
@@ -189,7 +189,7 @@ bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_I
        }
        else
        {
-               rendertools->ProcessLighting(m_material->GetLightLayer());
+               rendertools->ProcessLighting(RAS_IRenderTools::RAS_LIGHT_OBJECT_LAYER/*m_material->GetLightLayer()*/);
        }
 
        drawmode = (rasty->GetDrawingMode()  < RAS_IRasterizer::KX_SOLID ?      
@@ -204,7 +204,6 @@ void RAS_MaterialBucket::RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRa
        if (!ms.m_bVisible)
                return;
        
-       rendertools->SetClientObject(ms.m_clientObj);
        m_material->ActivateMeshSlot(ms, rasty);
 
        /* __NLA Do the deformation */
@@ -317,15 +316,12 @@ void RAS_MaterialBucket::Render(const MT_Transform& cameratrans,
 
        //rasty->SetMaterial(*m_material);
        
-       if (m_meshSlots.size() >0)
-       {
-               rendertools->SetClientObject((*m_meshSlots.begin()).m_clientObj);
-       }
        
        int drawmode;
        for (T_MeshSlotList::const_iterator it = m_meshSlots.begin();
        ! (it == m_meshSlots.end()); ++it)
        {
+               rendertools->SetClientObject((*it).m_clientObj);
                while (ActivateMaterial(cameratrans, rasty, rendertools, drawmode))
                        RenderMeshSlot(cameratrans, rasty, rendertools, *it, drawmode);
        }