Ejemplo n.º 1
0
        public override bool Equals(System.Object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            IndexedEdge p = (IndexedEdge)obj;

            return((index1 == p.index1) && (index2 == p.index2) || (index1 == p.index2) && (index2 == p.index1));
        }
Ejemplo n.º 2
0
        public static void GetSpriteData(Sprite sprite, out Vector2[] vertices, out IndexedEdge[] edges, out int[] indices)
        {
            int width  = 0;
            int height = 0;

            GetSpriteTextureSize(sprite, ref width, ref height);

            Vector2[] uvs = sprite.uv;

            vertices = new Vector2[uvs.Length];

            for (int i = 0; i < uvs.Length; ++i)
            {
                vertices[i] = new Vector2(uvs[i].x * width, uvs[i].y * height);
            }

            ushort[] l_indices = sprite.triangles;

            indices = new int[l_indices.Length];

            for (int i = 0; i < l_indices.Length; ++i)
            {
                indices[i] = (int)l_indices[i];
            }

            HashSet <IndexedEdge> edgesSet = new HashSet <IndexedEdge>();

            for (int i = 0; i < indices.Length; i += 3)
            {
                int index1 = indices[i];
                int index2 = indices[i + 1];
                int index3 = indices[i + 2];

                IndexedEdge edge1 = new IndexedEdge(index1, index2);
                IndexedEdge edge2 = new IndexedEdge(index2, index3);
                IndexedEdge edge3 = new IndexedEdge(index1, index3);

                if (edgesSet.Contains(edge1))
                {
                    edgesSet.Remove(edge1);
                }
                else
                {
                    edgesSet.Add(edge1);
                }

                if (edgesSet.Contains(edge2))
                {
                    edgesSet.Remove(edge2);
                }
                else
                {
                    edgesSet.Add(edge2);
                }

                if (edgesSet.Contains(edge3))
                {
                    edgesSet.Remove(edge3);
                }
                else
                {
                    edgesSet.Add(edge3);
                }
            }

            edges = new IndexedEdge[edgesSet.Count];
            int edgeIndex = 0;

            foreach (IndexedEdge edge in edgesSet)
            {
                edges[edgeIndex] = edge;
                ++edgeIndex;
            }
        }