4236 Commits

Author SHA1 Message Date
Kawe Mazidjatari
afab9c2206 Recast: fix crash in dtPathCorridor
Must alloc the jumpTypes array, currently not fully implemented yet.
2024-09-02 18:02:47 +02:00
Kawe Mazidjatari
652d8f9da0 Recast: remove invert parameter from rdCalcEdgeNormal*
Extraneous parameter.
2024-09-02 17:26:16 +02:00
Kawe Mazidjatari
603878d413 Recast: fix heap buffer overflow in createPolyMeshCells
Must iterate up to num detail tris for current detail mesh instead of total detail tris for entire tile mesh.
2024-09-02 17:17:21 +02:00
Kawe Mazidjatari
ec741313c2 Recast: fix stack corruption caused by out-of-scope variable usage
pmin and pmax pointed to these stack arrays, but these stack arrays were inside the loop while pmin and pmax, along with their usages were outside the scope of the loop causing undefined behavior when they pointed to the currently out-of-scope stack variables. Moved the arrays outside the loop so they remain valid up to the last point they are needed.
2024-09-02 15:40:29 +02:00
Kawe Mazidjatari
3e56daf398 Recast: properly handle out-of-memory situations during build
Return false if createBVTree or createPolyMeshCells fails as a result of memory allocation failure rather than crashing the application.
2024-09-02 15:36:23 +02:00
Kawe Mazidjatari
7071de1643 Recast: BVTree build bug fix and large optimization
dtMeshHeader::bvNodeCount is always set to polycount*2, but when we have null bv nodes, then these will also be used during dtNavMeshQuery::queryPolygonsInTile, which can yield incorrect results when the null nodes overlaps query box. Also added an additional optimization to only store non-null BV nodes which can save a significant amount of memory during the runtime. After this bug fix and optimization, the resulting mesh still works as intended in-game.
2024-09-02 15:20:59 +02:00
Kawe Mazidjatari
05cc26dfe5 Recast: tag semi and fully unlinked tiles with userid's
Fully unlinked can be removed entirely, semi unlinked needs a rebuild to remove unlinked polygons (still work in progress). Added ability to automatically remove fully unlinked tiles.
2024-09-02 12:25:15 +02:00
Kawe Mazidjatari
e315b8d36f Recast: move fine tuner under collapsing header
UX improvements.
2024-09-01 00:02:28 +02:00
Kawe Mazidjatari
66cf9678d2 Recast: add method for marking cells as occupied 2024-09-01 00:01:51 +02:00
Kawe Mazidjatari
3227208533 Recast: fix signed/unsigned mismatch 2024-08-31 23:40:21 +02:00
Kawe Mazidjatari
ec115d7c97 Recast: start of jump type implementation in findStraightPath 2024-08-31 23:03:44 +02:00
Kawe Mazidjatari
ab88364779 Recast: fix comment location 2024-08-31 15:59:36 +02:00
Kawe Mazidjatari
b39214e517 Recast: check for traverse filter in dtNavMeshQuery::moveAlongSurface 2024-08-31 15:58:57 +02:00
Kawe Mazidjatari
14225dccc1 Recast: optimizations for getPortalPoints
Don't loop over the linked list again to find the corresponding link while we already have a pointer to it.
2024-08-31 15:58:28 +02:00
Kawe Mazidjatari
54f1e217de Recast: start of navmesh query modifications
Start of implementing changes of Titanfall 2 and Apex into dtNavMeshQuery.
2024-08-31 15:13:24 +02:00
Kawe Mazidjatari
7fb9a2d48b Recast: fix typo in function name 2024-08-31 11:57:09 +02:00
Kawe Mazidjatari
09a052ff18 Recast: tag unlinked and unusable tiles
Don't add tiles with no links to the position lookup table.
2024-08-31 11:54:09 +02:00
Kawe Mazidjatari
537f149be3 Recast: fix compile error
This function was removed in commit 041d02cd654d94bf4b059c212cb6a63a39e5324e but it should've been kept in as it was still used for dtNavMeshQuery::findRandomPointAroundCircle. Only the quantizer should be removed.
2024-08-30 15:54:30 +02:00
Kawe Mazidjatari
77b9d056e8 Recast: properly flag polygons after creation
Titanfall 2 navmeshes flag their polygons as follows. The pattern was always that if a polygon connects to a polygon on a neighboring tile, it should be flagged as   EDITOR_POLYFLAGS_HAS_NEIGHBOUR, and if the polygon's surface area isn't higher than 120 (NAVMESH_SMALL_POLYGON_THRESHOLD) it should be flagged as EDITOR_POLYFLAGS_TOO_SMALL.
2024-08-30 15:51:28 +02:00
Kawe Mazidjatari
041d02cd65 Recast: move polygon surface area calculation to librecast
Let recast compute this instead of detour. We need this before the detour navmesh is getting build as we have to determine whether a polygon is too small before that, and flag it as such.
2024-08-30 15:43:21 +02:00
Kawe Mazidjatari
05b6e23a75 Recast: fix naming consistency of helper function
Should be upper case to match the rest.
2024-08-29 22:43:15 +02:00
Kawe Mazidjatari
400fe00cea Recast: improve generation of traverse link type 7
At least one edge must overlap another during the projection test.
2024-08-29 22:41:52 +02:00
Kawe Mazidjatari
5bf5713eba Recast: allow moving cursor through UI 2024-08-29 16:26:25 +02:00
Kawe Mazidjatari
25cd598b17 Recast: major improvement to traverse linking algorithm
Instead of using just the polygon edges, use the detail edges as well. Ray cast errors have been fully eliminated; nothing ever clips through geometry anymore. The results are also a lot more detailed now as we can connect various sub edges together. The resulting navmesh also performs better in-game, the npc's are now a lot more fluent with jumps and climbs, they rarely clip though geometry, if they do its typically an error with the input geometry used to build the navmesh.

