public void Execute() { Dictionary <CellIndex, Cell> cellCenters = new Dictionary <CellIndex, Cell>(); ForEachCell1(size, v => { Vector3 vp = GetPosition(size, v); ForEachEdge((d1, d2, d3) => { CellIndex d1d2 = d1 + d2; Vector3 e = vp + GetPosition(size, d1d2) * .5f; Vector3 e1 = e + GetPosition(size, d3) * .5f; Vector3 e2 = e - GetPosition(size, d3) * .5f; int sign = entityField.GetMidpointSign(e1, e2); if (sign != 0) { Vector3 midPoint = entityField.GetMidPoint(e1, e2); AddCellCenter(cellCenters, midPoint, v); AddCellCenter(cellCenters, midPoint, v + d1); AddCellCenter(cellCenters, midPoint, v + d1d2); AddCellCenter(cellCenters, midPoint, v + d2); } }); }); ForEachCell2(size, v => { Vector3 vp = GetPosition(size, v); ForEachEdge((d1, d2, d3) => { CellIndex d1d2 = d1 + d2; Vector3 e = vp + GetPosition(size, d1d2) * .5f; Vector3 e1 = e + GetPosition(size, d3) * .5f; Vector3 e2 = e - GetPosition(size, d3) * .5f; int sign = entityField.GetMidpointSign(e1, e2); if (sign != 0) { var vd1 = v + d1; var vd2 = v + d2; var vd1d2 = vd1 + d2; var vd1p = GetCellCenter(cellCenters, vd1); var vd2p = GetCellCenter(cellCenters, vd2); var vd1d2p = GetCellCenter(cellCenters, vd1d2); Vector3 v1 = GetCellCenter(cellCenters, v); Vector3 v2 = GetCellCenter(cellCenters, vd1); Vector3 v3 = GetCellCenter(cellCenters, vd1d2); Vector3 v4 = GetCellCenter(cellCenters, vd2); if (sign > 0) { meshBuilder.AddQuad(v1, v4, v3, v2); } else { meshBuilder.AddQuad(v1, v2, v3, v4); } navMesh.Connect(v, vd1, v1, vd1p); navMesh.Connect(vd1, vd1d2, vd1p, vd1d2p); navMesh.Connect(v, vd1d2, v1, vd1d2p); navMesh.Connect(vd2, vd1d2, vd2p, vd1d2p); navMesh.Connect(v, vd2, v1, vd2p); //navMesh.Connect(vd1, vd2, vd1p, vd2p); } }); }); }