4524 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
1bb531c36b Recast: add option to reset shape volume attributes
When you edit a shape volume, you might want to fully reset it and start over again.
2024-10-22 12:03:26 +02:00
Kawe Mazidjatari
fda4e694d6 Recast: build navmesh directly into the game's load path
The engine loads it from here during development, store the file directly there so we can hot reload it into the game.
2024-10-22 12:02:22 +02:00
Kawe Mazidjatari
fc4fabd116 Recast: fix a crash in the tile builder tool
Check if tile isn't null before derefing it for the header.
2024-10-22 12:01:09 +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
aaddd53cfc Recast: increase cell height to 6.0
This was required as a cell height of 2.0 is too low for the map "mp_rr_canyonlands_64k_x_64k". This particular level is very large, and has another level far underneath; its the old firing range. In order to ensure full coverage on Z, the cell height must be increased. After the change in commit b3946e924aeea05f65f9fcba5e9043771d14af23, the new cell height actually produces more accurate and consistent results accross all levels.
2024-10-20 01:34:32 +02:00
Kawe Mazidjatari
8e3097c321 Recast: move cross marker to the center of the highlighted tile or poly
Make it easier to see where a small polygon or tile is as the cross is noticable.
2024-10-20 01:29:55 +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
b3946e924a Recast: use step height for the climb height parameter
The Hull_s::height field is actually Hull_s::stepHeight. This results in much better navigation and prevents entities "popping" into air as they shouldn't be able to walk over some obstacles.
2024-10-19 12:45:12 +02:00
Kawe Mazidjatari
b28b167467 Recast: fix regression in geometry raycaster
After the implementation of brush intersection detection in commit 6fa5080fe51e2ea118f2cf4f922bcb6e815b3a9f, we return out as soon as we have a hit, even when tmin is provided. But if tmin is provided, the caller is interested in finding the closest intersection so we must go over the input mesh as well. This fixes a bug of raycasts going through geometry when there's a brush behind it.
2024-10-19 12:02:53 +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
d9db7d3d15 Recast: fix crash in prune tool
Always check if we allocated a flag buffer before showing the options.
2024-10-18 13:51:28 +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
af19a2e5b3 Recast: fix off-mesh connection user id's when loaded from project files
User id's were never assigned when the off-mesh links were loaded from project files.
2024-10-17 13:41:04 +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
d027621028 Recast: set new default rasterization and polygonization values
Defaults have been fine tuned and now generated much better results, especially in narrow area's such as small buildings and corridors. Previously, there usually were gaps in between door frames and tunnels.
2024-10-16 19:51:05 +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
b5527cff5b Recast: increase cell height
32 seems to generate the nicest tessellation, way better and more consistent than the previous value.
2024-10-15 15:33:46 +02:00
Kawe Mazidjatari
136fc4ecf5 Recast: properly free data on shutdown
Editor::m_navMesh is always deleted in the base class, removed extraneous deletion from the tilemesh editor.
2024-10-13 21:39:12 +02:00
Kawe Mazidjatari
1491f6eaac Recast: default to watershed
Larger levels require watershed as some complex geometry (buildings with multiple floors) will exceed the maximum number of allowed sweep scans when building regions.
2024-10-13 21:38:04 +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
dedcf4f94f Recast: add >4GB file support for OBJ mesh loader
Needed for very large levels.
2024-10-12 01:49:49 +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
d9432129b2 Recast: allow loading OBJ and PLY geometry from project files
Deduplicated mesh load function and implemented a simple type handler instead. Code can now load OBJ and PLY geometry from the user interface and project files.
2024-10-11 01:17:52 +02:00
Kawe Mazidjatari
b4b0e22d61 Recast: fix crash in prune tool when initiating NavMesh flood algorithm
dtNavMeshQuery::findNearestPoly can return an error flag, and the function cal also succeed while returning a NULL polyref. Both need to be checked before the algorithm is called. Also moved the memory allocation for flags inside this new check to avoid allocating for nothing.
2024-10-11 01:15:45 +02:00
Kawe Mazidjatari
dabedb2c8b ImGui: remove extraneous print 2024-10-08 23:24:13 +02:00
Kawe Mazidjatari
0db61d2244 Resource: remove old imgui layout config file during update 2024-10-08 23:09:28 +02:00