Fix navmesh countour
  gJZEzXHb6nFn 2023年11月12日 27 0


Fix navmesh countour

(Jin Qing’s Column, Jan., 2023)

After changing some parameters of watershed region partition algorithm,
my test mesh generated an odd region shape, which caused a wrong contour.

Wrong contour:

Fix navmesh countour_i++

Wrong navmesh:

Fix navmesh countour_开发语言_02

There are 2 regions, the big region with red contour forms a C shape,
which is closed at one point.
The error is caused by the closing point, which should be a vertex in the simplified contour
of the small blue region but not.

In simplifyContour(), the closing point is incorrectly regarded as the edge point between 2 regions,
and is skipped, but it is accurately a vertex among 3 regions and must be a contour vertex.

To fix the problem, each vertex of the raw contour should count the regions around the vertex.
If the regions count is 3 or 4, then it must be a contour vertex of the simplified contour.

Fixed contour:

Fix navmesh countour_c++_03

Code:

// Returns the regions count of the contour vertex's 4 cells.
// The contour vertex is the front-right of the current span.
// This vertex must be the simplified contour's vertex.
// The non-region(0) is count as a region.
//
// reg is 4 region IDs of 4 cells in clockwise order: 0-current, 1-dir, 2-diagonal, 3-dirp
//
// Diagonal cells are not connected, so these 4 cells have regions count 4,
//   because region a and b are separated from each other:
//   ```
//   a|b
//   -+-
//   b|a
// ```
size_t getRegionsCount(const rcRegionId reg[4])
{
	size_t diffCount = 0;
	for (size_t i = 0, j = 3; i < 4; j = i++)
	{
		if (reg[i] != reg[j])
			++diffCount;
	}
	assert(diffCount <= 4);
	assert(diffCount != 1);
	if (0 == diffCount)
		return 1;
	return diffCount;
}

void testGetRegionsCount()
{
	assert(1 == getRegionsCount4(1, 1, 1, 1));
	assert(2 == getRegionsCount4(1, 0, 0, 0));
	assert(2 == getRegionsCount4(1, 1, 0, 0));
	assert(3 == getRegionsCount4(0, 1, 2, 0));

	assert(4 == getRegionsCount4(0, 1, 2, 3));
	assert(4 == getRegionsCount4(1, 0, 1, 0));
	assert(4 == getRegionsCount4(1, 0, 2, 0));
}

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月12日 0

暂无评论

推荐阅读
  sLjOnCldvVSM   2023年11月12日   37   0   0 #include#definec++
  ff1CyeNEm5RT   2023年11月12日   27   0   0 sedv8配置项
  xWYnr39PTA9E   2023年11月19日   20   0   0 c++
  nlgnJ1WR9L5p   2023年11月12日   29   0   0 g++c++
  XtSxkqspRqdI   2023年11月13日   18   0   0 整除i++
gJZEzXHb6nFn