| 1 | using System; | 
 
 
 
 
 | 2 | using System.Collections.Generic; | 
 
 
 
 
 | 3 | using System.Xml; | 
 
 
 
 
 | 4 | using Oni.Imaging; | 
 
 
 
 
 | 5 | using Oni.Metadata; | 
 
 
 
 
 | 6 |  | 
 
 
 
 
 | 7 | namespace Oni.Xml | 
 
 
 
 
 | 8 | { | 
 
 
 
 
 | 9 | internal class TmbdXmlExporter : RawXmlExporter | 
 
 
 
 
 | 10 | { | 
 
 
 
 
 | 11 | private TmbdXmlExporter(BinaryReader reader, XmlWriter writer) | 
 
 
 
 
 | 12 | : base(reader, writer) | 
 
 
 
 
 | 13 | { | 
 
 
 
 
 | 14 | } | 
 
 
 
 
 | 15 |  | 
 
 
 
 
 | 16 | public static void Export(BinaryReader reader, XmlWriter writer) | 
 
 
 
 
 | 17 | { | 
 
 
 
 
 | 18 | var exporter = new TmbdXmlExporter(reader, writer); | 
 
 
 
 
 | 19 | exporter.Export(); | 
 
 
 
 
 | 20 | } | 
 
 
 
 
 | 21 |  | 
 
 
 
 
 | 22 | private void Export() | 
 
 
 
 
 | 23 | { | 
 
 
 
 
 | 24 | int size = Reader.ReadInt32(); | 
 
 
 
 
 | 25 | int version = Reader.ReadInt32(); | 
 
 
 
 
 | 26 | int count = Reader.ReadInt32(); | 
 
 
 
 
 | 27 |  | 
 
 
 
 
 | 28 | var materials = new Dictionary<string, List<string>>(count); | 
 
 
 
 
 | 29 |  | 
 
 
 
 
 | 30 | for (int i = 0; i < count; i++) | 
 
 
 
 
 | 31 | { | 
 
 
 
 
 | 32 | var materialName = Reader.ReadString(32); | 
 
 
 
 
 | 33 | var textureName = Reader.ReadString(32); | 
 
 
 
 
 | 34 |  | 
 
 
 
 
 | 35 | List<string> textures; | 
 
 
 
 
 | 36 |  | 
 
 
 
 
 | 37 | if (!materials.TryGetValue(materialName, out textures)) | 
 
 
 
 
 | 38 | { | 
 
 
 
 
 | 39 | textures = new List<string>(); | 
 
 
 
 
 | 40 | materials.Add(materialName, textures); | 
 
 
 
 
 | 41 | } | 
 
 
 
 
 | 42 |  | 
 
 
 
 
 | 43 | textures.Add(textureName); | 
 
 
 
 
 | 44 | } | 
 
 
 
 
 | 45 |  | 
 
 
 
 
 | 46 | Xml.WriteStartElement("TextureMaterials"); | 
 
 
 
 
 | 47 |  | 
 
 
 
 
 | 48 | foreach (var pair in materials) | 
 
 
 
 
 | 49 | { | 
 
 
 
 
 | 50 | Xml.WriteStartElement("Material"); | 
 
 
 
 
 | 51 | Xml.WriteAttributeString("Name", pair.Key); | 
 
 
 
 
 | 52 |  | 
 
 
 
 
 | 53 | foreach (var textureName in pair.Value) | 
 
 
 
 
 | 54 | Xml.WriteElementString("Texture", textureName); | 
 
 
 
 
 | 55 |  | 
 
 
 
 
 | 56 | Xml.WriteEndElement(); | 
 
 
 
 
 | 57 | } | 
 
 
 
 
 | 58 |  | 
 
 
 
 
 | 59 | Xml.WriteEndElement(); | 
 
 
 
 
 | 60 | } | 
 
 
 
 
 | 61 | } | 
 
 
 
 
 | 62 | } |