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

@ -692,10 +692,7 @@ public class DynamicUpdateSampleTool : ISampleTool
{
try
{
using var fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
using var br = new BinaryReader(fs);
VoxelFileReader reader = new VoxelFileReader(DtVoxelTileLZ4DemoCompressor.Shared);
VoxelFile voxelFile = reader.Read(br);
var voxelFile = _tool.Load(filename, DtVoxelTileLZ4DemoCompressor.Shared);
dynaMesh = new DynamicNavMesh(voxelFile);
dynaMesh.config.keepIntermediateResults = true;
@ -714,11 +711,8 @@ public class DynamicUpdateSampleTool : ISampleTool
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);
VoxelFileWriter writer = new VoxelFileWriter(DtVoxelTileLZ4DemoCompressor.Shared);
writer.Write(bw, voxelFile, compression);
_tool.Save(filename, voxelFile, compression, DtVoxelTileLZ4DemoCompressor.Shared);
}
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
{
@ -6,5 +10,23 @@
{
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);
}
}
}