diff --git a/lroom.h b/lroom.h index 5986d9c..0facb3a 100644 --- a/lroom.h +++ b/lroom.h @@ -113,6 +113,8 @@ public: LRoom(); Spatial * GetGodotRoom() const; + // retained purely for debugging visualization + Geometry::MeshData m_Bound_MeshData; }; diff --git a/lroom_converter.cpp b/lroom_converter.cpp index 1cf3770..0b46d30 100644 --- a/lroom_converter.cpp +++ b/lroom_converter.cpp @@ -253,6 +253,22 @@ bool LRoomConverter::Convert_Bound(LRoom &lroom, MeshInstance * pMI) } LPRINT(2, "\t\t\tcontained " + itos(lroom.m_Bound.m_Planes.size()) + " planes."); + + // make a copy of the mesh data for debugging + // note this could be avoided in release builds? NYI + lroom.m_Bound_MeshData = md; + +// for (int f=0; fset_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); // m_mat_Debug_Planes->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); m_mat_Debug_Planes->set_albedo(Color(1, 0, 1, 1)); - p->set_material_override(m_mat_Debug_Planes); - p->hide(); + + + ImmediateGeometry * b = memnew(ImmediateGeometry); + b->set_name("debug_bounds"); + add_child(b); + m_ID_DebugBounds = b->get_instance_id(); + m_mat_Debug_Bounds = Ref(memnew(SpatialMaterial)); + //m_mat_Debug_Bounds->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + m_mat_Debug_Bounds->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + m_mat_Debug_Bounds->set_albedo(Color(0, 0, 1, 0.4)); + b->set_material_override(m_mat_Debug_Bounds); + b->hide(); } @@ -424,6 +435,22 @@ Node * LRoomManager::rooms_get_room(int room_id) return pRoom->GetGodotRoom(); } +void LRoomManager::rooms_set_debug_bounds(bool bActive) +{ + m_bDebugBounds = bActive; + + Object * pObj = ObjectDB::get_instance(m_ID_DebugBounds); + ImmediateGeometry * im = Object::cast_to(pObj); + if (!im) + return; + + if (bActive) + im->show(); + else + im->hide(); +} + + void LRoomManager::rooms_set_debug_planes(bool bActive) { m_bDebugPlanes = bActive; @@ -437,7 +464,6 @@ void LRoomManager::rooms_set_debug_planes(bool bActive) im->show(); else im->hide(); - } @@ -648,39 +674,70 @@ void LRoomManager::FrameUpdate() // hide all the DOB // draw debug - FrameUpdate_DrawDebug(cam); + FrameUpdate_DrawDebug(cam, *pRoom); // when running, emit less debugging output so as not to choke the IDE Lawn::LDebug::m_bRunning = true; } -void LRoomManager::FrameUpdate_DrawDebug(const LCamera &cam) +void LRoomManager::FrameUpdate_DrawDebug(const LCamera &cam, const LRoom &lroom) { - if (!m_bDebugPlanes) - return; - - Vector3 ptCam = cam.m_ptPos; - // slight adjustment to prevent parallel lines in viewport - ptCam += (cam.m_ptDir * 0.1f); - - Object * pObj = ObjectDB::get_instance(m_ID_DebugPlanes); - ImmediateGeometry * im = Object::cast_to(pObj); - if (!im) - return; - - im->clear(); - - im->begin(Mesh::PRIMITIVE_LINES, NULL); - - int nVerts = m_DebugPlanes.size(); - - for (int n=0; nadd_vertex(ptCam); - im->add_vertex(m_DebugPlanes[n]); + Vector3 ptCam = cam.m_ptPos; + // slight adjustment to prevent parallel lines in viewport + ptCam += (cam.m_ptDir * 0.1f); + + Object * pObj = ObjectDB::get_instance(m_ID_DebugPlanes); + ImmediateGeometry * im = Object::cast_to(pObj); + if (!im) + return; + + im->clear(); + + im->begin(Mesh::PRIMITIVE_LINES, NULL); + + int nVerts = m_DebugPlanes.size(); + + for (int n=0; nadd_vertex(ptCam); + im->add_vertex(m_DebugPlanes[n]); + } + im->end(); + } + + // if debug bounds are on and there is a bound for this room + const Geometry::MeshData &md = lroom.m_Bound_MeshData; + if (m_bDebugBounds && md.faces.size()) + { + Object * pObj = ObjectDB::get_instance(m_ID_DebugBounds); + ImmediateGeometry * im = Object::cast_to(pObj); + if (!im) + return; + + im->clear(); + + im->begin(Mesh::PRIMITIVE_TRIANGLES, NULL); + + for (int n=0; nset_normal(f.plane.normal); + im->add_vertex(md.vertices[f.indices[0]]); + im->add_vertex(md.vertices[f.indices[t+1]]); + im->add_vertex(md.vertices[f.indices[t+2]]); + } + } + + im->end(); } - im->end(); } void LRoomManager::_notification(int p_what) { @@ -718,6 +775,7 @@ void LRoomManager::_bind_methods() ClassDB::bind_method(D_METHOD("rooms_log_frame"), &LRoomManager::rooms_log_frame); ClassDB::bind_method(D_METHOD("rooms_set_active"), &LRoomManager::rooms_set_active); ClassDB::bind_method(D_METHOD("rooms_set_debug_planes"), &LRoomManager::rooms_set_debug_planes); + ClassDB::bind_method(D_METHOD("rooms_set_debug_bounds"), &LRoomManager::rooms_set_debug_bounds); // functions to add dynamic objects to the culling system diff --git a/lroom_manager.h b/lroom_manager.h index 49012db..940d6cd 100644 --- a/lroom_manager.h +++ b/lroom_manager.h @@ -81,8 +81,8 @@ public: // turn on and off culling for debugging void rooms_set_active(bool bActive); - void rooms_set_debug_planes(bool bActive); + void rooms_set_debug_bounds(bool bActive); // 0 to 6 .. defaults to 4 which is (2) in our priorities (i.e. 6 - level) void rooms_set_logging(int level); @@ -148,7 +148,7 @@ private: void FrameUpdate_FrustumOnly(); // draw planes and room hulls - void FrameUpdate_DrawDebug(const LCamera &cam); + void FrameUpdate_DrawDebug(const LCamera &cam, const LRoom &lroom); // find which room is linked by a portal LRoom &Portal_GetLinkedRoom(const LPortal &port); @@ -160,12 +160,15 @@ private: public: // whether debug planes is switched on bool m_bDebugPlanes; + bool m_bDebugBounds; // the planes are shown as a list of lines from the camera to the portal verts LVector m_DebugPlanes; private: ObjectID m_ID_DebugPlanes; + ObjectID m_ID_DebugBounds; Ref m_mat_Debug_Planes; + Ref m_mat_Debug_Bounds; }; #endif