diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs | 1702 |
1 files changed, 1702 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs new file mode 100644 index 0000000..4caa9cb --- /dev/null +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs | |||
@@ -0,0 +1,1702 @@ | |||
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 OpenSimulator 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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Drawing; | ||
31 | using System.IO; | ||
32 | using System.Linq; | ||
33 | using System.Reflection; | ||
34 | using System.Xml; | ||
35 | using log4net; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Serialization.External; | ||
39 | using OpenSim.Region.Framework.Interfaces; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Services.Interfaces; | ||
42 | |||
43 | namespace OpenSim.Region.Framework.Scenes.Serialization | ||
44 | { | ||
45 | /// <summary> | ||
46 | /// Serialize and deserialize scene objects. | ||
47 | /// </summary> | ||
48 | /// This should really be in OpenSim.Framework.Serialization but this would mean circular dependency problems | ||
49 | /// right now - hopefully this isn't forever. | ||
50 | public class SceneObjectSerializer | ||
51 | { | ||
52 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
53 | |||
54 | private static IUserManagement m_UserManagement; | ||
55 | |||
56 | /// <summary> | ||
57 | /// Deserialize a scene object from the original xml format | ||
58 | /// </summary> | ||
59 | /// <param name="xmlData"></param> | ||
60 | /// <returns>The scene object deserialized. Null on failure.</returns> | ||
61 | public static SceneObjectGroup FromOriginalXmlFormat(string xmlData) | ||
62 | { | ||
63 | String fixedData = ExternalRepresentationUtils.SanitizeXml(xmlData); | ||
64 | using (XmlTextReader wrappedReader = new XmlTextReader(fixedData, XmlNodeType.Element, null)) | ||
65 | { | ||
66 | using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment })) | ||
67 | { | ||
68 | try { | ||
69 | return FromOriginalXmlFormat(reader); | ||
70 | } | ||
71 | catch (Exception e) | ||
72 | { | ||
73 | m_log.Error("[SERIALIZER]: Deserialization of xml failed ", e); | ||
74 | Util.LogFailedXML("[SERIALIZER]:", fixedData); | ||
75 | return null; | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | |||
81 | /// <summary> | ||
82 | /// Deserialize a scene object from the original xml format | ||
83 | /// </summary> | ||
84 | /// <param name="xmlData"></param> | ||
85 | /// <returns>The scene object deserialized. Null on failure.</returns> | ||
86 | public static SceneObjectGroup FromOriginalXmlFormat(XmlReader reader) | ||
87 | { | ||
88 | //m_log.DebugFormat("[SOG]: Starting deserialization of SOG"); | ||
89 | //int time = System.Environment.TickCount; | ||
90 | |||
91 | int linkNum; | ||
92 | |||
93 | reader.ReadToFollowing("RootPart"); | ||
94 | reader.ReadToFollowing("SceneObjectPart"); | ||
95 | SceneObjectGroup sceneObject = new SceneObjectGroup(SceneObjectPart.FromXml(reader)); | ||
96 | reader.ReadToFollowing("OtherParts"); | ||
97 | |||
98 | if (reader.ReadToDescendant("Part")) | ||
99 | { | ||
100 | do | ||
101 | { | ||
102 | if (reader.ReadToDescendant("SceneObjectPart")) | ||
103 | { | ||
104 | SceneObjectPart part = SceneObjectPart.FromXml(reader); | ||
105 | linkNum = part.LinkNum; | ||
106 | sceneObject.AddPart(part); | ||
107 | part.LinkNum = linkNum; | ||
108 | part.TrimPermissions(); | ||
109 | } | ||
110 | } | ||
111 | while (reader.ReadToNextSibling("Part")); | ||
112 | } | ||
113 | |||
114 | // Script state may, or may not, exist. Not having any, is NOT | ||
115 | // ever a problem. | ||
116 | sceneObject.LoadScriptState(reader); | ||
117 | |||
118 | return sceneObject; | ||
119 | } | ||
120 | |||
121 | /// <summary> | ||
122 | /// Serialize a scene object to the original xml format | ||
123 | /// </summary> | ||
124 | /// <param name="sceneObject"></param> | ||
125 | /// <returns></returns> | ||
126 | public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject) | ||
127 | { | ||
128 | return ToOriginalXmlFormat(sceneObject, true); | ||
129 | } | ||
130 | |||
131 | /// <summary> | ||
132 | /// Serialize a scene object to the original xml format | ||
133 | /// </summary> | ||
134 | /// <param name="sceneObject"></param> | ||
135 | /// <param name="doScriptStates">Control whether script states are also serialized.</para> | ||
136 | /// <returns></returns> | ||
137 | public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, bool doScriptStates) | ||
138 | { | ||
139 | using (StringWriter sw = new StringWriter()) | ||
140 | { | ||
141 | using (XmlTextWriter writer = new XmlTextWriter(sw)) | ||
142 | { | ||
143 | ToOriginalXmlFormat(sceneObject, writer, doScriptStates); | ||
144 | } | ||
145 | |||
146 | return sw.ToString(); | ||
147 | } | ||
148 | } | ||
149 | |||
150 | /// <summary> | ||
151 | /// Serialize a scene object to the original xml format | ||
152 | /// </summary> | ||
153 | /// <param name="sceneObject"></param> | ||
154 | /// <returns></returns> | ||
155 | public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates) | ||
156 | { | ||
157 | ToOriginalXmlFormat(sceneObject, writer, doScriptStates, false); | ||
158 | } | ||
159 | |||
160 | public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, string scriptedState) | ||
161 | { | ||
162 | using (StringWriter sw = new StringWriter()) | ||
163 | { | ||
164 | using (XmlTextWriter writer = new XmlTextWriter(sw)) | ||
165 | { | ||
166 | writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty); | ||
167 | |||
168 | ToOriginalXmlFormat(sceneObject, writer, false, true); | ||
169 | |||
170 | writer.WriteRaw(scriptedState); | ||
171 | |||
172 | writer.WriteEndElement(); | ||
173 | } | ||
174 | return sw.ToString(); | ||
175 | } | ||
176 | } | ||
177 | |||
178 | /// <summary> | ||
179 | /// Serialize a scene object to the original xml format | ||
180 | /// </summary> | ||
181 | /// <param name="sceneObject"></param> | ||
182 | /// <param name="writer"></param> | ||
183 | /// <param name="noRootElement">If false, don't write the enclosing SceneObjectGroup element</param> | ||
184 | /// <returns></returns> | ||
185 | public static void ToOriginalXmlFormat( | ||
186 | SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates, bool noRootElement) | ||
187 | { | ||
188 | // m_log.DebugFormat("[SERIALIZER]: Starting serialization of {0}", sceneObject.Name); | ||
189 | // int time = System.Environment.TickCount; | ||
190 | |||
191 | if (!noRootElement) | ||
192 | writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty); | ||
193 | |||
194 | writer.WriteStartElement(String.Empty, "RootPart", String.Empty); | ||
195 | ToXmlFormat(sceneObject.RootPart, writer); | ||
196 | writer.WriteEndElement(); | ||
197 | writer.WriteStartElement(String.Empty, "OtherParts", String.Empty); | ||
198 | |||
199 | SceneObjectPart[] parts = sceneObject.Parts; | ||
200 | for (int i = 0; i < parts.Length; i++) | ||
201 | { | ||
202 | SceneObjectPart part = parts[i]; | ||
203 | if (part.UUID != sceneObject.RootPart.UUID) | ||
204 | { | ||
205 | writer.WriteStartElement(String.Empty, "Part", String.Empty); | ||
206 | ToXmlFormat(part, writer); | ||
207 | writer.WriteEndElement(); | ||
208 | } | ||
209 | } | ||
210 | |||
211 | writer.WriteEndElement(); // OtherParts | ||
212 | |||
213 | if (doScriptStates) | ||
214 | sceneObject.SaveScriptedState(writer); | ||
215 | |||
216 | if (!noRootElement) | ||
217 | writer.WriteEndElement(); // SceneObjectGroup | ||
218 | |||
219 | // m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0}, {1}ms", sceneObject.Name, System.Environment.TickCount - time); | ||
220 | } | ||
221 | |||
222 | protected static void ToXmlFormat(SceneObjectPart part, XmlTextWriter writer) | ||
223 | { | ||
224 | SOPToXml2(writer, part, new Dictionary<string, object>()); | ||
225 | } | ||
226 | |||
227 | public static SceneObjectGroup FromXml2Format(string xmlData) | ||
228 | { | ||
229 | //m_log.DebugFormat("[SOG]: Starting deserialization of SOG"); | ||
230 | //int time = System.Environment.TickCount; | ||
231 | |||
232 | try | ||
233 | { | ||
234 | XmlDocument doc = new XmlDocument(); | ||
235 | doc.LoadXml(xmlData); | ||
236 | |||
237 | XmlNodeList parts = doc.GetElementsByTagName("SceneObjectPart"); | ||
238 | |||
239 | if (parts.Count == 0) | ||
240 | { | ||
241 | m_log.Error("[SERIALIZER]: Deserialization of xml failed: No SceneObjectPart nodes"); | ||
242 | Util.LogFailedXML("[SERIALIZER]:", xmlData); | ||
243 | return null; | ||
244 | } | ||
245 | |||
246 | StringReader sr = new StringReader(parts[0].OuterXml); | ||
247 | XmlTextReader reader = new XmlTextReader(sr); | ||
248 | SceneObjectGroup sceneObject = new SceneObjectGroup(SceneObjectPart.FromXml(reader)); | ||
249 | reader.Close(); | ||
250 | sr.Close(); | ||
251 | |||
252 | // Then deal with the rest | ||
253 | for (int i = 1; i < parts.Count; i++) | ||
254 | { | ||
255 | sr = new StringReader(parts[i].OuterXml); | ||
256 | reader = new XmlTextReader(sr); | ||
257 | SceneObjectPart part = SceneObjectPart.FromXml(reader); | ||
258 | |||
259 | int originalLinkNum = part.LinkNum; | ||
260 | |||
261 | sceneObject.AddPart(part); | ||
262 | |||
263 | // SceneObjectGroup.AddPart() tries to be smart and automatically set the LinkNum. | ||
264 | // We override that here | ||
265 | if (originalLinkNum != 0) | ||
266 | part.LinkNum = originalLinkNum; | ||
267 | |||
268 | reader.Close(); | ||
269 | sr.Close(); | ||
270 | } | ||
271 | |||
272 | XmlNodeList keymotion = doc.GetElementsByTagName("KeyframeMotion"); | ||
273 | if (keymotion.Count > 0) | ||
274 | sceneObject.RootPart.KeyframeMotion = KeyframeMotion.FromData(sceneObject, Convert.FromBase64String(keymotion[0].InnerText)); | ||
275 | else | ||
276 | sceneObject.RootPart.KeyframeMotion = null; | ||
277 | |||
278 | // Script state may, or may not, exist. Not having any, is NOT | ||
279 | // ever a problem. | ||
280 | sceneObject.LoadScriptState(doc); | ||
281 | |||
282 | return sceneObject; | ||
283 | } | ||
284 | catch (Exception e) | ||
285 | { | ||
286 | m_log.Error("[SERIALIZER]: Deserialization of xml failed ", e); | ||
287 | Util.LogFailedXML("[SERIALIZER]:", xmlData); | ||
288 | return null; | ||
289 | } | ||
290 | } | ||
291 | |||
292 | /// <summary> | ||
293 | /// Serialize a scene object to the 'xml2' format. | ||
294 | /// </summary> | ||
295 | /// <param name="sceneObject"></param> | ||
296 | /// <returns></returns> | ||
297 | public static string ToXml2Format(SceneObjectGroup sceneObject) | ||
298 | { | ||
299 | using (StringWriter sw = new StringWriter()) | ||
300 | { | ||
301 | using (XmlTextWriter writer = new XmlTextWriter(sw)) | ||
302 | { | ||
303 | SOGToXml2(writer, sceneObject, new Dictionary<string,object>()); | ||
304 | } | ||
305 | |||
306 | return sw.ToString(); | ||
307 | } | ||
308 | } | ||
309 | |||
310 | |||
311 | /// <summary> | ||
312 | /// Modifies a SceneObjectGroup. | ||
313 | /// </summary> | ||
314 | /// <param name="sog">The object</param> | ||
315 | /// <returns>Whether the object was actually modified</returns> | ||
316 | public delegate bool SceneObjectModifier(SceneObjectGroup sog); | ||
317 | |||
318 | /// <summary> | ||
319 | /// Modifies an object by deserializing it; applying 'modifier' to each SceneObjectGroup; and reserializing. | ||
320 | /// </summary> | ||
321 | /// <param name="assetId">The object's UUID</param> | ||
322 | /// <param name="data">Serialized data</param> | ||
323 | /// <param name="modifier">The function to run on each SceneObjectGroup</param> | ||
324 | /// <returns>The new serialized object's data, or null if an error occurred</returns> | ||
325 | public static byte[] ModifySerializedObject(UUID assetId, byte[] data, SceneObjectModifier modifier) | ||
326 | { | ||
327 | List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>(); | ||
328 | CoalescedSceneObjects coa = null; | ||
329 | |||
330 | string xmlData = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(data)); | ||
331 | |||
332 | if (CoalescedSceneObjectsSerializer.TryFromXml(xmlData, out coa)) | ||
333 | { | ||
334 | // m_log.DebugFormat("[SERIALIZER]: Loaded coalescence {0} has {1} objects", assetId, coa.Count); | ||
335 | |||
336 | if (coa.Objects.Count == 0) | ||
337 | { | ||
338 | m_log.WarnFormat("[SERIALIZER]: Aborting load of coalesced object from asset {0} as it has zero loaded components", assetId); | ||
339 | return null; | ||
340 | } | ||
341 | |||
342 | sceneObjects.AddRange(coa.Objects); | ||
343 | } | ||
344 | else | ||
345 | { | ||
346 | SceneObjectGroup deserializedObject = FromOriginalXmlFormat(xmlData); | ||
347 | |||
348 | if (deserializedObject != null) | ||
349 | { | ||
350 | sceneObjects.Add(deserializedObject); | ||
351 | } | ||
352 | else | ||
353 | { | ||
354 | m_log.WarnFormat("[SERIALIZER]: Aborting load of object from asset {0} as deserialization failed", assetId); | ||
355 | return null; | ||
356 | } | ||
357 | } | ||
358 | |||
359 | bool modified = false; | ||
360 | foreach (SceneObjectGroup sog in sceneObjects) | ||
361 | { | ||
362 | if (modifier(sog)) | ||
363 | modified = true; | ||
364 | } | ||
365 | |||
366 | if (modified) | ||
367 | { | ||
368 | if (coa != null) | ||
369 | data = Utils.StringToBytes(CoalescedSceneObjectsSerializer.ToXml(coa)); | ||
370 | else | ||
371 | data = Utils.StringToBytes(ToOriginalXmlFormat(sceneObjects[0])); | ||
372 | } | ||
373 | |||
374 | return data; | ||
375 | } | ||
376 | |||
377 | |||
378 | #region manual serialization | ||
379 | |||
380 | private static Dictionary<string, Action<SceneObjectPart, XmlReader>> m_SOPXmlProcessors | ||
381 | = new Dictionary<string, Action<SceneObjectPart, XmlReader>>(); | ||
382 | |||
383 | private static Dictionary<string, Action<TaskInventoryItem, XmlReader>> m_TaskInventoryXmlProcessors | ||
384 | = new Dictionary<string, Action<TaskInventoryItem, XmlReader>>(); | ||
385 | |||
386 | private static Dictionary<string, Action<PrimitiveBaseShape, XmlReader>> m_ShapeXmlProcessors | ||
387 | = new Dictionary<string, Action<PrimitiveBaseShape, XmlReader>>(); | ||
388 | |||
389 | static SceneObjectSerializer() | ||
390 | { | ||
391 | #region SOPXmlProcessors initialization | ||
392 | m_SOPXmlProcessors.Add("AllowedDrop", ProcessAllowedDrop); | ||
393 | m_SOPXmlProcessors.Add("CreatorID", ProcessCreatorID); | ||
394 | m_SOPXmlProcessors.Add("CreatorData", ProcessCreatorData); | ||
395 | m_SOPXmlProcessors.Add("FolderID", ProcessFolderID); | ||
396 | m_SOPXmlProcessors.Add("InventorySerial", ProcessInventorySerial); | ||
397 | m_SOPXmlProcessors.Add("TaskInventory", ProcessTaskInventory); | ||
398 | m_SOPXmlProcessors.Add("UUID", ProcessUUID); | ||
399 | m_SOPXmlProcessors.Add("LocalId", ProcessLocalId); | ||
400 | m_SOPXmlProcessors.Add("Name", ProcessName); | ||
401 | m_SOPXmlProcessors.Add("Material", ProcessMaterial); | ||
402 | m_SOPXmlProcessors.Add("PassTouches", ProcessPassTouches); | ||
403 | m_SOPXmlProcessors.Add("PassCollisions", ProcessPassCollisions); | ||
404 | m_SOPXmlProcessors.Add("RegionHandle", ProcessRegionHandle); | ||
405 | m_SOPXmlProcessors.Add("ScriptAccessPin", ProcessScriptAccessPin); | ||
406 | m_SOPXmlProcessors.Add("GroupPosition", ProcessGroupPosition); | ||
407 | m_SOPXmlProcessors.Add("OffsetPosition", ProcessOffsetPosition); | ||
408 | m_SOPXmlProcessors.Add("RotationOffset", ProcessRotationOffset); | ||
409 | m_SOPXmlProcessors.Add("Velocity", ProcessVelocity); | ||
410 | m_SOPXmlProcessors.Add("AngularVelocity", ProcessAngularVelocity); | ||
411 | m_SOPXmlProcessors.Add("Acceleration", ProcessAcceleration); | ||
412 | m_SOPXmlProcessors.Add("Description", ProcessDescription); | ||
413 | m_SOPXmlProcessors.Add("Color", ProcessColor); | ||
414 | m_SOPXmlProcessors.Add("Text", ProcessText); | ||
415 | m_SOPXmlProcessors.Add("SitName", ProcessSitName); | ||
416 | m_SOPXmlProcessors.Add("TouchName", ProcessTouchName); | ||
417 | m_SOPXmlProcessors.Add("LinkNum", ProcessLinkNum); | ||
418 | m_SOPXmlProcessors.Add("ClickAction", ProcessClickAction); | ||
419 | m_SOPXmlProcessors.Add("Shape", ProcessShape); | ||
420 | m_SOPXmlProcessors.Add("Scale", ProcessScale); | ||
421 | m_SOPXmlProcessors.Add("SitTargetOrientation", ProcessSitTargetOrientation); | ||
422 | m_SOPXmlProcessors.Add("SitTargetPosition", ProcessSitTargetPosition); | ||
423 | m_SOPXmlProcessors.Add("SitTargetPositionLL", ProcessSitTargetPositionLL); | ||
424 | m_SOPXmlProcessors.Add("SitTargetOrientationLL", ProcessSitTargetOrientationLL); | ||
425 | m_SOPXmlProcessors.Add("ParentID", ProcessParentID); | ||
426 | m_SOPXmlProcessors.Add("CreationDate", ProcessCreationDate); | ||
427 | m_SOPXmlProcessors.Add("Category", ProcessCategory); | ||
428 | m_SOPXmlProcessors.Add("SalePrice", ProcessSalePrice); | ||
429 | m_SOPXmlProcessors.Add("ObjectSaleType", ProcessObjectSaleType); | ||
430 | m_SOPXmlProcessors.Add("OwnershipCost", ProcessOwnershipCost); | ||
431 | m_SOPXmlProcessors.Add("GroupID", ProcessGroupID); | ||
432 | m_SOPXmlProcessors.Add("OwnerID", ProcessOwnerID); | ||
433 | m_SOPXmlProcessors.Add("LastOwnerID", ProcessLastOwnerID); | ||
434 | m_SOPXmlProcessors.Add("BaseMask", ProcessBaseMask); | ||
435 | m_SOPXmlProcessors.Add("OwnerMask", ProcessOwnerMask); | ||
436 | m_SOPXmlProcessors.Add("GroupMask", ProcessGroupMask); | ||
437 | m_SOPXmlProcessors.Add("EveryoneMask", ProcessEveryoneMask); | ||
438 | m_SOPXmlProcessors.Add("NextOwnerMask", ProcessNextOwnerMask); | ||
439 | m_SOPXmlProcessors.Add("Flags", ProcessFlags); | ||
440 | m_SOPXmlProcessors.Add("CollisionSound", ProcessCollisionSound); | ||
441 | m_SOPXmlProcessors.Add("CollisionSoundVolume", ProcessCollisionSoundVolume); | ||
442 | m_SOPXmlProcessors.Add("MediaUrl", ProcessMediaUrl); | ||
443 | m_SOPXmlProcessors.Add("AttachedPos", ProcessAttachedPos); | ||
444 | m_SOPXmlProcessors.Add("DynAttrs", ProcessDynAttrs); | ||
445 | m_SOPXmlProcessors.Add("TextureAnimation", ProcessTextureAnimation); | ||
446 | m_SOPXmlProcessors.Add("ParticleSystem", ProcessParticleSystem); | ||
447 | m_SOPXmlProcessors.Add("PayPrice0", ProcessPayPrice0); | ||
448 | m_SOPXmlProcessors.Add("PayPrice1", ProcessPayPrice1); | ||
449 | m_SOPXmlProcessors.Add("PayPrice2", ProcessPayPrice2); | ||
450 | m_SOPXmlProcessors.Add("PayPrice3", ProcessPayPrice3); | ||
451 | m_SOPXmlProcessors.Add("PayPrice4", ProcessPayPrice4); | ||
452 | |||
453 | m_SOPXmlProcessors.Add("PhysicsShapeType", ProcessPhysicsShapeType); | ||
454 | m_SOPXmlProcessors.Add("Density", ProcessDensity); | ||
455 | m_SOPXmlProcessors.Add("Friction", ProcessFriction); | ||
456 | m_SOPXmlProcessors.Add("Bounce", ProcessBounce); | ||
457 | m_SOPXmlProcessors.Add("GravityModifier", ProcessGravityModifier); | ||
458 | |||
459 | #endregion | ||
460 | |||
461 | #region TaskInventoryXmlProcessors initialization | ||
462 | m_TaskInventoryXmlProcessors.Add("AssetID", ProcessTIAssetID); | ||
463 | m_TaskInventoryXmlProcessors.Add("BasePermissions", ProcessTIBasePermissions); | ||
464 | m_TaskInventoryXmlProcessors.Add("CreationDate", ProcessTICreationDate); | ||
465 | m_TaskInventoryXmlProcessors.Add("CreatorID", ProcessTICreatorID); | ||
466 | m_TaskInventoryXmlProcessors.Add("CreatorData", ProcessTICreatorData); | ||
467 | m_TaskInventoryXmlProcessors.Add("Description", ProcessTIDescription); | ||
468 | m_TaskInventoryXmlProcessors.Add("EveryonePermissions", ProcessTIEveryonePermissions); | ||
469 | m_TaskInventoryXmlProcessors.Add("Flags", ProcessTIFlags); | ||
470 | m_TaskInventoryXmlProcessors.Add("GroupID", ProcessTIGroupID); | ||
471 | m_TaskInventoryXmlProcessors.Add("GroupPermissions", ProcessTIGroupPermissions); | ||
472 | m_TaskInventoryXmlProcessors.Add("InvType", ProcessTIInvType); | ||
473 | m_TaskInventoryXmlProcessors.Add("ItemID", ProcessTIItemID); | ||
474 | m_TaskInventoryXmlProcessors.Add("OldItemID", ProcessTIOldItemID); | ||
475 | m_TaskInventoryXmlProcessors.Add("LastOwnerID", ProcessTILastOwnerID); | ||
476 | m_TaskInventoryXmlProcessors.Add("Name", ProcessTIName); | ||
477 | m_TaskInventoryXmlProcessors.Add("NextPermissions", ProcessTINextPermissions); | ||
478 | m_TaskInventoryXmlProcessors.Add("OwnerID", ProcessTIOwnerID); | ||
479 | m_TaskInventoryXmlProcessors.Add("CurrentPermissions", ProcessTICurrentPermissions); | ||
480 | m_TaskInventoryXmlProcessors.Add("ParentID", ProcessTIParentID); | ||
481 | m_TaskInventoryXmlProcessors.Add("ParentPartID", ProcessTIParentPartID); | ||
482 | m_TaskInventoryXmlProcessors.Add("PermsGranter", ProcessTIPermsGranter); | ||
483 | m_TaskInventoryXmlProcessors.Add("PermsMask", ProcessTIPermsMask); | ||
484 | m_TaskInventoryXmlProcessors.Add("Type", ProcessTIType); | ||
485 | m_TaskInventoryXmlProcessors.Add("OwnerChanged", ProcessTIOwnerChanged); | ||
486 | |||
487 | #endregion | ||
488 | |||
489 | #region ShapeXmlProcessors initialization | ||
490 | m_ShapeXmlProcessors.Add("ProfileCurve", ProcessShpProfileCurve); | ||
491 | m_ShapeXmlProcessors.Add("TextureEntry", ProcessShpTextureEntry); | ||
492 | m_ShapeXmlProcessors.Add("ExtraParams", ProcessShpExtraParams); | ||
493 | m_ShapeXmlProcessors.Add("PathBegin", ProcessShpPathBegin); | ||
494 | m_ShapeXmlProcessors.Add("PathCurve", ProcessShpPathCurve); | ||
495 | m_ShapeXmlProcessors.Add("PathEnd", ProcessShpPathEnd); | ||
496 | m_ShapeXmlProcessors.Add("PathRadiusOffset", ProcessShpPathRadiusOffset); | ||
497 | m_ShapeXmlProcessors.Add("PathRevolutions", ProcessShpPathRevolutions); | ||
498 | m_ShapeXmlProcessors.Add("PathScaleX", ProcessShpPathScaleX); | ||
499 | m_ShapeXmlProcessors.Add("PathScaleY", ProcessShpPathScaleY); | ||
500 | m_ShapeXmlProcessors.Add("PathShearX", ProcessShpPathShearX); | ||
501 | m_ShapeXmlProcessors.Add("PathShearY", ProcessShpPathShearY); | ||
502 | m_ShapeXmlProcessors.Add("PathSkew", ProcessShpPathSkew); | ||
503 | m_ShapeXmlProcessors.Add("PathTaperX", ProcessShpPathTaperX); | ||
504 | m_ShapeXmlProcessors.Add("PathTaperY", ProcessShpPathTaperY); | ||
505 | m_ShapeXmlProcessors.Add("PathTwist", ProcessShpPathTwist); | ||
506 | m_ShapeXmlProcessors.Add("PathTwistBegin", ProcessShpPathTwistBegin); | ||
507 | m_ShapeXmlProcessors.Add("PCode", ProcessShpPCode); | ||
508 | m_ShapeXmlProcessors.Add("ProfileBegin", ProcessShpProfileBegin); | ||
509 | m_ShapeXmlProcessors.Add("ProfileEnd", ProcessShpProfileEnd); | ||
510 | m_ShapeXmlProcessors.Add("ProfileHollow", ProcessShpProfileHollow); | ||
511 | m_ShapeXmlProcessors.Add("Scale", ProcessShpScale); | ||
512 | m_ShapeXmlProcessors.Add("LastAttachPoint", ProcessShpLastAttach); | ||
513 | m_ShapeXmlProcessors.Add("State", ProcessShpState); | ||
514 | m_ShapeXmlProcessors.Add("ProfileShape", ProcessShpProfileShape); | ||
515 | m_ShapeXmlProcessors.Add("HollowShape", ProcessShpHollowShape); | ||
516 | m_ShapeXmlProcessors.Add("SculptTexture", ProcessShpSculptTexture); | ||
517 | m_ShapeXmlProcessors.Add("SculptType", ProcessShpSculptType); | ||
518 | // Ignore "SculptData"; this element is deprecated | ||
519 | m_ShapeXmlProcessors.Add("FlexiSoftness", ProcessShpFlexiSoftness); | ||
520 | m_ShapeXmlProcessors.Add("FlexiTension", ProcessShpFlexiTension); | ||
521 | m_ShapeXmlProcessors.Add("FlexiDrag", ProcessShpFlexiDrag); | ||
522 | m_ShapeXmlProcessors.Add("FlexiGravity", ProcessShpFlexiGravity); | ||
523 | m_ShapeXmlProcessors.Add("FlexiWind", ProcessShpFlexiWind); | ||
524 | m_ShapeXmlProcessors.Add("FlexiForceX", ProcessShpFlexiForceX); | ||
525 | m_ShapeXmlProcessors.Add("FlexiForceY", ProcessShpFlexiForceY); | ||
526 | m_ShapeXmlProcessors.Add("FlexiForceZ", ProcessShpFlexiForceZ); | ||
527 | m_ShapeXmlProcessors.Add("LightColorR", ProcessShpLightColorR); | ||
528 | m_ShapeXmlProcessors.Add("LightColorG", ProcessShpLightColorG); | ||
529 | m_ShapeXmlProcessors.Add("LightColorB", ProcessShpLightColorB); | ||
530 | m_ShapeXmlProcessors.Add("LightColorA", ProcessShpLightColorA); | ||
531 | m_ShapeXmlProcessors.Add("LightRadius", ProcessShpLightRadius); | ||
532 | m_ShapeXmlProcessors.Add("LightCutoff", ProcessShpLightCutoff); | ||
533 | m_ShapeXmlProcessors.Add("LightFalloff", ProcessShpLightFalloff); | ||
534 | m_ShapeXmlProcessors.Add("LightIntensity", ProcessShpLightIntensity); | ||
535 | m_ShapeXmlProcessors.Add("FlexiEntry", ProcessShpFlexiEntry); | ||
536 | m_ShapeXmlProcessors.Add("LightEntry", ProcessShpLightEntry); | ||
537 | m_ShapeXmlProcessors.Add("SculptEntry", ProcessShpSculptEntry); | ||
538 | m_ShapeXmlProcessors.Add("Media", ProcessShpMedia); | ||
539 | #endregion | ||
540 | } | ||
541 | |||
542 | #region SOPXmlProcessors | ||
543 | private static void ProcessAllowedDrop(SceneObjectPart obj, XmlReader reader) | ||
544 | { | ||
545 | obj.AllowedDrop = Util.ReadBoolean(reader); | ||
546 | } | ||
547 | |||
548 | private static void ProcessCreatorID(SceneObjectPart obj, XmlReader reader) | ||
549 | { | ||
550 | obj.CreatorID = Util.ReadUUID(reader, "CreatorID"); | ||
551 | } | ||
552 | |||
553 | private static void ProcessCreatorData(SceneObjectPart obj, XmlReader reader) | ||
554 | { | ||
555 | obj.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty); | ||
556 | } | ||
557 | |||
558 | private static void ProcessFolderID(SceneObjectPart obj, XmlReader reader) | ||
559 | { | ||
560 | obj.FolderID = Util.ReadUUID(reader, "FolderID"); | ||
561 | } | ||
562 | |||
563 | private static void ProcessInventorySerial(SceneObjectPart obj, XmlReader reader) | ||
564 | { | ||
565 | obj.InventorySerial = (uint)reader.ReadElementContentAsInt("InventorySerial", String.Empty); | ||
566 | } | ||
567 | |||
568 | private static void ProcessTaskInventory(SceneObjectPart obj, XmlReader reader) | ||
569 | { | ||
570 | obj.TaskInventory = ReadTaskInventory(reader, "TaskInventory"); | ||
571 | } | ||
572 | |||
573 | private static void ProcessUUID(SceneObjectPart obj, XmlReader reader) | ||
574 | { | ||
575 | obj.UUID = Util.ReadUUID(reader, "UUID"); | ||
576 | } | ||
577 | |||
578 | private static void ProcessLocalId(SceneObjectPart obj, XmlReader reader) | ||
579 | { | ||
580 | obj.LocalId = (uint)reader.ReadElementContentAsLong("LocalId", String.Empty); | ||
581 | } | ||
582 | |||
583 | private static void ProcessName(SceneObjectPart obj, XmlReader reader) | ||
584 | { | ||
585 | obj.Name = reader.ReadElementString("Name"); | ||
586 | } | ||
587 | |||
588 | private static void ProcessMaterial(SceneObjectPart obj, XmlReader reader) | ||
589 | { | ||
590 | obj.Material = (byte)reader.ReadElementContentAsInt("Material", String.Empty); | ||
591 | } | ||
592 | |||
593 | private static void ProcessPassTouches(SceneObjectPart obj, XmlReader reader) | ||
594 | { | ||
595 | obj.PassTouches = Util.ReadBoolean(reader); | ||
596 | } | ||
597 | |||
598 | private static void ProcessPassCollisions(SceneObjectPart obj, XmlReader reader) | ||
599 | { | ||
600 | obj.PassCollisions = Util.ReadBoolean(reader); | ||
601 | } | ||
602 | |||
603 | private static void ProcessRegionHandle(SceneObjectPart obj, XmlReader reader) | ||
604 | { | ||
605 | obj.RegionHandle = (ulong)reader.ReadElementContentAsLong("RegionHandle", String.Empty); | ||
606 | } | ||
607 | |||
608 | private static void ProcessScriptAccessPin(SceneObjectPart obj, XmlReader reader) | ||
609 | { | ||
610 | obj.ScriptAccessPin = reader.ReadElementContentAsInt("ScriptAccessPin", String.Empty); | ||
611 | } | ||
612 | |||
613 | private static void ProcessGroupPosition(SceneObjectPart obj, XmlReader reader) | ||
614 | { | ||
615 | obj.GroupPosition = Util.ReadVector(reader, "GroupPosition"); | ||
616 | } | ||
617 | |||
618 | private static void ProcessOffsetPosition(SceneObjectPart obj, XmlReader reader) | ||
619 | { | ||
620 | obj.OffsetPosition = Util.ReadVector(reader, "OffsetPosition"); ; | ||
621 | } | ||
622 | |||
623 | private static void ProcessRotationOffset(SceneObjectPart obj, XmlReader reader) | ||
624 | { | ||
625 | obj.RotationOffset = Util.ReadQuaternion(reader, "RotationOffset"); | ||
626 | } | ||
627 | |||
628 | private static void ProcessVelocity(SceneObjectPart obj, XmlReader reader) | ||
629 | { | ||
630 | obj.Velocity = Util.ReadVector(reader, "Velocity"); | ||
631 | } | ||
632 | |||
633 | private static void ProcessAngularVelocity(SceneObjectPart obj, XmlReader reader) | ||
634 | { | ||
635 | obj.AngularVelocity = Util.ReadVector(reader, "AngularVelocity"); | ||
636 | } | ||
637 | |||
638 | private static void ProcessAcceleration(SceneObjectPart obj, XmlReader reader) | ||
639 | { | ||
640 | obj.Acceleration = Util.ReadVector(reader, "Acceleration"); | ||
641 | } | ||
642 | |||
643 | private static void ProcessDescription(SceneObjectPart obj, XmlReader reader) | ||
644 | { | ||
645 | obj.Description = reader.ReadElementString("Description"); | ||
646 | } | ||
647 | |||
648 | private static void ProcessColor(SceneObjectPart obj, XmlReader reader) | ||
649 | { | ||
650 | reader.ReadStartElement("Color"); | ||
651 | if (reader.Name == "R") | ||
652 | { | ||
653 | float r = reader.ReadElementContentAsFloat("R", String.Empty); | ||
654 | float g = reader.ReadElementContentAsFloat("G", String.Empty); | ||
655 | float b = reader.ReadElementContentAsFloat("B", String.Empty); | ||
656 | float a = reader.ReadElementContentAsFloat("A", String.Empty); | ||
657 | obj.Color = Color.FromArgb((int)a, (int)r, (int)g, (int)b); | ||
658 | reader.ReadEndElement(); | ||
659 | } | ||
660 | } | ||
661 | |||
662 | private static void ProcessText(SceneObjectPart obj, XmlReader reader) | ||
663 | { | ||
664 | obj.Text = reader.ReadElementString("Text", String.Empty); | ||
665 | } | ||
666 | |||
667 | private static void ProcessSitName(SceneObjectPart obj, XmlReader reader) | ||
668 | { | ||
669 | obj.SitName = reader.ReadElementString("SitName", String.Empty); | ||
670 | } | ||
671 | |||
672 | private static void ProcessTouchName(SceneObjectPart obj, XmlReader reader) | ||
673 | { | ||
674 | obj.TouchName = reader.ReadElementString("TouchName", String.Empty); | ||
675 | } | ||
676 | |||
677 | private static void ProcessLinkNum(SceneObjectPart obj, XmlReader reader) | ||
678 | { | ||
679 | obj.LinkNum = reader.ReadElementContentAsInt("LinkNum", String.Empty); | ||
680 | } | ||
681 | |||
682 | private static void ProcessClickAction(SceneObjectPart obj, XmlReader reader) | ||
683 | { | ||
684 | obj.ClickAction = (byte)reader.ReadElementContentAsInt("ClickAction", String.Empty); | ||
685 | } | ||
686 | |||
687 | private static void ProcessPhysicsShapeType(SceneObjectPart obj, XmlReader reader) | ||
688 | { | ||
689 | obj.PhysicsShapeType = (byte)reader.ReadElementContentAsInt("PhysicsShapeType", String.Empty); | ||
690 | } | ||
691 | |||
692 | private static void ProcessDensity(SceneObjectPart obj, XmlReader reader) | ||
693 | { | ||
694 | obj.Density = reader.ReadElementContentAsFloat("Density", String.Empty); | ||
695 | } | ||
696 | |||
697 | private static void ProcessFriction(SceneObjectPart obj, XmlReader reader) | ||
698 | { | ||
699 | obj.Friction = reader.ReadElementContentAsFloat("Friction", String.Empty); | ||
700 | } | ||
701 | |||
702 | private static void ProcessBounce(SceneObjectPart obj, XmlReader reader) | ||
703 | { | ||
704 | obj.Restitution = reader.ReadElementContentAsFloat("Bounce", String.Empty); | ||
705 | } | ||
706 | |||
707 | private static void ProcessGravityModifier(SceneObjectPart obj, XmlReader reader) | ||
708 | { | ||
709 | obj.GravityModifier = reader.ReadElementContentAsFloat("GravityModifier", String.Empty); | ||
710 | } | ||
711 | |||
712 | private static void ProcessShape(SceneObjectPart obj, XmlReader reader) | ||
713 | { | ||
714 | List<string> errorNodeNames; | ||
715 | obj.Shape = ReadShape(reader, "Shape", out errorNodeNames, obj); | ||
716 | |||
717 | if (errorNodeNames != null) | ||
718 | { | ||
719 | m_log.DebugFormat( | ||
720 | "[SceneObjectSerializer]: Parsing PrimitiveBaseShape for object part {0} {1} encountered errors in properties {2}.", | ||
721 | obj.Name, obj.UUID, string.Join(", ", errorNodeNames.ToArray())); | ||
722 | } | ||
723 | } | ||
724 | |||
725 | private static void ProcessScale(SceneObjectPart obj, XmlReader reader) | ||
726 | { | ||
727 | obj.Scale = Util.ReadVector(reader, "Scale"); | ||
728 | } | ||
729 | |||
730 | private static void ProcessSitTargetOrientation(SceneObjectPart obj, XmlReader reader) | ||
731 | { | ||
732 | obj.SitTargetOrientation = Util.ReadQuaternion(reader, "SitTargetOrientation"); | ||
733 | } | ||
734 | |||
735 | private static void ProcessSitTargetPosition(SceneObjectPart obj, XmlReader reader) | ||
736 | { | ||
737 | obj.SitTargetPosition = Util.ReadVector(reader, "SitTargetPosition"); | ||
738 | } | ||
739 | |||
740 | private static void ProcessSitTargetPositionLL(SceneObjectPart obj, XmlReader reader) | ||
741 | { | ||
742 | obj.SitTargetPositionLL = Util.ReadVector(reader, "SitTargetPositionLL"); | ||
743 | } | ||
744 | |||
745 | private static void ProcessSitTargetOrientationLL(SceneObjectPart obj, XmlReader reader) | ||
746 | { | ||
747 | obj.SitTargetOrientationLL = Util.ReadQuaternion(reader, "SitTargetOrientationLL"); | ||
748 | } | ||
749 | |||
750 | private static void ProcessParentID(SceneObjectPart obj, XmlReader reader) | ||
751 | { | ||
752 | string str = reader.ReadElementContentAsString("ParentID", String.Empty); | ||
753 | obj.ParentID = Convert.ToUInt32(str); | ||
754 | } | ||
755 | |||
756 | private static void ProcessCreationDate(SceneObjectPart obj, XmlReader reader) | ||
757 | { | ||
758 | obj.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty); | ||
759 | } | ||
760 | |||
761 | private static void ProcessCategory(SceneObjectPart obj, XmlReader reader) | ||
762 | { | ||
763 | obj.Category = (uint)reader.ReadElementContentAsInt("Category", String.Empty); | ||
764 | } | ||
765 | |||
766 | private static void ProcessSalePrice(SceneObjectPart obj, XmlReader reader) | ||
767 | { | ||
768 | obj.SalePrice = reader.ReadElementContentAsInt("SalePrice", String.Empty); | ||
769 | } | ||
770 | |||
771 | private static void ProcessObjectSaleType(SceneObjectPart obj, XmlReader reader) | ||
772 | { | ||
773 | obj.ObjectSaleType = (byte)reader.ReadElementContentAsInt("ObjectSaleType", String.Empty); | ||
774 | } | ||
775 | |||
776 | private static void ProcessOwnershipCost(SceneObjectPart obj, XmlReader reader) | ||
777 | { | ||
778 | obj.OwnershipCost = reader.ReadElementContentAsInt("OwnershipCost", String.Empty); | ||
779 | } | ||
780 | |||
781 | private static void ProcessGroupID(SceneObjectPart obj, XmlReader reader) | ||
782 | { | ||
783 | obj.GroupID = Util.ReadUUID(reader, "GroupID"); | ||
784 | } | ||
785 | |||
786 | private static void ProcessOwnerID(SceneObjectPart obj, XmlReader reader) | ||
787 | { | ||
788 | obj.OwnerID = Util.ReadUUID(reader, "OwnerID"); | ||
789 | } | ||
790 | |||
791 | private static void ProcessLastOwnerID(SceneObjectPart obj, XmlReader reader) | ||
792 | { | ||
793 | obj.LastOwnerID = Util.ReadUUID(reader, "LastOwnerID"); | ||
794 | } | ||
795 | |||
796 | private static void ProcessBaseMask(SceneObjectPart obj, XmlReader reader) | ||
797 | { | ||
798 | obj.BaseMask = (uint)reader.ReadElementContentAsInt("BaseMask", String.Empty); | ||
799 | } | ||
800 | |||
801 | private static void ProcessOwnerMask(SceneObjectPart obj, XmlReader reader) | ||
802 | { | ||
803 | obj.OwnerMask = (uint)reader.ReadElementContentAsInt("OwnerMask", String.Empty); | ||
804 | } | ||
805 | |||
806 | private static void ProcessGroupMask(SceneObjectPart obj, XmlReader reader) | ||
807 | { | ||
808 | obj.GroupMask = (uint)reader.ReadElementContentAsInt("GroupMask", String.Empty); | ||
809 | } | ||
810 | |||
811 | private static void ProcessEveryoneMask(SceneObjectPart obj, XmlReader reader) | ||
812 | { | ||
813 | obj.EveryoneMask = (uint)reader.ReadElementContentAsInt("EveryoneMask", String.Empty); | ||
814 | } | ||
815 | |||
816 | private static void ProcessNextOwnerMask(SceneObjectPart obj, XmlReader reader) | ||
817 | { | ||
818 | obj.NextOwnerMask = (uint)reader.ReadElementContentAsInt("NextOwnerMask", String.Empty); | ||
819 | } | ||
820 | |||
821 | private static void ProcessFlags(SceneObjectPart obj, XmlReader reader) | ||
822 | { | ||
823 | obj.Flags = Util.ReadEnum<PrimFlags>(reader, "Flags"); | ||
824 | } | ||
825 | |||
826 | private static void ProcessCollisionSound(SceneObjectPart obj, XmlReader reader) | ||
827 | { | ||
828 | obj.CollisionSound = Util.ReadUUID(reader, "CollisionSound"); | ||
829 | } | ||
830 | |||
831 | private static void ProcessCollisionSoundVolume(SceneObjectPart obj, XmlReader reader) | ||
832 | { | ||
833 | obj.CollisionSoundVolume = reader.ReadElementContentAsFloat("CollisionSoundVolume", String.Empty); | ||
834 | } | ||
835 | |||
836 | private static void ProcessMediaUrl(SceneObjectPart obj, XmlReader reader) | ||
837 | { | ||
838 | obj.MediaUrl = reader.ReadElementContentAsString("MediaUrl", String.Empty); | ||
839 | } | ||
840 | |||
841 | private static void ProcessAttachedPos(SceneObjectPart obj, XmlReader reader) | ||
842 | { | ||
843 | obj.AttachedPos = Util.ReadVector(reader, "AttachedPos"); | ||
844 | } | ||
845 | |||
846 | private static void ProcessDynAttrs(SceneObjectPart obj, XmlReader reader) | ||
847 | { | ||
848 | obj.DynAttrs.ReadXml(reader); | ||
849 | } | ||
850 | |||
851 | private static void ProcessTextureAnimation(SceneObjectPart obj, XmlReader reader) | ||
852 | { | ||
853 | obj.TextureAnimation = Convert.FromBase64String(reader.ReadElementContentAsString("TextureAnimation", String.Empty)); | ||
854 | } | ||
855 | |||
856 | private static void ProcessParticleSystem(SceneObjectPart obj, XmlReader reader) | ||
857 | { | ||
858 | obj.ParticleSystem = Convert.FromBase64String(reader.ReadElementContentAsString("ParticleSystem", String.Empty)); | ||
859 | } | ||
860 | |||
861 | private static void ProcessPayPrice0(SceneObjectPart obj, XmlReader reader) | ||
862 | { | ||
863 | obj.PayPrice[0] = (int)reader.ReadElementContentAsInt("PayPrice0", String.Empty); | ||
864 | } | ||
865 | |||
866 | private static void ProcessPayPrice1(SceneObjectPart obj, XmlReader reader) | ||
867 | { | ||
868 | obj.PayPrice[1] = (int)reader.ReadElementContentAsInt("PayPrice1", String.Empty); | ||
869 | } | ||
870 | |||
871 | private static void ProcessPayPrice2(SceneObjectPart obj, XmlReader reader) | ||
872 | { | ||
873 | obj.PayPrice[2] = (int)reader.ReadElementContentAsInt("PayPrice2", String.Empty); | ||
874 | } | ||
875 | |||
876 | private static void ProcessPayPrice3(SceneObjectPart obj, XmlReader reader) | ||
877 | { | ||
878 | obj.PayPrice[3] = (int)reader.ReadElementContentAsInt("PayPrice3", String.Empty); | ||
879 | } | ||
880 | |||
881 | private static void ProcessPayPrice4(SceneObjectPart obj, XmlReader reader) | ||
882 | { | ||
883 | obj.PayPrice[4] = (int)reader.ReadElementContentAsInt("PayPrice4", String.Empty); | ||
884 | } | ||
885 | |||
886 | #endregion | ||
887 | |||
888 | #region TaskInventoryXmlProcessors | ||
889 | private static void ProcessTIAssetID(TaskInventoryItem item, XmlReader reader) | ||
890 | { | ||
891 | item.AssetID = Util.ReadUUID(reader, "AssetID"); | ||
892 | } | ||
893 | |||
894 | private static void ProcessTIBasePermissions(TaskInventoryItem item, XmlReader reader) | ||
895 | { | ||
896 | item.BasePermissions = (uint)reader.ReadElementContentAsInt("BasePermissions", String.Empty); | ||
897 | } | ||
898 | |||
899 | private static void ProcessTICreationDate(TaskInventoryItem item, XmlReader reader) | ||
900 | { | ||
901 | item.CreationDate = (uint)reader.ReadElementContentAsInt("CreationDate", String.Empty); | ||
902 | } | ||
903 | |||
904 | private static void ProcessTICreatorID(TaskInventoryItem item, XmlReader reader) | ||
905 | { | ||
906 | item.CreatorID = Util.ReadUUID(reader, "CreatorID"); | ||
907 | } | ||
908 | |||
909 | private static void ProcessTICreatorData(TaskInventoryItem item, XmlReader reader) | ||
910 | { | ||
911 | item.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty); | ||
912 | } | ||
913 | |||
914 | private static void ProcessTIDescription(TaskInventoryItem item, XmlReader reader) | ||
915 | { | ||
916 | item.Description = reader.ReadElementContentAsString("Description", String.Empty); | ||
917 | } | ||
918 | |||
919 | private static void ProcessTIEveryonePermissions(TaskInventoryItem item, XmlReader reader) | ||
920 | { | ||
921 | item.EveryonePermissions = (uint)reader.ReadElementContentAsInt("EveryonePermissions", String.Empty); | ||
922 | } | ||
923 | |||
924 | private static void ProcessTIFlags(TaskInventoryItem item, XmlReader reader) | ||
925 | { | ||
926 | item.Flags = (uint)reader.ReadElementContentAsInt("Flags", String.Empty); | ||
927 | } | ||
928 | |||
929 | private static void ProcessTIGroupID(TaskInventoryItem item, XmlReader reader) | ||
930 | { | ||
931 | item.GroupID = Util.ReadUUID(reader, "GroupID"); | ||
932 | } | ||
933 | |||
934 | private static void ProcessTIGroupPermissions(TaskInventoryItem item, XmlReader reader) | ||
935 | { | ||
936 | item.GroupPermissions = (uint)reader.ReadElementContentAsInt("GroupPermissions", String.Empty); | ||
937 | } | ||
938 | |||
939 | private static void ProcessTIInvType(TaskInventoryItem item, XmlReader reader) | ||
940 | { | ||
941 | item.InvType = reader.ReadElementContentAsInt("InvType", String.Empty); | ||
942 | } | ||
943 | |||
944 | private static void ProcessTIItemID(TaskInventoryItem item, XmlReader reader) | ||
945 | { | ||
946 | item.ItemID = Util.ReadUUID(reader, "ItemID"); | ||
947 | } | ||
948 | |||
949 | private static void ProcessTIOldItemID(TaskInventoryItem item, XmlReader reader) | ||
950 | { | ||
951 | item.OldItemID = Util.ReadUUID(reader, "OldItemID"); | ||
952 | } | ||
953 | |||
954 | private static void ProcessTILastOwnerID(TaskInventoryItem item, XmlReader reader) | ||
955 | { | ||
956 | item.LastOwnerID = Util.ReadUUID(reader, "LastOwnerID"); | ||
957 | } | ||
958 | |||
959 | private static void ProcessTIName(TaskInventoryItem item, XmlReader reader) | ||
960 | { | ||
961 | item.Name = reader.ReadElementContentAsString("Name", String.Empty); | ||
962 | } | ||
963 | |||
964 | private static void ProcessTINextPermissions(TaskInventoryItem item, XmlReader reader) | ||
965 | { | ||
966 | item.NextPermissions = (uint)reader.ReadElementContentAsInt("NextPermissions", String.Empty); | ||
967 | } | ||
968 | |||
969 | private static void ProcessTIOwnerID(TaskInventoryItem item, XmlReader reader) | ||
970 | { | ||
971 | item.OwnerID = Util.ReadUUID(reader, "OwnerID"); | ||
972 | } | ||
973 | |||
974 | private static void ProcessTICurrentPermissions(TaskInventoryItem item, XmlReader reader) | ||
975 | { | ||
976 | item.CurrentPermissions = (uint)reader.ReadElementContentAsInt("CurrentPermissions", String.Empty); | ||
977 | } | ||
978 | |||
979 | private static void ProcessTIParentID(TaskInventoryItem item, XmlReader reader) | ||
980 | { | ||
981 | item.ParentID = Util.ReadUUID(reader, "ParentID"); | ||
982 | } | ||
983 | |||
984 | private static void ProcessTIParentPartID(TaskInventoryItem item, XmlReader reader) | ||
985 | { | ||
986 | item.ParentPartID = Util.ReadUUID(reader, "ParentPartID"); | ||
987 | } | ||
988 | |||
989 | private static void ProcessTIPermsGranter(TaskInventoryItem item, XmlReader reader) | ||
990 | { | ||
991 | item.PermsGranter = Util.ReadUUID(reader, "PermsGranter"); | ||
992 | } | ||
993 | |||
994 | private static void ProcessTIPermsMask(TaskInventoryItem item, XmlReader reader) | ||
995 | { | ||
996 | item.PermsMask = reader.ReadElementContentAsInt("PermsMask", String.Empty); | ||
997 | } | ||
998 | |||
999 | private static void ProcessTIType(TaskInventoryItem item, XmlReader reader) | ||
1000 | { | ||
1001 | item.Type = reader.ReadElementContentAsInt("Type", String.Empty); | ||
1002 | } | ||
1003 | |||
1004 | private static void ProcessTIOwnerChanged(TaskInventoryItem item, XmlReader reader) | ||
1005 | { | ||
1006 | item.OwnerChanged = Util.ReadBoolean(reader); | ||
1007 | } | ||
1008 | |||
1009 | #endregion | ||
1010 | |||
1011 | #region ShapeXmlProcessors | ||
1012 | private static void ProcessShpProfileCurve(PrimitiveBaseShape shp, XmlReader reader) | ||
1013 | { | ||
1014 | shp.ProfileCurve = (byte)reader.ReadElementContentAsInt("ProfileCurve", String.Empty); | ||
1015 | } | ||
1016 | |||
1017 | private static void ProcessShpTextureEntry(PrimitiveBaseShape shp, XmlReader reader) | ||
1018 | { | ||
1019 | byte[] teData = Convert.FromBase64String(reader.ReadElementString("TextureEntry")); | ||
1020 | shp.Textures = new Primitive.TextureEntry(teData, 0, teData.Length); | ||
1021 | } | ||
1022 | |||
1023 | private static void ProcessShpExtraParams(PrimitiveBaseShape shp, XmlReader reader) | ||
1024 | { | ||
1025 | shp.ExtraParams = Convert.FromBase64String(reader.ReadElementString("ExtraParams")); | ||
1026 | } | ||
1027 | |||
1028 | private static void ProcessShpPathBegin(PrimitiveBaseShape shp, XmlReader reader) | ||
1029 | { | ||
1030 | shp.PathBegin = (ushort)reader.ReadElementContentAsInt("PathBegin", String.Empty); | ||
1031 | } | ||
1032 | |||
1033 | private static void ProcessShpPathCurve(PrimitiveBaseShape shp, XmlReader reader) | ||
1034 | { | ||
1035 | shp.PathCurve = (byte)reader.ReadElementContentAsInt("PathCurve", String.Empty); | ||
1036 | } | ||
1037 | |||
1038 | private static void ProcessShpPathEnd(PrimitiveBaseShape shp, XmlReader reader) | ||
1039 | { | ||
1040 | shp.PathEnd = (ushort)reader.ReadElementContentAsInt("PathEnd", String.Empty); | ||
1041 | } | ||
1042 | |||
1043 | private static void ProcessShpPathRadiusOffset(PrimitiveBaseShape shp, XmlReader reader) | ||
1044 | { | ||
1045 | shp.PathRadiusOffset = (sbyte)reader.ReadElementContentAsInt("PathRadiusOffset", String.Empty); | ||
1046 | } | ||
1047 | |||
1048 | private static void ProcessShpPathRevolutions(PrimitiveBaseShape shp, XmlReader reader) | ||
1049 | { | ||
1050 | shp.PathRevolutions = (byte)reader.ReadElementContentAsInt("PathRevolutions", String.Empty); | ||
1051 | } | ||
1052 | |||
1053 | private static void ProcessShpPathScaleX(PrimitiveBaseShape shp, XmlReader reader) | ||
1054 | { | ||
1055 | shp.PathScaleX = (byte)reader.ReadElementContentAsInt("PathScaleX", String.Empty); | ||
1056 | } | ||
1057 | |||
1058 | private static void ProcessShpPathScaleY(PrimitiveBaseShape shp, XmlReader reader) | ||
1059 | { | ||
1060 | shp.PathScaleY = (byte)reader.ReadElementContentAsInt("PathScaleY", String.Empty); | ||
1061 | } | ||
1062 | |||
1063 | private static void ProcessShpPathShearX(PrimitiveBaseShape shp, XmlReader reader) | ||
1064 | { | ||
1065 | shp.PathShearX = (byte)reader.ReadElementContentAsInt("PathShearX", String.Empty); | ||
1066 | } | ||
1067 | |||
1068 | private static void ProcessShpPathShearY(PrimitiveBaseShape shp, XmlReader reader) | ||
1069 | { | ||
1070 | shp.PathShearY = (byte)reader.ReadElementContentAsInt("PathShearY", String.Empty); | ||
1071 | } | ||
1072 | |||
1073 | private static void ProcessShpPathSkew(PrimitiveBaseShape shp, XmlReader reader) | ||
1074 | { | ||
1075 | shp.PathSkew = (sbyte)reader.ReadElementContentAsInt("PathSkew", String.Empty); | ||
1076 | } | ||
1077 | |||
1078 | private static void ProcessShpPathTaperX(PrimitiveBaseShape shp, XmlReader reader) | ||
1079 | { | ||
1080 | shp.PathTaperX = (sbyte)reader.ReadElementContentAsInt("PathTaperX", String.Empty); | ||
1081 | } | ||
1082 | |||
1083 | private static void ProcessShpPathTaperY(PrimitiveBaseShape shp, XmlReader reader) | ||
1084 | { | ||
1085 | shp.PathTaperY = (sbyte)reader.ReadElementContentAsInt("PathTaperY", String.Empty); | ||
1086 | } | ||
1087 | |||
1088 | private static void ProcessShpPathTwist(PrimitiveBaseShape shp, XmlReader reader) | ||
1089 | { | ||
1090 | shp.PathTwist = (sbyte)reader.ReadElementContentAsInt("PathTwist", String.Empty); | ||
1091 | } | ||
1092 | |||
1093 | private static void ProcessShpPathTwistBegin(PrimitiveBaseShape shp, XmlReader reader) | ||
1094 | { | ||
1095 | shp.PathTwistBegin = (sbyte)reader.ReadElementContentAsInt("PathTwistBegin", String.Empty); | ||
1096 | } | ||
1097 | |||
1098 | private static void ProcessShpPCode(PrimitiveBaseShape shp, XmlReader reader) | ||
1099 | { | ||
1100 | shp.PCode = (byte)reader.ReadElementContentAsInt("PCode", String.Empty); | ||
1101 | } | ||
1102 | |||
1103 | private static void ProcessShpProfileBegin(PrimitiveBaseShape shp, XmlReader reader) | ||
1104 | { | ||
1105 | shp.ProfileBegin = (ushort)reader.ReadElementContentAsInt("ProfileBegin", String.Empty); | ||
1106 | } | ||
1107 | |||
1108 | private static void ProcessShpProfileEnd(PrimitiveBaseShape shp, XmlReader reader) | ||
1109 | { | ||
1110 | shp.ProfileEnd = (ushort)reader.ReadElementContentAsInt("ProfileEnd", String.Empty); | ||
1111 | } | ||
1112 | |||
1113 | private static void ProcessShpProfileHollow(PrimitiveBaseShape shp, XmlReader reader) | ||
1114 | { | ||
1115 | shp.ProfileHollow = (ushort)reader.ReadElementContentAsInt("ProfileHollow", String.Empty); | ||
1116 | } | ||
1117 | |||
1118 | private static void ProcessShpScale(PrimitiveBaseShape shp, XmlReader reader) | ||
1119 | { | ||
1120 | shp.Scale = Util.ReadVector(reader, "Scale"); | ||
1121 | } | ||
1122 | |||
1123 | private static void ProcessShpState(PrimitiveBaseShape shp, XmlReader reader) | ||
1124 | { | ||
1125 | shp.State = (byte)reader.ReadElementContentAsInt("State", String.Empty); | ||
1126 | } | ||
1127 | |||
1128 | private static void ProcessShpLastAttach(PrimitiveBaseShape shp, XmlReader reader) | ||
1129 | { | ||
1130 | shp.LastAttachPoint = (byte)reader.ReadElementContentAsInt("LastAttachPoint", String.Empty); | ||
1131 | } | ||
1132 | |||
1133 | private static void ProcessShpProfileShape(PrimitiveBaseShape shp, XmlReader reader) | ||
1134 | { | ||
1135 | shp.ProfileShape = Util.ReadEnum<ProfileShape>(reader, "ProfileShape"); | ||
1136 | } | ||
1137 | |||
1138 | private static void ProcessShpHollowShape(PrimitiveBaseShape shp, XmlReader reader) | ||
1139 | { | ||
1140 | shp.HollowShape = Util.ReadEnum<HollowShape>(reader, "HollowShape"); | ||
1141 | } | ||
1142 | |||
1143 | private static void ProcessShpSculptTexture(PrimitiveBaseShape shp, XmlReader reader) | ||
1144 | { | ||
1145 | shp.SculptTexture = Util.ReadUUID(reader, "SculptTexture"); | ||
1146 | } | ||
1147 | |||
1148 | private static void ProcessShpSculptType(PrimitiveBaseShape shp, XmlReader reader) | ||
1149 | { | ||
1150 | shp.SculptType = (byte)reader.ReadElementContentAsInt("SculptType", String.Empty); | ||
1151 | } | ||
1152 | |||
1153 | private static void ProcessShpFlexiSoftness(PrimitiveBaseShape shp, XmlReader reader) | ||
1154 | { | ||
1155 | shp.FlexiSoftness = reader.ReadElementContentAsInt("FlexiSoftness", String.Empty); | ||
1156 | } | ||
1157 | |||
1158 | private static void ProcessShpFlexiTension(PrimitiveBaseShape shp, XmlReader reader) | ||
1159 | { | ||
1160 | shp.FlexiTension = reader.ReadElementContentAsFloat("FlexiTension", String.Empty); | ||
1161 | } | ||
1162 | |||
1163 | private static void ProcessShpFlexiDrag(PrimitiveBaseShape shp, XmlReader reader) | ||
1164 | { | ||
1165 | shp.FlexiDrag = reader.ReadElementContentAsFloat("FlexiDrag", String.Empty); | ||
1166 | } | ||
1167 | |||
1168 | private static void ProcessShpFlexiGravity(PrimitiveBaseShape shp, XmlReader reader) | ||
1169 | { | ||
1170 | shp.FlexiGravity = reader.ReadElementContentAsFloat("FlexiGravity", String.Empty); | ||
1171 | } | ||
1172 | |||
1173 | private static void ProcessShpFlexiWind(PrimitiveBaseShape shp, XmlReader reader) | ||
1174 | { | ||
1175 | shp.FlexiWind = reader.ReadElementContentAsFloat("FlexiWind", String.Empty); | ||
1176 | } | ||
1177 | |||
1178 | private static void ProcessShpFlexiForceX(PrimitiveBaseShape shp, XmlReader reader) | ||
1179 | { | ||
1180 | shp.FlexiForceX = reader.ReadElementContentAsFloat("FlexiForceX", String.Empty); | ||
1181 | } | ||
1182 | |||
1183 | private static void ProcessShpFlexiForceY(PrimitiveBaseShape shp, XmlReader reader) | ||
1184 | { | ||
1185 | shp.FlexiForceY = reader.ReadElementContentAsFloat("FlexiForceY", String.Empty); | ||
1186 | } | ||
1187 | |||
1188 | private static void ProcessShpFlexiForceZ(PrimitiveBaseShape shp, XmlReader reader) | ||
1189 | { | ||
1190 | shp.FlexiForceZ = reader.ReadElementContentAsFloat("FlexiForceZ", String.Empty); | ||
1191 | } | ||
1192 | |||
1193 | private static void ProcessShpLightColorR(PrimitiveBaseShape shp, XmlReader reader) | ||
1194 | { | ||
1195 | shp.LightColorR = reader.ReadElementContentAsFloat("LightColorR", String.Empty); | ||
1196 | } | ||
1197 | |||
1198 | private static void ProcessShpLightColorG(PrimitiveBaseShape shp, XmlReader reader) | ||
1199 | { | ||
1200 | shp.LightColorG = reader.ReadElementContentAsFloat("LightColorG", String.Empty); | ||
1201 | } | ||
1202 | |||
1203 | private static void ProcessShpLightColorB(PrimitiveBaseShape shp, XmlReader reader) | ||
1204 | { | ||
1205 | shp.LightColorB = reader.ReadElementContentAsFloat("LightColorB", String.Empty); | ||
1206 | } | ||
1207 | |||
1208 | private static void ProcessShpLightColorA(PrimitiveBaseShape shp, XmlReader reader) | ||
1209 | { | ||
1210 | shp.LightColorA = reader.ReadElementContentAsFloat("LightColorA", String.Empty); | ||
1211 | } | ||
1212 | |||
1213 | private static void ProcessShpLightRadius(PrimitiveBaseShape shp, XmlReader reader) | ||
1214 | { | ||
1215 | shp.LightRadius = reader.ReadElementContentAsFloat("LightRadius", String.Empty); | ||
1216 | } | ||
1217 | |||
1218 | private static void ProcessShpLightCutoff(PrimitiveBaseShape shp, XmlReader reader) | ||
1219 | { | ||
1220 | shp.LightCutoff = reader.ReadElementContentAsFloat("LightCutoff", String.Empty); | ||
1221 | } | ||
1222 | |||
1223 | private static void ProcessShpLightFalloff(PrimitiveBaseShape shp, XmlReader reader) | ||
1224 | { | ||
1225 | shp.LightFalloff = reader.ReadElementContentAsFloat("LightFalloff", String.Empty); | ||
1226 | } | ||
1227 | |||
1228 | private static void ProcessShpLightIntensity(PrimitiveBaseShape shp, XmlReader reader) | ||
1229 | { | ||
1230 | shp.LightIntensity = reader.ReadElementContentAsFloat("LightIntensity", String.Empty); | ||
1231 | } | ||
1232 | |||
1233 | private static void ProcessShpFlexiEntry(PrimitiveBaseShape shp, XmlReader reader) | ||
1234 | { | ||
1235 | shp.FlexiEntry = Util.ReadBoolean(reader); | ||
1236 | } | ||
1237 | |||
1238 | private static void ProcessShpLightEntry(PrimitiveBaseShape shp, XmlReader reader) | ||
1239 | { | ||
1240 | shp.LightEntry = Util.ReadBoolean(reader); | ||
1241 | } | ||
1242 | |||
1243 | private static void ProcessShpSculptEntry(PrimitiveBaseShape shp, XmlReader reader) | ||
1244 | { | ||
1245 | shp.SculptEntry = Util.ReadBoolean(reader); | ||
1246 | } | ||
1247 | |||
1248 | private static void ProcessShpMedia(PrimitiveBaseShape shp, XmlReader reader) | ||
1249 | { | ||
1250 | string value = reader.ReadElementContentAsString("Media", String.Empty); | ||
1251 | shp.Media = PrimitiveBaseShape.MediaList.FromXml(value); | ||
1252 | } | ||
1253 | |||
1254 | #endregion | ||
1255 | |||
1256 | ////////// Write ///////// | ||
1257 | |||
1258 | public static void SOGToXml2(XmlTextWriter writer, SceneObjectGroup sog, Dictionary<string, object>options) | ||
1259 | { | ||
1260 | writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty); | ||
1261 | SOPToXml2(writer, sog.RootPart, options); | ||
1262 | writer.WriteStartElement(String.Empty, "OtherParts", String.Empty); | ||
1263 | |||
1264 | sog.ForEachPart(delegate(SceneObjectPart sop) | ||
1265 | { | ||
1266 | if (sop.UUID != sog.RootPart.UUID) | ||
1267 | SOPToXml2(writer, sop, options); | ||
1268 | }); | ||
1269 | |||
1270 | writer.WriteEndElement(); | ||
1271 | |||
1272 | if (sog.RootPart.KeyframeMotion != null) | ||
1273 | { | ||
1274 | Byte[] data = sog.RootPart.KeyframeMotion.Serialize(); | ||
1275 | |||
1276 | writer.WriteStartElement(String.Empty, "KeyframeMotion", String.Empty); | ||
1277 | writer.WriteBase64(data, 0, data.Length); | ||
1278 | writer.WriteEndElement(); | ||
1279 | } | ||
1280 | |||
1281 | writer.WriteEndElement(); | ||
1282 | } | ||
1283 | |||
1284 | public static void SOPToXml2(XmlTextWriter writer, SceneObjectPart sop, Dictionary<string, object> options) | ||
1285 | { | ||
1286 | writer.WriteStartElement("SceneObjectPart"); | ||
1287 | writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); | ||
1288 | writer.WriteAttributeString("xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); | ||
1289 | |||
1290 | writer.WriteElementString("AllowedDrop", sop.AllowedDrop.ToString().ToLower()); | ||
1291 | |||
1292 | WriteUUID(writer, "CreatorID", sop.CreatorID, options); | ||
1293 | |||
1294 | if (!string.IsNullOrEmpty(sop.CreatorData)) | ||
1295 | writer.WriteElementString("CreatorData", sop.CreatorData); | ||
1296 | else if (options.ContainsKey("home")) | ||
1297 | { | ||
1298 | if (m_UserManagement == null) | ||
1299 | m_UserManagement = sop.ParentGroup.Scene.RequestModuleInterface<IUserManagement>(); | ||
1300 | string name = m_UserManagement.GetUserName(sop.CreatorID); | ||
1301 | writer.WriteElementString("CreatorData", ExternalRepresentationUtils.CalcCreatorData((string)options["home"], name)); | ||
1302 | } | ||
1303 | |||
1304 | WriteUUID(writer, "FolderID", sop.FolderID, options); | ||
1305 | writer.WriteElementString("InventorySerial", sop.InventorySerial.ToString()); | ||
1306 | |||
1307 | WriteTaskInventory(writer, sop.TaskInventory, options, sop.ParentGroup.Scene); | ||
1308 | |||
1309 | WriteUUID(writer, "UUID", sop.UUID, options); | ||
1310 | writer.WriteElementString("LocalId", sop.LocalId.ToString()); | ||
1311 | writer.WriteElementString("Name", sop.Name); | ||
1312 | writer.WriteElementString("Material", sop.Material.ToString()); | ||
1313 | writer.WriteElementString("PassTouches", sop.PassTouches.ToString().ToLower()); | ||
1314 | writer.WriteElementString("PassCollisions", sop.PassCollisions.ToString().ToLower()); | ||
1315 | writer.WriteElementString("RegionHandle", sop.RegionHandle.ToString()); | ||
1316 | writer.WriteElementString("ScriptAccessPin", sop.ScriptAccessPin.ToString()); | ||
1317 | |||
1318 | WriteVector(writer, "GroupPosition", sop.GroupPosition); | ||
1319 | WriteVector(writer, "OffsetPosition", sop.OffsetPosition); | ||
1320 | |||
1321 | WriteQuaternion(writer, "RotationOffset", sop.RotationOffset); | ||
1322 | WriteVector(writer, "Velocity", sop.Velocity); | ||
1323 | WriteVector(writer, "AngularVelocity", sop.AngularVelocity); | ||
1324 | WriteVector(writer, "Acceleration", sop.Acceleration); | ||
1325 | writer.WriteElementString("Description", sop.Description); | ||
1326 | |||
1327 | writer.WriteStartElement("Color"); | ||
1328 | writer.WriteElementString("R", sop.Color.R.ToString(Utils.EnUsCulture)); | ||
1329 | writer.WriteElementString("G", sop.Color.G.ToString(Utils.EnUsCulture)); | ||
1330 | writer.WriteElementString("B", sop.Color.B.ToString(Utils.EnUsCulture)); | ||
1331 | writer.WriteElementString("A", sop.Color.A.ToString(Utils.EnUsCulture)); | ||
1332 | writer.WriteEndElement(); | ||
1333 | |||
1334 | writer.WriteElementString("Text", sop.Text); | ||
1335 | writer.WriteElementString("SitName", sop.SitName); | ||
1336 | writer.WriteElementString("TouchName", sop.TouchName); | ||
1337 | |||
1338 | writer.WriteElementString("LinkNum", sop.LinkNum.ToString()); | ||
1339 | writer.WriteElementString("ClickAction", sop.ClickAction.ToString()); | ||
1340 | |||
1341 | WriteShape(writer, sop.Shape, options); | ||
1342 | |||
1343 | WriteVector(writer, "Scale", sop.Scale); | ||
1344 | WriteQuaternion(writer, "SitTargetOrientation", sop.SitTargetOrientation); | ||
1345 | WriteVector(writer, "SitTargetPosition", sop.SitTargetPosition); | ||
1346 | WriteVector(writer, "SitTargetPositionLL", sop.SitTargetPositionLL); | ||
1347 | WriteQuaternion(writer, "SitTargetOrientationLL", sop.SitTargetOrientationLL); | ||
1348 | writer.WriteElementString("ParentID", sop.ParentID.ToString()); | ||
1349 | writer.WriteElementString("CreationDate", sop.CreationDate.ToString()); | ||
1350 | writer.WriteElementString("Category", sop.Category.ToString()); | ||
1351 | writer.WriteElementString("SalePrice", sop.SalePrice.ToString()); | ||
1352 | writer.WriteElementString("ObjectSaleType", sop.ObjectSaleType.ToString()); | ||
1353 | writer.WriteElementString("OwnershipCost", sop.OwnershipCost.ToString()); | ||
1354 | |||
1355 | UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.GroupID; | ||
1356 | WriteUUID(writer, "GroupID", groupID, options); | ||
1357 | |||
1358 | UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.OwnerID; | ||
1359 | WriteUUID(writer, "OwnerID", ownerID, options); | ||
1360 | |||
1361 | UUID lastOwnerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.LastOwnerID; | ||
1362 | WriteUUID(writer, "LastOwnerID", lastOwnerID, options); | ||
1363 | |||
1364 | writer.WriteElementString("BaseMask", sop.BaseMask.ToString()); | ||
1365 | writer.WriteElementString("OwnerMask", sop.OwnerMask.ToString()); | ||
1366 | writer.WriteElementString("GroupMask", sop.GroupMask.ToString()); | ||
1367 | writer.WriteElementString("EveryoneMask", sop.EveryoneMask.ToString()); | ||
1368 | writer.WriteElementString("NextOwnerMask", sop.NextOwnerMask.ToString()); | ||
1369 | WriteFlags(writer, "Flags", sop.Flags.ToString(), options); | ||
1370 | WriteUUID(writer, "CollisionSound", sop.CollisionSound, options); | ||
1371 | writer.WriteElementString("CollisionSoundVolume", sop.CollisionSoundVolume.ToString()); | ||
1372 | if (sop.MediaUrl != null) | ||
1373 | writer.WriteElementString("MediaUrl", sop.MediaUrl.ToString()); | ||
1374 | WriteVector(writer, "AttachedPos", sop.AttachedPos); | ||
1375 | |||
1376 | if (sop.DynAttrs.CountNamespaces > 0) | ||
1377 | { | ||
1378 | writer.WriteStartElement("DynAttrs"); | ||
1379 | sop.DynAttrs.WriteXml(writer); | ||
1380 | writer.WriteEndElement(); | ||
1381 | } | ||
1382 | |||
1383 | WriteBytes(writer, "TextureAnimation", sop.TextureAnimation); | ||
1384 | WriteBytes(writer, "ParticleSystem", sop.ParticleSystem); | ||
1385 | writer.WriteElementString("PayPrice0", sop.PayPrice[0].ToString()); | ||
1386 | writer.WriteElementString("PayPrice1", sop.PayPrice[1].ToString()); | ||
1387 | writer.WriteElementString("PayPrice2", sop.PayPrice[2].ToString()); | ||
1388 | writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString()); | ||
1389 | writer.WriteElementString("PayPrice4", sop.PayPrice[4].ToString()); | ||
1390 | |||
1391 | if(sop.PhysicsShapeType != sop.DefaultPhysicsShapeType()) | ||
1392 | writer.WriteElementString("PhysicsShapeType", sop.PhysicsShapeType.ToString().ToLower()); | ||
1393 | if (sop.Density != 1000.0f) | ||
1394 | writer.WriteElementString("Density", sop.Density.ToString().ToLower()); | ||
1395 | if (sop.Friction != 0.6f) | ||
1396 | writer.WriteElementString("Friction", sop.Friction.ToString().ToLower()); | ||
1397 | if (sop.Restitution != 0.5f) | ||
1398 | writer.WriteElementString("Bounce", sop.Restitution.ToString().ToLower()); | ||
1399 | if (sop.GravityModifier != 1.0f) | ||
1400 | writer.WriteElementString("GravityModifier", sop.GravityModifier.ToString().ToLower()); | ||
1401 | |||
1402 | writer.WriteEndElement(); | ||
1403 | } | ||
1404 | |||
1405 | static void WriteUUID(XmlTextWriter writer, string name, UUID id, Dictionary<string, object> options) | ||
1406 | { | ||
1407 | writer.WriteStartElement(name); | ||
1408 | if (options.ContainsKey("old-guids")) | ||
1409 | writer.WriteElementString("Guid", id.ToString()); | ||
1410 | else | ||
1411 | writer.WriteElementString("UUID", id.ToString()); | ||
1412 | writer.WriteEndElement(); | ||
1413 | } | ||
1414 | |||
1415 | static void WriteVector(XmlTextWriter writer, string name, Vector3 vec) | ||
1416 | { | ||
1417 | writer.WriteStartElement(name); | ||
1418 | writer.WriteElementString("X", vec.X.ToString(Utils.EnUsCulture)); | ||
1419 | writer.WriteElementString("Y", vec.Y.ToString(Utils.EnUsCulture)); | ||
1420 | writer.WriteElementString("Z", vec.Z.ToString(Utils.EnUsCulture)); | ||
1421 | writer.WriteEndElement(); | ||
1422 | } | ||
1423 | |||
1424 | static void WriteQuaternion(XmlTextWriter writer, string name, Quaternion quat) | ||
1425 | { | ||
1426 | writer.WriteStartElement(name); | ||
1427 | writer.WriteElementString("X", quat.X.ToString(Utils.EnUsCulture)); | ||
1428 | writer.WriteElementString("Y", quat.Y.ToString(Utils.EnUsCulture)); | ||
1429 | writer.WriteElementString("Z", quat.Z.ToString(Utils.EnUsCulture)); | ||
1430 | writer.WriteElementString("W", quat.W.ToString(Utils.EnUsCulture)); | ||
1431 | writer.WriteEndElement(); | ||
1432 | } | ||
1433 | |||
1434 | static void WriteBytes(XmlTextWriter writer, string name, byte[] data) | ||
1435 | { | ||
1436 | writer.WriteStartElement(name); | ||
1437 | byte[] d; | ||
1438 | if (data != null) | ||
1439 | d = data; | ||
1440 | else | ||
1441 | d = Utils.EmptyBytes; | ||
1442 | writer.WriteBase64(d, 0, d.Length); | ||
1443 | writer.WriteEndElement(); // name | ||
1444 | |||
1445 | } | ||
1446 | |||
1447 | static void WriteFlags(XmlTextWriter writer, string name, string flagsStr, Dictionary<string, object> options) | ||
1448 | { | ||
1449 | // Older versions of serialization can't cope with commas, so we eliminate the commas | ||
1450 | writer.WriteElementString(name, flagsStr.Replace(",", "")); | ||
1451 | } | ||
1452 | |||
1453 | public static void WriteTaskInventory(XmlTextWriter writer, TaskInventoryDictionary tinv, Dictionary<string, object> options, Scene scene) | ||
1454 | { | ||
1455 | if (tinv.Count > 0) // otherwise skip this | ||
1456 | { | ||
1457 | writer.WriteStartElement("TaskInventory"); | ||
1458 | |||
1459 | foreach (TaskInventoryItem item in tinv.Values) | ||
1460 | { | ||
1461 | writer.WriteStartElement("TaskInventoryItem"); | ||
1462 | |||
1463 | WriteUUID(writer, "AssetID", item.AssetID, options); | ||
1464 | writer.WriteElementString("BasePermissions", item.BasePermissions.ToString()); | ||
1465 | writer.WriteElementString("CreationDate", item.CreationDate.ToString()); | ||
1466 | |||
1467 | WriteUUID(writer, "CreatorID", item.CreatorID, options); | ||
1468 | |||
1469 | if (!string.IsNullOrEmpty(item.CreatorData)) | ||
1470 | writer.WriteElementString("CreatorData", item.CreatorData); | ||
1471 | else if (options.ContainsKey("home")) | ||
1472 | { | ||
1473 | if (m_UserManagement == null) | ||
1474 | m_UserManagement = scene.RequestModuleInterface<IUserManagement>(); | ||
1475 | string name = m_UserManagement.GetUserName(item.CreatorID); | ||
1476 | writer.WriteElementString("CreatorData", ExternalRepresentationUtils.CalcCreatorData((string)options["home"], name)); | ||
1477 | } | ||
1478 | |||
1479 | writer.WriteElementString("Description", item.Description); | ||
1480 | writer.WriteElementString("EveryonePermissions", item.EveryonePermissions.ToString()); | ||
1481 | writer.WriteElementString("Flags", item.Flags.ToString()); | ||
1482 | |||
1483 | UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.GroupID; | ||
1484 | WriteUUID(writer, "GroupID", groupID, options); | ||
1485 | |||
1486 | writer.WriteElementString("GroupPermissions", item.GroupPermissions.ToString()); | ||
1487 | writer.WriteElementString("InvType", item.InvType.ToString()); | ||
1488 | WriteUUID(writer, "ItemID", item.ItemID, options); | ||
1489 | WriteUUID(writer, "OldItemID", item.OldItemID, options); | ||
1490 | |||
1491 | UUID lastOwnerID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.LastOwnerID; | ||
1492 | WriteUUID(writer, "LastOwnerID", lastOwnerID, options); | ||
1493 | |||
1494 | writer.WriteElementString("Name", item.Name); | ||
1495 | writer.WriteElementString("NextPermissions", item.NextPermissions.ToString()); | ||
1496 | |||
1497 | UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.OwnerID; | ||
1498 | WriteUUID(writer, "OwnerID", ownerID, options); | ||
1499 | |||
1500 | writer.WriteElementString("CurrentPermissions", item.CurrentPermissions.ToString()); | ||
1501 | WriteUUID(writer, "ParentID", item.ParentID, options); | ||
1502 | WriteUUID(writer, "ParentPartID", item.ParentPartID, options); | ||
1503 | WriteUUID(writer, "PermsGranter", item.PermsGranter, options); | ||
1504 | writer.WriteElementString("PermsMask", item.PermsMask.ToString()); | ||
1505 | writer.WriteElementString("Type", item.Type.ToString()); | ||
1506 | |||
1507 | bool ownerChanged = options.ContainsKey("wipe-owners") ? false : item.OwnerChanged; | ||
1508 | writer.WriteElementString("OwnerChanged", ownerChanged.ToString().ToLower()); | ||
1509 | |||
1510 | writer.WriteEndElement(); // TaskInventoryItem | ||
1511 | } | ||
1512 | |||
1513 | writer.WriteEndElement(); // TaskInventory | ||
1514 | } | ||
1515 | } | ||
1516 | |||
1517 | public static void WriteShape(XmlTextWriter writer, PrimitiveBaseShape shp, Dictionary<string, object> options) | ||
1518 | { | ||
1519 | if (shp != null) | ||
1520 | { | ||
1521 | writer.WriteStartElement("Shape"); | ||
1522 | |||
1523 | writer.WriteElementString("ProfileCurve", shp.ProfileCurve.ToString()); | ||
1524 | |||
1525 | writer.WriteStartElement("TextureEntry"); | ||
1526 | byte[] te; | ||
1527 | if (shp.TextureEntry != null) | ||
1528 | te = shp.TextureEntry; | ||
1529 | else | ||
1530 | te = Utils.EmptyBytes; | ||
1531 | writer.WriteBase64(te, 0, te.Length); | ||
1532 | writer.WriteEndElement(); // TextureEntry | ||
1533 | |||
1534 | writer.WriteStartElement("ExtraParams"); | ||
1535 | byte[] ep; | ||
1536 | if (shp.ExtraParams != null) | ||
1537 | ep = shp.ExtraParams; | ||
1538 | else | ||
1539 | ep = Utils.EmptyBytes; | ||
1540 | writer.WriteBase64(ep, 0, ep.Length); | ||
1541 | writer.WriteEndElement(); // ExtraParams | ||
1542 | |||
1543 | writer.WriteElementString("PathBegin", shp.PathBegin.ToString()); | ||
1544 | writer.WriteElementString("PathCurve", shp.PathCurve.ToString()); | ||
1545 | writer.WriteElementString("PathEnd", shp.PathEnd.ToString()); | ||
1546 | writer.WriteElementString("PathRadiusOffset", shp.PathRadiusOffset.ToString()); | ||
1547 | writer.WriteElementString("PathRevolutions", shp.PathRevolutions.ToString()); | ||
1548 | writer.WriteElementString("PathScaleX", shp.PathScaleX.ToString()); | ||
1549 | writer.WriteElementString("PathScaleY", shp.PathScaleY.ToString()); | ||
1550 | writer.WriteElementString("PathShearX", shp.PathShearX.ToString()); | ||
1551 | writer.WriteElementString("PathShearY", shp.PathShearY.ToString()); | ||
1552 | writer.WriteElementString("PathSkew", shp.PathSkew.ToString()); | ||
1553 | writer.WriteElementString("PathTaperX", shp.PathTaperX.ToString()); | ||
1554 | writer.WriteElementString("PathTaperY", shp.PathTaperY.ToString()); | ||
1555 | writer.WriteElementString("PathTwist", shp.PathTwist.ToString()); | ||
1556 | writer.WriteElementString("PathTwistBegin", shp.PathTwistBegin.ToString()); | ||
1557 | writer.WriteElementString("PCode", shp.PCode.ToString()); | ||
1558 | writer.WriteElementString("ProfileBegin", shp.ProfileBegin.ToString()); | ||
1559 | writer.WriteElementString("ProfileEnd", shp.ProfileEnd.ToString()); | ||
1560 | writer.WriteElementString("ProfileHollow", shp.ProfileHollow.ToString()); | ||
1561 | writer.WriteElementString("State", shp.State.ToString()); | ||
1562 | writer.WriteElementString("LastAttachPoint", shp.LastAttachPoint.ToString()); | ||
1563 | |||
1564 | WriteFlags(writer, "ProfileShape", shp.ProfileShape.ToString(), options); | ||
1565 | WriteFlags(writer, "HollowShape", shp.HollowShape.ToString(), options); | ||
1566 | |||
1567 | WriteUUID(writer, "SculptTexture", shp.SculptTexture, options); | ||
1568 | writer.WriteElementString("SculptType", shp.SculptType.ToString()); | ||
1569 | // Don't serialize SculptData. It's just a copy of the asset, which can be loaded separately using 'SculptTexture'. | ||
1570 | |||
1571 | writer.WriteElementString("FlexiSoftness", shp.FlexiSoftness.ToString()); | ||
1572 | writer.WriteElementString("FlexiTension", shp.FlexiTension.ToString()); | ||
1573 | writer.WriteElementString("FlexiDrag", shp.FlexiDrag.ToString()); | ||
1574 | writer.WriteElementString("FlexiGravity", shp.FlexiGravity.ToString()); | ||
1575 | writer.WriteElementString("FlexiWind", shp.FlexiWind.ToString()); | ||
1576 | writer.WriteElementString("FlexiForceX", shp.FlexiForceX.ToString()); | ||
1577 | writer.WriteElementString("FlexiForceY", shp.FlexiForceY.ToString()); | ||
1578 | writer.WriteElementString("FlexiForceZ", shp.FlexiForceZ.ToString()); | ||
1579 | |||
1580 | writer.WriteElementString("LightColorR", shp.LightColorR.ToString()); | ||
1581 | writer.WriteElementString("LightColorG", shp.LightColorG.ToString()); | ||
1582 | writer.WriteElementString("LightColorB", shp.LightColorB.ToString()); | ||
1583 | writer.WriteElementString("LightColorA", shp.LightColorA.ToString()); | ||
1584 | writer.WriteElementString("LightRadius", shp.LightRadius.ToString()); | ||
1585 | writer.WriteElementString("LightCutoff", shp.LightCutoff.ToString()); | ||
1586 | writer.WriteElementString("LightFalloff", shp.LightFalloff.ToString()); | ||
1587 | writer.WriteElementString("LightIntensity", shp.LightIntensity.ToString()); | ||
1588 | |||
1589 | writer.WriteElementString("FlexiEntry", shp.FlexiEntry.ToString().ToLower()); | ||
1590 | writer.WriteElementString("LightEntry", shp.LightEntry.ToString().ToLower()); | ||
1591 | writer.WriteElementString("SculptEntry", shp.SculptEntry.ToString().ToLower()); | ||
1592 | |||
1593 | if (shp.Media != null) | ||
1594 | writer.WriteElementString("Media", shp.Media.ToXml()); | ||
1595 | |||
1596 | writer.WriteEndElement(); // Shape | ||
1597 | } | ||
1598 | } | ||
1599 | |||
1600 | public static SceneObjectPart Xml2ToSOP(XmlReader reader) | ||
1601 | { | ||
1602 | SceneObjectPart obj = new SceneObjectPart(); | ||
1603 | |||
1604 | reader.ReadStartElement("SceneObjectPart"); | ||
1605 | |||
1606 | bool errors = ExternalRepresentationUtils.ExecuteReadProcessors( | ||
1607 | obj, | ||
1608 | m_SOPXmlProcessors, | ||
1609 | reader, | ||
1610 | (o, nodeName, e) => { | ||
1611 | m_log.Debug(string.Format("[SceneObjectSerializer]: Error while parsing element {0} in object {1} {2} ", | ||
1612 | nodeName, ((SceneObjectPart)o).Name, ((SceneObjectPart)o).UUID), e); | ||
1613 | }); | ||
1614 | |||
1615 | if (errors) | ||
1616 | throw new XmlException(string.Format("Error parsing object {0} {1}", obj.Name, obj.UUID)); | ||
1617 | |||
1618 | reader.ReadEndElement(); // SceneObjectPart | ||
1619 | |||
1620 | // m_log.DebugFormat("[SceneObjectSerializer]: parsed SOP {0} {1}", obj.Name, obj.UUID); | ||
1621 | return obj; | ||
1622 | } | ||
1623 | |||
1624 | public static TaskInventoryDictionary ReadTaskInventory(XmlReader reader, string name) | ||
1625 | { | ||
1626 | TaskInventoryDictionary tinv = new TaskInventoryDictionary(); | ||
1627 | |||
1628 | if (reader.IsEmptyElement) | ||
1629 | { | ||
1630 | reader.Read(); | ||
1631 | return tinv; | ||
1632 | } | ||
1633 | |||
1634 | reader.ReadStartElement(name, String.Empty); | ||
1635 | |||
1636 | while (reader.Name == "TaskInventoryItem") | ||
1637 | { | ||
1638 | reader.ReadStartElement("TaskInventoryItem", String.Empty); // TaskInventory | ||
1639 | |||
1640 | TaskInventoryItem item = new TaskInventoryItem(); | ||
1641 | |||
1642 | ExternalRepresentationUtils.ExecuteReadProcessors( | ||
1643 | item, | ||
1644 | m_TaskInventoryXmlProcessors, | ||
1645 | reader); | ||
1646 | |||
1647 | reader.ReadEndElement(); // TaskInventoryItem | ||
1648 | tinv.Add(item.ItemID, item); | ||
1649 | |||
1650 | } | ||
1651 | |||
1652 | if (reader.NodeType == XmlNodeType.EndElement) | ||
1653 | reader.ReadEndElement(); // TaskInventory | ||
1654 | |||
1655 | return tinv; | ||
1656 | } | ||
1657 | |||
1658 | /// <summary> | ||
1659 | /// Read a shape from xml input | ||
1660 | /// </summary> | ||
1661 | /// <param name="reader"></param> | ||
1662 | /// <param name="name">The name of the xml element containing the shape</param> | ||
1663 | /// <param name="errors">a list containing the failing node names. If no failures then null.</param> | ||
1664 | /// <returns>The shape parsed</returns> | ||
1665 | public static PrimitiveBaseShape ReadShape(XmlReader reader, string name, out List<string> errorNodeNames, SceneObjectPart obj) | ||
1666 | { | ||
1667 | List<string> internalErrorNodeNames = null; | ||
1668 | |||
1669 | PrimitiveBaseShape shape = new PrimitiveBaseShape(); | ||
1670 | |||
1671 | if (reader.IsEmptyElement) | ||
1672 | { | ||
1673 | reader.Read(); | ||
1674 | errorNodeNames = null; | ||
1675 | return shape; | ||
1676 | } | ||
1677 | |||
1678 | reader.ReadStartElement(name, String.Empty); // Shape | ||
1679 | |||
1680 | ExternalRepresentationUtils.ExecuteReadProcessors( | ||
1681 | shape, | ||
1682 | m_ShapeXmlProcessors, | ||
1683 | reader, | ||
1684 | (o, nodeName, e) => { | ||
1685 | m_log.Debug(string.Format("[SceneObjectSerializer]: Error while parsing element {0} in Shape property of object {1} {2} ", | ||
1686 | nodeName, obj.Name, obj.UUID), e); | ||
1687 | |||
1688 | if (internalErrorNodeNames == null) | ||
1689 | internalErrorNodeNames = new List<string>(); | ||
1690 | internalErrorNodeNames.Add(nodeName); | ||
1691 | }); | ||
1692 | |||
1693 | reader.ReadEndElement(); // Shape | ||
1694 | |||
1695 | errorNodeNames = internalErrorNodeNames; | ||
1696 | |||
1697 | return shape; | ||
1698 | } | ||
1699 | |||
1700 | #endregion | ||
1701 | } | ||
1702 | } | ||