4 using System.Collections.Generic;
9 namespace SiliconStudio.TextureConverter
27 Layout =
new TexLayout();
37 : base(atlas.Data, atlas.DataSize, atlas.Width, atlas.Height, atlas.Depth, atlas.Format, atlas.MipmapCount, atlas.ArraySize, atlas.Dimension, atlas.FaceCount)
39 RowPitch = atlas.RowPitch;
40 SlicePitch = atlas.SlicePitch;
41 SubImageArray = atlas.SubImageArray;
43 DisposingLibrary = atlas.DisposingLibrary;
44 CurrentLibrary = atlas.CurrentLibrary;
45 LibraryData = atlas.LibraryData;
50 public override Object
Clone(
bool CopyMemory)
55 foreach (var entry
in Layout.TexList)
57 atlas.Layout.TexList.Add(entry.Key, entry.Value);
68 internal override void Rescale(
int width,
int height)
70 double ratio = (double)width / Width;
71 base.Rescale(width, height);
73 var texList =
new Dictionary<string, TexLayout.Position>();
74 TexLayout.Position current;
76 foreach (var entry
in Layout.TexList)
78 current = entry.Value;
79 current.Width = (int)(entry.Value.Width * ratio);
80 current.Height = (int)(entry.Value.Height * ratio);
81 current.UOffset = (int)(entry.Value.UOffset * ratio);
82 current.VOffset = (int)(entry.Value.VOffset * ratio);
84 texList.Add(entry.Key, current);
87 Layout.TexList = texList;
95 internal override void Flip(
Orientation orientation)
97 var texList =
new Dictionary<string, TexLayout.Position>();
98 TexLayout.Position current;
100 foreach (var entry
in Layout.TexList)
102 current = entry.Value;
103 if(orientation ==
Orientation.Horizontal) current.UOffset = Width - entry.Value.UOffset - entry.Value.Width;
104 else current.VOffset = Height - entry.Value.VOffset - entry.Value.Height;
106 texList.Add(entry.Key, current);
109 Layout.TexList = texList;
117 internal override void Save(
string file)
119 Layout.Export(Path.ChangeExtension(file, TexLayout.Extension));
131 public Dictionary<string, Position> TexList {
get;
internal set; }
137 public static readonly
string Extension =
".ats";
145 TexList =
new Dictionary<string, Position>();
159 public Position(
int uOffset,
int vVOffset,
int width,
int height)
169 return "u:" + UOffset +
", v:" + VOffset +
", w:" + Width +
", h:" + Height;
183 using (var file =
new StreamWriter(@filePath,
false))
185 XElement xml =
new XElement(
"texture-list");
188 foreach (var entry
in TexList)
190 xml.Add(
new XElement(
"texture",
191 new XAttribute(
"name", entry.Key),
192 new XAttribute(
"uOffset", entry.Value.UOffset),
193 new XAttribute(
"vOffset", entry.Value.VOffset),
194 new XAttribute(
"width", entry.Value.Width),
195 new XAttribute(
"height", entry.Value.Height)));
216 using (var reader = XmlReader.Create(file))
218 while (reader.ReadToFollowing(
"texture"))
220 texLayout.TexList.Add(
221 reader.GetAttribute(
"name"),
223 int.Parse(reader.GetAttribute(
"uOffset")),
224 int.Parse(reader.GetAttribute(
"vOffset")),
225 int.Parse(reader.GetAttribute(
"width")),
226 int.Parse(reader.GetAttribute(
"height"))
Contains the needed informatio to retrieve an inner texture from the corresponding texture atlas...
override Object Clone(bool CopyMemory)
Creates a new object that is a copy of the current instance.
TexAtlas(TexLayout layout, TexImage atlas)
Initializes a new instance of the TexAtlas class.
Position(int uOffset, int vVOffset, int width, int height)
TexLayout()
Initializes a new instance of the TexLayout class.
Describes the positions and size of every inner textures of a texture atlas
A texture atlas : a texture made from a composition of many textures.
override String ToString()
Temporary format containing texture data and information. Used as buffer between texture libraries...
Android.Widget.Orientation Orientation
static TexLayout Import(string file)
Create an instance of TexLayout from a layout file.
void Export(string filePath)
Exports the atlas layout into a specified file.