SceneObjectSerializer.cs 69 KB

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