SceneObjectSerializer.cs 72 KB

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