OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
SceneObjectSerializer.cs
Go to the documentation of this file.
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 {
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 
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 
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 
126  public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject)
127  {
128  return ToOriginalXmlFormat(sceneObject, true);
129  }
130 
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 
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 
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 
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 
315  public delegate bool SceneObjectModifier(SceneObjectGroup sog);
316 
324  public static byte[] ModifySerializedObject(UUID assetId, byte[] data, SceneObjectModifier modifier)
325  {
326  List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>();
327  CoalescedSceneObjects coa = null;
328 
329  string xmlData = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(data));
330  if (CoalescedSceneObjectsSerializer.TryFromXml(xmlData, out coa))
331  {
332  // m_log.DebugFormat("[SERIALIZER]: Loaded coalescence {0} has {1} objects", assetId, coa.Count);
333 
334  if (coa.Objects.Count == 0)
335  {
336  m_log.WarnFormat("[SERIALIZER]: Aborting load of coalesced object from asset {0} as it has zero loaded components", assetId);
337  return null;
338  }
339 
340  sceneObjects.AddRange(coa.Objects);
341  }
342  else
343  {
344  SceneObjectGroup deserializedObject = FromOriginalXmlFormat(xmlData);
345 
346  if (deserializedObject != null)
347  {
348  sceneObjects.Add(deserializedObject);
349  }
350  else
351  {
352  m_log.WarnFormat("[SERIALIZER]: Aborting load of object from asset {0} as deserialization failed", assetId);
353  return null;
354  }
355  }
356 
357  bool modified = false;
358  foreach (SceneObjectGroup sog in sceneObjects)
359  {
360  if (modifier(sog))
361  modified = true;
362  }
363 
364  if (modified)
365  {
366  if (coa != null)
367  data = Utils.StringToBytes(CoalescedSceneObjectsSerializer.ToXml(coa));
368  else
369  data = Utils.StringToBytes(ToOriginalXmlFormat(sceneObjects[0]));
370  }
371 
372  return data;
373  }
374 
375  #region manual serialization
376 
377  private static Dictionary<string, Action<SceneObjectPart, XmlReader>> m_SOPXmlProcessors
378  = new Dictionary<string, Action<SceneObjectPart, XmlReader>>();
379 
380  private static Dictionary<string, Action<TaskInventoryItem, XmlReader>> m_TaskInventoryXmlProcessors
381  = new Dictionary<string, Action<TaskInventoryItem, XmlReader>>();
382 
383  private static Dictionary<string, Action<PrimitiveBaseShape, XmlReader>> m_ShapeXmlProcessors
384  = new Dictionary<string, Action<PrimitiveBaseShape, XmlReader>>();
385 
386  static SceneObjectSerializer()
387  {
388  #region SOPXmlProcessors initialization
389  m_SOPXmlProcessors.Add("AllowedDrop", ProcessAllowedDrop);
390  m_SOPXmlProcessors.Add("CreatorID", ProcessCreatorID);
391  m_SOPXmlProcessors.Add("CreatorData", ProcessCreatorData);
392  m_SOPXmlProcessors.Add("FolderID", ProcessFolderID);
393  m_SOPXmlProcessors.Add("InventorySerial", ProcessInventorySerial);
394  m_SOPXmlProcessors.Add("TaskInventory", ProcessTaskInventory);
395  m_SOPXmlProcessors.Add("UUID", ProcessUUID);
396  m_SOPXmlProcessors.Add("LocalId", ProcessLocalId);
397  m_SOPXmlProcessors.Add("Name", ProcessName);
398  m_SOPXmlProcessors.Add("Material", ProcessMaterial);
399  m_SOPXmlProcessors.Add("PassTouches", ProcessPassTouches);
400  m_SOPXmlProcessors.Add("PassCollisions", ProcessPassCollisions);
401  m_SOPXmlProcessors.Add("RegionHandle", ProcessRegionHandle);
402  m_SOPXmlProcessors.Add("ScriptAccessPin", ProcessScriptAccessPin);
403  m_SOPXmlProcessors.Add("GroupPosition", ProcessGroupPosition);
404  m_SOPXmlProcessors.Add("OffsetPosition", ProcessOffsetPosition);
405  m_SOPXmlProcessors.Add("RotationOffset", ProcessRotationOffset);
406  m_SOPXmlProcessors.Add("Velocity", ProcessVelocity);
407  m_SOPXmlProcessors.Add("AngularVelocity", ProcessAngularVelocity);
408  m_SOPXmlProcessors.Add("Acceleration", ProcessAcceleration);
409  m_SOPXmlProcessors.Add("Description", ProcessDescription);
410  m_SOPXmlProcessors.Add("Color", ProcessColor);
411  m_SOPXmlProcessors.Add("Text", ProcessText);
412  m_SOPXmlProcessors.Add("SitName", ProcessSitName);
413  m_SOPXmlProcessors.Add("TouchName", ProcessTouchName);
414  m_SOPXmlProcessors.Add("LinkNum", ProcessLinkNum);
415  m_SOPXmlProcessors.Add("ClickAction", ProcessClickAction);
416  m_SOPXmlProcessors.Add("Shape", ProcessShape);
417  m_SOPXmlProcessors.Add("Scale", ProcessScale);
418  m_SOPXmlProcessors.Add("SitTargetOrientation", ProcessSitTargetOrientation);
419  m_SOPXmlProcessors.Add("SitTargetPosition", ProcessSitTargetPosition);
420  m_SOPXmlProcessors.Add("SitTargetPositionLL", ProcessSitTargetPositionLL);
421  m_SOPXmlProcessors.Add("SitTargetOrientationLL", ProcessSitTargetOrientationLL);
422  m_SOPXmlProcessors.Add("ParentID", ProcessParentID);
423  m_SOPXmlProcessors.Add("CreationDate", ProcessCreationDate);
424  m_SOPXmlProcessors.Add("Category", ProcessCategory);
425  m_SOPXmlProcessors.Add("SalePrice", ProcessSalePrice);
426  m_SOPXmlProcessors.Add("ObjectSaleType", ProcessObjectSaleType);
427  m_SOPXmlProcessors.Add("OwnershipCost", ProcessOwnershipCost);
428  m_SOPXmlProcessors.Add("GroupID", ProcessGroupID);
429  m_SOPXmlProcessors.Add("OwnerID", ProcessOwnerID);
430  m_SOPXmlProcessors.Add("LastOwnerID", ProcessLastOwnerID);
431  m_SOPXmlProcessors.Add("BaseMask", ProcessBaseMask);
432  m_SOPXmlProcessors.Add("OwnerMask", ProcessOwnerMask);
433  m_SOPXmlProcessors.Add("GroupMask", ProcessGroupMask);
434  m_SOPXmlProcessors.Add("EveryoneMask", ProcessEveryoneMask);
435  m_SOPXmlProcessors.Add("NextOwnerMask", ProcessNextOwnerMask);
436  m_SOPXmlProcessors.Add("Flags", ProcessFlags);
437  m_SOPXmlProcessors.Add("CollisionSound", ProcessCollisionSound);
438  m_SOPXmlProcessors.Add("CollisionSoundVolume", ProcessCollisionSoundVolume);
439  m_SOPXmlProcessors.Add("MediaUrl", ProcessMediaUrl);
440  m_SOPXmlProcessors.Add("AttachedPos", ProcessAttachedPos);
441  m_SOPXmlProcessors.Add("DynAttrs", ProcessDynAttrs);
442  m_SOPXmlProcessors.Add("TextureAnimation", ProcessTextureAnimation);
443  m_SOPXmlProcessors.Add("ParticleSystem", ProcessParticleSystem);
444  m_SOPXmlProcessors.Add("PayPrice0", ProcessPayPrice0);
445  m_SOPXmlProcessors.Add("PayPrice1", ProcessPayPrice1);
446  m_SOPXmlProcessors.Add("PayPrice2", ProcessPayPrice2);
447  m_SOPXmlProcessors.Add("PayPrice3", ProcessPayPrice3);
448  m_SOPXmlProcessors.Add("PayPrice4", ProcessPayPrice4);
449 
450  m_SOPXmlProcessors.Add("Buoyancy", ProcessBuoyancy);
451  m_SOPXmlProcessors.Add("Force", ProcessForce);
452  m_SOPXmlProcessors.Add("Torque", ProcessTorque);
453  m_SOPXmlProcessors.Add("VolumeDetectActive", ProcessVolumeDetectActive);
454 
455 
456  m_SOPXmlProcessors.Add("Vehicle", ProcessVehicle);
457 
458  m_SOPXmlProcessors.Add("RotationAxisLocks", ProcessRotationAxisLocks);
459  m_SOPXmlProcessors.Add("PhysicsShapeType", ProcessPhysicsShapeType);
460  m_SOPXmlProcessors.Add("Density", ProcessDensity);
461  m_SOPXmlProcessors.Add("Friction", ProcessFriction);
462  m_SOPXmlProcessors.Add("Bounce", ProcessBounce);
463  m_SOPXmlProcessors.Add("GravityModifier", ProcessGravityModifier);
464  m_SOPXmlProcessors.Add("CameraEyeOffset", ProcessCameraEyeOffset);
465  m_SOPXmlProcessors.Add("CameraAtOffset", ProcessCameraAtOffset);
466 
467  m_SOPXmlProcessors.Add("SoundID", ProcessSoundID);
468  m_SOPXmlProcessors.Add("SoundGain", ProcessSoundGain);
469  m_SOPXmlProcessors.Add("SoundFlags", ProcessSoundFlags);
470  m_SOPXmlProcessors.Add("SoundRadius", ProcessSoundRadius);
471  m_SOPXmlProcessors.Add("SoundQueueing", ProcessSoundQueueing);
472 
473  #endregion
474 
475  #region TaskInventoryXmlProcessors initialization
476  m_TaskInventoryXmlProcessors.Add("AssetID", ProcessTIAssetID);
477  m_TaskInventoryXmlProcessors.Add("BasePermissions", ProcessTIBasePermissions);
478  m_TaskInventoryXmlProcessors.Add("CreationDate", ProcessTICreationDate);
479  m_TaskInventoryXmlProcessors.Add("CreatorID", ProcessTICreatorID);
480  m_TaskInventoryXmlProcessors.Add("CreatorData", ProcessTICreatorData);
481  m_TaskInventoryXmlProcessors.Add("Description", ProcessTIDescription);
482  m_TaskInventoryXmlProcessors.Add("EveryonePermissions", ProcessTIEveryonePermissions);
483  m_TaskInventoryXmlProcessors.Add("Flags", ProcessTIFlags);
484  m_TaskInventoryXmlProcessors.Add("GroupID", ProcessTIGroupID);
485  m_TaskInventoryXmlProcessors.Add("GroupPermissions", ProcessTIGroupPermissions);
486  m_TaskInventoryXmlProcessors.Add("InvType", ProcessTIInvType);
487  m_TaskInventoryXmlProcessors.Add("ItemID", ProcessTIItemID);
488  m_TaskInventoryXmlProcessors.Add("OldItemID", ProcessTIOldItemID);
489  m_TaskInventoryXmlProcessors.Add("LastOwnerID", ProcessTILastOwnerID);
490  m_TaskInventoryXmlProcessors.Add("Name", ProcessTIName);
491  m_TaskInventoryXmlProcessors.Add("NextPermissions", ProcessTINextPermissions);
492  m_TaskInventoryXmlProcessors.Add("OwnerID", ProcessTIOwnerID);
493  m_TaskInventoryXmlProcessors.Add("CurrentPermissions", ProcessTICurrentPermissions);
494  m_TaskInventoryXmlProcessors.Add("ParentID", ProcessTIParentID);
495  m_TaskInventoryXmlProcessors.Add("ParentPartID", ProcessTIParentPartID);
496  m_TaskInventoryXmlProcessors.Add("PermsGranter", ProcessTIPermsGranter);
497  m_TaskInventoryXmlProcessors.Add("PermsMask", ProcessTIPermsMask);
498  m_TaskInventoryXmlProcessors.Add("Type", ProcessTIType);
499  m_TaskInventoryXmlProcessors.Add("OwnerChanged", ProcessTIOwnerChanged);
500 
501  #endregion
502 
503  #region ShapeXmlProcessors initialization
504  m_ShapeXmlProcessors.Add("ProfileCurve", ProcessShpProfileCurve);
505  m_ShapeXmlProcessors.Add("TextureEntry", ProcessShpTextureEntry);
506  m_ShapeXmlProcessors.Add("ExtraParams", ProcessShpExtraParams);
507  m_ShapeXmlProcessors.Add("PathBegin", ProcessShpPathBegin);
508  m_ShapeXmlProcessors.Add("PathCurve", ProcessShpPathCurve);
509  m_ShapeXmlProcessors.Add("PathEnd", ProcessShpPathEnd);
510  m_ShapeXmlProcessors.Add("PathRadiusOffset", ProcessShpPathRadiusOffset);
511  m_ShapeXmlProcessors.Add("PathRevolutions", ProcessShpPathRevolutions);
512  m_ShapeXmlProcessors.Add("PathScaleX", ProcessShpPathScaleX);
513  m_ShapeXmlProcessors.Add("PathScaleY", ProcessShpPathScaleY);
514  m_ShapeXmlProcessors.Add("PathShearX", ProcessShpPathShearX);
515  m_ShapeXmlProcessors.Add("PathShearY", ProcessShpPathShearY);
516  m_ShapeXmlProcessors.Add("PathSkew", ProcessShpPathSkew);
517  m_ShapeXmlProcessors.Add("PathTaperX", ProcessShpPathTaperX);
518  m_ShapeXmlProcessors.Add("PathTaperY", ProcessShpPathTaperY);
519  m_ShapeXmlProcessors.Add("PathTwist", ProcessShpPathTwist);
520  m_ShapeXmlProcessors.Add("PathTwistBegin", ProcessShpPathTwistBegin);
521  m_ShapeXmlProcessors.Add("PCode", ProcessShpPCode);
522  m_ShapeXmlProcessors.Add("ProfileBegin", ProcessShpProfileBegin);
523  m_ShapeXmlProcessors.Add("ProfileEnd", ProcessShpProfileEnd);
524  m_ShapeXmlProcessors.Add("ProfileHollow", ProcessShpProfileHollow);
525  m_ShapeXmlProcessors.Add("Scale", ProcessShpScale);
526  m_ShapeXmlProcessors.Add("LastAttachPoint", ProcessShpLastAttach);
527  m_ShapeXmlProcessors.Add("State", ProcessShpState);
528  m_ShapeXmlProcessors.Add("ProfileShape", ProcessShpProfileShape);
529  m_ShapeXmlProcessors.Add("HollowShape", ProcessShpHollowShape);
530  m_ShapeXmlProcessors.Add("SculptTexture", ProcessShpSculptTexture);
531  m_ShapeXmlProcessors.Add("SculptType", ProcessShpSculptType);
532  // Ignore "SculptData"; this element is deprecated
533  m_ShapeXmlProcessors.Add("FlexiSoftness", ProcessShpFlexiSoftness);
534  m_ShapeXmlProcessors.Add("FlexiTension", ProcessShpFlexiTension);
535  m_ShapeXmlProcessors.Add("FlexiDrag", ProcessShpFlexiDrag);
536  m_ShapeXmlProcessors.Add("FlexiGravity", ProcessShpFlexiGravity);
537  m_ShapeXmlProcessors.Add("FlexiWind", ProcessShpFlexiWind);
538  m_ShapeXmlProcessors.Add("FlexiForceX", ProcessShpFlexiForceX);
539  m_ShapeXmlProcessors.Add("FlexiForceY", ProcessShpFlexiForceY);
540  m_ShapeXmlProcessors.Add("FlexiForceZ", ProcessShpFlexiForceZ);
541  m_ShapeXmlProcessors.Add("LightColorR", ProcessShpLightColorR);
542  m_ShapeXmlProcessors.Add("LightColorG", ProcessShpLightColorG);
543  m_ShapeXmlProcessors.Add("LightColorB", ProcessShpLightColorB);
544  m_ShapeXmlProcessors.Add("LightColorA", ProcessShpLightColorA);
545  m_ShapeXmlProcessors.Add("LightRadius", ProcessShpLightRadius);
546  m_ShapeXmlProcessors.Add("LightCutoff", ProcessShpLightCutoff);
547  m_ShapeXmlProcessors.Add("LightFalloff", ProcessShpLightFalloff);
548  m_ShapeXmlProcessors.Add("LightIntensity", ProcessShpLightIntensity);
549  m_ShapeXmlProcessors.Add("FlexiEntry", ProcessShpFlexiEntry);
550  m_ShapeXmlProcessors.Add("LightEntry", ProcessShpLightEntry);
551  m_ShapeXmlProcessors.Add("SculptEntry", ProcessShpSculptEntry);
552  m_ShapeXmlProcessors.Add("Media", ProcessShpMedia);
553  #endregion
554  }
555 
556  #region SOPXmlProcessors
557  private static void ProcessAllowedDrop(SceneObjectPart obj, XmlReader reader)
558  {
559  obj.AllowedDrop = Util.ReadBoolean(reader);
560  }
561 
562  private static void ProcessCreatorID(SceneObjectPart obj, XmlReader reader)
563  {
564  obj.CreatorID = Util.ReadUUID(reader, "CreatorID");
565  }
566 
567  private static void ProcessCreatorData(SceneObjectPart obj, XmlReader reader)
568  {
569  obj.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty);
570  }
571 
572  private static void ProcessFolderID(SceneObjectPart obj, XmlReader reader)
573  {
574  obj.FolderID = Util.ReadUUID(reader, "FolderID");
575  }
576 
577  private static void ProcessInventorySerial(SceneObjectPart obj, XmlReader reader)
578  {
579  obj.InventorySerial = (uint)reader.ReadElementContentAsInt("InventorySerial", String.Empty);
580  }
581 
582  private static void ProcessTaskInventory(SceneObjectPart obj, XmlReader reader)
583  {
584  obj.TaskInventory = ReadTaskInventory(reader, "TaskInventory");
585  }
586 
587  private static void ProcessUUID(SceneObjectPart obj, XmlReader reader)
588  {
589  obj.UUID = Util.ReadUUID(reader, "UUID");
590  }
591 
592  private static void ProcessLocalId(SceneObjectPart obj, XmlReader reader)
593  {
594  obj.LocalId = (uint)reader.ReadElementContentAsLong("LocalId", String.Empty);
595  }
596 
597  private static void ProcessName(SceneObjectPart obj, XmlReader reader)
598  {
599  obj.Name = reader.ReadElementString("Name");
600  }
601 
602  private static void ProcessMaterial(SceneObjectPart obj, XmlReader reader)
603  {
604  obj.Material = (byte)reader.ReadElementContentAsInt("Material", String.Empty);
605  }
606 
607  private static void ProcessPassTouches(SceneObjectPart obj, XmlReader reader)
608  {
609  obj.PassTouches = Util.ReadBoolean(reader);
610  }
611 
612  private static void ProcessPassCollisions(SceneObjectPart obj, XmlReader reader)
613  {
614  obj.PassCollisions = Util.ReadBoolean(reader);
615  }
616 
617  private static void ProcessRegionHandle(SceneObjectPart obj, XmlReader reader)
618  {
619  obj.RegionHandle = (ulong)reader.ReadElementContentAsLong("RegionHandle", String.Empty);
620  }
621 
622  private static void ProcessScriptAccessPin(SceneObjectPart obj, XmlReader reader)
623  {
624  obj.ScriptAccessPin = reader.ReadElementContentAsInt("ScriptAccessPin", String.Empty);
625  }
626 
627  private static void ProcessGroupPosition(SceneObjectPart obj, XmlReader reader)
628  {
629  obj.GroupPosition = Util.ReadVector(reader, "GroupPosition");
630  }
631 
632  private static void ProcessOffsetPosition(SceneObjectPart obj, XmlReader reader)
633  {
634  obj.OffsetPosition = Util.ReadVector(reader, "OffsetPosition"); ;
635  }
636 
637  private static void ProcessRotationOffset(SceneObjectPart obj, XmlReader reader)
638  {
639  obj.RotationOffset = Util.ReadQuaternion(reader, "RotationOffset");
640  }
641 
642  private static void ProcessVelocity(SceneObjectPart obj, XmlReader reader)
643  {
644  obj.Velocity = Util.ReadVector(reader, "Velocity");
645  }
646 
647  private static void ProcessAngularVelocity(SceneObjectPart obj, XmlReader reader)
648  {
649  obj.AngularVelocity = Util.ReadVector(reader, "AngularVelocity");
650  }
651 
652  private static void ProcessAcceleration(SceneObjectPart obj, XmlReader reader)
653  {
654  obj.Acceleration = Util.ReadVector(reader, "Acceleration");
655  }
656 
657  private static void ProcessDescription(SceneObjectPart obj, XmlReader reader)
658  {
659  obj.Description = reader.ReadElementString("Description");
660  }
661 
662  private static void ProcessColor(SceneObjectPart obj, XmlReader reader)
663  {
664  reader.ReadStartElement("Color");
665  if (reader.Name == "R")
666  {
667  float r = reader.ReadElementContentAsFloat("R", String.Empty);
668  float g = reader.ReadElementContentAsFloat("G", String.Empty);
669  float b = reader.ReadElementContentAsFloat("B", String.Empty);
670  float a = reader.ReadElementContentAsFloat("A", String.Empty);
671  obj.Color = Color.FromArgb((int)a, (int)r, (int)g, (int)b);
672  reader.ReadEndElement();
673  }
674  }
675 
676  private static void ProcessText(SceneObjectPart obj, XmlReader reader)
677  {
678  obj.Text = reader.ReadElementString("Text", String.Empty);
679  }
680 
681  private static void ProcessSitName(SceneObjectPart obj, XmlReader reader)
682  {
683  obj.SitName = reader.ReadElementString("SitName", String.Empty);
684  }
685 
686  private static void ProcessTouchName(SceneObjectPart obj, XmlReader reader)
687  {
688  obj.TouchName = reader.ReadElementString("TouchName", String.Empty);
689  }
690 
691  private static void ProcessLinkNum(SceneObjectPart obj, XmlReader reader)
692  {
693  obj.LinkNum = reader.ReadElementContentAsInt("LinkNum", String.Empty);
694  }
695 
696  private static void ProcessClickAction(SceneObjectPart obj, XmlReader reader)
697  {
698  obj.ClickAction = (byte)reader.ReadElementContentAsInt("ClickAction", String.Empty);
699  }
700 
701  private static void ProcessRotationAxisLocks(SceneObjectPart obj, XmlReader reader)
702  {
703  obj.RotationAxisLocks = (byte)reader.ReadElementContentAsInt("RotationAxisLocks", String.Empty);
704  }
705 
706  private static void ProcessPhysicsShapeType(SceneObjectPart obj, XmlReader reader)
707  {
708  obj.PhysicsShapeType = (byte)reader.ReadElementContentAsInt("PhysicsShapeType", String.Empty);
709  }
710 
711  private static void ProcessDensity(SceneObjectPart obj, XmlReader reader)
712  {
713  obj.Density = reader.ReadElementContentAsFloat("Density", String.Empty);
714  }
715 
716  private static void ProcessFriction(SceneObjectPart obj, XmlReader reader)
717  {
718  obj.Friction = reader.ReadElementContentAsFloat("Friction", String.Empty);
719  }
720 
721  private static void ProcessBounce(SceneObjectPart obj, XmlReader reader)
722  {
723  obj.Restitution = reader.ReadElementContentAsFloat("Bounce", String.Empty);
724  }
725 
726  private static void ProcessGravityModifier(SceneObjectPart obj, XmlReader reader)
727  {
728  obj.GravityModifier = reader.ReadElementContentAsFloat("GravityModifier", String.Empty);
729  }
730 
731  private static void ProcessCameraEyeOffset(SceneObjectPart obj, XmlReader reader)
732  {
733  obj.SetCameraEyeOffset(Util.ReadVector(reader, "CameraEyeOffset"));
734  }
735 
736  private static void ProcessCameraAtOffset(SceneObjectPart obj, XmlReader reader)
737  {
738  obj.SetCameraAtOffset(Util.ReadVector(reader, "CameraAtOffset"));
739  }
740 
741  private static void ProcessSoundID(SceneObjectPart obj, XmlReader reader)
742  {
743  obj.Sound = Util.ReadUUID(reader, "SoundID");
744  }
745 
746  private static void ProcessSoundGain(SceneObjectPart obj, XmlReader reader)
747  {
748  obj.SoundGain = reader.ReadElementContentAsDouble("SoundGain", String.Empty);
749  }
750 
751  private static void ProcessSoundFlags(SceneObjectPart obj, XmlReader reader)
752  {
753  obj.SoundFlags = (byte)reader.ReadElementContentAsInt("SoundFlags", String.Empty);
754  }
755 
756  private static void ProcessSoundRadius(SceneObjectPart obj, XmlReader reader)
757  {
758  obj.SoundRadius = reader.ReadElementContentAsDouble("SoundRadius", String.Empty);
759  }
760 
761  private static void ProcessSoundQueueing(SceneObjectPart obj, XmlReader reader)
762  {
763  obj.SoundQueueing = Util.ReadBoolean(reader);
764  }
765 
766  private static void ProcessVehicle(SceneObjectPart obj, XmlReader reader)
767  {
768  SOPVehicle vehicle = SOPVehicle.FromXml2(reader);
769 
770  if (vehicle == null)
771  {
772  obj.VehicleParams = null;
773  m_log.DebugFormat(
774  "[SceneObjectSerializer]: Parsing Vehicle for object part {0} {1} encountered errors. Please see earlier log entries.",
775  obj.Name, obj.UUID);
776  }
777  else
778  {
779  obj.VehicleParams = vehicle;
780  }
781  }
782 
783  private static void ProcessShape(SceneObjectPart obj, XmlReader reader)
784  {
785  List<string> errorNodeNames;
786  obj.Shape = ReadShape(reader, "Shape", out errorNodeNames, obj);
787 
788  if (errorNodeNames != null)
789  {
790  m_log.DebugFormat(
791  "[SceneObjectSerializer]: Parsing PrimitiveBaseShape for object part {0} {1} encountered errors in properties {2}.",
792  obj.Name, obj.UUID, string.Join(", ", errorNodeNames.ToArray()));
793  }
794  }
795 
796  private static void ProcessScale(SceneObjectPart obj, XmlReader reader)
797  {
798  obj.Scale = Util.ReadVector(reader, "Scale");
799  }
800 
801  private static void ProcessSitTargetOrientation(SceneObjectPart obj, XmlReader reader)
802  {
803  obj.SitTargetOrientation = Util.ReadQuaternion(reader, "SitTargetOrientation");
804  }
805 
806  private static void ProcessSitTargetPosition(SceneObjectPart obj, XmlReader reader)
807  {
808  obj.SitTargetPosition = Util.ReadVector(reader, "SitTargetPosition");
809  }
810 
811  private static void ProcessSitTargetPositionLL(SceneObjectPart obj, XmlReader reader)
812  {
813  obj.SitTargetPositionLL = Util.ReadVector(reader, "SitTargetPositionLL");
814  }
815 
816  private static void ProcessSitTargetOrientationLL(SceneObjectPart obj, XmlReader reader)
817  {
818  obj.SitTargetOrientationLL = Util.ReadQuaternion(reader, "SitTargetOrientationLL");
819  }
820 
821  private static void ProcessParentID(SceneObjectPart obj, XmlReader reader)
822  {
823  string str = reader.ReadElementContentAsString("ParentID", String.Empty);
824  obj.ParentID = Convert.ToUInt32(str);
825  }
826 
827  private static void ProcessCreationDate(SceneObjectPart obj, XmlReader reader)
828  {
829  obj.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty);
830  }
831 
832  private static void ProcessCategory(SceneObjectPart obj, XmlReader reader)
833  {
834  obj.Category = (uint)reader.ReadElementContentAsInt("Category", String.Empty);
835  }
836 
837  private static void ProcessSalePrice(SceneObjectPart obj, XmlReader reader)
838  {
839  obj.SalePrice = reader.ReadElementContentAsInt("SalePrice", String.Empty);
840  }
841 
842  private static void ProcessObjectSaleType(SceneObjectPart obj, XmlReader reader)
843  {
844  obj.ObjectSaleType = (byte)reader.ReadElementContentAsInt("ObjectSaleType", String.Empty);
845  }
846 
847  private static void ProcessOwnershipCost(SceneObjectPart obj, XmlReader reader)
848  {
849  obj.OwnershipCost = reader.ReadElementContentAsInt("OwnershipCost", String.Empty);
850  }
851 
852  private static void ProcessGroupID(SceneObjectPart obj, XmlReader reader)
853  {
854  obj.GroupID = Util.ReadUUID(reader, "GroupID");
855  }
856 
857  private static void ProcessOwnerID(SceneObjectPart obj, XmlReader reader)
858  {
859  obj.OwnerID = Util.ReadUUID(reader, "OwnerID");
860  }
861 
862  private static void ProcessLastOwnerID(SceneObjectPart obj, XmlReader reader)
863  {
864  obj.LastOwnerID = Util.ReadUUID(reader, "LastOwnerID");
865  }
866 
867  private static void ProcessBaseMask(SceneObjectPart obj, XmlReader reader)
868  {
869  obj.BaseMask = (uint)reader.ReadElementContentAsInt("BaseMask", String.Empty);
870  }
871 
872  private static void ProcessOwnerMask(SceneObjectPart obj, XmlReader reader)
873  {
874  obj.OwnerMask = (uint)reader.ReadElementContentAsInt("OwnerMask", String.Empty);
875  }
876 
877  private static void ProcessGroupMask(SceneObjectPart obj, XmlReader reader)
878  {
879  obj.GroupMask = (uint)reader.ReadElementContentAsInt("GroupMask", String.Empty);
880  }
881 
882  private static void ProcessEveryoneMask(SceneObjectPart obj, XmlReader reader)
883  {
884  obj.EveryoneMask = (uint)reader.ReadElementContentAsInt("EveryoneMask", String.Empty);
885  }
886 
887  private static void ProcessNextOwnerMask(SceneObjectPart obj, XmlReader reader)
888  {
889  obj.NextOwnerMask = (uint)reader.ReadElementContentAsInt("NextOwnerMask", String.Empty);
890  }
891 
892  private static void ProcessFlags(SceneObjectPart obj, XmlReader reader)
893  {
894  obj.Flags = Util.ReadEnum<PrimFlags>(reader, "Flags");
895  }
896 
897  private static void ProcessCollisionSound(SceneObjectPart obj, XmlReader reader)
898  {
899  obj.CollisionSound = Util.ReadUUID(reader, "CollisionSound");
900  }
901 
902  private static void ProcessCollisionSoundVolume(SceneObjectPart obj, XmlReader reader)
903  {
904  obj.CollisionSoundVolume = reader.ReadElementContentAsFloat("CollisionSoundVolume", String.Empty);
905  }
906 
907  private static void ProcessMediaUrl(SceneObjectPart obj, XmlReader reader)
908  {
909  obj.MediaUrl = reader.ReadElementContentAsString("MediaUrl", String.Empty);
910  }
911 
912  private static void ProcessAttachedPos(SceneObjectPart obj, XmlReader reader)
913  {
914  obj.AttachedPos = Util.ReadVector(reader, "AttachedPos");
915  }
916 
917  private static void ProcessDynAttrs(SceneObjectPart obj, XmlReader reader)
918  {
919  obj.DynAttrs.ReadXml(reader);
920  }
921 
922  private static void ProcessTextureAnimation(SceneObjectPart obj, XmlReader reader)
923  {
924  obj.TextureAnimation = Convert.FromBase64String(reader.ReadElementContentAsString("TextureAnimation", String.Empty));
925  }
926 
927  private static void ProcessParticleSystem(SceneObjectPart obj, XmlReader reader)
928  {
929  obj.ParticleSystem = Convert.FromBase64String(reader.ReadElementContentAsString("ParticleSystem", String.Empty));
930  }
931 
932  private static void ProcessPayPrice0(SceneObjectPart obj, XmlReader reader)
933  {
934  obj.PayPrice[0] = (int)reader.ReadElementContentAsInt("PayPrice0", String.Empty);
935  }
936 
937  private static void ProcessPayPrice1(SceneObjectPart obj, XmlReader reader)
938  {
939  obj.PayPrice[1] = (int)reader.ReadElementContentAsInt("PayPrice1", String.Empty);
940  }
941 
942  private static void ProcessPayPrice2(SceneObjectPart obj, XmlReader reader)
943  {
944  obj.PayPrice[2] = (int)reader.ReadElementContentAsInt("PayPrice2", String.Empty);
945  }
946 
947  private static void ProcessPayPrice3(SceneObjectPart obj, XmlReader reader)
948  {
949  obj.PayPrice[3] = (int)reader.ReadElementContentAsInt("PayPrice3", String.Empty);
950  }
951 
952  private static void ProcessPayPrice4(SceneObjectPart obj, XmlReader reader)
953  {
954  obj.PayPrice[4] = (int)reader.ReadElementContentAsInt("PayPrice4", String.Empty);
955  }
956 
957  private static void ProcessBuoyancy(SceneObjectPart obj, XmlReader reader)
958  {
959  obj.Buoyancy = (float)reader.ReadElementContentAsFloat("Buoyancy", String.Empty);
960  }
961 
962  private static void ProcessForce(SceneObjectPart obj, XmlReader reader)
963  {
964  obj.Force = Util.ReadVector(reader, "Force");
965  }
966  private static void ProcessTorque(SceneObjectPart obj, XmlReader reader)
967  {
968  obj.Torque = Util.ReadVector(reader, "Torque");
969  }
970 
971  private static void ProcessVolumeDetectActive(SceneObjectPart obj, XmlReader reader)
972  {
973  obj.VolumeDetectActive = Util.ReadBoolean(reader);
974  }
975 
976  #endregion
977 
978  #region TaskInventoryXmlProcessors
979  private static void ProcessTIAssetID(TaskInventoryItem item, XmlReader reader)
980  {
981  item.AssetID = Util.ReadUUID(reader, "AssetID");
982  }
983 
984  private static void ProcessTIBasePermissions(TaskInventoryItem item, XmlReader reader)
985  {
986  item.BasePermissions = (uint)reader.ReadElementContentAsInt("BasePermissions", String.Empty);
987  }
988 
989  private static void ProcessTICreationDate(TaskInventoryItem item, XmlReader reader)
990  {
991  item.CreationDate = (uint)reader.ReadElementContentAsInt("CreationDate", String.Empty);
992  }
993 
994  private static void ProcessTICreatorID(TaskInventoryItem item, XmlReader reader)
995  {
996  item.CreatorID = Util.ReadUUID(reader, "CreatorID");
997  }
998 
999  private static void ProcessTICreatorData(TaskInventoryItem item, XmlReader reader)
1000  {
1001  item.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty);
1002  }
1003 
1004  private static void ProcessTIDescription(TaskInventoryItem item, XmlReader reader)
1005  {
1006  item.Description = reader.ReadElementContentAsString("Description", String.Empty);
1007  }
1008 
1009  private static void ProcessTIEveryonePermissions(TaskInventoryItem item, XmlReader reader)
1010  {
1011  item.EveryonePermissions = (uint)reader.ReadElementContentAsInt("EveryonePermissions", String.Empty);
1012  }
1013 
1014  private static void ProcessTIFlags(TaskInventoryItem item, XmlReader reader)
1015  {
1016  item.Flags = (uint)reader.ReadElementContentAsInt("Flags", String.Empty);
1017  }
1018 
1019  private static void ProcessTIGroupID(TaskInventoryItem item, XmlReader reader)
1020  {
1021  item.GroupID = Util.ReadUUID(reader, "GroupID");
1022  }
1023 
1024  private static void ProcessTIGroupPermissions(TaskInventoryItem item, XmlReader reader)
1025  {
1026  item.GroupPermissions = (uint)reader.ReadElementContentAsInt("GroupPermissions", String.Empty);
1027  }
1028 
1029  private static void ProcessTIInvType(TaskInventoryItem item, XmlReader reader)
1030  {
1031  item.InvType = reader.ReadElementContentAsInt("InvType", String.Empty);
1032  }
1033 
1034  private static void ProcessTIItemID(TaskInventoryItem item, XmlReader reader)
1035  {
1036  item.ItemID = Util.ReadUUID(reader, "ItemID");
1037  }
1038 
1039  private static void ProcessTIOldItemID(TaskInventoryItem item, XmlReader reader)
1040  {
1041  item.OldItemID = Util.ReadUUID(reader, "OldItemID");
1042  }
1043 
1044  private static void ProcessTILastOwnerID(TaskInventoryItem item, XmlReader reader)
1045  {
1046  item.LastOwnerID = Util.ReadUUID(reader, "LastOwnerID");
1047  }
1048 
1049  private static void ProcessTIName(TaskInventoryItem item, XmlReader reader)
1050  {
1051  item.Name = reader.ReadElementContentAsString("Name", String.Empty);
1052  }
1053 
1054  private static void ProcessTINextPermissions(TaskInventoryItem item, XmlReader reader)
1055  {
1056  item.NextPermissions = (uint)reader.ReadElementContentAsInt("NextPermissions", String.Empty);
1057  }
1058 
1059  private static void ProcessTIOwnerID(TaskInventoryItem item, XmlReader reader)
1060  {
1061  item.OwnerID = Util.ReadUUID(reader, "OwnerID");
1062  }
1063 
1064  private static void ProcessTICurrentPermissions(TaskInventoryItem item, XmlReader reader)
1065  {
1066  item.CurrentPermissions = (uint)reader.ReadElementContentAsInt("CurrentPermissions", String.Empty);
1067  }
1068 
1069  private static void ProcessTIParentID(TaskInventoryItem item, XmlReader reader)
1070  {
1071  item.ParentID = Util.ReadUUID(reader, "ParentID");
1072  }
1073 
1074  private static void ProcessTIParentPartID(TaskInventoryItem item, XmlReader reader)
1075  {
1076  item.ParentPartID = Util.ReadUUID(reader, "ParentPartID");
1077  }
1078 
1079  private static void ProcessTIPermsGranter(TaskInventoryItem item, XmlReader reader)
1080  {
1081  item.PermsGranter = Util.ReadUUID(reader, "PermsGranter");
1082  }
1083 
1084  private static void ProcessTIPermsMask(TaskInventoryItem item, XmlReader reader)
1085  {
1086  item.PermsMask = reader.ReadElementContentAsInt("PermsMask", String.Empty);
1087  }
1088 
1089  private static void ProcessTIType(TaskInventoryItem item, XmlReader reader)
1090  {
1091  item.Type = reader.ReadElementContentAsInt("Type", String.Empty);
1092  }
1093 
1094  private static void ProcessTIOwnerChanged(TaskInventoryItem item, XmlReader reader)
1095  {
1096  item.OwnerChanged = Util.ReadBoolean(reader);
1097  }
1098 
1099  #endregion
1100 
1101  #region ShapeXmlProcessors
1102  private static void ProcessShpProfileCurve(PrimitiveBaseShape shp, XmlReader reader)
1103  {
1104  shp.ProfileCurve = (byte)reader.ReadElementContentAsInt("ProfileCurve", String.Empty);
1105  }
1106 
1107  private static void ProcessShpTextureEntry(PrimitiveBaseShape shp, XmlReader reader)
1108  {
1109  byte[] teData = Convert.FromBase64String(reader.ReadElementString("TextureEntry"));
1110  shp.Textures = new Primitive.TextureEntry(teData, 0, teData.Length);
1111  }
1112 
1113  private static void ProcessShpExtraParams(PrimitiveBaseShape shp, XmlReader reader)
1114  {
1115  shp.ExtraParams = Convert.FromBase64String(reader.ReadElementString("ExtraParams"));
1116  }
1117 
1118  private static void ProcessShpPathBegin(PrimitiveBaseShape shp, XmlReader reader)
1119  {
1120  shp.PathBegin = (ushort)reader.ReadElementContentAsInt("PathBegin", String.Empty);
1121  }
1122 
1123  private static void ProcessShpPathCurve(PrimitiveBaseShape shp, XmlReader reader)
1124  {
1125  shp.PathCurve = (byte)reader.ReadElementContentAsInt("PathCurve", String.Empty);
1126  }
1127 
1128  private static void ProcessShpPathEnd(PrimitiveBaseShape shp, XmlReader reader)
1129  {
1130  shp.PathEnd = (ushort)reader.ReadElementContentAsInt("PathEnd", String.Empty);
1131  }
1132 
1133  private static void ProcessShpPathRadiusOffset(PrimitiveBaseShape shp, XmlReader reader)
1134  {
1135  shp.PathRadiusOffset = (sbyte)reader.ReadElementContentAsInt("PathRadiusOffset", String.Empty);
1136  }
1137 
1138  private static void ProcessShpPathRevolutions(PrimitiveBaseShape shp, XmlReader reader)
1139  {
1140  shp.PathRevolutions = (byte)reader.ReadElementContentAsInt("PathRevolutions", String.Empty);
1141  }
1142 
1143  private static void ProcessShpPathScaleX(PrimitiveBaseShape shp, XmlReader reader)
1144  {
1145  shp.PathScaleX = (byte)reader.ReadElementContentAsInt("PathScaleX", String.Empty);
1146  }
1147 
1148  private static void ProcessShpPathScaleY(PrimitiveBaseShape shp, XmlReader reader)
1149  {
1150  shp.PathScaleY = (byte)reader.ReadElementContentAsInt("PathScaleY", String.Empty);
1151  }
1152 
1153  private static void ProcessShpPathShearX(PrimitiveBaseShape shp, XmlReader reader)
1154  {
1155  shp.PathShearX = (byte)reader.ReadElementContentAsInt("PathShearX", String.Empty);
1156  }
1157 
1158  private static void ProcessShpPathShearY(PrimitiveBaseShape shp, XmlReader reader)
1159  {
1160  shp.PathShearY = (byte)reader.ReadElementContentAsInt("PathShearY", String.Empty);
1161  }
1162 
1163  private static void ProcessShpPathSkew(PrimitiveBaseShape shp, XmlReader reader)
1164  {
1165  shp.PathSkew = (sbyte)reader.ReadElementContentAsInt("PathSkew", String.Empty);
1166  }
1167 
1168  private static void ProcessShpPathTaperX(PrimitiveBaseShape shp, XmlReader reader)
1169  {
1170  shp.PathTaperX = (sbyte)reader.ReadElementContentAsInt("PathTaperX", String.Empty);
1171  }
1172 
1173  private static void ProcessShpPathTaperY(PrimitiveBaseShape shp, XmlReader reader)
1174  {
1175  shp.PathTaperY = (sbyte)reader.ReadElementContentAsInt("PathTaperY", String.Empty);
1176  }
1177 
1178  private static void ProcessShpPathTwist(PrimitiveBaseShape shp, XmlReader reader)
1179  {
1180  shp.PathTwist = (sbyte)reader.ReadElementContentAsInt("PathTwist", String.Empty);
1181  }
1182 
1183  private static void ProcessShpPathTwistBegin(PrimitiveBaseShape shp, XmlReader reader)
1184  {
1185  shp.PathTwistBegin = (sbyte)reader.ReadElementContentAsInt("PathTwistBegin", String.Empty);
1186  }
1187 
1188  private static void ProcessShpPCode(PrimitiveBaseShape shp, XmlReader reader)
1189  {
1190  shp.PCode = (byte)reader.ReadElementContentAsInt("PCode", String.Empty);
1191  }
1192 
1193  private static void ProcessShpProfileBegin(PrimitiveBaseShape shp, XmlReader reader)
1194  {
1195  shp.ProfileBegin = (ushort)reader.ReadElementContentAsInt("ProfileBegin", String.Empty);
1196  }
1197 
1198  private static void ProcessShpProfileEnd(PrimitiveBaseShape shp, XmlReader reader)
1199  {
1200  shp.ProfileEnd = (ushort)reader.ReadElementContentAsInt("ProfileEnd", String.Empty);
1201  }
1202 
1203  private static void ProcessShpProfileHollow(PrimitiveBaseShape shp, XmlReader reader)
1204  {
1205  shp.ProfileHollow = (ushort)reader.ReadElementContentAsInt("ProfileHollow", String.Empty);
1206  }
1207 
1208  private static void ProcessShpScale(PrimitiveBaseShape shp, XmlReader reader)
1209  {
1210  shp.Scale = Util.ReadVector(reader, "Scale");
1211  }
1212 
1213  private static void ProcessShpState(PrimitiveBaseShape shp, XmlReader reader)
1214  {
1215  shp.State = (byte)reader.ReadElementContentAsInt("State", String.Empty);
1216  }
1217 
1218  private static void ProcessShpLastAttach(PrimitiveBaseShape shp, XmlReader reader)
1219  {
1220  shp.LastAttachPoint = (byte)reader.ReadElementContentAsInt("LastAttachPoint", String.Empty);
1221  }
1222 
1223  private static void ProcessShpProfileShape(PrimitiveBaseShape shp, XmlReader reader)
1224  {
1225  shp.ProfileShape = Util.ReadEnum<ProfileShape>(reader, "ProfileShape");
1226  }
1227 
1228  private static void ProcessShpHollowShape(PrimitiveBaseShape shp, XmlReader reader)
1229  {
1230  shp.HollowShape = Util.ReadEnum<HollowShape>(reader, "HollowShape");
1231  }
1232 
1233  private static void ProcessShpSculptTexture(PrimitiveBaseShape shp, XmlReader reader)
1234  {
1235  shp.SculptTexture = Util.ReadUUID(reader, "SculptTexture");
1236  }
1237 
1238  private static void ProcessShpSculptType(PrimitiveBaseShape shp, XmlReader reader)
1239  {
1240  shp.SculptType = (byte)reader.ReadElementContentAsInt("SculptType", String.Empty);
1241  }
1242 
1243  private static void ProcessShpFlexiSoftness(PrimitiveBaseShape shp, XmlReader reader)
1244  {
1245  shp.FlexiSoftness = reader.ReadElementContentAsInt("FlexiSoftness", String.Empty);
1246  }
1247 
1248  private static void ProcessShpFlexiTension(PrimitiveBaseShape shp, XmlReader reader)
1249  {
1250  shp.FlexiTension = reader.ReadElementContentAsFloat("FlexiTension", String.Empty);
1251  }
1252 
1253  private static void ProcessShpFlexiDrag(PrimitiveBaseShape shp, XmlReader reader)
1254  {
1255  shp.FlexiDrag = reader.ReadElementContentAsFloat("FlexiDrag", String.Empty);
1256  }
1257 
1258  private static void ProcessShpFlexiGravity(PrimitiveBaseShape shp, XmlReader reader)
1259  {
1260  shp.FlexiGravity = reader.ReadElementContentAsFloat("FlexiGravity", String.Empty);
1261  }
1262 
1263  private static void ProcessShpFlexiWind(PrimitiveBaseShape shp, XmlReader reader)
1264  {
1265  shp.FlexiWind = reader.ReadElementContentAsFloat("FlexiWind", String.Empty);
1266  }
1267 
1268  private static void ProcessShpFlexiForceX(PrimitiveBaseShape shp, XmlReader reader)
1269  {
1270  shp.FlexiForceX = reader.ReadElementContentAsFloat("FlexiForceX", String.Empty);
1271  }
1272 
1273  private static void ProcessShpFlexiForceY(PrimitiveBaseShape shp, XmlReader reader)
1274  {
1275  shp.FlexiForceY = reader.ReadElementContentAsFloat("FlexiForceY", String.Empty);
1276  }
1277 
1278  private static void ProcessShpFlexiForceZ(PrimitiveBaseShape shp, XmlReader reader)
1279  {
1280  shp.FlexiForceZ = reader.ReadElementContentAsFloat("FlexiForceZ", String.Empty);
1281  }
1282 
1283  private static void ProcessShpLightColorR(PrimitiveBaseShape shp, XmlReader reader)
1284  {
1285  shp.LightColorR = reader.ReadElementContentAsFloat("LightColorR", String.Empty);
1286  }
1287 
1288  private static void ProcessShpLightColorG(PrimitiveBaseShape shp, XmlReader reader)
1289  {
1290  shp.LightColorG = reader.ReadElementContentAsFloat("LightColorG", String.Empty);
1291  }
1292 
1293  private static void ProcessShpLightColorB(PrimitiveBaseShape shp, XmlReader reader)
1294  {
1295  shp.LightColorB = reader.ReadElementContentAsFloat("LightColorB", String.Empty);
1296  }
1297 
1298  private static void ProcessShpLightColorA(PrimitiveBaseShape shp, XmlReader reader)
1299  {
1300  shp.LightColorA = reader.ReadElementContentAsFloat("LightColorA", String.Empty);
1301  }
1302 
1303  private static void ProcessShpLightRadius(PrimitiveBaseShape shp, XmlReader reader)
1304  {
1305  shp.LightRadius = reader.ReadElementContentAsFloat("LightRadius", String.Empty);
1306  }
1307 
1308  private static void ProcessShpLightCutoff(PrimitiveBaseShape shp, XmlReader reader)
1309  {
1310  shp.LightCutoff = reader.ReadElementContentAsFloat("LightCutoff", String.Empty);
1311  }
1312 
1313  private static void ProcessShpLightFalloff(PrimitiveBaseShape shp, XmlReader reader)
1314  {
1315  shp.LightFalloff = reader.ReadElementContentAsFloat("LightFalloff", String.Empty);
1316  }
1317 
1318  private static void ProcessShpLightIntensity(PrimitiveBaseShape shp, XmlReader reader)
1319  {
1320  shp.LightIntensity = reader.ReadElementContentAsFloat("LightIntensity", String.Empty);
1321  }
1322 
1323  private static void ProcessShpFlexiEntry(PrimitiveBaseShape shp, XmlReader reader)
1324  {
1325  shp.FlexiEntry = Util.ReadBoolean(reader);
1326  }
1327 
1328  private static void ProcessShpLightEntry(PrimitiveBaseShape shp, XmlReader reader)
1329  {
1330  shp.LightEntry = Util.ReadBoolean(reader);
1331  }
1332 
1333  private static void ProcessShpSculptEntry(PrimitiveBaseShape shp, XmlReader reader)
1334  {
1335  shp.SculptEntry = Util.ReadBoolean(reader);
1336  }
1337 
1338  private static void ProcessShpMedia(PrimitiveBaseShape shp, XmlReader reader)
1339  {
1340  string value = reader.ReadElementContentAsString("Media", String.Empty);
1341  shp.Media = PrimitiveBaseShape.MediaList.FromXml(value);
1342  }
1343 
1344  #endregion
1345 
1347 
1348  public static void SOGToXml2(XmlTextWriter writer, SceneObjectGroup sog, Dictionary<string, object>options)
1349  {
1350  writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
1351  SOPToXml2(writer, sog.RootPart, options);
1352  writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
1353 
1354  sog.ForEachPart(delegate(SceneObjectPart sop)
1355  {
1356  if (sop.UUID != sog.RootPart.UUID)
1357  SOPToXml2(writer, sop, options);
1358  });
1359 
1360  writer.WriteEndElement();
1361 
1362  if (sog.RootPart.KeyframeMotion != null)
1363  {
1364  Byte[] data = sog.RootPart.KeyframeMotion.Serialize();
1365 
1366  writer.WriteStartElement(String.Empty, "KeyframeMotion", String.Empty);
1367  writer.WriteBase64(data, 0, data.Length);
1368  writer.WriteEndElement();
1369  }
1370 
1371 
1372  writer.WriteEndElement();
1373  }
1374 
1375  public static void SOPToXml2(XmlTextWriter writer, SceneObjectPart sop, Dictionary<string, object> options)
1376  {
1377  writer.WriteStartElement("SceneObjectPart");
1378  writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
1379  writer.WriteAttributeString("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
1380 
1381  writer.WriteElementString("AllowedDrop", sop.AllowedDrop.ToString().ToLower());
1382 
1383  WriteUUID(writer, "CreatorID", sop.CreatorID, options);
1384 
1385  if (!string.IsNullOrEmpty(sop.CreatorData))
1386  writer.WriteElementString("CreatorData", sop.CreatorData);
1387  else if (options.ContainsKey("home"))
1388  {
1389  if (m_UserManagement == null)
1390  m_UserManagement = sop.ParentGroup.Scene.RequestModuleInterface<IUserManagement>();
1391  string name = m_UserManagement.GetUserName(sop.CreatorID);
1392  writer.WriteElementString("CreatorData", ExternalRepresentationUtils.CalcCreatorData((string)options["home"], name));
1393  }
1394 
1395  WriteUUID(writer, "FolderID", sop.FolderID, options);
1396  writer.WriteElementString("InventorySerial", sop.InventorySerial.ToString());
1397 
1398  WriteTaskInventory(writer, sop.TaskInventory, options, sop.ParentGroup.Scene);
1399 
1400  WriteUUID(writer, "UUID", sop.UUID, options);
1401  writer.WriteElementString("LocalId", sop.LocalId.ToString());
1402  writer.WriteElementString("Name", sop.Name);
1403  writer.WriteElementString("Material", sop.Material.ToString());
1404  writer.WriteElementString("PassTouches", sop.PassTouches.ToString().ToLower());
1405  writer.WriteElementString("PassCollisions", sop.PassCollisions.ToString().ToLower());
1406  writer.WriteElementString("RegionHandle", sop.RegionHandle.ToString());
1407  writer.WriteElementString("ScriptAccessPin", sop.ScriptAccessPin.ToString());
1408 
1409  WriteVector(writer, "GroupPosition", sop.GroupPosition);
1410  WriteVector(writer, "OffsetPosition", sop.OffsetPosition);
1411 
1412  WriteQuaternion(writer, "RotationOffset", sop.RotationOffset);
1413  WriteVector(writer, "Velocity", sop.Velocity);
1414  WriteVector(writer, "AngularVelocity", sop.AngularVelocity);
1415  WriteVector(writer, "Acceleration", sop.Acceleration);
1416  writer.WriteElementString("Description", sop.Description);
1417 
1418  writer.WriteStartElement("Color");
1419  writer.WriteElementString("R", sop.Color.R.ToString(Utils.EnUsCulture));
1420  writer.WriteElementString("G", sop.Color.G.ToString(Utils.EnUsCulture));
1421  writer.WriteElementString("B", sop.Color.B.ToString(Utils.EnUsCulture));
1422  writer.WriteElementString("A", sop.Color.A.ToString(Utils.EnUsCulture));
1423  writer.WriteEndElement();
1424 
1425  writer.WriteElementString("Text", sop.Text);
1426  writer.WriteElementString("SitName", sop.SitName);
1427  writer.WriteElementString("TouchName", sop.TouchName);
1428 
1429  writer.WriteElementString("LinkNum", sop.LinkNum.ToString());
1430  writer.WriteElementString("ClickAction", sop.ClickAction.ToString());
1431 
1432  WriteShape(writer, sop.Shape, options);
1433 
1434  WriteVector(writer, "Scale", sop.Scale);
1435  WriteQuaternion(writer, "SitTargetOrientation", sop.SitTargetOrientation);
1436  WriteVector(writer, "SitTargetPosition", sop.SitTargetPosition);
1437  WriteVector(writer, "SitTargetPositionLL", sop.SitTargetPositionLL);
1438  WriteQuaternion(writer, "SitTargetOrientationLL", sop.SitTargetOrientationLL);
1439  writer.WriteElementString("ParentID", sop.ParentID.ToString());
1440  writer.WriteElementString("CreationDate", sop.CreationDate.ToString());
1441  writer.WriteElementString("Category", sop.Category.ToString());
1442  writer.WriteElementString("SalePrice", sop.SalePrice.ToString());
1443  writer.WriteElementString("ObjectSaleType", sop.ObjectSaleType.ToString());
1444  writer.WriteElementString("OwnershipCost", sop.OwnershipCost.ToString());
1445 
1446  UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.GroupID;
1447  WriteUUID(writer, "GroupID", groupID, options);
1448 
1449  UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.OwnerID;
1450  WriteUUID(writer, "OwnerID", ownerID, options);
1451 
1452  UUID lastOwnerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.LastOwnerID;
1453  WriteUUID(writer, "LastOwnerID", lastOwnerID, options);
1454 
1455  writer.WriteElementString("BaseMask", sop.BaseMask.ToString());
1456  writer.WriteElementString("OwnerMask", sop.OwnerMask.ToString());
1457  writer.WriteElementString("GroupMask", sop.GroupMask.ToString());
1458  writer.WriteElementString("EveryoneMask", sop.EveryoneMask.ToString());
1459  writer.WriteElementString("NextOwnerMask", sop.NextOwnerMask.ToString());
1460  WriteFlags(writer, "Flags", sop.Flags.ToString(), options);
1461  WriteUUID(writer, "CollisionSound", sop.CollisionSound, options);
1462  writer.WriteElementString("CollisionSoundVolume", sop.CollisionSoundVolume.ToString());
1463  if (sop.MediaUrl != null)
1464  writer.WriteElementString("MediaUrl", sop.MediaUrl.ToString());
1465  WriteVector(writer, "AttachedPos", sop.AttachedPos);
1466 
1467  if (sop.DynAttrs.CountNamespaces > 0)
1468  {
1469  writer.WriteStartElement("DynAttrs");
1470  sop.DynAttrs.WriteXml(writer);
1471  writer.WriteEndElement();
1472  }
1473 
1474  WriteBytes(writer, "TextureAnimation", sop.TextureAnimation);
1475  WriteBytes(writer, "ParticleSystem", sop.ParticleSystem);
1476  writer.WriteElementString("PayPrice0", sop.PayPrice[0].ToString());
1477  writer.WriteElementString("PayPrice1", sop.PayPrice[1].ToString());
1478  writer.WriteElementString("PayPrice2", sop.PayPrice[2].ToString());
1479  writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString());
1480  writer.WriteElementString("PayPrice4", sop.PayPrice[4].ToString());
1481 
1482  writer.WriteElementString("Buoyancy", sop.Buoyancy.ToString());
1483 
1484  WriteVector(writer, "Force", sop.Force);
1485  WriteVector(writer, "Torque", sop.Torque);
1486 
1487  writer.WriteElementString("VolumeDetectActive", sop.VolumeDetectActive.ToString().ToLower());
1488 
1489  if (sop.VehicleParams != null)
1490  sop.VehicleParams.ToXml2(writer);
1491 
1492  if(sop.RotationAxisLocks != 0)
1493  writer.WriteElementString("RotationAxisLocks", sop.RotationAxisLocks.ToString().ToLower());
1494  writer.WriteElementString("PhysicsShapeType", sop.PhysicsShapeType.ToString().ToLower());
1495  if (sop.Density != 1000.0f)
1496  writer.WriteElementString("Density", sop.Density.ToString().ToLower());
1497  if (sop.Friction != 0.6f)
1498  writer.WriteElementString("Friction", sop.Friction.ToString().ToLower());
1499  if (sop.Restitution != 0.5f)
1500  writer.WriteElementString("Bounce", sop.Restitution.ToString().ToLower());
1501  if (sop.GravityModifier != 1.0f)
1502  writer.WriteElementString("GravityModifier", sop.GravityModifier.ToString().ToLower());
1503  WriteVector(writer, "CameraEyeOffset", sop.GetCameraEyeOffset());
1504  WriteVector(writer, "CameraAtOffset", sop.GetCameraAtOffset());
1505 
1506  // if (sop.Sound != UUID.Zero) force it till sop crossing does clear it on child prim
1507  {
1508  WriteUUID(writer, "SoundID", sop.Sound, options);
1509  writer.WriteElementString("SoundGain", sop.SoundGain.ToString().ToLower());
1510  writer.WriteElementString("SoundFlags", sop.SoundFlags.ToString().ToLower());
1511  writer.WriteElementString("SoundRadius", sop.SoundRadius.ToString().ToLower());
1512  }
1513  writer.WriteElementString("SoundQueueing", sop.SoundQueueing.ToString().ToLower());
1514 
1515  writer.WriteEndElement();
1516  }
1517 
1518  static void WriteUUID(XmlTextWriter writer, string name, UUID id, Dictionary<string, object> options)
1519  {
1520  writer.WriteStartElement(name);
1521  if (options.ContainsKey("old-guids"))
1522  writer.WriteElementString("Guid", id.ToString());
1523  else
1524  writer.WriteElementString("UUID", id.ToString());
1525  writer.WriteEndElement();
1526  }
1527 
1528  static void WriteVector(XmlTextWriter writer, string name, Vector3 vec)
1529  {
1530  writer.WriteStartElement(name);
1531  writer.WriteElementString("X", vec.X.ToString(Utils.EnUsCulture));
1532  writer.WriteElementString("Y", vec.Y.ToString(Utils.EnUsCulture));
1533  writer.WriteElementString("Z", vec.Z.ToString(Utils.EnUsCulture));
1534  writer.WriteEndElement();
1535  }
1536 
1537  static void WriteQuaternion(XmlTextWriter writer, string name, Quaternion quat)
1538  {
1539  writer.WriteStartElement(name);
1540  writer.WriteElementString("X", quat.X.ToString(Utils.EnUsCulture));
1541  writer.WriteElementString("Y", quat.Y.ToString(Utils.EnUsCulture));
1542  writer.WriteElementString("Z", quat.Z.ToString(Utils.EnUsCulture));
1543  writer.WriteElementString("W", quat.W.ToString(Utils.EnUsCulture));
1544  writer.WriteEndElement();
1545  }
1546 
1547  static void WriteBytes(XmlTextWriter writer, string name, byte[] data)
1548  {
1549  writer.WriteStartElement(name);
1550  byte[] d;
1551  if (data != null)
1552  d = data;
1553  else
1554  d = Utils.EmptyBytes;
1555  writer.WriteBase64(d, 0, d.Length);
1556  writer.WriteEndElement(); // name
1557 
1558  }
1559 
1560  static void WriteFlags(XmlTextWriter writer, string name, string flagsStr, Dictionary<string, object> options)
1561  {
1562  // Older versions of serialization can't cope with commas, so we eliminate the commas
1563  writer.WriteElementString(name, flagsStr.Replace(",", ""));
1564  }
1565 
1566  public static void WriteTaskInventory(XmlTextWriter writer, TaskInventoryDictionary tinv, Dictionary<string, object> options, Scene scene)
1567  {
1568  if (tinv.Count > 0) // otherwise skip this
1569  {
1570  writer.WriteStartElement("TaskInventory");
1571 
1572  foreach (TaskInventoryItem item in tinv.Values)
1573  {
1574  writer.WriteStartElement("TaskInventoryItem");
1575 
1576  WriteUUID(writer, "AssetID", item.AssetID, options);
1577  writer.WriteElementString("BasePermissions", item.BasePermissions.ToString());
1578  writer.WriteElementString("CreationDate", item.CreationDate.ToString());
1579 
1580  WriteUUID(writer, "CreatorID", item.CreatorID, options);
1581 
1582  if (!string.IsNullOrEmpty(item.CreatorData))
1583  writer.WriteElementString("CreatorData", item.CreatorData);
1584  else if (options.ContainsKey("home"))
1585  {
1586  if (m_UserManagement == null)
1587  m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
1588  string name = m_UserManagement.GetUserName(item.CreatorID);
1589  writer.WriteElementString("CreatorData", ExternalRepresentationUtils.CalcCreatorData((string)options["home"], name));
1590  }
1591 
1592  writer.WriteElementString("Description", item.Description);
1593  writer.WriteElementString("EveryonePermissions", item.EveryonePermissions.ToString());
1594  writer.WriteElementString("Flags", item.Flags.ToString());
1595 
1596  UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.GroupID;
1597  WriteUUID(writer, "GroupID", groupID, options);
1598 
1599  writer.WriteElementString("GroupPermissions", item.GroupPermissions.ToString());
1600  writer.WriteElementString("InvType", item.InvType.ToString());
1601  WriteUUID(writer, "ItemID", item.ItemID, options);
1602  WriteUUID(writer, "OldItemID", item.OldItemID, options);
1603 
1604  UUID lastOwnerID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.LastOwnerID;
1605  WriteUUID(writer, "LastOwnerID", lastOwnerID, options);
1606 
1607  writer.WriteElementString("Name", item.Name);
1608  writer.WriteElementString("NextPermissions", item.NextPermissions.ToString());
1609 
1610  UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.OwnerID;
1611  WriteUUID(writer, "OwnerID", ownerID, options);
1612 
1613  writer.WriteElementString("CurrentPermissions", item.CurrentPermissions.ToString());
1614  WriteUUID(writer, "ParentID", item.ParentID, options);
1615  WriteUUID(writer, "ParentPartID", item.ParentPartID, options);
1616  WriteUUID(writer, "PermsGranter", item.PermsGranter, options);
1617  writer.WriteElementString("PermsMask", item.PermsMask.ToString());
1618  writer.WriteElementString("Type", item.Type.ToString());
1619 
1620  bool ownerChanged = options.ContainsKey("wipe-owners") ? false : item.OwnerChanged;
1621  writer.WriteElementString("OwnerChanged", ownerChanged.ToString().ToLower());
1622 
1623  writer.WriteEndElement(); // TaskInventoryItem
1624  }
1625 
1626  writer.WriteEndElement(); // TaskInventory
1627  }
1628  }
1629 
1630  public static void WriteShape(XmlTextWriter writer, PrimitiveBaseShape shp, Dictionary<string, object> options)
1631  {
1632  if (shp != null)
1633  {
1634  writer.WriteStartElement("Shape");
1635 
1636  writer.WriteElementString("ProfileCurve", shp.ProfileCurve.ToString());
1637 
1638  writer.WriteStartElement("TextureEntry");
1639  byte[] te;
1640  if (shp.TextureEntry != null)
1641  te = shp.TextureEntry;
1642  else
1643  te = Utils.EmptyBytes;
1644  writer.WriteBase64(te, 0, te.Length);
1645  writer.WriteEndElement(); // TextureEntry
1646 
1647  writer.WriteStartElement("ExtraParams");
1648  byte[] ep;
1649  if (shp.ExtraParams != null)
1650  ep = shp.ExtraParams;
1651  else
1652  ep = Utils.EmptyBytes;
1653  writer.WriteBase64(ep, 0, ep.Length);
1654  writer.WriteEndElement(); // ExtraParams
1655 
1656  writer.WriteElementString("PathBegin", shp.PathBegin.ToString());
1657  writer.WriteElementString("PathCurve", shp.PathCurve.ToString());
1658  writer.WriteElementString("PathEnd", shp.PathEnd.ToString());
1659  writer.WriteElementString("PathRadiusOffset", shp.PathRadiusOffset.ToString());
1660  writer.WriteElementString("PathRevolutions", shp.PathRevolutions.ToString());
1661  writer.WriteElementString("PathScaleX", shp.PathScaleX.ToString());
1662  writer.WriteElementString("PathScaleY", shp.PathScaleY.ToString());
1663  writer.WriteElementString("PathShearX", shp.PathShearX.ToString());
1664  writer.WriteElementString("PathShearY", shp.PathShearY.ToString());
1665  writer.WriteElementString("PathSkew", shp.PathSkew.ToString());
1666  writer.WriteElementString("PathTaperX", shp.PathTaperX.ToString());
1667  writer.WriteElementString("PathTaperY", shp.PathTaperY.ToString());
1668  writer.WriteElementString("PathTwist", shp.PathTwist.ToString());
1669  writer.WriteElementString("PathTwistBegin", shp.PathTwistBegin.ToString());
1670  writer.WriteElementString("PCode", shp.PCode.ToString());
1671  writer.WriteElementString("ProfileBegin", shp.ProfileBegin.ToString());
1672  writer.WriteElementString("ProfileEnd", shp.ProfileEnd.ToString());
1673  writer.WriteElementString("ProfileHollow", shp.ProfileHollow.ToString());
1674  writer.WriteElementString("State", shp.State.ToString());
1675  writer.WriteElementString("LastAttachPoint", shp.LastAttachPoint.ToString());
1676 
1677  WriteFlags(writer, "ProfileShape", shp.ProfileShape.ToString(), options);
1678  WriteFlags(writer, "HollowShape", shp.HollowShape.ToString(), options);
1679 
1680  WriteUUID(writer, "SculptTexture", shp.SculptTexture, options);
1681  writer.WriteElementString("SculptType", shp.SculptType.ToString());
1682  // Don't serialize SculptData. It's just a copy of the asset, which can be loaded separately using 'SculptTexture'.
1683 
1684  writer.WriteElementString("FlexiSoftness", shp.FlexiSoftness.ToString());
1685  writer.WriteElementString("FlexiTension", shp.FlexiTension.ToString());
1686  writer.WriteElementString("FlexiDrag", shp.FlexiDrag.ToString());
1687  writer.WriteElementString("FlexiGravity", shp.FlexiGravity.ToString());
1688  writer.WriteElementString("FlexiWind", shp.FlexiWind.ToString());
1689  writer.WriteElementString("FlexiForceX", shp.FlexiForceX.ToString());
1690  writer.WriteElementString("FlexiForceY", shp.FlexiForceY.ToString());
1691  writer.WriteElementString("FlexiForceZ", shp.FlexiForceZ.ToString());
1692 
1693  writer.WriteElementString("LightColorR", shp.LightColorR.ToString());
1694  writer.WriteElementString("LightColorG", shp.LightColorG.ToString());
1695  writer.WriteElementString("LightColorB", shp.LightColorB.ToString());
1696  writer.WriteElementString("LightColorA", shp.LightColorA.ToString());
1697  writer.WriteElementString("LightRadius", shp.LightRadius.ToString());
1698  writer.WriteElementString("LightCutoff", shp.LightCutoff.ToString());
1699  writer.WriteElementString("LightFalloff", shp.LightFalloff.ToString());
1700  writer.WriteElementString("LightIntensity", shp.LightIntensity.ToString());
1701 
1702  writer.WriteElementString("FlexiEntry", shp.FlexiEntry.ToString().ToLower());
1703  writer.WriteElementString("LightEntry", shp.LightEntry.ToString().ToLower());
1704  writer.WriteElementString("SculptEntry", shp.SculptEntry.ToString().ToLower());
1705 
1706  if (shp.Media != null)
1707  writer.WriteElementString("Media", shp.Media.ToXml());
1708 
1709  writer.WriteEndElement(); // Shape
1710  }
1711  }
1712 
1713  public static SceneObjectPart Xml2ToSOP(XmlReader reader)
1714  {
1715  SceneObjectPart obj = new SceneObjectPart();
1716 
1717  reader.ReadStartElement("SceneObjectPart");
1718 
1719  bool errors = ExternalRepresentationUtils.ExecuteReadProcessors(
1720  obj,
1721  m_SOPXmlProcessors,
1722  reader,
1723  (o, nodeName, e) => {
1724  m_log.Debug(string.Format("[SceneObjectSerializer]: Error while parsing element {0} in object {1} {2} ",
1725  nodeName, ((SceneObjectPart)o).Name, ((SceneObjectPart)o).UUID), e);
1726  });
1727 
1728  if (errors)
1729  throw new XmlException(string.Format("Error parsing object {0} {1}", obj.Name, obj.UUID));
1730 
1731  reader.ReadEndElement(); // SceneObjectPart
1732 
1733  // m_log.DebugFormat("[SceneObjectSerializer]: parsed SOP {0} {1}", obj.Name, obj.UUID);
1734  return obj;
1735  }
1736 
1737  public static TaskInventoryDictionary ReadTaskInventory(XmlReader reader, string name)
1738  {
1740 
1741  reader.ReadStartElement(name, String.Empty);
1742 
1743  while (reader.Name == "TaskInventoryItem")
1744  {
1745  reader.ReadStartElement("TaskInventoryItem", String.Empty); // TaskInventory
1746 
1747  TaskInventoryItem item = new TaskInventoryItem();
1748 
1749  ExternalRepresentationUtils.ExecuteReadProcessors(
1750  item,
1751  m_TaskInventoryXmlProcessors,
1752  reader);
1753 
1754  reader.ReadEndElement(); // TaskInventoryItem
1755  tinv.Add(item.ItemID, item);
1756 
1757  }
1758 
1759  if (reader.NodeType == XmlNodeType.EndElement)
1760  reader.ReadEndElement(); // TaskInventory
1761 
1762  return tinv;
1763  }
1764 
1772  public static PrimitiveBaseShape ReadShape(XmlReader reader, string name, out List<string> errorNodeNames, SceneObjectPart obj)
1773  {
1774  List<string> internalErrorNodeNames = null;
1775 
1776  PrimitiveBaseShape shape = new PrimitiveBaseShape();
1777 
1778  if (reader.IsEmptyElement)
1779  {
1780  reader.Read();
1781  errorNodeNames = null;
1782  return shape;
1783  }
1784 
1785  reader.ReadStartElement(name, String.Empty); // Shape
1786 
1787  ExternalRepresentationUtils.ExecuteReadProcessors(
1788  shape,
1789  m_ShapeXmlProcessors,
1790  reader,
1791  (o, nodeName, e) => {
1792  m_log.Debug(string.Format("[SceneObjectSerializer]: Error while parsing element {0} in Shape property of object {1} {2} ",
1793  nodeName, obj.Name, obj.UUID), e);
1794 
1795  if (internalErrorNodeNames == null)
1796  internalErrorNodeNames = new List<string>();
1797  internalErrorNodeNames.Add(nodeName);
1798  });
1799 
1800  reader.ReadEndElement(); // Shape
1801 
1802  errorNodeNames = internalErrorNodeNames;
1803 
1804  return shape;
1805  }
1806 
1807  #endregion
1808  }
1809 }
static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, string scriptedState)
static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, bool doScriptStates)
Serialize a scene object to the original xml format
Vector3 GroupPosition
The position of the entire group that this prim belongs to.
static void SOPToXml2(XmlTextWriter writer, SceneObjectPart sop, Dictionary< string, object > options)
Scene Scene
The scene to which this entity belongs
Definition: EntityBase.cs:46
static void SOGToXml2(XmlTextWriter writer, SceneObjectGroup sog, Dictionary< string, object >options)
static void ToXmlFormat(SceneObjectPart part, XmlTextWriter writer)
A dictionary containing task inventory items. Indexed by item UUID.
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
PrimFlags Flags
Property flags. See OpenMetaverse.PrimFlags
MediaList Media
Entries to store media textures on each face
int CountNamespaces
Get the number of namespaces
Definition: DAMap.cs:183
Represents an item in a task inventory
string MediaUrl
Used for media on a prim.
static string ToOriginalXmlFormat(SceneObjectGroup sceneObject)
Serialize a scene object to the original xml format
UUID FolderID
A relic from when we we thought that prims contained folder objects. In reality, prim == folder Expos...
Vector3 Scale
Change the scale of this part.
string CreatorData
Data about the creator in the form home_url;name
static SceneObjectPart FromXml(XmlReader xmlReader)
Restore this part from the serialized xml representation.
static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates, bool noRootElement)
Serialize a scene object to the original xml format
static void WriteShape(XmlTextWriter writer, PrimitiveBaseShape shp, Dictionary< string, object > options)
static SceneObjectGroup FromOriginalXmlFormat(string xmlData)
Deserialize a scene object from the original xml format
static void WriteTaskInventory(XmlTextWriter writer, TaskInventoryDictionary tinv, Dictionary< string, object > options, Scene scene)
Vector3 AngularVelocity
Get or set angular velocity. Does not schedule update.
static TaskInventoryDictionary ReadTaskInventory(XmlReader reader, string name)
static PrimitiveBaseShape ReadShape(XmlReader reader, string name, out List< string > errorNodeNames, SceneObjectPart obj)
Read a shape from xml input
static SceneObjectGroup FromOriginalXmlFormat(XmlReader reader)
Deserialize a scene object from the original xml format
DAMap DynAttrs
Dynamic attributes can be created and deleted as required.
static byte[] ModifySerializedObject(UUID assetId, byte[] data, SceneObjectModifier modifier)
Modifies an object by deserializing it; applying 'modifier' to each SceneObjectGroup; and reserializi...
static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates)
Serialize a scene object to the original xml format
This maintains the relationship between a UUID and a user name.
Represents a coalescene of scene objects. A coalescence occurs when objects that are not in the same ...
static string ToXml2Format(SceneObjectGroup sceneObject)
Serialize a scene object to the 'xml2' format.