mirror of
https://github.com/Relintai/godot-lportal.git
synced 2024-11-11 10:52:09 +01:00
Hiding is now detach from scene tree
This commit is contained in:
parent
aa10d540cc
commit
5da7be42e2
@ -6,7 +6,7 @@ namespace Lawn
|
|||||||
int LDebug::m_iLoggingLevel = 0; // 2
|
int LDebug::m_iLoggingLevel = 0; // 2
|
||||||
int LDebug::m_iWarningLevel = 0;
|
int LDebug::m_iWarningLevel = 0;
|
||||||
int LDebug::m_iTabDepth = 0;
|
int LDebug::m_iTabDepth = 0;
|
||||||
bool LDebug::m_bRunning = false;
|
bool LDebug::m_bRunning = true;
|
||||||
|
|
||||||
|
|
||||||
void LDebug::print(String sz)
|
void LDebug::print(String sz)
|
||||||
|
105
ldob.cpp
105
ldob.cpp
@ -24,8 +24,67 @@
|
|||||||
|
|
||||||
#include "ldob.h"
|
#include "ldob.h"
|
||||||
#include "scene/3d/mesh_instance.h"
|
#include "scene/3d/mesh_instance.h"
|
||||||
|
#include "scene/3d/light.h"
|
||||||
|
|
||||||
|
|
||||||
|
void LHidable::Hidable_Create(Node * pNode)
|
||||||
|
{
|
||||||
|
// m_pNode = 0; m_pParent = 0; m_bShow = true;
|
||||||
|
m_pNode = pNode;
|
||||||
|
m_pParent = m_pNode->get_parent();
|
||||||
|
m_bShow = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LHidable::Show(bool bShow)
|
||||||
|
{
|
||||||
|
// noop
|
||||||
|
if (bShow == m_bShow)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// new state
|
||||||
|
m_bShow = bShow;
|
||||||
|
|
||||||
|
assert (m_pParent);
|
||||||
|
|
||||||
|
if (bShow)
|
||||||
|
{
|
||||||
|
// add to tree
|
||||||
|
m_pParent->add_child(m_pNode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// remove from tree
|
||||||
|
m_pParent->remove_child(m_pNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
void LLight::SetDefaults()
|
||||||
|
{
|
||||||
|
m_GodotID = 0;
|
||||||
|
m_eType = LT_DIRECTIONAL;
|
||||||
|
m_fSpread = 0.0f; // for spotlight
|
||||||
|
m_fMaxDist = 100.0f;
|
||||||
|
m_RoomID = -1;
|
||||||
|
|
||||||
|
m_FirstCaster = 0;
|
||||||
|
m_NumCasters = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Light * LLight::GetGodotLight()
|
||||||
|
{
|
||||||
|
Object * pObj = ObjectDB::get_instance(m_GodotID);
|
||||||
|
Light * p = Object::cast_to<Light>(pObj);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
Spatial * LSob::GetSpatial() const
|
Spatial * LSob::GetSpatial() const
|
||||||
{
|
{
|
||||||
Object * pObj = ObjectDB::get_instance(m_ID);
|
Object * pObj = ObjectDB::get_instance(m_ID);
|
||||||
@ -60,30 +119,52 @@ VisualInstance * LSob::GetVI() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
void LSob::Show(bool bShow)
|
void LSob::Show(bool bShow)
|
||||||
{
|
{
|
||||||
|
// noop
|
||||||
|
if (bShow == m_bShow)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// new state
|
||||||
|
m_bShow = bShow;
|
||||||
|
|
||||||
Spatial * pS = GetSpatial();
|
Spatial * pS = GetSpatial();
|
||||||
if (!pS)
|
if (!pS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// noop
|
assert (m_pParent);
|
||||||
if (pS->is_visible() == bShow)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (bShow)
|
if (bShow)
|
||||||
pS->show();
|
|
||||||
else
|
|
||||||
pS->hide();
|
|
||||||
|
|
||||||
GeometryInstance * pGI = Object::cast_to<GeometryInstance>(pS);
|
|
||||||
if (pGI)
|
|
||||||
{
|
{
|
||||||
// godot visible bug workaround
|
// add to tree
|
||||||
pGI->set_extra_cull_margin(0.0f);
|
m_pParent->add_child(m_pNode);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// remove from tree
|
||||||
|
m_pParent->remove_child(m_pNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
// noop
|
||||||
|
// if (pS->is_visible() == bShow)
|
||||||
|
// return;
|
||||||
|
|
||||||
|
// if (bShow)
|
||||||
|
// pS->show();
|
||||||
|
// else
|
||||||
|
// pS->hide();
|
||||||
|
|
||||||
|
// GeometryInstance * pGI = Object::cast_to<GeometryInstance>(pS);
|
||||||
|
// if (pGI)
|
||||||
|
// {
|
||||||
|
// // godot visible bug workaround
|
||||||
|
// pGI->set_extra_cull_margin(0.0f);
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
Spatial * LDob::GetSpatial() const
|
Spatial * LDob::GetSpatial() const
|
||||||
|
49
ldob.h
49
ldob.h
@ -28,19 +28,33 @@
|
|||||||
#include "scene/3d/spatial.h"
|
#include "scene/3d/spatial.h"
|
||||||
|
|
||||||
class VisualInstance;
|
class VisualInstance;
|
||||||
|
class Light;
|
||||||
|
|
||||||
|
class LHidable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void Hidable_Create(Node * pNode);
|
||||||
|
void Show(bool bShow);
|
||||||
|
|
||||||
|
// new .. can be separated from the scene tree to cull
|
||||||
|
Node * m_pNode;
|
||||||
|
Node * m_pParent;
|
||||||
|
|
||||||
|
// separate flag so we don't have to touch the godot lookup
|
||||||
|
bool m_bShow;
|
||||||
|
};
|
||||||
|
|
||||||
// static object
|
// static object
|
||||||
class LSob
|
class LSob : public LHidable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Spatial * GetSpatial() const;
|
Spatial * GetSpatial() const;
|
||||||
VisualInstance * GetVI() const;
|
VisualInstance * GetVI() const;
|
||||||
void Show(bool bShow);
|
//void Show(bool bShow);
|
||||||
bool IsShadowCaster() const;
|
bool IsShadowCaster() const;
|
||||||
|
|
||||||
ObjectID m_ID; // godot object
|
ObjectID m_ID; // godot object
|
||||||
AABB m_aabb; // world space
|
AABB m_aabb; // world space
|
||||||
//bool m_bSOBVisible;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// dynamic object
|
// dynamic object
|
||||||
@ -55,3 +69,32 @@ public:
|
|||||||
bool m_bVisible;
|
bool m_bVisible;
|
||||||
float m_fRadius;
|
float m_fRadius;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class LLight : public LHidable
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum eLightType
|
||||||
|
{
|
||||||
|
LT_DIRECTIONAL,
|
||||||
|
LT_SPOTLIGHT,
|
||||||
|
LT_OMNI,
|
||||||
|
};
|
||||||
|
void SetDefaults();
|
||||||
|
Light * GetGodotLight();
|
||||||
|
bool IsGlobal() const {return m_RoomID == -1;}
|
||||||
|
|
||||||
|
Vector3 m_ptDir;
|
||||||
|
Vector3 m_ptPos;
|
||||||
|
ObjectID m_GodotID;
|
||||||
|
eLightType m_eType;
|
||||||
|
float m_fSpread; // for spotlight
|
||||||
|
float m_fMaxDist; // shadow distance not light distance
|
||||||
|
|
||||||
|
// source room
|
||||||
|
int m_RoomID; // or -1 for global lights
|
||||||
|
|
||||||
|
// shadow casters
|
||||||
|
int m_FirstCaster;
|
||||||
|
int m_NumCasters;
|
||||||
|
};
|
||||||
|
21
lportal.cpp
21
lportal.cpp
@ -23,27 +23,6 @@
|
|||||||
#include "lroom.h"
|
#include "lroom.h"
|
||||||
#include "ldebug.h"
|
#include "ldebug.h"
|
||||||
#include "lroom_manager.h"
|
#include "lroom_manager.h"
|
||||||
#include "scene/3d/light.h"
|
|
||||||
|
|
||||||
void LLight::SetDefaults()
|
|
||||||
{
|
|
||||||
m_GodotID = 0;
|
|
||||||
m_eType = LT_DIRECTIONAL;
|
|
||||||
m_fSpread = 0.0f; // for spotlight
|
|
||||||
m_fMaxDist = 100.0f;
|
|
||||||
m_RoomID = -1;
|
|
||||||
|
|
||||||
m_FirstCaster = 0;
|
|
||||||
m_NumCasters = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Light * LLight::GetGodotLight()
|
|
||||||
{
|
|
||||||
Object * pObj = ObjectDB::get_instance(m_GodotID);
|
|
||||||
Light * p = Object::cast_to<Light>(pObj);
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
27
lportal.h
27
lportal.h
@ -35,33 +35,6 @@ class LRoomManager;
|
|||||||
class Light;
|
class Light;
|
||||||
|
|
||||||
|
|
||||||
class LLight
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum eLightType
|
|
||||||
{
|
|
||||||
LT_DIRECTIONAL,
|
|
||||||
LT_SPOTLIGHT,
|
|
||||||
LT_OMNI,
|
|
||||||
};
|
|
||||||
void SetDefaults();
|
|
||||||
Light * GetGodotLight();
|
|
||||||
bool IsGlobal() const {return m_RoomID == -1;}
|
|
||||||
|
|
||||||
Vector3 m_ptDir;
|
|
||||||
Vector3 m_ptPos;
|
|
||||||
ObjectID m_GodotID;
|
|
||||||
eLightType m_eType;
|
|
||||||
float m_fSpread; // for spotlight
|
|
||||||
float m_fMaxDist; // shadow distance not light distance
|
|
||||||
|
|
||||||
// source room
|
|
||||||
int m_RoomID; // or -1 for global lights
|
|
||||||
|
|
||||||
// shadow casters
|
|
||||||
int m_FirstCaster;
|
|
||||||
int m_NumCasters;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class LPortal {
|
class LPortal {
|
||||||
|
12
lroom.cpp
12
lroom.cpp
@ -198,7 +198,7 @@ void LRoom::SoftShow(VisualInstance * pVI, uint32_t show_flags)
|
|||||||
// naive version, adds all the non visible objects in visible rooms as shadow casters
|
// naive version, adds all the non visible objects in visible rooms as shadow casters
|
||||||
void LRoom::AddShadowCasters(LRoomManager &manager)
|
void LRoom::AddShadowCasters(LRoomManager &manager)
|
||||||
{
|
{
|
||||||
LPRINT(2, "ADDSHADOWCASTERS room " + get_name() + ", " + itos(m_iNumShadowCasters_SOB) + " shadow casters");
|
LPRINT_RUN(2, "ADDSHADOWCASTERS room " + get_name() + ", " + itos(m_iNumShadowCasters_SOB) + " shadow casters");
|
||||||
|
|
||||||
// add all the active lights in this room
|
// add all the active lights in this room
|
||||||
for (int n=0; n<m_LocalLights.size(); n++)
|
for (int n=0; n<m_LocalLights.size(); n++)
|
||||||
@ -219,7 +219,7 @@ void LRoom::AddShadowCasters(LRoomManager &manager)
|
|||||||
// only add to the caster list if not in it already (does this check need to happen, can this ever occur?)
|
// only add to the caster list if not in it already (does this check need to happen, can this ever occur?)
|
||||||
if (!manager.m_BF_caster_SOBs.GetBit(sobID))
|
if (!manager.m_BF_caster_SOBs.GetBit(sobID))
|
||||||
{
|
{
|
||||||
//LPRINT(2, "\t" + itos(sobID) + ", " + manager.m_SOBs[sobID].GetSpatial()->get_name());
|
LPRINT_RUN(2, "\t" + itos(sobID) + ", " + manager.m_SOBs[sobID].GetSpatial()->get_name());
|
||||||
manager.m_BF_caster_SOBs.SetBit(sobID, true);
|
manager.m_BF_caster_SOBs.SetBit(sobID, true);
|
||||||
manager.m_CasterList_SOBs.push_back(sobID);
|
manager.m_CasterList_SOBs.push_back(sobID);
|
||||||
}
|
}
|
||||||
@ -363,7 +363,7 @@ void LRoom::Room_MakeVisible(bool bVisible)
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
// show godot room and all linked dobs and all sobs
|
// show godot room and all linked dobs and all sobs
|
||||||
void LRoom::Debug_ShowAll()
|
void LRoom::Debug_ShowAll(bool bActive)
|
||||||
{
|
{
|
||||||
Room_MakeVisible(true);
|
Room_MakeVisible(true);
|
||||||
|
|
||||||
@ -374,6 +374,12 @@ void LRoom::Debug_ShowAll()
|
|||||||
// Spatial * pS = sob.GetSpatial();
|
// Spatial * pS = sob.GetSpatial();
|
||||||
// if (pS)
|
// if (pS)
|
||||||
// pS->show();
|
// pS->show();
|
||||||
|
|
||||||
|
// VisualInstance * pVI = sob.GetVI();
|
||||||
|
// if (pVI)
|
||||||
|
// {
|
||||||
|
// SoftShow(pVI, LRoom::LAYER_MASK_CAMERA | LRoom::LAYER_MASK_LIGHT);
|
||||||
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
2
lroom.h
2
lroom.h
@ -112,7 +112,7 @@ public:
|
|||||||
// void Hide_All();
|
// void Hide_All();
|
||||||
|
|
||||||
// show godot room and all linked dobs and all sobs
|
// show godot room and all linked dobs and all sobs
|
||||||
void Debug_ShowAll();
|
void Debug_ShowAll(bool bActive);
|
||||||
|
|
||||||
// hide all the objects not hit on this frame .. instead of calling godot hide without need
|
// hide all the objects not hit on this frame .. instead of calling godot hide without need
|
||||||
// (it might be expensive)
|
// (it might be expensive)
|
||||||
|
@ -182,6 +182,7 @@ void LRoomConverter::Convert_Room_FindObjects_Recursive(Node * pParent, LRoom &l
|
|||||||
LSob sob;
|
LSob sob;
|
||||||
sob.m_ID = pVI->get_instance_id();
|
sob.m_ID = pVI->get_instance_id();
|
||||||
sob.m_aabb = bb;
|
sob.m_aabb = bb;
|
||||||
|
sob.Hidable_Create(pChild);
|
||||||
|
|
||||||
//lroom.m_SOBs.push_back(sob);
|
//lroom.m_SOBs.push_back(sob);
|
||||||
LRoom_PushBackSOB(lroom, sob);
|
LRoom_PushBackSOB(lroom, sob);
|
||||||
@ -345,6 +346,15 @@ void LRoomConverter::Convert_HideAll()
|
|||||||
LSob &sob = LMAN->m_SOBs[n];
|
LSob &sob = LMAN->m_SOBs[n];
|
||||||
sob.Show(false);
|
sob.Show(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hide all lights that are non global
|
||||||
|
for (int n=0; n<LMAN->m_Lights.size(); n++)
|
||||||
|
{
|
||||||
|
LLight &light = LMAN->m_Lights[n];
|
||||||
|
if (!light.IsGlobal())
|
||||||
|
light.Show(false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LRoomConverter::Convert_Lights()
|
void LRoomConverter::Convert_Lights()
|
||||||
|
@ -480,6 +480,7 @@ bool LRoomManager::LightCreate(Light * pLight, int roomID)
|
|||||||
// create new light
|
// create new light
|
||||||
LLight l;
|
LLight l;
|
||||||
l.SetDefaults();
|
l.SetDefaults();
|
||||||
|
l.Hidable_Create(pLight);
|
||||||
l.m_GodotID = pLight->get_instance_id();
|
l.m_GodotID = pLight->get_instance_id();
|
||||||
|
|
||||||
// direction
|
// direction
|
||||||
@ -535,7 +536,10 @@ bool LRoomManager::LightCreate(Light * pLight, int roomID)
|
|||||||
|
|
||||||
// turn the local light off to start with
|
// turn the local light off to start with
|
||||||
if (!l.IsGlobal())
|
if (!l.IsGlobal())
|
||||||
pLight->hide();
|
{
|
||||||
|
// l.Show(false);
|
||||||
|
//pLight->hide();
|
||||||
|
}
|
||||||
|
|
||||||
m_Lights.push_back(l);
|
m_Lights.push_back(l);
|
||||||
|
|
||||||
@ -688,10 +692,33 @@ void LRoomManager::rooms_set_active(bool bActive)
|
|||||||
for (int n=0; n<m_Rooms.size(); n++)
|
for (int n=0; n<m_Rooms.size(); n++)
|
||||||
{
|
{
|
||||||
LRoom &lroom = m_Rooms[n];
|
LRoom &lroom = m_Rooms[n];
|
||||||
lroom.Debug_ShowAll();
|
lroom.Debug_ShowAll(bActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (int n=0; n<m_SOBs.size(); n++)
|
||||||
|
{
|
||||||
|
LSob &sob = m_SOBs[n];
|
||||||
|
Spatial * pS = sob.GetSpatial();
|
||||||
|
if (pS)
|
||||||
|
if (!bActive)
|
||||||
|
pS->show();
|
||||||
|
else
|
||||||
|
pS->hide();
|
||||||
|
|
||||||
|
VisualInstance * pVI = sob.GetVI();
|
||||||
|
if (pVI)
|
||||||
|
{
|
||||||
|
uint32_t mask = 0;
|
||||||
|
if (!bActive)
|
||||||
|
{
|
||||||
|
mask = LRoom::LAYER_MASK_CAMERA | LRoom::LAYER_MASK_LIGHT;
|
||||||
|
}
|
||||||
|
LRoom::SoftShow(pVI, mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LRoomManager::rooms_set_logging(int level)
|
void LRoomManager::rooms_set_logging(int level)
|
||||||
@ -1015,11 +1042,13 @@ void LRoomManager::FrameUpdate_FinalizeVisibility_SoftShow()
|
|||||||
if (!m_BF_ActiveLights_prev.GetBit(lid))
|
if (!m_BF_ActiveLights_prev.GetBit(lid))
|
||||||
{
|
{
|
||||||
LLight &light = m_Lights[lid];
|
LLight &light = m_Lights[lid];
|
||||||
|
light.Show(true);
|
||||||
|
|
||||||
Light * pLight = light.GetGodotLight();
|
Light * pLight = light.GetGodotLight();
|
||||||
if (pLight)
|
if (pLight)
|
||||||
{
|
{
|
||||||
//Lawn::LDebug::print("Showing light " + itos (n));
|
//Lawn::LDebug::print("Showing light " + itos (n));
|
||||||
pLight->show();
|
//pLight->show();
|
||||||
|
|
||||||
// FIX GODOT BUG - light cull mask is not preserved when hiding and showing
|
// FIX GODOT BUG - light cull mask is not preserved when hiding and showing
|
||||||
// set culling flag for light
|
// set culling flag for light
|
||||||
@ -1038,12 +1067,13 @@ void LRoomManager::FrameUpdate_FinalizeVisibility_SoftShow()
|
|||||||
if (!m_BF_ActiveLights.GetBit(lid))
|
if (!m_BF_ActiveLights.GetBit(lid))
|
||||||
{
|
{
|
||||||
LLight &light = m_Lights[lid];
|
LLight &light = m_Lights[lid];
|
||||||
Light * pLight = light.GetGodotLight();
|
light.Show(false);
|
||||||
if (pLight)
|
// Light * pLight = light.GetGodotLight();
|
||||||
{
|
// if (pLight)
|
||||||
//Lawn::LDebug::print("Hiding light " + itos (n));
|
// {
|
||||||
pLight->hide();
|
// //Lawn::LDebug::print("Hiding light " + itos (n));
|
||||||
}
|
// pLight->hide();
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user