public override GameObject Generate() { int scale = configuration.Scale; Map map = configuration.MapGenerator.Generate(); Material floorMaterial = configuration.Material; IHeightMap heightMap = configuration.HeightMapModule.GetHeightMap(); OutlineModule outlinePrefabber = configuration.OutlineModule; GameObject cave = new GameObject("Cave"); Map[,] mapChunks = MapSplitter.Subdivide(map); mapChunks.ForEach((x, y) => { Coord index = new Coord(x, y); WallGrid grid = MapConverter.MapToWallGrid(mapChunks[x, y], scale, index); List <Vector3[]> outlines = meshGenerator.BuildOutlines(grid); CaveMeshes caveMeshes = BuildCaveMesh(grid, heightMap); Sector sector = BuildSector(caveMeshes, index, cave, floorMaterial); GameObject rockAnchor = BuildRockAnchor(sector.GameObject, index); BuildOutline(outlines, outlinePrefabber, rockAnchor.transform); }); return(cave); }
Sector BuildSector(CaveMeshes caveMeshes, Coord index, GameObject parent, Material mat) { Sector sector = new Sector(caveMeshes, index.x, index.y); sector.Floor.Material = mat; sector.GameObject.transform.parent = parent.transform; return(sector); }
void CreateMesh() { var wallGrid = new WallGrid(new byte[size, size], Vector3.zero); IHeightMap heightMap = parameters.ToHeightMap(); CaveMeshes meshes = MeshGenerator.GenerateCaveMeshes(wallGrid, CaveType.Isometric, heightMap, heightMap); mesh = meshes.Floor; }
internal Sector(CaveMeshes caveMeshes, string index) { GameObject = new GameObject(AppendIndex("Sector", index)); GameObject.SetActive(false); Ceiling = new Ceiling(caveMeshes.Ceiling, AppendIndex("Ceiling", index)); Walls = new Walls(caveMeshes.Walls, AppendIndex("Walls", index)); Floor = new Floor(caveMeshes.Floor, AppendIndex("Floor", index)); AddChild(Ceiling); AddChild(Walls); AddChild(Floor); }
public GameObject Generate(RockCaveConfiguration config, bool randomizeSeeds) { if (config == null) { throw new ArgumentNullException("config"); } string message = config.Validate(); if (message.Length > 0) { throw new ArgumentException(message, "config"); } if (randomizeSeeds) { config.SetSeed(GetRandomSeed()); } int scale = config.Scale; Map map = config.MapGenerator.Generate(); Material floorMaterial = config.Material; IHeightMap heightMap = config.HeightMapModule.GetHeightMap(); IOutlinePrefabber outlinePrefabber = config.OutlineModule.GetOutlinePrefabber(); GameObject cave = new GameObject("Cave"); Map[,] mapChunks = MapSplitter.Subdivide(map); mapChunks.ForEach((x, y) => { Coord index = new Coord(x, y); WallGrid grid = MapConverter.MapToWallGrid(mapChunks[x, y], scale, index); List <Vector3[]> outlines = MeshGenerator.BuildOutlines(grid); CaveMeshes caveMeshes = BuildCaveMesh(grid, heightMap); Sector sector = BuildSector(caveMeshes, index, cave, floorMaterial); GameObject rockAnchor = BuildRockAnchor(sector.GameObject, index); PlaceRocks(outlines, outlinePrefabber, rockAnchor.transform); }); return(cave); }
internal Sector(CaveMeshes caveMeshes, int x, int y) { string index = string.Format("{0},{1}", x, y); GameObject = new GameObject(AppendIndex(SECTOR_NAME, index)); if (caveMeshes.HasCeilingMesh) { Ceiling = new CaveComponent(caveMeshes.ExtractCeilingMesh(), AppendIndex(CEILING_NAME, index), addCollider: false); SetChild(Ceiling); } if (caveMeshes.HasFloorMesh) { Floor = new CaveComponent(caveMeshes.ExtractFloorMesh(), AppendIndex(FLOOR_NAME, index), true); SetChild(Floor); } if (caveMeshes.HasWallMesh) { Walls = new CaveComponent(caveMeshes.ExtractWallMesh(), AppendIndex(WALL_NAME, index), true); SetChild(Walls); } }
static CaveMeshes[,] GenerateCaveChunks(Map[,] mapChunks, ThreeTierCaveType type, int scale, IHeightMap floor, IHeightMap ceiling) { int xNumChunks = mapChunks.GetLength(0); int yNumChunks = mapChunks.GetLength(1); var caveChunks = new CaveMeshes[xNumChunks, yNumChunks]; var actions = new Action[mapChunks.Length]; mapChunks.ForEach((x, y) => { Coord index = new Coord(x, y); actions[y * xNumChunks + x] = new Action(() => { WallGrid grid = MapConverter.MapToWallGrid(mapChunks[x, y], scale, index); MeshData floorMesh = MeshGenerator.BuildFloor(grid, floor); MeshData ceilingMesh = SelectCeilingBuilder(type)(grid, ceiling); MeshData wallMesh = MeshGenerator.BuildWalls(grid, floor, ceiling); caveChunks[index.x, index.y] = new CaveMeshes(floorMesh, wallMesh, ceilingMesh); }); }); Execute(actions); return(caveChunks); }