コード例 #1
0
        //Draws a polygon given a list of Vector3 that is a closed shape
        public GameObject dropPolygon(List <Vector3> shape, float height, Material material, GOUVMappingStyle uvMappingStyle)
        {
            GameObject polygon = new GameObject("Polygon");

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

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

            GOMesh goMesh = Poly2Mesh.CreateMeshInBackground(poly);

            goMesh.uvMappingStyle = uvMappingStyle;
            goMesh.ApplyUV(shape);

            if (height > 0)
            {
                goMesh = SimpleExtruder.SliceExtrudePremesh(goMesh, height, 4f, 4f, 10f);
            }

            Mesh mesh = goMesh.ToSubmeshes();

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

            polygon.AddComponent <MeshCollider> ();

            return(polygon);
        }
コード例 #2
0
        public static GOMesh PreloadPolygon(GOFeature feature)
        {
            if (feature.convertedGeometry == null)
            {
                return(null);
            }

            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);
            }


            Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon();
            poly.outside = feature.convertedGeometry;
            if (feature.clips != null)
            {
                foreach (List <Vector3> clipVerts in feature.clips)
                {
                    poly.holes.Add(clipVerts);
                }
            }

            GOMesh goMesh = null;

            goMesh = Poly2Mesh.CreateMeshInBackground(poly);

            if (goMesh != null)
            {
                goMesh.uvMappingStyle = feature.layer.uvMappingStyle;
                goMesh.ApplyUV(feature.convertedGeometry);
                goMesh.Y = feature.y;

                if (feature.goTile.useElevation)
                {
                    feature.ComputeHighestAltitude();
                }

                if (feature.height > 0)
                {
                    feature.height      *= feature.goTile.worldScale;
                    goMesh.secondaryMesh = new GOMesh(goMesh);

                    float h = feature.height;

                    if (feature.goTile.useElevation)
                    {
                        h += GOFeature.BuildingElevationOffset;
                    }

                    h += Noise();
                    goMesh.separateTop = feature.renderingOptions.hasRoof;

                    if (feature.layer.slicedExtrusion)
                    {
                        goMesh = SimpleExtruder.SliceExtrudePremesh(goMesh, h, 4f, 4f, 10f * feature.goTile.worldScale);
                    }
                    else
                    {
                        goMesh = SimpleExtruder.ExtrudePremesh(goMesh, h);
                    }
                }

                if (feature.height < feature.layer.colliderHeight)
                {
                    float h = feature.layer.colliderHeight;
                    h *= feature.goTile.worldScale;
                    if (feature.goTile.useElevation)
                    {
                        h += GOFeature.BuildingElevationOffset;
                    }

                    goMesh.secondaryMesh = new GOMesh(goMesh);
                    goMesh.secondaryMesh = SimpleExtruder.SliceExtrudePremesh(goMesh.secondaryMesh, h, 4f, 4f, 10f * feature.goTile.worldScale);
                }
            }

            return(goMesh);
        }