Пример #1
0
        public override List <MeshObject> GetMeshes()
        {
            if (Meshes == null)
            {
                List <Polygon2> polygons = GetPolygonsLocal();

                if (polygons.Count > 0)
                {
                    Meshes = new List <MeshObject>();

                    foreach (Polygon2 poly in polygons)
                    {
                        if (poly.points.Length < 3)
                        {
                            continue;
                        }

                        Mesh mesh = PolygonTriangulator2.Triangulate(poly, Vector2.zero, Vector2.zero, PolygonTriangulator2.Triangulation.Advanced);

                        if (mesh)
                        {
                            MeshObject meshObject = MeshObject.Get(mesh);

                            if (meshObject != null)
                            {
                                Meshes.Add(meshObject);
                            }
                        }
                    }
                }
            }
            return(Meshes);
        }
Пример #2
0
        public void GenerateFill(Transform transform, DayLightColliderShape shape, float height)
        {
            List <Polygon2> polys     = shape.GetPolygonsLocal();
            float           direction = Lighting2D.DayLightingSettings.direction * Mathf.Deg2Rad;

            foreach (Polygon2 polygon in polys)
            {
                if (polygon.points.Length < 2)
                {
                    continue;
                }

                Polygon2 worldPolygon = polygon.Copy();

                worldPolygon.ToScaleSelf(transform.localScale);
                worldPolygon.ToRotationSelf(transform.rotation.eulerAngles.z * Mathf.Deg2Rad);

                Polygon2           polygonShadow = GenerateShadow(worldPolygon, direction, height);
                List <DoublePair2> polygonPairs  = DoublePair2.GetList(polygonShadow.points);

                Polygon2 polygonShadowFill = polygonShadow.Copy();

                int pointsCount = polygonShadowFill.points.Length;

                for (int i = 0; i < pointsCount; i++)
                {
                    Vector2 a = polygonShadowFill.points[(i - 1 + pointsCount) % pointsCount];
                    Vector2 b = polygonShadowFill.points[i];
                    Vector2 c = polygonShadowFill.points[(i + 1) % pointsCount];

                    float angle_a = (float)System.Math.Atan2(a.y - b.y, a.x - b.x) + pi2;
                    float angle_c = (float)System.Math.Atan2(b.y - c.y, b.x - c.x) + pi2;

                    b.x += Mathf.Cos(angle_a) * 0.001f;
                    b.y += Mathf.Sin(angle_a) * 0.001f;

                    b.x += Mathf.Cos(angle_c) * 0.001f;
                    b.y += Mathf.Sin(angle_c) * 0.001f;

                    polygonShadowFill.points[i] = b;
                }

                polygonsPairs.Add(polygonPairs);

                Mesh mesh = PolygonTriangulator2.TriangulateSimple(polygonShadowFill, Vector2.zero, Vector2.zero);

                MeshObject meshObject = MeshObject.Get(mesh);

                if (meshObject != null)
                {
                    meshes.Add(meshObject);
                }
            }
        }
Пример #3
0
    public Mesh CreateMesh(GameObject gameObject, Vector2 UVScale, Vector2 UVOffset, PolygonTriangulator2.Triangulation triangulation = PolygonTriangulator2.Triangulation.Advanced)
    {
        if (gameObject.GetComponent <MeshRenderer>() == null)
        {
            gameObject.AddComponent <MeshRenderer>();
        }

        MeshFilter filter = gameObject.GetComponent <MeshFilter> ();

        if (filter == null)
        {
            filter = gameObject.AddComponent <MeshFilter>() as MeshFilter;
        }

        filter.sharedMesh = PolygonTriangulator2.Triangulate(this, UVScale, UVOffset, triangulation);
        if (filter.sharedMesh == null)
        {
            UnityEngine.Object.Destroy(gameObject);
        }

        return(filter.sharedMesh);
    }
Пример #4
0
 public Mesh CreateMesh(Vector2 UVScale, Vector2 UVOffset, PolygonTriangulator2.Triangulation triangulation = PolygonTriangulator2.Triangulation.Advanced)
 {
     return(PolygonTriangulator2.Triangulate(this, UVScale, UVOffset, triangulation));
 }