From ff9fb328f31dc13a87c59a839510a54cf6a9229c Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:51:35 +0200 Subject: [PATCH] Recast: store off-mesh link traverse type and lookup orders in project file Now also gets stored in the project file. Also reordered the way each field gets stored so its easier to tweak or add/remove outside the editor by external tools. --- src/naveditor/Editor_TileMesh.cpp | 4 +- src/naveditor/InputGeom.cpp | 40 +++++++++++-------- src/naveditor/include/InputGeom.h | 4 +- .../Detour/Include/DetourNavMeshBuilder.h | 8 ++-- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/naveditor/Editor_TileMesh.cpp b/src/naveditor/Editor_TileMesh.cpp index da5c076c..2f65d52b 100644 --- a/src/naveditor/Editor_TileMesh.cpp +++ b/src/naveditor/Editor_TileMesh.cpp @@ -1274,15 +1274,15 @@ unsigned char* Editor_TileMesh::buildTileMesh(const int tx, const int ty, const params.detailTris = m_dmesh->tris; params.detailTriCount = m_dmesh->ntris; params.offMeshConVerts = m_geom->getOffMeshConnectionVerts(); + params.offMeshConRefPos = m_geom->getOffMeshConnectionRefPos(); params.offMeshConRad = m_geom->getOffMeshConnectionRads(); + params.offMeshConRefYaw = m_geom->getOffMeshConnectionRefYaws(); params.offMeshConDir = m_geom->getOffMeshConnectionDirs(); params.offMeshConJumps = m_geom->getOffMeshConnectionJumps(); params.offMeshConOrders = m_geom->getOffMeshConnectionOrders(); params.offMeshConAreas = m_geom->getOffMeshConnectionAreas(); params.offMeshConFlags = m_geom->getOffMeshConnectionFlags(); params.offMeshConUserID = m_geom->getOffMeshConnectionId(); - params.offMeshConRefPos = m_geom->getOffMeshConnectionRefPos(); - params.offMeshConRefYaw = m_geom->getOffMeshConnectionRefYaws(); params.offMeshConCount = m_geom->getOffMeshConnectionCount(); params.walkableHeight = m_agentHeight; params.walkableRadius = m_agentRadius; diff --git a/src/naveditor/InputGeom.cpp b/src/naveditor/InputGeom.cpp index 439f770a..2d5e0c89 100644 --- a/src/naveditor/InputGeom.cpp +++ b/src/naveditor/InputGeom.cpp @@ -287,19 +287,22 @@ bool InputGeom::loadGeomSet(rcContext* ctx, const std::string& filepath) float* refs = &m_offMeshConRefPos[m_offMeshConCount*3]; float rad; float yaw; - int bidir, area = 0, flags = 0; - sscanf(row+1, "%f %f %f %f %f %f %f %d %d %d %f %f %f %f", + int bidir = 0, jump = 0, order = 0, area = 0, flags = 0; + sscanf(row+1, "%f %f %f %f %f %f %f %f %f %f %f %d %d %d %d %d", &verts[0], &verts[1], &verts[2], &verts[3], &verts[4], &verts[5], - &rad, - &bidir, &area, &flags, &refs[0], &refs[1], &refs[2], - &yaw); + &rad, + &yaw, + &bidir, &jump, &order, &area, &flags); + m_offMeshConRads[m_offMeshConCount] = rad; + m_offMeshConRefYaws[m_offMeshConCount] = yaw; m_offMeshConDirs[m_offMeshConCount] = (unsigned char)bidir; + m_offMeshConJumps[m_offMeshConCount] = (unsigned char)jump; + m_offMeshConOrders[m_offMeshConCount] = (unsigned char)order; m_offMeshConAreas[m_offMeshConCount] = (unsigned char)area; m_offMeshConFlags[m_offMeshConCount] = (unsigned short)flags; - m_offMeshConRefYaws[m_offMeshConCount] = yaw; m_offMeshConCount++; } } @@ -433,15 +436,17 @@ bool InputGeom::saveGeomSet(const BuildSettings* settings) const float rad = m_offMeshConRads[i]; const float yaw = m_offMeshConRefYaws[i]; const int bidir = m_offMeshConDirs[i]; + const int jump = m_offMeshConJumps[i]; + const int order = m_offMeshConOrders[i]; const int area = m_offMeshConAreas[i]; const int flags = m_offMeshConFlags[i]; - fprintf(fp, "c %f %f %f %f %f %f %f %d %d %d %f %f %f %f\n", + fprintf(fp, "c %f %f %f %f %f %f %f %f %f %f %f %d %d %d %d %d\n", verts[0], verts[1], verts[2], verts[3], verts[4], verts[5], - rad, - bidir, area, flags, refs[0], refs[1], refs[2], - yaw); + rad, + yaw, + bidir, jump, order, area, flags); } // Convex volumes @@ -552,10 +557,12 @@ void InputGeom::addOffMeshConnection(const float* spos, const float* epos, const if (m_offMeshConCount >= MAX_OFFMESH_CONNECTIONS) return; rdAssert(jump < DT_MAX_TRAVERSE_TYPES); - float* refs = &m_offMeshConRefPos[m_offMeshConCount*3]; float* verts = &m_offMeshConVerts[m_offMeshConCount*3*2]; - float yaw = dtCalcOffMeshRefYaw(spos, epos); + rdVcopy(&verts[0], spos); + rdVcopy(&verts[3], epos); + float* refs = &m_offMeshConRefPos[m_offMeshConCount*3]; + const float yaw = dtCalcOffMeshRefYaw(spos, epos); dtCalcOffMeshRefPos(spos, yaw, DT_OFFMESH_CON_REFPOS_OFFSET, refs); m_offMeshConRads[m_offMeshConCount] = rad; @@ -566,21 +573,22 @@ void InputGeom::addOffMeshConnection(const float* spos, const float* epos, const m_offMeshConAreas[m_offMeshConCount] = area; m_offMeshConFlags[m_offMeshConCount] = flags; m_offMeshConId[m_offMeshConCount] = 1000 + m_offMeshConCount; - rdVcopy(&verts[0], spos); - rdVcopy(&verts[3], epos); m_offMeshConCount++; } void InputGeom::deleteOffMeshConnection(int i) { m_offMeshConCount--; + float* vertsSrc = &m_offMeshConVerts[m_offMeshConCount*3*2]; float* vertsDst = &m_offMeshConVerts[i*3*2]; - float* refSrc = &m_offMeshConRefPos[m_offMeshConCount*3]; - float* refDst = &m_offMeshConRefPos[i*3]; rdVcopy(&vertsDst[0], &vertsSrc[0]); rdVcopy(&vertsDst[3], &vertsSrc[3]); + + float* refSrc = &m_offMeshConRefPos[m_offMeshConCount*3]; + float* refDst = &m_offMeshConRefPos[i*3]; rdVcopy(&refDst[0], &refSrc[0]); + m_offMeshConRads[i] = m_offMeshConRads[m_offMeshConCount]; m_offMeshConRefYaws[i] = m_offMeshConRefYaws[m_offMeshConCount]; m_offMeshConDirs[i] = m_offMeshConDirs[m_offMeshConCount]; diff --git a/src/naveditor/include/InputGeom.h b/src/naveditor/include/InputGeom.h index 3f12bf7a..c0182814 100644 --- a/src/naveditor/include/InputGeom.h +++ b/src/naveditor/include/InputGeom.h @@ -87,15 +87,15 @@ class InputGeom ///@{ static const int MAX_OFFMESH_CONNECTIONS = 256; float m_offMeshConVerts[MAX_OFFMESH_CONNECTIONS*3*2]; + float m_offMeshConRefPos[MAX_OFFMESH_CONNECTIONS*3]; float m_offMeshConRads[MAX_OFFMESH_CONNECTIONS]; + float m_offMeshConRefYaws[MAX_OFFMESH_CONNECTIONS]; unsigned char m_offMeshConDirs[MAX_OFFMESH_CONNECTIONS]; unsigned char m_offMeshConJumps[MAX_OFFMESH_CONNECTIONS]; unsigned char m_offMeshConOrders[MAX_OFFMESH_CONNECTIONS]; unsigned char m_offMeshConAreas[MAX_OFFMESH_CONNECTIONS]; unsigned short m_offMeshConFlags[MAX_OFFMESH_CONNECTIONS]; unsigned short m_offMeshConId[MAX_OFFMESH_CONNECTIONS]; - float m_offMeshConRefPos[MAX_OFFMESH_CONNECTIONS*3]; - float m_offMeshConRefYaws[MAX_OFFMESH_CONNECTIONS]; short m_offMeshConCount; ///@} diff --git a/src/thirdparty/recast/Detour/Include/DetourNavMeshBuilder.h b/src/thirdparty/recast/Detour/Include/DetourNavMeshBuilder.h index b8ed2be2..7db4a2f0 100644 --- a/src/thirdparty/recast/Detour/Include/DetourNavMeshBuilder.h +++ b/src/thirdparty/recast/Detour/Include/DetourNavMeshBuilder.h @@ -60,8 +60,12 @@ struct dtNavMeshCreateParams /// Off-mesh connection vertices. [(ax, ay, az, bx, by, bz) * #offMeshConCount] [Unit: wu] const float* offMeshConVerts; + /// Off-mesh connection reference positions. [(x, y, z) * #offMeshConCount] [Unit: wu] + const float* offMeshConRefPos; /// Off-mesh connection radii. [Size: #offMeshConCount] [Unit: wu] const float* offMeshConRad; + /// Off-mesh connection reference yaw. [Size: #offMeshConCount] [Unit: wu] + const float* offMeshConRefYaw; /// User defined flags assigned to the off-mesh connections. [Size: #offMeshConCount] const unsigned short* offMeshConFlags; /// User defined area ids assigned to the off-mesh connections. [Size: #offMeshConCount] @@ -77,10 +81,6 @@ struct dtNavMeshCreateParams const unsigned char* offMeshConOrders; /// The user defined ids of the off-mesh connection. [Size: #offMeshConCount] const unsigned short* offMeshConUserID; - /// Off-mesh connection reference positions. [(x, y, z) * #offMeshConCount] [Unit: wu] - const float* offMeshConRefPos; - /// Off-mesh connection reference yaw. [Size: #offMeshConCount] [Unit: wu] - const float* offMeshConRefYaw; /// The number of off-mesh connections. [Limit: >= 0] int offMeshConCount;