forked from bit/DotRecastNetSim
rename in DotRecast.Detour.Dynamic
This commit is contained in:
parent
fea18a5064
commit
3ff14834f0
|
@ -17,11 +17,9 @@ freely, subject to the following restrictions:
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using DotRecast.Core;
|
namespace DotRecast.Core
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic.Io
|
|
||||||
{
|
{
|
||||||
public static class ByteUtils
|
public static class RcByteUtils
|
||||||
{
|
{
|
||||||
public static int GetInt(byte[] data, int position, RcByteOrder order)
|
public static int GetInt(byte[] data, int position, RcByteOrder order)
|
||||||
{
|
{
|
||||||
|
@ -30,13 +28,17 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
|
|
||||||
public static int GetIntBE(byte[] data, int position)
|
public static int GetIntBE(byte[] data, int position)
|
||||||
{
|
{
|
||||||
return ((data[position] & 0xff) << 24) | ((data[position + 1] & 0xff) << 16) | ((data[position + 2] & 0xff) << 8)
|
return ((data[position] & 0xff) << 24)
|
||||||
|
| ((data[position + 1] & 0xff) << 16)
|
||||||
|
| ((data[position + 2] & 0xff) << 8)
|
||||||
| (data[position + 3] & 0xff);
|
| (data[position + 3] & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetIntLE(byte[] data, int position)
|
public static int GetIntLE(byte[] data, int position)
|
||||||
{
|
{
|
||||||
return ((data[position + 3] & 0xff) << 24) | ((data[position + 2] & 0xff) << 16) | ((data[position + 1] & 0xff) << 8)
|
return ((data[position + 3] & 0xff) << 24)
|
||||||
|
| ((data[position + 2] & 0xff) << 16)
|
||||||
|
| ((data[position + 1] & 0xff) << 8)
|
||||||
| (data[position] & 0xff);
|
| (data[position] & 0xff);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ freely, subject to the following restrictions:
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Detour.Crowd.Tracking;
|
using DotRecast.Detour.Crowd.Tracking;
|
||||||
|
|
|
@ -23,12 +23,12 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic.Colliders
|
namespace DotRecast.Detour.Dynamic.Colliders
|
||||||
{
|
{
|
||||||
public class BoxCollider : AbstractCollider
|
public class DtBoxCollider : DtCollider
|
||||||
{
|
{
|
||||||
private readonly RcVec3f center;
|
private readonly RcVec3f center;
|
||||||
private readonly RcVec3f[] halfEdges;
|
private readonly RcVec3f[] halfEdges;
|
||||||
|
|
||||||
public BoxCollider(RcVec3f center, RcVec3f[] halfEdges, int area, float flagMergeThreshold) :
|
public DtBoxCollider(RcVec3f center, RcVec3f[] halfEdges, int area, float flagMergeThreshold) :
|
||||||
base(area, flagMergeThreshold, Bounds(center, halfEdges))
|
base(area, flagMergeThreshold, Bounds(center, halfEdges))
|
||||||
{
|
{
|
||||||
this.center = center;
|
this.center = center;
|
|
@ -23,13 +23,13 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic.Colliders
|
namespace DotRecast.Detour.Dynamic.Colliders
|
||||||
{
|
{
|
||||||
public class CapsuleCollider : AbstractCollider
|
public class DtCapsuleCollider : DtCollider
|
||||||
{
|
{
|
||||||
private readonly RcVec3f start;
|
private readonly RcVec3f start;
|
||||||
private readonly RcVec3f end;
|
private readonly RcVec3f end;
|
||||||
private readonly float radius;
|
private readonly float radius;
|
||||||
|
|
||||||
public CapsuleCollider(RcVec3f start, RcVec3f end, float radius, int area, float flagMergeThreshold)
|
public DtCapsuleCollider(RcVec3f start, RcVec3f end, float radius, int area, float flagMergeThreshold)
|
||||||
: base(area, flagMergeThreshold, Bounds(start, end, radius))
|
: base(area, flagMergeThreshold, Bounds(start, end, radius))
|
||||||
{
|
{
|
||||||
this.start = start;
|
this.start = start;
|
|
@ -22,13 +22,13 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic.Colliders
|
namespace DotRecast.Detour.Dynamic.Colliders
|
||||||
{
|
{
|
||||||
public abstract class AbstractCollider : ICollider
|
public abstract class DtCollider : IDtCollider
|
||||||
{
|
{
|
||||||
protected readonly int area;
|
protected readonly int area;
|
||||||
protected readonly float flagMergeThreshold;
|
protected readonly float flagMergeThreshold;
|
||||||
protected readonly float[] _bounds;
|
protected readonly float[] _bounds;
|
||||||
|
|
||||||
public AbstractCollider(int area, float flagMergeThreshold, float[] bounds)
|
public DtCollider(int area, float flagMergeThreshold, float[] bounds)
|
||||||
{
|
{
|
||||||
this.area = area;
|
this.area = area;
|
||||||
this.flagMergeThreshold = flagMergeThreshold;
|
this.flagMergeThreshold = flagMergeThreshold;
|
|
@ -25,18 +25,18 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic.Colliders
|
namespace DotRecast.Detour.Dynamic.Colliders
|
||||||
{
|
{
|
||||||
public class CompositeCollider : ICollider
|
public class DtCompositeCollider : IDtCollider
|
||||||
{
|
{
|
||||||
private readonly List<ICollider> colliders;
|
private readonly List<IDtCollider> colliders;
|
||||||
private readonly float[] _bounds;
|
private readonly float[] _bounds;
|
||||||
|
|
||||||
public CompositeCollider(List<ICollider> colliders)
|
public DtCompositeCollider(List<IDtCollider> colliders)
|
||||||
{
|
{
|
||||||
this.colliders = colliders;
|
this.colliders = colliders;
|
||||||
_bounds = Bounds(colliders);
|
_bounds = Bounds(colliders);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompositeCollider(params ICollider[] colliders)
|
public DtCompositeCollider(params IDtCollider[] colliders)
|
||||||
{
|
{
|
||||||
this.colliders = colliders.ToList();
|
this.colliders = colliders.ToList();
|
||||||
_bounds = Bounds(this.colliders);
|
_bounds = Bounds(this.colliders);
|
||||||
|
@ -47,14 +47,14 @@ namespace DotRecast.Detour.Dynamic.Colliders
|
||||||
return _bounds;
|
return _bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float[] Bounds(List<ICollider> colliders)
|
private static float[] Bounds(List<IDtCollider> colliders)
|
||||||
{
|
{
|
||||||
float[] bounds = new float[]
|
float[] bounds = new float[]
|
||||||
{
|
{
|
||||||
float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity,
|
float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity,
|
||||||
float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity
|
float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity
|
||||||
};
|
};
|
||||||
foreach (ICollider collider in colliders)
|
foreach (IDtCollider collider in colliders)
|
||||||
{
|
{
|
||||||
float[] b = collider.Bounds();
|
float[] b = collider.Bounds();
|
||||||
bounds[0] = Math.Min(bounds[0], b[0]);
|
bounds[0] = Math.Min(bounds[0], b[0]);
|
|
@ -23,19 +23,19 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic.Colliders
|
namespace DotRecast.Detour.Dynamic.Colliders
|
||||||
{
|
{
|
||||||
public class ConvexTrimeshCollider : AbstractCollider
|
public class DtConvexTrimeshCollider : DtCollider
|
||||||
{
|
{
|
||||||
private readonly float[] vertices;
|
private readonly float[] vertices;
|
||||||
private readonly int[] triangles;
|
private readonly int[] triangles;
|
||||||
|
|
||||||
public ConvexTrimeshCollider(float[] vertices, int[] triangles, int area, float flagMergeThreshold)
|
public DtConvexTrimeshCollider(float[] vertices, int[] triangles, int area, float flagMergeThreshold)
|
||||||
: base(area, flagMergeThreshold, TrimeshCollider.ComputeBounds(vertices))
|
: base(area, flagMergeThreshold, DtTrimeshCollider.ComputeBounds(vertices))
|
||||||
{
|
{
|
||||||
this.vertices = vertices;
|
this.vertices = vertices;
|
||||||
this.triangles = triangles;
|
this.triangles = triangles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConvexTrimeshCollider(float[] vertices, int[] triangles, float[] bounds, int area, float flagMergeThreshold)
|
public DtConvexTrimeshCollider(float[] vertices, int[] triangles, float[] bounds, int area, float flagMergeThreshold)
|
||||||
: base(area, flagMergeThreshold, bounds)
|
: base(area, flagMergeThreshold, bounds)
|
||||||
{
|
{
|
||||||
this.vertices = vertices;
|
this.vertices = vertices;
|
|
@ -23,13 +23,13 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic.Colliders
|
namespace DotRecast.Detour.Dynamic.Colliders
|
||||||
{
|
{
|
||||||
public class CylinderCollider : AbstractCollider
|
public class DtCylinderCollider : DtCollider
|
||||||
{
|
{
|
||||||
private readonly RcVec3f start;
|
private readonly RcVec3f start;
|
||||||
private readonly RcVec3f end;
|
private readonly RcVec3f end;
|
||||||
private readonly float radius;
|
private readonly float radius;
|
||||||
|
|
||||||
public CylinderCollider(RcVec3f start, RcVec3f end, float radius, int area, float flagMergeThreshold) :
|
public DtCylinderCollider(RcVec3f start, RcVec3f end, float radius, int area, float flagMergeThreshold) :
|
||||||
base(area, flagMergeThreshold, Bounds(start, end, radius))
|
base(area, flagMergeThreshold, Bounds(start, end, radius))
|
||||||
{
|
{
|
||||||
this.start = start;
|
this.start = start;
|
|
@ -23,12 +23,12 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic.Colliders
|
namespace DotRecast.Detour.Dynamic.Colliders
|
||||||
{
|
{
|
||||||
public class SphereCollider : AbstractCollider
|
public class DtSphereCollider : DtCollider
|
||||||
{
|
{
|
||||||
private readonly RcVec3f center;
|
private readonly RcVec3f center;
|
||||||
private readonly float radius;
|
private readonly float radius;
|
||||||
|
|
||||||
public SphereCollider(RcVec3f center, float radius, int area, float flagMergeThreshold)
|
public DtSphereCollider(RcVec3f center, float radius, int area, float flagMergeThreshold)
|
||||||
: base(area, flagMergeThreshold, Bounds(center, radius))
|
: base(area, flagMergeThreshold, Bounds(center, radius))
|
||||||
{
|
{
|
||||||
this.center = center;
|
this.center = center;
|
|
@ -23,19 +23,19 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic.Colliders
|
namespace DotRecast.Detour.Dynamic.Colliders
|
||||||
{
|
{
|
||||||
public class TrimeshCollider : AbstractCollider
|
public class DtTrimeshCollider : DtCollider
|
||||||
{
|
{
|
||||||
private readonly float[] vertices;
|
private readonly float[] vertices;
|
||||||
private readonly int[] triangles;
|
private readonly int[] triangles;
|
||||||
|
|
||||||
public TrimeshCollider(float[] vertices, int[] triangles, int area, float flagMergeThreshold)
|
public DtTrimeshCollider(float[] vertices, int[] triangles, int area, float flagMergeThreshold)
|
||||||
: base(area, flagMergeThreshold, ComputeBounds(vertices))
|
: base(area, flagMergeThreshold, ComputeBounds(vertices))
|
||||||
{
|
{
|
||||||
this.vertices = vertices;
|
this.vertices = vertices;
|
||||||
this.triangles = triangles;
|
this.triangles = triangles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TrimeshCollider(float[] vertices, int[] triangles, float[] bounds, int area, float flagMergeThreshold) :
|
public DtTrimeshCollider(float[] vertices, int[] triangles, float[] bounds, int area, float flagMergeThreshold) :
|
||||||
base(area, flagMergeThreshold, bounds)
|
base(area, flagMergeThreshold, bounds)
|
||||||
{
|
{
|
||||||
this.vertices = vertices;
|
this.vertices = vertices;
|
|
@ -22,7 +22,7 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic.Colliders
|
namespace DotRecast.Detour.Dynamic.Colliders
|
||||||
{
|
{
|
||||||
public interface ICollider
|
public interface IDtCollider
|
||||||
{
|
{
|
||||||
float[] Bounds();
|
float[] Bounds();
|
||||||
void Rasterize(RcHeightfield hf, RcTelemetry telemetry);
|
void Rasterize(RcHeightfield hf, RcTelemetry telemetry);
|
|
@ -20,7 +20,6 @@ freely, subject to the following restrictions:
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
|
@ -30,22 +29,22 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic
|
namespace DotRecast.Detour.Dynamic
|
||||||
{
|
{
|
||||||
public class DynamicNavMesh
|
public class DtDynamicNavMesh
|
||||||
{
|
{
|
||||||
public const int MAX_VERTS_PER_POLY = 6;
|
public const int MAX_VERTS_PER_POLY = 6;
|
||||||
public readonly DynamicNavMeshConfig config;
|
public readonly DtDynamicNavMeshConfig config;
|
||||||
private readonly RecastBuilder builder;
|
private readonly RecastBuilder builder;
|
||||||
private readonly Dictionary<long, DynamicTile> _tiles = new Dictionary<long, DynamicTile>();
|
private readonly Dictionary<long, DtDynamicTile> _tiles = new Dictionary<long, DtDynamicTile>();
|
||||||
private readonly RcTelemetry telemetry;
|
private readonly RcTelemetry telemetry;
|
||||||
private readonly DtNavMeshParams navMeshParams;
|
private readonly DtNavMeshParams navMeshParams;
|
||||||
private readonly BlockingCollection<IUpdateQueueItem> updateQueue = new BlockingCollection<IUpdateQueueItem>();
|
private readonly BlockingCollection<IDtDaynmicTileJob> updateQueue = new BlockingCollection<IDtDaynmicTileJob>();
|
||||||
private readonly RcAtomicLong currentColliderId = new RcAtomicLong(0);
|
private readonly RcAtomicLong currentColliderId = new RcAtomicLong(0);
|
||||||
private DtNavMesh _navMesh;
|
private DtNavMesh _navMesh;
|
||||||
private bool dirty = true;
|
private bool dirty = true;
|
||||||
|
|
||||||
public DynamicNavMesh(VoxelFile voxelFile)
|
public DtDynamicNavMesh(DtVoxelFile voxelFile)
|
||||||
{
|
{
|
||||||
config = new DynamicNavMeshConfig(voxelFile.useTiles, voxelFile.tileSizeX, voxelFile.tileSizeZ, voxelFile.cellSize);
|
config = new DtDynamicNavMeshConfig(voxelFile.useTiles, voxelFile.tileSizeX, voxelFile.tileSizeZ, voxelFile.cellSize);
|
||||||
config.walkableHeight = voxelFile.walkableHeight;
|
config.walkableHeight = voxelFile.walkableHeight;
|
||||||
config.walkableRadius = voxelFile.walkableRadius;
|
config.walkableRadius = voxelFile.walkableRadius;
|
||||||
config.walkableClimb = voxelFile.walkableClimb;
|
config.walkableClimb = voxelFile.walkableClimb;
|
||||||
|
@ -69,7 +68,7 @@ namespace DotRecast.Detour.Dynamic
|
||||||
navMeshParams.maxPolys = 0x8000;
|
navMeshParams.maxPolys = 0x8000;
|
||||||
foreach (var t in voxelFile.tiles)
|
foreach (var t in voxelFile.tiles)
|
||||||
{
|
{
|
||||||
_tiles.Add(LookupKey(t.tileX, t.tileZ), new DynamicTile(t));
|
_tiles.Add(LookupKey(t.tileX, t.tileZ), new DtDynamicTile(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
;
|
||||||
|
@ -84,9 +83,9 @@ namespace DotRecast.Detour.Dynamic
|
||||||
/**
|
/**
|
||||||
* Voxel queries require checkpoints to be enabled in {@link DynamicNavMeshConfig}
|
* Voxel queries require checkpoints to be enabled in {@link DynamicNavMeshConfig}
|
||||||
*/
|
*/
|
||||||
public VoxelQuery VoxelQuery()
|
public DtVoxelQuery VoxelQuery()
|
||||||
{
|
{
|
||||||
return new VoxelQuery(navMeshParams.orig, navMeshParams.tileWidth, navMeshParams.tileHeight, LookupHeightfield);
|
return new DtVoxelQuery(navMeshParams.orig, navMeshParams.tileWidth, navMeshParams.tileHeight, LookupHeightfield);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RcHeightfield LookupHeightfield(int x, int z)
|
private RcHeightfield LookupHeightfield(int x, int z)
|
||||||
|
@ -94,16 +93,16 @@ namespace DotRecast.Detour.Dynamic
|
||||||
return GetTileAt(x, z)?.checkpoint.heightfield;
|
return GetTileAt(x, z)?.checkpoint.heightfield;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long AddCollider(ICollider collider)
|
public long AddCollider(IDtCollider collider)
|
||||||
{
|
{
|
||||||
long cid = currentColliderId.IncrementAndGet();
|
long cid = currentColliderId.IncrementAndGet();
|
||||||
updateQueue.Add(new AddColliderQueueItem(cid, collider, GetTiles(collider.Bounds())));
|
updateQueue.Add(new DtDynamicTileColliderAdditionJob(cid, collider, GetTiles(collider.Bounds())));
|
||||||
return cid;
|
return cid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveCollider(long colliderId)
|
public void RemoveCollider(long colliderId)
|
||||||
{
|
{
|
||||||
updateQueue.Add(new RemoveColliderQueueItem(colliderId, GetTilesByCollider(colliderId)));
|
updateQueue.Add(new DtDynamicTileColliderRemovalJob(colliderId, GetTilesByCollider(colliderId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -123,14 +122,14 @@ namespace DotRecast.Detour.Dynamic
|
||||||
return Rebuild(ProcessQueue());
|
return Rebuild(ProcessQueue());
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool Rebuild(ICollection<DynamicTile> stream)
|
private bool Rebuild(ICollection<DtDynamicTile> stream)
|
||||||
{
|
{
|
||||||
foreach (var dynamicTile in stream)
|
foreach (var dynamicTile in stream)
|
||||||
Rebuild(dynamicTile);
|
Rebuild(dynamicTile);
|
||||||
return UpdateNavMesh();
|
return UpdateNavMesh();
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashSet<DynamicTile> ProcessQueue()
|
private HashSet<DtDynamicTile> ProcessQueue()
|
||||||
{
|
{
|
||||||
var items = ConsumeQueue();
|
var items = ConsumeQueue();
|
||||||
foreach (var item in items)
|
foreach (var item in items)
|
||||||
|
@ -141,9 +140,9 @@ namespace DotRecast.Detour.Dynamic
|
||||||
return items.SelectMany(i => i.AffectedTiles()).ToHashSet();
|
return items.SelectMany(i => i.AffectedTiles()).ToHashSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<IUpdateQueueItem> ConsumeQueue()
|
private List<IDtDaynmicTileJob> ConsumeQueue()
|
||||||
{
|
{
|
||||||
List<IUpdateQueueItem> items = new List<IUpdateQueueItem>();
|
List<IDtDaynmicTileJob> items = new List<IDtDaynmicTileJob>();
|
||||||
while (updateQueue.TryTake(out var item))
|
while (updateQueue.TryTake(out var item))
|
||||||
{
|
{
|
||||||
items.Add(item);
|
items.Add(item);
|
||||||
|
@ -152,7 +151,7 @@ namespace DotRecast.Detour.Dynamic
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Process(IUpdateQueueItem item)
|
private void Process(IDtDaynmicTileJob item)
|
||||||
{
|
{
|
||||||
foreach (var tile in item.AffectedTiles())
|
foreach (var tile in item.AffectedTiles())
|
||||||
{
|
{
|
||||||
|
@ -177,13 +176,13 @@ namespace DotRecast.Detour.Dynamic
|
||||||
return Rebuild(ProcessQueue(), executor);
|
return Rebuild(ProcessQueue(), executor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task<bool> Rebuild(ICollection<DynamicTile> tiles, TaskFactory executor)
|
private Task<bool> Rebuild(ICollection<DtDynamicTile> tiles, TaskFactory executor)
|
||||||
{
|
{
|
||||||
var tasks = tiles.Select(tile => executor.StartNew(() => Rebuild(tile))).ToArray();
|
var tasks = tiles.Select(tile => executor.StartNew(() => Rebuild(tile))).ToArray();
|
||||||
return Task.WhenAll(tasks).ContinueWith(k => UpdateNavMesh());
|
return Task.WhenAll(tasks).ContinueWith(k => UpdateNavMesh());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICollection<DynamicTile> GetTiles(float[] bounds)
|
private ICollection<DtDynamicTile> GetTiles(float[] bounds)
|
||||||
{
|
{
|
||||||
if (bounds == null)
|
if (bounds == null)
|
||||||
{
|
{
|
||||||
|
@ -194,12 +193,12 @@ namespace DotRecast.Detour.Dynamic
|
||||||
int minz = (int)Math.Floor((bounds[2] - navMeshParams.orig.z) / navMeshParams.tileHeight);
|
int minz = (int)Math.Floor((bounds[2] - navMeshParams.orig.z) / navMeshParams.tileHeight);
|
||||||
int maxx = (int)Math.Floor((bounds[3] - navMeshParams.orig.x) / navMeshParams.tileWidth);
|
int maxx = (int)Math.Floor((bounds[3] - navMeshParams.orig.x) / navMeshParams.tileWidth);
|
||||||
int maxz = (int)Math.Floor((bounds[5] - navMeshParams.orig.z) / navMeshParams.tileHeight);
|
int maxz = (int)Math.Floor((bounds[5] - navMeshParams.orig.z) / navMeshParams.tileHeight);
|
||||||
List<DynamicTile> tiles = new List<DynamicTile>();
|
List<DtDynamicTile> tiles = new List<DtDynamicTile>();
|
||||||
for (int z = minz; z <= maxz; ++z)
|
for (int z = minz; z <= maxz; ++z)
|
||||||
{
|
{
|
||||||
for (int x = minx; x <= maxx; ++x)
|
for (int x = minx; x <= maxx; ++x)
|
||||||
{
|
{
|
||||||
DynamicTile tile = GetTileAt(x, z);
|
DtDynamicTile tile = GetTileAt(x, z);
|
||||||
if (tile != null)
|
if (tile != null)
|
||||||
{
|
{
|
||||||
tiles.Add(tile);
|
tiles.Add(tile);
|
||||||
|
@ -210,12 +209,12 @@ namespace DotRecast.Detour.Dynamic
|
||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<DynamicTile> GetTilesByCollider(long cid)
|
private List<DtDynamicTile> GetTilesByCollider(long cid)
|
||||||
{
|
{
|
||||||
return _tiles.Values.Where(t => t.ContainsCollider(cid)).ToList();
|
return _tiles.Values.Where(t => t.ContainsCollider(cid)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Rebuild(DynamicTile tile)
|
private void Rebuild(DtDynamicTile tile)
|
||||||
{
|
{
|
||||||
DtNavMeshCreateParams option = new DtNavMeshCreateParams();
|
DtNavMeshCreateParams option = new DtNavMeshCreateParams();
|
||||||
option.walkableHeight = config.walkableHeight;
|
option.walkableHeight = config.walkableHeight;
|
||||||
|
@ -238,7 +237,7 @@ namespace DotRecast.Detour.Dynamic
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DynamicTile GetTileAt(int x, int z)
|
private DtDynamicTile GetTileAt(int x, int z)
|
||||||
{
|
{
|
||||||
return _tiles.TryGetValue(LookupKey(x, z), out var tile)
|
return _tiles.TryGetValue(LookupKey(x, z), out var tile)
|
||||||
? tile
|
? tile
|
||||||
|
@ -250,7 +249,7 @@ namespace DotRecast.Detour.Dynamic
|
||||||
return (z << 32) | x;
|
return (z << 32) | x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<VoxelTile> VoxelTiles()
|
public List<DtVoxelTile> VoxelTiles()
|
||||||
{
|
{
|
||||||
return _tiles.Values.Select(t => t.voxelTile).ToList();
|
return _tiles.Values.Select(t => t.voxelTile).ToList();
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic
|
namespace DotRecast.Detour.Dynamic
|
||||||
{
|
{
|
||||||
public class DynamicNavMeshConfig
|
public class DtDynamicNavMeshConfig
|
||||||
{
|
{
|
||||||
public readonly bool useTiles;
|
public readonly bool useTiles;
|
||||||
public readonly int tileSizeX;
|
public readonly int tileSizeX;
|
||||||
|
@ -47,7 +47,7 @@ namespace DotRecast.Detour.Dynamic
|
||||||
public bool enableCheckpoints = true;
|
public bool enableCheckpoints = true;
|
||||||
public bool keepIntermediateResults = false;
|
public bool keepIntermediateResults = false;
|
||||||
|
|
||||||
public DynamicNavMeshConfig(bool useTiles, int tileSizeX, int tileSizeZ, float cellSize)
|
public DtDynamicNavMeshConfig(bool useTiles, int tileSizeX, int tileSizeZ, float cellSize)
|
||||||
{
|
{
|
||||||
this.useTiles = useTiles;
|
this.useTiles = useTiles;
|
||||||
this.tileSizeX = tileSizeX;
|
this.tileSizeX = tileSizeX;
|
|
@ -20,7 +20,7 @@ freely, subject to the following restrictions:
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Detour.Dynamic.Colliders;
|
using DotRecast.Detour.Dynamic.Colliders;
|
||||||
|
@ -29,22 +29,22 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic
|
namespace DotRecast.Detour.Dynamic
|
||||||
{
|
{
|
||||||
public class DynamicTile
|
public class DtDynamicTile
|
||||||
{
|
{
|
||||||
public readonly VoxelTile voxelTile;
|
public readonly DtVoxelTile voxelTile;
|
||||||
public DynamicTileCheckpoint checkpoint;
|
public DtDynamicTileCheckpoint checkpoint;
|
||||||
public RecastBuilderResult recastResult;
|
public RecastBuilderResult recastResult;
|
||||||
private DtMeshData meshData;
|
private DtMeshData meshData;
|
||||||
private readonly ConcurrentDictionary<long, ICollider> colliders = new ConcurrentDictionary<long, ICollider>();
|
private readonly ConcurrentDictionary<long, IDtCollider> colliders = new ConcurrentDictionary<long, IDtCollider>();
|
||||||
private bool dirty = true;
|
private bool dirty = true;
|
||||||
private long id;
|
private long id;
|
||||||
|
|
||||||
public DynamicTile(VoxelTile voxelTile)
|
public DtDynamicTile(DtVoxelTile voxelTile)
|
||||||
{
|
{
|
||||||
this.voxelTile = voxelTile;
|
this.voxelTile = voxelTile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Build(RecastBuilder builder, DynamicNavMeshConfig config, RcTelemetry telemetry)
|
public bool Build(RecastBuilder builder, DtDynamicNavMeshConfig config, RcTelemetry telemetry)
|
||||||
{
|
{
|
||||||
if (dirty)
|
if (dirty)
|
||||||
{
|
{
|
||||||
|
@ -59,7 +59,7 @@ namespace DotRecast.Detour.Dynamic
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private RcHeightfield BuildHeightfield(DynamicNavMeshConfig config, RcTelemetry telemetry)
|
private RcHeightfield BuildHeightfield(DtDynamicNavMeshConfig config, RcTelemetry telemetry)
|
||||||
{
|
{
|
||||||
ICollection<long> rasterizedColliders = checkpoint != null
|
ICollection<long> rasterizedColliders = checkpoint != null
|
||||||
? checkpoint.colliders as ICollection<long>
|
? checkpoint.colliders as ICollection<long>
|
||||||
|
@ -80,13 +80,13 @@ namespace DotRecast.Detour.Dynamic
|
||||||
|
|
||||||
if (config.enableCheckpoints)
|
if (config.enableCheckpoints)
|
||||||
{
|
{
|
||||||
checkpoint = new DynamicTileCheckpoint(heightfield, colliders.Keys.ToHashSet());
|
checkpoint = new DtDynamicTileCheckpoint(heightfield, colliders.Keys.ToHashSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
return heightfield;
|
return heightfield;
|
||||||
}
|
}
|
||||||
|
|
||||||
private RecastBuilderResult BuildRecast(RecastBuilder builder, DynamicNavMeshConfig config, VoxelTile vt,
|
private RecastBuilderResult BuildRecast(RecastBuilder builder, DtDynamicNavMeshConfig config, DtVoxelTile vt,
|
||||||
RcHeightfield heightfield, RcTelemetry telemetry)
|
RcHeightfield heightfield, RcTelemetry telemetry)
|
||||||
{
|
{
|
||||||
RcConfig rcConfig = new RcConfig(
|
RcConfig rcConfig = new RcConfig(
|
||||||
|
@ -97,7 +97,7 @@ namespace DotRecast.Detour.Dynamic
|
||||||
config.walkableSlopeAngle, config.walkableHeight, config.walkableRadius, config.walkableClimb,
|
config.walkableSlopeAngle, config.walkableHeight, config.walkableRadius, config.walkableClimb,
|
||||||
config.minRegionArea, config.regionMergeArea,
|
config.minRegionArea, config.regionMergeArea,
|
||||||
config.maxEdgeLen, config.maxSimplificationError,
|
config.maxEdgeLen, config.maxSimplificationError,
|
||||||
Math.Min(DynamicNavMesh.MAX_VERTS_PER_POLY, config.vertsPerPoly),
|
Math.Min(DtDynamicNavMesh.MAX_VERTS_PER_POLY, config.vertsPerPoly),
|
||||||
config.detailSampleDistance, config.detailSampleMaxError,
|
config.detailSampleDistance, config.detailSampleMaxError,
|
||||||
true, true, true, null, true);
|
true, true, true, null, true);
|
||||||
RecastBuilderResult r = builder.Build(vt.tileX, vt.tileZ, null, rcConfig, heightfield, telemetry);
|
RecastBuilderResult r = builder.Build(vt.tileX, vt.tileZ, null, rcConfig, heightfield, telemetry);
|
||||||
|
@ -109,7 +109,7 @@ namespace DotRecast.Detour.Dynamic
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddCollider(long cid, ICollider collider)
|
public void AddCollider(long cid, IDtCollider collider)
|
||||||
{
|
{
|
||||||
colliders[cid] = collider;
|
colliders[cid] = collider;
|
||||||
dirty = true;
|
dirty = true;
|
||||||
|
@ -130,7 +130,7 @@ namespace DotRecast.Detour.Dynamic
|
||||||
}
|
}
|
||||||
|
|
||||||
private DtNavMeshCreateParams NavMeshCreateParams(int tilex, int tileZ, float cellSize, float cellHeight,
|
private DtNavMeshCreateParams NavMeshCreateParams(int tilex, int tileZ, float cellSize, float cellHeight,
|
||||||
DynamicNavMeshConfig config, RecastBuilderResult rcResult)
|
DtDynamicNavMeshConfig config, RecastBuilderResult rcResult)
|
||||||
{
|
{
|
||||||
RcPolyMesh m_pmesh = rcResult.GetMesh();
|
RcPolyMesh m_pmesh = rcResult.GetMesh();
|
||||||
RcPolyMeshDetail m_dmesh = rcResult.GetMeshDetail();
|
RcPolyMeshDetail m_dmesh = rcResult.GetMeshDetail();
|
|
@ -22,12 +22,12 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic
|
namespace DotRecast.Detour.Dynamic
|
||||||
{
|
{
|
||||||
public class DynamicTileCheckpoint
|
public class DtDynamicTileCheckpoint
|
||||||
{
|
{
|
||||||
public readonly RcHeightfield heightfield;
|
public readonly RcHeightfield heightfield;
|
||||||
public readonly ISet<long> colliders;
|
public readonly ISet<long> colliders;
|
||||||
|
|
||||||
public DynamicTileCheckpoint(RcHeightfield heightfield, ISet<long> colliders)
|
public DtDynamicTileCheckpoint(RcHeightfield heightfield, ISet<long> colliders)
|
||||||
{
|
{
|
||||||
this.colliders = colliders;
|
this.colliders = colliders;
|
||||||
this.heightfield = Clone(heightfield);
|
this.heightfield = Clone(heightfield);
|
|
@ -22,27 +22,27 @@ using DotRecast.Detour.Dynamic.Colliders;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic
|
namespace DotRecast.Detour.Dynamic
|
||||||
{
|
{
|
||||||
public class AddColliderQueueItem : IUpdateQueueItem
|
public class DtDynamicTileColliderAdditionJob : IDtDaynmicTileJob
|
||||||
{
|
{
|
||||||
private readonly long colliderId;
|
private readonly long _colliderId;
|
||||||
private readonly ICollider collider;
|
private readonly IDtCollider _collider;
|
||||||
private readonly ICollection<DynamicTile> _affectedTiles;
|
private readonly ICollection<DtDynamicTile> _affectedTiles;
|
||||||
|
|
||||||
public AddColliderQueueItem(long colliderId, ICollider collider, ICollection<DynamicTile> affectedTiles)
|
public DtDynamicTileColliderAdditionJob(long colliderId, IDtCollider collider, ICollection<DtDynamicTile> affectedTiles)
|
||||||
{
|
{
|
||||||
this.colliderId = colliderId;
|
_colliderId = colliderId;
|
||||||
this.collider = collider;
|
_collider = collider;
|
||||||
_affectedTiles = affectedTiles;
|
_affectedTiles = affectedTiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICollection<DynamicTile> AffectedTiles()
|
public ICollection<DtDynamicTile> AffectedTiles()
|
||||||
{
|
{
|
||||||
return _affectedTiles;
|
return _affectedTiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Process(DynamicTile tile)
|
public void Process(DtDynamicTile tile)
|
||||||
{
|
{
|
||||||
tile.AddCollider(colliderId, collider);
|
tile.AddCollider(_colliderId, _collider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,23 +21,23 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic
|
namespace DotRecast.Detour.Dynamic
|
||||||
{
|
{
|
||||||
public class RemoveColliderQueueItem : IUpdateQueueItem
|
public class DtDynamicTileColliderRemovalJob : IDtDaynmicTileJob
|
||||||
{
|
{
|
||||||
private readonly long colliderId;
|
private readonly long colliderId;
|
||||||
private readonly ICollection<DynamicTile> _affectedTiles;
|
private readonly ICollection<DtDynamicTile> _affectedTiles;
|
||||||
|
|
||||||
public RemoveColliderQueueItem(long colliderId, ICollection<DynamicTile> affectedTiles)
|
public DtDynamicTileColliderRemovalJob(long colliderId, ICollection<DtDynamicTile> affectedTiles)
|
||||||
{
|
{
|
||||||
this.colliderId = colliderId;
|
this.colliderId = colliderId;
|
||||||
this._affectedTiles = affectedTiles;
|
this._affectedTiles = affectedTiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICollection<DynamicTile> AffectedTiles()
|
public ICollection<DtDynamicTile> AffectedTiles()
|
||||||
{
|
{
|
||||||
return _affectedTiles;
|
return _affectedTiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Process(DynamicTile tile)
|
public void Process(DtDynamicTile tile)
|
||||||
{
|
{
|
||||||
tile.RemoveCollider(colliderId);
|
tile.RemoveCollider(colliderId);
|
||||||
}
|
}
|
|
@ -28,14 +28,14 @@ namespace DotRecast.Detour.Dynamic
|
||||||
*
|
*
|
||||||
* "A Fast Voxel Traversal Algorithm for Ray Tracing" by John Amanatides and Andrew Woo
|
* "A Fast Voxel Traversal Algorithm for Ray Tracing" by John Amanatides and Andrew Woo
|
||||||
*/
|
*/
|
||||||
public class VoxelQuery
|
public class DtVoxelQuery
|
||||||
{
|
{
|
||||||
private readonly RcVec3f origin;
|
private readonly RcVec3f origin;
|
||||||
private readonly float tileWidth;
|
private readonly float tileWidth;
|
||||||
private readonly float tileDepth;
|
private readonly float tileDepth;
|
||||||
private readonly Func<int, int, RcHeightfield> heightfieldProvider;
|
private readonly Func<int, int, RcHeightfield> heightfieldProvider;
|
||||||
|
|
||||||
public VoxelQuery(RcVec3f origin, float tileWidth, float tileDepth, Func<int, int, RcHeightfield> heightfieldProvider)
|
public DtVoxelQuery(RcVec3f origin, float tileWidth, float tileDepth, Func<int, int, RcHeightfield> heightfieldProvider)
|
||||||
{
|
{
|
||||||
this.origin = origin;
|
this.origin = origin;
|
||||||
this.tileWidth = tileWidth;
|
this.tileWidth = tileWidth;
|
|
@ -21,10 +21,10 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic
|
namespace DotRecast.Detour.Dynamic
|
||||||
{
|
{
|
||||||
public interface IUpdateQueueItem
|
public interface IDtDaynmicTileJob
|
||||||
{
|
{
|
||||||
ICollection<DynamicTile> AffectedTiles();
|
ICollection<DtDynamicTile> AffectedTiles();
|
||||||
|
|
||||||
void Process(DynamicTile tile);
|
void Process(DtDynamicTile tile);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,7 +24,7 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic.Io
|
namespace DotRecast.Detour.Dynamic.Io
|
||||||
{
|
{
|
||||||
public class VoxelFile
|
public class DtVoxelFile
|
||||||
{
|
{
|
||||||
public static readonly RcByteOrder PREFERRED_BYTE_ORDER = RcByteOrder.BIG_ENDIAN;
|
public static readonly RcByteOrder PREFERRED_BYTE_ORDER = RcByteOrder.BIG_ENDIAN;
|
||||||
public const int MAGIC = 'V' << 24 | 'O' << 16 | 'X' << 8 | 'L';
|
public const int MAGIC = 'V' << 24 | 'O' << 16 | 'X' << 8 | 'L';
|
||||||
|
@ -55,14 +55,14 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
public int tileSizeZ;
|
public int tileSizeZ;
|
||||||
public RcVec3f rotation = new RcVec3f();
|
public RcVec3f rotation = new RcVec3f();
|
||||||
public float[] bounds = new float[6];
|
public float[] bounds = new float[6];
|
||||||
public readonly List<VoxelTile> tiles = new List<VoxelTile>();
|
public readonly List<DtVoxelTile> tiles = new List<DtVoxelTile>();
|
||||||
|
|
||||||
public void AddTile(VoxelTile tile)
|
public void AddTile(DtVoxelTile tile)
|
||||||
{
|
{
|
||||||
tiles.Add(tile);
|
tiles.Add(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RcConfig GetConfig(VoxelTile tile, RcAreaModification walkbableAreaMod, bool buildMeshDetail)
|
public RcConfig GetConfig(DtVoxelTile tile, RcAreaModification walkbableAreaMod, bool buildMeshDetail)
|
||||||
{
|
{
|
||||||
return new RcConfig(useTiles, tileSizeX, tileSizeZ,
|
return new RcConfig(useTiles, tileSizeX, tileSizeZ,
|
||||||
tile.borderSize,
|
tile.borderSize,
|
||||||
|
@ -77,9 +77,9 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
walkbableAreaMod, buildMeshDetail);
|
walkbableAreaMod, buildMeshDetail);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VoxelFile From(RcConfig config, List<RecastBuilderResult> results)
|
public static DtVoxelFile From(RcConfig config, List<RecastBuilderResult> results)
|
||||||
{
|
{
|
||||||
VoxelFile f = new VoxelFile();
|
DtVoxelFile f = new DtVoxelFile();
|
||||||
f.version = 1;
|
f.version = 1;
|
||||||
f.partition = config.Partition;
|
f.partition = config.Partition;
|
||||||
f.filterLowHangingObstacles = config.FilterLowHangingObstacles;
|
f.filterLowHangingObstacles = config.FilterLowHangingObstacles;
|
||||||
|
@ -108,7 +108,7 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
};
|
};
|
||||||
foreach (RecastBuilderResult r in results)
|
foreach (RecastBuilderResult r in results)
|
||||||
{
|
{
|
||||||
f.tiles.Add(new VoxelTile(r.tileX, r.tileZ, r.GetSolidHeightfield()));
|
f.tiles.Add(new DtVoxelTile(r.tileX, r.tileZ, r.GetSolidHeightfield()));
|
||||||
f.bounds[0] = Math.Min(f.bounds[0], r.GetSolidHeightfield().bmin.x);
|
f.bounds[0] = Math.Min(f.bounds[0], r.GetSolidHeightfield().bmin.x);
|
||||||
f.bounds[1] = Math.Min(f.bounds[1], r.GetSolidHeightfield().bmin.y);
|
f.bounds[1] = Math.Min(f.bounds[1], r.GetSolidHeightfield().bmin.y);
|
||||||
f.bounds[2] = Math.Min(f.bounds[2], r.GetSolidHeightfield().bmin.z);
|
f.bounds[2] = Math.Min(f.bounds[2], r.GetSolidHeightfield().bmin.z);
|
||||||
|
@ -120,11 +120,11 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VoxelFile From(DynamicNavMesh mesh)
|
public static DtVoxelFile From(DtDynamicNavMesh mesh)
|
||||||
{
|
{
|
||||||
VoxelFile f = new VoxelFile();
|
DtVoxelFile f = new DtVoxelFile();
|
||||||
f.version = 1;
|
f.version = 1;
|
||||||
DynamicNavMeshConfig config = mesh.config;
|
DtDynamicNavMeshConfig config = mesh.config;
|
||||||
f.partition = config.partition;
|
f.partition = config.partition;
|
||||||
f.filterLowHangingObstacles = config.filterLowHangingObstacles;
|
f.filterLowHangingObstacles = config.filterLowHangingObstacles;
|
||||||
f.filterLedgeSpans = config.filterLedgeSpans;
|
f.filterLedgeSpans = config.filterLedgeSpans;
|
||||||
|
@ -150,10 +150,10 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity,
|
float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity,
|
||||||
float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity
|
float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity
|
||||||
};
|
};
|
||||||
foreach (VoxelTile vt in mesh.VoxelTiles())
|
foreach (DtVoxelTile vt in mesh.VoxelTiles())
|
||||||
{
|
{
|
||||||
RcHeightfield heightfield = vt.Heightfield();
|
RcHeightfield heightfield = vt.Heightfield();
|
||||||
f.tiles.Add(new VoxelTile(vt.tileX, vt.tileZ, heightfield));
|
f.tiles.Add(new DtVoxelTile(vt.tileX, vt.tileZ, heightfield));
|
||||||
f.bounds[0] = Math.Min(f.bounds[0], vt.boundsMin.x);
|
f.bounds[0] = Math.Min(f.bounds[0], vt.boundsMin.x);
|
||||||
f.bounds[1] = Math.Min(f.bounds[1], vt.boundsMin.y);
|
f.bounds[1] = Math.Min(f.bounds[1], vt.boundsMin.y);
|
||||||
f.bounds[2] = Math.Min(f.bounds[2], vt.boundsMin.z);
|
f.bounds[2] = Math.Min(f.bounds[2], vt.boundsMin.z);
|
|
@ -23,24 +23,24 @@ using DotRecast.Detour.Io;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic.Io
|
namespace DotRecast.Detour.Dynamic.Io
|
||||||
{
|
{
|
||||||
public class VoxelFileReader
|
public class DtVoxelFileReader
|
||||||
{
|
{
|
||||||
private readonly IRcCompressor _compressor;
|
private readonly IRcCompressor _compressor;
|
||||||
|
|
||||||
public VoxelFileReader(IRcCompressor compressor)
|
public DtVoxelFileReader(IRcCompressor compressor)
|
||||||
{
|
{
|
||||||
_compressor = compressor;
|
_compressor = compressor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VoxelFile Read(BinaryReader stream)
|
public DtVoxelFile Read(BinaryReader stream)
|
||||||
{
|
{
|
||||||
RcByteBuffer buf = IOUtils.ToByteBuffer(stream);
|
RcByteBuffer buf = IOUtils.ToByteBuffer(stream);
|
||||||
VoxelFile file = new VoxelFile();
|
DtVoxelFile file = new DtVoxelFile();
|
||||||
int magic = buf.GetInt();
|
int magic = buf.GetInt();
|
||||||
if (magic != VoxelFile.MAGIC)
|
if (magic != DtVoxelFile.MAGIC)
|
||||||
{
|
{
|
||||||
magic = IOUtils.SwapEndianness(magic);
|
magic = IOUtils.SwapEndianness(magic);
|
||||||
if (magic != VoxelFile.MAGIC)
|
if (magic != DtVoxelFile.MAGIC)
|
||||||
{
|
{
|
||||||
throw new IOException("Invalid magic");
|
throw new IOException("Invalid magic");
|
||||||
}
|
}
|
||||||
|
@ -49,8 +49,8 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
}
|
}
|
||||||
|
|
||||||
file.version = buf.GetInt();
|
file.version = buf.GetInt();
|
||||||
bool isExportedFromAstar = (file.version & VoxelFile.VERSION_EXPORTER_MASK) == 0;
|
bool isExportedFromAstar = (file.version & DtVoxelFile.VERSION_EXPORTER_MASK) == 0;
|
||||||
bool compression = (file.version & VoxelFile.VERSION_COMPRESSION_MASK) == VoxelFile.VERSION_COMPRESSION_LZ4;
|
bool compression = (file.version & DtVoxelFile.VERSION_COMPRESSION_MASK) == DtVoxelFile.VERSION_COMPRESSION_LZ4;
|
||||||
file.walkableRadius = buf.GetFloat();
|
file.walkableRadius = buf.GetFloat();
|
||||||
file.walkableHeight = buf.GetFloat();
|
file.walkableHeight = buf.GetFloat();
|
||||||
file.walkableClimb = buf.GetFloat();
|
file.walkableClimb = buf.GetFloat();
|
||||||
|
@ -138,7 +138,7 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
|
|
||||||
RcByteBuffer data = new RcByteBuffer(bytes);
|
RcByteBuffer data = new RcByteBuffer(bytes);
|
||||||
data.Order(buf.Order());
|
data.Order(buf.Order());
|
||||||
file.AddTile(new VoxelTile(tileX, tileZ, width, depth, boundsMin, boundsMax, cellSize, cellHeight, borderSize, data));
|
file.AddTile(new DtVoxelTile(tileX, tileZ, width, depth, boundsMin, boundsMax, cellSize, cellHeight, borderSize, data));
|
||||||
buf.Position(position + voxelSize);
|
buf.Position(position + voxelSize);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,24 +23,24 @@ using DotRecast.Detour.Io;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic.Io
|
namespace DotRecast.Detour.Dynamic.Io
|
||||||
{
|
{
|
||||||
public class VoxelFileWriter : DtWriter
|
public class DtVoxelFileWriter : DtWriter
|
||||||
{
|
{
|
||||||
private readonly IRcCompressor _compressor;
|
private readonly IRcCompressor _compressor;
|
||||||
|
|
||||||
public VoxelFileWriter(IRcCompressor compressor)
|
public DtVoxelFileWriter(IRcCompressor compressor)
|
||||||
{
|
{
|
||||||
_compressor = compressor;
|
_compressor = compressor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(BinaryWriter stream, VoxelFile f, bool compression)
|
public void Write(BinaryWriter stream, DtVoxelFile f, bool compression)
|
||||||
{
|
{
|
||||||
Write(stream, f, VoxelFile.PREFERRED_BYTE_ORDER, compression);
|
Write(stream, f, DtVoxelFile.PREFERRED_BYTE_ORDER, compression);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write(BinaryWriter stream, VoxelFile f, RcByteOrder byteOrder, bool compression)
|
public void Write(BinaryWriter stream, DtVoxelFile f, RcByteOrder byteOrder, bool compression)
|
||||||
{
|
{
|
||||||
Write(stream, VoxelFile.MAGIC, byteOrder);
|
Write(stream, DtVoxelFile.MAGIC, byteOrder);
|
||||||
Write(stream, VoxelFile.VERSION_EXPORTER_RECAST4J | (compression ? VoxelFile.VERSION_COMPRESSION_LZ4 : 0), byteOrder);
|
Write(stream, DtVoxelFile.VERSION_EXPORTER_RECAST4J | (compression ? DtVoxelFile.VERSION_COMPRESSION_LZ4 : 0), byteOrder);
|
||||||
Write(stream, f.walkableRadius, byteOrder);
|
Write(stream, f.walkableRadius, byteOrder);
|
||||||
Write(stream, f.walkableHeight, byteOrder);
|
Write(stream, f.walkableHeight, byteOrder);
|
||||||
Write(stream, f.walkableClimb, byteOrder);
|
Write(stream, f.walkableClimb, byteOrder);
|
||||||
|
@ -67,13 +67,13 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
Write(stream, f.bounds[4], byteOrder);
|
Write(stream, f.bounds[4], byteOrder);
|
||||||
Write(stream, f.bounds[5], byteOrder);
|
Write(stream, f.bounds[5], byteOrder);
|
||||||
Write(stream, f.tiles.Count, byteOrder);
|
Write(stream, f.tiles.Count, byteOrder);
|
||||||
foreach (VoxelTile t in f.tiles)
|
foreach (DtVoxelTile t in f.tiles)
|
||||||
{
|
{
|
||||||
WriteTile(stream, t, byteOrder, compression);
|
WriteTile(stream, t, byteOrder, compression);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteTile(BinaryWriter stream, VoxelTile tile, RcByteOrder byteOrder, bool compression)
|
public void WriteTile(BinaryWriter stream, DtVoxelTile tile, RcByteOrder byteOrder, bool compression)
|
||||||
{
|
{
|
||||||
Write(stream, tile.tileX, byteOrder);
|
Write(stream, tile.tileX, byteOrder);
|
||||||
Write(stream, tile.tileZ, byteOrder);
|
Write(stream, tile.tileZ, byteOrder);
|
|
@ -22,7 +22,7 @@ using DotRecast.Recast;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic.Io
|
namespace DotRecast.Detour.Dynamic.Io
|
||||||
{
|
{
|
||||||
public class VoxelTile
|
public class DtVoxelTile
|
||||||
{
|
{
|
||||||
private const int SERIALIZED_SPAN_COUNT_BYTES = 2;
|
private const int SERIALIZED_SPAN_COUNT_BYTES = 2;
|
||||||
private const int SERIALIZED_SPAN_BYTES = 12;
|
private const int SERIALIZED_SPAN_BYTES = 12;
|
||||||
|
@ -37,7 +37,7 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
public float cellHeight;
|
public float cellHeight;
|
||||||
public readonly byte[] spanData;
|
public readonly byte[] spanData;
|
||||||
|
|
||||||
public VoxelTile(int tileX, int tileZ, int width, int depth, RcVec3f boundsMin, RcVec3f boundsMax, float cellSize,
|
public DtVoxelTile(int tileX, int tileZ, int width, int depth, RcVec3f boundsMin, RcVec3f boundsMax, float cellSize,
|
||||||
float cellHeight, int borderSize, RcByteBuffer buffer)
|
float cellHeight, int borderSize, RcByteBuffer buffer)
|
||||||
{
|
{
|
||||||
this.tileX = tileX;
|
this.tileX = tileX;
|
||||||
|
@ -49,10 +49,10 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
this.cellSize = cellSize;
|
this.cellSize = cellSize;
|
||||||
this.cellHeight = cellHeight;
|
this.cellHeight = cellHeight;
|
||||||
this.borderSize = borderSize;
|
this.borderSize = borderSize;
|
||||||
spanData = ToByteArray(buffer, width, depth, VoxelFile.PREFERRED_BYTE_ORDER);
|
spanData = ToByteArray(buffer, width, depth, DtVoxelFile.PREFERRED_BYTE_ORDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public VoxelTile(int tileX, int tileZ, RcHeightfield heightfield)
|
public DtVoxelTile(int tileX, int tileZ, RcHeightfield heightfield)
|
||||||
{
|
{
|
||||||
this.tileX = tileX;
|
this.tileX = tileX;
|
||||||
this.tileZ = tileZ;
|
this.tileZ = tileZ;
|
||||||
|
@ -63,12 +63,12 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
cellSize = heightfield.cs;
|
cellSize = heightfield.cs;
|
||||||
cellHeight = heightfield.ch;
|
cellHeight = heightfield.ch;
|
||||||
borderSize = heightfield.borderSize;
|
borderSize = heightfield.borderSize;
|
||||||
spanData = SerializeSpans(heightfield, VoxelFile.PREFERRED_BYTE_ORDER);
|
spanData = SerializeSpans(heightfield, DtVoxelFile.PREFERRED_BYTE_ORDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RcHeightfield Heightfield()
|
public RcHeightfield Heightfield()
|
||||||
{
|
{
|
||||||
return VoxelFile.PREFERRED_BYTE_ORDER == RcByteOrder.BIG_ENDIAN ? HeightfieldBE() : HeightfieldLE();
|
return DtVoxelFile.PREFERRED_BYTE_ORDER == RcByteOrder.BIG_ENDIAN ? HeightfieldBE() : HeightfieldLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
private RcHeightfield HeightfieldBE()
|
private RcHeightfield HeightfieldBE()
|
||||||
|
@ -80,16 +80,16 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
for (int x = 0; x < width; x++)
|
for (int x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
RcSpan prev = null;
|
RcSpan prev = null;
|
||||||
int spanCount = ByteUtils.GetShortBE(spanData, position);
|
int spanCount = RcByteUtils.GetShortBE(spanData, position);
|
||||||
position += 2;
|
position += 2;
|
||||||
for (int s = 0; s < spanCount; s++)
|
for (int s = 0; s < spanCount; s++)
|
||||||
{
|
{
|
||||||
RcSpan span = new RcSpan();
|
RcSpan span = new RcSpan();
|
||||||
span.smin = ByteUtils.GetIntBE(spanData, position);
|
span.smin = RcByteUtils.GetIntBE(spanData, position);
|
||||||
position += 4;
|
position += 4;
|
||||||
span.smax = ByteUtils.GetIntBE(spanData, position);
|
span.smax = RcByteUtils.GetIntBE(spanData, position);
|
||||||
position += 4;
|
position += 4;
|
||||||
span.area = ByteUtils.GetIntBE(spanData, position);
|
span.area = RcByteUtils.GetIntBE(spanData, position);
|
||||||
position += 4;
|
position += 4;
|
||||||
if (prev == null)
|
if (prev == null)
|
||||||
{
|
{
|
||||||
|
@ -117,16 +117,16 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
for (int x = 0; x < width; x++)
|
for (int x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
RcSpan prev = null;
|
RcSpan prev = null;
|
||||||
int spanCount = ByteUtils.GetShortLE(spanData, position);
|
int spanCount = RcByteUtils.GetShortLE(spanData, position);
|
||||||
position += 2;
|
position += 2;
|
||||||
for (int s = 0; s < spanCount; s++)
|
for (int s = 0; s < spanCount; s++)
|
||||||
{
|
{
|
||||||
RcSpan span = new RcSpan();
|
RcSpan span = new RcSpan();
|
||||||
span.smin = ByteUtils.GetIntLE(spanData, position);
|
span.smin = RcByteUtils.GetIntLE(spanData, position);
|
||||||
position += 4;
|
position += 4;
|
||||||
span.smax = ByteUtils.GetIntLE(spanData, position);
|
span.smax = RcByteUtils.GetIntLE(spanData, position);
|
||||||
position += 4;
|
position += 4;
|
||||||
span.area = ByteUtils.GetIntLE(spanData, position);
|
span.area = RcByteUtils.GetIntLE(spanData, position);
|
||||||
position += 4;
|
position += 4;
|
||||||
if (prev == null)
|
if (prev == null)
|
||||||
{
|
{
|
||||||
|
@ -169,13 +169,13 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
{
|
{
|
||||||
for (int x = 0; x < heightfield.width; x++)
|
for (int x = 0; x < heightfield.width; x++)
|
||||||
{
|
{
|
||||||
position = ByteUtils.PutShort(counts[pz + x], data, position, order);
|
position = RcByteUtils.PutShort(counts[pz + x], data, position, order);
|
||||||
RcSpan span = heightfield.spans[pz + x];
|
RcSpan span = heightfield.spans[pz + x];
|
||||||
while (span != null)
|
while (span != null)
|
||||||
{
|
{
|
||||||
position = ByteUtils.PutInt(span.smin, data, position, order);
|
position = RcByteUtils.PutInt(span.smin, data, position, order);
|
||||||
position = ByteUtils.PutInt(span.smax, data, position, order);
|
position = RcByteUtils.PutInt(span.smax, data, position, order);
|
||||||
position = ByteUtils.PutInt(span.area, data, position, order);
|
position = RcByteUtils.PutInt(span.area, data, position, order);
|
||||||
span = span.next;
|
span = span.next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,15 +199,15 @@ namespace DotRecast.Detour.Dynamic.Io
|
||||||
for (int i = 0; i < l; i++)
|
for (int i = 0; i < l; i++)
|
||||||
{
|
{
|
||||||
int count = buf.GetShort();
|
int count = buf.GetShort();
|
||||||
ByteUtils.PutShort(count, data, position, order);
|
RcByteUtils.PutShort(count, data, position, order);
|
||||||
position += 2;
|
position += 2;
|
||||||
for (int j = 0; j < count; j++)
|
for (int j = 0; j < count; j++)
|
||||||
{
|
{
|
||||||
ByteUtils.PutInt(buf.GetInt(), data, position, order);
|
RcByteUtils.PutInt(buf.GetInt(), data, position, order);
|
||||||
position += 4;
|
position += 4;
|
||||||
ByteUtils.PutInt(buf.GetInt(), data, position, order);
|
RcByteUtils.PutInt(buf.GetInt(), data, position, order);
|
||||||
position += 4;
|
position += 4;
|
||||||
ByteUtils.PutInt(buf.GetInt(), data, position, order);
|
RcByteUtils.PutInt(buf.GetInt(), data, position, order);
|
||||||
position += 4;
|
position += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Recast;
|
using DotRecast.Recast;
|
||||||
using static DotRecast.Core.RcMath;
|
|
||||||
|
|
||||||
namespace DotRecast.Detour.Extras.Jumplink
|
namespace DotRecast.Detour.Extras.Jumplink
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class DtVoxelTileLZ4DemoCompressor : IRcCompressor
|
||||||
|
|
||||||
public byte[] Decompress(byte[] data)
|
public byte[] Decompress(byte[] data)
|
||||||
{
|
{
|
||||||
int compressedSize = ByteUtils.GetIntBE(data, 0);
|
int compressedSize = RcByteUtils.GetIntBE(data, 0);
|
||||||
return LZ4Pickler.Unpickle(data.AsSpan(4, compressedSize));
|
return LZ4Pickler.Unpickle(data.AsSpan(4, compressedSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ public class DtVoxelTileLZ4DemoCompressor : IRcCompressor
|
||||||
{
|
{
|
||||||
byte[] compressed = LZ4Pickler.Pickle(data, LZ4Level.L12_MAX);
|
byte[] compressed = LZ4Pickler.Pickle(data, LZ4Level.L12_MAX);
|
||||||
byte[] result = new byte[4 + compressed.Length];
|
byte[] result = new byte[4 + compressed.Length];
|
||||||
ByteUtils.PutInt(compressed.Length, result, 0, RcByteOrder.BIG_ENDIAN);
|
RcByteUtils.PutInt(compressed.Length, result, 0, RcByteOrder.BIG_ENDIAN);
|
||||||
Array.Copy(compressed, 0, result, 4, compressed.Length);
|
Array.Copy(compressed, 0, result, 4, compressed.Length);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -461,7 +461,7 @@ public class DynamicUpdateSampleTool : ISampleTool
|
||||||
_sample.Update(null, dynaMesh.RecastResults(), dynaMesh.NavMesh());
|
_sample.Update(null, dynaMesh.RecastResults(), dynaMesh.NavMesh());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateTo(DynamicNavMeshConfig config)
|
private void UpdateTo(DtDynamicNavMeshConfig config)
|
||||||
{
|
{
|
||||||
config.partition = partitioning;
|
config.partition = partitioning;
|
||||||
config.walkableHeight = walkableHeight;
|
config.walkableHeight = walkableHeight;
|
||||||
|
@ -481,7 +481,7 @@ public class DynamicUpdateSampleTool : ISampleTool
|
||||||
config.detailSampleMaxError = detailSampleMaxError;
|
config.detailSampleMaxError = detailSampleMaxError;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateFrom(DynamicNavMeshConfig config)
|
private void UpdateFrom(DtDynamicNavMeshConfig config)
|
||||||
{
|
{
|
||||||
cellSize = config.cellSize;
|
cellSize = config.cellSize;
|
||||||
partitioning = config.partition;
|
partitioning = config.partition;
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace DotRecast.Recast.Toolset.Gizmos
|
||||||
public readonly RcVec3f[] halfEdges;
|
public readonly RcVec3f[] halfEdges;
|
||||||
|
|
||||||
public RcBoxGizmo(RcVec3f center, RcVec3f extent, RcVec3f forward, RcVec3f up) :
|
public RcBoxGizmo(RcVec3f center, RcVec3f extent, RcVec3f forward, RcVec3f up) :
|
||||||
this(center, BoxCollider.GetHalfEdges(up, forward, extent))
|
this(center, DtBoxCollider.GetHalfEdges(up, forward, extent))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@ namespace DotRecast.Recast.Toolset.Gizmos
|
||||||
public class RcGizmo
|
public class RcGizmo
|
||||||
{
|
{
|
||||||
public readonly IRcGizmoMeshFilter Gizmo;
|
public readonly IRcGizmoMeshFilter Gizmo;
|
||||||
public readonly ICollider Collider;
|
public readonly IDtCollider Collider;
|
||||||
|
|
||||||
public RcGizmo(ICollider collider, IRcGizmoMeshFilter gizmo)
|
public RcGizmo(IDtCollider collider, IRcGizmoMeshFilter gizmo)
|
||||||
{
|
{
|
||||||
Collider = collider;
|
Collider = collider;
|
||||||
Gizmo = gizmo;
|
Gizmo = gizmo;
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
{
|
{
|
||||||
public class RcDynamicUpdateTool : IRcToolable
|
public class RcDynamicUpdateTool : IRcToolable
|
||||||
{
|
{
|
||||||
private DynamicNavMesh dynaMesh;
|
private DtDynamicNavMesh dynaMesh;
|
||||||
private readonly Dictionary<long, RcGizmo> colliderGizmos;
|
private readonly Dictionary<long, RcGizmo> colliderGizmos;
|
||||||
|
|
||||||
private readonly Random random;
|
private readonly Random random;
|
||||||
|
@ -41,7 +41,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
return "Dynamic Updates";
|
return "Dynamic Updates";
|
||||||
}
|
}
|
||||||
|
|
||||||
public DynamicNavMesh GetDynamicNavMesh()
|
public DtDynamicNavMesh GetDynamicNavMesh()
|
||||||
{
|
{
|
||||||
return dynaMesh;
|
return dynaMesh;
|
||||||
}
|
}
|
||||||
|
@ -140,14 +140,14 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
return colliderWithGizmo;
|
return colliderWithGizmo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DynamicNavMesh Load(string filename, IRcCompressor compressor)
|
public DtDynamicNavMesh Load(string filename, IRcCompressor compressor)
|
||||||
{
|
{
|
||||||
using var fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
|
using var fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
|
||||||
using var br = new BinaryReader(fs);
|
using var br = new BinaryReader(fs);
|
||||||
VoxelFileReader reader = new VoxelFileReader(compressor);
|
DtVoxelFileReader reader = new DtVoxelFileReader(compressor);
|
||||||
VoxelFile voxelFile = reader.Read(br);
|
DtVoxelFile voxelFile = reader.Read(br);
|
||||||
|
|
||||||
dynaMesh = new DynamicNavMesh(voxelFile);
|
dynaMesh = new DtDynamicNavMesh(voxelFile);
|
||||||
dynaMesh.config.keepIntermediateResults = true;
|
dynaMesh.config.keepIntermediateResults = true;
|
||||||
|
|
||||||
colliderGizmos.Clear();
|
colliderGizmos.Clear();
|
||||||
|
@ -157,10 +157,10 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
|
|
||||||
public void Save(string filename, bool compression, IRcCompressor compressor)
|
public void Save(string filename, bool compression, IRcCompressor compressor)
|
||||||
{
|
{
|
||||||
VoxelFile voxelFile = VoxelFile.From(dynaMesh);
|
DtVoxelFile voxelFile = DtVoxelFile.From(dynaMesh);
|
||||||
using var fs = new FileStream(filename, FileMode.CreateNew, FileAccess.Write);
|
using var fs = new FileStream(filename, FileMode.CreateNew, FileAccess.Write);
|
||||||
using var bw = new BinaryWriter(fs);
|
using var bw = new BinaryWriter(fs);
|
||||||
VoxelFileWriter writer = new VoxelFileWriter(compressor);
|
DtVoxelFileWriter writer = new DtVoxelFileWriter(compressor);
|
||||||
writer.Write(bw, voxelFile, compression);
|
writer.Write(bw, voxelFile, compression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
public RcGizmo SphereCollider(RcVec3f p, float walkableClimb)
|
public RcGizmo SphereCollider(RcVec3f p, float walkableClimb)
|
||||||
{
|
{
|
||||||
float radius = 1 + (float)random.NextDouble() * 10;
|
float radius = 1 + (float)random.NextDouble() * 10;
|
||||||
var collider = new SphereCollider(p, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, walkableClimb);
|
var collider = new DtSphereCollider(p, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, walkableClimb);
|
||||||
var gizmo = GizmoFactory.Sphere(p, radius);
|
var gizmo = GizmoFactory.Sphere(p, radius);
|
||||||
|
|
||||||
return new RcGizmo(collider, gizmo);
|
return new RcGizmo(collider, gizmo);
|
||||||
|
@ -189,7 +189,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
a.z *= len;
|
a.z *= len;
|
||||||
RcVec3f start = RcVec3f.Of(p.x, p.y, p.z);
|
RcVec3f start = RcVec3f.Of(p.x, p.y, p.z);
|
||||||
RcVec3f end = RcVec3f.Of(p.x + a.x, p.y + a.y, p.z + a.z);
|
RcVec3f end = RcVec3f.Of(p.x + a.x, p.y + a.y, p.z + a.z);
|
||||||
var collider = new CapsuleCollider(start, end, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, walkableClimb);
|
var collider = new DtCapsuleCollider(start, end, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, walkableClimb);
|
||||||
var gizmo = GizmoFactory.Capsule(start, end, radius);
|
var gizmo = GizmoFactory.Capsule(start, end, radius);
|
||||||
return new RcGizmo(collider, gizmo);
|
return new RcGizmo(collider, gizmo);
|
||||||
}
|
}
|
||||||
|
@ -203,8 +203,8 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
);
|
);
|
||||||
RcVec3f forward = RcVec3f.Of((1f - 2 * (float)random.NextDouble()), 0, (1f - 2 * (float)random.NextDouble()));
|
RcVec3f forward = RcVec3f.Of((1f - 2 * (float)random.NextDouble()), 0, (1f - 2 * (float)random.NextDouble()));
|
||||||
RcVec3f up = RcVec3f.Of((1f - 2 * (float)random.NextDouble()), 0.01f + (float)random.NextDouble(), (1f - 2 * (float)random.NextDouble()));
|
RcVec3f up = RcVec3f.Of((1f - 2 * (float)random.NextDouble()), 0.01f + (float)random.NextDouble(), (1f - 2 * (float)random.NextDouble()));
|
||||||
RcVec3f[] halfEdges = Detour.Dynamic.Colliders.BoxCollider.GetHalfEdges(up, forward, extent);
|
RcVec3f[] halfEdges = Detour.Dynamic.Colliders.DtBoxCollider.GetHalfEdges(up, forward, extent);
|
||||||
var collider = new BoxCollider(p, halfEdges, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, walkableClimb);
|
var collider = new DtBoxCollider(p, halfEdges, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, walkableClimb);
|
||||||
var gizmo = GizmoFactory.Box(p, halfEdges);
|
var gizmo = GizmoFactory.Box(p, halfEdges);
|
||||||
return new RcGizmo(collider, gizmo);
|
return new RcGizmo(collider, gizmo);
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
a[2] *= len;
|
a[2] *= len;
|
||||||
RcVec3f start = RcVec3f.Of(p.x, p.y, p.z);
|
RcVec3f start = RcVec3f.Of(p.x, p.y, p.z);
|
||||||
RcVec3f end = RcVec3f.Of(p.x + a.x, p.y + a.y, p.z + a.z);
|
RcVec3f end = RcVec3f.Of(p.x + a.x, p.y + a.y, p.z + a.z);
|
||||||
var collider = new CylinderCollider(start, end, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, walkableClimb);
|
var collider = new DtCylinderCollider(start, end, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, walkableClimb);
|
||||||
var gizmo = GizmoFactory.Cylinder(start, end, radius);
|
var gizmo = GizmoFactory.Cylinder(start, end, radius);
|
||||||
|
|
||||||
return new RcGizmo(collider, gizmo);
|
return new RcGizmo(collider, gizmo);
|
||||||
|
@ -234,14 +234,14 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
RcVec3f forward = RcVec3f.Of((1f - 2 * (float)random.NextDouble()), 0, (1f - 2 * (float)random.NextDouble()));
|
RcVec3f forward = RcVec3f.Of((1f - 2 * (float)random.NextDouble()), 0, (1f - 2 * (float)random.NextDouble()));
|
||||||
forward.Normalize();
|
forward.Normalize();
|
||||||
RcVec3f side = RcVec3f.Cross(forward, baseUp);
|
RcVec3f side = RcVec3f.Cross(forward, baseUp);
|
||||||
BoxCollider @base = new BoxCollider(baseCenter, Detour.Dynamic.Colliders.BoxCollider.GetHalfEdges(baseUp, forward, baseExtent),
|
DtBoxCollider @base = new DtBoxCollider(baseCenter, Detour.Dynamic.Colliders.DtBoxCollider.GetHalfEdges(baseUp, forward, baseExtent),
|
||||||
SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, walkableClimb);
|
SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, walkableClimb);
|
||||||
var roofUp = RcVec3f.Zero;
|
var roofUp = RcVec3f.Zero;
|
||||||
RcVec3f roofExtent = RcVec3f.Of(4.5f, 4.5f, 8f);
|
RcVec3f roofExtent = RcVec3f.Of(4.5f, 4.5f, 8f);
|
||||||
var rx = RcMatrix4x4f.CreateFromRotate(45, forward.x, forward.y, forward.z);
|
var rx = RcMatrix4x4f.CreateFromRotate(45, forward.x, forward.y, forward.z);
|
||||||
roofUp = MulMatrixVector(ref roofUp, rx, baseUp);
|
roofUp = MulMatrixVector(ref roofUp, rx, baseUp);
|
||||||
RcVec3f roofCenter = RcVec3f.Of(p.x, p.y + 6, p.z);
|
RcVec3f roofCenter = RcVec3f.Of(p.x, p.y + 6, p.z);
|
||||||
BoxCollider roof = new BoxCollider(roofCenter, Detour.Dynamic.Colliders.BoxCollider.GetHalfEdges(roofUp, forward, roofExtent),
|
DtBoxCollider roof = new DtBoxCollider(roofCenter, Detour.Dynamic.Colliders.DtBoxCollider.GetHalfEdges(roofUp, forward, roofExtent),
|
||||||
SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, walkableClimb);
|
SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, walkableClimb);
|
||||||
RcVec3f trunkStart = RcVec3f.Of(
|
RcVec3f trunkStart = RcVec3f.Of(
|
||||||
baseCenter.x - forward.x * 15 + side.x * 6,
|
baseCenter.x - forward.x * 15 + side.x * 6,
|
||||||
|
@ -249,17 +249,17 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
baseCenter.z - forward.z * 15 + side.z * 6
|
baseCenter.z - forward.z * 15 + side.z * 6
|
||||||
);
|
);
|
||||||
RcVec3f trunkEnd = RcVec3f.Of(trunkStart.x, trunkStart.y + 10, trunkStart.z);
|
RcVec3f trunkEnd = RcVec3f.Of(trunkStart.x, trunkStart.y + 10, trunkStart.z);
|
||||||
CapsuleCollider trunk = new CapsuleCollider(trunkStart, trunkEnd, 0.5f, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD,
|
DtCapsuleCollider trunk = new DtCapsuleCollider(trunkStart, trunkEnd, 0.5f, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD,
|
||||||
walkableClimb);
|
walkableClimb);
|
||||||
RcVec3f crownCenter = RcVec3f.Of(
|
RcVec3f crownCenter = RcVec3f.Of(
|
||||||
baseCenter.x - forward.x * 15 + side.x * 6, p.y + 10,
|
baseCenter.x - forward.x * 15 + side.x * 6, p.y + 10,
|
||||||
baseCenter.z - forward.z * 15 + side.z * 6
|
baseCenter.z - forward.z * 15 + side.z * 6
|
||||||
);
|
);
|
||||||
SphereCollider crown = new SphereCollider(crownCenter, 4f, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_GRASS,
|
DtSphereCollider crown = new DtSphereCollider(crownCenter, 4f, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_GRASS,
|
||||||
walkableClimb);
|
walkableClimb);
|
||||||
CompositeCollider collider = new CompositeCollider(@base, roof, trunk, crown);
|
DtCompositeCollider collider = new DtCompositeCollider(@base, roof, trunk, crown);
|
||||||
IRcGizmoMeshFilter baseGizmo = GizmoFactory.Box(baseCenter, Detour.Dynamic.Colliders.BoxCollider.GetHalfEdges(baseUp, forward, baseExtent));
|
IRcGizmoMeshFilter baseGizmo = GizmoFactory.Box(baseCenter, Detour.Dynamic.Colliders.DtBoxCollider.GetHalfEdges(baseUp, forward, baseExtent));
|
||||||
IRcGizmoMeshFilter roofGizmo = GizmoFactory.Box(roofCenter, Detour.Dynamic.Colliders.BoxCollider.GetHalfEdges(roofUp, forward, roofExtent));
|
IRcGizmoMeshFilter roofGizmo = GizmoFactory.Box(roofCenter, Detour.Dynamic.Colliders.DtBoxCollider.GetHalfEdges(roofUp, forward, roofExtent));
|
||||||
IRcGizmoMeshFilter trunkGizmo = GizmoFactory.Capsule(trunkStart, trunkEnd, 0.5f);
|
IRcGizmoMeshFilter trunkGizmo = GizmoFactory.Capsule(trunkStart, trunkEnd, 0.5f);
|
||||||
IRcGizmoMeshFilter crownGizmo = GizmoFactory.Sphere(crownCenter, 4f);
|
IRcGizmoMeshFilter crownGizmo = GizmoFactory.Sphere(crownCenter, 4f);
|
||||||
IRcGizmoMeshFilter gizmo = GizmoFactory.Composite(baseGizmo, roofGizmo, trunkGizmo, crownGizmo);
|
IRcGizmoMeshFilter gizmo = GizmoFactory.Composite(baseGizmo, roofGizmo, trunkGizmo, crownGizmo);
|
||||||
|
@ -279,7 +279,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
public RcGizmo ConvexTrimesh(RcVec3f p, float walkableClimb)
|
public RcGizmo ConvexTrimesh(RcVec3f p, float walkableClimb)
|
||||||
{
|
{
|
||||||
float[] verts = TransformVertices(p, convexGeom, 360);
|
float[] verts = TransformVertices(p, convexGeom, 360);
|
||||||
var collider = new ConvexTrimeshCollider(verts, convexGeom.faces,
|
var collider = new DtConvexTrimeshCollider(verts, convexGeom.faces,
|
||||||
SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, walkableClimb * 10);
|
SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, walkableClimb * 10);
|
||||||
var gizmo = GizmoFactory.Trimesh(verts, convexGeom.faces);
|
var gizmo = GizmoFactory.Trimesh(verts, convexGeom.faces);
|
||||||
return new RcGizmo(collider, gizmo);
|
return new RcGizmo(collider, gizmo);
|
||||||
|
@ -288,7 +288,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
private RcGizmo TrimeshCollider(RcVec3f p, DemoInputGeomProvider geom, float walkableClimb)
|
private RcGizmo TrimeshCollider(RcVec3f p, DemoInputGeomProvider geom, float walkableClimb)
|
||||||
{
|
{
|
||||||
float[] verts = TransformVertices(p, geom, 0);
|
float[] verts = TransformVertices(p, geom, 0);
|
||||||
var collider = new TrimeshCollider(verts, geom.faces, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD,
|
var collider = new DtTrimeshCollider(verts, geom.faces, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD,
|
||||||
walkableClimb * 10);
|
walkableClimb * 10);
|
||||||
var gizmo = GizmoFactory.Trimesh(verts, geom.faces);
|
var gizmo = GizmoFactory.Trimesh(verts, geom.faces);
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,10 @@ public class DynamicNavMeshTest
|
||||||
using var br = new BinaryReader(ms);
|
using var br = new BinaryReader(ms);
|
||||||
|
|
||||||
// load voxels from file
|
// load voxels from file
|
||||||
VoxelFileReader reader = new VoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared);
|
DtVoxelFileReader reader = new DtVoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared);
|
||||||
VoxelFile f = reader.Read(br);
|
DtVoxelFile f = reader.Read(br);
|
||||||
// create dynamic navmesh
|
// create dynamic navmesh
|
||||||
DynamicNavMesh mesh = new DynamicNavMesh(f);
|
DtDynamicNavMesh mesh = new DtDynamicNavMesh(f);
|
||||||
// build navmesh asynchronously using multiple threads
|
// build navmesh asynchronously using multiple threads
|
||||||
Task<bool> future = mesh.Build(Task.Factory);
|
Task<bool> future = mesh.Build(Task.Factory);
|
||||||
// wait for build to complete
|
// wait for build to complete
|
||||||
|
@ -49,7 +49,7 @@ public class DynamicNavMeshTest
|
||||||
Assert.That(path.Count, Is.EqualTo(16));
|
Assert.That(path.Count, Is.EqualTo(16));
|
||||||
|
|
||||||
// place obstacle
|
// place obstacle
|
||||||
ICollider colldier = new SphereCollider(SPHERE_POS, 20, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_GROUND, 0.1f);
|
IDtCollider colldier = new DtSphereCollider(SPHERE_POS, 20, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_GROUND, 0.1f);
|
||||||
long colliderId = mesh.AddCollider(colldier);
|
long colliderId = mesh.AddCollider(colldier);
|
||||||
|
|
||||||
// update navmesh asynchronously
|
// update navmesh asynchronously
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace DotRecast.Detour.Dynamic.Test.Io
|
||||||
|
|
||||||
public byte[] Decompress(byte[] data)
|
public byte[] Decompress(byte[] data)
|
||||||
{
|
{
|
||||||
int compressedSize = ByteUtils.GetIntBE(data, 0);
|
int compressedSize = RcByteUtils.GetIntBE(data, 0);
|
||||||
return LZ4Pickler.Unpickle(data.AsSpan(4, compressedSize));
|
return LZ4Pickler.Unpickle(data.AsSpan(4, compressedSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ namespace DotRecast.Detour.Dynamic.Test.Io
|
||||||
{
|
{
|
||||||
byte[] compressed = LZ4Pickler.Pickle(data, LZ4Level.L12_MAX);
|
byte[] compressed = LZ4Pickler.Pickle(data, LZ4Level.L12_MAX);
|
||||||
byte[] result = new byte[4 + compressed.Length];
|
byte[] result = new byte[4 + compressed.Length];
|
||||||
ByteUtils.PutInt(compressed.Length, result, 0, RcByteOrder.BIG_ENDIAN);
|
RcByteUtils.PutInt(compressed.Length, result, 0, RcByteOrder.BIG_ENDIAN);
|
||||||
Array.Copy(compressed, 0, result, 4, compressed.Length);
|
Array.Copy(compressed, 0, result, 4, compressed.Length);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,8 +34,8 @@ public class VoxelFileReaderTest
|
||||||
using var ms = new MemoryStream(bytes);
|
using var ms = new MemoryStream(bytes);
|
||||||
using var br = new BinaryReader(ms);
|
using var br = new BinaryReader(ms);
|
||||||
|
|
||||||
VoxelFileReader reader = new VoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared);
|
DtVoxelFileReader reader = new DtVoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared);
|
||||||
VoxelFile f = reader.Read(br);
|
DtVoxelFile f = reader.Read(br);
|
||||||
Assert.That(f.useTiles, Is.False);
|
Assert.That(f.useTiles, Is.False);
|
||||||
Assert.That(f.bounds, Is.EqualTo(new float[] { -100.0f, 0f, -100f, 100f, 5f, 100f }));
|
Assert.That(f.bounds, Is.EqualTo(new float[] { -100.0f, 0f, -100f, 100f, 5f, 100f }));
|
||||||
Assert.That(f.cellSize, Is.EqualTo(0.25f));
|
Assert.That(f.cellSize, Is.EqualTo(0.25f));
|
||||||
|
@ -60,8 +60,8 @@ public class VoxelFileReaderTest
|
||||||
using var ms = new MemoryStream(bytes);
|
using var ms = new MemoryStream(bytes);
|
||||||
using var br = new BinaryReader(ms);
|
using var br = new BinaryReader(ms);
|
||||||
|
|
||||||
VoxelFileReader reader = new VoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared);
|
DtVoxelFileReader reader = new DtVoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared);
|
||||||
VoxelFile f = reader.Read(br);
|
DtVoxelFile f = reader.Read(br);
|
||||||
|
|
||||||
Assert.That(f.useTiles, Is.True);
|
Assert.That(f.useTiles, Is.True);
|
||||||
Assert.That(f.bounds, Is.EqualTo(new float[] { -100.0f, 0f, -100f, 100f, 5f, 100f }));
|
Assert.That(f.bounds, Is.EqualTo(new float[] { -100.0f, 0f, -100f, 100f, 5f, 100f }));
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class VoxelFileReaderWriterTest
|
||||||
using var ms = new MemoryStream(bytes);
|
using var ms = new MemoryStream(bytes);
|
||||||
using var br = new BinaryReader(ms);
|
using var br = new BinaryReader(ms);
|
||||||
|
|
||||||
VoxelFile f = ReadWriteRead(br, compression);
|
DtVoxelFile f = ReadWriteRead(br, compression);
|
||||||
Assert.That(f.useTiles, Is.False);
|
Assert.That(f.useTiles, Is.False);
|
||||||
Assert.That(f.bounds, Is.EqualTo(new[] { -100.0f, 0f, -100f, 100f, 5f, 100f }));
|
Assert.That(f.bounds, Is.EqualTo(new[] { -100.0f, 0f, -100f, 100f, 5f, 100f }));
|
||||||
Assert.That(f.cellSize, Is.EqualTo(0.25f));
|
Assert.That(f.cellSize, Is.EqualTo(0.25f));
|
||||||
|
@ -63,7 +63,7 @@ public class VoxelFileReaderWriterTest
|
||||||
using var ms = new MemoryStream(bytes);
|
using var ms = new MemoryStream(bytes);
|
||||||
using var br = new BinaryReader(ms);
|
using var br = new BinaryReader(ms);
|
||||||
|
|
||||||
VoxelFile f = ReadWriteRead(br, compression);
|
DtVoxelFile f = ReadWriteRead(br, compression);
|
||||||
|
|
||||||
Assert.That(f.useTiles, Is.True);
|
Assert.That(f.useTiles, Is.True);
|
||||||
Assert.That(f.bounds, Is.EqualTo(new[] { -100.0f, 0f, -100f, 100f, 5f, 100f }));
|
Assert.That(f.bounds, Is.EqualTo(new[] { -100.0f, 0f, -100f, 100f, 5f, 100f }));
|
||||||
|
@ -86,14 +86,14 @@ public class VoxelFileReaderWriterTest
|
||||||
Assert.That(f.tiles[0].boundsMax, Is.EqualTo(RcVec3f.Of(-78.75f, 5.0f, -78.75f)));
|
Assert.That(f.tiles[0].boundsMax, Is.EqualTo(RcVec3f.Of(-78.75f, 5.0f, -78.75f)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private VoxelFile ReadWriteRead(BinaryReader bis, bool compression)
|
private DtVoxelFile ReadWriteRead(BinaryReader bis, bool compression)
|
||||||
{
|
{
|
||||||
VoxelFileReader reader = new VoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared);
|
DtVoxelFileReader reader = new DtVoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared);
|
||||||
VoxelFile f = reader.Read(bis);
|
DtVoxelFile f = reader.Read(bis);
|
||||||
|
|
||||||
using var msw = new MemoryStream();
|
using var msw = new MemoryStream();
|
||||||
using var bw = new BinaryWriter(msw);
|
using var bw = new BinaryWriter(msw);
|
||||||
VoxelFileWriter writer = new VoxelFileWriter(DtVoxelTileLZ4ForTestCompressor.Shared);
|
DtVoxelFileWriter writer = new DtVoxelFileWriter(DtVoxelTileLZ4ForTestCompressor.Shared);
|
||||||
writer.Write(bw, f, compression);
|
writer.Write(bw, f, compression);
|
||||||
|
|
||||||
using var msr = new MemoryStream(msw.ToArray());
|
using var msr = new MemoryStream(msw.ToArray());
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class VoxelQueryTest
|
||||||
captorZ.Add(z);
|
captorZ.Add(z);
|
||||||
});
|
});
|
||||||
|
|
||||||
VoxelQuery query = new VoxelQuery(ORIGIN, TILE_WIDTH, TILE_DEPTH, hfProvider.Object);
|
DtVoxelQuery query = new DtVoxelQuery(ORIGIN, TILE_WIDTH, TILE_DEPTH, hfProvider.Object);
|
||||||
RcVec3f start = RcVec3f.Of(120, 10, 365);
|
RcVec3f start = RcVec3f.Of(120, 10, 365);
|
||||||
RcVec3f end = RcVec3f.Of(320, 10, 57);
|
RcVec3f end = RcVec3f.Of(320, 10, 57);
|
||||||
|
|
||||||
|
@ -71,8 +71,8 @@ public class VoxelQueryTest
|
||||||
[Test]
|
[Test]
|
||||||
public void ShouldHandleRaycastWithoutObstacles()
|
public void ShouldHandleRaycastWithoutObstacles()
|
||||||
{
|
{
|
||||||
DynamicNavMesh mesh = CreateDynaMesh();
|
DtDynamicNavMesh mesh = CreateDynaMesh();
|
||||||
VoxelQuery query = mesh.VoxelQuery();
|
DtVoxelQuery query = mesh.VoxelQuery();
|
||||||
RcVec3f start = RcVec3f.Of(7.4f, 0.5f, -64.8f);
|
RcVec3f start = RcVec3f.Of(7.4f, 0.5f, -64.8f);
|
||||||
RcVec3f end = RcVec3f.Of(31.2f, 0.5f, -75.3f);
|
RcVec3f end = RcVec3f.Of(31.2f, 0.5f, -75.3f);
|
||||||
bool isHit = query.Raycast(start, end, out var hit);
|
bool isHit = query.Raycast(start, end, out var hit);
|
||||||
|
@ -82,8 +82,8 @@ public class VoxelQueryTest
|
||||||
[Test]
|
[Test]
|
||||||
public void ShouldHandleRaycastWithObstacles()
|
public void ShouldHandleRaycastWithObstacles()
|
||||||
{
|
{
|
||||||
DynamicNavMesh mesh = CreateDynaMesh();
|
DtDynamicNavMesh mesh = CreateDynaMesh();
|
||||||
VoxelQuery query = mesh.VoxelQuery();
|
DtVoxelQuery query = mesh.VoxelQuery();
|
||||||
RcVec3f start = RcVec3f.Of(32.3f, 0.5f, 47.9f);
|
RcVec3f start = RcVec3f.Of(32.3f, 0.5f, 47.9f);
|
||||||
RcVec3f end = RcVec3f.Of(-31.2f, 0.5f, -29.8f);
|
RcVec3f end = RcVec3f.Of(-31.2f, 0.5f, -29.8f);
|
||||||
bool isHit = query.Raycast(start, end, out var hit);
|
bool isHit = query.Raycast(start, end, out var hit);
|
||||||
|
@ -91,17 +91,17 @@ public class VoxelQueryTest
|
||||||
Assert.That(hit, Is.EqualTo(0.5263836f).Within(1e-7f));
|
Assert.That(hit, Is.EqualTo(0.5263836f).Within(1e-7f));
|
||||||
}
|
}
|
||||||
|
|
||||||
private DynamicNavMesh CreateDynaMesh()
|
private DtDynamicNavMesh CreateDynaMesh()
|
||||||
{
|
{
|
||||||
var bytes = Loader.ToBytes("test_tiles.voxels");
|
var bytes = Loader.ToBytes("test_tiles.voxels");
|
||||||
using var ms = new MemoryStream(bytes);
|
using var ms = new MemoryStream(bytes);
|
||||||
using var br = new BinaryReader(ms);
|
using var br = new BinaryReader(ms);
|
||||||
|
|
||||||
// load voxels from file
|
// load voxels from file
|
||||||
VoxelFileReader reader = new VoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared);
|
DtVoxelFileReader reader = new DtVoxelFileReader(DtVoxelTileLZ4ForTestCompressor.Shared);
|
||||||
VoxelFile f = reader.Read(br);
|
DtVoxelFile f = reader.Read(br);
|
||||||
// create dynamic navmesh
|
// create dynamic navmesh
|
||||||
var mesh = new DynamicNavMesh(f);
|
var mesh = new DtDynamicNavMesh(f);
|
||||||
// build navmesh asynchronously using multiple threads
|
// build navmesh asynchronously using multiple threads
|
||||||
Task<bool> future = mesh.Build(Task.Factory);
|
Task<bool> future = mesh.Build(Task.Factory);
|
||||||
// wait for build to complete
|
// wait for build to complete
|
||||||
|
|
Loading…
Reference in New Issue