SceneObjectSerializer.cs 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  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. namespace OpenSim.Region.Framework.Scenes.Serialization
  41. {
  42. /// <summary>
  43. /// Serialize and deserialize scene objects.
  44. /// </summary>
  45. /// This should really be in OpenSim.Framework.Serialization but this would mean circular dependency problems
  46. /// right now - hopefully this isn't forever.
  47. public class SceneObjectSerializer
  48. {
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. private static IUserManagement m_UserManagement;
  51. /// <summary>
  52. /// Deserialize a scene object from the original xml format
  53. /// </summary>
  54. /// <param name="xmlData"></param>
  55. /// <returns>The scene object deserialized. Null on failure.</returns>
  56. public static SceneObjectGroup FromOriginalXmlFormat(string xmlData)
  57. {
  58. //m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
  59. //int time = System.Environment.TickCount;
  60. try
  61. {
  62. StringReader sr;
  63. XmlTextReader reader;
  64. XmlNodeList parts;
  65. XmlDocument doc;
  66. int linkNum;
  67. doc = new XmlDocument();
  68. doc.LoadXml(xmlData);
  69. parts = doc.GetElementsByTagName("RootPart");
  70. if (parts.Count == 0)
  71. throw new Exception("Invalid Xml format - no root part");
  72. sr = new StringReader(parts[0].InnerXml);
  73. reader = new XmlTextReader(sr);
  74. SceneObjectGroup sceneObject = new SceneObjectGroup(SceneObjectPart.FromXml(reader));
  75. reader.Close();
  76. sr.Close();
  77. parts = doc.GetElementsByTagName("Part");
  78. for (int i = 0; i < parts.Count; i++)
  79. {
  80. sr = new StringReader(parts[i].InnerXml);
  81. reader = new XmlTextReader(sr);
  82. SceneObjectPart part = SceneObjectPart.FromXml(reader);
  83. linkNum = part.LinkNum;
  84. sceneObject.AddPart(part);
  85. part.LinkNum = linkNum;
  86. part.TrimPermissions();
  87. reader.Close();
  88. sr.Close();
  89. }
  90. // Script state may, or may not, exist. Not having any, is NOT
  91. // ever a problem.
  92. sceneObject.LoadScriptState(doc);
  93. return sceneObject;
  94. }
  95. catch (Exception e)
  96. {
  97. m_log.ErrorFormat(
  98. "[SERIALIZER]: Deserialization of xml failed with {0}. xml was {1}", e, xmlData);
  99. return null;
  100. }
  101. }
  102. /// <summary>
  103. /// Serialize a scene object to the original xml format
  104. /// </summary>
  105. /// <param name="sceneObject"></param>
  106. /// <returns></returns>
  107. public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject)
  108. {
  109. return ToOriginalXmlFormat(sceneObject, true);
  110. }
  111. /// <summary>
  112. /// Serialize a scene object to the original xml format
  113. /// </summary>
  114. /// <param name="sceneObject"></param>
  115. /// <param name="doScriptStates">Control whether script states are also serialized.</para>
  116. /// <returns></returns>
  117. public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, bool doScriptStates)
  118. {
  119. using (StringWriter sw = new StringWriter())
  120. {
  121. using (XmlTextWriter writer = new XmlTextWriter(sw))
  122. {
  123. ToOriginalXmlFormat(sceneObject, writer, doScriptStates);
  124. }
  125. return sw.ToString();
  126. }
  127. }
  128. /// <summary>
  129. /// Serialize a scene object to the original xml format
  130. /// </summary>
  131. /// <param name="sceneObject"></param>
  132. /// <returns></returns>
  133. public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates)
  134. {
  135. ToOriginalXmlFormat(sceneObject, writer, doScriptStates, false);
  136. }
  137. /// <summary>
  138. /// Serialize a scene object to the original xml format
  139. /// </summary>
  140. /// <param name="sceneObject"></param>
  141. /// <param name="writer"></param>
  142. /// <param name="noRootElement">If false, don't write the enclosing SceneObjectGroup element</param>
  143. /// <returns></returns>
  144. public static void ToOriginalXmlFormat(
  145. SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates, bool noRootElement)
  146. {
  147. // m_log.DebugFormat("[SERIALIZER]: Starting serialization of {0}", sceneObject.Name);
  148. // int time = System.Environment.TickCount;
  149. if (!noRootElement)
  150. writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
  151. writer.WriteStartElement(String.Empty, "RootPart", String.Empty);
  152. ToXmlFormat(sceneObject.RootPart, writer);
  153. writer.WriteEndElement();
  154. writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
  155. SceneObjectPart[] parts = sceneObject.Parts;
  156. for (int i = 0; i < parts.Length; i++)
  157. {
  158. SceneObjectPart part = parts[i];
  159. if (part.UUID != sceneObject.RootPart.UUID)
  160. {
  161. writer.WriteStartElement(String.Empty, "Part", String.Empty);
  162. ToXmlFormat(part, writer);
  163. writer.WriteEndElement();
  164. }
  165. }
  166. writer.WriteEndElement(); // OtherParts
  167. if (doScriptStates)
  168. sceneObject.SaveScriptedState(writer);
  169. if (!noRootElement)
  170. writer.WriteEndElement(); // SceneObjectGroup
  171. // m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0}, {1}ms", sceneObject.Name, System.Environment.TickCount - time);
  172. }
  173. protected static void ToXmlFormat(SceneObjectPart part, XmlTextWriter writer)
  174. {
  175. SOPToXml2(writer, part, new Dictionary<string, object>());
  176. }
  177. public static SceneObjectGroup FromXml2Format(string xmlData)
  178. {
  179. //m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
  180. //int time = System.Environment.TickCount;
  181. try
  182. {
  183. XmlDocument doc = new XmlDocument();
  184. doc.LoadXml(xmlData);
  185. XmlNodeList parts = doc.GetElementsByTagName("SceneObjectPart");
  186. if (parts.Count == 0)
  187. {
  188. m_log.ErrorFormat("[SERIALIZER]: Deserialization of xml failed: No SceneObjectPart nodes. xml was " + xmlData);
  189. return null;
  190. }
  191. StringReader sr = new StringReader(parts[0].OuterXml);
  192. XmlTextReader reader = new XmlTextReader(sr);
  193. SceneObjectGroup sceneObject = new SceneObjectGroup(SceneObjectPart.FromXml(reader));
  194. reader.Close();
  195. sr.Close();
  196. // Then deal with the rest
  197. for (int i = 1; i < parts.Count; i++)
  198. {
  199. sr = new StringReader(parts[i].OuterXml);
  200. reader = new XmlTextReader(sr);
  201. SceneObjectPart part = SceneObjectPart.FromXml(reader);
  202. int originalLinkNum = part.LinkNum;
  203. sceneObject.AddPart(part);
  204. // SceneObjectGroup.AddPart() tries to be smart and automatically set the LinkNum.
  205. // We override that here
  206. if (originalLinkNum != 0)
  207. part.LinkNum = originalLinkNum;
  208. reader.Close();
  209. sr.Close();
  210. }
  211. // Script state may, or may not, exist. Not having any, is NOT
  212. // ever a problem.
  213. sceneObject.LoadScriptState(doc);
  214. return sceneObject;
  215. }
  216. catch (Exception e)
  217. {
  218. m_log.ErrorFormat("[SERIALIZER]: Deserialization of xml failed with {0}. xml was {1}", e, xmlData);
  219. return null;
  220. }
  221. }
  222. /// <summary>
  223. /// Serialize a scene object to the 'xml2' format.
  224. /// </summary>
  225. /// <param name="sceneObject"></param>
  226. /// <returns></returns>
  227. public static string ToXml2Format(SceneObjectGroup sceneObject)
  228. {
  229. using (StringWriter sw = new StringWriter())
  230. {
  231. using (XmlTextWriter writer = new XmlTextWriter(sw))
  232. {
  233. SOGToXml2(writer, sceneObject, new Dictionary<string,object>());
  234. }
  235. return sw.ToString();
  236. }
  237. }
  238. #region manual serialization
  239. private static Dictionary<string, Action<SceneObjectPart, XmlTextReader>> m_SOPXmlProcessors
  240. = new Dictionary<string, Action<SceneObjectPart, XmlTextReader>>();
  241. private static Dictionary<string, Action<TaskInventoryItem, XmlTextReader>> m_TaskInventoryXmlProcessors
  242. = new Dictionary<string, Action<TaskInventoryItem, XmlTextReader>>();
  243. private static Dictionary<string, Action<PrimitiveBaseShape, XmlTextReader>> m_ShapeXmlProcessors
  244. = new Dictionary<string, Action<PrimitiveBaseShape, XmlTextReader>>();
  245. static SceneObjectSerializer()
  246. {
  247. #region SOPXmlProcessors initialization
  248. m_SOPXmlProcessors.Add("AllowedDrop", ProcessAllowedDrop);
  249. m_SOPXmlProcessors.Add("CreatorID", ProcessCreatorID);
  250. m_SOPXmlProcessors.Add("CreatorData", ProcessCreatorData);
  251. m_SOPXmlProcessors.Add("FolderID", ProcessFolderID);
  252. m_SOPXmlProcessors.Add("InventorySerial", ProcessInventorySerial);
  253. m_SOPXmlProcessors.Add("TaskInventory", ProcessTaskInventory);
  254. m_SOPXmlProcessors.Add("UUID", ProcessUUID);
  255. m_SOPXmlProcessors.Add("LocalId", ProcessLocalId);
  256. m_SOPXmlProcessors.Add("Name", ProcessName);
  257. m_SOPXmlProcessors.Add("Material", ProcessMaterial);
  258. m_SOPXmlProcessors.Add("PassTouches", ProcessPassTouches);
  259. m_SOPXmlProcessors.Add("RegionHandle", ProcessRegionHandle);
  260. m_SOPXmlProcessors.Add("ScriptAccessPin", ProcessScriptAccessPin);
  261. m_SOPXmlProcessors.Add("GroupPosition", ProcessGroupPosition);
  262. m_SOPXmlProcessors.Add("OffsetPosition", ProcessOffsetPosition);
  263. m_SOPXmlProcessors.Add("RotationOffset", ProcessRotationOffset);
  264. m_SOPXmlProcessors.Add("Velocity", ProcessVelocity);
  265. m_SOPXmlProcessors.Add("AngularVelocity", ProcessAngularVelocity);
  266. m_SOPXmlProcessors.Add("Acceleration", ProcessAcceleration);
  267. m_SOPXmlProcessors.Add("Description", ProcessDescription);
  268. m_SOPXmlProcessors.Add("Color", ProcessColor);
  269. m_SOPXmlProcessors.Add("Text", ProcessText);
  270. m_SOPXmlProcessors.Add("SitName", ProcessSitName);
  271. m_SOPXmlProcessors.Add("TouchName", ProcessTouchName);
  272. m_SOPXmlProcessors.Add("LinkNum", ProcessLinkNum);
  273. m_SOPXmlProcessors.Add("ClickAction", ProcessClickAction);
  274. m_SOPXmlProcessors.Add("Shape", ProcessShape);
  275. m_SOPXmlProcessors.Add("Scale", ProcessScale);
  276. m_SOPXmlProcessors.Add("SitTargetOrientation", ProcessSitTargetOrientation);
  277. m_SOPXmlProcessors.Add("SitTargetPosition", ProcessSitTargetPosition);
  278. m_SOPXmlProcessors.Add("SitTargetPositionLL", ProcessSitTargetPositionLL);
  279. m_SOPXmlProcessors.Add("SitTargetOrientationLL", ProcessSitTargetOrientationLL);
  280. m_SOPXmlProcessors.Add("ParentID", ProcessParentID);
  281. m_SOPXmlProcessors.Add("CreationDate", ProcessCreationDate);
  282. m_SOPXmlProcessors.Add("Category", ProcessCategory);
  283. m_SOPXmlProcessors.Add("SalePrice", ProcessSalePrice);
  284. m_SOPXmlProcessors.Add("ObjectSaleType", ProcessObjectSaleType);
  285. m_SOPXmlProcessors.Add("OwnershipCost", ProcessOwnershipCost);
  286. m_SOPXmlProcessors.Add("GroupID", ProcessGroupID);
  287. m_SOPXmlProcessors.Add("OwnerID", ProcessOwnerID);
  288. m_SOPXmlProcessors.Add("LastOwnerID", ProcessLastOwnerID);
  289. m_SOPXmlProcessors.Add("BaseMask", ProcessBaseMask);
  290. m_SOPXmlProcessors.Add("OwnerMask", ProcessOwnerMask);
  291. m_SOPXmlProcessors.Add("GroupMask", ProcessGroupMask);
  292. m_SOPXmlProcessors.Add("EveryoneMask", ProcessEveryoneMask);
  293. m_SOPXmlProcessors.Add("NextOwnerMask", ProcessNextOwnerMask);
  294. m_SOPXmlProcessors.Add("Flags", ProcessFlags);
  295. m_SOPXmlProcessors.Add("CollisionSound", ProcessCollisionSound);
  296. m_SOPXmlProcessors.Add("CollisionSoundVolume", ProcessCollisionSoundVolume);
  297. m_SOPXmlProcessors.Add("MediaUrl", ProcessMediaUrl);
  298. m_SOPXmlProcessors.Add("TextureAnimation", ProcessTextureAnimation);
  299. m_SOPXmlProcessors.Add("ParticleSystem", ProcessParticleSystem);
  300. m_SOPXmlProcessors.Add("PayPrice0", ProcessPayPrice0);
  301. m_SOPXmlProcessors.Add("PayPrice1", ProcessPayPrice1);
  302. m_SOPXmlProcessors.Add("PayPrice2", ProcessPayPrice2);
  303. m_SOPXmlProcessors.Add("PayPrice3", ProcessPayPrice3);
  304. m_SOPXmlProcessors.Add("PayPrice4", ProcessPayPrice4);
  305. #endregion
  306. #region TaskInventoryXmlProcessors initialization
  307. m_TaskInventoryXmlProcessors.Add("AssetID", ProcessTIAssetID);
  308. m_TaskInventoryXmlProcessors.Add("BasePermissions", ProcessTIBasePermissions);
  309. m_TaskInventoryXmlProcessors.Add("CreationDate", ProcessTICreationDate);
  310. m_TaskInventoryXmlProcessors.Add("CreatorID", ProcessTICreatorID);
  311. m_TaskInventoryXmlProcessors.Add("CreatorData", ProcessTICreatorData);
  312. m_TaskInventoryXmlProcessors.Add("Description", ProcessTIDescription);
  313. m_TaskInventoryXmlProcessors.Add("EveryonePermissions", ProcessTIEveryonePermissions);
  314. m_TaskInventoryXmlProcessors.Add("Flags", ProcessTIFlags);
  315. m_TaskInventoryXmlProcessors.Add("GroupID", ProcessTIGroupID);
  316. m_TaskInventoryXmlProcessors.Add("GroupPermissions", ProcessTIGroupPermissions);
  317. m_TaskInventoryXmlProcessors.Add("InvType", ProcessTIInvType);
  318. m_TaskInventoryXmlProcessors.Add("ItemID", ProcessTIItemID);
  319. m_TaskInventoryXmlProcessors.Add("OldItemID", ProcessTIOldItemID);
  320. m_TaskInventoryXmlProcessors.Add("LastOwnerID", ProcessTILastOwnerID);
  321. m_TaskInventoryXmlProcessors.Add("Name", ProcessTIName);
  322. m_TaskInventoryXmlProcessors.Add("NextPermissions", ProcessTINextPermissions);
  323. m_TaskInventoryXmlProcessors.Add("OwnerID", ProcessTIOwnerID);
  324. m_TaskInventoryXmlProcessors.Add("CurrentPermissions", ProcessTICurrentPermissions);
  325. m_TaskInventoryXmlProcessors.Add("ParentID", ProcessTIParentID);
  326. m_TaskInventoryXmlProcessors.Add("ParentPartID", ProcessTIParentPartID);
  327. m_TaskInventoryXmlProcessors.Add("PermsGranter", ProcessTIPermsGranter);
  328. m_TaskInventoryXmlProcessors.Add("PermsMask", ProcessTIPermsMask);
  329. m_TaskInventoryXmlProcessors.Add("Type", ProcessTIType);
  330. m_TaskInventoryXmlProcessors.Add("OwnerChanged", ProcessTIOwnerChanged);
  331. #endregion
  332. #region ShapeXmlProcessors initialization
  333. m_ShapeXmlProcessors.Add("ProfileCurve", ProcessShpProfileCurve);
  334. m_ShapeXmlProcessors.Add("TextureEntry", ProcessShpTextureEntry);
  335. m_ShapeXmlProcessors.Add("ExtraParams", ProcessShpExtraParams);
  336. m_ShapeXmlProcessors.Add("PathBegin", ProcessShpPathBegin);
  337. m_ShapeXmlProcessors.Add("PathCurve", ProcessShpPathCurve);
  338. m_ShapeXmlProcessors.Add("PathEnd", ProcessShpPathEnd);
  339. m_ShapeXmlProcessors.Add("PathRadiusOffset", ProcessShpPathRadiusOffset);
  340. m_ShapeXmlProcessors.Add("PathRevolutions", ProcessShpPathRevolutions);
  341. m_ShapeXmlProcessors.Add("PathScaleX", ProcessShpPathScaleX);
  342. m_ShapeXmlProcessors.Add("PathScaleY", ProcessShpPathScaleY);
  343. m_ShapeXmlProcessors.Add("PathShearX", ProcessShpPathShearX);
  344. m_ShapeXmlProcessors.Add("PathShearY", ProcessShpPathShearY);
  345. m_ShapeXmlProcessors.Add("PathSkew", ProcessShpPathSkew);
  346. m_ShapeXmlProcessors.Add("PathTaperX", ProcessShpPathTaperX);
  347. m_ShapeXmlProcessors.Add("PathTaperY", ProcessShpPathTaperY);
  348. m_ShapeXmlProcessors.Add("PathTwist", ProcessShpPathTwist);
  349. m_ShapeXmlProcessors.Add("PathTwistBegin", ProcessShpPathTwistBegin);
  350. m_ShapeXmlProcessors.Add("PCode", ProcessShpPCode);
  351. m_ShapeXmlProcessors.Add("ProfileBegin", ProcessShpProfileBegin);
  352. m_ShapeXmlProcessors.Add("ProfileEnd", ProcessShpProfileEnd);
  353. m_ShapeXmlProcessors.Add("ProfileHollow", ProcessShpProfileHollow);
  354. m_ShapeXmlProcessors.Add("Scale", ProcessShpScale);
  355. m_ShapeXmlProcessors.Add("State", ProcessShpState);
  356. m_ShapeXmlProcessors.Add("ProfileShape", ProcessShpProfileShape);
  357. m_ShapeXmlProcessors.Add("HollowShape", ProcessShpHollowShape);
  358. m_ShapeXmlProcessors.Add("SculptTexture", ProcessShpSculptTexture);
  359. m_ShapeXmlProcessors.Add("SculptType", ProcessShpSculptType);
  360. m_ShapeXmlProcessors.Add("SculptData", ProcessShpSculptData);
  361. m_ShapeXmlProcessors.Add("FlexiSoftness", ProcessShpFlexiSoftness);
  362. m_ShapeXmlProcessors.Add("FlexiTension", ProcessShpFlexiTension);
  363. m_ShapeXmlProcessors.Add("FlexiDrag", ProcessShpFlexiDrag);
  364. m_ShapeXmlProcessors.Add("FlexiGravity", ProcessShpFlexiGravity);
  365. m_ShapeXmlProcessors.Add("FlexiWind", ProcessShpFlexiWind);
  366. m_ShapeXmlProcessors.Add("FlexiForceX", ProcessShpFlexiForceX);
  367. m_ShapeXmlProcessors.Add("FlexiForceY", ProcessShpFlexiForceY);
  368. m_ShapeXmlProcessors.Add("FlexiForceZ", ProcessShpFlexiForceZ);
  369. m_ShapeXmlProcessors.Add("LightColorR", ProcessShpLightColorR);
  370. m_ShapeXmlProcessors.Add("LightColorG", ProcessShpLightColorG);
  371. m_ShapeXmlProcessors.Add("LightColorB", ProcessShpLightColorB);
  372. m_ShapeXmlProcessors.Add("LightColorA", ProcessShpLightColorA);
  373. m_ShapeXmlProcessors.Add("LightRadius", ProcessShpLightRadius);
  374. m_ShapeXmlProcessors.Add("LightCutoff", ProcessShpLightCutoff);
  375. m_ShapeXmlProcessors.Add("LightFalloff", ProcessShpLightFalloff);
  376. m_ShapeXmlProcessors.Add("LightIntensity", ProcessShpLightIntensity);
  377. m_ShapeXmlProcessors.Add("FlexiEntry", ProcessShpFlexiEntry);
  378. m_ShapeXmlProcessors.Add("LightEntry", ProcessShpLightEntry);
  379. m_ShapeXmlProcessors.Add("SculptEntry", ProcessShpSculptEntry);
  380. m_ShapeXmlProcessors.Add("Media", ProcessShpMedia);
  381. #endregion
  382. }
  383. #region SOPXmlProcessors
  384. private static void ProcessAllowedDrop(SceneObjectPart obj, XmlTextReader reader)
  385. {
  386. obj.AllowedDrop = Util.ReadBoolean(reader);
  387. }
  388. private static void ProcessCreatorID(SceneObjectPart obj, XmlTextReader reader)
  389. {
  390. obj.CreatorID = Util.ReadUUID(reader, "CreatorID");
  391. }
  392. private static void ProcessCreatorData(SceneObjectPart obj, XmlTextReader reader)
  393. {
  394. obj.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty);
  395. }
  396. private static void ProcessFolderID(SceneObjectPart obj, XmlTextReader reader)
  397. {
  398. obj.FolderID = Util.ReadUUID(reader, "FolderID");
  399. }
  400. private static void ProcessInventorySerial(SceneObjectPart obj, XmlTextReader reader)
  401. {
  402. obj.InventorySerial = (uint)reader.ReadElementContentAsInt("InventorySerial", String.Empty);
  403. }
  404. private static void ProcessTaskInventory(SceneObjectPart obj, XmlTextReader reader)
  405. {
  406. obj.TaskInventory = ReadTaskInventory(reader, "TaskInventory");
  407. }
  408. private static void ProcessUUID(SceneObjectPart obj, XmlTextReader reader)
  409. {
  410. obj.UUID = Util.ReadUUID(reader, "UUID");
  411. }
  412. private static void ProcessLocalId(SceneObjectPart obj, XmlTextReader reader)
  413. {
  414. obj.LocalId = (uint)reader.ReadElementContentAsLong("LocalId", String.Empty);
  415. }
  416. private static void ProcessName(SceneObjectPart obj, XmlTextReader reader)
  417. {
  418. obj.Name = reader.ReadElementString("Name");
  419. }
  420. private static void ProcessMaterial(SceneObjectPart obj, XmlTextReader reader)
  421. {
  422. obj.Material = (byte)reader.ReadElementContentAsInt("Material", String.Empty);
  423. }
  424. private static void ProcessPassTouches(SceneObjectPart obj, XmlTextReader reader)
  425. {
  426. obj.PassTouches = Util.ReadBoolean(reader);
  427. }
  428. private static void ProcessRegionHandle(SceneObjectPart obj, XmlTextReader reader)
  429. {
  430. obj.RegionHandle = (ulong)reader.ReadElementContentAsLong("RegionHandle", String.Empty);
  431. }
  432. private static void ProcessScriptAccessPin(SceneObjectPart obj, XmlTextReader reader)
  433. {
  434. obj.ScriptAccessPin = reader.ReadElementContentAsInt("ScriptAccessPin", String.Empty);
  435. }
  436. private static void ProcessGroupPosition(SceneObjectPart obj, XmlTextReader reader)
  437. {
  438. obj.GroupPosition = Util.ReadVector(reader, "GroupPosition");
  439. }
  440. private static void ProcessOffsetPosition(SceneObjectPart obj, XmlTextReader reader)
  441. {
  442. obj.OffsetPosition = Util.ReadVector(reader, "OffsetPosition"); ;
  443. }
  444. private static void ProcessRotationOffset(SceneObjectPart obj, XmlTextReader reader)
  445. {
  446. obj.RotationOffset = Util.ReadQuaternion(reader, "RotationOffset");
  447. }
  448. private static void ProcessVelocity(SceneObjectPart obj, XmlTextReader reader)
  449. {
  450. obj.Velocity = Util.ReadVector(reader, "Velocity");
  451. }
  452. private static void ProcessAngularVelocity(SceneObjectPart obj, XmlTextReader reader)
  453. {
  454. obj.AngularVelocity = Util.ReadVector(reader, "AngularVelocity");
  455. }
  456. private static void ProcessAcceleration(SceneObjectPart obj, XmlTextReader reader)
  457. {
  458. obj.Acceleration = Util.ReadVector(reader, "Acceleration");
  459. }
  460. private static void ProcessDescription(SceneObjectPart obj, XmlTextReader reader)
  461. {
  462. obj.Description = reader.ReadElementString("Description");
  463. }
  464. private static void ProcessColor(SceneObjectPart obj, XmlTextReader reader)
  465. {
  466. reader.ReadStartElement("Color");
  467. if (reader.Name == "R")
  468. {
  469. float r = reader.ReadElementContentAsFloat("R", String.Empty);
  470. float g = reader.ReadElementContentAsFloat("G", String.Empty);
  471. float b = reader.ReadElementContentAsFloat("B", String.Empty);
  472. float a = reader.ReadElementContentAsFloat("A", String.Empty);
  473. obj.Color = Color.FromArgb((int)a, (int)r, (int)g, (int)b);
  474. reader.ReadEndElement();
  475. }
  476. }
  477. private static void ProcessText(SceneObjectPart obj, XmlTextReader reader)
  478. {
  479. obj.Text = reader.ReadElementString("Text", String.Empty);
  480. }
  481. private static void ProcessSitName(SceneObjectPart obj, XmlTextReader reader)
  482. {
  483. obj.SitName = reader.ReadElementString("SitName", String.Empty);
  484. }
  485. private static void ProcessTouchName(SceneObjectPart obj, XmlTextReader reader)
  486. {
  487. obj.TouchName = reader.ReadElementString("TouchName", String.Empty);
  488. }
  489. private static void ProcessLinkNum(SceneObjectPart obj, XmlTextReader reader)
  490. {
  491. obj.LinkNum = reader.ReadElementContentAsInt("LinkNum", String.Empty);
  492. }
  493. private static void ProcessClickAction(SceneObjectPart obj, XmlTextReader reader)
  494. {
  495. obj.ClickAction = (byte)reader.ReadElementContentAsInt("ClickAction", String.Empty);
  496. }
  497. private static void ProcessShape(SceneObjectPart obj, XmlTextReader reader)
  498. {
  499. List<string> errorNodeNames;
  500. obj.Shape = ReadShape(reader, "Shape", out errorNodeNames);
  501. if (errorNodeNames != null)
  502. {
  503. m_log.DebugFormat(
  504. "[SceneObjectSerializer]: Parsing PrimitiveBaseShape for object part {0} {1} encountered errors in properties {2}.",
  505. obj.Name, obj.UUID, string.Join(", ", errorNodeNames.ToArray()));
  506. }
  507. }
  508. private static void ProcessScale(SceneObjectPart obj, XmlTextReader reader)
  509. {
  510. obj.Scale = Util.ReadVector(reader, "Scale");
  511. }
  512. private static void ProcessSitTargetOrientation(SceneObjectPart obj, XmlTextReader reader)
  513. {
  514. obj.SitTargetOrientation = Util.ReadQuaternion(reader, "SitTargetOrientation");
  515. }
  516. private static void ProcessSitTargetPosition(SceneObjectPart obj, XmlTextReader reader)
  517. {
  518. obj.SitTargetPosition = Util.ReadVector(reader, "SitTargetPosition");
  519. }
  520. private static void ProcessSitTargetPositionLL(SceneObjectPart obj, XmlTextReader reader)
  521. {
  522. obj.SitTargetPositionLL = Util.ReadVector(reader, "SitTargetPositionLL");
  523. }
  524. private static void ProcessSitTargetOrientationLL(SceneObjectPart obj, XmlTextReader reader)
  525. {
  526. obj.SitTargetOrientationLL = Util.ReadQuaternion(reader, "SitTargetOrientationLL");
  527. }
  528. private static void ProcessParentID(SceneObjectPart obj, XmlTextReader reader)
  529. {
  530. string str = reader.ReadElementContentAsString("ParentID", String.Empty);
  531. obj.ParentID = Convert.ToUInt32(str);
  532. }
  533. private static void ProcessCreationDate(SceneObjectPart obj, XmlTextReader reader)
  534. {
  535. obj.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty);
  536. }
  537. private static void ProcessCategory(SceneObjectPart obj, XmlTextReader reader)
  538. {
  539. obj.Category = (uint)reader.ReadElementContentAsInt("Category", String.Empty);
  540. }
  541. private static void ProcessSalePrice(SceneObjectPart obj, XmlTextReader reader)
  542. {
  543. obj.SalePrice = reader.ReadElementContentAsInt("SalePrice", String.Empty);
  544. }
  545. private static void ProcessObjectSaleType(SceneObjectPart obj, XmlTextReader reader)
  546. {
  547. obj.ObjectSaleType = (byte)reader.ReadElementContentAsInt("ObjectSaleType", String.Empty);
  548. }
  549. private static void ProcessOwnershipCost(SceneObjectPart obj, XmlTextReader reader)
  550. {
  551. obj.OwnershipCost = reader.ReadElementContentAsInt("OwnershipCost", String.Empty);
  552. }
  553. private static void ProcessGroupID(SceneObjectPart obj, XmlTextReader reader)
  554. {
  555. obj.GroupID = Util.ReadUUID(reader, "GroupID");
  556. }
  557. private static void ProcessOwnerID(SceneObjectPart obj, XmlTextReader reader)
  558. {
  559. obj.OwnerID = Util.ReadUUID(reader, "OwnerID");
  560. }
  561. private static void ProcessLastOwnerID(SceneObjectPart obj, XmlTextReader reader)
  562. {
  563. obj.LastOwnerID = Util.ReadUUID(reader, "LastOwnerID");
  564. }
  565. private static void ProcessBaseMask(SceneObjectPart obj, XmlTextReader reader)
  566. {
  567. obj.BaseMask = (uint)reader.ReadElementContentAsInt("BaseMask", String.Empty);
  568. }
  569. private static void ProcessOwnerMask(SceneObjectPart obj, XmlTextReader reader)
  570. {
  571. obj.OwnerMask = (uint)reader.ReadElementContentAsInt("OwnerMask", String.Empty);
  572. }
  573. private static void ProcessGroupMask(SceneObjectPart obj, XmlTextReader reader)
  574. {
  575. obj.GroupMask = (uint)reader.ReadElementContentAsInt("GroupMask", String.Empty);
  576. }
  577. private static void ProcessEveryoneMask(SceneObjectPart obj, XmlTextReader reader)
  578. {
  579. obj.EveryoneMask = (uint)reader.ReadElementContentAsInt("EveryoneMask", String.Empty);
  580. }
  581. private static void ProcessNextOwnerMask(SceneObjectPart obj, XmlTextReader reader)
  582. {
  583. obj.NextOwnerMask = (uint)reader.ReadElementContentAsInt("NextOwnerMask", String.Empty);
  584. }
  585. private static void ProcessFlags(SceneObjectPart obj, XmlTextReader reader)
  586. {
  587. obj.Flags = Util.ReadEnum<PrimFlags>(reader, "Flags");
  588. }
  589. private static void ProcessCollisionSound(SceneObjectPart obj, XmlTextReader reader)
  590. {
  591. obj.CollisionSound = Util.ReadUUID(reader, "CollisionSound");
  592. }
  593. private static void ProcessCollisionSoundVolume(SceneObjectPart obj, XmlTextReader reader)
  594. {
  595. obj.CollisionSoundVolume = reader.ReadElementContentAsFloat("CollisionSoundVolume", String.Empty);
  596. }
  597. private static void ProcessMediaUrl(SceneObjectPart obj, XmlTextReader reader)
  598. {
  599. obj.MediaUrl = reader.ReadElementContentAsString("MediaUrl", String.Empty);
  600. }
  601. private static void ProcessTextureAnimation(SceneObjectPart obj, XmlTextReader reader)
  602. {
  603. obj.TextureAnimation = Convert.FromBase64String(reader.ReadElementContentAsString("TextureAnimation", String.Empty));
  604. }
  605. private static void ProcessParticleSystem(SceneObjectPart obj, XmlTextReader reader)
  606. {
  607. obj.ParticleSystem = Convert.FromBase64String(reader.ReadElementContentAsString("ParticleSystem", String.Empty));
  608. }
  609. private static void ProcessPayPrice0(SceneObjectPart obj, XmlTextReader reader)
  610. {
  611. obj.PayPrice[0] = (int)reader.ReadElementContentAsInt("PayPrice0", String.Empty);
  612. }
  613. private static void ProcessPayPrice1(SceneObjectPart obj, XmlTextReader reader)
  614. {
  615. obj.PayPrice[1] = (int)reader.ReadElementContentAsInt("PayPrice1", String.Empty);
  616. }
  617. private static void ProcessPayPrice2(SceneObjectPart obj, XmlTextReader reader)
  618. {
  619. obj.PayPrice[2] = (int)reader.ReadElementContentAsInt("PayPrice2", String.Empty);
  620. }
  621. private static void ProcessPayPrice3(SceneObjectPart obj, XmlTextReader reader)
  622. {
  623. obj.PayPrice[3] = (int)reader.ReadElementContentAsInt("PayPrice3", String.Empty);
  624. }
  625. private static void ProcessPayPrice4(SceneObjectPart obj, XmlTextReader reader)
  626. {
  627. obj.PayPrice[4] = (int)reader.ReadElementContentAsInt("PayPrice4", String.Empty);
  628. }
  629. #endregion
  630. #region TaskInventoryXmlProcessors
  631. private static void ProcessTIAssetID(TaskInventoryItem item, XmlTextReader reader)
  632. {
  633. item.AssetID = Util.ReadUUID(reader, "AssetID");
  634. }
  635. private static void ProcessTIBasePermissions(TaskInventoryItem item, XmlTextReader reader)
  636. {
  637. item.BasePermissions = (uint)reader.ReadElementContentAsInt("BasePermissions", String.Empty);
  638. }
  639. private static void ProcessTICreationDate(TaskInventoryItem item, XmlTextReader reader)
  640. {
  641. item.CreationDate = (uint)reader.ReadElementContentAsInt("CreationDate", String.Empty);
  642. }
  643. private static void ProcessTICreatorID(TaskInventoryItem item, XmlTextReader reader)
  644. {
  645. item.CreatorID = Util.ReadUUID(reader, "CreatorID");
  646. }
  647. private static void ProcessTICreatorData(TaskInventoryItem item, XmlTextReader reader)
  648. {
  649. item.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty);
  650. }
  651. private static void ProcessTIDescription(TaskInventoryItem item, XmlTextReader reader)
  652. {
  653. item.Description = reader.ReadElementContentAsString("Description", String.Empty);
  654. }
  655. private static void ProcessTIEveryonePermissions(TaskInventoryItem item, XmlTextReader reader)
  656. {
  657. item.EveryonePermissions = (uint)reader.ReadElementContentAsInt("EveryonePermissions", String.Empty);
  658. }
  659. private static void ProcessTIFlags(TaskInventoryItem item, XmlTextReader reader)
  660. {
  661. item.Flags = (uint)reader.ReadElementContentAsInt("Flags", String.Empty);
  662. }
  663. private static void ProcessTIGroupID(TaskInventoryItem item, XmlTextReader reader)
  664. {
  665. item.GroupID = Util.ReadUUID(reader, "GroupID");
  666. }
  667. private static void ProcessTIGroupPermissions(TaskInventoryItem item, XmlTextReader reader)
  668. {
  669. item.GroupPermissions = (uint)reader.ReadElementContentAsInt("GroupPermissions", String.Empty);
  670. }
  671. private static void ProcessTIInvType(TaskInventoryItem item, XmlTextReader reader)
  672. {
  673. item.InvType = reader.ReadElementContentAsInt("InvType", String.Empty);
  674. }
  675. private static void ProcessTIItemID(TaskInventoryItem item, XmlTextReader reader)
  676. {
  677. item.ItemID = Util.ReadUUID(reader, "ItemID");
  678. }
  679. private static void ProcessTIOldItemID(TaskInventoryItem item, XmlTextReader reader)
  680. {
  681. item.OldItemID = Util.ReadUUID(reader, "OldItemID");
  682. }
  683. private static void ProcessTILastOwnerID(TaskInventoryItem item, XmlTextReader reader)
  684. {
  685. item.LastOwnerID = Util.ReadUUID(reader, "LastOwnerID");
  686. }
  687. private static void ProcessTIName(TaskInventoryItem item, XmlTextReader reader)
  688. {
  689. item.Name = reader.ReadElementContentAsString("Name", String.Empty);
  690. }
  691. private static void ProcessTINextPermissions(TaskInventoryItem item, XmlTextReader reader)
  692. {
  693. item.NextPermissions = (uint)reader.ReadElementContentAsInt("NextPermissions", String.Empty);
  694. }
  695. private static void ProcessTIOwnerID(TaskInventoryItem item, XmlTextReader reader)
  696. {
  697. item.OwnerID = Util.ReadUUID(reader, "OwnerID");
  698. }
  699. private static void ProcessTICurrentPermissions(TaskInventoryItem item, XmlTextReader reader)
  700. {
  701. item.CurrentPermissions = (uint)reader.ReadElementContentAsInt("CurrentPermissions", String.Empty);
  702. }
  703. private static void ProcessTIParentID(TaskInventoryItem item, XmlTextReader reader)
  704. {
  705. item.ParentID = Util.ReadUUID(reader, "ParentID");
  706. }
  707. private static void ProcessTIParentPartID(TaskInventoryItem item, XmlTextReader reader)
  708. {
  709. item.ParentPartID = Util.ReadUUID(reader, "ParentPartID");
  710. }
  711. private static void ProcessTIPermsGranter(TaskInventoryItem item, XmlTextReader reader)
  712. {
  713. item.PermsGranter = Util.ReadUUID(reader, "PermsGranter");
  714. }
  715. private static void ProcessTIPermsMask(TaskInventoryItem item, XmlTextReader reader)
  716. {
  717. item.PermsMask = reader.ReadElementContentAsInt("PermsMask", String.Empty);
  718. }
  719. private static void ProcessTIType(TaskInventoryItem item, XmlTextReader reader)
  720. {
  721. item.Type = reader.ReadElementContentAsInt("Type", String.Empty);
  722. }
  723. private static void ProcessTIOwnerChanged(TaskInventoryItem item, XmlTextReader reader)
  724. {
  725. item.OwnerChanged = Util.ReadBoolean(reader);
  726. }
  727. #endregion
  728. #region ShapeXmlProcessors
  729. private static void ProcessShpProfileCurve(PrimitiveBaseShape shp, XmlTextReader reader)
  730. {
  731. shp.ProfileCurve = (byte)reader.ReadElementContentAsInt("ProfileCurve", String.Empty);
  732. }
  733. private static void ProcessShpTextureEntry(PrimitiveBaseShape shp, XmlTextReader reader)
  734. {
  735. byte[] teData = Convert.FromBase64String(reader.ReadElementString("TextureEntry"));
  736. shp.Textures = new Primitive.TextureEntry(teData, 0, teData.Length);
  737. }
  738. private static void ProcessShpExtraParams(PrimitiveBaseShape shp, XmlTextReader reader)
  739. {
  740. shp.ExtraParams = Convert.FromBase64String(reader.ReadElementString("ExtraParams"));
  741. }
  742. private static void ProcessShpPathBegin(PrimitiveBaseShape shp, XmlTextReader reader)
  743. {
  744. shp.PathBegin = (ushort)reader.ReadElementContentAsInt("PathBegin", String.Empty);
  745. }
  746. private static void ProcessShpPathCurve(PrimitiveBaseShape shp, XmlTextReader reader)
  747. {
  748. shp.PathCurve = (byte)reader.ReadElementContentAsInt("PathCurve", String.Empty);
  749. }
  750. private static void ProcessShpPathEnd(PrimitiveBaseShape shp, XmlTextReader reader)
  751. {
  752. shp.PathEnd = (ushort)reader.ReadElementContentAsInt("PathEnd", String.Empty);
  753. }
  754. private static void ProcessShpPathRadiusOffset(PrimitiveBaseShape shp, XmlTextReader reader)
  755. {
  756. shp.PathRadiusOffset = (sbyte)reader.ReadElementContentAsInt("PathRadiusOffset", String.Empty);
  757. }
  758. private static void ProcessShpPathRevolutions(PrimitiveBaseShape shp, XmlTextReader reader)
  759. {
  760. shp.PathRevolutions = (byte)reader.ReadElementContentAsInt("PathRevolutions", String.Empty);
  761. }
  762. private static void ProcessShpPathScaleX(PrimitiveBaseShape shp, XmlTextReader reader)
  763. {
  764. shp.PathScaleX = (byte)reader.ReadElementContentAsInt("PathScaleX", String.Empty);
  765. }
  766. private static void ProcessShpPathScaleY(PrimitiveBaseShape shp, XmlTextReader reader)
  767. {
  768. shp.PathScaleY = (byte)reader.ReadElementContentAsInt("PathScaleY", String.Empty);
  769. }
  770. private static void ProcessShpPathShearX(PrimitiveBaseShape shp, XmlTextReader reader)
  771. {
  772. shp.PathShearX = (byte)reader.ReadElementContentAsInt("PathShearX", String.Empty);
  773. }
  774. private static void ProcessShpPathShearY(PrimitiveBaseShape shp, XmlTextReader reader)
  775. {
  776. shp.PathShearY = (byte)reader.ReadElementContentAsInt("PathShearY", String.Empty);
  777. }
  778. private static void ProcessShpPathSkew(PrimitiveBaseShape shp, XmlTextReader reader)
  779. {
  780. shp.PathSkew = (sbyte)reader.ReadElementContentAsInt("PathSkew", String.Empty);
  781. }
  782. private static void ProcessShpPathTaperX(PrimitiveBaseShape shp, XmlTextReader reader)
  783. {
  784. shp.PathTaperX = (sbyte)reader.ReadElementContentAsInt("PathTaperX", String.Empty);
  785. }
  786. private static void ProcessShpPathTaperY(PrimitiveBaseShape shp, XmlTextReader reader)
  787. {
  788. shp.PathTaperY = (sbyte)reader.ReadElementContentAsInt("PathTaperY", String.Empty);
  789. }
  790. private static void ProcessShpPathTwist(PrimitiveBaseShape shp, XmlTextReader reader)
  791. {
  792. shp.PathTwist = (sbyte)reader.ReadElementContentAsInt("PathTwist", String.Empty);
  793. }
  794. private static void ProcessShpPathTwistBegin(PrimitiveBaseShape shp, XmlTextReader reader)
  795. {
  796. shp.PathTwistBegin = (sbyte)reader.ReadElementContentAsInt("PathTwistBegin", String.Empty);
  797. }
  798. private static void ProcessShpPCode(PrimitiveBaseShape shp, XmlTextReader reader)
  799. {
  800. shp.PCode = (byte)reader.ReadElementContentAsInt("PCode", String.Empty);
  801. }
  802. private static void ProcessShpProfileBegin(PrimitiveBaseShape shp, XmlTextReader reader)
  803. {
  804. shp.ProfileBegin = (ushort)reader.ReadElementContentAsInt("ProfileBegin", String.Empty);
  805. }
  806. private static void ProcessShpProfileEnd(PrimitiveBaseShape shp, XmlTextReader reader)
  807. {
  808. shp.ProfileEnd = (ushort)reader.ReadElementContentAsInt("ProfileEnd", String.Empty);
  809. }
  810. private static void ProcessShpProfileHollow(PrimitiveBaseShape shp, XmlTextReader reader)
  811. {
  812. shp.ProfileHollow = (ushort)reader.ReadElementContentAsInt("ProfileHollow", String.Empty);
  813. }
  814. private static void ProcessShpScale(PrimitiveBaseShape shp, XmlTextReader reader)
  815. {
  816. shp.Scale = Util.ReadVector(reader, "Scale");
  817. }
  818. private static void ProcessShpState(PrimitiveBaseShape shp, XmlTextReader reader)
  819. {
  820. shp.State = (byte)reader.ReadElementContentAsInt("State", String.Empty);
  821. }
  822. private static void ProcessShpProfileShape(PrimitiveBaseShape shp, XmlTextReader reader)
  823. {
  824. shp.ProfileShape = Util.ReadEnum<ProfileShape>(reader, "ProfileShape");
  825. }
  826. private static void ProcessShpHollowShape(PrimitiveBaseShape shp, XmlTextReader reader)
  827. {
  828. shp.HollowShape = Util.ReadEnum<HollowShape>(reader, "HollowShape");
  829. }
  830. private static void ProcessShpSculptTexture(PrimitiveBaseShape shp, XmlTextReader reader)
  831. {
  832. shp.SculptTexture = Util.ReadUUID(reader, "SculptTexture");
  833. }
  834. private static void ProcessShpSculptType(PrimitiveBaseShape shp, XmlTextReader reader)
  835. {
  836. shp.SculptType = (byte)reader.ReadElementContentAsInt("SculptType", String.Empty);
  837. }
  838. private static void ProcessShpSculptData(PrimitiveBaseShape shp, XmlTextReader reader)
  839. {
  840. // m_log.DebugFormat("[SCENE OBJECT SERIALIZER]: Setting sculpt data length {0}", shp.SculptData.Length);
  841. shp.SculptData = Convert.FromBase64String(reader.ReadElementString("SculptData"));
  842. }
  843. private static void ProcessShpFlexiSoftness(PrimitiveBaseShape shp, XmlTextReader reader)
  844. {
  845. shp.FlexiSoftness = reader.ReadElementContentAsInt("FlexiSoftness", String.Empty);
  846. }
  847. private static void ProcessShpFlexiTension(PrimitiveBaseShape shp, XmlTextReader reader)
  848. {
  849. shp.FlexiTension = reader.ReadElementContentAsFloat("FlexiTension", String.Empty);
  850. }
  851. private static void ProcessShpFlexiDrag(PrimitiveBaseShape shp, XmlTextReader reader)
  852. {
  853. shp.FlexiDrag = reader.ReadElementContentAsFloat("FlexiDrag", String.Empty);
  854. }
  855. private static void ProcessShpFlexiGravity(PrimitiveBaseShape shp, XmlTextReader reader)
  856. {
  857. shp.FlexiGravity = reader.ReadElementContentAsFloat("FlexiGravity", String.Empty);
  858. }
  859. private static void ProcessShpFlexiWind(PrimitiveBaseShape shp, XmlTextReader reader)
  860. {
  861. shp.FlexiWind = reader.ReadElementContentAsFloat("FlexiWind", String.Empty);
  862. }
  863. private static void ProcessShpFlexiForceX(PrimitiveBaseShape shp, XmlTextReader reader)
  864. {
  865. shp.FlexiForceX = reader.ReadElementContentAsFloat("FlexiForceX", String.Empty);
  866. }
  867. private static void ProcessShpFlexiForceY(PrimitiveBaseShape shp, XmlTextReader reader)
  868. {
  869. shp.FlexiForceY = reader.ReadElementContentAsFloat("FlexiForceY", String.Empty);
  870. }
  871. private static void ProcessShpFlexiForceZ(PrimitiveBaseShape shp, XmlTextReader reader)
  872. {
  873. shp.FlexiForceZ = reader.ReadElementContentAsFloat("FlexiForceZ", String.Empty);
  874. }
  875. private static void ProcessShpLightColorR(PrimitiveBaseShape shp, XmlTextReader reader)
  876. {
  877. shp.LightColorR = reader.ReadElementContentAsFloat("LightColorR", String.Empty);
  878. }
  879. private static void ProcessShpLightColorG(PrimitiveBaseShape shp, XmlTextReader reader)
  880. {
  881. shp.LightColorG = reader.ReadElementContentAsFloat("LightColorG", String.Empty);
  882. }
  883. private static void ProcessShpLightColorB(PrimitiveBaseShape shp, XmlTextReader reader)
  884. {
  885. shp.LightColorB = reader.ReadElementContentAsFloat("LightColorB", String.Empty);
  886. }
  887. private static void ProcessShpLightColorA(PrimitiveBaseShape shp, XmlTextReader reader)
  888. {
  889. shp.LightColorA = reader.ReadElementContentAsFloat("LightColorA", String.Empty);
  890. }
  891. private static void ProcessShpLightRadius(PrimitiveBaseShape shp, XmlTextReader reader)
  892. {
  893. shp.LightRadius = reader.ReadElementContentAsFloat("LightRadius", String.Empty);
  894. }
  895. private static void ProcessShpLightCutoff(PrimitiveBaseShape shp, XmlTextReader reader)
  896. {
  897. shp.LightCutoff = reader.ReadElementContentAsFloat("LightCutoff", String.Empty);
  898. }
  899. private static void ProcessShpLightFalloff(PrimitiveBaseShape shp, XmlTextReader reader)
  900. {
  901. shp.LightFalloff = reader.ReadElementContentAsFloat("LightFalloff", String.Empty);
  902. }
  903. private static void ProcessShpLightIntensity(PrimitiveBaseShape shp, XmlTextReader reader)
  904. {
  905. shp.LightIntensity = reader.ReadElementContentAsFloat("LightIntensity", String.Empty);
  906. }
  907. private static void ProcessShpFlexiEntry(PrimitiveBaseShape shp, XmlTextReader reader)
  908. {
  909. shp.FlexiEntry = Util.ReadBoolean(reader);
  910. }
  911. private static void ProcessShpLightEntry(PrimitiveBaseShape shp, XmlTextReader reader)
  912. {
  913. shp.LightEntry = Util.ReadBoolean(reader);
  914. }
  915. private static void ProcessShpSculptEntry(PrimitiveBaseShape shp, XmlTextReader reader)
  916. {
  917. shp.SculptEntry = Util.ReadBoolean(reader);
  918. }
  919. private static void ProcessShpMedia(PrimitiveBaseShape shp, XmlTextReader reader)
  920. {
  921. string value = reader.ReadElementContentAsString("Media", String.Empty);
  922. shp.Media = PrimitiveBaseShape.MediaList.FromXml(value);
  923. }
  924. #endregion
  925. ////////// Write /////////
  926. public static void SOGToXml2(XmlTextWriter writer, SceneObjectGroup sog, Dictionary<string, object>options)
  927. {
  928. writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
  929. SOPToXml2(writer, sog.RootPart, options);
  930. writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
  931. sog.ForEachPart(delegate(SceneObjectPart sop)
  932. {
  933. if (sop.UUID != sog.RootPart.UUID)
  934. SOPToXml2(writer, sop, options);
  935. });
  936. writer.WriteEndElement();
  937. writer.WriteEndElement();
  938. }
  939. public static void SOPToXml2(XmlTextWriter writer, SceneObjectPart sop, Dictionary<string, object> options)
  940. {
  941. writer.WriteStartElement("SceneObjectPart");
  942. writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
  943. writer.WriteAttributeString("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
  944. writer.WriteElementString("AllowedDrop", sop.AllowedDrop.ToString().ToLower());
  945. WriteUUID(writer, "CreatorID", sop.CreatorID, options);
  946. if (sop.CreatorData != null && sop.CreatorData != string.Empty)
  947. writer.WriteElementString("CreatorData", sop.CreatorData);
  948. else if (options.ContainsKey("home"))
  949. {
  950. if (m_UserManagement == null)
  951. m_UserManagement = sop.ParentGroup.Scene.RequestModuleInterface<IUserManagement>();
  952. string name = m_UserManagement.GetUserName(sop.CreatorID);
  953. writer.WriteElementString("CreatorData", (string)options["home"] + ";" + name);
  954. }
  955. WriteUUID(writer, "FolderID", sop.FolderID, options);
  956. writer.WriteElementString("InventorySerial", sop.InventorySerial.ToString());
  957. WriteTaskInventory(writer, sop.TaskInventory, options, sop.ParentGroup.Scene);
  958. WriteUUID(writer, "UUID", sop.UUID, options);
  959. writer.WriteElementString("LocalId", sop.LocalId.ToString());
  960. writer.WriteElementString("Name", sop.Name);
  961. writer.WriteElementString("Material", sop.Material.ToString());
  962. writer.WriteElementString("PassTouches", sop.PassTouches.ToString().ToLower());
  963. writer.WriteElementString("RegionHandle", sop.RegionHandle.ToString());
  964. writer.WriteElementString("ScriptAccessPin", sop.ScriptAccessPin.ToString());
  965. WriteVector(writer, "GroupPosition", sop.GroupPosition);
  966. WriteVector(writer, "OffsetPosition", sop.OffsetPosition);
  967. WriteQuaternion(writer, "RotationOffset", sop.RotationOffset);
  968. WriteVector(writer, "Velocity", sop.Velocity);
  969. WriteVector(writer, "AngularVelocity", sop.AngularVelocity);
  970. WriteVector(writer, "Acceleration", sop.Acceleration);
  971. writer.WriteElementString("Description", sop.Description);
  972. writer.WriteStartElement("Color");
  973. writer.WriteElementString("R", sop.Color.R.ToString(Utils.EnUsCulture));
  974. writer.WriteElementString("G", sop.Color.G.ToString(Utils.EnUsCulture));
  975. writer.WriteElementString("B", sop.Color.B.ToString(Utils.EnUsCulture));
  976. writer.WriteElementString("A", sop.Color.A.ToString(Utils.EnUsCulture));
  977. writer.WriteEndElement();
  978. writer.WriteElementString("Text", sop.Text);
  979. writer.WriteElementString("SitName", sop.SitName);
  980. writer.WriteElementString("TouchName", sop.TouchName);
  981. writer.WriteElementString("LinkNum", sop.LinkNum.ToString());
  982. writer.WriteElementString("ClickAction", sop.ClickAction.ToString());
  983. WriteShape(writer, sop.Shape, options);
  984. WriteVector(writer, "Scale", sop.Scale);
  985. WriteQuaternion(writer, "SitTargetOrientation", sop.SitTargetOrientation);
  986. WriteVector(writer, "SitTargetPosition", sop.SitTargetPosition);
  987. WriteVector(writer, "SitTargetPositionLL", sop.SitTargetPositionLL);
  988. WriteQuaternion(writer, "SitTargetOrientationLL", sop.SitTargetOrientationLL);
  989. writer.WriteElementString("ParentID", sop.ParentID.ToString());
  990. writer.WriteElementString("CreationDate", sop.CreationDate.ToString());
  991. writer.WriteElementString("Category", sop.Category.ToString());
  992. writer.WriteElementString("SalePrice", sop.SalePrice.ToString());
  993. writer.WriteElementString("ObjectSaleType", sop.ObjectSaleType.ToString());
  994. writer.WriteElementString("OwnershipCost", sop.OwnershipCost.ToString());
  995. WriteUUID(writer, "GroupID", sop.GroupID, options);
  996. UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.OwnerID;
  997. WriteUUID(writer, "OwnerID", ownerID, options);
  998. UUID lastOwnerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.LastOwnerID;
  999. WriteUUID(writer, "LastOwnerID", lastOwnerID, options);
  1000. writer.WriteElementString("BaseMask", sop.BaseMask.ToString());
  1001. writer.WriteElementString("OwnerMask", sop.OwnerMask.ToString());
  1002. writer.WriteElementString("GroupMask", sop.GroupMask.ToString());
  1003. writer.WriteElementString("EveryoneMask", sop.EveryoneMask.ToString());
  1004. writer.WriteElementString("NextOwnerMask", sop.NextOwnerMask.ToString());
  1005. WriteFlags(writer, "Flags", sop.Flags.ToString(), options);
  1006. WriteUUID(writer, "CollisionSound", sop.CollisionSound, options);
  1007. writer.WriteElementString("CollisionSoundVolume", sop.CollisionSoundVolume.ToString());
  1008. if (sop.MediaUrl != null)
  1009. writer.WriteElementString("MediaUrl", sop.MediaUrl.ToString());
  1010. WriteBytes(writer, "TextureAnimation", sop.TextureAnimation);
  1011. WriteBytes(writer, "ParticleSystem", sop.ParticleSystem);
  1012. writer.WriteElementString("PayPrice0", sop.PayPrice[0].ToString());
  1013. writer.WriteElementString("PayPrice1", sop.PayPrice[1].ToString());
  1014. writer.WriteElementString("PayPrice2", sop.PayPrice[2].ToString());
  1015. writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString());
  1016. writer.WriteElementString("PayPrice4", sop.PayPrice[4].ToString());
  1017. writer.WriteEndElement();
  1018. }
  1019. static void WriteUUID(XmlTextWriter writer, string name, UUID id, Dictionary<string, object> options)
  1020. {
  1021. writer.WriteStartElement(name);
  1022. if (options.ContainsKey("old-guids"))
  1023. writer.WriteElementString("Guid", id.ToString());
  1024. else
  1025. writer.WriteElementString("UUID", id.ToString());
  1026. writer.WriteEndElement();
  1027. }
  1028. static void WriteVector(XmlTextWriter writer, string name, Vector3 vec)
  1029. {
  1030. writer.WriteStartElement(name);
  1031. writer.WriteElementString("X", vec.X.ToString(Utils.EnUsCulture));
  1032. writer.WriteElementString("Y", vec.Y.ToString(Utils.EnUsCulture));
  1033. writer.WriteElementString("Z", vec.Z.ToString(Utils.EnUsCulture));
  1034. writer.WriteEndElement();
  1035. }
  1036. static void WriteQuaternion(XmlTextWriter writer, string name, Quaternion quat)
  1037. {
  1038. writer.WriteStartElement(name);
  1039. writer.WriteElementString("X", quat.X.ToString(Utils.EnUsCulture));
  1040. writer.WriteElementString("Y", quat.Y.ToString(Utils.EnUsCulture));
  1041. writer.WriteElementString("Z", quat.Z.ToString(Utils.EnUsCulture));
  1042. writer.WriteElementString("W", quat.W.ToString(Utils.EnUsCulture));
  1043. writer.WriteEndElement();
  1044. }
  1045. static void WriteBytes(XmlTextWriter writer, string name, byte[] data)
  1046. {
  1047. writer.WriteStartElement(name);
  1048. byte[] d;
  1049. if (data != null)
  1050. d = data;
  1051. else
  1052. d = Utils.EmptyBytes;
  1053. writer.WriteBase64(d, 0, d.Length);
  1054. writer.WriteEndElement(); // name
  1055. }
  1056. static void WriteFlags(XmlTextWriter writer, string name, string flagsStr, Dictionary<string, object> options)
  1057. {
  1058. // Older versions of serialization can't cope with commas, so we eliminate the commas
  1059. writer.WriteElementString(name, flagsStr.Replace(",", ""));
  1060. }
  1061. public static void WriteTaskInventory(XmlTextWriter writer, TaskInventoryDictionary tinv, Dictionary<string, object> options, Scene scene)
  1062. {
  1063. if (tinv.Count > 0) // otherwise skip this
  1064. {
  1065. writer.WriteStartElement("TaskInventory");
  1066. foreach (TaskInventoryItem item in tinv.Values)
  1067. {
  1068. writer.WriteStartElement("TaskInventoryItem");
  1069. WriteUUID(writer, "AssetID", item.AssetID, options);
  1070. writer.WriteElementString("BasePermissions", item.BasePermissions.ToString());
  1071. writer.WriteElementString("CreationDate", item.CreationDate.ToString());
  1072. WriteUUID(writer, "CreatorID", item.CreatorID, options);
  1073. if (item.CreatorData != null && item.CreatorData != string.Empty)
  1074. writer.WriteElementString("CreatorData", item.CreatorData);
  1075. else if (options.ContainsKey("home"))
  1076. {
  1077. if (m_UserManagement == null)
  1078. m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
  1079. string name = m_UserManagement.GetUserName(item.CreatorID);
  1080. writer.WriteElementString("CreatorData", (string)options["home"] + ";" + name);
  1081. }
  1082. writer.WriteElementString("Description", item.Description);
  1083. writer.WriteElementString("EveryonePermissions", item.EveryonePermissions.ToString());
  1084. writer.WriteElementString("Flags", item.Flags.ToString());
  1085. WriteUUID(writer, "GroupID", item.GroupID, options);
  1086. writer.WriteElementString("GroupPermissions", item.GroupPermissions.ToString());
  1087. writer.WriteElementString("InvType", item.InvType.ToString());
  1088. WriteUUID(writer, "ItemID", item.ItemID, options);
  1089. WriteUUID(writer, "OldItemID", item.OldItemID, options);
  1090. UUID lastOwnerID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.LastOwnerID;
  1091. WriteUUID(writer, "LastOwnerID", lastOwnerID, options);
  1092. writer.WriteElementString("Name", item.Name);
  1093. writer.WriteElementString("NextPermissions", item.NextPermissions.ToString());
  1094. UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.OwnerID;
  1095. WriteUUID(writer, "OwnerID", ownerID, options);
  1096. writer.WriteElementString("CurrentPermissions", item.CurrentPermissions.ToString());
  1097. WriteUUID(writer, "ParentID", item.ParentID, options);
  1098. WriteUUID(writer, "ParentPartID", item.ParentPartID, options);
  1099. WriteUUID(writer, "PermsGranter", item.PermsGranter, options);
  1100. writer.WriteElementString("PermsMask", item.PermsMask.ToString());
  1101. writer.WriteElementString("Type", item.Type.ToString());
  1102. writer.WriteElementString("OwnerChanged", item.OwnerChanged.ToString().ToLower());
  1103. writer.WriteEndElement(); // TaskInventoryItem
  1104. }
  1105. writer.WriteEndElement(); // TaskInventory
  1106. }
  1107. }
  1108. public static void WriteShape(XmlTextWriter writer, PrimitiveBaseShape shp, Dictionary<string, object> options)
  1109. {
  1110. if (shp != null)
  1111. {
  1112. writer.WriteStartElement("Shape");
  1113. writer.WriteElementString("ProfileCurve", shp.ProfileCurve.ToString());
  1114. writer.WriteStartElement("TextureEntry");
  1115. byte[] te;
  1116. if (shp.TextureEntry != null)
  1117. te = shp.TextureEntry;
  1118. else
  1119. te = Utils.EmptyBytes;
  1120. writer.WriteBase64(te, 0, te.Length);
  1121. writer.WriteEndElement(); // TextureEntry
  1122. writer.WriteStartElement("ExtraParams");
  1123. byte[] ep;
  1124. if (shp.ExtraParams != null)
  1125. ep = shp.ExtraParams;
  1126. else
  1127. ep = Utils.EmptyBytes;
  1128. writer.WriteBase64(ep, 0, ep.Length);
  1129. writer.WriteEndElement(); // ExtraParams
  1130. writer.WriteElementString("PathBegin", shp.PathBegin.ToString());
  1131. writer.WriteElementString("PathCurve", shp.PathCurve.ToString());
  1132. writer.WriteElementString("PathEnd", shp.PathEnd.ToString());
  1133. writer.WriteElementString("PathRadiusOffset", shp.PathRadiusOffset.ToString());
  1134. writer.WriteElementString("PathRevolutions", shp.PathRevolutions.ToString());
  1135. writer.WriteElementString("PathScaleX", shp.PathScaleX.ToString());
  1136. writer.WriteElementString("PathScaleY", shp.PathScaleY.ToString());
  1137. writer.WriteElementString("PathShearX", shp.PathShearX.ToString());
  1138. writer.WriteElementString("PathShearY", shp.PathShearY.ToString());
  1139. writer.WriteElementString("PathSkew", shp.PathSkew.ToString());
  1140. writer.WriteElementString("PathTaperX", shp.PathTaperX.ToString());
  1141. writer.WriteElementString("PathTaperY", shp.PathTaperY.ToString());
  1142. writer.WriteElementString("PathTwist", shp.PathTwist.ToString());
  1143. writer.WriteElementString("PathTwistBegin", shp.PathTwistBegin.ToString());
  1144. writer.WriteElementString("PCode", shp.PCode.ToString());
  1145. writer.WriteElementString("ProfileBegin", shp.ProfileBegin.ToString());
  1146. writer.WriteElementString("ProfileEnd", shp.ProfileEnd.ToString());
  1147. writer.WriteElementString("ProfileHollow", shp.ProfileHollow.ToString());
  1148. writer.WriteElementString("State", shp.State.ToString());
  1149. WriteFlags(writer, "ProfileShape", shp.ProfileShape.ToString(), options);
  1150. WriteFlags(writer, "HollowShape", shp.HollowShape.ToString(), options);
  1151. WriteUUID(writer, "SculptTexture", shp.SculptTexture, options);
  1152. writer.WriteElementString("SculptType", shp.SculptType.ToString());
  1153. writer.WriteStartElement("SculptData");
  1154. byte[] sd;
  1155. if (shp.SculptData != null)
  1156. sd = shp.SculptData;
  1157. else
  1158. sd = Utils.EmptyBytes;
  1159. writer.WriteBase64(sd, 0, sd.Length);
  1160. writer.WriteEndElement(); // SculptData
  1161. writer.WriteElementString("FlexiSoftness", shp.FlexiSoftness.ToString());
  1162. writer.WriteElementString("FlexiTension", shp.FlexiTension.ToString());
  1163. writer.WriteElementString("FlexiDrag", shp.FlexiDrag.ToString());
  1164. writer.WriteElementString("FlexiGravity", shp.FlexiGravity.ToString());
  1165. writer.WriteElementString("FlexiWind", shp.FlexiWind.ToString());
  1166. writer.WriteElementString("FlexiForceX", shp.FlexiForceX.ToString());
  1167. writer.WriteElementString("FlexiForceY", shp.FlexiForceY.ToString());
  1168. writer.WriteElementString("FlexiForceZ", shp.FlexiForceZ.ToString());
  1169. writer.WriteElementString("LightColorR", shp.LightColorR.ToString());
  1170. writer.WriteElementString("LightColorG", shp.LightColorG.ToString());
  1171. writer.WriteElementString("LightColorB", shp.LightColorB.ToString());
  1172. writer.WriteElementString("LightColorA", shp.LightColorA.ToString());
  1173. writer.WriteElementString("LightRadius", shp.LightRadius.ToString());
  1174. writer.WriteElementString("LightCutoff", shp.LightCutoff.ToString());
  1175. writer.WriteElementString("LightFalloff", shp.LightFalloff.ToString());
  1176. writer.WriteElementString("LightIntensity", shp.LightIntensity.ToString());
  1177. writer.WriteElementString("FlexiEntry", shp.FlexiEntry.ToString().ToLower());
  1178. writer.WriteElementString("LightEntry", shp.LightEntry.ToString().ToLower());
  1179. writer.WriteElementString("SculptEntry", shp.SculptEntry.ToString().ToLower());
  1180. if (shp.Media != null)
  1181. writer.WriteElementString("Media", shp.Media.ToXml());
  1182. writer.WriteEndElement(); // Shape
  1183. }
  1184. }
  1185. public static SceneObjectPart Xml2ToSOP(XmlTextReader reader)
  1186. {
  1187. SceneObjectPart obj = new SceneObjectPart();
  1188. reader.ReadStartElement("SceneObjectPart");
  1189. ExternalRepresentationUtils.ExecuteReadProcessors(
  1190. obj,
  1191. m_SOPXmlProcessors,
  1192. reader,
  1193. (o, nodeName, e)
  1194. => m_log.DebugFormat(
  1195. "[SceneObjectSerializer]: Exception while parsing {0} in object {1} {2}: {3}{4}",
  1196. ((SceneObjectPart)o).Name, ((SceneObjectPart)o).UUID, nodeName, e.Message, e.StackTrace));
  1197. reader.ReadEndElement(); // SceneObjectPart
  1198. //m_log.DebugFormat("[XXX]: parsed SOP {0} - {1}", obj.Name, obj.UUID);
  1199. return obj;
  1200. }
  1201. public static TaskInventoryDictionary ReadTaskInventory(XmlTextReader reader, string name)
  1202. {
  1203. TaskInventoryDictionary tinv = new TaskInventoryDictionary();
  1204. if (reader.IsEmptyElement)
  1205. {
  1206. reader.Read();
  1207. return tinv;
  1208. }
  1209. reader.ReadStartElement(name, String.Empty);
  1210. while (reader.Name == "TaskInventoryItem")
  1211. {
  1212. reader.ReadStartElement("TaskInventoryItem", String.Empty); // TaskInventory
  1213. TaskInventoryItem item = new TaskInventoryItem();
  1214. ExternalRepresentationUtils.ExecuteReadProcessors(
  1215. item,
  1216. m_TaskInventoryXmlProcessors,
  1217. reader);
  1218. reader.ReadEndElement(); // TaskInventoryItem
  1219. tinv.Add(item.ItemID, item);
  1220. }
  1221. if (reader.NodeType == XmlNodeType.EndElement)
  1222. reader.ReadEndElement(); // TaskInventory
  1223. return tinv;
  1224. }
  1225. /// <summary>
  1226. /// Read a shape from xml input
  1227. /// </summary>
  1228. /// <param name="reader"></param>
  1229. /// <param name="name">The name of the xml element containing the shape</param>
  1230. /// <param name="errors">a list containing the failing node names. If no failures then null.</param>
  1231. /// <returns>The shape parsed</returns>
  1232. public static PrimitiveBaseShape ReadShape(XmlTextReader reader, string name, out List<string> errorNodeNames)
  1233. {
  1234. List<string> internalErrorNodeNames = null;
  1235. PrimitiveBaseShape shape = new PrimitiveBaseShape();
  1236. if (reader.IsEmptyElement)
  1237. {
  1238. reader.Read();
  1239. errorNodeNames = null;
  1240. return shape;
  1241. }
  1242. reader.ReadStartElement(name, String.Empty); // Shape
  1243. ExternalRepresentationUtils.ExecuteReadProcessors(
  1244. shape,
  1245. m_ShapeXmlProcessors,
  1246. reader,
  1247. (o, nodeName, e)
  1248. =>
  1249. {
  1250. // m_log.DebugFormat(
  1251. // "[SceneObjectSerializer]: Exception while parsing Shape property {0}: {1}{2}",
  1252. // nodeName, e.Message, e.StackTrace);
  1253. if (internalErrorNodeNames == null)
  1254. internalErrorNodeNames = new List<string>();
  1255. internalErrorNodeNames.Add(nodeName);
  1256. }
  1257. );
  1258. reader.ReadEndElement(); // Shape
  1259. errorNodeNames = internalErrorNodeNames;
  1260. return shape;
  1261. }
  1262. #endregion
  1263. }
  1264. }