Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dependencies"></param>
        /// <returns></returns>
        public Stream OpenTargetStream(IEnumerable <string> dependencies)
        {
            var dir = Path.GetDirectoryName(FullTargetPath);

            Directory.CreateDirectory(dir);

            var args = string.Join(" ", BuildArguments);

            return(AssetStream.OpenWrite(FullTargetPath, args, dependencies.Concat(new[] { KeyPath }).Distinct().ToArray()));
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="buildContext"></param>
        public override void Process(AssetSource assetFile, BuildContext context)
        {
            Log.Message("-------- Virtual Texture --------");

            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var xmlFiles = Directory.EnumerateFiles(Path.Combine(Builder.FullInputDirectory, "vt"), "*.xml").ToList();

            Log.Message("{0} megatexture segments", xmlFiles.Count);


            //
            //	Process tiles :
            //
            using (var tileStorage = context.GetVTStorage()) {
                var pageTable = CreateVTTextureTable(xmlFiles, context, tileStorage);


                //
                //	Get allocator and pack/repack textures :
                //
                Allocator2D allocator = null;

                if (tileStorage.FileExists(targetAllocator) && tileStorage.FileExists(targetMegatexture))
                {
                    Log.Message("Loading VT allocator...");

                    using (var allocStream = tileStorage.OpenRead(targetAllocator)) {
                        allocator = Allocator2D.LoadState(allocStream);
                        var targetTime = tileStorage.GetLastWriteTimeUtc(targetMegatexture);

                        Log.Message("Repacking textures to atlas...");
                        RepackTextureAtlas(pageTable, allocator, targetTime);
                    }
                }
                else
                {
                    allocator = new Allocator2D(VTConfig.VirtualPageCount);

                    Log.Message("Packing ALL textures to atlas...");
                    PackTextureAtlas(pageTable.SourceTextures, allocator);
                }

                Log.Message("Saving VT allocator...");

                using (var allocStream = tileStorage.OpenWrite(targetAllocator)) {
                    Allocator2D.SaveState(allocStream, allocator);
                }

                //
                //	Generate top-level pages :
                //
                Log.Message("Generating pages...");
                GenerateMostDetailedPages(pageTable.SourceTextures, context, pageTable, tileStorage);


                //
                //	Generate mip-maps :
                //
                Log.Message("Generating mipmaps...");
                for (int mip = 0; mip < VTConfig.MipCount - 1; mip++)
                {
                    Log.Message("Generating mip level {0}/{1}...", mip, VTConfig.MipCount);
                    GenerateMipLevels(context, pageTable, mip, tileStorage);
                }


                //
                //	Write asset :
                //
                using (var stream = tileStorage.OpenWrite(targetMegatexture)) {
                    using (var assetStream = AssetStream.OpenWrite(stream, "", new[] { "" })) {
                        using (var sw = new BinaryWriter(assetStream)) {
                            sw.Write(pageTable.SourceTextures.Count);

                            foreach (var tex in pageTable.SourceTextures)
                            {
                                VTTexture.Write(tex, sw);
                            }
                        }
                    }
                }
            }

            stopwatch.Stop();
            Log.Message("{0}", stopwatch.Elapsed.ToString());

            Log.Message("----------------");
        }