/// <summary> /// Generates meshes for a cave. /// </summary> /// <exception cref="System.ArgumentException"></exception> /// <exception cref="System.ArgumentNullException"></exception> public static CaveMeshes GenerateCaveMeshes(WallGrid grid, CaveType type, IHeightMap floorHeightMap, IHeightMap ceilingHeightMap) { var generator = new MeshGenerator(); generator.Generate(grid, type, floorHeightMap, ceilingHeightMap); return(generator.ExtractMeshes()); }
void GenerateIsometric(WallGrid grid, IHeightMap floorHeightMap, IHeightMap ceilingHeightMap) { ceilingMesh = MeshBuilder.BuildCeiling(grid, ceilingHeightMap); outlines = OutlineGenerator.Generate(ceilingMesh); wallMesh = MeshBuilder.BuildWalls(outlines, floorHeightMap, ceilingHeightMap); floorMesh = MeshBuilder.BuildFloor(grid, floorHeightMap); }
void GenerateEnclosed(WallGrid grid, IHeightMap floorHeightMap, IHeightMap enclosureHeightMap) { floorMesh = MeshBuilder.BuildFloor(grid, floorHeightMap); outlines = OutlineGenerator.Generate(floorMesh, reverseOutlines: true); ceilingMesh = MeshBuilder.BuildEnclosure(floorMesh, enclosureHeightMap); wallMesh = MeshBuilder.BuildWalls(outlines, floorHeightMap, enclosureHeightMap); PruneWallsAtGlobalSeams(grid.Scale); }
static MeshData BuildFlatMesh(WallGrid grid, IHeightMap heightMap) { MeshData mesh = MapTriangulator.Triangulate(grid); mesh.uv = ComputeFlatUVArray(mesh.vertices); ApplyHeightMap(mesh.vertices, heightMap); return(mesh); }
static int ComputeConfiguration(WallGrid grid, int x, int y) { byte botLeft = grid[x, y]; byte botRight = grid[x + 1, y]; byte topRight = grid[x + 1, y + 1]; byte topLeft = grid[x, y + 1]; return(MarchingSquares.ComputeConfiguration(botLeft, botRight, topRight, topLeft)); }
MapTriangulator(WallGrid grid) { this.grid = grid; int maxPossibleVertices = grid.Length * grid.Width; vertexIndices = new VertexIndex[MarchingSquares.MAX_VERTICES_IN_TRIANGULATION]; localVertices = new List <LocalPosition>(maxPossibleVertices); triangles = new List <VertexIndex>(maxPossibleVertices * 6); vertexCache = new VertexLookup(grid.Length); }
internal FloorTester(WallGrid grid) { Assert.IsNotNull(grid); this.grid = grid; // WallGrids are immutable so we don't need to create a copy. scale = grid.Scale; scaleReciprocal = 1f / scale; xMax = (grid.Length - 1) * scale; zMax = (grid.Width - 1) * scale; wallCache = new WallCache(grid); }
public WallCache(WallGrid grid) { Assert.IsNotNull(grid); length = grid.Length; width = grid.Width; wallSums = new int[length, width]; for (int y = 0; y < width; y++) { for (int x = 0; x < length; x++) { wallSums[x, y] = grid[x, y] + GetWallSum(x - 1, y) + GetWallSum(x, y - 1) - GetWallSum(x - 1, y - 1); } } }
/// <summary> /// Generate the data necessary to produce meshes for a cave. Safe to execute outside the primary thread. /// Call ExtractMeshes to build and retrieve the meshes generated by this method. /// </summary> /// <exception cref="System.ArgumentException"></exception> /// <exception cref="System.ArgumentNullException"></exception> /// <param name="grid">Grid specifying walls and floors. Must have length and width at most 200.</param> public void Generate(WallGrid grid, CaveType type, IHeightMap floorHeightMap, IHeightMap ceilingHeightMap) { ValidateInput(grid, floorHeightMap, ceilingHeightMap); switch (type) { case CaveType.Isometric: GenerateIsometric(grid, floorHeightMap, ceilingHeightMap); break; case CaveType.Enclosed: GenerateEnclosed(grid, floorHeightMap, ceilingHeightMap); break; default: throw new System.ArgumentException("Unrecognized Cave Type."); } }
void ValidateInput(WallGrid grid, IHeightMap floorHeightMap, IHeightMap ceilingHeightMap) { if (grid == null) { throw new System.ArgumentNullException("grid"); } if (grid.Length > MAX_SIZE || grid.Width > MAX_SIZE) { throw new System.ArgumentException(string.Format("Max grid size is {0} by {0}", MAX_SIZE)); } if (floorHeightMap == null) { throw new System.ArgumentNullException("floorHeightMap"); } if (ceilingHeightMap == null) { throw new System.ArgumentNullException("ceilingHeightMap"); } }
public static MeshData BuildFloor(WallGrid grid, IHeightMap heightMap) { WallGrid invertedGrid = grid.Invert(); return(BuildFlatMesh(invertedGrid, heightMap)); }
public static MeshData BuildCeiling(WallGrid grid, IHeightMap heightMap) { return(BuildFlatMesh(grid, heightMap)); }
public static MeshData Triangulate(WallGrid grid) { var triangulator = new MapTriangulator(grid); return(triangulator.Triangulate()); }