diff options
Some more refactoring
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs')
-rw-r--r-- | OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs b/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs new file mode 100644 index 0000000..1176e13 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs | |||
@@ -0,0 +1,145 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using System.Xml; | ||
5 | using System.IO; | ||
6 | using libsecondlife; | ||
7 | using Axiom.Math; | ||
8 | using OpenSim.Framework; | ||
9 | using OpenSim.Region.Physics.Manager; | ||
10 | |||
11 | namespace OpenSim.Region.Environment.Scenes | ||
12 | { | ||
13 | public class SceneXmlLoader //Most likely can move to a module | ||
14 | { | ||
15 | protected InnerScene m_innerScene; | ||
16 | protected RegionInfo m_regInfo; | ||
17 | protected Scene m_parentScene; | ||
18 | |||
19 | public SceneXmlLoader(Scene parentScene, InnerScene innerScene, RegionInfo regionInfo) | ||
20 | { | ||
21 | m_parentScene = parentScene; | ||
22 | m_innerScene = innerScene; | ||
23 | m_regInfo = regionInfo; | ||
24 | } | ||
25 | |||
26 | public void LoadPrimsFromXml(string fileName) | ||
27 | { | ||
28 | XmlDocument doc = new XmlDocument(); | ||
29 | XmlNode rootNode; | ||
30 | int primCount = 0; | ||
31 | if (fileName.StartsWith("http:") || File.Exists(fileName)) | ||
32 | { | ||
33 | XmlTextReader reader = new XmlTextReader(fileName); | ||
34 | reader.WhitespaceHandling = WhitespaceHandling.None; | ||
35 | doc.Load(reader); | ||
36 | reader.Close(); | ||
37 | rootNode = doc.FirstChild; | ||
38 | foreach (XmlNode aPrimNode in rootNode.ChildNodes) | ||
39 | { | ||
40 | SceneObjectGroup obj = new SceneObjectGroup(m_parentScene, | ||
41 | m_regInfo.RegionHandle, aPrimNode.OuterXml); | ||
42 | //if we want this to be a import method then we need new uuids for the object to avoid any clashes | ||
43 | //obj.RegenerateFullIDs(); | ||
44 | m_innerScene.AddEntity(obj); | ||
45 | |||
46 | SceneObjectPart rootPart = obj.GetChildPart(obj.UUID); | ||
47 | bool UsePhysics = ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Physics) > 0); | ||
48 | if ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Phantom) == 0) | ||
49 | rootPart.PhysActor = m_innerScene.PhyScene.AddPrimShape( | ||
50 | rootPart.Name, | ||
51 | rootPart.Shape, | ||
52 | new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y, | ||
53 | rootPart.AbsolutePosition.Z), | ||
54 | new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z), | ||
55 | new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X, | ||
56 | rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics); | ||
57 | primCount++; | ||
58 | } | ||
59 | } | ||
60 | else | ||
61 | { | ||
62 | throw new Exception("Could not open file " + fileName + " for reading"); | ||
63 | } | ||
64 | } | ||
65 | |||
66 | public void SavePrimsToXml(string fileName) | ||
67 | { | ||
68 | FileStream file = new FileStream(fileName, FileMode.Create); | ||
69 | StreamWriter stream = new StreamWriter(file); | ||
70 | int primCount = 0; | ||
71 | stream.WriteLine("<scene>\n"); | ||
72 | foreach (EntityBase ent in m_innerScene.Entities.Values) | ||
73 | { | ||
74 | if (ent is SceneObjectGroup) | ||
75 | { | ||
76 | stream.WriteLine(((SceneObjectGroup)ent).ToXmlString()); | ||
77 | primCount++; | ||
78 | } | ||
79 | } | ||
80 | stream.WriteLine("</scene>\n"); | ||
81 | stream.Close(); | ||
82 | file.Close(); | ||
83 | } | ||
84 | |||
85 | public void LoadPrimsFromXml2(string fileName) | ||
86 | { | ||
87 | XmlDocument doc = new XmlDocument(); | ||
88 | XmlNode rootNode; | ||
89 | if (fileName.StartsWith("http:") || File.Exists(fileName)) | ||
90 | { | ||
91 | XmlTextReader reader = new XmlTextReader(fileName); | ||
92 | reader.WhitespaceHandling = WhitespaceHandling.None; | ||
93 | doc.Load(reader); | ||
94 | reader.Close(); | ||
95 | rootNode = doc.FirstChild; | ||
96 | foreach (XmlNode aPrimNode in rootNode.ChildNodes) | ||
97 | { | ||
98 | CreatePrimFromXml(aPrimNode.OuterXml); | ||
99 | } | ||
100 | } | ||
101 | else | ||
102 | { | ||
103 | throw new Exception("Could not open file " + fileName + " for reading"); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | public void CreatePrimFromXml(string xmlData) | ||
108 | { | ||
109 | SceneObjectGroup obj = new SceneObjectGroup(xmlData); | ||
110 | m_innerScene.AddEntityFromStorage(obj); | ||
111 | |||
112 | SceneObjectPart rootPart = obj.GetChildPart(obj.UUID); | ||
113 | bool UsePhysics = ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Physics) > 0); | ||
114 | if ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Phantom) == 0) | ||
115 | rootPart.PhysActor = m_innerScene.PhyScene.AddPrimShape( | ||
116 | rootPart.Name, | ||
117 | rootPart.Shape, | ||
118 | new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y, | ||
119 | rootPart.AbsolutePosition.Z), | ||
120 | new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z), | ||
121 | new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X, | ||
122 | rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics); | ||
123 | } | ||
124 | |||
125 | public void SavePrimsToXml2(string fileName) | ||
126 | { | ||
127 | FileStream file = new FileStream(fileName, FileMode.Create); | ||
128 | StreamWriter stream = new StreamWriter(file); | ||
129 | int primCount = 0; | ||
130 | stream.WriteLine("<scene>\n"); | ||
131 | foreach (EntityBase ent in m_innerScene.Entities.Values) | ||
132 | { | ||
133 | if (ent is SceneObjectGroup) | ||
134 | { | ||
135 | stream.WriteLine(((SceneObjectGroup)ent).ToXmlString2()); | ||
136 | primCount++; | ||
137 | } | ||
138 | } | ||
139 | stream.WriteLine("</scene>\n"); | ||
140 | stream.Close(); | ||
141 | file.Close(); | ||
142 | } | ||
143 | |||
144 | } | ||
145 | } | ||