From 1008a15856a48fd02dd99ca09c93b0028a0fd3e8 Mon Sep 17 00:00:00 2001 From: ikpil Date: Tue, 5 Sep 2023 00:06:19 +0900 Subject: [PATCH] MeshProcess --- .../Builder/DemoNavMeshBuilder.cs | 6 +- .../Builder/SoloNavMeshBuilder.cs | 27 ++---- .../Geom/DemoDtTileCacheMeshProcess.cs | 82 +++++++++++-------- .../Geom/RcOffMeshConnection.cs | 1 + 4 files changed, 59 insertions(+), 57 deletions(-) diff --git a/src/DotRecast.Recast.Toolset/Builder/DemoNavMeshBuilder.cs b/src/DotRecast.Recast.Toolset/Builder/DemoNavMeshBuilder.cs index 26621a4..1b78aac 100644 --- a/src/DotRecast.Recast.Toolset/Builder/DemoNavMeshBuilder.cs +++ b/src/DotRecast.Recast.Toolset/Builder/DemoNavMeshBuilder.cs @@ -43,7 +43,8 @@ namespace DotRecast.Recast.Toolset.Builder option.ch = cellHeight; option.buildBvTree = true; - option.offMeshConCount = geom.GetOffMeshConnections().Count; + var offMeshConnections = geom.GetOffMeshConnections(); + option.offMeshConCount = offMeshConnections.Count; option.offMeshConVerts = new float[option.offMeshConCount * 6]; option.offMeshConRad = new float[option.offMeshConCount]; option.offMeshConDir = new int[option.offMeshConCount]; @@ -52,7 +53,7 @@ namespace DotRecast.Recast.Toolset.Builder option.offMeshConUserID = new int[option.offMeshConCount]; for (int i = 0; i < option.offMeshConCount; i++) { - RcOffMeshConnection offMeshCon = geom.GetOffMeshConnections()[i]; + RcOffMeshConnection offMeshCon = offMeshConnections[i]; for (int j = 0; j < 6; j++) { option.offMeshConVerts[6 * i + j] = offMeshCon.verts[j]; @@ -62,6 +63,7 @@ namespace DotRecast.Recast.Toolset.Builder option.offMeshConDir[i] = offMeshCon.bidir ? 1 : 0; option.offMeshConAreas[i] = offMeshCon.area; option.offMeshConFlags[i] = offMeshCon.flags; + // option.offMeshConUserID[i] = offMeshCon.userId; } return option; diff --git a/src/DotRecast.Recast.Toolset/Builder/SoloNavMeshBuilder.cs b/src/DotRecast.Recast.Toolset/Builder/SoloNavMeshBuilder.cs index e0aca75..6ac153c 100644 --- a/src/DotRecast.Recast.Toolset/Builder/SoloNavMeshBuilder.cs +++ b/src/DotRecast.Recast.Toolset/Builder/SoloNavMeshBuilder.cs @@ -49,8 +49,7 @@ namespace DotRecast.Recast.Toolset.Builder float detailSampleDist, float detailSampleMaxError, bool filterLowHangingObstacles, bool filterLedgeSpans, bool filterWalkableLowHeightSpans) { - RecastBuilderResult rcResult = BuildRecastResult( - geom, + RcConfig cfg = new RcConfig( partitionType, cellSize, cellHeight, agentMaxSlope, agentHeight, agentRadius, agentMaxClimb, @@ -58,8 +57,10 @@ namespace DotRecast.Recast.Toolset.Builder edgeMaxLen, edgeMaxError, vertsPerPoly, detailSampleDist, detailSampleMaxError, - filterLowHangingObstacles, filterLedgeSpans, filterWalkableLowHeightSpans); + filterLowHangingObstacles, filterLedgeSpans, filterWalkableLowHeightSpans, + SampleAreaModifications.SAMPLE_AREAMOD_WALKABLE, true); + RecastBuilderResult rcResult = BuildRecastResult(geom, cfg); var meshData = BuildMeshData(geom, cellSize, cellHeight, agentHeight, agentRadius, agentMaxClimb, rcResult); if (null == meshData) { @@ -75,26 +76,8 @@ namespace DotRecast.Recast.Toolset.Builder return new DtNavMesh(meshData, vertsPerPoly, 0); } - private RecastBuilderResult BuildRecastResult(DemoInputGeomProvider 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, - bool filterLowHangingObstacles, bool filterLedgeSpans, bool filterWalkableLowHeightSpans) + private RecastBuilderResult BuildRecastResult(DemoInputGeomProvider geom, RcConfig cfg) { - RcConfig cfg = new RcConfig( - partitionType, - cellSize, cellHeight, - agentMaxSlope, agentHeight, agentRadius, agentMaxClimb, - regionMinSize, regionMergeSize, - edgeMaxLen, edgeMaxError, - vertsPerPoly, - detailSampleDist, detailSampleMaxError, - filterLowHangingObstacles, filterLedgeSpans, filterWalkableLowHeightSpans, - SampleAreaModifications.SAMPLE_AREAMOD_WALKABLE, true); RecastBuilderConfig bcfg = new RecastBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax()); RecastBuilder rcBuilder = new RecastBuilder(); return rcBuilder.Build(geom, bcfg); diff --git a/src/DotRecast.Recast.Toolset/Geom/DemoDtTileCacheMeshProcess.cs b/src/DotRecast.Recast.Toolset/Geom/DemoDtTileCacheMeshProcess.cs index 03eca7c..87818d1 100644 --- a/src/DotRecast.Recast.Toolset/Geom/DemoDtTileCacheMeshProcess.cs +++ b/src/DotRecast.Recast.Toolset/Geom/DemoDtTileCacheMeshProcess.cs @@ -1,6 +1,7 @@ using DotRecast.Detour; using DotRecast.Detour.TileCache; using DotRecast.Recast.Geom; +using DotRecast.Recast.Toolset.Builder; namespace DotRecast.Recast.Toolset.Geom { @@ -19,39 +20,54 @@ namespace DotRecast.Recast.Toolset.Geom public void Process(DtNavMeshCreateParams option) { - // // Update poly flags from areas. - // for (int i = 0; i < option.polyCount; ++i) - // { - // if (option.polyAreas[i] == DtTileCacheBuilder.DT_TILECACHE_WALKABLE_AREA) - // option.polyAreas[i] = SAMPLE_POLYAREA_GROUND; - // - // if (option.polyAreas[i] == SAMPLE_POLYAREA_GROUND || - // option.polyAreas[i] == SAMPLE_POLYAREA_GRASS || - // option.polyAreas[i] == SAMPLE_POLYAREA_ROAD) - // { - // option.polyFlags[i] = SAMPLE_POLYFLAGS_WALK; - // } - // else if (option.polyAreas[i] == SAMPLE_POLYAREA_WATER) - // { - // option.polyFlags[i] = SAMPLE_POLYFLAGS_SWIM; - // } - // else if (option.polyAreas[i] == SAMPLE_POLYAREA_DOOR) - // { - // option.polyFlags[i] = SAMPLE_POLYFLAGS_WALK | SAMPLE_POLYFLAGS_DOOR; - // } - // } - // - // // Pass in off-mesh connections. - // if (null != _geom) - // { - // option.offMeshConVerts = _geom.GetOffMeshConnectionVerts(); - // option.offMeshConRad = _geom.GetOffMeshConnectionRads(); - // option.offMeshConDir = _geom.GetOffMeshConnectionDirs(); - // option.offMeshConAreas = _geom.GetOffMeshConnectionAreas(); - // option.offMeshConFlags = _geom.GetOffMeshConnectionFlags(); - // option.offMeshConUserID = _geom.GetOffMeshConnectionId(); - // option.offMeshConCount = _geom.GetOffMeshConnectionCount(); - // } + // Update poly flags from areas. + for (int i = 0; i < option.polyCount; ++i) + { + if (option.polyAreas[i] == DtTileCacheBuilder.DT_TILECACHE_WALKABLE_AREA) + option.polyAreas[i] = SampleAreaModifications.SAMPLE_POLYAREA_TYPE_GROUND; + + if (option.polyAreas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_GROUND || + option.polyAreas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_GRASS || + option.polyAreas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD) + { + option.polyFlags[i] = SampleAreaModifications.SAMPLE_POLYFLAGS_WALK; + } + else if (option.polyAreas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER) + { + option.polyFlags[i] = SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM; + } + else if (option.polyAreas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_DOOR) + { + option.polyFlags[i] = SampleAreaModifications.SAMPLE_POLYFLAGS_WALK | SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR; + } + } + + // Pass in off-mesh connections. + if (null != _geom) + { + var offMeshConnections = _geom.GetOffMeshConnections(); + option.offMeshConVerts = new float[option.offMeshConCount * 6]; + option.offMeshConRad = new float[option.offMeshConCount]; + option.offMeshConDir = new int[option.offMeshConCount]; + option.offMeshConAreas = new int[option.offMeshConCount]; + option.offMeshConFlags = new int[option.offMeshConCount]; + option.offMeshConUserID = new int[option.offMeshConCount]; + option.offMeshConCount = offMeshConnections.Count; + for (int i = 0; i < option.offMeshConCount; i++) + { + RcOffMeshConnection offMeshCon = offMeshConnections[i]; + for (int j = 0; j < 6; j++) + { + option.offMeshConVerts[6 * i + j] = offMeshCon.verts[j]; + } + + option.offMeshConRad[i] = offMeshCon.radius; + option.offMeshConDir[i] = offMeshCon.bidir ? 1 : 0; + option.offMeshConAreas[i] = offMeshCon.area; + option.offMeshConFlags[i] = offMeshCon.flags; + // option.offMeshConUserID[i] = offMeshCon.userId; + } + } } } } \ No newline at end of file diff --git a/src/DotRecast.Recast/Geom/RcOffMeshConnection.cs b/src/DotRecast.Recast/Geom/RcOffMeshConnection.cs index fd916f8..a346512 100644 --- a/src/DotRecast.Recast/Geom/RcOffMeshConnection.cs +++ b/src/DotRecast.Recast/Geom/RcOffMeshConnection.cs @@ -31,6 +31,7 @@ namespace DotRecast.Recast.Geom public readonly int area; public readonly int flags; + public readonly int userId; public RcOffMeshConnection(RcVec3f start, RcVec3f end, float radius, bool bidir, int area, int flags) {