aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs')
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs238
1 files changed, 0 insertions, 238 deletions
diff --git a/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs b/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs
deleted file mode 100644
index 742996e..0000000
--- a/OpenSim/Region/Environment/Scenes/SceneXmlLoader.cs
+++ /dev/null
@@ -1,238 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Xml;
32using Axiom.Math;
33using libsecondlife;
34using OpenSim.Framework;
35using OpenSim.Region.Physics.Manager;
36
37namespace OpenSim.Region.Environment.Scenes
38{
39 public class SceneXmlLoader // can move to a module?
40 {
41 protected InnerScene m_innerScene;
42 protected RegionInfo m_regInfo;
43 protected Scene m_parentScene;
44
45 public SceneXmlLoader(Scene parentScene, InnerScene innerScene, RegionInfo regionInfo)
46 {
47 m_parentScene = parentScene;
48 m_innerScene = innerScene;
49 m_regInfo = regionInfo;
50 }
51
52 public void LoadPrimsFromXml(string fileName, bool newIDS, LLVector3 loadOffset)
53 {
54 XmlDocument doc = new XmlDocument();
55 XmlNode rootNode;
56 int primCount = 0;
57 if (fileName.StartsWith("http:") || File.Exists(fileName))
58 {
59 XmlTextReader reader = new XmlTextReader(fileName);
60 reader.WhitespaceHandling = WhitespaceHandling.None;
61 doc.Load(reader);
62 reader.Close();
63 rootNode = doc.FirstChild;
64 foreach (XmlNode aPrimNode in rootNode.ChildNodes)
65 {
66 SceneObjectGroup obj = new SceneObjectGroup(m_parentScene,
67 m_regInfo.RegionHandle, aPrimNode.OuterXml);
68 if (newIDS)
69 {
70 obj.ResetIDs();
71 }
72 //if we want this to be a import method then we need new uuids for the object to avoid any clashes
73 //obj.RegenerateFullIDs();
74
75 m_innerScene.AddSceneObject(obj);
76
77 SceneObjectPart rootPart = obj.GetChildPart(obj.UUID);
78 // Apply loadOffsets for load/import and move combinations
79 rootPart.GroupPosition = rootPart.AbsolutePosition + loadOffset;
80 bool UsePhysics = (((rootPart.GetEffectiveObjectFlags() & (uint) LLObject.ObjectFlags.Physics) > 0) &&
81 m_parentScene.m_physicalPrim);
82 if ((rootPart.GetEffectiveObjectFlags() & (uint) LLObject.ObjectFlags.Phantom) == 0)
83 {
84 rootPart.PhysActor = m_innerScene.PhysicsScene.AddPrimShape(
85 rootPart.Name,
86 rootPart.Shape,
87 new PhysicsVector(rootPart.AbsolutePosition.X + loadOffset.X,
88 rootPart.AbsolutePosition.Y + loadOffset.Y,
89 rootPart.AbsolutePosition.Z + loadOffset.Z),
90 new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z),
91 new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X,
92 rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics);
93
94 // to quote from SceneObjectPart: Basic
95 // Physics returns null.. joy joy joy.
96 if (rootPart.PhysActor != null)
97 {
98 rootPart.PhysActor.LocalID = rootPart.LocalId;
99 rootPart.DoPhysicsPropertyUpdate(UsePhysics, true);
100 }
101 }
102 primCount++;
103 }
104 }
105 else
106 {
107 throw new Exception("Could not open file " + fileName + " for reading");
108 }
109 }
110
111 public void SavePrimsToXml(string fileName)
112 {
113 FileStream file = new FileStream(fileName, FileMode.Create);
114 StreamWriter stream = new StreamWriter(file);
115 int primCount = 0;
116 stream.WriteLine("<scene>\n");
117
118 List<EntityBase> EntityList = m_innerScene.GetEntities();
119
120 foreach (EntityBase ent in EntityList)
121 {
122 if (ent is SceneObjectGroup)
123 {
124 stream.WriteLine(((SceneObjectGroup) ent).ToXmlString());
125 primCount++;
126 }
127 }
128 stream.WriteLine("</scene>\n");
129 stream.Close();
130 file.Close();
131 }
132
133 public string SavePrimGroupToXML2String(SceneObjectGroup grp)
134 {
135 string returnstring = "";
136 returnstring += "<scene>\n";
137 returnstring += grp.ToXmlString2();
138 returnstring += "</scene>\n";
139 return returnstring;
140
141 }
142
143 public void LoadGroupFromXml2String(string xmlString)
144 {
145 XmlDocument doc = new XmlDocument();
146 XmlNode rootNode;
147
148 XmlTextReader reader = new XmlTextReader(new StringReader(xmlString));
149 reader.WhitespaceHandling = WhitespaceHandling.None;
150 doc.Load(reader);
151 reader.Close();
152 rootNode = doc.FirstChild;
153 foreach (XmlNode aPrimNode in rootNode.ChildNodes)
154 {
155 CreatePrimFromXml(aPrimNode.OuterXml);
156 }
157
158 }
159
160 public void LoadPrimsFromXml2(string fileName)
161 {
162 XmlDocument doc = new XmlDocument();
163 XmlNode rootNode;
164 if (fileName.StartsWith("http:") || File.Exists(fileName))
165 {
166 XmlTextReader reader = new XmlTextReader(fileName);
167 reader.WhitespaceHandling = WhitespaceHandling.None;
168 doc.Load(reader);
169 reader.Close();
170 rootNode = doc.FirstChild;
171 foreach (XmlNode aPrimNode in rootNode.ChildNodes)
172 {
173 CreatePrimFromXml(aPrimNode.OuterXml);
174 }
175 }
176 else
177 {
178 throw new Exception("Could not open file " + fileName + " for reading");
179 }
180 }
181
182 public void CreatePrimFromXml(string xmlData)
183 {
184 SceneObjectGroup obj = new SceneObjectGroup(xmlData);
185 LLVector3 receivedVelocity = obj.RootPart.Velocity;
186 //System.Console.WriteLine(obj.RootPart.Velocity.ToString());
187 m_innerScene.AddSceneObjectFromStorage(obj);
188
189 SceneObjectPart rootPart = obj.GetChildPart(obj.UUID);
190 bool UsePhysics = (((rootPart.GetEffectiveObjectFlags() & (uint) LLObject.ObjectFlags.Physics) > 0) &&
191 m_parentScene.m_physicalPrim);
192 if ((rootPart.GetEffectiveObjectFlags() & (uint) LLObject.ObjectFlags.Phantom) == 0)
193 {
194 rootPart.PhysActor = m_innerScene.PhysicsScene.AddPrimShape(
195 rootPart.Name,
196 rootPart.Shape,
197 new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y,
198 rootPart.AbsolutePosition.Z),
199 new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z),
200 new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X,
201 rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics);
202
203 // to quote from SceneObjectPart: Basic
204 // Physics returns null.. joy joy joy.
205 if (rootPart.PhysActor != null)
206 {
207 rootPart.PhysActor.LocalID = rootPart.LocalId;
208 rootPart.DoPhysicsPropertyUpdate(UsePhysics, true);
209 }
210 rootPart.Velocity = receivedVelocity;
211 }
212
213 obj.ScheduleGroupForFullUpdate();
214 }
215
216 public void SavePrimsToXml2(string fileName)
217 {
218 FileStream file = new FileStream(fileName, FileMode.Create);
219 StreamWriter stream = new StreamWriter(file);
220 int primCount = 0;
221 stream.WriteLine("<scene>\n");
222
223 List<EntityBase> EntityList = m_innerScene.GetEntities();
224
225 foreach (EntityBase ent in EntityList)
226 {
227 if (ent is SceneObjectGroup)
228 {
229 stream.WriteLine(((SceneObjectGroup) ent).ToXmlString2());
230 primCount++;
231 }
232 }
233 stream.WriteLine("</scene>\n");
234 stream.Close();
235 file.Close();
236 }
237 }
238}