//Draws a polygon given a list of Vector3 that is a closed shape
        public GameObject dropPolygon(List <Vector3> shape, float height, Material material)
        {
            GameObject polygon = new GameObject("Polygon");

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

            Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon();
            poly.outside = shape;

            Mesh mesh = Poly2Mesh.CreateMesh(poly);

            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) * 100;
            }
            mesh.uv = uvs;

            if (height > 0)
            {
                mesh = SimpleExtruder.SliceExtrude(mesh, polygon, height, 4f, 4f, 10f);
            }

            filter.sharedMesh = mesh;
            renderer.material = material;

            polygon.AddComponent <MeshCollider> ();

            return(polygon);
        }
        //Draws a line given a list of vector 3
        public GameObject dropLine(List <Vector3> polyline, float witdh, float height, Material material, bool curved = false)
        {
            GameObject line = new GameObject("Polyline");

            MeshFilter   filter   = line.AddComponent <MeshFilter>();
            MeshRenderer renderer = line.AddComponent <MeshRenderer>();

            GOLineMesh lineMesh = new GOLineMesh(polyline, curved);

            lineMesh.width = witdh;
            lineMesh.load(line);
            Mesh mesh = lineMesh.mesh;

            if (height > 0)
            {
                mesh = SimpleExtruder.SliceExtrude(mesh, line, height, 4f, 4f, 10f);
            }

            filter.sharedMesh = mesh;
            renderer.material = material;

            line.AddComponent <MeshCollider> ();

            return(line);
        }
Esempio n. 3
0
        public GameObject BuildPolygon(GOLayer layer, float height)
        {
            if (feature.convertedGeometry.Count == 2 && feature.convertedGeometry[0].Equals(feature.convertedGeometry[1]))
            {
                return(null);
            }
            List <Vector3> clean = feature.convertedGeometry.Distinct().ToList();

            if (clean == null || clean.Count <= 2)
            {
                return(null);
            }

            GameObject polygon = new GameObject();

            Profiler.BeginSample("[GoMap] Start poly2mesh");
            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, true));
                }
            }
            Profiler.EndSample();

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

            meshRenderer = polygon.AddComponent <MeshRenderer>();

            Profiler.BeginSample("[GoMap] Create polygon mesh");
            try {
                mesh = Poly2Mesh.CreateMesh(poly);
            } catch {
            }
            Profiler.EndSample();


            if (mesh)
            {
                Profiler.BeginSample("[GoMap] Set polygon UV");
                Vector2[] uvs      = new Vector2[mesh.vertices.Length];
                Vector3[] vertices = mesh.vertices;
                for (int i = 0; i < uvs.Length; i++)
                {
                    uvs[i] = new Vector2(vertices[i].x, vertices[i].z);
                }
                mesh.uv = uvs;
                Profiler.EndSample();

                Profiler.BeginSample("[GoMap] instantiate mesh 2D");
                mesh2D = Mesh.Instantiate(mesh);
                Profiler.EndSample();

                Profiler.BeginSample("[GoMap] polygon extrusion");
                if (height > 0)
                {
                    mesh = SimpleExtruder.SliceExtrude(mesh, polygon, height, 4f, 4f, 10f);
//					mesh = SimpleExtruder.Extrude (mesh, polygon, height);
                }
                Profiler.EndSample();
            }


            filter.sharedMesh = mesh;

            if (layer.useColliders && mesh != null && feature.convertedGeometry.Count() > 2)
            {
                polygon.AddComponent <MeshCollider>().sharedMesh = mesh;
            }


            return(polygon);
        }