コード例 #1
0
        public static Rectangle Compile(IEnumerable <SpriteAtlasEntry> Entries)
        {
            var entries = Entries.ToList();

            entries.Sort((A, B) =>
            {
                return((B.AtlasBounds.Width * B.AtlasBounds.Height) - (A.AtlasBounds.Width * A.AtlasBounds.Height));
            });

            // Find smallest power of 2 sized texture that can hold the largest entry.
            var largestEntry = entries[0];
            var texSize      = new Rectangle(0, 0, 1, 1);

            while (texSize.Width < largestEntry.AtlasBounds.Width)
            {
                texSize.Width *= 2;
            }
            while (texSize.Height < largestEntry.AtlasBounds.Height)
            {
                texSize.Height *= 2;
            }

            texSize = BspSubdivision.ExpandHorizontal(texSize, texSize, entries);
            return(texSize);
        }
コード例 #2
0
        public static Atlas Compile(List <Entry> Entries)
        {
            Entries.Sort((A, B) =>
            {
                return((B.Rect.Width * B.Rect.Height) - (A.Rect.Width * A.Rect.Height));
            });

            // Find smallest power of 2 sized texture that can hold the largest entry.
            var largestEntry = Entries[0];
            var texSize      = new Rectangle(0, 0, 1, 1);

            while (texSize.Width < largestEntry.Rect.Width)
            {
                texSize.Width *= 2;
            }
            while (texSize.Height < largestEntry.Rect.Height)
            {
                texSize.Height *= 2;
            }

            // Be sure to pass a copy of the list since the algorithm modifies it.
            texSize = BspSubdivision.ExpandHorizontal(texSize, texSize, new List <Entry>(Entries));
            return(new Atlas {
                Dimensions = texSize, Textures = Entries
            });
        }