55
66#include < imgui_memory_editor.h>
77
8- #include " implot3d_internal.h"
98#include " utils/debug_draw.h"
109
1110std::mutex g_actorListMutex;
@@ -89,9 +88,6 @@ void EntityDebugger::UpdateEntityMemory() {
8988 if (actorData.first == " GameROMPlayer" ) {
9089 CemuHooks::readMemory (actorData.second + offsetof (ActorWiiU, mtx), &playerPos);
9190 glm::fvec3 newPlayerPos = playerPos.getPos ().getLE ();
92- if (glm::distance (newPlayerPos, m_playerPos) > 25 .0f ) {
93- m_resetPlot = true ;
94- }
9591 m_playerPos = newPlayerPos;
9692
9793 // // set invisibility flag
@@ -194,19 +190,39 @@ void EntityDebugger::UpdateEntityMemory() {
194190 SetAABB (actorId, aabbMin.getLE (), aabbMax.getLE ());
195191 }
196192
197- if ( float distance = glm::distance (m_playerPos, mtx.getPos ().getLE ()); distance <= 100 . 0f ) {
198- glm::fvec3 pos = mtx.getPos ().getLE ();
199- glm::fquat rot = mtx.getRotLE ();
193+ float distance = glm::distance (m_playerPos, mtx.getPos ().getLE ());
194+ glm::fvec3 pos = mtx.getPos ().getLE ();
195+ glm::fquat rot = mtx.getRotLE ();
200196
201- glm::fvec3 localMin = aabbMin.getLE ();
202- glm::fvec3 localMax = aabbMax.getLE ();
203- glm::fvec3 localCenter = (localMin + localMax) * 0 .5f ;
204- glm::fvec3 halfExtents = (localMax - localMin) * 0 .5f ;
197+ glm::fvec3 localMin = aabbMin.getLE ();
198+ glm::fvec3 localMax = aabbMax.getLE ();
199+ glm::fvec3 localCenter = (localMin + localMax) * 0 .5f ;
200+ glm::fvec3 halfExtents = (localMax - localMin) * 0 .5f ;
201+ bool matchesFilter = m_filter.empty () || actorName.find (m_filter) != std::string::npos;
205202
206- // Transform local AABB center to world space
207- glm::fvec3 worldCenter = pos + glm::mat3_cast (rot) * localCenter;
203+ if (m_showWorldLabels && matchesFilter && distance <= 100 .0f ) {
204+ float labelFontScale = 0 .325f ;
205+ if (distance <= 8 .0f ) {
206+ labelFontScale = 0 .72f ;
207+ }
208+ else if (distance <= 16 .0f ) {
209+ labelFontScale = 0 .6f ;
210+ }
211+ else if (distance <= 40 .0f ) {
212+ labelFontScale = 0 .45f ;
213+ }
208214
209- DebugDraw::instance ().Box (worldCenter, halfExtents, rot, IM_COL32 (255 , 255 , 255 , 255 /10 ), 1 .0f );
215+ DebugDraw::instance ().Text (pos, actorName, IM_COL32 (255 , 255 , 255 , 255 ), ImVec2 (6 .0f , -18 .0f ), labelFontScale);
216+ }
217+
218+ if (m_showWorldAABBs && matchesFilter && distance <= m_worldAABBMaxDistance) {
219+ if (glm::all (glm::greaterThan (halfExtents, glm::vec3 (0 .0f )))) {
220+ glm::fvec3 worldCenter = pos + glm::mat3_cast (rot) * localCenter;
221+ DebugDraw::instance ().Box (worldCenter, halfExtents, rot, IM_COL32 (255 , 255 , 255 , 255 / 10 ), 1 .0f );
222+ }
223+ else {
224+ DebugDraw::instance ().Dot (pos, 3 .0f , IM_COL32 (255 , 255 , 255 , 180 ));
225+ }
210226 }
211227
212228 // uint32_t physicsMtxPtr = 0;
@@ -275,41 +291,6 @@ void EntityDebugger::UpdateEntityMemory() {
275291 }
276292 }
277293}
278-
279-
280- void DrawAABBInPlot (glm::fvec3 pos, glm::fvec3& min, glm::fvec3& max, glm::fquat& rotation) {
281- glm::fvec3 corners[8 ] = {
282- {min.x , min.y , min.z },
283- {max.x , min.y , min.z },
284- {max.x , max.y , min.z },
285- {min.x , max.y , min.z },
286- {min.x , min.y , max.z },
287- {max.x , min.y , max.z },
288- {max.x , max.y , max.z },
289- {min.x , max.y , max.z }
290- };
291-
292- glm::mat4 transform = glm::translate (glm::mat4 (1 .0f ), pos) * glm::mat4_cast (rotation);
293-
294- ImPlot3DPoint aabbPoints[8 ];
295- for (int i = 0 ; i < 8 ; ++i) {
296- glm::vec4 worldPos = transform * glm::vec4 (corners[i], 1 .0f );
297- aabbPoints[i] = ImPlot3DPoint (worldPos.x , worldPos.z , worldPos.y );
298- }
299-
300- int edges[12 ][2 ] = {
301- {0 , 1 }, {1 , 2 }, {2 , 3 }, {3 , 0 }, // near plane
302- {4 , 5 }, {5 , 6 }, {6 , 7 }, {7 , 4 }, // far plane
303- {0 , 4 }, {1 , 5 }, {2 , 6 }, {3 , 7 } // connecting edges
304- };
305-
306- for (const auto & edge : edges) {
307- ImVec2 p0 = ImPlot3D::PlotToPixels (aabbPoints[edge[0 ]]);
308- ImVec2 p1 = ImPlot3D::PlotToPixels (aabbPoints[edge[1 ]]);
309- ImPlot3D::GetPlotDrawList ()->AddLine (p0, p1, IM_COL32 (255 , 0 , 0 , 255 ));
310- }
311- }
312-
313294void EntityDebugger::DrawEntityInspector () {
314295 ImGui::Begin (" BetterVR Debugger" );
315296
@@ -319,54 +300,14 @@ void EntityDebugger::DrawEntityInspector() {
319300
320301 ImGui::BeginChild (" ScrollArea" , ImVec2 (0 , 0 ));
321302
322- if (ImGui::CollapsingHeader (" World Space Inspector" )) {
323- ImGui::Checkbox (" Disable Points For Entities" , &m_disablePoints);
324- ImGui::Checkbox (" Disable Text For Entities" , &m_disableTexts);
325- ImGui::Checkbox (" Disable Rotations For Entities" , &m_disableRotations);
326- ImGui::Checkbox (" Disable AABBs For Entities" , &m_disableAABBs);
327-
328- if (ImPlot3D::BeginPlot (" ##plot" , ImVec2 (-1 , 0 ), ImPlot3DFlags_NoLegend | ImPlot3DFlags_NoTitle)) {
329- // add -50 and 50 to playerPos to make the plot centered around the player
330- constexpr float zoomOutAxis = 30 .0f ;
331- ImPlot3D::SetupAxesLimits (
332- -zoomOutAxis, +zoomOutAxis,
333- -zoomOutAxis, +zoomOutAxis,
334- -zoomOutAxis, +zoomOutAxis,
335- ImPlot3DCond_Once
336- );
337- ImPlot3D::SetupAxes (" X" , " Z" , " Y" );
338-
339- if (m_resetPlot) {
340- ImPlot3D::GetCurrentPlot ()->Axes [ImAxis3D_X].SetRange (m_playerPos.x -zoomOutAxis, m_playerPos.x +zoomOutAxis);
341- ImPlot3D::GetCurrentPlot ()->Axes [ImAxis3D_Y].SetRange (m_playerPos.z -zoomOutAxis, m_playerPos.z +zoomOutAxis);
342- ImPlot3D::GetCurrentPlot ()->Axes [ImAxis3D_Z].SetRange (m_playerPos.y -zoomOutAxis, m_playerPos.y +zoomOutAxis);
343- m_resetPlot = false ;
344- }
345-
346- // plot entities in 3D space
347- for (auto & entity : m_entities | std::views::values) {
348- if (!m_disableTexts) {
349- ImPlot3D::PlotText (entity.name .c_str (), entity.position .x .getLE (), entity.position .z .getLE (), entity.position .y .getLE (), 0 , ImVec2 (0 , 5 ));
350- }
351- if (!m_disablePoints) {
352- ImVec2 cntr = ImPlot3D::PlotToPixels (ImPlot3DPoint (entity.position .x .getLE (), entity.position .z .getLE (), entity.position .y .getLE ()));
353- ImPlot3D::GetPlotDrawList ()->AddCircleFilled (cntr, 2 , IM_COL32 (255 , 255 , 0 , 255 ), 8 );
354- }
355- if (!m_disableRotations) {
356- glm::fvec3 start = entity.position .getLE ();
357- glm::fvec3 end = entity.rotation * entity.position .getLE () * 0 .05f ;
358- float xList[] = { start.x , end.x };
359- float yList[] = { start.z , end.z };
360- float zList[] = { start.y , end.y };
361- ImPlot3D::PlotLine (entity.name .c_str (), xList, yList, zList, 2 );
362- }
363- if (!m_disableAABBs) {
364- DrawAABBInPlot (entity.position .getLE (), entity.aabbMin , entity.aabbMax , entity.rotation );
365- }
366- }
367-
368- ImPlot3D::EndPlot ();
303+ if (ImGui::CollapsingHeader (" World Space Overlay" , ImGuiTreeNodeFlags_DefaultOpen)) {
304+ ImGui::Checkbox (" Show Entity Names In 3D View" , &m_showWorldLabels);
305+ ImGui::Checkbox (" Show Entity Boxes In 3D View" , &m_showWorldAABBs);
306+ if (m_showWorldAABBs) {
307+ ImGui::SetNextItemWidth (160 .0f );
308+ ImGui::DragFloat (" 3D Box Distance" , &m_worldAABBMaxDistance, 1 .0f , 0 .0f , 10000 .0f , " %.0f" );
369309 }
310+ ImGui::Checkbox (" Show Raycast Lines" , &m_showRaycastLines);
370311 }
371312
372313 // display entities
@@ -774,4 +715,4 @@ void EntityDebugger::DrawFPSOverlayContent(RND_Renderer* renderer, bool renderTe
774715
775716 ImPlot::EndPlot ();
776717 }
777- }
718+ }
0 commit comments