// Use this for initialization
	void Start () {
		Mesh mesh = GetComponent<MeshFilter>().mesh;
		vertices = mesh.vertices;
		normals = mesh.normals;
		triangles = mesh.triangles;
		meshStruct = new MeshStructure ();

		for (int i = 0; i < triangles.Length - 1; i+=3) {
			Face f = createFace (i);
			meshStruct.addFace (f);
		}

		meshStruct.recalculateLabels ();

		highMesh = new HighLevelMesh(meshStruct);
		highMesh.construct ();
		float num = UnityEngine.Random.value;
		if (num < 0.5f) {
			ModelBlackBricks module = new ModelBlackBricks (this.transform);
			module.apply (highMesh);
		} else {
			ModelRedBricks module = new ModelRedBricks (this.transform);
			module.apply (highMesh);
		}
	}
		public override bool apply (HighLevelMesh mesh)
		{
			List<MeshFilter> meshes = new List<MeshFilter> ();
			// Apply all corners
			meshes.AddRange(this.applyCorners (mesh.getCorners ()));

			// Apply all edges
			meshes.AddRange(this.applyEdges (mesh.getEdges ()));

			// Apply all regions
			meshes.AddRange(this.applyRegions (mesh.getRegions ()));


			MeshFilter[] meshFilters = meshes.ToArray ();

			CombineInstance[] combine = new CombineInstance[meshFilters.Length];
			int i = 0;
			while (i < meshFilters.Length) {
				combine[i].mesh = meshFilters[i].sharedMesh;
				combine[i].transform = meshFilters[i].transform.localToWorldMatrix;
				meshFilters [i].gameObject.SetActive (false);
				i++;
			}
			GameObject regionCombined = new GameObject ();
			regionCombined.name = "BlackBrickBuilding";
			regionCombined.AddComponent<MeshFilter> ();
			MeshRenderer renderer = regionCombined.AddComponent<MeshRenderer> ();
			regionCombined.GetComponent<MeshFilter>().mesh = new Mesh();
			regionCombined.GetComponent<MeshFilter>().mesh.CombineMeshes(combine);

			Material newMat = Resources.Load("Materials/Concrete_Asphalt_02", typeof(Material)) as Material;
			renderer.sharedMaterial = newMat;
			renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
			regionCombined.isStatic = true;
			regionCombined.gameObject.SetActive (true);

			return true;
		}
		public abstract bool apply (HighLevelMesh mesh);