refactor: vcelfile save and load

This commit is contained in:
ikpil 2023-09-11 23:22:11 +09:00
parent 9788fd536f
commit 6e8867ec94
2 changed files with 31 additions and 15 deletions

View File

@ -56,23 +56,23 @@ public class DynamicUpdateSampleTool : ISampleTool
private float walkableHeight = 2f; private float walkableHeight = 2f;
private float walkableRadius = 0.6f; private float walkableRadius = 0.6f;
private float walkableClimb = 0.9f; private float walkableClimb = 0.9f;
private float minRegionArea = 6f; private float minRegionArea = 6f;
private float regionMergeSize = 36f; private float regionMergeSize = 36f;
private float maxEdgeLen = 12f; private float maxEdgeLen = 12f;
private float maxSimplificationError = 1.3f; private float maxSimplificationError = 1.3f;
private int vertsPerPoly = 6; private int vertsPerPoly = 6;
private float detailSampleDist = 6f; private float detailSampleDist = 6f;
private float detailSampleMaxError = 1f; private float detailSampleMaxError = 1f;
private bool filterLowHangingObstacles = true; private bool filterLowHangingObstacles = true;
private bool filterLedgeSpans = true; private bool filterLedgeSpans = true;
private bool filterWalkableLowHeightSpans = true; private bool filterWalkableLowHeightSpans = true;
private bool buildDetailMesh = true; private bool buildDetailMesh = true;
private bool compression = true; private bool compression = true;
private bool showColliders = false; private bool showColliders = false;
private long buildTime; private long buildTime;
@ -692,10 +692,7 @@ public class DynamicUpdateSampleTool : ISampleTool
{ {
try try
{ {
using var fs = new FileStream(filename, FileMode.Open, FileAccess.Read); var voxelFile = _tool.Load(filename, DtVoxelTileLZ4DemoCompressor.Shared);
using var br = new BinaryReader(fs);
VoxelFileReader reader = new VoxelFileReader(DtVoxelTileLZ4DemoCompressor.Shared);
VoxelFile voxelFile = reader.Read(br);
dynaMesh = new DynamicNavMesh(voxelFile); dynaMesh = new DynamicNavMesh(voxelFile);
dynaMesh.config.keepIntermediateResults = true; dynaMesh.config.keepIntermediateResults = true;
@ -714,11 +711,8 @@ public class DynamicUpdateSampleTool : ISampleTool
private void Save(string filename) private void Save(string filename)
{ {
using var fs = new FileStream(filename, FileMode.CreateNew, FileAccess.Write);
using var bw = new BinaryWriter(fs);
VoxelFile voxelFile = VoxelFile.From(dynaMesh); VoxelFile voxelFile = VoxelFile.From(dynaMesh);
VoxelFileWriter writer = new VoxelFileWriter(DtVoxelTileLZ4DemoCompressor.Shared); _tool.Save(filename, voxelFile, compression, DtVoxelTileLZ4DemoCompressor.Shared);
writer.Write(bw, voxelFile, compression);
} }
private void BuildDynaMesh() private void BuildDynaMesh()

View File

@ -1,4 +1,8 @@
namespace DotRecast.Recast.Toolset.Tools using System.IO;
using DotRecast.Core;
using DotRecast.Detour.Dynamic.Io;
namespace DotRecast.Recast.Toolset.Tools
{ {
public class RcDynamicUpdateTool : IRcToolable public class RcDynamicUpdateTool : IRcToolable
{ {
@ -6,5 +10,23 @@
{ {
return "Dynamic Updates"; return "Dynamic Updates";
} }
public VoxelFile Load(string filename, IRcCompressor compressor)
{
using var fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
using var br = new BinaryReader(fs);
VoxelFileReader reader = new VoxelFileReader(compressor);
VoxelFile voxelFile = reader.Read(br);
return voxelFile;
}
public void Save(string filename, VoxelFile voxelFile, bool compression, IRcCompressor compressor)
{
using var fs = new FileStream(filename, FileMode.CreateNew, FileAccess.Write);
using var bw = new BinaryWriter(fs);
VoxelFileWriter writer = new VoxelFileWriter(compressor);
writer.Write(bw, voxelFile, compression);
}
} }
} }