diff --git a/lportal.cpp b/lportal.cpp index 32416ed..d23478a 100644 --- a/lportal.cpp +++ b/lportal.cpp @@ -229,7 +229,7 @@ LPortal::eClipResult LPortal::ClipWithPlane(const Plane &p) const } -void LPortal::CreateGeometry(PoolVector p_vertices, const Transform &trans) +void LPortal::CreateGeometry(PoolVector p_vertices, const Transform &trans, bool bPortalPlane_Convention) { int nPoints = p_vertices.size(); ERR_FAIL_COND(nPoints < 3); @@ -238,10 +238,16 @@ void LPortal::CreateGeometry(PoolVector p_vertices, const Transform &tr //print("\t\t\tLPortal::CreateGeometry nPoints : " + itos(nPoints)); + //Vector3 ptFirstThree[3]; + for (int n=0; n p_vertices, const Transform &tr //print("\t\t\t\t" + itos(n) + "\tLocal : " + Variant(p_vertices[n]) + "\tWorld : " + ptWorld); } - SortVertsClockwise(); +// Plane portal_plane = Plane(ptFirstThree[0], ptFirstThree[1], ptFirstThree[2]); + + SortVertsClockwise(bPortalPlane_Convention); PlaneFromPoints(); } -// assume first 3 determine the desired normal -void LPortal::SortVertsClockwise() +void LPortal::SortVertsClockwise(bool bPortalPlane_Convention) { Vector &verts = m_ptsWorld; + // We first assumed first 3 determine the desired normal + // find normal - Plane plane = Plane(verts[0], verts[1], verts[2]); + Plane plane; + if (bPortalPlane_Convention) + plane = Plane(verts[0], verts[2], verts[1]); + else + plane = Plane(verts[0], verts[1], verts[2]); + Vector3 ptNormal = plane.normal; // find centroid diff --git a/lportal.h b/lportal.h index 3b7b929..73741d1 100644 --- a/lportal.h +++ b/lportal.h @@ -76,9 +76,9 @@ public: LPortal(); void CopyReversedGeometry(const LPortal &source); - void CreateGeometry(PoolVector p_vertices, const Transform &trans); + void CreateGeometry(PoolVector p_vertices, const Transform &trans, bool bPortalPlane_Convention); void PlaneFromPoints(); - void SortVertsClockwise(); + void SortVertsClockwise(bool bPortalPlane_Convention); void ReverseWindingOrder(); // useful funcs diff --git a/lroom_converter.cpp b/lroom_converter.cpp index f29ec37..2d4bffc 100644 --- a/lroom_converter.cpp +++ b/lroom_converter.cpp @@ -1388,7 +1388,7 @@ void LRoomConverter::LRoom_DetectedPortalMesh(LRoom &lroom, LTempRoom &troom, Me lport.m_iRoomNum = iLinkRoom; // create the portal geometry - lport.CreateGeometry(p_vertices, pMeshInstance->get_global_transform()); + lport.CreateGeometry(p_vertices, pMeshInstance->get_global_transform(), LMAN->m_bPortalPlane_Convention); // LPRINT(2, "\t\t\tnum portals now " + itos(troom.m_Portals.size())); diff --git a/lroom_manager.cpp b/lroom_manager.cpp index 500327b..9e4edb7 100644 --- a/lroom_manager.cpp +++ b/lroom_manager.cpp @@ -56,6 +56,8 @@ LRoomManager::LRoomManager() m_bActive = true; m_bFrustumOnly = false; + m_bPortalPlane_Convention = false; + // to know which rooms to hide we keep track of which were shown this, and the previous frame m_pCurr_VisibleRoomList = &m_VisibleRoomList_A; m_pPrev_VisibleRoomList = &m_VisibleRoomList_B; @@ -1025,6 +1027,17 @@ int LRoomManager::rooms_get_num_rooms() const return m_Rooms.size(); } +Vector3 LRoomManager::rooms_get_room_centre(int room_id) const +{ + const LRoom * pRoom = GetRoom(room_id); + + if (!pRoom) + return Vector3(0, 0, 0); + + return pRoom->m_ptCentre; +} + + bool LRoomManager::rooms_is_room_visible(int room_id) const { if (room_id >= m_Rooms.size()) @@ -1218,6 +1231,12 @@ bool LRoomManager::rooms_single_room_convert(bool bVerbose, bool bDeleteLights) return RoomsConvert(bVerbose, bDeleteLights, true); } + +void LRoomManager::rooms_set_portal_plane_convention(bool bFlip) +{ + m_bPortalPlane_Convention = bFlip; +} + // convert empties and meshes to rooms and portals bool LRoomManager::rooms_convert(bool bVerbose, bool bDeleteLights) { @@ -1983,6 +2002,8 @@ void LRoomManager::_bind_methods() // main functions ClassDB::bind_method(D_METHOD("rooms_convert", "verbose", "delete lights"), &LRoomManager::rooms_convert); ClassDB::bind_method(D_METHOD("rooms_single_room_convert", "verbose", "delete lights"), &LRoomManager::rooms_single_room_convert); + ClassDB::bind_method(D_METHOD("rooms_set_portal_plane_convention", "flip"), &LRoomManager::rooms_set_portal_plane_convention); + ClassDB::bind_method(D_METHOD("rooms_release"), &LRoomManager::rooms_release); ClassDB::bind_method(D_METHOD("rooms_set_camera", "camera"), &LRoomManager::rooms_set_camera); @@ -2015,6 +2036,7 @@ void LRoomManager::_bind_methods() ClassDB::bind_method(D_METHOD("rooms_set_debug_frame_string", "active"), &LRoomManager::rooms_set_debug_frame_string); ClassDB::bind_method(D_METHOD("rooms_get_debug_frame_string"), &LRoomManager::rooms_get_debug_frame_string); + ClassDB::bind_method(D_METHOD("rooms_get_room_centre", "room_id"), &LRoomManager::rooms_get_room_centre); // functions to add dynamic objects to the culling system // Note that these should not be placed directly in rooms, the system will 'soft link' to them diff --git a/lroom_manager.h b/lroom_manager.h index 3243d1f..d551c60 100644 --- a/lroom_manager.h +++ b/lroom_manager.h @@ -60,6 +60,7 @@ public: // convert empties and meshes to rooms and portals bool rooms_convert(bool bVerbose, bool bDeleteLights); bool rooms_single_room_convert(bool bVerbose, bool bDeleteLights); + void rooms_set_portal_plane_convention(bool bFlip); // free memory for current set of rooms, prepare for converting a new game level void rooms_release(); @@ -141,6 +142,9 @@ public: void rooms_set_debug_frustums(bool bActive); void rooms_set_debug_frame_string(bool bActive); + // rough .. for debugging + Vector3 rooms_get_room_centre(int room_id) const; + // 0 to 6 .. less to more // defaults to 4 which is (2) in our priorities (i.e. 6 - level) void rooms_set_logging(int level); @@ -208,6 +212,10 @@ private: // already to prevent multiple hits on rooms and objects unsigned int m_uiFrameCounter; + // the portal plane determined by the artwork geometry for room conversion can either point in or out, + // this convention is switchable + bool m_bPortalPlane_Convention; + private: // lists of rooms and portals, contiguous list so cache friendly LVector m_Rooms;