SceneObjectSerializer.cs 71 KB

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