Skip to content

Commit d2ec905

Browse files
committed
refactor: consolidate input geometry providers into RcSampleInputGeomProvider
- Rename `DemoInputGeomProvider` to `RcSampleInputGeomProvider` and move to `DotRecast.Recast.Geom` namespace. - Remove `RcSimpleInputGeomProvider` as it is now redundant. - Update all references in Demo, Toolset, and Test projects to use `RcSampleInputGeomProvider`. - This unifies the input geometry handling and removes code duplication.
1 parent e1d97c3 commit d2ec905

File tree

21 files changed

+56
-227
lines changed

21 files changed

+56
-227
lines changed

src/DotRecast.Recast.Demo/DemoSample.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,23 @@ 3. This notice may not be removed or altered from any source distribution.
2020

2121
using System.Collections.Generic;
2222
using DotRecast.Detour;
23+
using DotRecast.Recast.Geom;
2324
using DotRecast.Recast.Toolset;
2425
using DotRecast.Recast.Toolset.Geom;
2526

2627
namespace DotRecast.Recast.Demo
2728
{
2829
public class DemoSample
2930
{
30-
private DemoInputGeomProvider _geom;
31+
private RcSampleInputGeomProvider _geom;
3132
private DtNavMesh _navMesh;
3233
private DtNavMeshQuery _navMeshQuery;
3334
private readonly RcNavMeshBuildSettings _settings;
3435
private RcConfig _cfg;
3536
private IList<RcBuilderResult> _recastResults;
3637
private bool _changed;
3738

38-
public DemoSample(DemoInputGeomProvider geom, IList<RcBuilderResult> recastResults, DtNavMesh navMesh)
39+
public DemoSample(RcSampleInputGeomProvider geom, IList<RcBuilderResult> recastResults, DtNavMesh navMesh)
3940
{
4041
_geom = geom;
4142
_recastResults = recastResults;
@@ -51,7 +52,7 @@ private void SetQuery(DtNavMesh navMesh)
5152
_navMeshQuery = navMesh != null ? new DtNavMeshQuery(navMesh) : null;
5253
}
5354

54-
public DemoInputGeomProvider GetInputGeom()
55+
public RcSampleInputGeomProvider GetInputGeom()
5556
{
5657
return _geom;
5758
}
@@ -91,7 +92,7 @@ public void SetChanged(bool changed)
9192
_changed = changed;
9293
}
9394

94-
public void Update(DemoInputGeomProvider geom, RcConfig cfg, IList<RcBuilderResult> recastResults, DtNavMesh navMesh)
95+
public void Update(RcSampleInputGeomProvider geom, RcConfig cfg, IList<RcBuilderResult> recastResults, DtNavMesh navMesh)
9596
{
9697
_geom = geom;
9798
_cfg = cfg;

src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ 3. This notice may not be removed or altered from any source distribution.
2121
using System.Collections.Generic;
2222
using DotRecast.Core.Numerics;
2323
using DotRecast.Detour;
24+
using DotRecast.Recast.Geom;
2425
using DotRecast.Recast.Toolset.Builder;
2526
using DotRecast.Recast.Toolset.Geom;
2627
using static DotRecast.Recast.RcRecast;
@@ -50,7 +51,7 @@ public void Render(DemoSample sample, DrawMode drawMode)
5051
}
5152

5253
DtNavMeshQuery navQuery = sample.GetNavMeshQuery();
53-
DemoInputGeomProvider geom = sample.GetInputGeom();
54+
RcSampleInputGeomProvider geom = sample.GetInputGeom();
5455
IList<RcBuilderResult> rcBuilderResults = sample.GetRecastResults();
5556
DtNavMesh navMesh = sample.GetNavMesh();
5657
var settings = sample.GetSettings();
@@ -207,7 +208,7 @@ public void Render(DemoSample sample, DrawMode drawMode)
207208
}
208209
}
209210

210-
private void DrawGeomBounds(DemoInputGeomProvider geom)
211+
private void DrawGeomBounds(RcSampleInputGeomProvider geom)
211212
{
212213
// Draw bounds
213214
RcVec3f bmin = geom.GetMeshBoundsMin();
@@ -219,7 +220,7 @@ private void DrawGeomBounds(DemoInputGeomProvider geom)
219220
_debugDraw.End();
220221
}
221222

