From 2681de366b22d1fc57d808c0cd98da0426a0379e Mon Sep 17 00:00:00 2001
From: MW
Date: Mon, 22 Oct 2007 11:06:54 +0000
Subject: Made some changes to the load/save xml format, So that the old format
can still be used, I have added new console commands of "load-xml2" and
"save-xml2", if the old versions worked for you then please continue using
them (at least for now). The new versions haven't been tested that much, so
their format could be subject to change.
---
OpenSim/Region/Environment/Scenes/Scene.cs | 58 ++++++++++++++++++++++
OpenSim/Region/Environment/Scenes/SceneManager.cs | 10 ++++
.../Region/Environment/Scenes/SceneObjectGroup.cs | 33 ++++++++++--
3 files changed, 98 insertions(+), 3 deletions(-)
(limited to 'OpenSim/Region/Environment/Scenes')
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index f7e3543..553e55f 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -709,6 +709,64 @@ namespace OpenSim.Region.Environment.Scenes
file.Close();
}
+ public void LoadPrimsFromXml2(string fileName)
+ {
+ XmlDocument doc = new XmlDocument();
+ XmlNode rootNode;
+ if ((fileName.StartsWith("http:")) | (File.Exists(fileName)))
+ {
+ XmlTextReader reader = new XmlTextReader(fileName);
+ reader.WhitespaceHandling = WhitespaceHandling.None;
+ doc.Load(reader);
+ reader.Close();
+ rootNode = doc.FirstChild;
+ foreach (XmlNode aPrimNode in rootNode.ChildNodes)
+ {
+ CreatePrimFromXml(aPrimNode.OuterXml);
+ }
+ }
+ else
+ {
+ throw new Exception("Could not open file " + fileName + " for reading");
+ }
+ }
+
+ public void CreatePrimFromXml(string xmlData)
+ {
+ SceneObjectGroup obj = new SceneObjectGroup(xmlData);
+ AddEntityFromStorage(obj);
+
+ SceneObjectPart rootPart = obj.GetChildPart(obj.UUID);
+ if ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Phantom) == 0)
+ rootPart.PhysActor = phyScene.AddPrimShape(
+ rootPart.Name,
+ rootPart.Shape,
+ new PhysicsVector(rootPart.AbsolutePosition.X, rootPart.AbsolutePosition.Y,
+ rootPart.AbsolutePosition.Z),
+ new PhysicsVector(rootPart.Scale.X, rootPart.Scale.Y, rootPart.Scale.Z),
+ new Quaternion(rootPart.RotationOffset.W, rootPart.RotationOffset.X,
+ rootPart.RotationOffset.Y, rootPart.RotationOffset.Z));
+ }
+
+ public void SavePrimsToXml2(string fileName)
+ {
+ FileStream file = new FileStream(fileName, FileMode.Create);
+ StreamWriter stream = new StreamWriter(file);
+ int primCount = 0;
+ stream.WriteLine("\n");
+ foreach (EntityBase ent in Entities.Values)
+ {
+ if (ent is SceneObjectGroup)
+ {
+ stream.WriteLine(((SceneObjectGroup)ent).ToXmlString2());
+ primCount++;
+ }
+ }
+ stream.WriteLine("\n");
+ stream.Close();
+ file.Close();
+ }
+
#endregion
#region Add/Remove Avatar Methods
diff --git a/OpenSim/Region/Environment/Scenes/SceneManager.cs b/OpenSim/Region/Environment/Scenes/SceneManager.cs
index e3da550..d2718df 100644
--- a/OpenSim/Region/Environment/Scenes/SceneManager.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneManager.cs
@@ -85,6 +85,16 @@ namespace OpenSim.Region.Environment.Scenes
public void LoadCurrentSceneFromXml(string filename)
{
CurrentOrFirstScene.LoadPrimsFromXml(filename);
+ }
+
+ public void SaveCurrentSceneToXml2(string filename)
+ {
+ CurrentOrFirstScene.SavePrimsToXml2(filename);
+ }
+
+ public void LoadCurrentSceneFromXml2(string filename)
+ {
+ CurrentOrFirstScene.LoadPrimsFromXml2(filename);
}
public bool RunTerrainCmdOnCurrentScene(string[] cmdparams, ref string result)
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
index 1839051..bb2eadb 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
@@ -272,7 +272,6 @@ namespace OpenSim.Region.Environment.Scenes
reader.Read();
reader.ReadStartElement("SceneObjectGroup");
- // reader.ReadStartElement("RootPart");
m_rootPart = SceneObjectPart.FromXml(reader);
reader.Read();
@@ -286,8 +285,7 @@ namespace OpenSim.Region.Environment.Scenes
if (reader.Name == "SceneObjectPart")
{
SceneObjectPart Part = SceneObjectPart.FromXml(reader);
- AddPart(Part);
-
+ AddPart(Part);
}
break;
case XmlNodeType.EndElement:
@@ -375,6 +373,35 @@ namespace OpenSim.Region.Environment.Scenes
writer.WriteEndElement();
}
+ public string ToXmlString2()
+ {
+ using (StringWriter sw = new StringWriter())
+ {
+ using (XmlTextWriter writer = new XmlTextWriter(sw))
+ {
+ ToXml2(writer);
+ }
+
+ return sw.ToString();
+ }
+ }
+
+ public void ToXml2(XmlTextWriter writer)
+ {
+ writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
+ m_rootPart.ToXml(writer);
+ writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
+ foreach (SceneObjectPart part in m_parts.Values)
+ {
+ if (part.UUID != m_rootPart.UUID)
+ {
+ part.ToXml(writer);
+ }
+ }
+ writer.WriteEndElement();
+ writer.WriteEndElement();
+ }
+
#region Copying
///
--
cgit v1.1