diff --git a/lportal.cpp b/lportal.cpp index e52676b..7f27bbe 100644 --- a/lportal.cpp +++ b/lportal.cpp @@ -23,10 +23,6 @@ #include "lroom.h" -//#define SMOOTHCLASS Smooth -//#define SMOOTHNODE Spatial -//#include "smooth_body.inl" - bool LPortal::NameStartsWith(Node * pNode, String szSearch) { int sl = szSearch.length(); @@ -37,7 +33,9 @@ bool LPortal::NameStartsWith(Node * pNode, String szSearch) if (l < sl) return false; - String szStart = name.substr(sl); + String szStart = name.substr(0, sl); + + //print_line("\t\tNameStartsWith szStart is " + szStart); if (szStart == szSearch) return true; @@ -46,11 +44,13 @@ bool LPortal::NameStartsWith(Node * pNode, String szSearch) } -String LPortal::FindNameAfter(Node * pNode, int CharsToMiss) +String LPortal::FindNameAfter(Node * pNode, String szStart) { String szRes; String name = pNode->get_name(); - szRes = name.substr(CharsToMiss); + szRes = name.substr(szStart.length()); + + print_line("\t\tNameAfter is " + szRes); return szRes; } @@ -85,13 +85,15 @@ LPortal::eClipResult LPortal::ClipWithPlane(const Plane &p) const void LPortal::Link(LRoom * pParentRoom) { // should start with 'portal_' - if (!NameStartsWith(this, "portal_")) + if (!NameStartsWith(this, "lportal_")) { WARN_PRINT("Portal name should begin with lportal_"); return; } - String szRoom = FindNameAfter(this, 8); + String szRoom = FindNameAfter(this, "lportal_"); + + print_line("LPortal::Link to room " + szRoom); // find the room group Spatial * pGroup = Object::cast_to(pParentRoom->get_parent()); @@ -134,27 +136,163 @@ void LPortal::CreateGeometry(PoolVector p_vertices) int nPoints = p_vertices.size(); ERR_FAIL_COND(nPoints < 3); + m_ptsLocal.resize(nPoints); m_ptsWorld.resize(nPoints); + print_line("\tLPortal::CreateGeometry nPoints : " + itos(nPoints)); + for (int n=0; n &verts = m_ptsLocal; + + // find normal + Plane plane = Plane(verts[0], verts[1], verts[2]); + Vector3 ptNormal = plane.normal; + + // find centroid + int nPoints = verts.size(); + + Vector3 ptCentre = Vector3(0, 0, 0); + + for (int n=0; n 0.0f) +// if (p.WhichSideNDLCompatible(m_Verts[m], 0.0f) != CoPlane::NEGATIVE_SIDE) + { + Vector3 b = m_ptsLocal[m] - ptCentre; + b.normalize(); + + double Angle = a.dot(b); + + if (Angle > SmallestAngle) + { + SmallestAngle = Angle; + Smallest = m; + } + } // which side + + } // for m + + // swap smallest and n+1 vert + if (Smallest != -1) + { + Vector3 temp = verts[Smallest]; + verts.set(Smallest, verts[n+1]); + verts.set(n+1, temp); + } + } // for n + + + // the vertices are now sorted, but may be in the opposite order to that wanted. + // we detect this by calculating the normal of the poly, then flipping the order if the normal is pointing + // the wrong way. + plane = Plane(verts[0], verts[1], verts[2]); + + if (ptNormal.dot(plane.normal) < 0.0f) + { + // reverse order of verts + ReverseWindingOrder(); + } + +} + +void LPortal::ReverseWindingOrder() +{ + Vector &verts = m_ptsLocal; + Vector copy = verts; + + for (int n=0; n(get_node(path)); @@ -202,6 +347,10 @@ bool LPortal::AddRoom(NodePath path) return false; } } + else + { + WARN_PRINTS("portal link room not found : " + path); + } return false; } @@ -211,97 +360,26 @@ LPortal::LPortal() { m_room_ID = 0; } +LRoom * LPortal::GetLinkedRoom() const +{ + Object *pObj = ObjectDB::get_instance(m_room_ID); + + if (!pObj) + return 0; + + LRoom * pRoom = Object::cast_to(pObj); + if (!pRoom) + { + WARN_PRINT_ONCE("LRoomManager::FrameUpdate : curr room is not an LRoom"); + } + + return pRoom; +} + void LPortal::_bind_methods() { -// BIND_ENUM_CONSTANT(MODE_LOCAL); -// BIND_ENUM_CONSTANT(MODE_GLOBAL); - - -// ClassDB::bind_method(D_METHOD("teleport"), &SMOOTHCLASS::teleport); - -// ClassDB::bind_method(D_METHOD("set_enabled"), &SMOOTHCLASS::set_enabled); -// ClassDB::bind_method(D_METHOD("is_enabled"), &SMOOTHCLASS::is_enabled); -// ClassDB::bind_method(D_METHOD("set_smooth_translate"), &SMOOTHCLASS::set_interpolate_translation); -// ClassDB::bind_method(D_METHOD("get_smooth_translate"), &SMOOTHCLASS::get_interpolate_translation); -// ClassDB::bind_method(D_METHOD("set_smooth_rotate"), &SMOOTHCLASS::set_interpolate_rotation); -// ClassDB::bind_method(D_METHOD("get_smooth_rotate"), &SMOOTHCLASS::get_interpolate_rotation); -// ClassDB::bind_method(D_METHOD("set_smooth_scale"), &SMOOTHCLASS::set_interpolate_scale); -// ClassDB::bind_method(D_METHOD("get_smooth_scale"), &SMOOTHCLASS::get_interpolate_scale); - -// ClassDB::bind_method(D_METHOD("set_input_mode", "mode"), &SMOOTHCLASS::set_input_mode); -// ClassDB::bind_method(D_METHOD("get_input_mode"), &SMOOTHCLASS::get_input_mode); -// ClassDB::bind_method(D_METHOD("set_output_mode", "mode"), &SMOOTHCLASS::set_output_mode); -// ClassDB::bind_method(D_METHOD("get_output_mode"), &SMOOTHCLASS::get_output_mode); - -// ClassDB::bind_method(D_METHOD("set_target", "target"), &SMOOTHCLASS::set_target); -// ClassDB::bind_method(D_METHOD("set_target_path", "path"), &SMOOTHCLASS::set_target_path); -// ClassDB::bind_method(D_METHOD("get_target_path"), &SMOOTHCLASS::get_target_path); - - -// ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); - -// ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "target"), "set_target_path", "get_target_path"); - - -// ADD_GROUP("Components", ""); -// ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_translate"), "set_smooth_translate", "get_smooth_translate"); -// ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_rotate"), "set_smooth_rotate", "get_smooth_rotate"); -// ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_scale"), "set_smooth_scale", "get_smooth_scale"); -// ADD_GROUP("Coords", ""); -// ADD_PROPERTY(PropertyInfo(Variant::INT, "input", PROPERTY_HINT_ENUM, "Local,Global"), "set_input_mode", "get_input_mode"); -// ADD_PROPERTY(PropertyInfo(Variant::INT, "output", PROPERTY_HINT_ENUM, "Local,Global"), "set_output_mode", "get_output_mode"); - -// ADD_PROPERTY(PropertyInfo(Variant::BOOL, "lerp"), "set_lerp", "get_lerp"); - -// finish the bind with custom stuff -//BIND_ENUM_CONSTANT(METHOD_SLERP); -//BIND_ENUM_CONSTANT(METHOD_LERP); -//ClassDB::bind_method(D_METHOD("set_method", "method"), &Room::set_method); -//ClassDB::bind_method(D_METHOD("get_method"), &Room::get_method); - -//ADD_GROUP("Misc", ""); -//ADD_PROPERTY(PropertyInfo(Variant::INT, "method", PROPERTY_HINT_ENUM, "Slerp,Lerp"), "set_method", "get_method"); } -//void Smooth::set_method(eMethod p_method) -//{ - //ChangeFlags(SF_LERP, p_method == METHOD_LERP); -//} - -//Smooth::eMethod Smooth::get_method() const -//{ - //if (TestFlags(SF_LERP)) - //return METHOD_LERP; - - //return METHOD_SLERP; -//} - - - - - - -//bool Smooth::FindVisibility() const -//{ -// const Spatial *s = this; - -// int count = 0; -// while (s) { - -// if (!s->data.visible) -// { -// print_line(itos(count++) + " hidden"); -// return false; -// } -// else -// { -// print_line(itos(count++) + " visible"); -// } -// s = s->data.parent; -// } - -// return true; -//} diff --git a/lportal.h b/lportal.h index 6d42fb3..5620239 100644 --- a/lportal.h +++ b/lportal.h @@ -66,20 +66,15 @@ protected: public: // normal determined by winding order Vector m_ptsWorld; + Vector m_ptsLocal; Plane m_Plane; - //enum eMethod - //{ - //METHOD_SLERP, - //METHOD_LERP, - //}; ObjectID GetLinkedRoomID() const {return m_room_ID;} + LRoom * GetLinkedRoom() const; LPortal(); -// void set_method(eMethod p_method); -// eMethod get_method() const; private: // use the name of the portal to find a room to link to void Link(LRoom * pParentRoom); @@ -88,16 +83,17 @@ private: void CreateGeometry(PoolVector p_vertices); void PlaneFromPoints(); + void CalculateWorldPoints(); + void CalculateLocalPoints(); + + void SortVertsClockwise(); + void ReverseWindingOrder(); + // useful funcs public: static bool NameStartsWith(Node * pNode, String szSearch); - static String FindNameAfter(Node * pNode, int CharsToMiss); + static String FindNameAfter(Node * pNode, String szStart); }; -//VARIANT_ENUM_CAST(Smooth::eMode); -//VARIANT_ENUM_CAST(Smooth::eMethod); - - - #endif diff --git a/lroom.cpp b/lroom.cpp index f17200a..d4361d8 100644 --- a/lroom.cpp +++ b/lroom.cpp @@ -24,18 +24,20 @@ #include "lportal.h" -//#define SMOOTHCLASS Smooth -//#define SMOOTHNODE Spatial -//#include "smooth_body.inl" - - LRoom::LRoom() { -// m_Flags = 0; -// SetFlags(SF_ENABLED | SF_TRANSLATE | SF_ROTATE); } -void LRoom::DetermineVisibility_Recursive(LCamera &cam, const Vector &planes, ObjectID portalID_from) +void LRoom::DetermineVisibility_Recursive(int depth, const LCamera &cam, const Vector &planes, ObjectID portalID_from) { + // prevent too much depth + if (depth >= 8) + { + print_line("\t\t\tDEPTH LIMIT REACHED"); + return; + } + + print_line("DetermineVisibility_Recursive from " + get_name()); + // clip all objects in this room to the clipping planes // NYI @@ -65,11 +67,16 @@ void LRoom::DetermineVisibility_Recursive(LCamera &cam, const Vector &pla } const Vector3 &portal_normal = pPortal->m_Plane.normal; + print_line("\ttesting portal " + pPortal->get_name() + " normal " + portal_normal); // direction with the camera? (might not need to check) float dot = cam.m_ptDir.dot(portal_normal); if (dot <= 0.0f) + { + Variant vd = dot; + print_line("\t\tportal culled (wrong direction) dot is " + String(vd)); continue; + } // is it culled by the planes? LPortal::eClipResult overall_res = LPortal::eClipResult::CLIP_INSIDE; @@ -94,7 +101,10 @@ void LRoom::DetermineVisibility_Recursive(LCamera &cam, const Vector &pla // this portal is culled if (overall_res == LPortal::eClipResult::CLIP_OUTSIDE) + { + print_line("\t\tportal culled (outside planes)"); continue; + } // else recurse into that portal Vector new_planes = planes; @@ -102,7 +112,10 @@ void LRoom::DetermineVisibility_Recursive(LCamera &cam, const Vector &pla // add the planes for the portal // NYI - DetermineVisibility_Recursive(cam, new_planes, id); + // get the room pointed to by the portal + LRoom * pLinkedRoom = pPortal->GetLinkedRoom(); + if (pLinkedRoom) + pLinkedRoom->DetermineVisibility_Recursive(depth + 1, cam, new_planes, id); } } @@ -112,6 +125,8 @@ void LRoom::DetermineVisibility_Recursive(LCamera &cam, const Vector &pla // which will be auto converted to LPortals with this method void LRoom::DetectPortalMeshes() { + print_line("DetectPortalMeshes"); + bool bFoundOne = true; while (bFoundOne) @@ -128,7 +143,7 @@ void LRoom::DetectPortalMeshes() // name must start with portal_ if (LPortal::NameStartsWith(pMesh, "portal_")) { - String szLinkRoom = LPortal::FindNameAfter(pMesh, 8); + String szLinkRoom = LPortal::FindNameAfter(pMesh, "portal_"); DetectedPortalMesh(pMesh, szLinkRoom); bFoundOne = true; } @@ -143,17 +158,21 @@ void LRoom::DetectPortalMeshes() void LRoom::DetectedPortalMesh(MeshInstance * pMeshInstance, String szLinkRoom) { + print_line("\tDetected PortalMesh"); + Ref rmesh = pMeshInstance->get_mesh(); Array arrays = rmesh->surface_get_arrays(0); PoolVector p_vertices = arrays[VS::ARRAY_VERTEX]; LPortal * pNew = memnew(LPortal); - pNew->set_name("lportal"); + pNew->set_name("lportal_"); add_child(pNew); + pNew->set_transform(pMeshInstance->get_transform()); + NodePath temppath = "../../" + szLinkRoom; - pNew->AddRoom(szLinkRoom); + pNew->AddRoom(temppath); // create the portal geometry pNew->CreateGeometry(p_vertices); @@ -231,132 +250,6 @@ void LRoom::MakeOppositePortal(LPortal * pPortalFrom, LRoom * pRoomTo) void LRoom::_bind_methods() { -// BIND_ENUM_CONSTANT(MODE_LOCAL); -// BIND_ENUM_CONSTANT(MODE_GLOBAL); - - -// ClassDB::bind_method(D_METHOD("teleport"), &SMOOTHCLASS::teleport); - -// ClassDB::bind_method(D_METHOD("set_enabled"), &SMOOTHCLASS::set_enabled); -// ClassDB::bind_method(D_METHOD("is_enabled"), &SMOOTHCLASS::is_enabled); -// ClassDB::bind_method(D_METHOD("set_smooth_translate"), &SMOOTHCLASS::set_interpolate_translation); -// ClassDB::bind_method(D_METHOD("get_smooth_translate"), &SMOOTHCLASS::get_interpolate_translation); -// ClassDB::bind_method(D_METHOD("set_smooth_rotate"), &SMOOTHCLASS::set_interpolate_rotation); -// ClassDB::bind_method(D_METHOD("get_smooth_rotate"), &SMOOTHCLASS::get_interpolate_rotation); -// ClassDB::bind_method(D_METHOD("set_smooth_scale"), &SMOOTHCLASS::set_interpolate_scale); -// ClassDB::bind_method(D_METHOD("get_smooth_scale"), &SMOOTHCLASS::get_interpolate_scale); - -// ClassDB::bind_method(D_METHOD("set_input_mode", "mode"), &SMOOTHCLASS::set_input_mode); -// ClassDB::bind_method(D_METHOD("get_input_mode"), &SMOOTHCLASS::get_input_mode); -// ClassDB::bind_method(D_METHOD("set_output_mode", "mode"), &SMOOTHCLASS::set_output_mode); -// ClassDB::bind_method(D_METHOD("get_output_mode"), &SMOOTHCLASS::get_output_mode); - -// ClassDB::bind_method(D_METHOD("set_target", "target"), &SMOOTHCLASS::set_target); -// ClassDB::bind_method(D_METHOD("set_target_path", "path"), &SMOOTHCLASS::set_target_path); -// ClassDB::bind_method(D_METHOD("get_target_path"), &SMOOTHCLASS::get_target_path); - - -// ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); - -// ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "target"), "set_target_path", "get_target_path"); - - -// ADD_GROUP("Components", ""); -// ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_translate"), "set_smooth_translate", "get_smooth_translate"); -// ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_rotate"), "set_smooth_rotate", "get_smooth_rotate"); -// ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_scale"), "set_smooth_scale", "get_smooth_scale"); -// ADD_GROUP("Coords", ""); -// ADD_PROPERTY(PropertyInfo(Variant::INT, "input", PROPERTY_HINT_ENUM, "Local,Global"), "set_input_mode", "get_input_mode"); -// ADD_PROPERTY(PropertyInfo(Variant::INT, "output", PROPERTY_HINT_ENUM, "Local,Global"), "set_output_mode", "get_output_mode"); - -// ADD_PROPERTY(PropertyInfo(Variant::BOOL, "lerp"), "set_lerp", "get_lerp"); - -// finish the bind with custom stuff -//BIND_ENUM_CONSTANT(METHOD_SLERP); -//BIND_ENUM_CONSTANT(METHOD_LERP); -//ClassDB::bind_method(D_METHOD("set_method", "method"), &LRoom::set_method); -//ClassDB::bind_method(D_METHOD("get_method"), &LRoom::get_method); - -//ADD_GROUP("Misc", ""); -//ADD_PROPERTY(PropertyInfo(Variant::INT, "method", PROPERTY_HINT_ENUM, "Slerp,Lerp"), "set_method", "get_method"); } - -//void LRoom::SetupPortal(LPortal * pPortal) -//{ -// ObjectID id = pPortal->get_instance_id(); -// m_portal_IDs.push_back(id); - -//} - -//void LRoom::AddPortal(ObjectID id) -//{ -//} - -//bool LRoom::AddPortal(LPortal * pNode) -//{ -// if (has_node(path)) -// { -// LPortal * pNode = Object::cast_to(get_node(path)); -// if (pNode) -// { -// ObjectID id = pNode->get_instance_id(); - -// m_portal_paths.push_back(path); -// m_portal_IDs.push_back(id); - -// // add the room to the portal automatically -// NodePath self_path = get_path_to(this); -// pNode->AddRoom(self_path); -// return true; -// } -// else -// { -// WARN_PRINT("not a portal"); -// return false; -// } -// } - -// return false; -//} - -//void Smooth::set_method(eMethod p_method) -//{ - //ChangeFlags(SF_LERP, p_method == METHOD_LERP); -//} - -//Smooth::eMethod Smooth::get_method() const -//{ - //if (TestFlags(SF_LERP)) - //return METHOD_LERP; - - //return METHOD_SLERP; -//} - - - - - - -//bool Smooth::FindVisibility() const -//{ -// const Spatial *s = this; - -// int count = 0; -// while (s) { - -// if (!s->data.visible) -// { -// print_line(itos(count++) + " hidden"); -// return false; -// } -// else -// { -// print_line(itos(count++) + " visible"); -// } -// s = s->data.parent; -// } - -// return true; -//} diff --git a/lroom.h b/lroom.h index d955f7b..6230072 100644 --- a/lroom.h +++ b/lroom.h @@ -55,20 +55,7 @@ class LRoom : public Spatial { GDCLASS(LRoom, Spatial); friend class LPortal; -public: - -// custom private: - //class STransform - //{ - //public: - //Transform m_Transform; - //Quat m_qtRotate; - //Vector3 m_ptScale; - //}; - - //Vector3 m_ptTranslateDiff; - // a quick list of object IDs of child portals of this room Vector m_portal_IDs; @@ -76,13 +63,6 @@ protected: static void _bind_methods(); public: - //enum eMethod - //{ - //METHOD_SLERP, - //METHOD_LERP, - //}; -// bool AddPortal(LPortal * pNode); - // initial setup, allows importing portals as meshes from modelling program, // which will be auto converted to LPortals with this method void DetectPortalMeshes(); @@ -91,25 +71,19 @@ public: void MakePortalQuickList(); // main function - void DetermineVisibility_Recursive(LCamera &cam, const Vector &planes, ObjectID portalID_from = 0); + void DetermineVisibility_Recursive(int depth, const LCamera &cam, const Vector &planes, ObjectID portalID_from = 0); // specific public: LRoom(); -// void set_method(eMethod p_method); -// eMethod get_method() const; private: // void SetupPortal(LPortal * pPortal); void MakeOppositePortal(LPortal * pPortalFrom, LRoom * pRoomTo); void DetectedPortalMesh(MeshInstance * pMeshInstance, String szLinkRoom); -// void AddPortal(ObjectID id); -// void LerpBasis(const Basis &from, const Basis &to, Basis &res, float f) const; }; -//VARIANT_ENUM_CAST(Smooth::eMode); -//VARIANT_ENUM_CAST(Smooth::eMethod); #endif diff --git a/lroom_manager.cpp b/lroom_manager.cpp index 4582f22..93476b5 100644 --- a/lroom_manager.cpp +++ b/lroom_manager.cpp @@ -21,22 +21,54 @@ #include "lroom_manager.h" #include "lportal.h" #include "lroom.h" +#include "core/engine.h" LRoomManager::LRoomManager() { - + m_room_curr = 0; } // convert empties and meshes to rooms and portals -void LRoomManager::Convert() +void LRoomManager::convert() { + print_line("running convert"); + Convert_Rooms(); Convert_Portals(); + Find_Rooms(); +} + +void LRoomManager::Find_Rooms() +{ + print_line ("Find_Rooms"); + m_room_IDs.clear(); + + // first find all room empties and convert to LRooms + for (int n=0; n(pChild); + if (pRoom) + m_room_IDs.push_back(pRoom->get_instance_id()); + } + + m_room_curr = 0; + + // just set current room to first room + if (m_room_IDs.size()) + { + m_room_curr = m_room_IDs[0]; + print_line("first room ID is " + itos(m_room_curr)); + } } void LRoomManager::Convert_Rooms() { + print_line("Convert_Rooms"); + bool bConvertedOne = true; // instead of recursive routine @@ -54,9 +86,13 @@ void LRoomManager::Convert_Rooms() if (pRoom) continue; - if (LPortal::NameStartsWith(pChild, "room_")) + Spatial * pSpatialChild = Object::cast_to(pChild); + if (!pSpatialChild) + continue; + + if (LPortal::NameStartsWith(pSpatialChild, "room_")) { - if (Convert_Room(pChild)) + if (Convert_Room(pSpatialChild)) bConvertedOne = true; } @@ -71,6 +107,8 @@ void LRoomManager::Convert_Portals() { for (int pass=0; pass<3; pass++) { + print_line("Convert_Portals pass " + itos(pass)); + // first find all room empties and convert to LRooms for (int n=0; nget_name(); - String szRoom = LPortal::FindNameAfter(pNode, 6); + String szRoom = LPortal::FindNameAfter(pNode, "room_"); + + print_line("Convert_Room : " + szFullName); // create a new LRoom to exchange the children over to, and delete the original empty LRoom * pNew = memnew(LRoom); pNew->set_name(szRoom); add_child(pNew); + // make the transform of the L room match the original spatial + pNew->set_transform(pNode->get_transform()); + int nChildren = pNode->get_child_count(); for (int n=0; n(pObj); + if (!pRoom) + { + WARN_PRINT_ONCE("LRoomManager::FrameUpdate : curr room is not an LRoom"); + print_line("curr room is not an LRoom"); + m_room_curr = 0; + return; + } + + LCamera cam; + cam.m_ptPos = Vector3(0, 0, 0); + cam.m_ptDir = Vector3 (-1, 0, 0); + + Vector planes; + + pRoom->DetermineVisibility_Recursive(0, cam, planes); + + + + // only do once for now + m_room_curr = 0; +} + + +void LRoomManager::_notification(int p_what) { + + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { +// bool bVisible = is_visible_in_tree(); +// ChangeFlags(SF_INVISIBLE, bVisible == false); +// SetProcessing(); + if (!Engine::get_singleton()->is_editor_hint()) + set_process_internal(true); + +// // we can't translate string name of Target to a node until we are in the tree +// ResolveTargetPath(); + } break; +// case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { +// FixedUpdate(); +// } break; + case NOTIFICATION_INTERNAL_PROCESS: { + FrameUpdate(); + } break; +// case NOTIFICATION_VISIBILITY_CHANGED: { +// bool bVisible = is_visible_in_tree(); +// ChangeFlags(SF_INVISIBLE, bVisible == false); +// SetProcessing(); +//// if (bVisible) +//// print_line("now visible"); +//// else +//// print_line("now hidden"); +// } break; + } +} + void LRoomManager::_bind_methods() { + ClassDB::bind_method(D_METHOD("convert"), &LRoomManager::convert); } diff --git a/lroom_manager.h b/lroom_manager.h index 8c07af3..a5fa665 100644 --- a/lroom_manager.h +++ b/lroom_manager.h @@ -31,19 +31,28 @@ class LRoomManager : public Spatial { GDCLASS(LRoomManager, Spatial); + // a quick list of object IDs of child rooms + Vector m_room_IDs; + + ObjectID m_room_curr; + public: LRoomManager(); // convert empties and meshes to rooms and portals - void Convert(); + void convert(); protected: static void _bind_methods(); + void _notification(int p_what); private: void Convert_Rooms(); - bool Convert_Room(Node * pNode); + bool Convert_Room(Spatial * pNode); void Convert_Portals(); + void Find_Rooms(); + + void FrameUpdate(); }; #endif