From 2acbdf8c5399896df3dee3cce85fec8aab81caa5 Mon Sep 17 00:00:00 2001 From: ikpil Date: Tue, 28 May 2024 00:06:21 +0900 Subject: [PATCH] changed RecastTestMeshBuilder to TestMeshDataFactory --- .../AbstractCrowdTest.cs | 2 +- ...tMeshBuilder.cs => TestMeshDataFactory.cs} | 107 ++++++++---------- 2 files changed, 51 insertions(+), 58 deletions(-) rename test/DotRecast.Detour.Crowd.Test/{RecastTestMeshBuilder.cs => TestMeshDataFactory.cs} (53%) diff --git a/test/DotRecast.Detour.Crowd.Test/AbstractCrowdTest.cs b/test/DotRecast.Detour.Crowd.Test/AbstractCrowdTest.cs index 248bd1b..b2f186d 100644 --- a/test/DotRecast.Detour.Crowd.Test/AbstractCrowdTest.cs +++ b/test/DotRecast.Detour.Crowd.Test/AbstractCrowdTest.cs @@ -62,7 +62,7 @@ public class AbstractCrowdTest [SetUp] public void SetUp() { - nmd = new RecastTestMeshBuilder().GetMeshData(); + nmd = TestMeshDataFactory.Create(); navmesh = new DtNavMesh(); navmesh.Init(nmd, 6, 0); query = new DtNavMeshQuery(navmesh); diff --git a/test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs b/test/DotRecast.Detour.Crowd.Test/TestMeshDataFactory.cs similarity index 53% rename from test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs rename to test/DotRecast.Detour.Crowd.Test/TestMeshDataFactory.cs index 39a362a..d186f77 100644 --- a/test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs +++ b/test/DotRecast.Detour.Crowd.Test/TestMeshDataFactory.cs @@ -23,46 +23,42 @@ using DotRecast.Recast.Geom; namespace DotRecast.Detour.Crowd.Test; -public class RecastTestMeshBuilder +public class TestMeshDataFactory { - private readonly DtMeshData meshData; - 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; + private const float m_cellSize = 0.3f; + private const float m_cellHeight = 0.2f; + private const float m_agentHeight = 2.0f; + private const float m_agentRadius = 0.6f; + private const float m_agentMaxClimb = 0.9f; + private const float m_agentMaxSlope = 45.0f; + private const int m_regionMinSize = 8; + private const int m_regionMergeSize = 20; + private const float m_edgeMaxLen = 12.0f; + private const float m_edgeMaxError = 1.3f; + private const int m_vertsPerPoly = 6; + private const float m_detailSampleDist = 6.0f; + private const float m_detailSampleMaxError = 1.0f; - public RecastTestMeshBuilder() - : 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) + public static DtMeshData Create() { - } + 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( - partitionType, + partition, cellSize, cellHeight, agentMaxSlope, agentHeight, agentRadius, agentMaxClimb, regionMinSize, regionMergeSize, @@ -74,31 +70,31 @@ public class RecastTestMeshBuilder RcBuilderConfig bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax()); RcBuilder rcBuilder = new RcBuilder(); RcBuilderResult rcResult = rcBuilder.Build(geom, bcfg, false); - RcPolyMesh m_pmesh = rcResult.Mesh; - for (int i = 0; i < m_pmesh.npolys; ++i) + RcPolyMesh pmesh = rcResult.Mesh; + 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(); - 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.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; + option.detailMeshes = dmesh.meshes; + option.detailVerts = dmesh.verts; + option.detailVertsCount = dmesh.nverts; + option.detailTris = dmesh.tris; + option.detailTriCount = dmesh.ntris; option.walkableHeight = agentHeight; option.walkableRadius = agentRadius; option.walkableClimb = agentMaxClimb; - option.bmin = m_pmesh.bmin; - option.bmax = m_pmesh.bmax; + option.bmin = pmesh.bmin; + option.bmax = pmesh.bmax; option.cs = cellSize; option.ch = cellHeight; option.buildBvTree = true; @@ -121,11 +117,8 @@ public class RecastTestMeshBuilder option.offMeshConUserID = new int[1]; option.offMeshConUserID[0] = 0x4567; option.offMeshConCount = 1; - meshData = DtNavMeshBuilder.CreateNavMeshData(option); - } + var meshData = DtNavMeshBuilder.CreateNavMeshData(option); - public DtMeshData GetMeshData() - { return meshData; } } \ No newline at end of file