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

View File

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

View File

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