示例#1
0
        private void CopyAllocatedItemsToAtlas(List <TextureTools.AtlasItem> items, string atlasChain, int atlasId, Size size)
        {
            var atlasPath   = AssetCooker.GetAtlasPath(atlasChain, atlasId);
            var atlasPixels = new Color4[size.Width * size.Height];

            foreach (var item in items.Where(i => i.Allocated))
            {
                var atlasRect = item.AtlasRect;
                using (var bitmap = TextureTools.OpenAtlasItemBitmapAndRescaleIfNeeded(AssetCooker.Platform, item)) {
                    CopyPixels(bitmap, atlasPixels, atlasRect.A.X, atlasRect.A.Y, size.Width, size.Height);
                }
                var atlasPart = new TextureAtlasElement.Params {
                    AtlasRect = atlasRect,
                    AtlasPath = Path.ChangeExtension(atlasPath, null)
                };
                var srcPath = Path.ChangeExtension(item.Path, item.SourceExtension);
                InternalPersistence.Instance.WriteObjectToBundle(AssetCooker.OutputBundle, item.Path, atlasPart, Persistence.Format.Binary,
                                                                 item.SourceExtension, AssetCooker.InputBundle.GetFileLastWriteTime(srcPath), AssetAttributes.None, item.CookingRules.SHA1);
                // Delete non-atlased texture since now its useless
                var texturePath = Path.ChangeExtension(item.Path, AssetCooker.GetPlatformTextureExtension());
                if (AssetCooker.OutputBundle.FileExists(texturePath))
                {
                    AssetCooker.DeleteFileFromBundle(texturePath);
                }
                UserInterface.Instance.IncreaseProgressBar();
            }
            Console.WriteLine("+ " + atlasPath);
            var firstItem = items.First(i => i.Allocated);

            using (var atlas = new Bitmap(atlasPixels, size.Width, size.Height)) {
                AssetCooker.ImportTexture(atlasPath, atlas, firstItem.CookingRules, AssetCooker.InputBundle.GetFileLastWriteTime(atlasPath), CookingRulesSHA1: null);
            }
        }
示例#2
0
        private static void CopyAllocatedItemsToAtlas(List <AtlasItem> items, string atlasChain, int atlasId, Size size)
        {
            var atlasPath   = GetAtlasPath(atlasChain, atlasId);
            var atlasPixels = new Color4[size.Width * size.Height];

            foreach (var item in items.Where(i => i.Allocated))
            {
                CopyPixels(item.Bitmap, atlasPixels, item.AtlasRect.A.X, item.AtlasRect.A.Y, size.Width, size.Height);
                var atlasPart = new TextureAtlasElement.Params();
                atlasPart.AtlasRect    = item.AtlasRect;
                atlasPart.AtlasRect.B -= new IntVector2(2, 2);
                atlasPart.AtlasPath    = Path.ChangeExtension(atlasPath, null);
                Serialization.WriteObjectToBundle(AssetBundle, item.Path, atlasPart, Serialization.Format.Binary,
                                                  item.SourceExtension, AssetAttributes.None, item.CookingRules.SHA1);
                // Delete non-atlased texture since now its useless
                var texturePath = Path.ChangeExtension(item.Path, GetPlatformTextureExtension());
                if (AssetBundle.FileExists(texturePath))
                {
                    DeleteFileFromBundle(texturePath);
                }
            }
            Console.WriteLine("+ " + atlasPath);
            var firstItem = items.First(i => i.Allocated);

            using (var atlas = new Bitmap(atlasPixels, size.Width, size.Height)) {
                ImportTexture(atlasPath, atlas, firstItem.CookingRules, CookingRulesSHA1: null);
            }
        }