Ejemplo n.º 1
0
        public void GetExportPosition(out Rectf rect, out Vector2f pivot, out Vector4f border)
        {
            SpriteAtlas atlas = null;

            if (IsReadRendererData(File.Version))
            {
                atlas = SpriteAtlas.FindAsset(File);
            }
            Vector2f rectOffset;

            if (atlas == null)
            {
                Vector2f textureOffset = RD.TextureRect.Position;
                Vector2f textureSize   = RD.TextureRect.Size;
                rectOffset = RD.TextureRectOffset;                 // should be equal to RD.TextureRect.Position - Rect.Position
                rect       = new Rectf(textureOffset, textureSize);
            }
            else
            {
                SpriteAtlasData atlasData     = atlas.RenderDataMap[RenderDataKey];
                Vector2f        textureOffset = atlasData.TextureRect.Position;
                Vector2f        textureSize   = atlasData.TextureRect.Size;
                rectOffset = atlasData.TextureRectOffset;
                rect       = new Rectf(textureOffset, textureSize);
            }

            Vector2f sizeDif           = Rect.Size - rect.Size;
            Vector2f pivotShiftSize    = new Vector2f(Pivot.X * sizeDif.X, Pivot.Y * sizeDif.Y);
            Vector2f relPivotShiftPos  = new Vector2f(rectOffset.X / rect.Size.X, rectOffset.Y / rect.Size.Y);
            Vector2f relPivotShiftSize = new Vector2f(pivotShiftSize.X / rect.Size.X, pivotShiftSize.Y / rect.Size.Y);

            pivot = Pivot - relPivotShiftPos + relPivotShiftSize;

            float borderL = Border.X == 0.0f ? 0.0f : Border.X - rectOffset.X;
            float borderB = Border.Y == 0.0f ? 0.0f : Border.Y - rectOffset.Y;
            float borderR = Border.Z == 0.0f ? 0.0f : Border.Z + rectOffset.X - sizeDif.X;
            float borderT = Border.W == 0.0f ? 0.0f : Border.W + rectOffset.Y - sizeDif.Y;

            border = new Vector4f(borderL, borderB, borderR, borderT);
        }
Ejemplo n.º 2
0
        private IReadOnlyList <IReadOnlyList <Vector2f> > FixRotation(Vector2f[][] outlines)
        {
            bool isPacked = RD.IsPacked;
            SpritePackingRotation rotation = RD.PackingRotation;

            if (IsReadRendererData(File.Version))
            {
                SpriteAtlas atlas = SpriteAtlas.FindAsset(File);
                if (atlas != null)
                {
                    SpriteAtlasData atlasData = atlas.RenderDataMap[RenderDataKey];
                    isPacked = atlasData.IsPacked;
                    rotation = atlasData.PackingRotation;
                }
            }

            if (isPacked)
            {
                switch (rotation)
                {
                case SpritePackingRotation.FlipHorizontal:
                {
                    foreach (Vector2f[] outline in outlines)
                    {
                        for (int i = 0; i < outline.Length; i++)
                        {
                            Vector2f vertex = outline[i];
                            outline[i] = new Vector2f(-vertex.X, vertex.Y);
                        }
                    }
                }
                break;

                case SpritePackingRotation.FlipVertical:
                {
                    foreach (Vector2f[] outline in outlines)
                    {
                        for (int i = 0; i < outline.Length; i++)
                        {
                            Vector2f vertex = outline[i];
                            outline[i] = new Vector2f(vertex.X, -vertex.Y);
                        }
                    }
                }
                break;

                case SpritePackingRotation.Rotate90:
                {
                    foreach (Vector2f[] outline in outlines)
                    {
                        for (int i = 0; i < outline.Length; i++)
                        {
                            Vector2f vertex = outline[i];
                            outline[i] = new Vector2f(vertex.Y, vertex.X);
                        }
                    }
                }
                break;

                case SpritePackingRotation.Rotate180:
                {
                    foreach (Vector2f[] outline in outlines)
                    {
                        for (int i = 0; i < outline.Length; i++)
                        {
                            Vector2f vertex = outline[i];
                            outline[i] = new Vector2f(-vertex.X, -vertex.Y);
                        }
                    }
                }
                break;
                }
            }
            return(outlines);
        }