222-
public void DrawOffMeshConnections(DemoInputGeomProvider geom, bool hilight)
223+
public void DrawOffMeshConnections(RcSampleInputGeomProvider geom, bool hilight)
223224
{
224225
int conColor = DebugDraw.DuRGBA(192, 0, 128, 192);
225226
int baseColor = DebugDraw.DuRGBA(0, 0, 0, 64);
@@ -249,7 +250,7 @@ public void DrawOffMeshConnections(DemoInputGeomProvider geom, bool hilight)
249250
_debugDraw.DepthMask(true);
250251
}
251252

252-
void DrawConvexVolumes(DemoInputGeomProvider geom)
253+
void DrawConvexVolumes(RcSampleInputGeomProvider geom)
253254
{
254255
_debugDraw.DepthMask(false);
255256

src/DotRecast.Recast.Demo/RecastDemo.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ 3. This notice may not be removed or altered from any source distribution.
4545
using DotRecast.Recast.Toolset.Geom;
4646
using DotRecast.Recast.Demo.Tools;
4747
using DotRecast.Recast.Demo.UI;
48+
using DotRecast.Recast.Geom;
4849
using MouseButton = Silk.NET.Input.MouseButton;
4950
using Window = Silk.NET.Windowing.Window;
5051

@@ -294,9 +295,9 @@ private IWindow CreateWindow()
294295
return window;
295296
}
296297

297-
private DemoInputGeomProvider LoadInputMesh(string filename)
298+
private RcSampleInputGeomProvider LoadInputMesh(string filename)
298299
{
299-
DemoInputGeomProvider geom = DemoInputGeomProvider.LoadFile(filename);
300+
RcSampleInputGeomProvider geom = RcSampleInputGeomProvider.LoadFile(filename);
300301
_lastGeomFileName = filename;
301302
return geom;
302303
}
@@ -380,7 +381,7 @@ private void OnWindowOnLoad()
380381
//ImGui.GetStyle().ScaleAllSizes(scale);
381382
//ImGui.GetIO().FontGlobalScale = 2.0f;
382383

383-
DemoInputGeomProvider geom = LoadInputMesh("nav_test.obj");
384+
RcSampleInputGeomProvider geom = LoadInputMesh("nav_test.obj");
384385
_sample = new DemoSample(geom, ImmutableArray<RcBuilderResult>.Empty, null);
385386

386387
_menuView = new RcMenuView();
@@ -796,7 +797,7 @@ private void OnRaycast(RaycastEvent args)
796797
var rayEnd = args.End;
797798

798799
// Hit test mesh.
799-
DemoInputGeomProvider inputGeom = _sample.GetInputGeom();
800+
RcSampleInputGeomProvider inputGeom = _sample.GetInputGeom();
800801
if (_sample == null)
801802
return;
802803

src/DotRecast.Recast.Demo/Tools/DynamicUpdateSampleTool.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ 3. This notice may not be removed or altered from any source distribution.
2929
using DotRecast.Recast.Toolset.Tools;
3030
using DotRecast.Recast.Demo.Draw;
3131
using DotRecast.Recast.Demo.UI;
32+
using DotRecast.Recast.Geom;
3233
using DotRecast.Recast.Toolset.Geom;
3334
using ImGuiNET;
3435
using Serilog;
@@ -88,9 +89,9 @@ public class DynamicUpdateSampleTool : ISampleTool
8889

8990
public DynamicUpdateSampleTool()
9091
{
91-
var bridgeGeom = DemoInputGeomProvider.LoadFile("bridge.obj");
92-
var houseGeom = DemoInputGeomProvider.LoadFile("house.obj");
93-
var convexGeom = DemoInputGeomProvider.LoadFile("convex.obj");
92+
var bridgeGeom = RcSampleInputGeomProvider.LoadFile("bridge.obj");
93+
var houseGeom = RcSampleInputGeomProvider.LoadFile("house.obj");
94+
var convexGeom = RcSampleInputGeomProvider.LoadFile("convex.obj");
9495
_tool = new(new RcRand(Random.Shared), bridgeGeom, houseGeom, convexGeom);
9596
executor = Task.Factory;
9697
}

src/DotRecast.Recast.Demo/Tools/OffMeshConnectionSampleTool.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ 3. This notice may not be removed or altered from any source distribution.
2020

2121
using DotRecast.Core.Numerics;
2222
using DotRecast.Recast.Demo.Draw;
23+
using DotRecast.Recast.Geom;
2324
using DotRecast.Recast.Toolset;
2425
using DotRecast.Recast.Toolset.Geom;
2526
using DotRecast.Recast.Toolset.Tools;
@@ -64,7 +65,7 @@ public void HandleRender(NavMeshRenderer renderer)
6465
dd.DebugDrawCross(_startPt.X, _startPt.Y + 0.1f, _startPt.Z, s, DuRGBA(0, 0, 0, 128), 2.0f);
6566
}
6667

