forked from mirror/DotRecast
Tick 'Keep Intermediate Results' option.
This commit is contained in:
parent
97ffaf8700
commit
80e07ebb3c
|
@ -368,7 +368,7 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
|
|
||||||
var scale = (float)_resolution.X / 1920;
|
var scale = (float)_resolution.X / 1920;
|
||||||
int fontSize = Math.Max(10, (int)(16 * scale));
|
int fontSize = Math.Max(10, (int)(16 * scale));
|
||||||
|
|
||||||
// for windows : Microsoft Visual C++ Redistributable Package
|
// for windows : Microsoft Visual C++ Redistributable Package
|
||||||
// link - https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist
|
// link - https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist
|
||||||
var imGuiFontConfig = new ImGuiFontConfig(Path.Combine("resources\\fonts", "DroidSans.ttf"), fontSize, null);
|
var imGuiFontConfig = new ImGuiFontConfig(Path.Combine("resources\\fonts", "DroidSans.ttf"), fontSize, null);
|
||||||
|
@ -379,7 +379,7 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
|
|
||||||
DemoInputGeomProvider geom = LoadInputMesh("nav_test.obj");
|
DemoInputGeomProvider geom = LoadInputMesh("nav_test.obj");
|
||||||
_sample = new DemoSample(geom, ImmutableArray<RcBuilderResult>.Empty, null);
|
_sample = new DemoSample(geom, ImmutableArray<RcBuilderResult>.Empty, null);
|
||||||
|
|
||||||
_menuView = new RcMenuView();
|
_menuView = new RcMenuView();
|
||||||
settingsView = new RcSettingsView(this);
|
settingsView = new RcSettingsView(this);
|
||||||
settingsView.SetSample(_sample);
|
settingsView.SetSample(_sample);
|
||||||
|
@ -537,7 +537,7 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
bool hasBound = false;
|
bool hasBound = false;
|
||||||
RcVec3f bminN = RcVec3f.Zero;
|
RcVec3f bminN = RcVec3f.Zero;
|
||||||
RcVec3f bmaxN = RcVec3f.Zero;
|
RcVec3f bmaxN = RcVec3f.Zero;
|
||||||
|
|
||||||
if (_sample.GetInputGeom() != null)
|
if (_sample.GetInputGeom() != null)
|
||||||
{
|
{
|
||||||
bminN = _sample.GetInputGeom().GetMeshBoundsMin();
|
bminN = _sample.GetInputGeom().GetMeshBoundsMin();
|
||||||
|
@ -584,8 +584,8 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
RcVec3f bmin = bminN;
|
RcVec3f bmin = bminN;
|
||||||
RcVec3f bmax = bmaxN;
|
RcVec3f bmax = bmaxN;
|
||||||
|
|
||||||
camr = (float)(Math.Sqrt(RcMath.Sqr(bmax.X - bmin.X) +
|
camr = (float)(Math.Sqrt(RcMath.Sqr(bmax.X - bmin.X) +
|
||||||
RcMath.Sqr(bmax.Y - bmin.Y) +
|
RcMath.Sqr(bmax.Y - bmin.Y) +
|
||||||
RcMath.Sqr(bmax.Z - bmin.Z)) / 2);
|
RcMath.Sqr(bmax.Z - bmin.Z)) / 2);
|
||||||
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;
|
||||||
|
@ -692,14 +692,15 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
|
|
||||||
NavMeshBuildResult buildResult;
|
NavMeshBuildResult buildResult;
|
||||||
|
|
||||||
|
var geom = _sample.GetInputGeom();
|
||||||
var settings = _sample.GetSettings();
|
var settings = _sample.GetSettings();
|
||||||
if (settings.tiled)
|
if (settings.tiled)
|
||||||
{
|
{
|
||||||
buildResult = tileNavMeshBuilder.Build(_sample.GetInputGeom(), settings);
|
buildResult = tileNavMeshBuilder.Build(geom, settings);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
buildResult = soloNavMeshBuilder.Build(_sample.GetInputGeom(), settings);
|
buildResult = soloNavMeshBuilder.Build(geom, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!buildResult.Success)
|
if (!buildResult.Success)
|
||||||
|
|
|
@ -34,7 +34,8 @@ namespace DotRecast.Recast.Toolset.Builder
|
||||||
settings.edgeMaxLen, settings.edgeMaxError,
|
settings.edgeMaxLen, settings.edgeMaxError,
|
||||||
settings.vertsPerPoly,
|
settings.vertsPerPoly,
|
||||||
settings.detailSampleDist, settings.detailSampleMaxError,
|
settings.detailSampleDist, settings.detailSampleMaxError,
|
||||||
settings.filterLowHangingObstacles, settings.filterLedgeSpans, settings.filterWalkableLowHeightSpans);
|
settings.filterLowHangingObstacles, settings.filterLedgeSpans, settings.filterWalkableLowHeightSpans,
|
||||||
|
settings.keepInterResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavMeshBuildResult Build(DemoInputGeomProvider geom,
|
public NavMeshBuildResult Build(DemoInputGeomProvider geom,
|
||||||
|
@ -45,7 +46,8 @@ namespace DotRecast.Recast.Toolset.Builder
|
||||||
float edgeMaxLen, float edgeMaxError,
|
float edgeMaxLen, float edgeMaxError,
|
||||||
int vertsPerPoly,
|
int vertsPerPoly,
|
||||||
float detailSampleDist, float detailSampleMaxError,
|
float detailSampleDist, float detailSampleMaxError,
|
||||||
bool filterLowHangingObstacles, bool filterLedgeSpans, bool filterWalkableLowHeightSpans)
|
bool filterLowHangingObstacles, bool filterLedgeSpans, bool filterWalkableLowHeightSpans,
|
||||||
|
bool keepInterResults)
|
||||||
{
|
{
|
||||||
RcConfig cfg = new RcConfig(
|
RcConfig cfg = new RcConfig(
|
||||||
partitionType,
|
partitionType,
|
||||||
|
@ -58,7 +60,7 @@ namespace DotRecast.Recast.Toolset.Builder
|
||||||
filterLowHangingObstacles, filterLedgeSpans, filterWalkableLowHeightSpans,
|
filterLowHangingObstacles, filterLedgeSpans, filterWalkableLowHeightSpans,
|
||||||
SampleAreaModifications.SAMPLE_AREAMOD_WALKABLE, true);
|
SampleAreaModifications.SAMPLE_AREAMOD_WALKABLE, true);
|
||||||
|
|
||||||
RcBuilderResult rcResult = BuildRecastResult(geom, cfg);
|
RcBuilderResult rcResult = BuildRecastResult(geom, cfg, keepInterResults);
|
||||||
var meshData = BuildMeshData(geom, cellSize, cellHeight, agentHeight, agentRadius, agentMaxClimb, rcResult);
|
var meshData = BuildMeshData(geom, cellSize, cellHeight, agentHeight, agentRadius, agentMaxClimb, rcResult);
|
||||||
if (null == meshData)
|
if (null == meshData)
|
||||||
{
|
{
|
||||||
|
@ -74,11 +76,26 @@ namespace DotRecast.Recast.Toolset.Builder
|
||||||
return new DtNavMesh(meshData, vertsPerPoly, 0);
|
return new DtNavMesh(meshData, vertsPerPoly, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RcBuilderResult BuildRecastResult(DemoInputGeomProvider geom, RcConfig cfg)
|
private RcBuilderResult BuildRecastResult(DemoInputGeomProvider geom, RcConfig cfg, bool keepInterResults)
|
||||||
{
|
{
|
||||||
RcBuilderConfig bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax());
|
RcBuilderConfig bcfg = new RcBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax());
|
||||||
RcBuilder rcBuilder = new RcBuilder();
|
RcBuilder rcBuilder = new RcBuilder();
|
||||||
return rcBuilder.Build(geom, bcfg);
|
var result = rcBuilder.Build(geom, bcfg);
|
||||||
|
if (!keepInterResults)
|
||||||
|
{
|
||||||
|
return new RcBuilderResult(
|
||||||
|
result.TileX,
|
||||||
|
result.TileZ,
|
||||||
|
null,
|
||||||
|
result.CompactHeightfield,
|
||||||
|
result.ContourSet,
|
||||||
|
result.Mesh,
|
||||||
|
result.MeshDetail,
|
||||||
|
result.Context
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DtMeshData BuildMeshData(DemoInputGeomProvider geom,
|
public DtMeshData BuildMeshData(DemoInputGeomProvider geom,
|
||||||
|
|
|
@ -41,7 +41,8 @@ namespace DotRecast.Recast.Toolset.Builder
|
||||||
settings.minRegionSize, settings.mergedRegionSize,
|
settings.minRegionSize, settings.mergedRegionSize,
|
||||||
settings.edgeMaxLen, settings.edgeMaxError,
|
settings.edgeMaxLen, settings.edgeMaxError,
|
||||||
settings.vertsPerPoly, settings.detailSampleDist, settings.detailSampleMaxError,
|
settings.vertsPerPoly, settings.detailSampleDist, settings.detailSampleMaxError,
|
||||||
settings.filterLowHangingObstacles, settings.filterLedgeSpans, settings.filterWalkableLowHeightSpans);
|
settings.filterLowHangingObstacles, settings.filterLedgeSpans, settings.filterWalkableLowHeightSpans,
|
||||||
|
settings.keepInterResults, settings.buildAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NavMeshBuildResult Build(IInputGeomProvider geom,
|
public NavMeshBuildResult Build(IInputGeomProvider geom,
|
||||||
|
@ -53,7 +54,8 @@ namespace DotRecast.Recast.Toolset.Builder
|
||||||
float edgeMaxLen, float edgeMaxError,
|
float edgeMaxLen, float edgeMaxError,
|
||||||
int vertsPerPoly,
|
int vertsPerPoly,
|
||||||
float detailSampleDist, float detailSampleMaxError,
|
float detailSampleDist, float detailSampleMaxError,
|
||||||
bool filterLowHangingObstacles, bool filterLedgeSpans, bool filterWalkableLowHeightSpans)
|
bool filterLowHangingObstacles, bool filterLedgeSpans, bool filterWalkableLowHeightSpans,
|
||||||
|
bool keepInterResults, bool buildAll)
|
||||||
{
|
{
|
||||||
List<RcBuilderResult> results = BuildRecastResult(
|
List<RcBuilderResult> results = BuildRecastResult(
|
||||||
geom,
|
geom,
|
||||||
|
@ -65,7 +67,8 @@ namespace DotRecast.Recast.Toolset.Builder
|
||||||
edgeMaxLen, edgeMaxError,
|
edgeMaxLen, edgeMaxError,
|
||||||
vertsPerPoly,
|
vertsPerPoly,
|
||||||
detailSampleDist, detailSampleMaxError,
|
detailSampleDist, detailSampleMaxError,
|
||||||
filterLowHangingObstacles, filterLedgeSpans, filterWalkableLowHeightSpans
|
filterLowHangingObstacles, filterLedgeSpans, filterWalkableLowHeightSpans,
|
||||||
|
keepInterResults, buildAll
|
||||||
);
|
);
|
||||||
|
|
||||||
var tileMeshData = BuildMeshData(geom, cellSize, cellHeight, agentHeight, agentRadius, agentMaxClimb, results);
|
var tileMeshData = BuildMeshData(geom, cellSize, cellHeight, agentHeight, agentRadius, agentMaxClimb, results);
|
||||||
|
@ -82,7 +85,8 @@ namespace DotRecast.Recast.Toolset.Builder
|
||||||
float edgeMaxLen, float edgeMaxError,
|
float edgeMaxLen, float edgeMaxError,
|
||||||
int vertsPerPoly,
|
int vertsPerPoly,
|
||||||
float detailSampleDist, float detailSampleMaxError,
|
float detailSampleDist, float detailSampleMaxError,
|
||||||
bool filterLowHangingObstacles, bool filterLedgeSpans, bool filterWalkableLowHeightSpans)
|
bool filterLowHangingObstacles, bool filterLedgeSpans, bool filterWalkableLowHeightSpans,
|
||||||
|
bool keepInterResults, bool buildAll)
|
||||||
|
|
||||||
{
|
{
|
||||||
RcConfig cfg = new RcConfig(true, tileSize, tileSize,
|
RcConfig cfg = new RcConfig(true, tileSize, tileSize,
|
||||||
|
@ -125,8 +129,7 @@ namespace DotRecast.Recast.Toolset.Builder
|
||||||
{
|
{
|
||||||
int x = result.TileX;
|
int x = result.TileX;
|
||||||
int z = result.TileZ;
|
int z = result.TileZ;
|
||||||
DtNavMeshCreateParams option = DemoNavMeshBuilder
|
DtNavMeshCreateParams option = DemoNavMeshBuilder.GetNavMeshCreateParams(geom, cellSize, cellHeight, agentHeight, agentRadius, agentMaxClimb, result);
|
||||||
.GetNavMeshCreateParams(geom, cellSize, cellHeight, agentHeight, agentRadius, agentMaxClimb, result);
|
|
||||||
|
|
||||||
option.tileX = x;
|
option.tileX = x;
|
||||||
option.tileZ = z;
|
option.tileZ = z;
|
||||||
|
|
|
@ -94,7 +94,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
||||||
|
|
||||||
var beginTick = RcFrequency.Ticks;
|
var beginTick = RcFrequency.Ticks;
|
||||||
var rb = new RcBuilder();
|
var rb = new RcBuilder();
|
||||||
var result = rb.BuildTile(geom, cfg, bmin, bmax, tx, ty, new RcAtomicInteger(0), 1);
|
var result = rb.BuildTile(geom, cfg, bmin, bmax, tx, ty, new RcAtomicInteger(0), 1, settings.keepInterResults);
|
||||||
|
|
||||||
var tb = new TileNavMeshBuilder();
|
var tb = new TileNavMeshBuilder();
|
||||||
var meshData = tb.BuildMeshData(geom, settings.cellSize, settings.cellHeight, settings.agentHeight, settings.agentRadius, settings.agentMaxClimb, RcImmutableArray.Create(result)
|
var meshData = tb.BuildMeshData(geom, settings.cellSize, settings.cellHeight, settings.agentHeight, settings.agentRadius, settings.agentMaxClimb, RcImmutableArray.Create(result)
|
||||||
|
|
|
@ -48,7 +48,8 @@ namespace DotRecast.Recast
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RcBuilderResult> BuildTiles(IInputGeomProvider geom, RcConfig cfg,
|
public List<RcBuilderResult> BuildTiles(IInputGeomProvider geom, RcConfig cfg,
|
||||||
int threads = 0, TaskFactory taskFactory = null, CancellationToken cancellation = default)
|
int threads = 0, TaskFactory taskFactory = null, CancellationToken cancellation = default,
|
||||||
|
bool keepInterResults = false, bool buildAll = true)
|
||||||
{
|
{
|
||||||
RcVec3f bmin = geom.GetMeshBoundsMin();
|
RcVec3f bmin = geom.GetMeshBoundsMin();
|
||||||
RcVec3f bmax = geom.GetMeshBoundsMax();
|
RcVec3f bmax = geom.GetMeshBoundsMax();
|
||||||
|
@ -56,13 +57,14 @@ namespace DotRecast.Recast
|
||||||
|
|
||||||
if (1 < threads)
|
if (1 < threads)
|
||||||
{
|
{
|
||||||
return BuildMultiThread(geom, cfg, bmin, bmax, tw, th, threads, taskFactory ?? Task.Factory, cancellation);
|
return BuildMultiThread(geom, cfg, bmin, bmax, tw, th, threads, taskFactory ?? Task.Factory, cancellation, keepInterResults, buildAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
return BuildSingleThread(geom, cfg, bmin, bmax, tw, th);
|
return BuildSingleThread(geom, cfg, bmin, bmax, tw, th, keepInterResults, buildAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<RcBuilderResult> BuildSingleThread(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, int tw, int th)
|
private List<RcBuilderResult> BuildSingleThread(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, int tw, int th,
|
||||||
|
bool keepInterResults, bool buildAll)
|
||||||
{
|
{
|
||||||
var results = new List<RcBuilderResult>(th * tw);
|
var results = new List<RcBuilderResult>(th * tw);
|
||||||
RcAtomicInteger counter = new RcAtomicInteger(0);
|
RcAtomicInteger counter = new RcAtomicInteger(0);
|
||||||
|
@ -71,7 +73,7 @@ namespace DotRecast.Recast
|
||||||
{
|
{
|
||||||
for (int x = 0; x < tw; ++x)
|
for (int x = 0; x < tw; ++x)
|
||||||
{
|
{
|
||||||
var result = BuildTile(geom, cfg, bmin, bmax, x, y, counter, tw * th);
|
var result = BuildTile(geom, cfg, bmin, bmax, x, y, counter, tw * th, keepInterResults);
|
||||||
results.Add(result);
|
results.Add(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +82,8 @@ namespace DotRecast.Recast
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<RcBuilderResult> BuildMultiThread(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, int tw, int th,
|
private List<RcBuilderResult> BuildMultiThread(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, int tw, int th,
|
||||||
int threads, TaskFactory taskFactory, CancellationToken cancellation)
|
int threads, TaskFactory taskFactory, CancellationToken cancellation,
|
||||||
|
bool keepInterResults, bool buildAll)
|
||||||
{
|
{
|
||||||
var results = new ConcurrentQueue<RcBuilderResult>();
|
var results = new ConcurrentQueue<RcBuilderResult>();
|
||||||
RcAtomicInteger progress = new RcAtomicInteger(0);
|
RcAtomicInteger progress = new RcAtomicInteger(0);
|
||||||
|
@ -99,7 +102,7 @@ namespace DotRecast.Recast
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RcBuilderResult result = BuildTile(geom, cfg, bmin, bmax, tx, ty, progress, tw * th);
|
RcBuilderResult result = BuildTile(geom, cfg, bmin, bmax, tx, ty, progress, tw * th, keepInterResults);
|
||||||
results.Enqueue(result);
|
results.Enqueue(result);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -127,26 +130,41 @@ namespace DotRecast.Recast
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RcBuilderResult BuildTile(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, int tx, int ty, RcAtomicInteger progress, int total)
|
public RcBuilderResult BuildTile(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, int tx, int ty, RcAtomicInteger progress, int total, bool keepInterResults)
|
||||||
{
|
{
|
||||||
RcBuilderResult result = Build(geom, new RcBuilderConfig(cfg, bmin, bmax, tx, ty));
|
var bcfg = new RcBuilderConfig(cfg, bmin, bmax, tx, ty);
|
||||||
|
RcBuilderResult result = Build(geom, bcfg);
|
||||||
if (_progressListener != null)
|
if (_progressListener != null)
|
||||||
{
|
{
|
||||||
_progressListener.OnProgress(progress.IncrementAndGet(), total);
|
_progressListener.OnProgress(progress.IncrementAndGet(), total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!keepInterResults)
|
||||||
|
{
|
||||||
|
return new RcBuilderResult(
|
||||||
|
result.TileX,
|
||||||
|
result.TileZ,
|
||||||
|
null,
|
||||||
|
result.CompactHeightfield,
|
||||||
|
result.ContourSet,
|
||||||
|
result.Mesh,
|
||||||
|
result.MeshDetail,
|
||||||
|
result.Context
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RcBuilderResult Build(IInputGeomProvider geom, RcBuilderConfig builderCfg)
|
public RcBuilderResult Build(IInputGeomProvider geom, RcBuilderConfig bcfg)
|
||||||
{
|
{
|
||||||
RcConfig cfg = builderCfg.cfg;
|
RcConfig cfg = bcfg.cfg;
|
||||||
RcContext ctx = new RcContext();
|
RcContext ctx = new RcContext();
|
||||||
//
|
//
|
||||||
// Step 1. Rasterize input polygon soup.
|
// Step 1. Rasterize input polygon soup.
|
||||||
//
|
//
|
||||||
RcHeightfield solid = RcVoxelizations.BuildSolidHeightfield(ctx, geom, builderCfg);
|
RcHeightfield solid = RcVoxelizations.BuildSolidHeightfield(ctx, geom, bcfg);
|
||||||
return Build(ctx, builderCfg.tileX, builderCfg.tileZ, geom, cfg, solid);
|
return Build(ctx, bcfg.tileX, bcfg.tileZ, geom, cfg, solid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RcBuilderResult Build(RcContext ctx, int tileX, int tileZ, IInputGeomProvider geom, RcConfig cfg, RcHeightfield solid)
|
public RcBuilderResult Build(RcContext ctx, int tileX, int tileZ, IInputGeomProvider geom, RcConfig cfg, RcHeightfield solid)
|
||||||
|
|
Loading…
Reference in New Issue