1
0

SceneObjectSerializer.cs 83 KB

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