source: OniSplit/Xml/TmbdXmlExporter.cs@ 1114

Last change on this file since 1114 was 1114, checked in by iritscen, 5 years ago

Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.

File size: 1.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Xml;
4using Oni.Imaging;
5using Oni.Metadata;
6
7namespace 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}
Note: See TracBrowser for help on using the repository browser.