diff --git a/src/DotRecast.Recast.Demo/Builder/TileNavMeshBuilder.cs b/src/DotRecast.Recast.Demo/Builder/TileNavMeshBuilder.cs index 0a1b1c9..bdc31ea 100644 --- a/src/DotRecast.Recast.Demo/Builder/TileNavMeshBuilder.cs +++ b/src/DotRecast.Recast.Demo/Builder/TileNavMeshBuilder.cs @@ -97,18 +97,18 @@ public class TileNavMeshBuilder : AbstractNavMeshBuilder private int GetTileBits(DemoInputGeomProvider geom, float cellSize, int tileSize) { - int[] wh = Recast.CalcGridSize(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), cellSize); - int tw = (wh[0] + tileSize - 1) / tileSize; - int th = (wh[1] + tileSize - 1) / tileSize; + Recast.CalcGridSize(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), cellSize, out var gw, out var gh); + int tw = (gw + tileSize - 1) / tileSize; + int th = (gh + tileSize - 1) / tileSize; int tileBits = Math.Min(Ilog2(NextPow2(tw * th)), 14); return tileBits; } public int[] GetTiles(DemoInputGeomProvider geom, float cellSize, int tileSize) { - int[] wh = Recast.CalcGridSize(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), cellSize); - int tw = (wh[0] + tileSize - 1) / tileSize; - int th = (wh[1] + tileSize - 1) / tileSize; + Recast.CalcGridSize(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), cellSize, out var gw, out var gh); + int tw = (gw + tileSize - 1) / tileSize; + int th = (gh + tileSize - 1) / tileSize; return new int[] { tw, th }; } diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index 11d772f..40e40ef 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -429,8 +429,8 @@ public class RecastDemo { Vector3f bmin = sample.GetInputGeom().GetMeshBoundsMin(); Vector3f bmax = sample.GetInputGeom().GetMeshBoundsMax(); - int[] voxels = Recast.CalcGridSize(bmin, bmax, settingsUI.GetCellSize()); - settingsUI.SetVoxels(voxels); + Recast.CalcGridSize(bmin, bmax, settingsUI.GetCellSize(), out var gw, out var gh); + settingsUI.SetVoxels(gw, gh); settingsUI.SetTiles(tileNavMeshBuilder.GetTiles(sample.GetInputGeom(), settingsUI.GetCellSize(), settingsUI.GetTileSize())); settingsUI.SetMaxTiles(tileNavMeshBuilder.GetMaxTiles(sample.GetInputGeom(), settingsUI.GetCellSize(), settingsUI.GetTileSize())); settingsUI.SetMaxPolys(tileNavMeshBuilder.GetMaxPolysPerTile(sample.GetInputGeom(), settingsUI.GetCellSize(), settingsUI.GetTileSize())); diff --git a/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs b/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs index 282b7c8..cfbd5ac 100644 --- a/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs +++ b/src/DotRecast.Recast.Demo/UI/RcSettingsView.cs @@ -332,10 +332,10 @@ public class RcSettingsView : IRcView return detailSampleMaxError; } - public void SetVoxels(int[] voxels) + public void SetVoxels(int gw, int gh) { - this.voxels[0] = voxels[0]; - this.voxels[1] = voxels[1]; + voxels[0] = gw; + voxels[1] = gh; } public bool IsTiled() diff --git a/src/DotRecast.Recast/Recast.cs b/src/DotRecast.Recast/Recast.cs index fd1c209..8b165af 100644 --- a/src/DotRecast.Recast/Recast.cs +++ b/src/DotRecast.Recast/Recast.cs @@ -25,9 +25,9 @@ namespace DotRecast.Recast { using static RecastConstants; - public class Recast + public static class Recast { - void CalcBounds(float[] verts, int nv, float[] bmin, float[] bmax) + public static void CalcBounds(float[] verts, int nv, float[] bmin, float[] bmax) { for (int i = 0; i < 3; i++) { @@ -46,27 +46,16 @@ namespace DotRecast.Recast // Calculate bounding box. } - public static int[] CalcGridSize(float[] bmin, float[] bmax, float cs) + public static void CalcGridSize(Vector3f bmin, Vector3f bmax, float cs, out int sizeX, out int sizeZ) { - return new int[] { (int)((bmax[0] - bmin[0]) / cs + 0.5f), (int)((bmax[2] - bmin[2]) / cs + 0.5f) }; - } - - public static int[] CalcGridSize(Vector3f bmin, float[] bmax, float cs) - { - return new int[] { (int)((bmax[0] - bmin.x) / cs + 0.5f), (int)((bmax[2] - bmin.z) / cs + 0.5f) }; - } - - public static int[] CalcGridSize(Vector3f bmin, Vector3f bmax, float cs) - { - return new int[] { (int)((bmax.x - bmin.x) / cs + 0.5f), (int)((bmax.z - bmin.z) / cs + 0.5f) }; + sizeX = (int)((bmax.x - bmin.x) / cs + 0.5f); + sizeZ = (int)((bmax.z - bmin.z) / cs + 0.5f); } public static int[] CalcTileCount(Vector3f bmin, Vector3f bmax, float cs, int tileSizeX, int tileSizeZ) { - int[] gwd = CalcGridSize(bmin, bmax, cs); - int gw = gwd[0]; - int gd = gwd[1]; + CalcGridSize(bmin, bmax, cs, out var gw, out var gd); int tw = (gw + tileSizeX - 1) / tileSizeX; int td = (gd + tileSizeZ - 1) / tileSizeZ; return new int[] { tw, td }; @@ -79,8 +68,7 @@ namespace DotRecast.Recast /// See the #rcConfig documentation for more information on the configuration parameters. /// /// @see rcHeightfield, rcClearUnwalkableTriangles, rcRasterizeTriangles - public static int[] MarkWalkableTriangles(Telemetry ctx, float walkableSlopeAngle, float[] verts, int[] tris, int nt, - AreaModification areaMod) + public static int[] MarkWalkableTriangles(Telemetry ctx, float walkableSlopeAngle, float[] verts, int[] tris, int nt, AreaModification areaMod) { int[] areas = new int[nt]; float walkableThr = (float)Math.Cos(walkableSlopeAngle / 180.0f * Math.PI); @@ -97,17 +85,7 @@ namespace DotRecast.Recast return areas; } - static void CalcTriNormal(float[] verts, int v0, int v1, int v2, float[] norm) - { - Vector3f e0 = new Vector3f(); - Vector3f e1 = new Vector3f(); - Vector3f.Sub(ref e0, verts, v1 * 3, v0 * 3); - Vector3f.Sub(ref e1, verts, v2 * 3, v0 * 3); - Vector3f.Cross(norm, e0, e1); - Vector3f.Normalize(norm); - } - - static void CalcTriNormal(float[] verts, int v0, int v1, int v2, ref Vector3f norm) + public static void CalcTriNormal(float[] verts, int v0, int v1, int v2, ref Vector3f norm) { Vector3f e0 = new Vector3f(); Vector3f e1 = new Vector3f(); @@ -126,8 +104,7 @@ namespace DotRecast.Recast /// See the #rcConfig documentation for more information on the configuration parameters. /// /// @see rcHeightfield, rcClearUnwalkableTriangles, rcRasterizeTriangles - public static void ClearUnwalkableTriangles(Telemetry ctx, float walkableSlopeAngle, float[] verts, int nv, - int[] tris, int nt, int[] areas) + public static void ClearUnwalkableTriangles(Telemetry ctx, float walkableSlopeAngle, float[] verts, int nv, int[] tris, int nt, int[] areas) { float walkableThr = (float)Math.Cos(walkableSlopeAngle / 180.0f * Math.PI); @@ -143,4 +120,4 @@ namespace DotRecast.Recast } } } -} +} \ No newline at end of file diff --git a/src/DotRecast.Recast/RecastBuilderConfig.cs b/src/DotRecast.Recast/RecastBuilderConfig.cs index 95092fb..0647bb4 100644 --- a/src/DotRecast.Recast/RecastBuilderConfig.cs +++ b/src/DotRecast.Recast/RecastBuilderConfig.cs @@ -92,9 +92,7 @@ namespace DotRecast.Recast } else { - int[] wh = Recast.CalcGridSize(this.bmin, this.bmax, cfg.cs); - width = wh[0]; - height = wh[1]; + Recast.CalcGridSize(this.bmin, this.bmax, cfg.cs, out width, out height); } } } diff --git a/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs b/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs index 2760ed1..9eb108e 100644 --- a/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs +++ b/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs @@ -69,7 +69,7 @@ public class MeshSetReaderWriterTest Vector3f bmin = geom.GetMeshBoundsMin(); Vector3f bmax = geom.GetMeshBoundsMax(); - int[] twh = DotRecast.Recast.Recast.CalcTileCount(bmin, bmax, m_cellSize, m_tileSize, m_tileSize); + int[] twh = Recast.Recast.CalcTileCount(bmin, bmax, m_cellSize, m_tileSize, m_tileSize); int tw = twh[0]; int th = twh[1]; for (int y = 0; y < th; ++y) diff --git a/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs b/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs index 7e89f30..f95f768 100644 --- a/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs +++ b/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs @@ -22,7 +22,6 @@ using System.Collections.Generic; using DotRecast.Core; using DotRecast.Recast; using DotRecast.Recast.Geom; -using static DotRecast.Core.RcMath; namespace DotRecast.Detour.TileCache.Test;