From 112a530d5a4091499ff4104112075704bf16a8ef Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 26 Jul 2022 14:23:02 +0200 Subject: [PATCH] Improve Recast & Detour and NavMesh generation * Add missing dtQueryFilter field (some flag used in the engine but not sure yet what it does). * Set tile->polysEnd and tile->offMeshConsEnd to end of polys and offMeshCons array pointer (if ever needed). * Set camera perspective to 75 (previous 50). * Improve theme. * Lowered the climb height for all hulls (this improves NavMesh generation around low obstacles, previously it would create a poly connecting the ground on the side with the surface of the object around where it connects with the ground, causing AI to take this route instead and kind of 'glitch' onto the surface). --- r5dev/naveditor/Sample.cpp | 16 ++++++++-------- r5dev/naveditor/include/Sample.h | 2 +- r5dev/naveditor/main.cpp | 8 ++++---- .../recast/Detour/Include/DetourNavMeshQuery.h | 1 + .../recast/Detour/Source/DetourNavMesh.cpp | 2 ++ 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/r5dev/naveditor/Sample.cpp b/r5dev/naveditor/Sample.cpp index ffa0c98e..7c5df4d2 100644 --- a/r5dev/naveditor/Sample.cpp +++ b/r5dev/naveditor/Sample.cpp @@ -178,16 +178,16 @@ void Sample::resetCommonSettings() m_partitionType = SAMPLE_PARTITION_WATERSHED; m_reachabilityTableCount = 4; } -hulldef hulls[5] = { - {"small",8,72*0.5,70,512.0f}, - {"med_short",20,72*0.5,75,512.0f}, - {"medium",48,150*0.5,77,512.0f}, - {"large",60,235*0.5,80,960.0f}, - {"extra_large",88,235*0.5,80,960.0f}, +const hulldef hulls[5] = { + { "small", 8, 72 * 0.5, 45, 512.0f }, + { "med_short", 20, 72 * 0.5, 50, 512.0f }, + { "medium", 48, 150 * 0.5, 55, 512.0f }, + { "large", 60, 235 * 0.5, 60, 960.0f }, + { "extra_large", 88, 235 * 0.5, 65, 960.0f }, }; void Sample::handleCommonSettings() { - for (auto& h : hulls) + for (const hulldef& h : hulls) { if (imguiButton(h.name)) { @@ -246,7 +246,7 @@ void Sample::handleCommonSettings() imguiLabel("Polygonization"); imguiSlider("Max Edge Length", &m_edgeMaxLen, 0.0f, 50.0f, 1.0f); imguiSlider("Max Edge Error", &m_edgeMaxError, 0.1f, 3.0f, 0.1f); - imguiSlider("Verts Per Poly", &m_vertsPerPoly, 3.0f, 12.0f, 1.0f,false); + imguiSlider("Verts Per Poly", &m_vertsPerPoly, 3.0f, 12.0f, 1.0f); imguiSeparator(); imguiLabel("Detail Mesh"); diff --git a/r5dev/naveditor/include/Sample.h b/r5dev/naveditor/include/Sample.h index 7d29482a..68fb7f18 100644 --- a/r5dev/naveditor/include/Sample.h +++ b/r5dev/naveditor/include/Sample.h @@ -32,7 +32,7 @@ struct hulldef float tile_size; //TODO: voxel size, tile size }; -extern hulldef hulls[5]; +extern const hulldef hulls[5]; /// Tool types. enum SampleToolType diff --git a/r5dev/naveditor/main.cpp b/r5dev/naveditor/main.cpp index 4ad4cf2b..d5053c65 100644 --- a/r5dev/naveditor/main.cpp +++ b/r5dev/naveditor/main.cpp @@ -443,7 +443,7 @@ int not_main(int argc, char** argv) } } // Fog. - float fogColor[4] = { 0.32f, 0.31f, 0.30f, 1.0f }; + float fogColor[4] = { 0.30f, 0.31f, 0.32f, 1.0f }; glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_LINEAR); glFogf(GL_FOG_START, camr * 0.1f); @@ -708,7 +708,7 @@ int not_main(int argc, char** argv) glGetIntegerv(GL_VIEWPORT, viewport); // Clear the screen - glClearColor(0.3f, 0.3f, 0.32f, 1.0f); + glClearColor(0.20f, 0.21f, 0.22f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -718,7 +718,7 @@ int not_main(int argc, char** argv) // Compute the projection matrix. glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(50.0f, (float)width/(float)height, 1.0f, camr); + gluPerspective(75.0f, (float)width/(float)height, 1.0f, camr); GLdouble projectionMatrix[16]; glGetDoublev(GL_PROJECTION_MATRIX, projectionMatrix); @@ -727,7 +727,7 @@ int not_main(int argc, char** argv) glLoadIdentity(); glRotatef(cameraEulers[0], 1, 0, 0); glRotatef(cameraEulers[1], 0, 1, 0); - float mXZY_to_XYZ[16] = + const float mXZY_to_XYZ[16] = { 1,0,0,0, 0,0,-1,0, //tbh not sure why this is needed, the tri flips again? something is very stupid... diff --git a/r5dev/thirdparty/recast/Detour/Include/DetourNavMeshQuery.h b/r5dev/thirdparty/recast/Detour/Include/DetourNavMeshQuery.h index 75fe03fc..9aec6dde 100644 --- a/r5dev/thirdparty/recast/Detour/Include/DetourNavMeshQuery.h +++ b/r5dev/thirdparty/recast/Detour/Include/DetourNavMeshQuery.h @@ -37,6 +37,7 @@ class dtQueryFilter float m_areaCost[DT_MAX_AREAS]; ///< Cost per area type. (Used by default implementation.) unsigned short m_includeFlags; ///< Flags for polygons that can be visited. (Used by default implementation.) unsigned short m_excludeFlags; ///< Flags for polygons that should not be visted. (Used by default implementation.) + unsigned short m_unknownFlags; ///< Unknown. public: dtQueryFilter(); diff --git a/r5dev/thirdparty/recast/Detour/Source/DetourNavMesh.cpp b/r5dev/thirdparty/recast/Detour/Source/DetourNavMesh.cpp index cb2d0abe..b6a0ff95 100644 --- a/r5dev/thirdparty/recast/Detour/Source/DetourNavMesh.cpp +++ b/r5dev/thirdparty/recast/Detour/Source/DetourNavMesh.cpp @@ -1017,6 +1017,8 @@ dtStatus dtNavMesh::addTile(unsigned char* data, int dataSize, int flags, // Init tile. tile->header = header; + tile->polysEnd = &tile->polys[polysSize]; + tile->offMeshConsEnd = &tile->offMeshCons[offMeshLinksSize]; tile->data = data; tile->dataSize = dataSize; tile->flags = flags;