36#include "imgui_internal.h"
46 ImGui::SetNextWindowPosCenter(ImGuiCond_FirstUseEver);
47 ImGuiWindowFlags win_flags = ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_AlwaysAutoResize;
48 bool keep_open =
true;
49 ImGui::Begin(
_LC(
"About",
"Static collision debug"), &keep_open, win_flags);
51 ImGui::Text(
"Terrain name: %s",
App::GetGameContext()->GetTerrain()->getTerrainName().c_str());
59 ImGui::PushID(
"EVENTBOX");
61 ImGui::Text(
"Num event boxes: %d", (
int)
App::GetGameContext()->GetTerrain()->GetCollisions()->getCollisionBoxes().size());
76 if (ImGui::Button(
"Dump debug meshes (performance)."))
85 ImGui::PushID(
"COLLMESH");
87 ImGui::Text(
"Num collision meshes: %d (%d tris)",
104 if (ImGui::Button(
"Dump debug meshes (performance)."))
113 ImGui::PushID(
"CELL");
115 ImGui::Text(
"Occupancy: ");
116 for (
int i = 0; i <= 10; i+=1)
120 ImVec4 color(f * 2.0, 2.0 * (1.0 - f), 0.2, 0.7);
122 ImGui::TextColored(color,
"%d ", tris);
127 ImGui::TextDisabled(
"(?)");
128 if (ImGui::IsItemHovered())
130 ImGui::BeginTooltip();
131 ImGui::Text(
"To save memory and FPS, only cells around the characters will be visualized");
148 if (ImGui::Button(
"Dump debug meshes (performance)."))
155 m_is_hovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows);
198 debugmo->begin(
"tracks/debug/collision/triangle", RenderOperation::OT_TRIANGLE_LIST);
203 debugmo->position(ctri.
a - coll_mesh.
position);
204 debugmo->position(ctri.
b - coll_mesh.
position);
205 debugmo->position(ctri.
c - coll_mesh.
position);
209 debugmo->setBoundingBox(AxisAlignedBox::BOX_INFINITE);
213 debugsn->setPosition(coll_mesh.
position);
215 debugsn->attachObject(debugmo);
223 int scripthandler = -1;
229 debugsn->setPosition(coll_box.
center);
232 String matName =
"tracks/debug/collision/box";
233 if (coll_box.
virt && scripthandler == -1)
234 matName =
"tracks/debug/eventbox/unused";
235 else if (coll_box.
virt)
236 matName =
"tracks/debug/eventbox/used";
238 for (
int i = 0; i < 8; i++)
242 mo->begin(matName, Ogre::RenderOperation::OT_TRIANGLE_LIST);
253 mo->triangle(0, 1, 2);
254 mo->triangle(1, 3, 2);
256 mo->triangle(3, 1, 5);
257 mo->triangle(5, 7, 3);
259 mo->triangle(6, 4, 0);
260 mo->triangle(0, 2, 6);
262 mo->triangle(7, 5, 4);
263 mo->triangle(4, 6, 7);
265 mo->triangle(5, 4, 1);
266 mo->triangle(4, 0, 1);
268 mo->triangle(2, 3, 6);
269 mo->triangle(3, 7, 6);
272 mo->setBoundingBox(aa);
273 mo->setRenderingDistance(200);
274 debugsn->attachObject(mo);
278 mo->begin(matName, Ogre::RenderOperation::OT_LINE_LIST);
288 mo->index(0); mo->index(1); mo->index(1); mo->index(3); mo->index(3); mo->index(2); mo->index(2); mo->index(0);
290 mo->index(1); mo->index(5); mo->index(5); mo->index(7); mo->index(7); mo->index(3); mo->index(3); mo->index(1);
292 mo->index(0); mo->index(2); mo->index(2); mo->index(6); mo->index(6); mo->index(4); mo->index(4); mo->index(0);
294 mo->index(5); mo->index(4); mo->index(4); mo->index(6); mo->index(6); mo->index(7); mo->index(7); mo->index(5);
297 mo->setBoundingBox(aa);
298 debugsn->attachObject(mo);
299 mo->setRenderingDistance(200);
306 return Vector3(coll_box.
lo + (coll_box.
hi - coll_box.
lo) * 0.5f);
314 std::string caption = fmt::format(
"{}meshname:{}\ngroundmodel:{}",
315 label_type_str, coll_mesh.
mesh_name, ground_model_str);
318 caption += fmt::format(
"\nsource:{}", coll_mesh.
source_name);
332 std::string label = fmt::format(
"{}event: {}\ninstance: {}\nhandler: {}", type_str,
338 label +=
"\nfilter: avatar";
341 label +=
"\nfilter: truck";
344 label +=
"\nfilter: truck_wheels";
347 label +=
"\nfilter: airplane";
350 label +=
"\nfilter: boat";
362 ImVec2 screen_size = ImGui::GetIO().DisplaySize;
366 Ogre::Vector3 pos_xyz = world2screen.
Convert(world_pos);
372 ImVec2 pos((
int)pos_xyz.x + 0.5, (
int)pos_xyz.y + 0.5);
374 ImVec2 text_size = ImGui::CalcTextSize(caption.c_str());
378 ImGuiContext* g = ImGui::GetCurrentContext();
380 ImVec2 text_pos(pos.x - ((text_size.x / 2)), pos.y - ((text_size.y / 2)));
383 const float PADDING = 4.f;
384 drawlist->AddRectFilled(
385 text_pos - ImVec2(PADDING, PADDING),
386 text_pos + text_size + ImVec2(PADDING, PADDING),
388 ImGui::GetStyle().WindowRounding);
391 drawlist->AddText(g->Font, g->FontSize, text_pos, ImColor(text_color), caption.c_str());
410 if (MaterialManager::getSingleton().getByName(
"mat-coll-dbg-0", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME))
418 for (i = 0; i <= 100; i++)
421 sprintf(bname,
"mat-coll-dbg-%d", i);
422 MaterialPtr mat = (MaterialPtr)(MaterialManager::getSingleton().create(bname, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME));
423 float f = fabs(((
float)i) / 100);
424 Pass* p = mat->getTechnique(0)->getPass(0);
425 p->createTextureUnitState()->setColourOperationEx(LBX_MODULATE, LBS_MANUAL, LBS_CURRENT, ColourValue(f * 2.0, 2.0 * (1.0 - f), 0.2, 0.7));
426 p->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
427 p->setLightingEnabled(
false);
428 p->setDepthWriteEnabled(
false);
429 p->setDepthBias(3, 3);
430 p->setCullingMode(Ogre::CULL_NONE);
432 Pass* p2 = mat->getTechnique(0)->createPass();
433 p2->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
434 p2->setLightingEnabled(
false);
435 p2->setDepthWriteEnabled(
false);
436 p2->setDepthBias(3, 3);
437 p2->setCullingMode(Ogre::CULL_NONE);
438 p2->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
439 TextureUnitState* tus2 = p2->createTextureUnitState();
440 tus2->setTextureName(
"tile.png");
443 mat->setLightingEnabled(
false);
444 mat->setReceiveShadows(
false);
498 aabb.getMinimum().y = -FLT_MAX;
500 aabb.getMaximum().y = FLT_MAX;
505 catch (std::bad_alloc
const& allocex)
508 fmt::format(
"Could not create debug view, error: {}", allocex.what()));
523 Entity* ent =
static_cast<Entity*
>(snode->getAttachedObject(0));
536 Entity* ent =
static_cast<Entity*
>(snode->getAttachedObject(0));
549 ManualObject* mo =
static_cast<ManualObject*
>(snode->getAttachedObject(0));
Central state/object manager and communications hub.
Game state manager and message-queue provider.
Ogre::SceneNode * GetCameraNode()
CollisionMeshVec const & getCollisionMeshes() const
CollisionBoxVec const & getCollisionBoxes() const
static const int CELL_BLOCKSIZE
eventsource_t & getEventSource(int pos)
void createCollisionDebugVisualization(Ogre::SceneNode *root_node, Ogre::AxisAlignedBox const &area_limit, std::vector< Ogre::SceneNode * > &out_nodes)
CollisionTriVec const & getCollisionTriangles() const
@ CONSOLE_MSGTYPE_INFO
Generic message.
void putMessage(MessageArea area, MessageType type, std::string const &msg, std::string icon="")
float m_collision_mesh_draw_distance
const float WIDTH_DRAWDIST
void DrawCollisionMeshDebugText(collision_mesh_t const &coll_mesh)
void AddCollisionMeshDebugMesh(collision_mesh_t const &coll_mesh)
const ImVec4 COLOR_EVENTBOX
void SetDrawCollisionCells(bool val)
bool m_draw_collision_meshes
void SetDrawCollisionMeshes(bool val)
void SetDrawEventBoxes(bool val)
std::vector< Ogre::SceneNode * > m_collision_cells
int m_cell_generator_distance_limit
void DrawLabelAtWorldPos(std::string const &caption, Ogre::Vector3 const &world_pos, ImVec4 const &text_color)
void ClearCollisionMeshVisuals()
Ogre::SceneNode * m_collision_grid_root
std::vector< Ogre::SceneNode * > m_collision_boxes
bool m_draw_collision_boxes
float m_collision_box_draw_distance
const float DEFAULT_DRAWDIST
void AddCollisionBoxDebugMesh(collision_box_t const &coll_box)
Ogre::Vector3 GetCollBoxWorldPos(collision_box_t const &coll_box)
void ClearEventBoxVisuals()
float m_collision_cell_draw_distance
const ImVec4 COLOR_COLLMESH
bool m_labels_draw_sources
bool m_draw_collision_cells
void GenerateCellDebugMaterials()
void ClearCollisionCellVisuals()
std::vector< Ogre::SceneNode * > m_collision_meshes
void DrawCollisionBoxDebugText(collision_box_t const &coll_box)
void RequestGuiCaptureKeyboard(bool val)
Pass true during frame to prevent input passing to application.
const TerrainPtr & GetTerrain()
Ogre::SceneManager * GetSceneManager()
Collisions * GetCollisions()
< Keeps data close for faster access.
Ogre::Vector3 Convert(Ogre::Vector3 world_pos)
std::vector< collision_tri_t > CollisionTriVec
CameraManager * GetCameraManager()
GUIManager * GetGuiManager()
GameContext * GetGameContext()
bool IsDistanceWithin(Ogre::Vector3 const &a, Ogre::Vector3 const &b, float max)
ImDrawList * GetImDummyFullscreenWindow(const std::string &name="RoR_TransparentFullscreenWindow")
@ EVENT_TRUCK_WHEELS
'truck_wheels' ~ Triggered only by wheel nodes of land vehicle (ActorType::TRUCK)
@ EVENT_AIRPLANE
'airplane' ~ Triggered by any node of airplane (ActorType::AIRPLANE)
@ EVENT_AVATAR
'avatar' ~ Triggered by the character only
@ EVENT_TRUCK
'truck' ~ Triggered by any node of land vehicle (ActorType::TRUCK)
@ EVENT_BOAT
'boat' ~ Triggered by any node of boats (ActorType::BOAT)
ImVec4 semitransparent_window_bg
Ogre::Vector3 hi
absolute collision box
Ogre::Vector3 center
center of rotation
Ogre::Vector3 debug_verts[8]
box corners in absolute world position
Ogre::Vector3 lo
absolute collision box
CollisionEventFilter event_filter
Records which collision triangles belong to which mesh.
ground_model_t * ground_model
int es_script_handler
AngelScript function ID.
std::string es_box_name
Specified in ODEF file as "event".
std::string es_instance_name
Specified by user when calling "GameScript::spawnObject()".