forked from mirror/DotRecast
removed new int[2] in CalcGridSize()
This commit is contained in:
parent
d9f8629930
commit
a96f582a54
|
@ -97,18 +97,18 @@ public class TileNavMeshBuilder : AbstractNavMeshBuilder
|
||||||
|
|
||||||
private int GetTileBits(DemoInputGeomProvider geom, float cellSize, int tileSize)
|
private int GetTileBits(DemoInputGeomProvider geom, float cellSize, int tileSize)
|
||||||
{
|
{
|
||||||
int[] wh = Recast.CalcGridSize(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), cellSize);
|
Recast.CalcGridSize(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), cellSize, out var gw, out var gh);
|
||||||
int tw = (wh[0] + tileSize - 1) / tileSize;
|
int tw = (gw + tileSize - 1) / tileSize;
|
||||||
int th = (wh[1] + tileSize - 1) / tileSize;
|
int th = (gh + tileSize - 1) / tileSize;
|
||||||
int tileBits = Math.Min(Ilog2(NextPow2(tw * th)), 14);
|
int tileBits = Math.Min(Ilog2(NextPow2(tw * th)), 14);
|
||||||
return tileBits;
|
return tileBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] GetTiles(DemoInputGeomProvider geom, float cellSize, int tileSize)
|
public int[] GetTiles(DemoInputGeomProvider geom, float cellSize, int tileSize)
|
||||||
{
|
{
|
||||||
int[] wh = Recast.CalcGridSize(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), cellSize);
|
Recast.CalcGridSize(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), cellSize, out var gw, out var gh);
|
||||||
int tw = (wh[0] + tileSize - 1) / tileSize;
|
int tw = (gw + tileSize - 1) / tileSize;
|
||||||
int th = (wh[1] + tileSize - 1) / tileSize;
|
int th = (gh + tileSize - 1) / tileSize;
|
||||||
return new int[] { tw, th };
|
return new int[] { tw, th };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -429,8 +429,8 @@ public class RecastDemo
|
||||||
{
|
{
|
||||||
Vector3f bmin = sample.GetInputGeom().GetMeshBoundsMin();
|
Vector3f bmin = sample.GetInputGeom().GetMeshBoundsMin();
|
||||||
Vector3f bmax = sample.GetInputGeom().GetMeshBoundsMax();
|
Vector3f bmax = sample.GetInputGeom().GetMeshBoundsMax();
|
||||||
int[] voxels = Recast.CalcGridSize(bmin, bmax, settingsUI.GetCellSize());
|
Recast.CalcGridSize(bmin, bmax, settingsUI.GetCellSize(), out var gw, out var gh);
|
||||||
settingsUI.SetVoxels(voxels);
|
settingsUI.SetVoxels(gw, gh);
|
||||||
settingsUI.SetTiles(tileNavMeshBuilder.GetTiles(sample.GetInputGeom(), settingsUI.GetCellSize(), settingsUI.GetTileSize()));
|
settingsUI.SetTiles(tileNavMeshBuilder.GetTiles(sample.GetInputGeom(), settingsUI.GetCellSize(), settingsUI.GetTileSize()));
|
||||||
settingsUI.SetMaxTiles(tileNavMeshBuilder.GetMaxTiles(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()));
|
settingsUI.SetMaxPolys(tileNavMeshBuilder.GetMaxPolysPerTile(sample.GetInputGeom(), settingsUI.GetCellSize(), settingsUI.GetTileSize()));
|
||||||
|
|
|
@ -332,10 +332,10 @@ public class RcSettingsView : IRcView
|
||||||
return detailSampleMaxError;
|
return detailSampleMaxError;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetVoxels(int[] voxels)
|
public void SetVoxels(int gw, int gh)
|
||||||
{
|
{
|
||||||
this.voxels[0] = voxels[0];
|
voxels[0] = gw;
|
||||||
this.voxels[1] = voxels[1];
|
voxels[1] = gh;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsTiled()
|
public bool IsTiled()
|
||||||
|
|
|
@ -25,9 +25,9 @@ namespace DotRecast.Recast
|
||||||
{
|
{
|
||||||
using static RecastConstants;
|
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++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
|
@ -46,27 +46,16 @@ namespace DotRecast.Recast
|
||||||
// Calculate bounding box.
|
// 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) };
|
sizeX = (int)((bmax.x - bmin.x) / cs + 0.5f);
|
||||||
}
|
sizeZ = (int)((bmax.z - bmin.z) / 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) };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static int[] CalcTileCount(Vector3f bmin, Vector3f bmax, float cs, int tileSizeX, int tileSizeZ)
|
public static int[] CalcTileCount(Vector3f bmin, Vector3f bmax, float cs, int tileSizeX, int tileSizeZ)
|
||||||
{
|
{
|
||||||
int[] gwd = CalcGridSize(bmin, bmax, cs);
|
CalcGridSize(bmin, bmax, cs, out var gw, out var gd);
|
||||||
int gw = gwd[0];
|
|
||||||
int gd = gwd[1];
|
|
||||||
int tw = (gw + tileSizeX - 1) / tileSizeX;
|
int tw = (gw + tileSizeX - 1) / tileSizeX;
|
||||||
int td = (gd + tileSizeZ - 1) / tileSizeZ;
|
int td = (gd + tileSizeZ - 1) / tileSizeZ;
|
||||||
return new int[] { tw, td };
|
return new int[] { tw, td };
|
||||||
|
@ -79,8 +68,7 @@ namespace DotRecast.Recast
|
||||||
/// See the #rcConfig documentation for more information on the configuration parameters.
|
/// See the #rcConfig documentation for more information on the configuration parameters.
|
||||||
///
|
///
|
||||||
/// @see rcHeightfield, rcClearUnwalkableTriangles, rcRasterizeTriangles
|
/// @see rcHeightfield, rcClearUnwalkableTriangles, rcRasterizeTriangles
|
||||||
public static int[] MarkWalkableTriangles(Telemetry ctx, float walkableSlopeAngle, float[] verts, int[] tris, int nt,
|
public static int[] MarkWalkableTriangles(Telemetry ctx, float walkableSlopeAngle, float[] verts, int[] tris, int nt, AreaModification areaMod)
|
||||||
AreaModification areaMod)
|
|
||||||
{
|
{
|
||||||
int[] areas = new int[nt];
|
int[] areas = new int[nt];
|
||||||
float walkableThr = (float)Math.Cos(walkableSlopeAngle / 180.0f * Math.PI);
|
float walkableThr = (float)Math.Cos(walkableSlopeAngle / 180.0f * Math.PI);
|
||||||
|
@ -97,17 +85,7 @@ namespace DotRecast.Recast
|
||||||
return areas;
|
return areas;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CalcTriNormal(float[] verts, int v0, int v1, int v2, float[] norm)
|
public static void CalcTriNormal(float[] verts, int v0, int v1, int v2, ref Vector3f 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)
|
|
||||||
{
|
{
|
||||||
Vector3f e0 = new Vector3f();
|
Vector3f e0 = new Vector3f();
|
||||||
Vector3f e1 = 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 the #rcConfig documentation for more information on the configuration parameters.
|
||||||
///
|
///
|
||||||
/// @see rcHeightfield, rcClearUnwalkableTriangles, rcRasterizeTriangles
|
/// @see rcHeightfield, rcClearUnwalkableTriangles, rcRasterizeTriangles
|
||||||
public static void ClearUnwalkableTriangles(Telemetry ctx, float walkableSlopeAngle, float[] verts, int nv,
|
public static void ClearUnwalkableTriangles(Telemetry ctx, float walkableSlopeAngle, float[] verts, int nv, int[] tris, int nt, int[] areas)
|
||||||
int[] tris, int nt, int[] areas)
|
|
||||||
{
|
{
|
||||||
float walkableThr = (float)Math.Cos(walkableSlopeAngle / 180.0f * Math.PI);
|
float walkableThr = (float)Math.Cos(walkableSlopeAngle / 180.0f * Math.PI);
|
||||||
|
|
||||||
|
|
|
@ -92,9 +92,7 @@ namespace DotRecast.Recast
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int[] wh = Recast.CalcGridSize(this.bmin, this.bmax, cfg.cs);
|
Recast.CalcGridSize(this.bmin, this.bmax, cfg.cs, out width, out height);
|
||||||
width = wh[0];
|
|
||||||
height = wh[1];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class MeshSetReaderWriterTest
|
||||||
|
|
||||||
Vector3f bmin = geom.GetMeshBoundsMin();
|
Vector3f bmin = geom.GetMeshBoundsMin();
|
||||||
Vector3f bmax = geom.GetMeshBoundsMax();
|
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 tw = twh[0];
|
||||||
int th = twh[1];
|
int th = twh[1];
|
||||||
for (int y = 0; y < th; ++y)
|
for (int y = 0; y < th; ++y)
|
||||||
|
|
|
@ -22,7 +22,6 @@ using System.Collections.Generic;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Recast;
|
using DotRecast.Recast;
|
||||||
using DotRecast.Recast.Geom;
|
using DotRecast.Recast.Geom;
|
||||||
using static DotRecast.Core.RcMath;
|
|
||||||
|
|
||||||
namespace DotRecast.Detour.TileCache.Test;
|
namespace DotRecast.Detour.TileCache.Test;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue