Example #1
0
        public void TestPackEmptyAtlas()
        {
            TextureAtlas atlas = new TextureAtlas(AnimationSheetGenerator.GenerateDefaultAnimationExportSettings());

            DefaultTexturePacker packer = new DefaultTexturePacker();

            packer.Pack(atlas);

            Assert.AreEqual(new Rectangle(0, 0, 1, 1), atlas.AtlasRectangle, "Packing an empty texture atlas should result in an atlas with an empty area");
        }
Example #2
0
        public void TestPackEmptyFrames()
        {
            Animation anim = new Animation("TestAnim", 64, 64);

            // Fill the animation with a few empty frames
            anim.CreateFrame().ID = 1;
            anim.CreateFrame().ID = 2;

            TextureAtlas atlas = new TextureAtlas(AnimationSheetGenerator.GenerateDefaultAnimationExportSettings());

            atlas.InsertFramesFromAnimation(anim);

            DefaultTexturePacker packer = new DefaultTexturePacker();

            packer.Pack(atlas);

            Assert.AreEqual(new Rectangle(0, 0, 1, 1), atlas.AtlasRectangle, "Packing a texture atlas that contains empty frames should result in an atlas with a 1x1 area");
        }
Example #3
0
        /// <summary>
        /// Exports the given animations into an image sheet and returns the created sheet
        /// </summary>
        /// <param name="exportSettings">The export settings for the sheet</param>
        /// <param name="anims">The list of animations to export</param>
        /// <param name="name">The name for the generated texture atlas. Used for progress reports</param>
        /// <param name="cancellationToken">A cancelation token that is passed to the exporters and can be used to cancel the export process mid-way</param>
        /// <param name="progressHandler">Optional event handler for reporting the export progress</param>
        /// <returns>An image sheet representing the animations passed</returns>
        public async Task <TextureAtlas> GenerateAtlasFromAnimations(AnimationExportSettings exportSettings, Animation[] anims, string name = "", CancellationToken cancellationToken = new CancellationToken(), BundleExportProgressEventHandler progressHandler = null)
        {
            var atlas = new TextureAtlas(exportSettings, name);

            //
            // 1. Add the frames to the texture atlas
            //
            foreach (var anim in anims)
            {
                for (int i = 0; i < anim.FrameCount; i++)
                {
                    atlas.InsertFrame(anim.GetFrameAtIndex(i));
                }
            }

            //
            // 2. Pack the frames into the atlas
            //
            ITexturePacker packer = new DefaultTexturePacker();
            await packer.Pack(atlas, cancellationToken, progressHandler);

            return(atlas);
        }