diff --git a/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs index b092e53..8a5fbf1 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs @@ -9,14 +9,14 @@ namespace DotRecast.Recast.Toolset.Tools { public class RcObstacleTool : IRcToolable { - private readonly IDtTileCacheCompressorFactory _compFactory; - private readonly IDtTileCacheMeshProcess _proc; + private readonly IDtTileCacheCompressorFactory _comp; + private readonly DemoDtTileCacheMeshProcess _proc; private DtTileCache _tc; - public RcObstacleTool(IDtTileCacheCompressorFactory compFactory, IDtTileCacheMeshProcess meshProcessor = null) + public RcObstacleTool(IDtTileCacheCompressorFactory comp) { - _compFactory = compFactory; - _proc = meshProcessor ?? new DemoDtTileCacheMeshProcess(); + _comp = comp; + _proc = new DemoDtTileCacheMeshProcess(); } public string GetName() @@ -24,12 +24,47 @@ namespace DotRecast.Recast.Toolset.Tools return "Create Temp Obstacles"; } - public void Build(IInputGeomProvider geom, RcNavMeshBuildSettings setting, RcByteOrder order, bool cCompatibility) + public bool Build(IInputGeomProvider geom, RcNavMeshBuildSettings setting, RcByteOrder order, bool cCompatibility) { - RcUtils.CalcTileCount(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), - setting.cellSize, setting.tileSize, setting.tileSize, - out var tw, out var th - ); + DtStatus status; + + if (null == geom || null == geom.GetMesh()) + { + //m_ctx->log(RC_LOG_ERROR, "buildTiledNavigation: No vertices and triangles."); + return false; + } + + _proc.Init(geom); + + // Init cache + var bmin = geom.GetMeshBoundsMin(); + var bmax = geom.GetMeshBoundsMax(); + RcUtils.CalcGridSize(bmin, bmax, setting.cellSize, out var gw, out var gh); + int ts = setting.tileSize; + int tw = (gw + ts-1) / ts; + int th = (gh + ts-1) / ts; + + // Generation params. + // RcConfig cfg = new RcConfig(); + // cfg.cs = m_cellSize; + // cfg.ch = m_cellHeight; + // cfg.walkableSlopeAngle = m_agentMaxSlope; + // cfg.walkableHeight = (int)ceilf(m_agentHeight / cfg.ch); + // cfg.walkableClimb = (int)floorf(m_agentMaxClimb / cfg.ch); + // cfg.walkableRadius = (int)ceilf(m_agentRadius / cfg.cs); + // cfg.maxEdgeLen = (int)(m_edgeMaxLen / m_cellSize); + // cfg.maxSimplificationError = m_edgeMaxError; + // cfg.minRegionArea = (int)rcSqr(m_regionMinSize); // Note: area = size*size + // cfg.mergeRegionArea = (int)rcSqr(m_regionMergeSize); // Note: area = size*size + // cfg.maxVertsPerPoly = (int)m_vertsPerPoly; + // cfg.tileSize = (int)m_tileSize; + // cfg.borderSize = cfg.walkableRadius + 3; // Reserve enough padding. + // cfg.width = cfg.tileSize + cfg.borderSize*2; + // cfg.height = cfg.tileSize + cfg.borderSize*2; + // cfg.detailSampleDist = m_detailSampleDist < 0.9f ? 0 : m_cellSize * m_detailSampleDist; + // cfg.detailSampleMaxError = m_cellHeight * m_detailSampleMaxError; + // rcVcopy(cfg.bmin, bmin); + // rcVcopy(cfg.bmax, bmax); _tc = CreateTileCache(geom, setting, tw, th, order, cCompatibility); @@ -58,6 +93,8 @@ namespace DotRecast.Recast.Toolset.Tools // } } } + + return true; } public void ClearAllTempObstacles() @@ -121,7 +158,7 @@ namespace DotRecast.Recast.Toolset.Tools navMeshParams.maxPolys = 16384; var navMesh = new DtNavMesh(navMeshParams, 6); - var comp = _compFactory.Create(cCompatibility ? 0 : 1); + var comp = _comp.Create(cCompatibility ? 0 : 1); var storageParams = new DtTileCacheStorageParams(order, cCompatibility); DtTileCache tc = new DtTileCache(option, storageParams, navMesh, comp, _proc); return tc; diff --git a/src/DotRecast.Recast/RcConfig.cs b/src/DotRecast.Recast/RcConfig.cs index da80445..09dc38d 100644 --- a/src/DotRecast.Recast/RcConfig.cs +++ b/src/DotRecast.Recast/RcConfig.cs @@ -114,7 +114,7 @@ namespace DotRecast.Recast public readonly float WalkableClimbWorld; public readonly float WalkableRadiusWorld; public readonly float MaxEdgeLenWorld; - + /** * Non-tiled build configuration */ diff --git a/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs b/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs index e84b0dd..fadf497 100644 --- a/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs +++ b/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs @@ -110,7 +110,7 @@ public class RecastSoloMeshTest m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize, m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist, m_detailSampleMaxError, SampleAreaModifications.SAMPLE_AREAMOD_GROUND); RecastBuilderConfig bcfg = new RecastBuilderConfig(cfg, bmin, bmax); - + // // Step 2. Rasterize input polygon soup. // @@ -133,13 +133,12 @@ public class RecastSoloMeshTest // the are type for each of the meshes and rasterize them. int[] m_triareas = RcUtils.MarkWalkableTriangles(m_ctx, cfg.WalkableSlopeAngle, verts, tris, ntris, cfg.WalkableAreaMod); RecastRasterization.RasterizeTriangles(m_solid, verts, tris, m_triareas, ntris, cfg.WalkableClimb, m_ctx); - } - + // // Step 3. Filter walkable surfaces. // - + // Once all geometry is rasterized, we do initial pass of filtering to // remove unwanted overhangs caused by the conservative rasterization // as well as filter spans where the character cannot possibly stand.