public MeshColumn(int id, Vector2 position, float height, Column.Type type) { this.id = id; this.vertices = new Vector3[12]; this.vertices[0] = new Vector3(position.x, height, position.y); this.vertices[1] = new Vector3(position.x, height, position.y + 1f); this.vertices[2] = new Vector3(position.x + 1f, height, position.y + 1f); this.vertices[3] = new Vector3(position.x + 1f, height, position.y); this.vertices[4] = this.vertices[0]; this.vertices[5] = this.vertices[0]; this.vertices[6] = this.vertices[1]; this.vertices[7] = this.vertices[1]; this.vertices[8] = this.vertices[2]; this.vertices[9] = this.vertices[2]; this.vertices[10] = this.vertices[3]; this.vertices[11] = this.vertices[3]; this.type = type; }
private LegoMap ComputeLegoMap() { //Initialisation int count = 0; LegoMap legoMap = new LegoMap(); legoMap.mapSize = legoMapSize; legoMap.mapScale = scale; legoMap.columns = new List <Column>(); Vector3 rayOrigin = transform.position - new Vector3( legoMapSize.x * scale / 2f, 0, legoMapSize.y * scale / 2f ); float minHeight = analyserHeight; //Map computation for (int x = 0; x < legoMapSize.x; x++) { for (int z = 0; z < legoMapSize.y; z++) { Vector3 rayPosition = rayOrigin + new Vector3( (x + 0.5f) * scale, 0, (z + 0.5f) * scale ); RaycastHit hit; float height = 0; Column.Type type = Column.Type.Default; if (Physics.Raycast(rayPosition, Vector3.down, out hit, analyserHeight, collisionMask)) { height = analyserHeight - hit.distance; if (height < minHeight) { minHeight = height; } if (hit.collider.tag == "Ground") { type = Column.Type.Ground; } if (hit.collider.tag == "Building") { type = Column.Type.Building; } } Column column = new Column(height, type); legoMap.columns.Add(column); } } // Conversion to legos for (int i = 0; i < legoMap.columns.Count; i++) { // Lowest height brought to 0 if (setGroundAt0) { if (legoMap.columns[i].height < minHeight) { legoMap.columns[i].height = 0; } else { legoMap.columns[i].height -= minHeight; } } legoMap.columns[i].height = Mathf.Round(legoMap.columns[i].height * verticalScaleMultiplicator); count += (int)legoMap.columns[i].height; } legoMap.legoCount = count; return(legoMap); }