source: OniSplit/Level/CameraImporter.cs@ 1193

Last change on this file since 1193 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: 2.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Xml;
5
6namespace Oni.Level
7{
8 using Physics;
9
10 partial class LevelImporter
11 {
12 private void ReadCameras(XmlReader xml, string basePath)
13 {
14 if (!xml.IsStartElement("Cameras"))
15 return;
16
17 if (xml.SkipEmpty())
18 return;
19
20 xml.ReadStartElement();
21
22 while (xml.IsStartElement())
23 ReadCamera(xml, basePath);
24
25 xml.ReadEndElement();
26 }
27
28 private void ReadCamera(XmlReader xml, string basePath)
29 {
30 var filePath = Path.Combine(basePath, xml.GetAttribute("Path"));
31 var scene = LoadScene(filePath);
32 var clips = new List<ObjectAnimationClip>();
33
34 if (filePath.Contains("Camout"))
35 {
36 Console.WriteLine(filePath);
37 }
38
39 ReadSequence(xml, "Camera", name =>
40 {
41 switch (name)
42 {
43 case "Animation":
44 clips.Add(ReadAnimationClip(xml));
45 return true;
46
47 default:
48 return false;
49 }
50 });
51
52 var props = new ObjectDaeNodeProperties();
53 props.HasPhysics = true;
54 props.Animations.AddRange(clips);
55
56 var importer = new ObjectDaeImporter(null, new Dictionary<string, Akira.AkiraDaeNodeProperties> { { scene.Id, props } });
57
58 importer.Import(scene);
59
60 foreach (var node in importer.Nodes)
61 {
62 foreach (var animation in node.Animations)
63 {
64 var writer = new DatWriter();
65 ObjectDatWriter.WriteAnimation(animation, writer);
66 writer.Write(outputDirPath);
67 }
68 }
69 }
70
71 private void ReadSequence(XmlReader xml, string name, Func<string, bool> action)
72 {
73 if (!xml.SkipEmpty())
74 {
75 xml.ReadStartElement(name);
76
77 while (xml.IsStartElement())
78 {
79 if (!action(xml.LocalName))
80 {
81 error.WriteLine("Unknown element {0}", xml.LocalName);
82 xml.Skip();
83 }
84 }
85
86 xml.ReadEndElement();
87 }
88 }
89 }
90}
Note: See TracBrowser for help on using the repository browser.