diff --git a/src/DotRecast.Recast/ObjImporter.cs b/src/DotRecast.Core/RcObjImporter.cs similarity index 82% rename from src/DotRecast.Recast/ObjImporter.cs rename to src/DotRecast.Core/RcObjImporter.cs index 74c096e..28d0eeb 100644 --- a/src/DotRecast.Recast/ObjImporter.cs +++ b/src/DotRecast.Core/RcObjImporter.cs @@ -1,5 +1,6 @@ /* recast4j Copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org +DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -17,24 +18,16 @@ freely, subject to the following restrictions: */ using System; -using System.Collections.Generic; using System.Globalization; using System.IO; -using DotRecast.Recast.Geom; -namespace DotRecast.Recast +namespace DotRecast.Core { - public static class ObjImporter + public static class RcObjImporter { - public static IInputGeomProvider Load(byte[] chunk) + public static RcObjImporterContext LoadContext(byte[] chunk) { - var context = LoadContext(chunk); - return new SimpleInputGeomProvider(context.vertexPositions, context.meshFaces); - } - - public static ObjImporterContext LoadContext(byte[] chunk) - { - ObjImporterContext context = new ObjImporterContext(); + RcObjImporterContext context = new RcObjImporterContext(); try { using StreamReader reader = new StreamReader(new MemoryStream(chunk)); @@ -54,7 +47,7 @@ namespace DotRecast.Recast } - public static void ReadLine(string line, ObjImporterContext context) + public static void ReadLine(string line, RcObjImporterContext context) { if (line.StartsWith("v")) { @@ -66,7 +59,7 @@ namespace DotRecast.Recast } } - private static void ReadVertex(string line, ObjImporterContext context) + private static void ReadVertex(string line, RcObjImporterContext context) { if (line.StartsWith("v ")) { @@ -89,13 +82,13 @@ namespace DotRecast.Recast // fix - https://github.com/ikpil/DotRecast/issues/7 return new float[] { - float.Parse(v[1], CultureInfo.InvariantCulture), - float.Parse(v[2], CultureInfo.InvariantCulture), + float.Parse(v[1], CultureInfo.InvariantCulture), + float.Parse(v[2], CultureInfo.InvariantCulture), float.Parse(v[3], CultureInfo.InvariantCulture) }; } - private static void ReadFace(string line, ObjImporterContext context) + private static void ReadFace(string line, RcObjImporterContext context) { string[] v = line.Split(' ', StringSplitOptions.RemoveEmptyEntries); if (v.Length < 4) @@ -113,7 +106,7 @@ namespace DotRecast.Recast } } - private static int ReadFaceVertex(string face, ObjImporterContext context) + private static int ReadFaceVertex(string face, RcObjImporterContext context) { string[] v = face.Split("/"); return GetIndex(int.Parse(v[0]), context.vertexPositions.Count); diff --git a/src/DotRecast.Recast/ObjImporterContext.cs b/src/DotRecast.Core/RcObjImporterContext.cs similarity index 72% rename from src/DotRecast.Recast/ObjImporterContext.cs rename to src/DotRecast.Core/RcObjImporterContext.cs index e6cab53..a08deaf 100644 --- a/src/DotRecast.Recast/ObjImporterContext.cs +++ b/src/DotRecast.Core/RcObjImporterContext.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; -namespace DotRecast.Recast +namespace DotRecast.Core { - public class ObjImporterContext + public class RcObjImporterContext { public List vertexPositions = new List(); public List meshFaces = new List(); diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index df8fa82..98392a5 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -43,7 +43,6 @@ using DotRecast.Recast.Toolset.Geom; using DotRecast.Recast.Demo.Tools; using DotRecast.Recast.Demo.UI; using DotRecast.Recast.Toolset; - using MouseButton = Silk.NET.Input.MouseButton; using Window = Silk.NET.Windowing.Window; @@ -298,9 +297,7 @@ public class RecastDemo : IRecastDemoChannel private DemoInputGeomProvider LoadInputMesh(string filename) { - var bytes = RcResources.Load(filename); - DemoInputGeomProvider geom = DemoObjImporter.Load(bytes); - + DemoInputGeomProvider geom = DemoInputGeomProvider.LoadFile(filename); _lastGeomFileName = filename; return geom; } diff --git a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateSampleTool.cs index f6079a9..b9cfba0 100644 --- a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateSampleTool.cs @@ -30,6 +30,7 @@ using DotRecast.Recast.Toolset.Gizmos; using DotRecast.Recast.Toolset.Tools; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Demo.UI; +using DotRecast.Recast.Toolset.Geom; using ImGuiNET; using Serilog; using static DotRecast.Recast.Demo.Draw.DebugDraw; @@ -88,9 +89,9 @@ public class DynamicUpdateSampleTool : ISampleTool public DynamicUpdateSampleTool() { - var bridgeGeom = DemoObjImporter.Load(RcResources.Load("bridge.obj")); - var houseGeom = DemoObjImporter.Load(RcResources.Load("house.obj")); - var convexGeom = DemoObjImporter.Load(RcResources.Load("convex.obj")); + var bridgeGeom = DemoInputGeomProvider.LoadFile("bridge.obj"); + var houseGeom = DemoInputGeomProvider.LoadFile("house.obj"); + var convexGeom = DemoInputGeomProvider.LoadFile("convex.obj"); _tool = new(Random.Shared, bridgeGeom, houseGeom, convexGeom); executor = Task.Factory; } diff --git a/src/DotRecast.Recast.Toolset/DemoObjImporter.cs b/src/DotRecast.Recast.Toolset/DemoObjImporter.cs deleted file mode 100644 index ba44d0d..0000000 --- a/src/DotRecast.Recast.Toolset/DemoObjImporter.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.IO; -using DotRecast.Recast.Toolset.Geom; - -namespace DotRecast.Recast.Toolset -{ - public static class DemoObjImporter - { - public static DemoInputGeomProvider Load(byte[] chunk) - { - var context = ObjImporter.LoadContext(chunk); - return new DemoInputGeomProvider(context.vertexPositions, context.meshFaces); - } - } -} \ No newline at end of file diff --git a/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs b/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs index 4062544..56ae2f2 100644 --- a/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs +++ b/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs @@ -37,6 +37,13 @@ namespace DotRecast.Recast.Toolset.Geom private readonly List _offMeshConnections = new List(); private readonly RcTriMesh _mesh; + public static DemoInputGeomProvider LoadFile(string objFilePath) + { + byte[] chunk = RcResources.Load(objFilePath); + var context = RcObjImporter.LoadContext(chunk); + return new DemoInputGeomProvider(context.vertexPositions, context.meshFaces); + } + public DemoInputGeomProvider(List vertexPositions, List meshFaces) : this(MapVertices(vertexPositions), MapFaces(meshFaces)) { diff --git a/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs b/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs index 0eff052..b366f1d 100644 --- a/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs +++ b/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs @@ -35,6 +35,13 @@ namespace DotRecast.Recast.Geom private readonly List volumes = new List(); private readonly RcTriMesh _mesh; + public static SimpleInputGeomProvider LoadFile(string objFilePath) + { + byte[] chunk = RcResources.Load(objFilePath); + var context = RcObjImporter.LoadContext(chunk); + return new SimpleInputGeomProvider(context.vertexPositions, context.meshFaces); + } + public SimpleInputGeomProvider(List vertexPositions, List meshFaces) : this(MapVertices(vertexPositions), MapFaces(meshFaces)) { diff --git a/src/DotRecast.Recast/IRecastBuilderProgressListener.cs b/src/DotRecast.Recast/IRcBuilderProgressListener.cs similarity index 64% rename from src/DotRecast.Recast/IRecastBuilderProgressListener.cs rename to src/DotRecast.Recast/IRcBuilderProgressListener.cs index eecc49e..f10c423 100644 --- a/src/DotRecast.Recast/IRecastBuilderProgressListener.cs +++ b/src/DotRecast.Recast/IRcBuilderProgressListener.cs @@ -1,6 +1,6 @@ namespace DotRecast.Recast { - public interface IRecastBuilderProgressListener + public interface IRcBuilderProgressListener { void OnProgress(int completed, int total); } diff --git a/src/DotRecast.Recast/RcBuilder.cs b/src/DotRecast.Recast/RcBuilder.cs index 255d824..e2bd465 100644 --- a/src/DotRecast.Recast/RcBuilder.cs +++ b/src/DotRecast.Recast/RcBuilder.cs @@ -32,16 +32,16 @@ namespace DotRecast.Recast public class RcBuilder { - private readonly IRecastBuilderProgressListener progressListener; + private readonly IRcBuilderProgressListener _progressListener; public RcBuilder() { - progressListener = null; + _progressListener = null; } - public RcBuilder(IRecastBuilderProgressListener progressListener) + public RcBuilder(IRcBuilderProgressListener progressListener) { - this.progressListener = progressListener; + _progressListener = progressListener; } public List BuildTiles(IInputGeomProvider geom, RcConfig cfg, TaskFactory taskFactory) @@ -150,9 +150,9 @@ namespace DotRecast.Recast int ty, RcAtomicInteger counter, int total) { RcBuilderResult result = Build(geom, new RcBuilderConfig(cfg, bmin, bmax, tx, ty)); - if (progressListener != null) + if (_progressListener != null) { - progressListener.OnProgress(counter.IncrementAndGet(), total); + _progressListener.OnProgress(counter.IncrementAndGet(), total); } return result; @@ -237,8 +237,7 @@ namespace DotRecast.Recast // // Create contours. - RcContourSet cset = RcContours.BuildContours(ctx, chf, cfg.MaxSimplificationError, cfg.MaxEdgeLen, - RcConstants.RC_CONTOUR_TESS_WALL_EDGES); + RcContourSet cset = RcContours.BuildContours(ctx, chf, cfg.MaxSimplificationError, cfg.MaxEdgeLen, RcConstants.RC_CONTOUR_TESS_WALL_EDGES); // // Step 6. Build polygons mesh from contours. @@ -283,8 +282,7 @@ namespace DotRecast.Recast /* * Step 3. Partition walkable surface to simple regions. */ - private RcCompactHeightfield BuildCompactHeightfield(IInputGeomProvider geom, RcConfig cfg, RcTelemetry ctx, - RcHeightfield solid) + private RcCompactHeightfield BuildCompactHeightfield(IInputGeomProvider geom, RcConfig cfg, RcTelemetry ctx, RcHeightfield solid) { // Compact the heightfield so that it is faster to handle from now on. // This will result more cache coherent data as well as the neighbours diff --git a/test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs b/test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs index 359391e..22d8d74 100644 --- a/test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs +++ b/test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs @@ -40,7 +40,7 @@ public class RecastTestMeshBuilder public const float m_detailSampleMaxError = 1.0f; public RecastTestMeshBuilder() - : this(ObjImporter.Load(RcResources.Load("dungeon.obj")), + : this(SimpleInputGeomProvider.LoadFile("dungeon.obj"), RcPartition.WATERSHED, m_cellSize, m_cellHeight, m_agentMaxSlope, m_agentHeight, m_agentRadius, m_agentMaxClimb, diff --git a/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs b/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs index 01f8ed2..c739205 100644 --- a/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs +++ b/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs @@ -54,7 +54,7 @@ public class MeshSetReaderWriterTest [Test] public void Test() { - IInputGeomProvider geom = ObjImporter.Load(RcResources.Load("dungeon.obj")); + IInputGeomProvider geom = SimpleInputGeomProvider.LoadFile("dungeon.obj"); NavMeshSetHeader header = new NavMeshSetHeader(); header.magic = NavMeshSetHeader.NAVMESHSET_MAGIC; diff --git a/test/DotRecast.Detour.Test/RecastTestMeshBuilder.cs b/test/DotRecast.Detour.Test/RecastTestMeshBuilder.cs index 9978bc7..eabe133 100644 --- a/test/DotRecast.Detour.Test/RecastTestMeshBuilder.cs +++ b/test/DotRecast.Detour.Test/RecastTestMeshBuilder.cs @@ -40,7 +40,7 @@ public class RecastTestMeshBuilder private const float m_detailSampleMaxError = 1.0f; public RecastTestMeshBuilder() - : this(ObjImporter.Load(RcResources.Load("dungeon.obj")), + : this(SimpleInputGeomProvider.LoadFile("dungeon.obj"), RcPartition.WATERSHED, m_cellSize, m_cellHeight, m_agentMaxSlope, m_agentHeight, m_agentRadius, m_agentMaxClimb, diff --git a/test/DotRecast.Detour.Test/TestTiledNavMeshBuilder.cs b/test/DotRecast.Detour.Test/TestTiledNavMeshBuilder.cs index fed6d55..523fca2 100644 --- a/test/DotRecast.Detour.Test/TestTiledNavMeshBuilder.cs +++ b/test/DotRecast.Detour.Test/TestTiledNavMeshBuilder.cs @@ -45,7 +45,7 @@ public class TestTiledNavMeshBuilder private const int m_tileSize = 32; public TestTiledNavMeshBuilder() : - this(ObjImporter.Load(RcResources.Load("dungeon.obj")), + this(SimpleInputGeomProvider.LoadFile("dungeon.obj"), RcPartition.WATERSHED, m_cellSize, m_cellHeight, m_agentHeight, m_agentRadius, m_agentMaxClimb, m_agentMaxSlope, m_regionMinSize, m_regionMergeSize, m_edgeMaxLen, m_edgeMaxError, m_vertsPerPoly, m_detailSampleDist, m_detailSampleMaxError, m_tileSize) diff --git a/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderWriterTest.cs b/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderWriterTest.cs index 2655b76..c62767b 100644 --- a/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderWriterTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/Io/TileCacheReaderWriterTest.cs @@ -51,7 +51,7 @@ public class TileCacheReaderWriterTest : AbstractTileCacheTest private void TestDungeon(bool cCompatibility) { - IInputGeomProvider geom = ObjImporter.Load(RcResources.Load("dungeon.obj")); + IInputGeomProvider geom = SimpleInputGeomProvider.LoadFile("dungeon.obj"); TestTileLayerBuilder layerBuilder = new TestTileLayerBuilder(geom); List layers = layerBuilder.Build(RcByteOrder.LITTLE_ENDIAN, cCompatibility, 1); DtTileCache tc = GetTileCache(geom, RcByteOrder.LITTLE_ENDIAN, cCompatibility); diff --git a/test/DotRecast.Detour.TileCache.Test/TempObstaclesTest.cs b/test/DotRecast.Detour.TileCache.Test/TempObstaclesTest.cs index 92109a3..2ecf242 100644 --- a/test/DotRecast.Detour.TileCache.Test/TempObstaclesTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/TempObstaclesTest.cs @@ -34,7 +34,7 @@ public class TempObstaclesTest : AbstractTileCacheTest public void TestDungeon() { bool cCompatibility = true; - IInputGeomProvider geom = ObjImporter.Load(RcResources.Load("dungeon.obj")); + IInputGeomProvider geom = SimpleInputGeomProvider.LoadFile("dungeon.obj"); TestTileLayerBuilder layerBuilder = new TestTileLayerBuilder(geom); List layers = layerBuilder.Build(RcByteOrder.LITTLE_ENDIAN, cCompatibility, 1); DtTileCache tc = GetTileCache(geom, RcByteOrder.LITTLE_ENDIAN, cCompatibility); @@ -68,7 +68,7 @@ public class TempObstaclesTest : AbstractTileCacheTest public void TestDungeonBox() { bool cCompatibility = true; - IInputGeomProvider geom = ObjImporter.Load(RcResources.Load("dungeon.obj")); + IInputGeomProvider geom = SimpleInputGeomProvider.LoadFile("dungeon.obj"); TestTileLayerBuilder layerBuilder = new TestTileLayerBuilder(geom); List layers = layerBuilder.Build(RcByteOrder.LITTLE_ENDIAN, cCompatibility, 1); DtTileCache tc = GetTileCache(geom, RcByteOrder.LITTLE_ENDIAN, cCompatibility); diff --git a/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs b/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs index e1dd3ce..330cb6f 100644 --- a/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs @@ -55,7 +55,7 @@ public class TileCacheNavigationTest : AbstractTileCacheTest public void SetUp() { bool cCompatibility = true; - IInputGeomProvider geom = ObjImporter.Load(RcResources.Load("dungeon.obj")); + IInputGeomProvider geom = SimpleInputGeomProvider.LoadFile("dungeon.obj"); TestTileLayerBuilder layerBuilder = new TestTileLayerBuilder(geom); List layers = layerBuilder.Build(RcByteOrder.LITTLE_ENDIAN, cCompatibility, 1); DtTileCache tc = GetTileCache(geom, RcByteOrder.LITTLE_ENDIAN, cCompatibility); diff --git a/test/DotRecast.Detour.TileCache.Test/TileCacheTest.cs b/test/DotRecast.Detour.TileCache.Test/TileCacheTest.cs index 0caf5a1..e95031e 100644 --- a/test/DotRecast.Detour.TileCache.Test/TileCacheTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/TileCacheTest.cs @@ -59,7 +59,7 @@ public class TileCacheTest : AbstractTileCacheTest private void TestDungeon(RcByteOrder order, bool cCompatibility) { - IInputGeomProvider geom = ObjImporter.Load(RcResources.Load("dungeon.obj")); + IInputGeomProvider geom = SimpleInputGeomProvider.LoadFile("dungeon.obj"); DtTileCache tc = GetTileCache(geom, order, cCompatibility); TestTileLayerBuilder layerBuilder = new TestTileLayerBuilder(geom); List layers = layerBuilder.Build(order, cCompatibility, 1); @@ -155,7 +155,7 @@ public class TileCacheTest : AbstractTileCacheTest private void Test(RcByteOrder order, bool cCompatibility) { - IInputGeomProvider geom = ObjImporter.Load(RcResources.Load("nav_test.obj")); + IInputGeomProvider geom = SimpleInputGeomProvider.LoadFile("nav_test.obj"); DtTileCache tc = GetTileCache(geom, order, cCompatibility); TestTileLayerBuilder layerBuilder = new TestTileLayerBuilder(geom); List layers = layerBuilder.Build(order, cCompatibility, 1); @@ -182,8 +182,7 @@ public class TileCacheTest : AbstractTileCacheTest RcByteOrder order = RcByteOrder.LITTLE_ENDIAN; bool cCompatibility = false; - var objBytes = RcResources.Load("dungeon.obj"); - IInputGeomProvider geom = ObjImporter.Load(objBytes); + IInputGeomProvider geom = SimpleInputGeomProvider.LoadFile("dungeon.obj"); TestTileLayerBuilder layerBuilder = new TestTileLayerBuilder(geom); for (int i = 0; i < 4; i++) { diff --git a/test/DotRecast.Recast.Test/RecastLayersTest.cs b/test/DotRecast.Recast.Test/RecastLayersTest.cs index ed1b2d1..84f324b 100644 --- a/test/DotRecast.Recast.Test/RecastLayersTest.cs +++ b/test/DotRecast.Recast.Test/RecastLayersTest.cs @@ -145,7 +145,7 @@ public class RecastLayersTest private RcHeightfieldLayerSet Build(string filename, int x, int y) { - IInputGeomProvider geom = ObjImporter.Load(RcResources.Load(filename)); + IInputGeomProvider geom = SimpleInputGeomProvider.LoadFile(filename); RcBuilder builder = new RcBuilder(); RcConfig cfg = new RcConfig(true, m_tileSize, m_tileSize, RcConfig.CalcBorder(m_agentRadius, m_cellSize), diff --git a/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs b/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs index 41128c6..0e9ac47 100644 --- a/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs +++ b/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs @@ -97,7 +97,7 @@ public class RecastSoloMeshTest int expContours, int expVerts, int expPolys, int expDetMeshes, int expDetVerts, int expDetTris) { m_partitionType = partitionType; - IInputGeomProvider geomProvider = ObjImporter.Load(RcResources.Load(filename)); + IInputGeomProvider geomProvider = SimpleInputGeomProvider.LoadFile(filename); long time = RcFrequency.Ticks; RcVec3f bmin = geomProvider.GetMeshBoundsMin(); RcVec3f bmax = geomProvider.GetMeshBoundsMax(); diff --git a/test/DotRecast.Recast.Test/RecastTileMeshTest.cs b/test/DotRecast.Recast.Test/RecastTileMeshTest.cs index 95084da..10baf9c 100644 --- a/test/DotRecast.Recast.Test/RecastTileMeshTest.cs +++ b/test/DotRecast.Recast.Test/RecastTileMeshTest.cs @@ -58,7 +58,7 @@ public class RecastTileMeshTest public void TestBuild(string filename) { - IInputGeomProvider geom = ObjImporter.Load(RcResources.Load(filename)); + IInputGeomProvider geom = SimpleInputGeomProvider.LoadFile(filename); RcBuilder builder = new RcBuilder(); RcConfig cfg = new RcConfig( true, m_tileSize, m_tileSize, RcConfig.CalcBorder(m_agentRadius, m_cellSize), @@ -100,7 +100,7 @@ public class RecastTileMeshTest [Test] public void TestPerformance() { - IInputGeomProvider geom = ObjImporter.Load(RcResources.Load("dungeon.obj")); + IInputGeomProvider geom = SimpleInputGeomProvider.LoadFile("dungeon.obj"); RcBuilder builder = new RcBuilder(); RcConfig cfg = new RcConfig( true, m_tileSize, m_tileSize,