/// <summary> /// Loads the specified page. /// </summary> /// <param name="page">The page.</param> /// <param name="path">The path.</param> public void Load(AtlasPage page, string path) { path = Path.ChangeExtension(path, ".wpk"); Texture2D texture = this.assets.LoadAsset<Texture2D>(path); page.Texture = texture; page.Width = texture.Width; page.Height = texture.Height; }
/// <summary> /// Loads the specified reader. /// </summary> /// <param name="reader">The reader.</param> /// <param name="imagesDir">The images dir.</param> /// <param name="textureLoader">The texture loader.</param> /// <exception cref="System.ArgumentNullException">textureLoader cannot be null.</exception> private void Load(TextReader reader, string imagesDir, ITextureLoader textureLoader) { if (textureLoader == null) { throw new ArgumentNullException("textureLoader cannot be null."); } this.textureLoader = textureLoader; string[] tuple = new string[4]; AtlasPage page = null; while (true) { string line = reader.ReadLine(); if (line == null) { break; } if (line.Trim().Length == 0) { page = null; } else if (page == null) { page = new AtlasPage(); page.Name = line; page.Format = (Format)Enum.Parse(typeof(Format), this.ReadValue(reader), false); this.ReadTuple(reader, tuple); page.MinFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), tuple[0], true); page.MagFilter = (TextureFilter)Enum.Parse(typeof(TextureFilter), tuple[1], true); string direction = this.ReadValue(reader); page.UWrap = TextureWrap.ClampToEdge; page.VWrap = TextureWrap.ClampToEdge; if (direction == "x") { page.UWrap = TextureWrap.Repeat; } else if (direction == "y") { page.VWrap = TextureWrap.Repeat; } else if (direction == "xy") { page.UWrap = page.VWrap = TextureWrap.Repeat; } textureLoader.Load(page, Path.Combine(imagesDir, line)); this.Pages.Add(page); } else { AtlasRegion region = new AtlasRegion(); region.Name = line; region.Page = page; region.Rotate = bool.Parse(this.ReadValue(reader)); this.ReadTuple(reader, tuple); int x = int.Parse(tuple[0]); int y = int.Parse(tuple[1]); this.ReadTuple(reader, tuple); int width = int.Parse(tuple[0]); int height = int.Parse(tuple[1]); region.U = x / (float)page.Width; region.V = y / (float)page.Height; if (region.Rotate) { region.U2 = (x + height) / (float)page.Width; region.V2 = (y + width) / (float)page.Height; } else { region.U2 = (x + width) / (float)page.Width; region.V2 = (y + height) / (float)page.Height; } region.X = x; region.Y = y; region.Width = Math.Abs(width); region.Height = Math.Abs(height); if (this.ReadTuple(reader, tuple) == 4) { // split is optional region.Splits = new int[] { int.Parse(tuple[0]), int.Parse(tuple[1]), int.Parse(tuple[2]), int.Parse(tuple[3]) }; if (this.ReadTuple(reader, tuple) == 4) { // pad is optional, but only present with splits region.Pads = new int[] { int.Parse(tuple[0]), int.Parse(tuple[1]), int.Parse(tuple[2]), int.Parse(tuple[3]) }; this.ReadTuple(reader, tuple); } } region.OriginalWidth = int.Parse(tuple[0]); region.OriginalHeight = int.Parse(tuple[1]); this.ReadTuple(reader, tuple); region.OffsetX = int.Parse(tuple[0]); region.OffsetY = int.Parse(tuple[1]); region.Index = int.Parse(this.ReadValue(reader)); this.regions.Add(region); } } }