clockwerk-opensim – Blame information for rev 1

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