ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/OniSplit/Xml/TmbdXmlExporter.cs
Revision: 1114
Committed: Wed Jan 22 14:08:57 2020 UTC (5 years, 8 months ago) by iritscen
File size: 1762 byte(s)
Log Message:
Adding OniSplit source code (v0.9.99.0). Many thanks to Neo for all his work over the years.

File Contents

# Content
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 }