aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/World
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-05-30 17:52:14 +0000
committerJustin Clarke Casey2008-05-30 17:52:14 +0000
commit4f237f3ae3b8561de0dacd1ec0e937ec7a8e0307 (patch)
tree728db0e5d0691b553b8ebe4e5a13560c4657c7e2 /OpenSim/Region/Environment/Modules/World
parentMantis#1422. Thank you kindly, Xantor for your llLoopSound() (diff)
downloadopensim-SC_OLD-4f237f3ae3b8561de0dacd1ec0e937ec7a8e0307.zip
opensim-SC_OLD-4f237f3ae3b8561de0dacd1ec0e937ec7a8e0307.tar.gz
opensim-SC_OLD-4f237f3ae3b8561de0dacd1ec0e937ec7a8e0307.tar.bz2
opensim-SC_OLD-4f237f3ae3b8561de0dacd1ec0e937ec7a8e0307.tar.xz
* Crudely migrate SceneXmlLoader into the Serializer module
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Serialiser/IRegionSerialiser.cs17
-rw-r--r--OpenSim/Region/Environment/Modules/World/Serialiser/SceneXmlLoader.cs228
-rw-r--r--OpenSim/Region/Environment/Modules/World/Serialiser/SerialiserModule.cs35
3 files changed, 276 insertions, 4 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Serialiser/IRegionSerialiser.cs b/OpenSim/Region/Environment/Modules/World/Serialiser/IRegionSerialiser.cs
index 331b460..752b5b6 100644
--- a/OpenSim/Region/Environment/Modules/World/Serialiser/IRegionSerialiser.cs
+++ b/OpenSim/Region/Environment/Modules/World/Serialiser/IRegionSerialiser.cs
@@ -25,6 +25,7 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using libsecondlife;
28using System.Collections.Generic; 29using System.Collections.Generic;
29using OpenSim.Region.Environment.Scenes; 30using OpenSim.Region.Environment.Scenes;
30 31
@@ -32,6 +33,18 @@ namespace OpenSim.Region.Environment.Modules.World.Serialiser
32{ 33{
33 public interface IRegionSerialiser 34 public interface IRegionSerialiser
34 { 35 {
35 List<string> SerialiseRegion(Scene scene, string saveDir); 36 List<string> SerialiseRegion(Scene scene, string saveDir);
37
38 void LoadPrimsFromXml(Scene scene, string fileName, bool newIDS, LLVector3 loadOffset);
39
40 void SavePrimsToXml(Scene scene, string fileName);
41
42 void LoadPrimsFromXml2(Scene scene, string fileName);
43
44 void SavePrimsToXml2(Scene scene, string fileName);
45
46 void LoadGroupFromXml2String(Scene scene, string xmlString);
47
48 string SavePrimGroupToXML2String(SceneObjectGroup grp);
36 } 49 }
37} \ No newline at end of file 50}
diff --git a/OpenSim/Region/Environment/Modules/World/Serialiser/SceneXmlLoader.cs b/OpenSim/Region/Environment/Modules/World/Serialiser/SceneXmlLoader.cs
new file mode 100644
index 0000000..7f51b58
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/World/Serialiser/SceneXmlLoader.cs
@@ -0,0 +1,228 @@
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 /// <summary>
40 /// Static methods to serialize and deserialize scene objects to and from XML
41 /// </summary>
42 public class SceneXmlLoader
43 {
44 public static void LoadPrimsFromXml(Scene scene, string fileName, bool newIDS, LLVector3 loadOffset)
45 {
46 XmlDocument doc = new XmlDocument();
47 XmlNode rootNode;
48 int primCount = 0;
49 if (fileName.StartsWith("http:") || File.Exists(fileName))
50 {
51 XmlTextReader reader = new XmlTextReader(fileName);
52 reader.WhitespaceHandling = WhitespaceHandling.None;
53 doc.Load(reader);
54 reader.Close();
55 rootNode = doc.FirstChild;
56 foreach (XmlNode aPrimNode in rootNode.ChildNodes)
57 {
58 SceneObjectGroup obj = new SceneObjectGroup(scene, scene.RegionInfo.RegionHandle, aPrimNode.OuterXml);
59
60 if (newIDS)
61 {
62 obj.ResetIDs();
63 }
64 //if we want this to be a import method then we need new uuids for the object to avoid any clashes
65 //obj.RegenerateFullIDs();
66
67 scene.AddSceneObject(obj);
68
69 SceneObjectPart rootPart = obj.GetChildPart(obj.UUID);
70 // Apply loadOffsets for load/import and move combinations
71 rootPart.GroupPosition = rootPart.AbsolutePosition + loadOffset;
72 bool UsePhysics = (((rootPart.GetEffectiveObjectFlags() & (uint) LLObject.ObjectFlags.Physics) > 0) &&
73 scene.m_physicalPrim);
74 if ((rootPart.GetEffectiveObjectFlags() & (uint) LLObject.ObjectFlags.Phantom) == 0)
75 {
76 rootPart.PhysActor = scene.PhysicsScene.AddPrimShape(
77 rootPart.Name,
78 rootPart.Shape,
79 new PhysicsVector(rootPart.AbsolutePosition.X + loadOffset.X,
80 rootPart.AbsolutePosition.Y + loadOffset.Y,
81 rootPart.AbsolutePosition.Z + loadOffset.Z),
82 new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z),
83 new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X,
84 rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics);
85
86 // to quote from SceneObjectPart: Basic
87 // Physics returns null.. joy joy joy.
88 if (rootPart.PhysActor != null)
89 {
90 rootPart.PhysActor.LocalID = rootPart.LocalId;
91 rootPart.DoPhysicsPropertyUpdate(UsePhysics, true);
92 }
93 }
94 primCount++;
95 }
96 }
97 else
98 {
99 throw new Exception("Could not open file " + fileName + " for reading");
100 }
101 }
102
103 public static void SavePrimsToXml(Scene scene, string fileName)
104 {
105 FileStream file = new FileStream(fileName, FileMode.Create);
106 StreamWriter stream = new StreamWriter(file);
107 int primCount = 0;
108 stream.WriteLine("<scene>\n");
109
110 List<EntityBase> EntityList = scene.GetEntities();
111
112 foreach (EntityBase ent in EntityList)
113 {
114 if (ent is SceneObjectGroup)
115 {
116 stream.WriteLine(((SceneObjectGroup) ent).ToXmlString());
117 primCount++;
118 }
119 }
120 stream.WriteLine("</scene>\n");
121 stream.Close();
122 file.Close();
123 }
124
125 public static string SavePrimGroupToXML2String(SceneObjectGroup grp)
126 {
127 string returnstring = "";
128 returnstring += "<scene>\n";
129 returnstring += grp.ToXmlString2();
130 returnstring += "</scene>\n";
131 return returnstring;
132 }
133
134 public static void LoadGroupFromXml2String(Scene scene, string xmlString)
135 {
136 XmlDocument doc = new XmlDocument();
137 XmlNode rootNode;
138
139 XmlTextReader reader = new XmlTextReader(new StringReader(xmlString));
140 reader.WhitespaceHandling = WhitespaceHandling.None;
141 doc.Load(reader);
142 reader.Close();
143 rootNode = doc.FirstChild;
144 foreach (XmlNode aPrimNode in rootNode.ChildNodes)
145 {
146 CreatePrimFromXml(scene, aPrimNode.OuterXml);
147 }
148 }
149
150 public static void LoadPrimsFromXml2(Scene scene, string fileName)
151 {
152 XmlDocument doc = new XmlDocument();
153 XmlNode rootNode;
154 if (fileName.StartsWith("http:") || File.Exists(fileName))
155 {
156 XmlTextReader reader = new XmlTextReader(fileName);
157 reader.WhitespaceHandling = WhitespaceHandling.None;
158 doc.Load(reader);
159 reader.Close();
160 rootNode = doc.FirstChild;
161 foreach (XmlNode aPrimNode in rootNode.ChildNodes)
162 {
163 CreatePrimFromXml(scene, aPrimNode.OuterXml);
164 }
165 }
166 else
167 {
168 throw new Exception("Could not open file " + fileName + " for reading");
169 }
170 }
171
172 public static void CreatePrimFromXml(Scene scene, string xmlData)
173 {
174 SceneObjectGroup obj = new SceneObjectGroup(xmlData);
175 LLVector3 receivedVelocity = obj.RootPart.Velocity;
176 //System.Console.WriteLine(obj.RootPart.Velocity.ToString());
177 scene.AddSceneObjectFromStorage(obj);
178
179 SceneObjectPart rootPart = obj.GetChildPart(obj.UUID);
180 bool UsePhysics = (((rootPart.GetEffectiveObjectFlags() & (uint) LLObject.ObjectFlags.Physics) > 0) &&
181 scene.m_physicalPrim);
182 if ((rootPart.GetEffectiveObjectFlags() & (uint) LLObject.ObjectFlags.Phantom) == 0)
183 {
184 rootPart.PhysActor = scene.PhysicsScene.AddPrimShape(
185 rootPart.Name,
186 rootPart.Shape,
187 new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y,
188 rootPart.AbsolutePosition.Z),
189 new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z),
190 new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X,
191 rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics);
192
193 // to quote from SceneObjectPart: Basic
194 // Physics returns null.. joy joy joy.
195 if (rootPart.PhysActor != null)
196 {
197 rootPart.PhysActor.LocalID = rootPart.LocalId;
198 rootPart.DoPhysicsPropertyUpdate(UsePhysics, true);
199 }
200 rootPart.Velocity = receivedVelocity;
201 }
202
203 obj.ScheduleGroupForFullUpdate();
204 }
205
206 public static void SavePrimsToXml2(Scene scene, string fileName)
207 {
208 FileStream file = new FileStream(fileName, FileMode.Create);
209 StreamWriter stream = new StreamWriter(file);
210 int primCount = 0;
211 stream.WriteLine("<scene>\n");
212
213 List<EntityBase> EntityList = scene.GetEntities();
214
215 foreach (EntityBase ent in EntityList)
216 {
217 if (ent is SceneObjectGroup)
218 {
219 stream.WriteLine(((SceneObjectGroup) ent).ToXmlString2());
220 primCount++;
221 }
222 }
223 stream.WriteLine("</scene>\n");
224 stream.Close();
225 file.Close();
226 }
227 }
228}
diff --git a/OpenSim/Region/Environment/Modules/World/Serialiser/SerialiserModule.cs b/OpenSim/Region/Environment/Modules/World/Serialiser/SerialiserModule.cs
index bd8a0f4..bfa0a43 100644
--- a/OpenSim/Region/Environment/Modules/World/Serialiser/SerialiserModule.cs
+++ b/OpenSim/Region/Environment/Modules/World/Serialiser/SerialiserModule.cs
@@ -28,6 +28,7 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using libsecondlife;
31using Nini.Config; 32using Nini.Config;
32using OpenSim.Region.Environment.Interfaces; 33using OpenSim.Region.Environment.Interfaces;
33using OpenSim.Region.Environment.Modules.Framework.InterfaceCommander; 34using OpenSim.Region.Environment.Modules.Framework.InterfaceCommander;
@@ -85,7 +86,37 @@ namespace OpenSim.Region.Environment.Modules.World.Serialiser
85 #endregion 86 #endregion
86 87
87 #region IRegionSerialiser Members 88 #region IRegionSerialiser Members
88 89
90 public void LoadPrimsFromXml(Scene scene, string fileName, bool newIDS, LLVector3 loadOffset)
91 {
92 SceneXmlLoader.LoadPrimsFromXml(scene, fileName, newIDS, loadOffset);
93 }
94
95 public void SavePrimsToXml(Scene scene, string fileName)
96 {
97 SceneXmlLoader.SavePrimsToXml(scene, fileName);
98 }
99
100 public void LoadPrimsFromXml2(Scene scene, string fileName)
101 {
102 SceneXmlLoader.LoadPrimsFromXml2(scene, fileName);
103 }
104
105 public void SavePrimsToXml2(Scene scene, string fileName)
106 {
107 SceneXmlLoader.SavePrimsToXml2(scene, fileName);
108 }
109
110 public void LoadGroupFromXml2String(Scene scene, string xmlString)
111 {
112 SceneXmlLoader.LoadGroupFromXml2String(scene, xmlString);
113 }
114
115 public string SavePrimGroupToXML2String(SceneObjectGroup grp)
116 {
117 return SceneXmlLoader.SavePrimGroupToXML2String(grp);
118 }
119
89 public List<string> SerialiseRegion(Scene scene, string saveDir) 120 public List<string> SerialiseRegion(Scene scene, string saveDir)
90 { 121 {
91 List<string> results = new List<string>(); 122 List<string> results = new List<string>();
@@ -165,4 +196,4 @@ namespace OpenSim.Region.Environment.Modules.World.Serialiser
165 m_commander.RegisterCommand("save-all", serialiseAllScenesCommand); 196 m_commander.RegisterCommand("save-all", serialiseAllScenesCommand);
166 } 197 }
167 } 198 }
168} \ No newline at end of file 199}