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 6b0df44..a656c5e 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 3e83ed2..08e9e36 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 a5b8d8a..edda765 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 cf621e0..301a141 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 87775e8..da0cd69 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 5400328..e4054e0 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 30c96d0..16e1565 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 4642ffb..02e84f8 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);
        }