SceneObjectSerializer.cs 75 KB

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