public SceneObject BuildSquareMesh(Func<int, int, bool> shouldNotRenderTile, MaterialFlags materialProperties, RectangleF bounds, string description = null)
{
var trianglesPerRow = MaxTileRows;
var trianglesPerCol = MaxTileColumns;
var triangles = new List<IndexedTriangleWithNormal>(trianglesPerRow * trianglesPerCol * 2);
for (var row = 0; row < trianglesPerRow; row++)
{
for (var col = 0; col < trianglesPerCol; col++)
{
if (shouldNotRenderTile(col, row)) continue;
var topLeft = GetIndexAt(row, col);
var topRight = GetIndexAt(row, col + 1);
var bottomLeft = GetIndexAt(row + 1, col);
var bottomRight = GetIndexAt(row + 1, col + 1);
if (IsOutOfBounds(topLeft, bounds)
&& IsOutOfBounds(topRight, bounds)
&& IsOutOfBounds(bottomLeft, bounds)
&& IsOutOfBounds(bottomRight, bounds))
continue;
triangles.Add(MakeTriangle(bottomLeft, topRight, topLeft));
triangles.Add(MakeTriangle(topRight, bottomLeft, bottomRight));
}
}
if (triangles.Count == 0)
{
return null;
}
var vertices = _vertices.ToArray();
return new SceneObject
{
Bounds = BoundingBox.FromPoints(vertices),
MaterialProperties = materialProperties,
Geometry = new TriangleMesh
{
Vertices = vertices,
Triangles = triangles.ToArray()
},
Description = description
};
}