392 Commits

Author SHA1 Message Date
Kawe Mazidjatari
ed9cd80034 Recast: fix generation of concave polygons
These changes seem to yield better results for the larger maps. The improvements are minimal however. This change is probably more noticable on tile cache.
2024-10-25 01:12:51 +02:00
Kawe Mazidjatari
6451405fba Recast: ensure polygon is always within bounding volume
In recastnavigation/recastnavigation@15ebb8bd25 the change was made to use detail polygons, but it appears that after this change, the bounding volume gets build under the polygons, especially if the polygons's Z are equal on all vertices. Flooring the mins and ceiling the maxs appears to yield correct behavior in all scenarios by making sure the bounding volume always encases its respective polygon.
2024-10-25 00:51:54 +02:00
Kawe Mazidjatari
563427ae63 Recast: add option to disable rendering of shape volumes 2024-10-25 00:40:40 +02:00
Kawe Mazidjatari
349f7bd3b9 Recast: move and rename render flags
Improve code readability.
2024-10-25 00:39:35 +02:00
Kawe Mazidjatari
d1c5228d23 Recast: add getter for area edge color
Also get the color for the edge per area type, previously we would still render a blue edge on a green trigger area.
2024-10-24 15:06:12 +02:00
Kawe Mazidjatari
136bc8623b Recast: fix compile error for MSET 5 Recast builds
Titanfall 2 versions (MSET 5) do not support hints.
2024-10-22 14:28:03 +02:00
Kawe Mazidjatari
d7f2b7d319 Recast: implement off-mesh connection editor
Allows the user to modify core attributes of any off-mesh connection in the world.
2024-10-22 12:05:44 +02:00
Kawe Mazidjatari
8eb294b731 Recast: only run polygroup union logic if it won't be collapsed
No point in running this code if we are going to collapse it. This also fixes a possible deadlock when removing and rebuilding individual tiles.
2024-10-22 11:59:43 +02:00
Kawe Mazidjatari
1ad2f18573 Recast: improve comment for dtNavMesh::isGoalPolyReachable 2024-10-22 11:58:18 +02:00
Kawe Mazidjatari
ac6da44a18 Recast: properly implement navmesh destructor
Reverse engineered the last types that were mostly unused and unneeded by the navmesh. But to properly implement the destructor it had to go in. Cells and hints now get freed as well and we can now rely on our own destructor for the navmesh data allocated by the game.
2024-10-22 11:56:26 +02:00
Kawe Mazidjatari
62ccee8bb2 Recast: remove links from semi connected off-mesh connections
If an off-mesh connection has a base link, but no land link, there will be an invalid link as we never process there. These links must be removed. Due to this change, the link flagging had to be moved to a separate loop as we would otherwise store the dead link in the file (it won't cause a crash as it has been unlinked, but there is no reason it should be stored). Also improved the detection of external off-mesh connections landing on our current tile, instead of doing a position lookup just decode the polyref and check if the index equals our current tile.
2024-10-20 01:28:36 +02:00
Kawe Mazidjatari
9ebecbee20 Recast: properly remap off-mesh connection polyrefs
External references were never updated. Especially when the tile we process doesn't own an off-mesh connection, but does have one landing on it. After this patch, the navmesh passes all tests in game and all polygons appear to be remapped correctly when using all features of the Detour NavMesh (single step verification). Also no issues reported from address sanitizer after several tests on extremely large and complicated navmeshes.
2024-10-19 11:55:56 +02:00
Kawe Mazidjatari
e62051eff3 Recast: fix several bugs related to off-mesh connections
- Off-mesh connections should always be linked to target poly's first. Also set the linked flag on titanfall navmeshes as this is necessary during the pruning stage.
- When connecting off-mesh links, we need to iterate over tiles using m_maxTiles, not m_tileCount as m_tileCount counts the number of added tiles, while m_maxTiles contains the maximum tiles in the lookup array, there can be empties in between.
- Radians to degrees and visa versa has been moved to a simple inline function, but during this, a regression was made where it was accidentally inverted in dtCalcOffMeshRefYaw and dtCalcOffMeshRefPos.
2024-10-19 11:51:24 +02:00
Kawe Mazidjatari
49907272fb Recast: fix off-mesh connection remap during prune
Off-mesh connections were not properly mapped to their polygon instance, causing
a heap buffer overflow.
2024-10-18 15:48:57 +02:00
Kawe Mazidjatari
fc43cbabd9 Recast: fix a crash during NavMesh load without traverse tables
The sizes still need to be set as the engine at least needs to allocate the traverse table buffer.
2024-10-18 13:29:32 +02:00
Kawe Mazidjatari
5ddc96dc34 Recast: allocate extra links for detail edge boundaries
We need more links as detail edges are used for traverse linking. Unused links will be removed during the prune stage.
2024-10-18 13:00:36 +02:00
Kawe Mazidjatari
4501581c6a Recast: fix several bugs in traverse link algorithm
- rdCalcSubEdgeArea2D could return false when tmin > tmax, which prevents the link from being established, but tmin can be larger than tmax when the detail edge equals the main edge. The issue we wanted to prevent where the triangle had an inverted winding order has been fixed in commit 1e48d8abd9e604a384e65cf633b62f4e11737d35.
- In dtNavMesh::connectTraverseLinks, the extraneous dot product check has been removed; this is now handled by the user installed dtTraverseLinkConnectParams::getTraverseType and dtTraverseLinkConnectParams::getTraverseType.
- In dtNavMesh::connectTraverseLinks, when we ran out of links in the land tile, we would still continue the traversal of all its detail edges and polygons. We now break out of all loops to move on to the next tile as we can not establish any traverse link when there are no free ones available.
2024-10-18 12:13:16 +02:00
Kawe Mazidjatari
2ed41d67ae Recast: render unconnected portal edges
Mark them bright red or blue (depending on the polygon group id).
2024-10-18 12:01:57 +02:00
Kawe Mazidjatari
6d41854ed2 Recast: mark unconnected portal edges as boundary edges
We can utilize this edge to create traverse links, which only happen on boundary edges.
2024-10-17 20:37:42 +02:00
Kawe Mazidjatari
1e48d8abd9 Recast: revert to post polygon transformation
In commit a2d5d52dc4e571388b9b86f21e40a5110a69665e, the logic has been adjusted to build the polygon in the right order in the algorithm itself, but some indices are incorrect causing bad tesselation. The issue is somewhere in RecastMesh.cpp, writing polygon indices in the incorrect order '0, 3, 2, 1' instead of '3, 2, 1, 0'.  Reverted to using "REVERSE_DIRECTION 0" for RecastMesh.cpp.
Additional notes, tesselation appears correct when building the mesh with the layered partitioner, monotone and watershed causes bad tesselation. The vertex order is however still incorrect.
2024-10-17 13:09:43 +02:00
Kawe Mazidjatari
a8b302f165 Recast: rewrite polygon island grouping algorithm
Flood-fill assign instead to make sure all polygon islands are mapped to a contiguous range of group id's on the first pass. This is required as we will otherwise reach the DT_MAX_POLY_GROUP_COUNT limit on complex and large geometry before the prune pass while we don't have DT_MAX_POLY_GROUP_COUNT polygon islands inside the navmesh. Also implemented poly group overflow protection and simplified the API.
2024-10-16 19:55:37 +02:00
Kawe Mazidjatari
d5116913d6 Recast: fix heap buffer overflow during link remap [ASAN]
Polyrefs may become invalid as we remove dead polygons and reindex the remainders. If the polyref is invalid, skip the link as it will be thrown out anyways. Issue was found using address sanitizer on level mp_rr_desertlands_64k_x_64k.
2024-10-16 19:43:17 +02:00
Kawe Mazidjatari
9b44b098f8 Recast: use DT_MIN_POLY_GROUP_COUNT for dtCalcTraverseTableSize
Use the actual constant instead.
2024-10-16 17:06:18 +02:00
Kawe Mazidjatari
5460427cda Recast: fix typo in comment (XZY -> XYZ)
This is the Z axis as we changed the coordinate system.
2024-10-16 16:50:24 +02:00
Kawe Mazidjatari
4a34481e43 Recast: implement tile update algorithm to prune all unlinked polygons
The algorithm goes over each polygon in the tile and only keeps polygons and associated data if they don't originate from an unlinked polygon island (DT_UNLINKED_POLY_GROUP). The algorithm also drops all data associated to the polygons such as the detail meshes, cells, links, verts and detail (if not used by other polygons), off-mesh links that are dead (not having the DT_POLYFLAGS_JUMP_LINKED flag), and rebuilds the BVTree.

This algorithm reduced the file size of a navmesh generated for the map mp_rr_desertlands_64k_x_64k by over 50% (209mb to 97mb) while keeping it functionally identical.

Some additional updates that were required to make this work:
* dtCalcTraverseTableSize now return NULL if there are 2 or less polygroups.
* unionTraverseLinkedPolyGroups will not run if parameters instruct it to collapse groups, it will also not run if the disjoint set doesn't contain any poly groups.
* dtCreateTraverseTableData will not allocate traverse tables if there are 2 or less polygroups, as dtCalcTraverseTableSize will now always return 0 in this case. This is an enforcement of an optimization from the engine itself as there is no point in allocating and doing lookups on a table with only 2 groups (unlinked and linked), and linked will always be reachable and unlinked can't be reached in the first place.
2024-10-15 17:25:14 +02:00
Kawe Mazidjatari
324e933c04 Recast: properly implement detail mesh edge renderer
Previous implementation was incorrect as it was trying to render triangles as lines.
2024-10-15 16:43:36 +02:00
Kawe Mazidjatari
f6e27b8b86 Recast: draw crosses in dark color if a reverse link is broken 2024-10-15 16:12:03 +02:00
Kawe Mazidjatari
272818ade0 Recast: remove cell height offset from poly mesh verts
The reason why the BVTree's appeared under the polygon was because we were rendering and calculating them incorrectly. After fixing this, they now appeared above the polygons. This offset is not necessary as it causes BVTree's to build incorrectly.
2024-10-15 15:43:49 +02:00
Kawe Mazidjatari
9f430a455e Recast: traverse over every tile in the array
dtNavMesh::getTileCount returns the total number of added tiles, the issue with this is that if the navmesh gets pruned, that means disabling unlinked polygons and removing dead tiles, then some tile instances in the m_tiles array may become empty. Less tiles will be installed and since there are null tiles in between, we won't be traversing each tile.
2024-10-13 21:36:46 +02:00
Kawe Mazidjatari
c9c687fc73 Recast: add bounds check for sweepscan indices
Only happens on extremely large and complex geometry.
2024-10-13 14:39:52 +02:00
Kawe Mazidjatari
248a652a15 Recast: add option for collapsing linked polygon groups
This is necessary for navmeshes with more than UINT16_MAX polygon islands. Building navmeshes for mp_rr_desertlands_64k_x_64k will hit this limit.
2024-10-13 14:36:09 +02:00
Kawe Mazidjatari
c0832b91d3 SDL: fix buffer overrun in SDL_strncmp
Always check len first before dereferencing the pointers.
2024-10-12 01:47:52 +02:00
Kawe Mazidjatari
dabedb2c8b ImGui: remove extraneous print 2024-10-08 23:24:13 +02:00
Kawe Mazidjatari
455b7220f9 ImGui: load and save imgui layout configuration from user cfg directory
Keep it separate from the system configurations.
2024-10-08 23:07:24 +02:00
Kawe Mazidjatari
3974ba70bb Tier0: separate launcher and imgui configs to user directory
Keep it separate from the system configurations.
2024-10-08 23:04:45 +02:00
Kawe Mazidjatari
7e1e4e902a Recast: remove extraneous comments
Should not be flipped.
2024-09-23 12:34:00 +02:00
Kawe Mazidjatari
d21565d00f Recast: use rdSwap for rdVectorBase::swap
Headers were reorganized a while back, clean this code up.
2024-09-23 12:31:31 +02:00
Kawe Mazidjatari
da37f898cf Recast: deduplicate XX_VERTS_PER_POLYGON constant
Must be synced between Recast & Detour.
2024-09-23 12:25:25 +02:00
Kawe Mazidjatari
fa1db8f995 Recast: clamp the off-mesh connection positions as well
Allows for parsing zipline positions from BSP entity partitions and placing them whilst also having it clamp the positions correctly to the polygon the zipliner will end up or start from.
2024-09-23 12:11:44 +02:00
Kawe Mazidjatari
b37a77d547 Recast: enforce consistency in intersection code
Some code uses different timing bounds. Enforce consistency between all code utilizing this.
2024-09-21 12:26:34 +02:00
Kawe Mazidjatari
eb6a3b37d2 Recast: implement intersection test for convex hulls
Similar to the intersection test for cylindric volumes. The old convex hull intersection test in the raycast algorithm is inaccurate and also doesn't calculate the hit time, which prevents the editor from placing the cursor at the intersection. Raycast algorithm is pending a refactor and its convex hull isect test will be replaced with this.
2024-09-21 12:22:02 +02:00
Kawe Mazidjatari
3a51c4f8c9 Recast: take cylinder caps into account during intersection test
Cylinder caps were not accounted for and thus tmin/tmax were never set causing incorrect ray tracing results when intersecting with a cylinder cap.
2024-09-20 21:54:24 +02:00
Kawe Mazidjatari
32f470f2ed Recast: add functions for checking if point is in cylinder and AABB 2024-09-20 16:00:23 +02:00
Kawe Mazidjatari
4640a81d09 Recast: add cylindric and AABB intersection functions
'rdIntersectSegmentCylinder' is a new function that will be used for intersection tests on cylindric clip volumes.
'rdIntersectSegmentAABB' was already present in the library, but used and reimplemented across multiple source files (pending deduplication).
2024-09-20 14:55:45 +02:00
Kawe Mazidjatari
f98b3b9bff Recast: fix order of cylinder vertex drawing (XZY -> XYZ)
Face normals were flipped after the coordinate system change. This patch solves the issue.
2024-09-20 11:43:55 +02:00
Kawe Mazidjatari
98756f1a0b Recast: reorder function
Was in between area markers, move it above.
2024-09-20 00:30:52 +02:00
Kawe Mazidjatari
11e83769b5 Recast: also assign flags to compact height field in rcMarkCylinderArea
This function is currently not in use, but will be used.
2024-09-20 00:18:23 +02:00
Kawe Mazidjatari
4083318f83 Recast: separate box creation code from renderer
Allow usage in external code.
2024-09-20 00:07:00 +02:00
Kawe Mazidjatari
4a9bfbe79a Recast: vastly improve reliability of land-side off-mesh link tile query
Instead of a box query, just take the position in the tile grid the land-side off-mesh vert is on. This vastly improves the query reliability for off-mesh links with a larger radius to the point it never fails if it is in a valid location. The box query isn't needed here as the off-mesh vert has to be on a tile, else the polygon box query will fail (unless its bounding box does happen to overlap with the point, but in this case the off-mesh connection is placed improperly causing the only factor to have its link established being luck).
2024-09-19 15:44:23 +02:00
Kawe Mazidjatari
b2d0db40ef Recast: properly flag off-mesh connection polygons
MSET 7 or higher needs proper off-mesh connection flags.
2024-09-19 00:11:49 +02:00