2023-03-14 08:02:43 +03:00
|
|
|
/*
|
|
|
|
recast4j Copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using DotRecast.Recast;
|
|
|
|
using DotRecast.Recast.Geom;
|
|
|
|
|
|
|
|
namespace DotRecast.Detour.Test;
|
|
|
|
|
2023-03-16 19:48:49 +03:00
|
|
|
public class TestDetourBuilder : DetourBuilder
|
|
|
|
{
|
2023-05-05 02:44:48 +03:00
|
|
|
public MeshData Build(InputGeomProvider geom, RecastBuilderConfig rcConfig, float agentHeight, float agentRadius,
|
2023-03-16 19:48:49 +03:00
|
|
|
float agentMaxClimb, int x, int y, bool applyRecastDemoFlags)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
RecastBuilder rcBuilder = new RecastBuilder();
|
2023-05-05 02:44:48 +03:00
|
|
|
RecastBuilderResult rcResult = rcBuilder.Build(geom, rcConfig);
|
|
|
|
PolyMesh pmesh = rcResult.GetMesh();
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-03-16 19:48:49 +03:00
|
|
|
if (applyRecastDemoFlags)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
// Update poly flags from areas.
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int i = 0; i < pmesh.npolys; ++i)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
if (pmesh.areas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_GROUND
|
2023-03-16 19:48:49 +03:00
|
|
|
|| pmesh.areas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_GRASS
|
|
|
|
|| pmesh.areas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
pmesh.flags[i] = SampleAreaModifications.SAMPLE_POLYFLAGS_WALK;
|
2023-03-16 19:48:49 +03:00
|
|
|
}
|
|
|
|
else if (pmesh.areas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
pmesh.flags[i] = SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM;
|
2023-03-16 19:48:49 +03:00
|
|
|
}
|
|
|
|
else if (pmesh.areas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_DOOR)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
pmesh.flags[i] = SampleAreaModifications.SAMPLE_POLYFLAGS_WALK
|
2023-03-16 19:48:49 +03:00
|
|
|
| SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR;
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
|
|
|
if (pmesh.areas[i] > 0)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
pmesh.areas[i]--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
PolyMeshDetail dmesh = rcResult.GetMeshDetail();
|
|
|
|
NavMeshDataCreateParams option = GetNavMeshCreateParams(rcConfig.cfg, pmesh, dmesh, agentHeight, agentRadius,
|
2023-03-16 19:48:49 +03:00
|
|
|
agentMaxClimb);
|
2023-05-05 02:44:48 +03:00
|
|
|
return Build(option, x, y);
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
public NavMeshDataCreateParams GetNavMeshCreateParams(RecastConfig rcConfig, PolyMesh pmesh, PolyMeshDetail dmesh,
|
2023-03-16 19:48:49 +03:00
|
|
|
float agentHeight, float agentRadius, float agentMaxClimb)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
NavMeshDataCreateParams option = new NavMeshDataCreateParams();
|
|
|
|
option.verts = pmesh.verts;
|
|
|
|
option.vertCount = pmesh.nverts;
|
|
|
|
option.polys = pmesh.polys;
|
|
|
|
option.polyAreas = pmesh.areas;
|
|
|
|
option.polyFlags = pmesh.flags;
|
|
|
|
option.polyCount = pmesh.npolys;
|
|
|
|
option.nvp = pmesh.nvp;
|
2023-03-16 19:48:49 +03:00
|
|
|
if (dmesh != null)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
option.detailMeshes = dmesh.meshes;
|
|
|
|
option.detailVerts = dmesh.verts;
|
|
|
|
option.detailVertsCount = dmesh.nverts;
|
|
|
|
option.detailTris = dmesh.tris;
|
|
|
|
option.detailTriCount = dmesh.ntris;
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-03-14 08:02:43 +03:00
|
|
|
option.walkableHeight = agentHeight;
|
|
|
|
option.walkableRadius = agentRadius;
|
|
|
|
option.walkableClimb = agentMaxClimb;
|
|
|
|
option.bmin = pmesh.bmin;
|
|
|
|
option.bmax = pmesh.bmax;
|
|
|
|
option.cs = rcConfig.cs;
|
|
|
|
option.ch = rcConfig.ch;
|
|
|
|
option.buildBvTree = true;
|
|
|
|
/*
|
2023-05-05 02:44:48 +03:00
|
|
|
* option.offMeshConVerts = m_geom->GetOffMeshConnectionVerts(); option.offMeshConRad =
|
|
|
|
* m_geom->GetOffMeshConnectionRads(); option.offMeshConDir = m_geom->GetOffMeshConnectionDirs();
|
|
|
|
* option.offMeshConAreas = m_geom->GetOffMeshConnectionAreas(); option.offMeshConFlags =
|
|
|
|
* m_geom->GetOffMeshConnectionFlags(); option.offMeshConUserID = m_geom->GetOffMeshConnectionId();
|
|
|
|
* option.offMeshConCount = m_geom->GetOffMeshConnectionCount();
|
2023-03-14 08:02:43 +03:00
|
|
|
*/
|
|
|
|
return option;
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
}
|