29 using System.Collections.Generic;
31 using System.Reflection;
35 using OpenSim.Framework;
36 using OpenSim.Region.Framework.Scenes;
37 using OpenSim.Region.PhysicsModules.SharedBase;
39 namespace OpenSim.
Region.Framework.Scenes.Serialization
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48 #region old xml format
51 XmlDocument doc =
new XmlDocument();
54 if (fileName.StartsWith(
"http:") || File.Exists(fileName))
56 XmlTextReader reader =
new XmlTextReader(fileName);
57 reader.WhitespaceHandling = WhitespaceHandling.None;
60 rootNode = doc.FirstChild;
61 foreach (XmlNode aPrimNode
in rootNode.ChildNodes)
63 SceneObjectGroup obj = SceneObjectSerializer.FromOriginalXmlFormat(aPrimNode.OuterXml);
72 scene.AddNewSceneObject(obj,
true);
77 throw new Exception(
"Could not open file " + fileName +
" for reading");
83 FileStream file =
new FileStream(fileName, FileMode.Create);
84 StreamWriter stream =
new StreamWriter(file);
86 stream.WriteLine(
"<scene>\n");
93 stream.WriteLine(SceneObjectSerializer.ToOriginalXmlFormat((SceneObjectGroup)ent));
97 stream.WriteLine(
"</scene>\n");
104 #region XML2 serialization
110 using (MemoryStream mem =
new MemoryStream())
112 using (XmlTextWriter writer =
new XmlTextWriter(mem, System.Text.Encoding.UTF8))
114 SceneObjectSerializer.SOGToXml2(writer, grp,
options);
117 using (StreamReader reader =
new StreamReader(mem))
119 mem.Seek(0, SeekOrigin.Begin);
120 return reader.ReadToEnd();
129 EntityBase[] entityList = scene.GetEntities();
130 SavePrimListToXml2(entityList, fileName);
137 "[SERIALISER]: Saving prims with name {0} in xml2 format for region {1} to {2}",
138 primName, scene.RegionInfo.RegionName, fileName);
140 EntityBase[] entityList = scene.GetEntities();
141 List<EntityBase> primList =
new List<EntityBase>();
147 if (ent.
Name == primName)
154 SavePrimListToXml2(primList.ToArray(), fileName);
160 EntityBase[] entityList = scene.GetEntities();
161 SavePrimListToXml2(entityList, stream, min, max);
167 FileStream file =
new FileStream(fileName, FileMode.Create);
170 StreamWriter stream =
new StreamWriter(file);
173 SavePrimListToXml2(entityList, stream, Vector3.Zero, Vector3.Zero);
189 XmlTextWriter writer =
new XmlTextWriter(stream);
192 stream.WriteLine(
"<scene>\n");
198 SceneObjectGroup g = (SceneObjectGroup)ent;
199 if (!min.Equals(Vector3.Zero) || !max.Equals(Vector3.Zero))
201 Vector3 pos = g.RootPart.GetWorldPosition();
202 if (min.X > pos.X || min.Y > pos.Y || min.Z > pos.Z)
204 if (max.X < pos.X || max.Y < pos.Y || max.Z < pos.Z)
209 SceneObjectSerializer.SOGToXml2(writer, (SceneObjectGroup)ent,
new Dictionary<string,object>());
216 stream.WriteLine(
"</scene>\n");
222 #region XML2 deserialization
226 return SceneObjectSerializer.FromXml2Format(xmlString);
236 LoadPrimsFromXml2(scene,
new XmlTextReader(fileName),
false);
247 LoadPrimsFromXml2(scene,
new XmlTextReader(reader), startScripts);
258 XmlDocument doc =
new XmlDocument();
259 reader.WhitespaceHandling = WhitespaceHandling.None;
262 XmlNode rootNode = doc.FirstChild;
264 ICollection<SceneObjectGroup> sceneObjects =
new List<SceneObjectGroup>();
265 foreach (XmlNode aPrimNode
in rootNode.ChildNodes)
269 sceneObjects.Add(obj);
274 sceneObject.CreateScriptInstances(0,
true, scene.DefaultScriptEngine, 0);
275 sceneObject.ResumeScripts();
static void SavePrimListToXml2(EntityBase[] entityList, string fileName)
static void LoadPrimsFromXml2(Scene scene, string fileName)
Load prims from the xml2 format
static void LoadPrimsFromXml2(Scene scene, TextReader reader, bool startScripts)
Load prims from the xml2 format
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Static methods to serialize and deserialize scene objects to and from XML
static void SaveNamedPrimsToXml2(Scene scene, string primName, string fileName)
static void LoadPrimsFromXml(Scene scene, string fileName, bool newIDS, Vector3 loadOffset)
static void SavePrimsToXml2(Scene scene, TextWriter stream, Vector3 min, Vector3 max)
static SceneObjectGroup DeserializeGroupFromXml2(string xmlString)
static void SavePrimsToXml2(Scene scene, string fileName)
static string SaveGroupToXml2(SceneObjectGroup grp, Dictionary< string, object > options)
virtual string Name
The name of this entity
static void SavePrimListToXml2(EntityBase[] entityList, TextWriter stream, Vector3 min, Vector3 max)
static void LoadPrimsFromXml2(Scene scene, XmlTextReader reader, bool startScripts)
Load prims from the xml2 format. This method will close the reader
static void SavePrimsToXml(Scene scene, string fileName)