public BuildingMesh(Building parent, BuildingLot lot) { this.parent = parent; name = "neo_building_mesh"; var list = MaterialManager.Instance.GetCollection("mat_walls"); material = list[Random.Range(0, list.Count)]; parent.AddCombinable(material.name, this); if (parent.floorHeight <= 0f) floorHeight = Random.Range(3.8f, 4f); else floorHeight = parent.floorHeight; if (parent.floorCount <= 0) floorCount = Util.RollDice(new float[] {0.15f, 0.7f, 0.15f}); else floorCount = parent.floorCount; FindMeshOrigin(lot.edges[0].start, lot.edges[2].start, lot.edges[1].start, lot.edges[3].start); boundaries = new Vector3[8]; boundaries[0] = lot.edges[0].start - meshOrigin; boundaries[1] = lot.edges[1].start - meshOrigin; boundaries[2] = lot.edges[2].start - meshOrigin; boundaries[3] = lot.edges[3].start - meshOrigin; for (int i = 0; i < 4; ++i) boundaries[i + 4] = boundaries[i] + height * Vector3.up; ConstructFaces(lot); ConstructFaceComponents(); ConstructRoof(); }
public BuildingMesh (Building parent, BuildingLot lot) { this.parent = parent; name = "neo_building_mesh"; var list = MaterialManager.Instance.GetCollection("mat_walls"); material = list[Random.Range(0, list.Count)]; parent.AddCombinable(material.name, this); if (parent.floorHeight <= 0f) floorHeight = Random.Range(3.8f, 4f); else floorHeight = parent.floorHeight; if (parent.floorCount <= 0) floorCount = Util.RollDice(new float[] {0.15f, 0.7f, 0.15f}); else floorCount = parent.floorCount; FindMeshOrigin(lot.edges[0].start, lot.edges[2].start, lot.edges[1].start, lot.edges[3].start); boundaries = new Vector3[8]; boundaries[0] = lot.edges[0].start - meshOrigin; boundaries[1] = lot.edges[1].start - meshOrigin; boundaries[2] = lot.edges[2].start - meshOrigin; boundaries[3] = lot.edges[3].start - meshOrigin; for (int i = 0; i < 4; ++i) boundaries[i + 4] = boundaries[i] + height * Vector3.up; ConstructFaces(lot); ConstructFaceComponents(); ConstructRoof(); }
public void Bisect () { if (_isFinal) { FindSidewalkNLotVerts(); CityMapManager.Instance.AddRoad(this); CityMapManager.Instance.AddSidewalk(this); initialLot = new BuildingLot(this); if (initialLot.isFinal()) { initialLot.freeEdges.AddRange(new int[] { 0, 1, 2, 3 }); finalLots.Add(initialLot); } else CreateBuildingLots(); CityMapManager.Instance.Add(this); return; } var big_offset = Random.Range(0f, _divergence * edges[0].length) * edges[0].direction; if (Util.RollDice(new float[] { 0.5f, 0.5f }) == 1) big_offset *= -1; var opp_offset = Random.Range(0f, _divergence * edges[2].length) * edges[2].direction; if (Util.RollDice(new float[] { 0.5f, 0.5f }) == 1) opp_offset *= -1; Block b1 = new Block(edges[3].start, edges[3].end, edges[0].middle + big_offset, edges[2].middle + opp_offset); b1.Bisect(); Block b2 = new Block(edges[1].start, edges[1].end, edges[2].middle + opp_offset, edges[0].middle + big_offset); b2.Bisect(); }
public Building (BuildingLot lot) { Init(); // must be _after_ the initialization of this object buildingMesh = new BuildingMesh(this, lot); gameObject = new GameObject("Neoclassical"); gameObject.transform.position = buildingMesh.meshOrigin; }
public Building(BuildingLot lot) { Init(); // must be _after_ the initialization of this object buildingMesh = new BuildingMesh(this, lot); gameObject = new GameObject("Neoclassical"); gameObject.transform.position = buildingMesh.meshOrigin; }
public void Build (BuildingLot lot) { var n = new Building(lot); n.buildingMesh.FindVertices(); n.buildingMesh.FindTriangles(); n.buildingMesh.Draw(); n.CombineSubmeshes(); n.gameObject.SetActiveRecursively(true); _buildings.Add(n); }
public void Build(BuildingLot lot) { var n = new Building(lot); n.buildingMesh.FindVertices(); n.buildingMesh.FindTriangles(); n.buildingMesh.Draw(); n.CombineSubmeshes(); n.gameObject.SetActiveRecursively(true); _buildings.Add(n); }
public void Build(BuildingLot lot) { var n = new Building(lot); n.buildingMesh.FindVertices(); n.buildingMesh.FindTriangles(); n.buildingMesh.Draw(); n.CombineSubmeshes(); n.gameObject.SetActive(true); foreach (Transform t in n.gameObject.transform) { t.gameObject.SetActive(true); } _buildings.Add(n); }
public void ConstructFaces (BuildingLot lot) { faces.Add(new Face(this, boundaries[0], boundaries[1], lot.freeEdges.Contains(0))); faces.Add(new Face(this, boundaries[1], boundaries[2], lot.freeEdges.Contains(1))); faces.Add(new Face(this, boundaries[2], boundaries[3], lot.freeEdges.Contains(2))); faces.Add(new Face(this, boundaries[3], boundaries[0], lot.freeEdges.Contains(3))); SortFaces(); }
public void Build (BuildingLot lot) { var n = new Building(lot); n.buildingMesh.FindVertices(); n.buildingMesh.FindTriangles(); n.buildingMesh.Draw(); n.CombineSubmeshes(); n.gameObject.SetActive(true); foreach (Transform t in n.gameObject.transform) { t.gameObject.SetActive(true); } _buildings.Add(n); }
public void ConstructFaces(BuildingLot lot) { faces.Add(new Face(this, boundaries[0], boundaries[1], lot.freeEdges.Contains(0))); faces.Add(new Face(this, boundaries[1], boundaries[2], lot.freeEdges.Contains(1))); faces.Add(new Face(this, boundaries[2], boundaries[3], lot.freeEdges.Contains(2))); faces.Add(new Face(this, boundaries[3], boundaries[0], lot.freeEdges.Contains(3))); SortFaces(); }
public void AddDrawableLot(BuildingLot lot) { lot.name = "buildinglot"; lot.material = MaterialManager.Instance.Get("mat_lot"); _drawableLots.Add(lot); }
public void Add(BuildingLot lot) { _lots.Add(lot); }
public void Add (BuildingLot lot) { _lots.Add(lot); }
public void AddDrawableLot (BuildingLot lot) { lot.name = "buildinglot"; lot.material = MaterialManager.Instance.Get("mat_lot"); _drawableLots.Add(lot); }
private void CreateBuildingLots() { var es = initialLot.edges; var minLength = initialLot.edges.Min(e => e.length); BuildingLot lot; if (minLength <= 16f) { lot = new BuildingLot(es[0].start, es[0].middle, es[2].middle, es[2].end); lot.freeEdges.AddRange(new int[] { 0, 2, 3 }); finalLots.Add(lot); lot = new BuildingLot(es[0].middle, es[0].end, es[2].start, es[2].middle); lot.freeEdges.AddRange(new int[] { 0, 1, 2 }); finalLots.Add(lot); return; } if (minLength <= 27f && initialLot.edges[0].length <= 30f) { var r = Util.RollDice(new float[] { 0.5f, 0.5f }); var pointBig = es[0].start + r / 3f * es[0].length * es[0].direction; var pointOpp = es[2].start + (3 - r) / 3f * es[2].length * es[2].direction; var pointMid = (pointBig + pointOpp) / 2; lot = new BuildingLot(es[1].start, es[1].middle, pointMid, pointBig); lot.freeEdges.AddRange(new int[] { 0, 3 }); finalLots.Add(lot); lot = new BuildingLot(es[1].middle, es[1].end, pointOpp, pointMid); lot.freeEdges.AddRange(new int[] { 0, 1 }); finalLots.Add(lot); lot = new BuildingLot(es[0].start, pointBig, pointMid, es[3].middle); lot.freeEdges.AddRange(new int[] { 0, 3 }); finalLots.Add(lot); lot = new BuildingLot(pointOpp, es[2].end, es[3].middle, pointMid); lot.freeEdges.AddRange(new int[] { 0, 1 }); finalLots.Add(lot); return; } if (minLength <= 27f && es[0].length <= 40f) { var bisector = new Edge(es[3].middle, es[1].middle); var r = Random.Range(11, 16); var p1big = es[0].start + r * es[0].direction; var p2big = p1big + Vector3.Distance(p1big, es[0].end) / 2 * es[0].direction; var p1mid = es[3].middle + r / es[0].length * bisector.length * bisector.direction; var p2mid = p1mid + Vector3.Distance(p1mid, bisector.end) / 2 * bisector.direction; lot = new BuildingLot(es[0].start, p1big, p1mid, bisector.start); lot.freeEdges.AddRange(new int[] { 0, 3 }); finalLots.Add(lot); lot = new BuildingLot(p1big, p2big, p2mid, p1mid); lot.freeEdges.Add(0); finalLots.Add(lot); lot = new BuildingLot(p2big, es[0].end, bisector.end, p2mid); lot.freeEdges.AddRange(new int[] { 0, 1 }); finalLots.Add(lot); var p1opp = es[2].start + r * es[2].direction; var p2opp = p1opp + Vector3.Distance(p1opp, es[2].end) / 2 * es[2].direction; var p3mid = es[1].middle - r / es[2].length * bisector.length * bisector.direction; var p4mid = p3mid - Vector3.Distance(p3mid, bisector.start) / 2 * bisector.direction; lot = new BuildingLot(es[2].start, p1opp, p3mid, es[1].middle); lot.freeEdges.AddRange(new int[] { 0, 3 }); finalLots.Add(lot); lot = new BuildingLot(p1opp, p2opp, p4mid, p3mid); lot.freeEdges.Add(0); finalLots.Add(lot); lot = new BuildingLot(p2opp, es[2].end, es[3].middle, p4mid); lot.freeEdges.AddRange(new int[] { 0, 1 }); finalLots.Add(lot); return; } // for initialLots larger than 40x27 CityMapManager.Instance.AddDrawableLot(initialLot); // big face range -> 11 - 20 // small face range -> 6 - 9 // therefore small = (3big + 21) / 9 float r1, r2; Vector3 p1, p2, p3, p4; for (int i = 0; i < 3; i+=2) while (es[i].length - initialLot.occupied[i] > 7f) { if (initialLot.pointsInEdge[i].Count == 0) { r1 = Random.Range(11, 20); r2 = (3 * r1 + 21) / 9f; p1 = es[i].start; p2 = p1 + r1 * es[i].direction; p4 = es[i].start - r2 * es[(i + 3) % 4].direction; p3 = Util.IntersectionPoint(p2, es[i].right, p4, es[i].direction); initialLot.pointsInEdge[i].Add(p2); initialLot.occupied[i] += r1; initialLot.pointsInEdge[(i + 3) % 4].Add(p4); initialLot.occupied[(i + 3) % 4] += r2; lot = new BuildingLot(p1, p2, p3, p4); lot.freeEdges.AddRange(new int[] { 0, 3 }); finalLots.Add(lot); } else { r1 = es[i].length - initialLot.occupied[i]; if (r1 > 31f) { r1 = Random.Range(11, 20); r2 = (3 * r1 + 21) / 9f; p1 = initialLot.pointsInEdge[i].Last(); p2 = p1 + r1 * es[i].direction; p3 = p2 + r2 * es[i].right; p4 = p1 + r2 * es[i].right; initialLot.pointsInEdge[i].Add(p2); initialLot.occupied[i] += r1; lot = new BuildingLot(p1, p2, p3, p4); lot.freeEdges.Add(0); finalLots.Add(lot); } else if (25f <= r1 && r1 <= 31f) { r1 = r1 / 2; r2 = (3 * r1 + 21) / 9f; p1 = initialLot.pointsInEdge[i].Last(); p2 = p1 + r1 * es[i].direction; p3 = p2 + r2 * es[i].right; p4 = p1 + r2 * es[i].right; initialLot.pointsInEdge[i].Add(p2); initialLot.occupied[i] += r1; lot = new BuildingLot(p1, p2, p3, p4); lot.freeEdges.Add(0); finalLots.Add(lot); } else if (19f <= r1 && r1 <= 25f) { r1 -= 7f; r2 = (3 * r1 + 21) / 9f; p1 = initialLot.pointsInEdge[i].Last(); p2 = p1 + r1 * es[i].direction; p3 = p2 + r2 * es[(i + 1) % 4].direction; p4 = p1 + r2 * es[i].right; initialLot.pointsInEdge[i].Add(p2); initialLot.occupied[i] += r1; lot = new BuildingLot(p1, p2, p3, p4); lot.freeEdges.Add(0); finalLots.Add(lot); } else if (11f <= r1 && r1 <= 19f) { r2 = (3 * r1 + 21) / 9f; p1 = initialLot.pointsInEdge[i].Last(); p2 = es[i].end; p3 = es[i].end + r2 * es[(i + 1) % 4].direction; p4 = Util.IntersectionPoint(p1, es[i].right, p3, es[i].direction); initialLot.pointsInEdge[(i + 1) % 4].Add(p3); initialLot.occupied[(i + 1) % 4] += r2; initialLot.occupied[i] += r1; lot = new BuildingLot(p1, p2, p3, p4); lot.freeEdges.AddRange(new int[] { 0, 1 }); finalLots.Add(lot); } else break; } } for (int i = 1; i < 4; i+=2) { if (initialLot.pointsInEdge[i].Count == 2) { if (Vector3.Distance(es[i].start, initialLot.pointsInEdge[i][0]) > Vector3.Distance(es[i].start, initialLot.pointsInEdge[i][1])) initialLot.pointsInEdge[i].Reverse(); r1 = Vector3.Distance(initialLot.pointsInEdge[i][0], initialLot.pointsInEdge[i][1]); if (r1 <= 12f) r2 = r1; else r2 = (3 * r1 + 21) / 9f; p1 = initialLot.pointsInEdge[i][0]; p2 = initialLot.pointsInEdge[i][1]; p3 = p2 + r2 * es[(i + 1) % 4].direction; p4 = p1 - r2 * es[(i + 3) % 4].direction; lot = new BuildingLot(p1, p2, p3, p4); lot.freeEdges.Add(0); finalLots.Add(lot); continue; } if (initialLot.pointsInEdge[i].Count == 1) { var dist = Vector3.Distance(es[i].start, initialLot.pointsInEdge[i][0]); if (dist < 22f) { p1 = es[i].start; p2 = initialLot.pointsInEdge[i][0]; p4 = initialLot.pointsInEdge[(i + 3) % 4].Last(); p3 = Util.IntersectionPoint(p4, es[i].direction, p2, es[(i + 1) % 4].direction); lot = new BuildingLot(p1, p2, p3, p4); lot.freeEdges.AddRange(new int[] { 0, 3 }); finalLots.Add(lot); } else { r1 = dist / 2; p1 = es[i].start; p2 = p1 + r1 * es[i].direction; p4 = initialLot.pointsInEdge[(i + 3) % 4].Last(); p3 = Util.IntersectionPoint(p4, es[(i + 0) % 4].direction, p2, es[i].right); lot = new BuildingLot(p1, p2, p3, p4); lot.freeEdges.AddRange(new int[] { 0, 3 }); finalLots.Add(lot); r2 = (3 * r1 + 21) / 9f; p1 = p2; p2 = initialLot.pointsInEdge[i][0]; p3 = p2 + r2 * es[(i + 1) % 4].direction; p4 = p1 + r2 * es[i].right; lot = new BuildingLot(p1, p2, p3, p4); lot.freeEdges.Add(0); finalLots.Add(lot); } } } }