DotRecast icon indicating copy to clipboard operation
DotRecast copied to clipboard

Problems with removed vertices at tile borders

Open awgil opened this issue 11 months ago • 1 comments

I've been investigating problems with incorrect pathing, e.g. image

After some digging, I've found that the root cause is the logic that removes vertices on tile borders while building polymeshes.

There is a parameter that controls the max edge length while tracing contours, it correctly creates 'small' areas: image

When later poly mesh is built, it builds a triangulation for each contour. However, there is a piece of code (see RcMeshs.BuildPolyMesh) that marks vertices on the tile borders for removal:

                    if ((cont.verts[v + 3] & RC_BORDER_VERTEX) != 0)
                    {
                        // This vertex should be removed.
                        vflags[indices[j]] = 1;
                    }

As a result, recast creates a huge polygons on tile borders: image

Presumably this is done for better tile stitching? However, it creates problems for pathfinding (since the pathfinding considers edge midpoints, it thinks that going 'around' this polygon is 'shorter' than crossing long edge midpoint).

Removing this vertex removal bit fixes the triangulation (and consequently pathfinding), and doesn't seem to break stitching in my limited testing so far: image

However, I don't quite understand all implications. I suspect this part is directly ported from recast?

awgil avatar Mar 06 '24 22:03 awgil

There are parts that I also haven't fully understood, so it's difficult for me to respond. Firstly, the part that I don't understand from the perspective of porting is the technical porting.

ikpil avatar Mar 13 '24 14:03 ikpil