示例#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 bool Converter(string srcPath, string dstPath)
        {
            var rules = AssetCooker.CookingRulesMap[Path.ChangeExtension(dstPath, originalTextureExtension)];

            if (rules.TextureAtlas != null)
            {
                // No need to cache this texture since it is a part of texture atlas.
                return(false);
            }
            using (var stream = File.OpenRead(srcPath)) {
                var bitmap = new Bitmap(stream);
                if (TextureTools.ShouldDownscale(AssetCooker.Platform, bitmap, rules))
                {
                    var scaledBitmap = TextureTools.DownscaleTexture(AssetCooker.Platform, bitmap, srcPath, rules);
                    bitmap.Dispose();
                    bitmap = scaledBitmap;
                }
                AssetCooker.ImportTexture(dstPath, bitmap, rules, File.GetLastWriteTime(srcPath), rules.SHA1);
                bitmap.Dispose();
            }
            return(true);
        }