public static void Write(VTTexture vtex, BinaryWriter writer) { writer.Write(vtex.Name); writer.Write(vtex.TexelOffsetX); writer.Write(vtex.TexelOffsetY); writer.Write(vtex.Width); writer.Write(vtex.Height); }
/// <summary> /// /// </summary> /// <param name="keyPath"></param> /// <param name="scene"></param> /// <param name="meshIndex"></param> public void AddTexture(VTTexture texture) { if (!textures.ContainsKey(texture.Name)) { textures.Add(texture.Name, texture); } else { Log.Warning("Duplicate virtual texture entry: {0}", texture.Name); } }
/// <summary> /// Creates VT tex table from INI-data and base directory /// </summary> /// <param name="iniData"></param> /// <param name="baseDirectory"></param> /// <returns></returns> VTTextureTable CreateVTTextureTable(IEnumerable <string> xmlFilePaths, BuildContext context, IStorage tileStorage) { var texTable = new VTTextureTable(); foreach (var xmlFile in xmlFilePaths) { using (var stream = File.OpenRead(xmlFile)) { var name = Path.GetFileNameWithoutExtension(xmlFile); var content = (VTTextureContent)Misc.LoadObjectFromXml(typeof(VTTextureContent), stream); var writeTime = File.GetLastWriteTimeUtc(xmlFile); if (content.SkipProcessing) { continue; } var tex = new VTTexture(content, name, context, writeTime); texTable.AddTexture(tex); } } return(texTable); }
/// <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("----------------"); }