public void Compare() { ShapeRecognition recogniser = new ShapeRecognition(this); }
public MeshMan CreateMesh() { //MESH GO GameObject GO = Instantiate(trianglePref, trianglePref.transform.position, trianglePref.transform.rotation) as GameObject; MeshMan meshData = GO.GetComponent <MeshMan>(); meshData.nodes = new List <Vector2>(vertices); meshData.id = ShapeId; ShapeId++; Vector2 top = shape[0]; Vector2 bot = shape[0]; FindBoundingBounds(ref bot, ref top, ref shape); Debug.Log("BOUNDING BOUNDS " + bot + " " + top); for (int j = (int)bot.y; j < (int)top.y; j++) { for (int i = (int)bot.x; i < (int)top.x; i++) { if (PointInPolygon(new Vector2(i, j), ref shape)) { if (tiles[i, j] != 0) { graph[i, j].isConnected = true; } } } } // JUST FOR TESTING PURPOSES // ********************************************************************************* for (int i = 0; i < mapSizeX; i++) { for (int j = 0; j < mapSizeY; j++) { int tile = tiles[i, j]; if (tile != 0) { if (graph[i, j].isConnected) { graph[i, j].Go.GetComponent <SpriteRenderer>().color = Color.blue; } } } } // ********************************************************************************* // MESH RENDERER MeshRenderer mshRen = GO.GetComponent <MeshRenderer>(); ShapeRecognition shapeRec = FindObjectOfType <ShapeRecognition>(); Shape recognizedShape = shapeRec.ValidShape(); if (!FFA) { board.ProcessShape(recognizedShape); } if (recognizedShape != null) { //Debug.Log("VALID SHAPE, FILL WITH OTHER COLLOR"); mshRen.material = valid; meshData.shapes.Add(recognizedShape); } else { mshRen.material = invalid; } //Aray of nodes to list of vertices in world coordinates Vector2[] vertices2D = vertices.ToArray(); TileToWroldArray(ref vertices2D); // Fill shape with triagnels Triangulator tr = new Triangulator(vertices2D); int[] triangles = tr.Triangulate(); // Convert to Vector3 Vector3[] verticesV = new Vector3[vertices2D.Length]; for (int i = 0; i < verticesV.Length; i++) { verticesV[i] = new Vector3(vertices2D[i].x, vertices2D[i].y, 0); } Mesh msh = new Mesh(); msh.vertices = verticesV; msh.triangles = triangles; msh.RecalculateNormals(); msh.RecalculateBounds(); MeshFilter filter = GO.GetComponent <MeshFilter>(); GO.AddComponent <MeshCollider>(); GO.GetComponent <MeshCollider>().sharedMesh = msh; filter.mesh = msh; /* * foreach (var ele in map.vertices) * { * * Debug.Log(ele); * } * * for (int i = 0; i < triangles.Length; i++) * { * * Debug.Log(triangles[i]); * } */ return(meshData); }