forked from bit/DotRecastNetSim
fix - load navmesh binary
This commit is contained in:
parent
3b9234e83d
commit
e74cd58525
|
@ -117,7 +117,7 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
|
|
||||||
private long prevFrameTime;
|
private long prevFrameTime;
|
||||||
private RecastDebugDraw dd;
|
private RecastDebugDraw dd;
|
||||||
private Queue<IRecastDemoMessage> _messages;
|
private readonly Queue<IRecastDemoMessage> _messages;
|
||||||
|
|
||||||
public RecastDemo()
|
public RecastDemo()
|
||||||
{
|
{
|
||||||
|
@ -174,9 +174,7 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
if (pan)
|
if (pan)
|
||||||
{
|
{
|
||||||
float[] modelviewMatrix = dd.ViewMatrix(cameraPos, cameraEulers);
|
float[] modelviewMatrix = dd.ViewMatrix(cameraPos, cameraEulers);
|
||||||
cameraPos.x = origCameraPos.x;
|
cameraPos = origCameraPos;
|
||||||
cameraPos.y = origCameraPos.y;
|
|
||||||
cameraPos.z = origCameraPos.z;
|
|
||||||
|
|
||||||
cameraPos.x -= 0.1f * dx * modelviewMatrix[0];
|
cameraPos.x -= 0.1f * dx * modelviewMatrix[0];
|
||||||
cameraPos.y -= 0.1f * dx * modelviewMatrix[4];
|
cameraPos.y -= 0.1f * dx * modelviewMatrix[4];
|
||||||
|
@ -307,25 +305,30 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
|
|
||||||
private void LoadNavMesh(FileStream file, string filename)
|
private void LoadNavMesh(FileStream file, string filename)
|
||||||
{
|
{
|
||||||
DtNavMesh mesh = null;
|
try
|
||||||
if (filename.EndsWith(".zip") || filename.EndsWith(".bytes"))
|
|
||||||
{
|
{
|
||||||
UnityAStarPathfindingImporter importer = new UnityAStarPathfindingImporter();
|
DtNavMesh mesh = null;
|
||||||
mesh = importer.Load(file)[0];
|
if (filename.EndsWith(".zip"))
|
||||||
}
|
|
||||||
else if (filename.EndsWith(".bin") || filename.EndsWith(".navmesh"))
|
|
||||||
{
|
|
||||||
DtMeshSetReader reader = new DtMeshSetReader();
|
|
||||||
using (var fis = new BinaryReader(file))
|
|
||||||
{
|
{
|
||||||
mesh = reader.Read(fis, 6);
|
UnityAStarPathfindingImporter importer = new UnityAStarPathfindingImporter();
|
||||||
|
mesh = importer.Load(file)[0];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
using var br = new BinaryReader(file);
|
||||||
|
DtMeshSetReader reader = new DtMeshSetReader();
|
||||||
|
mesh = reader.Read(br, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null != mesh)
|
||||||
|
{
|
||||||
|
sample = new Sample(sample.GetInputGeom(), ImmutableArray<RecastBuilderResult>.Empty, mesh);
|
||||||
|
toolset.SetEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
if (mesh != null)
|
|
||||||
{
|
{
|
||||||
//sample = new Sample(null, ImmutableArray<RecastBuilderResult>.Empty, mesh, settingsUI, dd);
|
Logger.Error(e, "");
|
||||||
toolset.SetEnabled(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,7 +620,7 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
cameraPos.x = (bmax.x + bmin.x) / 2 + camr;
|
cameraPos.x = (bmax.x + bmin.x) / 2 + camr;
|
||||||
cameraPos.y = (bmax.y + bmin.y) / 2 + camr;
|
cameraPos.y = (bmax.y + bmin.y) / 2 + camr;
|
||||||
cameraPos.z = (bmax.z + bmin.z) / 2 + camr;
|
cameraPos.z = (bmax.z + bmin.z) / 2 + camr;
|
||||||
camr *= 3;
|
camr *= 5;
|
||||||
cameraEulers[0] = 45;
|
cameraEulers[0] = 45;
|
||||||
cameraEulers[1] = -45;
|
cameraEulers[1] = -45;
|
||||||
}
|
}
|
||||||
|
@ -804,31 +807,30 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
|
|
||||||
private void OnNavMeshSaveBegan(NavMeshSaveBeganEvent args)
|
private void OnNavMeshSaveBegan(NavMeshSaveBeganEvent args)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnNavMeshLoadBegan(NavMeshLoadBeganEvent args)
|
private void OnNavMeshLoadBegan(NavMeshLoadBeganEvent args)
|
||||||
{
|
{
|
||||||
// try (MemoryStack stack = StackPush()) {
|
if (string.IsNullOrEmpty(args.FilePath))
|
||||||
// PointerBuffer aFilterPatterns = stack.MallocPointer(4);
|
{
|
||||||
// aFilterPatterns.Put(stack.UTF8("*.bin"));
|
Logger.Error("file path is empty");
|
||||||
// aFilterPatterns.Put(stack.UTF8("*.zip"));
|
return;
|
||||||
// aFilterPatterns.Put(stack.UTF8("*.bytes"));
|
}
|
||||||
// aFilterPatterns.Put(stack.UTF8("*.navmesh"));
|
|
||||||
// aFilterPatterns.Flip();
|
if (!File.Exists(args.FilePath))
|
||||||
// string filename = TinyFileDialogs.Tinyfd_openFileDialog("Open Nav Mesh File", "", aFilterPatterns,
|
{
|
||||||
// "Nav Mesh File", false);
|
Logger.Error($"not found navmesh file - {args.FilePath}");
|
||||||
// if (filename != null) {
|
return;
|
||||||
// File file = new File(filename);
|
}
|
||||||
// if (file.Exists()) {
|
|
||||||
// try {
|
try
|
||||||
// LoadNavMesh(file, filename);
|
{
|
||||||
// geom = null;
|
using FileStream fs = new FileStream(args.FilePath, FileMode.Open, FileAccess.Read);
|
||||||
// } catch (Exception e) {
|
LoadNavMesh(fs, args.FilePath);
|
||||||
// Console.WriteLine(e);
|
}
|
||||||
// }
|
catch (Exception e)
|
||||||
// }
|
{
|
||||||
// }
|
Logger.Error(e, "");
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue