1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;
using libsecondlife;
using Axiom.Math;
using OpenSim.Framework;
using OpenSim.Region.Physics.Manager;
namespace OpenSim.Region.Environment.Scenes
{
public class SceneXmlLoader // can move to a module?
{
protected InnerScene m_innerScene;
protected RegionInfo m_regInfo;
protected Scene m_parentScene;
public SceneXmlLoader(Scene parentScene, InnerScene innerScene, RegionInfo regionInfo)
{
m_parentScene = parentScene;
m_innerScene = innerScene;
m_regInfo = regionInfo;
}
public void LoadPrimsFromXml(string fileName)
{
XmlDocument doc = new XmlDocument();
XmlNode rootNode;
int primCount = 0;
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)
{
SceneObjectGroup obj = new SceneObjectGroup(m_parentScene,
m_regInfo.RegionHandle, aPrimNode.OuterXml);
//if we want this to be a import method then we need new uuids for the object to avoid any clashes
//obj.RegenerateFullIDs();
m_innerScene.AddEntity(obj);
SceneObjectPart rootPart = obj.GetChildPart(obj.UUID);
bool UsePhysics = (((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Physics) > 0) && m_parentScene.m_physicalPrim);
if ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Phantom) == 0)
{
rootPart.PhysActor = m_innerScene.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), UsePhysics);
rootPart.doPhysicsPropertyUpdate(UsePhysics);
}
primCount++;
}
}
else
{
throw new Exception("Could not open file " + fileName + " for reading");
}
}
public void SavePrimsToXml(string fileName)
{
FileStream file = new FileStream(fileName, FileMode.Create);
StreamWriter stream = new StreamWriter(file);
int primCount = 0;
stream.WriteLine("<scene>\n");
foreach (EntityBase ent in m_innerScene.Entities.Values)
{
if (ent is SceneObjectGroup)
{
stream.WriteLine(((SceneObjectGroup)ent).ToXmlString());
primCount++;
}
}
stream.WriteLine("</scene>\n");
stream.Close();
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);
m_innerScene.AddEntityFromStorage(obj);
SceneObjectPart rootPart = obj.GetChildPart(obj.UUID);
bool UsePhysics = (((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Physics) > 0) && m_parentScene.m_physicalPrim);
if ((rootPart.ObjectFlags & (uint)LLObject.ObjectFlags.Phantom) == 0)
{
rootPart.PhysActor = m_innerScene.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), UsePhysics);
rootPart.doPhysicsPropertyUpdate(UsePhysics);
}
}
public void SavePrimsToXml2(string fileName)
{
FileStream file = new FileStream(fileName, FileMode.Create);
StreamWriter stream = new StreamWriter(file);
int primCount = 0;
stream.WriteLine("<scene>\n");
foreach (EntityBase ent in m_innerScene.Entities.Values)
{
if (ent is SceneObjectGroup)
{
stream.WriteLine(((SceneObjectGroup)ent).ToXmlString2());
primCount++;
}
}
stream.WriteLine("</scene>\n");
stream.Close();
file.Close();
}
}
}
|