MeshProcess

This commit is contained in:
ikpil 2023-09-05 00:06:19 +09:00
parent 5836fedc7b
commit 1008a15856
4 changed files with 59 additions and 57 deletions

View File

@ -43,7 +43,8 @@ namespace DotRecast.Recast.Toolset.Builder
option.ch = cellHeight;
option.buildBvTree = true;
option.offMeshConCount = geom.GetOffMeshConnections().Count;
var offMeshConnections = geom.GetOffMeshConnections();
option.offMeshConCount = offMeshConnections.Count;
option.offMeshConVerts = new float[option.offMeshConCount * 6];
option.offMeshConRad = new float[option.offMeshConCount];
option.offMeshConDir = new int[option.offMeshConCount];
@ -52,7 +53,7 @@ namespace DotRecast.Recast.Toolset.Builder
option.offMeshConUserID = new int[option.offMeshConCount];
for (int i = 0; i < option.offMeshConCount; i++)
{
RcOffMeshConnection offMeshCon = geom.GetOffMeshConnections()[i];
RcOffMeshConnection offMeshCon = offMeshConnections[i];
for (int j = 0; j < 6; j++)
{
option.offMeshConVerts[6 * i + j] = offMeshCon.verts[j];
@ -62,6 +63,7 @@ namespace DotRecast.Recast.Toolset.Builder
option.offMeshConDir[i] = offMeshCon.bidir ? 1 : 0;
option.offMeshConAreas[i] = offMeshCon.area;
option.offMeshConFlags[i] = offMeshCon.flags;
// option.offMeshConUserID[i] = offMeshCon.userId;
}
return option;

View File

@ -49,8 +49,7 @@ namespace DotRecast.Recast.Toolset.Builder
float detailSampleDist, float detailSampleMaxError,
bool filterLowHangingObstacles, bool filterLedgeSpans, bool filterWalkableLowHeightSpans)
{
RecastBuilderResult rcResult = BuildRecastResult(
geom,
RcConfig cfg = new RcConfig(
partitionType,
cellSize, cellHeight,
agentMaxSlope, agentHeight, agentRadius, agentMaxClimb,
@ -58,8 +57,10 @@ namespace DotRecast.Recast.Toolset.Builder
edgeMaxLen, edgeMaxError,
vertsPerPoly,
detailSampleDist, detailSampleMaxError,
filterLowHangingObstacles, filterLedgeSpans, filterWalkableLowHeightSpans);
filterLowHangingObstacles, filterLedgeSpans, filterWalkableLowHeightSpans,
SampleAreaModifications.SAMPLE_AREAMOD_WALKABLE, true);
RecastBuilderResult rcResult = BuildRecastResult(geom, cfg);
var meshData = BuildMeshData(geom, cellSize, cellHeight, agentHeight, agentRadius, agentMaxClimb, rcResult);
if (null == meshData)
{
@ -75,26 +76,8 @@ namespace DotRecast.Recast.Toolset.Builder
return new DtNavMesh(meshData, vertsPerPoly, 0);
}
private RecastBuilderResult BuildRecastResult(DemoInputGeomProvider geom,
RcPartition partitionType,
float cellSize, float cellHeight,
float agentMaxSlope, float agentHeight, float agentRadius, float agentMaxClimb,
int regionMinSize, int regionMergeSize,
float edgeMaxLen, float edgeMaxError,
int vertsPerPoly,
float detailSampleDist, float detailSampleMaxError,
bool filterLowHangingObstacles, bool filterLedgeSpans, bool filterWalkableLowHeightSpans)
private RecastBuilderResult BuildRecastResult(DemoInputGeomProvider geom, RcConfig cfg)
{
RcConfig cfg = new RcConfig(
partitionType,
cellSize, cellHeight,
agentMaxSlope, agentHeight, agentRadius, agentMaxClimb,
regionMinSize, regionMergeSize,
edgeMaxLen, edgeMaxError,
vertsPerPoly,
detailSampleDist, detailSampleMaxError,
filterLowHangingObstacles, filterLedgeSpans, filterWalkableLowHeightSpans,
SampleAreaModifications.SAMPLE_AREAMOD_WALKABLE, true);
RecastBuilderConfig bcfg = new RecastBuilderConfig(cfg, geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax());
RecastBuilder rcBuilder = new RecastBuilder();
return rcBuilder.Build(geom, bcfg);

View File

@ -1,6 +1,7 @@
using DotRecast.Detour;
using DotRecast.Detour.TileCache;
using DotRecast.Recast.Geom;
using DotRecast.Recast.Toolset.Builder;
namespace DotRecast.Recast.Toolset.Geom
{
@ -19,39 +20,54 @@ namespace DotRecast.Recast.Toolset.Geom
public void Process(DtNavMeshCreateParams option)
{
// // Update poly flags from areas.
// for (int i = 0; i < option.polyCount; ++i)
// {
// if (option.polyAreas[i] == DtTileCacheBuilder.DT_TILECACHE_WALKABLE_AREA)
// option.polyAreas[i] = SAMPLE_POLYAREA_GROUND;
//
// if (option.polyAreas[i] == SAMPLE_POLYAREA_GROUND ||
// option.polyAreas[i] == SAMPLE_POLYAREA_GRASS ||
// option.polyAreas[i] == SAMPLE_POLYAREA_ROAD)
// {
// option.polyFlags[i] = SAMPLE_POLYFLAGS_WALK;
// }
// else if (option.polyAreas[i] == SAMPLE_POLYAREA_WATER)
// {
// option.polyFlags[i] = SAMPLE_POLYFLAGS_SWIM;
// }
// else if (option.polyAreas[i] == SAMPLE_POLYAREA_DOOR)
// {
// option.polyFlags[i] = SAMPLE_POLYFLAGS_WALK | SAMPLE_POLYFLAGS_DOOR;
// }
// }
//
// // Pass in off-mesh connections.
// if (null != _geom)
// {
// option.offMeshConVerts = _geom.GetOffMeshConnectionVerts();
// option.offMeshConRad = _geom.GetOffMeshConnectionRads();
// option.offMeshConDir = _geom.GetOffMeshConnectionDirs();
// option.offMeshConAreas = _geom.GetOffMeshConnectionAreas();
// option.offMeshConFlags = _geom.GetOffMeshConnectionFlags();
// option.offMeshConUserID = _geom.GetOffMeshConnectionId();
// option.offMeshConCount = _geom.GetOffMeshConnectionCount();
// }
// Update poly flags from areas.
for (int i = 0; i < option.polyCount; ++i)
{
if (option.polyAreas[i] == DtTileCacheBuilder.DT_TILECACHE_WALKABLE_AREA)
option.polyAreas[i] = SampleAreaModifications.SAMPLE_POLYAREA_TYPE_GROUND;
if (option.polyAreas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_GROUND ||
option.polyAreas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_GRASS ||
option.polyAreas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD)
{
option.polyFlags[i] = SampleAreaModifications.SAMPLE_POLYFLAGS_WALK;
}
else if (option.polyAreas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER)
{
option.polyFlags[i] = SampleAreaModifications.SAMPLE_POLYFLAGS_SWIM;
}
else if (option.polyAreas[i] == SampleAreaModifications.SAMPLE_POLYAREA_TYPE_DOOR)
{
option.polyFlags[i] = SampleAreaModifications.SAMPLE_POLYFLAGS_WALK | SampleAreaModifications.SAMPLE_POLYFLAGS_DOOR;
}
}
// Pass in off-mesh connections.
if (null != _geom)
{
var offMeshConnections = _geom.GetOffMeshConnections();
option.offMeshConVerts = new float[option.offMeshConCount * 6];
option.offMeshConRad = new float[option.offMeshConCount];
option.offMeshConDir = new int[option.offMeshConCount];
option.offMeshConAreas = new int[option.offMeshConCount];
option.offMeshConFlags = new int[option.offMeshConCount];
option.offMeshConUserID = new int[option.offMeshConCount];
option.offMeshConCount = offMeshConnections.Count;
for (int i = 0; i < option.offMeshConCount; i++)
{
RcOffMeshConnection offMeshCon = offMeshConnections[i];
for (int j = 0; j < 6; j++)
{
option.offMeshConVerts[6 * i + j] = offMeshCon.verts[j];
}
option.offMeshConRad[i] = offMeshCon.radius;
option.offMeshConDir[i] = offMeshCon.bidir ? 1 : 0;
option.offMeshConAreas[i] = offMeshCon.area;
option.offMeshConFlags[i] = offMeshCon.flags;
// option.offMeshConUserID[i] = offMeshCon.userId;
}
}
}
}
}

View File

@ -31,6 +31,7 @@ namespace DotRecast.Recast.Geom
public readonly int area;
public readonly int flags;
public readonly int userId;
public RcOffMeshConnection(RcVec3f start, RcVec3f end, float radius, bool bidir, int area, int flags)
{