首页 > 其他分享 >Fix navmesh countour

Fix navmesh countour

时间:2023-06-15 16:36:51浏览次数:49  
标签:count reg navmesh countour region vertex contour regions Fix


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_sed

Wrong navmesh:

Fix navmesh countour_c++_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_开发语言_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));
}

标签:count,reg,navmesh,countour,region,vertex,contour,regions,Fix
From: https://blog.51cto.com/u_16162321/6493151

相关文章

  • Codeforces Round #223 (Div. 2)-C. Sereja and Prefixes
    原题链接C.SerejaandPrefixestimelimitpertestmemorylimitpertestinputoutputSerejalovesnumbersequencesverymuch.That'swhyhedecidedtomakehimselfanewonefollowingacertainalgorithm.......
  • Pytest - Fixture(12) - 配置文件pytest.ini
    Pytest-配置文件pytest.ini前言pytest.ini配置文件可以改变pytest的运行方式,它是一个固定的文件pytest.ini文件,读取配置信息,按指定的方式去运行。作用:可以改变pytest的默认行为;位置:一般放在项目的根目录(即当前项目的顶级文件夹下);命名:pytest.ini,不能使用任何中文符号,包......
  • quickfix协议当有中文时校验位错误问题解决
    quickfix校验位计算都是根据ISO-8859-1编码计算,知道这个规则后续我们处理中文就很好处理了。但是如果用ISO-8859-1编码有中文会出现乱码,如果将CharsetSupport.setCharset设置为UTF-8或者GBK时,在发送数据时会报java.nio.bufferoverflowexception:null,或者校验位失败。1、往step网......
  • 搭建邮件服务器之使用Postfix收发邮件
    发邮件0x01安装postfixaptinstallpostifx弹窗中选择第二个,其他配置项内容如下Noconfiguration:表示不要做任何配置;InternetSite:表示直接使用本地SMTP服务器发送和接收邮件;Internetwithsmarthos:表示使用本地SMTP服务器接收邮件,但发送邮件时不直接使用本地SMTP服务器,......
  • VMware ESXi 6.7 U3 Final Unlocker & OEM BIOS 集成 REALTEK 网卡驱动和 NVMe 驱动 (
    VMwareESXi6.7U3Final最终版,集成驱动版。此版本解决的问题:VMwareHostClient无法将现有虚拟磁盘(VMDK)附加到虚拟机请访问原文链接:https://sysin.org/blog/vmware-esxi-6-sysin/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.org2023-02-28,发布一个UIfix版......
  • How to fix Linux locale error All In One
    HowtofixLinuxlocaleerrorAllInOne如何修复Linux语言环境错误$cat/etc/default/localeerror❌pi@rpi3b:~/Desktop$localelocale:CannotsetLC_CTYPEtodefaultlocale:Nosuchfileordirectorylocale:CannotsetLC_ALLtodefaultlocale:???......
  • Pytest - Fixture(11) - 重命名fixture函数名称(name)
    Pytest-重命名fixture函数名称(name)fixture设置参数name=value后,可以重命名fixture函数名称,运行时传入重命名后的fixture函数名即可。使用重命名的fixture函数,可以使用装饰器:@pytest.mark.usefixtures();importpytest#编写[email protected](name="open_br......
  • Pytest - Fixture(12) - 配置文件conftest.py
    Pytest-配置文件-conftest.py前言如果在多个测试文件中的用到相同的fixture函数,则可以将其移动到conftest.py文件中conftest.py是专门存放fixture的配置文件;例如:如果测试用例都需要进行用户登录的时候,仅需将登录的功能放到conftest.py文件中,而不需要在每个用......
  • Pytest - Fixture(10) - 测试用例传参给Fixture
    Pytest-测试用例传参给Fixture大多数时候我们在fixture封装的是登陆、获取cookie等操作,但是一个系统可能不止一个用户,有多个用户;在写测试用例的时候,如何告诉fixture我们需要登录哪个用户?可以通过测试用例给fixture传递参数,指定登陆用户账户信息。传单个参数fi......
  • Pytest - Fixture(9) - Fixture传参给测试用例
    Pytest-Fixture传参给测试用例如果想要依赖fixture传递参数给测试用例,可以通过yield或者return来返回参数;yield:实现setup和teardown,并将参数传递给测试用例;return:仅实现setup,并将参数传递给测试用例而已;传单个参数return传递单个参数:test_py.pyimpo......