public static void EnsureTilesLoaded() { if (PoolTiles != null) { return; } PoolTiles = new Modelled3DFloorTile[16]; for (int i = 0; i < 16; i++) { using (var file = File.Open($"Content/3D/floor/pool_hq_{i}.obj", FileMode.Open, FileAccess.Read, FileShare.Read)) { var obj = new OBJ(file); PoolTiles[i] = new Modelled3DFloorTile(obj, "pool.png"); } } CornerTiles = new Modelled3DFloorTile[4]; for (int i = 0; i < 4; i++) { using (var file = File.Open($"Content/3D/floor/poolcorner_hq_{i}.obj", FileMode.Open, FileAccess.Read, FileShare.Read)) { var obj = new OBJ(file); CornerTiles[i] = new Modelled3DFloorTile(obj, "pool.png"); } } }
protected void AppendTile(List <int> inds, List <TerrainParallaxVertex> verts, Modelled3DFloorTile tile, ushort index) { var tileBaseX = index % Bp.Width; var tileBaseY = index / Bp.Width; var baseInd = verts.Count; var srcInds = tile.Indices; var indLength = srcInds.Length; for (int i = 0; i < indLength; i++) { inds.Add(srcInds[i] + baseInd); } var baseX = (int)Math.Max(1, Math.Min(Bp.Width - 1, tileBaseX)); var baseY = (int)Math.Max(1, Math.Min(Bp.Height - 1, tileBaseY)); var nextX = (int)Math.Max(1, Math.Min(Bp.Width - 1, tileBaseX + 1)); var nextY = (int)Math.Max(1, Math.Min(Bp.Height - 1, tileBaseY + 1)); var Altitude = Bp.Altitude; var by = (baseY % Bp.Height) * Bp.Width; var bx = (baseX % Bp.Width); var ny = (nextY % Bp.Height) * Bp.Width; var nx = (nextX % Bp.Width); float h00 = Altitude[(by + bx)]; float h01 = Altitude[(ny + bx)]; float h10 = Altitude[(by + nx)]; float h11 = Altitude[(ny + nx)]; var tFactor = Bp.TerrainFactor; var srcVerts = tile.Vertices; for (int i = 0; i < srcVerts.Length; i++) { var vert = srcVerts[i]; var xLerp = vert.Position.X; var yLerp = vert.Position.Z; float xl1 = xLerp * h10 + (1 - xLerp) * h00; float xl2 = xLerp * h11 + (1 - xLerp) * h01; var yOff = (yLerp * xl2 + (1 - yLerp) * xl1) * tFactor; vert.Position = (vert.Position + new Microsoft.Xna.Framework.Vector3(tileBaseX, yOff, tileBaseY)) * 3f; verts.Add(vert); } }