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.8 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Xml;
|
---|
4 |
|
---|
5 | namespace Oni.Xml
|
---|
6 | {
|
---|
7 | internal class TmbdXmlImporter : RawXmlImporter
|
---|
8 | {
|
---|
9 | private TmbdXmlImporter(XmlReader reader, BinaryWriter writer)
|
---|
10 | : base(reader, writer)
|
---|
11 | {
|
---|
12 | }
|
---|
13 |
|
---|
14 | public static void Import(XmlReader reader, BinaryWriter writer)
|
---|
15 | {
|
---|
16 | var importer = new TmbdXmlImporter(reader, writer);
|
---|
17 | importer.Import();
|
---|
18 | }
|
---|
19 |
|
---|
20 | private void Import()
|
---|
21 | {
|
---|
22 | Writer.Write(1);
|
---|
23 | int countPosition = Writer.Position;
|
---|
24 | Writer.Write(0);
|
---|
25 |
|
---|
26 | var materials = new Dictionary<string, List<string>>();
|
---|
27 |
|
---|
28 | while (Xml.IsStartElement("Material"))
|
---|
29 | {
|
---|
30 | string materialName = Xml.GetAttribute("Name");
|
---|
31 |
|
---|
32 | Xml.ReadStartElement();
|
---|
33 |
|
---|
34 | while (Xml.IsStartElement("Texture"))
|
---|
35 | {
|
---|
36 | string textureName = Xml.ReadElementContentAsString();
|
---|
37 |
|
---|
38 | List<string> textures;
|
---|
39 |
|
---|
40 | if (!materials.TryGetValue(materialName, out textures))
|
---|
41 | {
|
---|
42 | textures = new List<string>();
|
---|
43 | materials.Add(materialName, textures);
|
---|
44 | }
|
---|
45 |
|
---|
46 | textures.Add(textureName);
|
---|
47 | }
|
---|
48 |
|
---|
49 | Xml.ReadEndElement();
|
---|
50 | }
|
---|
51 |
|
---|
52 | int count = 0;
|
---|
53 |
|
---|
54 | foreach (var pair in materials)
|
---|
55 | {
|
---|
56 | foreach (string textureName in pair.Value)
|
---|
57 | {
|
---|
58 | Writer.Write(pair.Key, 32);
|
---|
59 | Writer.Write(textureName, 32);
|
---|
60 |
|
---|
61 | count++;
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | Writer.WriteAt(countPosition, count);
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.