There was also a bug in GetBestTraverseType; the exclusive check (where at least one overlap had to occur) returned true if both overlap tests failed. This has been fixed by flipping the check and now checking if at least one overlaps when an exclusive test was specified.
2024-08-29 16:18:51 +02:00
Kawe Mazidjatari
632e70aae1 Recast: reorder location of 'dtGetDetailTriEdgeFlags'
Move under dtPolyDetail structure.
2024-08-29 16:12:40 +02:00
Kawe Mazidjatari
75ff8adfac Recast: implement function for calculation sub edge area's 2024-08-29 16:11:55 +02:00
Kawe Mazidjatari
0b64e3bea1 Recast: add render option for poly detail edges 2024-08-28 23:56:44 +02:00
Kawe Mazidjatari
6dc9434460 Recast: update traverse reachability when removing all tiles
Must be updated.
2024-08-28 17:40:47 +02:00
Kawe Mazidjatari
3833b22b08 Recast: split traverse link creation from static path creation 2024-08-28 16:35:05 +02:00
Kawe Mazidjatari
05649dbcc3 Recast: use tile marker improvements
Use rdClassifyPointOutsideBounds to mark neighbor tile so it only gets marked if we mark a tile, and a polygon outside the marked tile. Also added an optimization so the same tile doesn't get rendered twice (side == 0xff).
2024-08-28 15:57:17 +02:00
Kawe Mazidjatari
a2e539c2a5 Recast: increase max off-mesh links to 1024
For larger maps, its possible to exceed the original limit of 256.
2024-08-28 15:52:13 +02:00
Kawe Mazidjatari
ff9fb328f3 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.
2024-08-28 15:51:35 +02:00
Kawe Mazidjatari
bcc86f2250 Recast: fix bug when setting off-mesh vert orders
Properly switch between flags, previously the switch was on the same flag.
2024-08-28 15:49:27 +02:00
Kawe Mazidjatari
0bfd44abba Recast: properly handle off-mesh linked polygon reachability
Handle it in the same loop as standard traverse links, off-mesh links also have a link determining its traverse type after it has been reverse engineered and fixed. The output and behavior is now correct.
2024-08-28 14:55:16 +02:00
Kawe Mazidjatari
4dfdbaee17 Recast: fix bug when removing and readding tiles on unlinked polygons
We would only clear polygons that weren't marked as unlinked, this was introduced when the prune tool was refactored to use the unlinked polygroup tag. The side effect is, when you remove a tile, and cause a polygon on a neighbor tile to not link to anything, it will be marked as unlinked which is the correct behavior, but when you readd the tile, the entire island will be marked as unlinked.

