forked from bit/DotRecastNetSim
refactor: readonly struct DtPolyDetail
This commit is contained in:
parent
cd62e7f328
commit
ac3f667bcc
|
@ -97,11 +97,11 @@ namespace DotRecast.Detour.Extras.Unity.Astar
|
||||||
ymax = Math.Max(ymax, verts[nodes[i].verts[0] * 3 + 1]);
|
ymax = Math.Max(ymax, verts[nodes[i].verts[0] * 3 + 1]);
|
||||||
ymax = Math.Max(ymax, verts[nodes[i].verts[1] * 3 + 1]);
|
ymax = Math.Max(ymax, verts[nodes[i].verts[1] * 3 + 1]);
|
||||||
ymax = Math.Max(ymax, verts[nodes[i].verts[2] * 3 + 1]);
|
ymax = Math.Max(ymax, verts[nodes[i].verts[2] * 3 + 1]);
|
||||||
detailNodes[i] = new DtPolyDetail();
|
int vertBase = 0;
|
||||||
detailNodes[i].vertBase = 0;
|
int vertCount = 0;
|
||||||
detailNodes[i].vertCount = 0;
|
int triBase = i;
|
||||||
detailNodes[i].triBase = i;
|
int triCount = 1;
|
||||||
detailNodes[i].triCount = 1;
|
detailNodes[i] = new DtPolyDetail(vertBase, triBase, vertCount, triCount);
|
||||||
detailTris[4 * i] = 0;
|
detailTris[4 * i] = 0;
|
||||||
detailTris[4 * i + 1] = 1;
|
detailTris[4 * i + 1] = 1;
|
||||||
detailTris[4 * i + 2] = 2;
|
detailTris[4 * i + 2] = 2;
|
||||||
|
|
|
@ -1137,7 +1137,7 @@ namespace DotRecast.Detour
|
||||||
|
|
||||||
if (tile.data.detailMeshes != null)
|
if (tile.data.detailMeshes != null)
|
||||||
{
|
{
|
||||||
DtPolyDetail pd = tile.data.detailMeshes[ip];
|
ref DtPolyDetail pd = ref tile.data.detailMeshes[ip];
|
||||||
for (int i = 0; i < pd.triCount; i++)
|
for (int i = 0; i < pd.triCount; i++)
|
||||||
{
|
{
|
||||||
int ti = (pd.triBase + i) * 4;
|
int ti = (pd.triBase + i) * 4;
|
||||||
|
@ -1248,7 +1248,7 @@ namespace DotRecast.Detour
|
||||||
// Find height at the location.
|
// Find height at the location.
|
||||||
if (tile.data.detailMeshes != null)
|
if (tile.data.detailMeshes != null)
|
||||||
{
|
{
|
||||||
DtPolyDetail pd = tile.data.detailMeshes[ip];
|
ref DtPolyDetail pd = ref tile.data.detailMeshes[ip];
|
||||||
for (int j = 0; j < pd.triCount; ++j)
|
for (int j = 0; j < pd.triCount; ++j)
|
||||||
{
|
{
|
||||||
int t = (pd.triBase + j) * 4;
|
int t = (pd.triBase + j) * 4;
|
||||||
|
|
|
@ -545,15 +545,14 @@ namespace DotRecast.Detour
|
||||||
int vbase = 0;
|
int vbase = 0;
|
||||||
for (int i = 0; i < option.polyCount; ++i)
|
for (int i = 0; i < option.polyCount; ++i)
|
||||||
{
|
{
|
||||||
DtPolyDetail dtl = new DtPolyDetail();
|
|
||||||
navDMeshes[i] = dtl;
|
|
||||||
int vb = option.detailMeshes[i * 4 + 0];
|
int vb = option.detailMeshes[i * 4 + 0];
|
||||||
int ndv = option.detailMeshes[i * 4 + 1];
|
int ndv = option.detailMeshes[i * 4 + 1];
|
||||||
int nv = navPolys[i].vertCount;
|
int nv = navPolys[i].vertCount;
|
||||||
dtl.vertBase = vbase;
|
int vertBase = vbase;
|
||||||
dtl.vertCount = (ndv - nv);
|
int vertCount = (ndv - nv);
|
||||||
dtl.triBase = option.detailMeshes[i * 4 + 2];
|
int triBase = option.detailMeshes[i * 4 + 2];
|
||||||
dtl.triCount = option.detailMeshes[i * 4 + 3];
|
int triCount = option.detailMeshes[i * 4 + 3];
|
||||||
|
navDMeshes[i] = new DtPolyDetail(vertBase, triBase, vertCount, triCount);
|
||||||
// Copy vertices except the first 'nv' verts which are equal to
|
// Copy vertices except the first 'nv' verts which are equal to
|
||||||
// nav poly verts.
|
// nav poly verts.
|
||||||
if (ndv - nv != 0)
|
if (ndv - nv != 0)
|
||||||
|
@ -572,13 +571,12 @@ namespace DotRecast.Detour
|
||||||
int tbase = 0;
|
int tbase = 0;
|
||||||
for (int i = 0; i < option.polyCount; ++i)
|
for (int i = 0; i < option.polyCount; ++i)
|
||||||
{
|
{
|
||||||
DtPolyDetail dtl = new DtPolyDetail();
|
|
||||||
navDMeshes[i] = dtl;
|
|
||||||
int nv = navPolys[i].vertCount;
|
int nv = navPolys[i].vertCount;
|
||||||
dtl.vertBase = 0;
|
int vertBase = 0;
|
||||||
dtl.vertCount = 0;
|
int vertCount = 0;
|
||||||
dtl.triBase = tbase;
|
int triBase = tbase;
|
||||||
dtl.triCount = (nv - 2);
|
int triCount = (nv - 2);
|
||||||
|
navDMeshes[i] = new DtPolyDetail(vertBase, triBase, vertCount, triCount);
|
||||||
// Triangulate polygon (local indices).
|
// Triangulate polygon (local indices).
|
||||||
for (int j = 2; j < nv; ++j)
|
for (int j = 2; j < nv; ++j)
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,10 +56,8 @@ namespace DotRecast.Detour
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
DtPolyDetail pd = tile.data.detailMeshes[i];
|
ref DtPolyDetail pd = ref tile.data.detailMeshes[i];
|
||||||
|
|
||||||
if (pd != null)
|
|
||||||
{
|
|
||||||
RcVec3f[] verts = new RcVec3f[3];
|
RcVec3f[] verts = new RcVec3f[3];
|
||||||
for (int j = 0; j < pd.triCount; ++j)
|
for (int j = 0; j < pd.triCount; ++j)
|
||||||
{
|
{
|
||||||
|
@ -87,11 +85,6 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// FIXME: Use Poly if PolyDetail is unavailable
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,18 +21,26 @@ freely, subject to the following restrictions:
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
/** Defines the location of detail sub-mesh data within a dtMeshTile. */
|
/** Defines the location of detail sub-mesh data within a dtMeshTile. */
|
||||||
public class DtPolyDetail
|
public readonly struct DtPolyDetail
|
||||||
{
|
{
|
||||||
/** The offset of the vertices in the MeshTile::detailVerts array. */
|
/** The offset of the vertices in the MeshTile::detailVerts array. */
|
||||||
public int vertBase;
|
public readonly int vertBase;
|
||||||
|
|
||||||
/** The offset of the triangles in the MeshTile::detailTris array. */
|
/** The offset of the triangles in the MeshTile::detailTris array. */
|
||||||
public int triBase;
|
public readonly int triBase;
|
||||||
|
|
||||||
/** The number of vertices in the sub-mesh. */
|
/** The number of vertices in the sub-mesh. */
|
||||||
public int vertCount;
|
public readonly int vertCount;
|
||||||
|
|
||||||
/** The number of triangles in the sub-mesh. */
|
/** The number of triangles in the sub-mesh. */
|
||||||
public int triCount;
|
public readonly int triCount;
|
||||||
|
|
||||||
|
public DtPolyDetail(int vertBase, int triBase, int vertCount, int triCount)
|
||||||
|
{
|
||||||
|
this.vertBase = vertBase;
|
||||||
|
this.triBase = triBase;
|
||||||
|
this.vertCount = vertCount;
|
||||||
|
this.triCount = triCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -169,11 +169,11 @@ namespace DotRecast.Detour.Io
|
||||||
DtPolyDetail[] polys = new DtPolyDetail[header.detailMeshCount];
|
DtPolyDetail[] polys = new DtPolyDetail[header.detailMeshCount];
|
||||||
for (int i = 0; i < polys.Length; i++)
|
for (int i = 0; i < polys.Length; i++)
|
||||||
{
|
{
|
||||||
polys[i] = new DtPolyDetail();
|
int vertBase = buf.GetInt();
|
||||||
polys[i].vertBase = buf.GetInt();
|
int triBase = buf.GetInt();
|
||||||
polys[i].triBase = buf.GetInt();
|
int vertCount = buf.Get() & 0xFF;
|
||||||
polys[i].vertCount = buf.Get() & 0xFF;
|
int triCount = buf.Get() & 0xFF;
|
||||||
polys[i].triCount = buf.Get() & 0xFF;
|
polys[i] = new DtPolyDetail(vertBase, triBase, vertCount, triCount);
|
||||||
if (cCompatibility)
|
if (cCompatibility)
|
||||||
{
|
{
|
||||||
buf.GetShort(); // C struct padding
|
buf.GetShort(); // C struct padding
|
||||||
|
|
|
@ -255,9 +255,7 @@ public class RecastDebugDraw : DebugDraw
|
||||||
DtPoly p = tile.data.polys[index];
|
DtPoly p = tile.data.polys[index];
|
||||||
if (tile.data.detailMeshes != null)
|
if (tile.data.detailMeshes != null)
|
||||||
{
|
{
|
||||||
DtPolyDetail pd = tile.data.detailMeshes[index];
|
ref DtPolyDetail pd = ref tile.data.detailMeshes[index];
|
||||||
if (pd != null)
|
|
||||||
{
|
|
||||||
for (int j = 0; j < pd.triCount; ++j)
|
for (int j = 0; j < pd.triCount; ++j)
|
||||||
{
|
{
|
||||||
int t = (pd.triBase + j) * 4;
|
int t = (pd.triBase + j) * 4;
|
||||||
|
@ -278,7 +276,6 @@ public class RecastDebugDraw : DebugDraw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int j = 1; j < p.vertCount - 1; ++j)
|
for (int j = 1; j < p.vertCount - 1; ++j)
|
||||||
|
@ -367,7 +364,7 @@ public class RecastDebugDraw : DebugDraw
|
||||||
// This is really slow.
|
// This is really slow.
|
||||||
if (tile.data.detailMeshes != null)
|
if (tile.data.detailMeshes != null)
|
||||||
{
|
{
|
||||||
DtPolyDetail pd = tile.data.detailMeshes[i];
|
ref DtPolyDetail pd = ref tile.data.detailMeshes[i];
|
||||||
for (int k = 0; k < pd.triCount; ++k)
|
for (int k = 0; k < pd.triCount; ++k)
|
||||||
{
|
{
|
||||||
int t = (pd.triBase + k) * 4;
|
int t = (pd.triBase + k) * 4;
|
||||||
|
|
Loading…
Reference in New Issue