How are dtLinks created in NavMesh

How are dtLinks created in NavMesh

(Jin Qing’s Column, Nov., 2022)

dtLink

dtLink defines a link between 2 polygons.
It is an internal data structure.

A dtLink is owned by its source polygon.

How link is used

The links are used in findPath(), to search
all the neighbor polygons, from the current best polygon.

fields of dtLink

dtLink has 2 required fields:

  • neighbor: the neighbor polygon reference that is linked to.
  • edge: index of the polygon edge that owns this link.
    It is used in getPortalPoints() and raycast().

If the link is a boundary link, which links to other tile, then it has more fields:

  • side: defines on which side the link is. 8 sides.
    It is used in findPath() and raycast().
  • bmin: defines the minimum sub-edge area.
  • bmax: defines the maximum sub-edge area.
    bmin and bmax are used in portal finding.

How are links created

Links are not saved to navmesh file. They are created on navmesh loading in addTile().

dtNavMesh::addTile() add a tile to the navmesh. A tile is a square block of the map.

The main job of dtNavMesh::addTile() is to create links inside this tile and between this tile and other tiles.
Actually a block indexed by (x, y) of constant size has many layers for multi-floor map.
A dtMeshTile is actually a layer with an index of (x, y, layer).

5 steps to create all links:

1. Connect internal links

connectIntLinks() iterates all the polygons in the tile and create links for them
by the help of neighbors information of the polygons.

2. Base off-mesh connections

baseOffMeshLinks() bases off-mesh connections to their starting polygons and connect connections inside the tile.

Off-mesh connection is between 2 points which are inside a tile or between 2 adjacent tiles.

For each off-mesh connection, there creates a specific polygon consisting of 2 vertices.
See DT_POLYTYPE_OFFMESH_CONNECTION.

baseOffMeshLinks() creates 2 links for each off-mesh connection:

  • From the off-mesh connection polygon to the source polygon
  • From the source polygon to the off-mesh connection polygon

The destinaton polygon of the off-mesh connection is skipped here.

3. Connect external off-mesn links within this tile

connectExtOffMeshLinks() with the source and target tile be this tile.

connectExtOffMeshLinks() searches off-mesh connections that are from this tile to the target tile
by checking the side direction of the connection.

It creates a link from off-mesh connection polygon to the target tile.
For bidirectional connection, it also creates a link from the target polygon to the off-mesh connection polygon.

So for each off-mesh connection of this tile, 3 or 4 links are created by baseOffMeshLinks() and connectExtOffMeshLinks(),
one on the source polygon, one on the destination polygon and 1/2 on the off-mesh connection polygon.

4. Connect with layers in current tile

For each layer other than this layer in this tile:

  • Create links from this layer to other layer
  • Create links from other layer to this layer
  • Create links of the off-mesh connection from this layer to other layer
  • Create links of the off-mesh connection from other layer to this layer

5. Connect with neighbour tiles

Check 9 neighbor tiles’ layers, and create links just like previous step:

  • Create links from this layer to neighnor layer
  • Create links from neighnor layer to this layer
  • Create links of the off-mesh connection from this layer to neighnor layer
  • Create links of the off-mesh connection from neighnor layer to this layer

By now, for every off-mesh connection of all the loaded tiles, 3/4 links are created.

Reference

  • https://blog.csdn.net/icebergliu1234/article/details/80322392
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值