diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp index 6b0df44cb16..a656c5e5523 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp @@ -91,6 +91,10 @@ int KX_BlenderRenderTools::ProcessLighting(int layer) { if (m_clientobject) { + if (layer == RAS_LIGHT_OBJECT_LAYER) + { + layer = static_cast(m_clientobject)->GetLayer(); + } if (applyLights(layer)) { EnableOpenGLLights(); diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 3e83ed20840..08e9e36c048 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -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; } diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp index a5b8d8aacdf..edda7657ef9 100644 --- a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp +++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp @@ -137,6 +137,10 @@ int GPC_RenderTools::ProcessLighting(int layer) { if (m_clientobject) { + if (layer == RAS_LIGHT_OBJECT_LAYER) + { + layer = static_cast(m_clientobject)->GetLayer(); + } if (applyLights(layer)) { EnableOpenGLLights(); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index cf621e04f99..301a1413bcd 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -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 diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 87775e81216..da0cd69e129 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -70,6 +70,7 @@ protected: KX_ClientObjectInfo* m_pClient_info; STR_String m_name; STR_String m_text; + int m_layer; std::vector 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. diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 54003284e03..e4054e07475 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -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 diff --git a/source/gameengine/Rasterizer/RAS_IRenderTools.h b/source/gameengine/Rasterizer/RAS_IRenderTools.h index 30c96d02847..16e15653c82 100644 --- a/source/gameengine/Rasterizer/RAS_IRenderTools.h +++ b/source/gameengine/Rasterizer/RAS_IRenderTools.h @@ -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( ) : diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp index 4642ffbaeb8..02e84f8a243 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp @@ -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); }