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];
|
||||||
|
@ -306,28 +304,33 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadNavMesh(FileStream file, string filename)
|
private void LoadNavMesh(FileStream file, string filename)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
DtNavMesh mesh = null;
|
DtNavMesh mesh = null;
|
||||||
if (filename.EndsWith(".zip") || filename.EndsWith(".bytes"))
|
if (filename.EndsWith(".zip"))
|
||||||
{
|
{
|
||||||
UnityAStarPathfindingImporter importer = new UnityAStarPathfindingImporter();
|
UnityAStarPathfindingImporter importer = new UnityAStarPathfindingImporter();
|
||||||
mesh = importer.Load(file)[0];
|
mesh = importer.Load(file)[0];
|
||||||
}
|
}
|
||||||
else if (filename.EndsWith(".bin") || filename.EndsWith(".navmesh"))
|
else
|
||||||
{
|
{
|
||||||
|
using var br = new BinaryReader(file);
|
||||||
DtMeshSetReader reader = new DtMeshSetReader();
|
DtMeshSetReader reader = new DtMeshSetReader();
|
||||||
using (var fis = new BinaryReader(file))
|
mesh = reader.Read(br, 6);
|
||||||
{
|
|
||||||
mesh = reader.Read(fis, 6);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mesh != null)
|
if (null != mesh)
|
||||||
{
|
{
|
||||||
//sample = new Sample(null, ImmutableArray<RecastBuilderResult>.Empty, mesh, settingsUI, dd);
|
sample = new Sample(sample.GetInputGeom(), ImmutableArray<RecastBuilderResult>.Empty, mesh);
|
||||||
toolset.SetEnabled(true);
|
toolset.SetEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Error(e, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnWindowClosing()
|
private void OnWindowClosing()
|
||||||
{
|
{
|
||||||
|
@ -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