The function dtCreateDisjointPolyGroups got fixed later by not taking traverse links into account, since polygon islands linked together with traverse links are still disjoint. This was also the time the check had to be removed when clearing all labels but this didn't happen.

Removing and readding tiles now work properly after this patch.
2024-08-28 14:40:08 +02:00
Kawe Mazidjatari
b144b200ad Recast: major improvements to traverse link algorithm
From now on, internal links are connected first before external neighbor links. This now also happens in the same pass which improves performance (this yields better results and behavior after the last few and current changes).

Also added a fine tunable test dictating whether links should only connect when edges overlap, or when one of the edges overlap (can be tweaked by setting an elevation trigger, by skipping out on lower elevations if this deems necessary, but typically doesn't).

The slope angle option was originally in the table but removed. After reconsideration this has been brought back in as you cannot define min/max slopes with 3d distances and elevation differences. The distance either needs to be 2d (which will break the max 2550.f distance per link rule), or an additional slope check has to be used to define this properly.

 After a lot of fine tuning, the results appear to be almost identical to the original navmeshes shipped with Respawn games. The algorithm is also a lot faster now (went from 30 seconds to 8 seconds on the staging area with much better and more accurate results).
2024-08-28 14:06:11 +02:00
Kawe Mazidjatari
f9fb1c6c64 Recast: move surface area quantization into its own function
Avoid potential mistakes in the future by using the wrong quant factor.
2024-08-28 13:47:21 +02:00
Kawe Mazidjatari
4f72c9aee8 Recast: implement new math functions
Implement functions for deriving vector magnitude and scalar projections.
2024-08-28 13:44:27 +02:00
Kawe Mazidjatari
bf251bccd5 Recast: fix naming of constant (XZY -> XYZ)
The direction is represented over the XY plane, previously XZ on Recast's original coordinate system. There were multiple inconsistencies in Recast where the XZ plane got represented as XY and visa versa.
2024-08-28 12:25:36 +02:00
Kawe Mazidjatari
57e66f1dfc Recast: add utility to get tile side by vector direction
Necessary for next upgrade to traverse link algorithm to get the neighbor tile facing the direction of the edge's normal.
2024-08-28 12:17:29 +02:00
Kawe Mazidjatari
a3753dec9f Recast: fix crash in tile tool when navmesh is NULL 2024-08-28 12:14:40 +02:00
Kawe Mazidjatari
2ccd443a8d Recast: fix misleading member variable name
These are draw parameters.
2024-08-26 00:54:10 +02:00
Kawe Mazidjatari
d81f6a24aa Recast: fix bugs causing mesh links to leak when removing and readding tiles
Rework the way traverse links are tracked and how the traverse table gets recreated when a tile gets removed/added. We would rebuild the entire traverse network and thus leak links since we also cleared the map that tracks the connections.
2024-08-25 23:58:04 +02:00
Kawe Mazidjatari
794f619d84 Recast: adds support for drawing off-mesh connection traverse links 2024-08-25 11:24:57 +02:00
Kawe Mazidjatari
247f2c65f1 Recast: (large change) full support for off-mesh links
Off-mesh links are now fully reverse engineered and working in Titanfall 2 and Apex Legends.
2024-08-25 11:21:01 +02:00
Kawe Mazidjatari
1a8acd5c16 Recast: fix incorrect dtLink allocation count for off-mesh links
Noticed this issue when creating multiple number of off-mesh links between 2 polygon islands. Turns out a pull request was already created to address this problem at https://github.com/recastnavigation/recastnavigation/pull/622. Merged the changes directly as this yields correct behavior as far as off-mesh links have been tested.
2024-08-24 20:33:37 +02:00
Kawe Mazidjatari
5b1bdbef68 Recast: fix stack var typo and update documentation around off-mesh ref yaw angles 2024-08-24 20:05:58 +02:00
Kawe Mazidjatari
0d1b12819e Recast: calculate ref yaw as radians, and calculate ref pos from radians
Must be converted to radians as per the comment. The behavior in-game is now correct after this patch.
2024-08-24 20:00:09 +02:00
Kawe Mazidjatari
b49033154c Recast: add debug option to mark tile by ref 2024-08-23 14:30:22 +02:00
Kawe Mazidjatari
cff151687d Recast: fix typo causing bug in rdClassifyPointInsideBounds
Needs the square root for normalization.
2024-08-23 14:15:26 +02:00