changed RecastTestMeshBuilder to TestMeshDataFactory

This commit is contained in:
ikpil 2024-05-28 00:06:21 +09:00
parent e9c8b3eddf
commit 2acbdf8c53
2 changed files with 51 additions and 58 deletions

View File

@ -62,7 +62,7 @@ public class AbstractCrowdTest
[SetUp] [SetUp]
public void SetUp() public void SetUp()
{ {
nmd = new RecastTestMeshBuilder().GetMeshData(); nmd = TestMeshDataFactory.Create();
navmesh = new DtNavMesh(); navmesh = new DtNavMesh();
navmesh.Init(nmd, 6, 0); navmesh.Init(nmd, 6, 0);
query = new DtNavMeshQuery(navmesh); query = new DtNavMeshQuery(navmesh);

View File

@ -23,46 +23,42 @@ using DotRecast.Recast.Geom;
namespace DotRecast.Detour.Crowd.Test; namespace DotRecast.Detour.Crowd.Test;
public class RecastTestMeshBuilder public class TestMeshDataFactory
{ {
private readonly DtMeshData meshData; private const float m_cellSize = 0.3f;
public const float m_cellSize = 0.3f; private const float m_cellHeight = 0.2f;
public const float m_cellHeight = 0.2f; private const float m_agentHeight = 2.0f;
public const float m_agentHeight = 2.0f; private const float m_agentRadius = 0.6f;
public const float m_agentRadius = 0.6f; private const float m_agentMaxClimb = 0.9f;
public const float m_agentMaxClimb = 0.9f; private const float m_agentMaxSlope = 45.0f;
public const float m_agentMaxSlope = 45.0f; private const int m_regionMinSize = 8;
public const int m_regionMinSize = 8; private const int m_regionMergeSize = 20;
public const int m_regionMergeSize = 20; private const float m_edgeMaxLen = 12.0f;
public const float m_edgeMaxLen = 12.0f; private const float m_edgeMaxError = 1.3f;
public const float m_edgeMaxError = 1.3f; private const int m_vertsPerPoly = 6;
public const int m_vertsPerPoly = 6; private const float m_detailSampleDist = 6.0f;
public const float m_detailSampleDist = 6.0f; private const float m_detailSampleMaxError = 1.0f;
public const float m_detailSampleMaxError = 1.0f;
public RecastTestMeshBuilder() public static DtMeshData Create()
: this(SimpleInputGeomProvider.LoadFile("dungeon.obj"),
RcPartition.WATERSHED,
m_cellSize, m_cellHeight,
m_agentMaxSlope, m_agentHeight, m_agentRadius, m_agentMaxClimb,
m_regionMinSize, m_regionMergeSize,
m_edgeMaxLen, m_edgeMaxError,
m_vertsPerPoly,
m_detailSampleDist, m_detailSampleMaxError)
{ {
} IInputGeomProvider geom = SimpleInputGeomProvider.LoadFile("dungeon.obj");
RcPartition partition = RcPartition.WATERSHED;
float cellSize = m_cellSize;
float cellHeight = m_cellHeight;
float agentMaxSlope = m_agentMaxSlope;
float agentHeight = m_agentHeight;
float agentRadius = m_agentRadius;
float agentMaxClimb = m_agentMaxClimb;
int regionMinSize = m_regionMinSize;
int regionMergeSize = m_regionMergeSize;
float edgeMaxLen = m_edgeMaxLen;
float edgeMaxError = m_edgeMaxError;
int vertsPerPoly = m_vertsPerPoly;
float detailSampleDist = m_detailSampleDist;
float detailSampleMaxError = m_detailSampleMaxError;
public RecastTestMeshBuilder(IInputGeomProvider geom,
RcPartition partitionType,
float cellSize, float cellHeight,
float agentMaxSlope, float agentHeight, float agentRadius, float agentMaxClimb,
int regionMinSize, int regionMergeSize,
float edgeMaxLen, float edgeMaxError,
int vertsPerPoly,
float detailSampleDist, float detailSampleMaxError)
{
RcConfig cfg = new RcConfig( RcConfig cfg = new RcConfig(
partitionType, partition,
cellSize, cellHeight, cellSize, cellHeight,
agentMaxSlope, agentHeight, agentRadius, agentMaxClimb, agentMaxSlope, agentHeight, agentRadius, agentMaxClimb,
regionMinSize, regionMergeSize, regionMinSize, regionMergeSize,
@ -74,31 +70,31 @@ public class RecastTestMeshBuilder
RcBuilderConfig bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax()); RcBuilderConfig bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax());
RcBuilder rcBuilder = new RcBuilder(); RcBuilder rcBuilder = new RcBuilder();
RcBuilderResult rcResult = rcBuilder.Build(geom, bcfg, false); RcBuilderResult rcResult = rcBuilder.Build(geom, bcfg, false);
RcPolyMesh m_pmesh = rcResult.Mesh; RcPolyMesh pmesh = rcResult.Mesh;
for (int i = 0; i < m_pmesh.npolys; ++i) for (int i = 0; i < pmesh.npolys; ++i)
{ {
m_pmesh.flags[i] = 1; pmesh.flags[i] = 1;
} }
RcPolyMeshDetail m_dmesh = rcResult.MeshDetail; RcPolyMeshDetail dmesh = rcResult.MeshDetail;
DtNavMeshCreateParams option = new DtNavMeshCreateParams(); DtNavMeshCreateParams option = new DtNavMeshCreateParams();
option.verts = m_pmesh.verts; option.verts = pmesh.verts;
option.vertCount = m_pmesh.nverts; option.vertCount = pmesh.nverts;
option.polys = m_pmesh.polys; option.polys = pmesh.polys;
option.polyAreas = m_pmesh.areas; option.polyAreas = pmesh.areas;
option.polyFlags = m_pmesh.flags; option.polyFlags = pmesh.flags;
option.polyCount = m_pmesh.npolys; option.polyCount = pmesh.npolys;
option.nvp = m_pmesh.nvp; option.nvp = pmesh.nvp;
option.detailMeshes = m_dmesh.meshes; option.detailMeshes = dmesh.meshes;
option.detailVerts = m_dmesh.verts; option.detailVerts = dmesh.verts;
option.detailVertsCount = m_dmesh.nverts; option.detailVertsCount = dmesh.nverts;
option.detailTris = m_dmesh.tris; option.detailTris = dmesh.tris;
option.detailTriCount = m_dmesh.ntris; option.detailTriCount = dmesh.ntris;
option.walkableHeight = agentHeight; option.walkableHeight = agentHeight;
option.walkableRadius = agentRadius; option.walkableRadius = agentRadius;
option.walkableClimb = agentMaxClimb; option.walkableClimb = agentMaxClimb;
option.bmin = m_pmesh.bmin; option.bmin = pmesh.bmin;
option.bmax = m_pmesh.bmax; option.bmax = pmesh.bmax;
option.cs = cellSize; option.cs = cellSize;
option.ch = cellHeight; option.ch = cellHeight;
option.buildBvTree = true; option.buildBvTree = true;
@ -121,11 +117,8 @@ public class RecastTestMeshBuilder
option.offMeshConUserID = new int[1]; option.offMeshConUserID = new int[1];
option.offMeshConUserID[0] = 0x4567; option.offMeshConUserID[0] = 0x4567;
option.offMeshConCount = 1; option.offMeshConCount = 1;
meshData = DtNavMeshBuilder.CreateNavMeshData(option); var meshData = DtNavMeshBuilder.CreateNavMeshData(option);
}
public DtMeshData GetMeshData()
{
return meshData; return meshData;
} }
} }