public void Generate(Vector3[] surroundingPoints) //Should this take in a reference to the surrounding blocks? { if (generationDone == false && pointsSet == true) { //Do generation stuff Vector3[] origins; Vector3 bottomLeftCorner = new Vector3(-blockSize, 0f, -blockSize); Vector3 topRightCorner = new Vector3(blockSize * 2, 0f, blockSize * 2); Mesh[] buildingBases = VoroniMeshGenerator.GenerateVoroniIslands(pointList, surroundingPoints, bottomLeftCorner, topRightCorner, blockSize, blockSize, roadWidth, out origins); for (int i = 0; i < buildingCount; i++) { //Create 3 new buildings, one for the base layer, one for bottom side of top layer and one for top side of top layer BuildingGenerator newBuilding = Instantiate(buildingGeneratorPrefab); newBuilding.transform.SetParent(transform); newBuilding.SetBaseMesh(buildingBases[i], origins[i]); newBuilding.Generate(); Vector3 elevatedOrigin = origins[i] + (Vector3.up * topLayerElevation); //Reposition origin of mesh to be on the upper layer plane newBuilding = Instantiate(buildingGeneratorPrefab); newBuilding.transform.SetParent(transform); newBuilding.SetBaseMesh(buildingBases[i], elevatedOrigin); newBuilding.Generate(true); newBuilding = Instantiate(buildingGeneratorPrefab); newBuilding.transform.SetParent(transform); newBuilding.SetBaseMesh(buildingBases[i], elevatedOrigin); newBuilding.Generate(); } } generationDone = true; }
public void Initialize(Int2 index, int buildingCount, float blockSize, float roadWidth) { indexPosition = index; this.blockSize = blockSize; this.roadWidth = roadWidth; this.buildingCount = buildingCount; pointList = VoroniMeshGenerator.GeneratePointsList(blockSize, blockSize, buildingCount); //CreateBaseMesh(); pointsSet = true; }
public void Generate() { MeshFilter meshFilter = GetComponent <MeshFilter>(); Mesh mesh; if (meshFilter.sharedMesh == null) { mesh = new Mesh(); } else { mesh = meshFilter.sharedMesh; } VoroniMeshGenerator.GenerateVoroniMesh(mesh, regionSize.x, regionSize.y, regions); mesh.RecalculateNormals(); meshFilter.sharedMesh = mesh; //for (int i = 0; i < mesh.vertices.Length; i++) //{ // Debug.Log(mesh.vertices[i]); //} }