small refactoring

This commit is contained in:
ikpil 2024-01-13 22:06:06 +09:00
parent f076d979ff
commit af5b70d7f4
3 changed files with 15 additions and 18 deletions

View File

@ -100,7 +100,7 @@ namespace DotRecast.Detour.Dynamic
Math.Min(DtDynamicNavMesh.MAX_VERTS_PER_POLY, config.vertsPerPoly), Math.Min(DtDynamicNavMesh.MAX_VERTS_PER_POLY, config.vertsPerPoly),
config.detailSampleDistance, config.detailSampleMaxError, config.detailSampleDistance, config.detailSampleMaxError,
true, true, true, default, true); true, true, true, default, true);
RcBuilderResult r = builder.Build(vt.tileX, vt.tileZ, null, rcConfig, heightfield, context); RcBuilderResult r = builder.Build(context, vt.tileX, vt.tileZ, null, rcConfig, heightfield);
if (config.keepIntermediateResults) if (config.keepIntermediateResults)
{ {
recastResult = r; recastResult = r;

View File

@ -166,14 +166,14 @@ namespace DotRecast.Recast
// //
// Step 1. Rasterize input polygon soup. // Step 1. Rasterize input polygon soup.
// //
RcHeightfield solid = RcVoxelizations.BuildSolidHeightfield(geom, builderCfg, ctx); RcHeightfield solid = RcVoxelizations.BuildSolidHeightfield(ctx, geom, builderCfg);
return Build(builderCfg.tileX, builderCfg.tileZ, geom, cfg, solid, ctx); return Build(ctx, builderCfg.tileX, builderCfg.tileZ, geom, cfg, solid);
} }
public RcBuilderResult Build(int tileX, int tileZ, IInputGeomProvider geom, RcConfig cfg, RcHeightfield solid, RcContext ctx) public RcBuilderResult Build(RcContext ctx, int tileX, int tileZ, IInputGeomProvider geom, RcConfig cfg, RcHeightfield solid)
{ {
FilterHeightfield(solid, cfg, ctx); FilterHeightfield(ctx, solid, cfg);
RcCompactHeightfield chf = BuildCompactHeightfield(geom, cfg, ctx, solid); RcCompactHeightfield chf = BuildCompactHeightfield(ctx, geom, cfg, solid);
// Partition the heightfield so that we can use simple algorithm later to triangulate the walkable areas. // Partition the heightfield so that we can use simple algorithm later to triangulate the walkable areas.
// There are 3 partitioning methods, each with some pros and cons: // There are 3 partitioning methods, each with some pros and cons:
@ -247,7 +247,7 @@ namespace DotRecast.Recast
/* /*
* Step 2. Filter walkable surfaces. * Step 2. Filter walkable surfaces.
*/ */
private void FilterHeightfield(RcHeightfield solid, RcConfig cfg, RcContext ctx) private void FilterHeightfield(RcContext ctx, RcHeightfield solid, RcConfig cfg)
{ {
// Once all geometry is rasterized, we do initial pass of filtering to // Once all geometry is rasterized, we do initial pass of filtering to
// remove unwanted overhangs caused by the conservative rasterization // remove unwanted overhangs caused by the conservative rasterization
@ -271,7 +271,7 @@ namespace DotRecast.Recast
/* /*
* Step 3. Partition walkable surface to simple regions. * Step 3. Partition walkable surface to simple regions.
*/ */
private RcCompactHeightfield BuildCompactHeightfield(IInputGeomProvider geom, RcConfig cfg, RcContext ctx, RcHeightfield solid) private RcCompactHeightfield BuildCompactHeightfield(RcContext ctx, IInputGeomProvider geom, RcConfig cfg, RcHeightfield solid)
{ {
// Compact the heightfield so that it is faster to handle from now on. // 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 // This will result more cache coherent data as well as the neighbours
@ -295,9 +295,9 @@ namespace DotRecast.Recast
public RcHeightfieldLayerSet BuildLayers(IInputGeomProvider geom, RcBuilderConfig builderCfg) public RcHeightfieldLayerSet BuildLayers(IInputGeomProvider geom, RcBuilderConfig builderCfg)
{ {
RcContext ctx = new RcContext(); RcContext ctx = new RcContext();
RcHeightfield solid = RcVoxelizations.BuildSolidHeightfield(geom, builderCfg, ctx); RcHeightfield solid = RcVoxelizations.BuildSolidHeightfield(ctx, geom, builderCfg);
FilterHeightfield(solid, builderCfg.cfg, ctx); FilterHeightfield(ctx, solid, builderCfg.cfg);
RcCompactHeightfield chf = BuildCompactHeightfield(geom, builderCfg.cfg, ctx, solid); RcCompactHeightfield chf = BuildCompactHeightfield(ctx, geom, builderCfg.cfg, solid);
RcLayers.BuildHeightfieldLayers(ctx, chf, builderCfg.cfg.BorderSize, builderCfg.cfg.WalkableHeight, out var lset); RcLayers.BuildHeightfieldLayers(ctx, chf, builderCfg.cfg.BorderSize, builderCfg.cfg.WalkableHeight, out var lset);
return lset; return lset;

View File

@ -25,7 +25,7 @@ namespace DotRecast.Recast
{ {
public static class RcVoxelizations public static class RcVoxelizations
{ {
public static RcHeightfield BuildSolidHeightfield(IInputGeomProvider geomProvider, RcBuilderConfig builderCfg, RcContext ctx) public static RcHeightfield BuildSolidHeightfield(RcContext ctx, IInputGeomProvider geomProvider, RcBuilderConfig builderCfg)
{ {
RcConfig cfg = builderCfg.cfg; RcConfig cfg = builderCfg.cfg;
@ -34,13 +34,10 @@ namespace DotRecast.Recast
// Allocate array that can hold triangle area types. // Allocate array that can hold triangle area types.
// If you have multiple meshes you need to process, allocate // If you have multiple meshes you need to process, allocate
// and array which can hold the max number of triangles you need to // and array which can hold the max number of triangles you need to process.
// process.
// Find triangles which are walkable based on their slope and rasterize // Find triangles which are walkable based on their slope and rasterize them.
// them. // If your input data is multiple meshes, you can transform them here, calculate
// If your input data is multiple meshes, you can transform them here,
// calculate
// the are type for each of the meshes and rasterize them. // the are type for each of the meshes and rasterize them.
foreach (RcTriMesh geom in geomProvider.Meshes()) foreach (RcTriMesh geom in geomProvider.Meshes())
{ {