SceneObjectSerializer.cs 81 KB

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