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.Core;
|
|
|
|
using DotRecast.Recast;
|
|
|
|
using DotRecast.Recast.Geom;
|
|
|
|
|
|
|
|
namespace DotRecast.Detour.Crowd.Test;
|
|
|
|
|
2023-03-16 19:48:49 +03:00
|
|
|
public class RecastTestMeshBuilder
|
|
|
|
{
|
2023-06-08 15:38:02 +03:00
|
|
|
private readonly DtMeshData meshData;
|
2023-03-14 08:02:43 +03:00
|
|
|
public const float m_cellSize = 0.3f;
|
|
|
|
public const float m_cellHeight = 0.2f;
|
|
|
|
public const float m_agentHeight = 2.0f;
|
|
|
|
public const float m_agentRadius = 0.6f;
|
|
|
|
public const float m_agentMaxClimb = 0.9f;
|
|
|
|
public const float m_agentMaxSlope = 45.0f;
|
|
|
|
public const int m_regionMinSize = 8;
|
|
|
|
public const int m_regionMergeSize = 20;
|
|
|
|
public const float m_edgeMaxLen = 12.0f;
|
|
|
|
public const float m_edgeMaxError = 1.3f;
|
|
|
|
public const int m_vertsPerPoly = 6;
|
|
|
|
public const float m_detailSampleDist = 6.0f;
|
|
|
|
public const float m_detailSampleMaxError = 1.0f;
|
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
public RecastTestMeshBuilder() : this(ObjImporter.Load(Loader.ToBytes("dungeon.obj")),
|
2023-03-16 19:48:49 +03:00
|
|
|
PartitionType.WATERSHED, m_cellSize, m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope,
|
|
|
|
m_regionMinSize, m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist,
|
|
|
|
m_detailSampleMaxError)
|
2023-03-14 08:02:43 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-05-05 03:06:43 +03:00
|
|
|
public RecastTestMeshBuilder(IInputGeomProvider m_geom, PartitionType m_partitionType, float m_cellSize,
|
2023-03-16 19:48:49 +03:00
|
|
|
float m_cellHeight, float m_agentHeight, float m_agentRadius, float m_agentMaxClimb, float m_agentMaxSlope,
|
|
|
|
int m_regionMinSize, int m_regionMergeSize, float m_edgeMaxLen, float m_edgeMaxError, int m_vertsPerPoly,
|
|
|
|
float m_detailSampleDist, float m_detailSampleMaxError)
|
|
|
|
{
|
2023-06-08 14:53:03 +03:00
|
|
|
RcConfig cfg = new RcConfig(m_partitionType, m_cellSize, m_cellHeight, m_agentHeight, m_agentRadius,
|
2023-03-16 19:48:49 +03:00
|
|
|
m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize, m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError,
|
|
|
|
m_vertsPerPoly, m_detailSampleDist, m_detailSampleMaxError, SampleAreaModifications.SAMPLE_AREAMOD_GROUND);
|
2023-05-05 02:44:48 +03:00
|
|
|
RecastBuilderConfig bcfg = new RecastBuilderConfig(cfg, m_geom.GetMeshBoundsMin(), m_geom.GetMeshBoundsMax());
|
2023-03-14 08:02:43 +03:00
|
|
|
RecastBuilder rcBuilder = new RecastBuilder();
|
2023-05-05 02:44:48 +03:00
|
|
|
RecastBuilderResult rcResult = rcBuilder.Build(m_geom, bcfg);
|
2023-06-08 14:53:03 +03:00
|
|
|
RcPolyMesh m_pmesh = rcResult.GetMesh();
|
2023-03-16 19:48:49 +03:00
|
|
|
for (int i = 0; i < m_pmesh.npolys; ++i)
|
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
m_pmesh.flags[i] = 1;
|
|
|
|
}
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-06-08 14:53:03 +03:00
|
|
|
RcPolyMeshDetail m_dmesh = rcResult.GetMeshDetail();
|
2023-06-08 15:38:02 +03:00
|
|
|
DtNavMeshCreateParams option = new DtNavMeshCreateParams();
|
2023-03-14 08:02:43 +03:00
|
|
|
option.verts = m_pmesh.verts;
|
|
|
|
option.vertCount = m_pmesh.nverts;
|
|
|
|
option.polys = m_pmesh.polys;
|
|
|
|
option.polyAreas = m_pmesh.areas;
|
|
|
|
option.polyFlags = m_pmesh.flags;
|
|
|
|
option.polyCount = m_pmesh.npolys;
|
|
|
|
option.nvp = m_pmesh.nvp;
|
|
|
|
option.detailMeshes = m_dmesh.meshes;
|
|
|
|
option.detailVerts = m_dmesh.verts;
|
|
|
|
option.detailVertsCount = m_dmesh.nverts;
|
|
|
|
option.detailTris = m_dmesh.tris;
|
|
|
|
option.detailTriCount = m_dmesh.ntris;
|
|
|
|
option.walkableHeight = m_agentHeight;
|
|
|
|
option.walkableRadius = m_agentRadius;
|
|
|
|
option.walkableClimb = m_agentMaxClimb;
|
|
|
|
option.bmin = m_pmesh.bmin;
|
|
|
|
option.bmax = m_pmesh.bmax;
|
|
|
|
option.cs = m_cellSize;
|
|
|
|
option.ch = m_cellHeight;
|
|
|
|
option.buildBvTree = true;
|
|
|
|
|
|
|
|
option.offMeshConVerts = new float[6];
|
|
|
|
option.offMeshConVerts[0] = 0.1f;
|
|
|
|
option.offMeshConVerts[1] = 0.2f;
|
|
|
|
option.offMeshConVerts[2] = 0.3f;
|
|
|
|
option.offMeshConVerts[3] = 0.4f;
|
|
|
|
option.offMeshConVerts[4] = 0.5f;
|
|
|
|
option.offMeshConVerts[5] = 0.6f;
|
|
|
|
option.offMeshConRad = new float[1];
|
|
|
|
option.offMeshConRad[0] = 0.1f;
|
|
|
|
option.offMeshConDir = new int[1];
|
|
|
|
option.offMeshConDir[0] = 1;
|
|
|
|
option.offMeshConAreas = new int[1];
|
|
|
|
option.offMeshConAreas[0] = 2;
|
|
|
|
option.offMeshConFlags = new int[1];
|
|
|
|
option.offMeshConFlags[0] = 12;
|
|
|
|
option.offMeshConUserID = new int[1];
|
|
|
|
option.offMeshConUserID[0] = 0x4567;
|
|
|
|
option.offMeshConCount = 1;
|
2023-05-05 02:44:48 +03:00
|
|
|
meshData = NavMeshBuilder.CreateNavMeshData(option);
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
public DtMeshData GetMeshData()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-03-14 08:02:43 +03:00
|
|
|
return meshData;
|
|
|
|
}
|
2023-04-29 07:29:40 +03:00
|
|
|
}
|