67-
DemoInputGeomProvider geom = _sample.GetInputGeom();
68+
RcSampleInputGeomProvider geom = _sample.GetInputGeom();
6869
if (geom != null)
6970
{
7071
renderer.DrawOffMeshConnections(geom, true);
@@ -89,7 +90,7 @@ public void OnSampleChanged()
8990

9091
public void HandleClick(RcVec3f s, RcVec3f p, bool shift)
9192
{
92-
DemoInputGeomProvider geom = _sample.GetInputGeom();
93+
RcSampleInputGeomProvider geom = _sample.GetInputGeom();
9394
if (geom == null)
9495
{
9596
return;

src/DotRecast.Recast.Toolset/Builder/SoloNavMeshBuilder.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ 3. This notice may not be removed or altered from any source distribution.
1919

2020
using DotRecast.Core.Collections;
2121
using DotRecast.Detour;
22+
using DotRecast.Recast.Geom;
2223
using DotRecast.Recast.Toolset.Geom;
2324

2425
namespace DotRecast.Recast.Toolset.Builder
2526
{
2627
public class SoloNavMeshBuilder
2728
{
28-
public NavMeshBuildResult Build(DemoInputGeomProvider geom, RcNavMeshBuildSettings settings)
29+
public NavMeshBuildResult Build(RcSampleInputGeomProvider geom, RcNavMeshBuildSettings settings)
2930
{
3031
return Build(geom,
3132
RcPartitionType.OfValue(settings.partitioning),
@@ -39,7 +40,7 @@ public NavMeshBuildResult Build(DemoInputGeomProvider geom, RcNavMeshBuildSettin
3940
settings.keepInterResults);
4041
}
4142

42-
public NavMeshBuildResult Build(DemoInputGeomProvider geom,
43+
public NavMeshBuildResult Build(RcSampleInputGeomProvider geom,
4344
RcPartition partitionType,
4445
float cellSize, float cellHeight,
4546
float agentMaxSlope, float agentHeight, float agentRadius, float agentMaxClimb,
@@ -84,14 +85,14 @@ private DtNavMesh BuildNavMesh(DtMeshData meshData, int vertsPerPoly)
8485
return mesh;
8586
}
8687

87-
private RcBuilderResult BuildRecastResult(DemoInputGeomProvider geom, RcConfig cfg, bool keepInterResults)
88+
private RcBuilderResult BuildRecastResult(RcSampleInputGeomProvider geom, RcConfig cfg, bool keepInterResults)
8889
{
8990
RcBuilderConfig bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax());
9091
RcBuilder rcBuilder = new RcBuilder();
9192
return rcBuilder.Build(geom, bcfg, keepInterResults);
9293
}
9394

94-
public DtMeshData BuildMeshData(DemoInputGeomProvider geom,
95+
public DtMeshData BuildMeshData(RcSampleInputGeomProvider geom,
9596
float cellSize, float cellHeight,
9697
float agentHeight, float agentRadius, float agentMaxClimb,
9798
RcBuilderResult result)

src/DotRecast.Recast.Toolset/Builder/TileNavMeshBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private int GetTileBits(IRcInputGeomProvider geom, float cellSize, int tileSize)
168168
return tileBits;
169169
}
170170

171-
public int[] GetTiles(DemoInputGeomProvider geom, float cellSize, int tileSize)
171+
public int[] GetTiles(RcSampleInputGeomProvider geom, float cellSize, int tileSize)
172172
{
173173
RcRecast.CalcGridSize(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), cellSize, out var gw, out var gh);
174174
int tw = (gw + tileSize - 1) / tileSize;

src/DotRecast.Recast.Toolset/Tools/RcDynamicUpdateTool.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using DotRecast.Detour.Dynamic;
77
using DotRecast.Detour.Dynamic.Colliders;
88
using DotRecast.Detour.Dynamic.Io;
9+
using DotRecast.Recast.Geom;
910
using DotRecast.Recast.Toolset.Builder;
1011
using DotRecast.Recast.Toolset.Geom;
1112
using DotRecast.Recast.Toolset.Gizmos;
@@ -18,11 +19,11 @@ public class RcDynamicUpdateTool : IRcToolable
1819
private readonly Dictionary<long, RcGizmo> colliderGizmos;
1920

2021
private readonly IRcRand random;
21-
private readonly DemoInputGeomProvider bridgeGeom;
22-
private readonly DemoInputGeomProvider houseGeom;
23-
private readonly DemoInputGeomProvider convexGeom;
22+
private readonly RcSampleInputGeomProvider bridgeGeom;
23+
private readonly RcSampleInputGeomProvider houseGeom;
24+
private readonly RcSampleInputGeomProvider convexGeom;
2425

25-
public RcDynamicUpdateTool(IRcRand rand, DemoInputGeomProvider bridgeGeom, DemoInputGeomProvider houseGeom, DemoInputGeomProvider convexGeom)
26+
public RcDynamicUpdateTool(IRcRand rand, RcSampleInputGeomProvider bridgeGeom, RcSampleInputGeomProvider houseGeom, RcSampleInputGeomProvider convexGeom)
2627
{
2728
this.colliderGizmos = new Dictionary<long, RcGizmo>();
2829
this.random = rand;
@@ -297,7 +298,7 @@ public RcGizmo ConvexTrimesh(RcVec3f p, float walkableClimb)
297298
return new RcGizmo(collider, gizmo);
298299
}
299300

300-
private RcGizmo TrimeshCollider(RcVec3f p, DemoInputGeomProvider geom, float walkableClimb)
301+
private RcGizmo TrimeshCollider(RcVec3f p, RcSampleInputGeomProvider geom, float walkableClimb)
301302
{
302303
float[] verts = TransformVertices(p, geom, 0);
303304
var collider = new DtTrimeshCollider(verts, geom.faces, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD,
@@ -307,7 +308,7 @@ private RcGizmo TrimeshCollider(RcVec3f p, DemoInputGeomProvider geom, float wal
307308
return new RcGizmo(collider, gizmo);
308309
}
309310

310-
private float[] TransformVertices(RcVec3f p, DemoInputGeomProvider geom, float ax)
311+
private float[] TransformVertices(RcVec3f p, RcSampleInputGeomProvider geom, float ax)
311312
{
312313
var rx = RcMatrix4x4f.CreateFromRotate((float)random.NextDouble() * ax, 1, 0, 0);
313314
var ry = RcMatrix4x4f.CreateFromRotate((float)random.NextDouble() * 360, 0, 1, 0);

src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs renamed to src/DotRecast.Recast/Geom/RcSampleInputGeomProvider.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ 3. This notice may not be removed or altered from any source distribution.
2323
using DotRecast.Core;
2424
using DotRecast.Core.Collections;
2525
using DotRecast.Core.Numerics;
26-
using DotRecast.Recast.Geom;
2726

28-
namespace DotRecast.Recast.Toolset.Geom
27+
namespace DotRecast.Recast.Geom
2928
{
30-
public class DemoInputGeomProvider : IRcInputGeomProvider
29+
public class RcSampleInputGeomProvider : IRcInputGeomProvider
3130
{
3231
public readonly float[] vertices;
3332
public readonly int[] faces;
@@ -39,19 +38,19 @@ public class DemoInputGeomProvider : IRcInputGeomProvider
3938
private readonly List<RcOffMeshConnection> _offMeshConnections = new List<RcOffMeshConnection>();
4039
private readonly RcTriMesh _mesh;
4140

42-
public static DemoInputGeomProvider LoadFile(string objFilePath)
41+
public static RcSampleInputGeomProvider LoadFile(string objFilePath)
4342
{
4443
byte[] chunk = RcIO.ReadFileIfFound(objFilePath);
4544
var context = RcObjImporter.LoadContext(chunk);
46-
return new DemoInputGeomProvider(context.vertexPositions, context.meshFaces);
45+
return new RcSampleInputGeomProvider(context.vertexPositions, context.meshFaces);
4746
}
4847

49-
public DemoInputGeomProvider(List<float> vertexPositions, List<int> meshFaces) :
48+
public RcSampleInputGeomProvider(List<float> vertexPositions, List<int> meshFaces) :
5049
this(MapVertices(vertexPositions), MapFaces(meshFaces))
5150
{
5251
}
5352

54-
public DemoInputGeomProvider(float[] vertices, int[] faces)
53+
public RcSampleInputGeomProvider(float[] vertices, int[] faces)
5554
{
5655
this.vertices = vertices;
5756
this.faces = faces;

0 commit comments

Comments
 (0)