public GameObject BuildPolygon(string name, Vector3 pos)
        {
            Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon();
            poly.outside = feature.convertedGeometry;
            if (feature.clips != null)
            {
                foreach (IList clipVerts in feature.clips)
                {
                    poly.holes.Add(GOFeature.CoordsToVerts(clipVerts));
                }
            }
            try
            {
                mesh = Poly2Mesh.CreateMesh(poly);
            }
            catch
            {
            }
            float   d     = 0f;
            Vector3 f_Pos = pos;

            for (int i = 0; i < mesh.vertices.Length; i++)
            {
                var l = Vector2.Distance(pos, mesh.vertices[i]);
                if (d < l)
                {
                    d     = l;
                    f_Pos = mesh.vertices[i];
                }
            }
            float ea_y = GetSC(f_Pos, pos);
            var   sc   = d / 1.414f;

            if (sc > 2f)
            {
                sc = sc / 4;
                GameObject polygon = new GameObject("polygon");
                polygon.transform.localPosition = pos;
                //for (int i = 0;i<2;i++)
                // {
                //    for (int j = 0;j<2;j++)
                //   {
                GameObject item = GameObject.Instantiate((GameObject)Resources.Load("Prefabs/CityBuildings/" + "B_10"));
                item.transform.localPosition    = pos;     //new Vector3((pos.x-sc/2)+sc*i,0, (pos.z - sc / 2) + sc * j) ;
                item.transform.localEulerAngles = new Vector3(0, ea_y, 0);
                item.transform.localScale       = Vector3.one * (sc * Global.tilesizeRank);
                item.transform.SetParent(polygon.transform);
                //  }
                //   }
                polygon.transform.Rotate(0, ea_y, 0);
                return(polygon);
            }
            else
            {
                if (sc < 0.8f)
                {
                    sc = 1f;
                }
                GameObject polygon = GameObject.Instantiate((GameObject)Resources.Load("Prefabs/CityBuildings/" + "B_" + UnityEngine.Random.Range(3, 10)));
                polygon.transform.localPosition    = pos;
                polygon.transform.localEulerAngles = new Vector3(0, ea_y, 0);
                polygon.transform.localScale       = Vector3.one * (sc * Global.tilesizeRank);
                return(polygon);
            }
        }
        public GameObject BuildPolygon(string name, GOLayer layer, float height)
        {
            //GameObject polygon = GameObject.Instantiate((GameObject)Resources.Load("Prefabs/CityBuildings/" + "Building_CornerHouse_A"));
            GameObject polygon = new GameObject();

            Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon();
            poly.outside = feature.convertedGeometry;
            if (feature.clips != null)
            {
                foreach (IList clipVerts in feature.clips)
                {
                    poly.holes.Add(GOFeature.CoordsToVerts(clipVerts));
                }
            }

            MeshFilter filter = polygon.AddComponent <MeshFilter>();

            polygon.AddComponent(typeof(MeshRenderer));

            try {
                mesh = Poly2Mesh.CreateMesh(poly);
            } catch {
            }
            if (height > 1)
            {
                if (mesh)
                {
                    Vector2[] uv2d = new Vector2[mesh.vertices.Length];
                    for (int i = 0; i < uv2d.Length; i++)
                    {
                        uv2d[i] = new Vector2(mesh.vertices[i].x, mesh.vertices[i].z);
                    }
                    var meshlemp = Mesh.Instantiate(mesh);
                    meshlemp.uv = uv2d;
                    mesh2D      = Mesh.Instantiate(meshlemp);

                    mesh.uv = uv2d;
                    if (height > 0)
                    {
                        mesh = SimpleExtruder.Extrude(mesh, polygon, height);
                        Vector2[] uvs3D = new Vector2[mesh.vertices.Length];
                        for (int i = 0; i < uvs3D.Length - 1; i++)
                        {
                            uvs3D[i] = new Vector2(Vector2.Distance(new Vector2(mesh.vertices[i + 1].x, mesh.vertices[i + 1].z), new Vector2(mesh.vertices[i].x, mesh.vertices[i].z)), mesh.vertices[i].y);
                        }
                        // uvs2[uvs2.Length - 1] = new Vector2(Mathf.Sqrt((float)(Math.Pow(mesh.vertices[0].x - mesh.vertices[uvs2.Length - 1].x, 2) + Math.Pow(mesh.vertices[0].z - mesh.vertices[uvs2.Length - 1].z, 2))), mesh.vertices[uvs2.Length - 1].y);
                        uvs3D[uvs3D.Length - 1] = new Vector2(10, mesh.vertices[uvs3D.Length - 1].y);
                        mesh.uv = uvs3D;
                    }
                }
            }
            else
            {
                if (mesh)
                {
                    Vector2[] uvs = new Vector2[mesh.vertices.Length];
                    for (int i = 0; i < uvs.Length; i++)
                    {
                        uvs[i] = new Vector2(mesh.vertices[i].x, mesh.vertices[i].z);
                    }
                    mesh.uv = uvs;
                    if (height > 0)
                    {
                        mesh = SimpleExtruder.Extrude(mesh, polygon, height);
                    }
                }
            }
            filter.sharedMesh = mesh;

            if (layer.useColliders)
            {
                polygon.AddComponent <MeshCollider>().sharedMesh = mesh;
            }
            return(polygon);
        }
Esempio n. 3
0
 public static bool IsGeoPolygonClockwise(IList coords)
 {
     return(IsClockwise(GOFeature.CoordsToVerts(coords)));
 }