123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920 |
- /*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSimulator Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Xml;
- using log4net;
- using OpenMetaverse;
- using OpenSim.Framework;
- using OpenSim.Framework.Serialization.External;
- using OpenSim.Region.Framework.Interfaces;
- using OpenSim.Region.Framework.Scenes;
- using OpenSim.Services.Interfaces;
- namespace OpenSim.Region.Framework.Scenes.Serialization
- {
- /// <summary>
- /// Serialize and deserialize scene objects.
- /// </summary>
- /// This should really be in OpenSim.Framework.Serialization but this would mean circular dependency problems
- /// right now - hopefully this isn't forever.
- public class SceneObjectSerializer
- {
- private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- private static IUserManagement m_UserManagement;
- /// <summary>
- /// Deserialize a scene object from the original xml format
- /// </summary>
- /// <param name="xmlData"></param>
- /// <returns>The scene object deserialized. Null on failure.</returns>
- public static SceneObjectGroup FromOriginalXmlFormat(string xmlData)
- {
- String fixedData = ExternalRepresentationUtils.SanitizeXml(xmlData);
- using (XmlTextReader wrappedReader = new XmlTextReader(fixedData, XmlNodeType.Element, null))
- {
- using (XmlReader reader = XmlReader.Create(wrappedReader, new XmlReaderSettings() { IgnoreWhitespace = true, ConformanceLevel = ConformanceLevel.Fragment}))
- {
- try
- {
- return FromOriginalXmlFormat(reader);
- }
- catch (Exception e)
- {
- m_log.Error("[SERIALIZER]: Deserialization of xml failed ", e);
- Util.LogFailedXML("[SERIALIZER]:", fixedData);
- return null;
- }
- }
- }
- }
- /// <summary>
- /// Deserialize a scene object from the original xml format
- /// </summary>
- /// <param name="xmlData"></param>
- /// <returns>The scene object deserialized. Null on failure.</returns>
- public static SceneObjectGroup FromOriginalXmlFormat(XmlReader reader)
- {
- //m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
- //int time = System.Environment.TickCount;
- int linkNum;
- reader.ReadToFollowing("RootPart");
- reader.ReadToFollowing("SceneObjectPart");
- SceneObjectGroup sceneObject = new SceneObjectGroup(SceneObjectPart.FromXml(reader));
- reader.ReadToFollowing("OtherParts");
- if (reader.ReadToDescendant("Part"))
- {
- do
- {
- if (reader.ReadToDescendant("SceneObjectPart"))
- {
- SceneObjectPart part = SceneObjectPart.FromXml(reader);
- linkNum = part.LinkNum;
- sceneObject.AddPart(part);
- part.LinkNum = linkNum;
- part.TrimPermissions();
- }
- }
- while (reader.ReadToNextSibling("Part"));
- reader.ReadEndElement();
- }
- if (reader.Name == "KeyframeMotion" && reader.NodeType == XmlNodeType.Element)
- {
- string innerkeytxt = reader.ReadElementContentAsString();
- sceneObject.RootPart.KeyframeMotion =
- KeyframeMotion.FromData(sceneObject, Convert.FromBase64String(innerkeytxt));
- }
- else
- sceneObject.RootPart.KeyframeMotion = null;
- // Script state may, or may not, exist. Not having any, is NOT
- // ever a problem.
- sceneObject.LoadScriptState(reader);
- sceneObject.InvalidateDeepEffectivePerms();
- return sceneObject;
- }
- /// <summary>
- /// Serialize a scene object to the original xml format
- /// </summary>
- /// <param name="sceneObject"></param>
- /// <returns></returns>
- public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject)
- {
- return ToOriginalXmlFormat(sceneObject, true);
- }
- /// <summary>
- /// Serialize a scene object to the original xml format
- /// </summary>
- /// <param name="sceneObject"></param>
- /// <param name="doScriptStates">Control whether script states are also serialized.</para>
- /// <returns></returns>
- public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, bool doScriptStates)
- {
- using (StringWriter sw = new StringWriter())
- {
- using (XmlTextWriter writer = new XmlTextWriter(sw))
- {
- ToOriginalXmlFormat(sceneObject, writer, doScriptStates);
- }
- return sw.ToString();
- }
- }
- /// <summary>
- /// Serialize a scene object to the original xml format
- /// </summary>
- /// <param name="sceneObject"></param>
- /// <returns></returns>
- public static void ToOriginalXmlFormat(SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates)
- {
- ToOriginalXmlFormat(sceneObject, writer, doScriptStates, false);
- }
- public static string ToOriginalXmlFormat(SceneObjectGroup sceneObject, string scriptedState)
- {
- using (StringWriter sw = new StringWriter())
- {
- using (XmlTextWriter writer = new XmlTextWriter(sw))
- {
- writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
- ToOriginalXmlFormat(sceneObject, writer, false, true);
- writer.WriteRaw(scriptedState);
- writer.WriteEndElement();
- }
- return sw.ToString();
- }
- }
- /// <summary>
- /// Serialize a scene object to the original xml format
- /// </summary>
- /// <param name="sceneObject"></param>
- /// <param name="writer"></param>
- /// <param name="noRootElement">If false, don't write the enclosing SceneObjectGroup element</param>
- /// <returns></returns>
- public static void ToOriginalXmlFormat(
- SceneObjectGroup sceneObject, XmlTextWriter writer, bool doScriptStates, bool noRootElement)
- {
- // m_log.DebugFormat("[SERIALIZER]: Starting serialization of {0}", sceneObject.Name);
- // int time = System.Environment.TickCount;
- if (!noRootElement)
- writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
- writer.WriteStartElement(String.Empty, "RootPart", String.Empty);
- ToXmlFormat(sceneObject.RootPart, writer);
- writer.WriteEndElement();
- writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
- SceneObjectPart[] parts = sceneObject.Parts;
- for (int i = 0; i < parts.Length; i++)
- {
- SceneObjectPart part = parts[i];
- if (part.UUID != sceneObject.RootPart.UUID)
- {
- writer.WriteStartElement(String.Empty, "Part", String.Empty);
- ToXmlFormat(part, writer);
- writer.WriteEndElement();
- }
- }
- writer.WriteEndElement(); // OtherParts
- if (sceneObject.RootPart.KeyframeMotion != null)
- {
- Byte[] data = sceneObject.RootPart.KeyframeMotion.Serialize();
- writer.WriteStartElement(String.Empty, "KeyframeMotion", String.Empty);
- writer.WriteBase64(data, 0, data.Length);
- writer.WriteEndElement();
- }
- if (doScriptStates)
- sceneObject.SaveScriptedState(writer);
- if (!noRootElement)
- writer.WriteEndElement(); // SceneObjectGroup
- // m_log.DebugFormat("[SERIALIZER]: Finished serialization of SOG {0}, {1}ms", sceneObject.Name, System.Environment.TickCount - time);
- }
- protected static void ToXmlFormat(SceneObjectPart part, XmlTextWriter writer)
- {
- SOPToXml2(writer, part, new Dictionary<string, object>());
- }
- public static SceneObjectGroup FromXml2Format(string xmlData)
- {
- //m_log.DebugFormat("[SOG]: Starting deserialization of SOG");
- //int time = System.Environment.TickCount;
- try
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(xmlData);
- XmlNodeList parts = doc.GetElementsByTagName("SceneObjectPart");
- if (parts.Count == 0)
- {
- m_log.Error("[SERIALIZER]: Deserialization of xml failed: No SceneObjectPart nodes");
- Util.LogFailedXML("[SERIALIZER]:", xmlData);
- return null;
- }
- SceneObjectGroup sceneObject;
- using(StringReader sr = new StringReader(parts[0].OuterXml))
- {
- using(XmlTextReader reader = new XmlTextReader(sr))
- sceneObject = new SceneObjectGroup(SceneObjectPart.FromXml(reader));
- }
- // Then deal with the rest
- SceneObjectPart part;
- for (int i = 1; i < parts.Count; i++)
- {
- using(StringReader sr = new StringReader(parts[i].OuterXml))
- {
- using(XmlTextReader reader = new XmlTextReader(sr))
- {
- part = SceneObjectPart.FromXml(reader);
- }
- }
- int originalLinkNum = part.LinkNum;
- sceneObject.AddPart(part);
- // SceneObjectGroup.AddPart() tries to be smart and automatically set the LinkNum.
- // We override that here
- if (originalLinkNum != 0)
- part.LinkNum = originalLinkNum;
- }
- XmlNodeList keymotion = doc.GetElementsByTagName("KeyframeMotion");
- if (keymotion.Count > 0)
- sceneObject.RootPart.KeyframeMotion = KeyframeMotion.FromData(sceneObject, Convert.FromBase64String(keymotion[0].InnerText));
- else
- sceneObject.RootPart.KeyframeMotion = null;
- // Script state may, or may not, exist. Not having any, is NOT
- // ever a problem.
- sceneObject.LoadScriptState(doc);
- // sceneObject.AggregatePerms();
- return sceneObject;
- }
- catch (Exception e)
- {
- m_log.Error("[SERIALIZER]: Deserialization of xml failed ", e);
- Util.LogFailedXML("[SERIALIZER]:", xmlData);
- return null;
- }
- }
- /// <summary>
- /// Serialize a scene object to the 'xml2' format.
- /// </summary>
- /// <param name="sceneObject"></param>
- /// <returns></returns>
- public static string ToXml2Format(SceneObjectGroup sceneObject)
- {
- using (StringWriter sw = new StringWriter())
- {
- using (XmlTextWriter writer = new XmlTextWriter(sw))
- {
- SOGToXml2(writer, sceneObject, new Dictionary<string,object>());
- }
- return sw.ToString();
- }
- }
- /// <summary>
- /// Modifies a SceneObjectGroup.
- /// </summary>
- /// <param name="sog">The object</param>
- /// <returns>Whether the object was actually modified</returns>
- public delegate bool SceneObjectModifier(SceneObjectGroup sog);
- /// <summary>
- /// Modifies an object by deserializing it; applying 'modifier' to each SceneObjectGroup; and reserializing.
- /// </summary>
- /// <param name="assetId">The object's UUID</param>
- /// <param name="data">Serialized data</param>
- /// <param name="modifier">The function to run on each SceneObjectGroup</param>
- /// <returns>The new serialized object's data, or null if an error occurred</returns>
- public static byte[] ModifySerializedObject(UUID assetId, byte[] data, SceneObjectModifier modifier)
- {
- List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>();
- CoalescedSceneObjects coa = null;
- string xmlData = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(data));
- if (CoalescedSceneObjectsSerializer.TryFromXml(xmlData, out coa))
- {
- // m_log.DebugFormat("[SERIALIZER]: Loaded coalescence {0} has {1} objects", assetId, coa.Count);
- if (coa.Objects.Count == 0)
- {
- m_log.WarnFormat("[SERIALIZER]: Aborting load of coalesced object from asset {0} as it has zero loaded components", assetId);
- return null;
- }
- sceneObjects.AddRange(coa.Objects);
- }
- else
- {
- SceneObjectGroup deserializedObject = FromOriginalXmlFormat(xmlData);
- if (deserializedObject != null)
- {
- sceneObjects.Add(deserializedObject);
- }
- else
- {
- m_log.WarnFormat("[SERIALIZER]: Aborting load of object from asset {0} as deserialization failed", assetId);
- return null;
- }
- }
- bool modified = false;
- foreach (SceneObjectGroup sog in sceneObjects)
- {
- if (modifier(sog))
- modified = true;
- }
- if (modified)
- {
- if (coa != null)
- data = Utils.StringToBytes(CoalescedSceneObjectsSerializer.ToXml(coa));
- else
- data = Utils.StringToBytes(ToOriginalXmlFormat(sceneObjects[0]));
- }
- return data;
- }
- #region manual serialization
- private static Dictionary<string, Action<SceneObjectPart, XmlReader>> m_SOPXmlProcessors
- = new Dictionary<string, Action<SceneObjectPart, XmlReader>>();
- private static Dictionary<string, Action<TaskInventoryItem, XmlReader>> m_TaskInventoryXmlProcessors
- = new Dictionary<string, Action<TaskInventoryItem, XmlReader>>();
- private static Dictionary<string, Action<PrimitiveBaseShape, XmlReader>> m_ShapeXmlProcessors
- = new Dictionary<string, Action<PrimitiveBaseShape, XmlReader>>();
- static SceneObjectSerializer()
- {
- #region SOPXmlProcessors initialization
- m_SOPXmlProcessors.Add("AllowedDrop", ProcessAllowedDrop);
- m_SOPXmlProcessors.Add("CreatorID", ProcessCreatorID);
- m_SOPXmlProcessors.Add("CreatorData", ProcessCreatorData);
- m_SOPXmlProcessors.Add("FolderID", ProcessFolderID);
- m_SOPXmlProcessors.Add("InventorySerial", ProcessInventorySerial);
- m_SOPXmlProcessors.Add("TaskInventory", ProcessTaskInventory);
- m_SOPXmlProcessors.Add("UUID", ProcessUUID);
- m_SOPXmlProcessors.Add("LocalId", ProcessLocalId);
- m_SOPXmlProcessors.Add("Name", ProcessName);
- m_SOPXmlProcessors.Add("Material", ProcessMaterial);
- m_SOPXmlProcessors.Add("PassTouches", ProcessPassTouches);
- m_SOPXmlProcessors.Add("PassCollisions", ProcessPassCollisions);
- m_SOPXmlProcessors.Add("RegionHandle", ProcessRegionHandle);
- m_SOPXmlProcessors.Add("ScriptAccessPin", ProcessScriptAccessPin);
- m_SOPXmlProcessors.Add("GroupPosition", ProcessGroupPosition);
- m_SOPXmlProcessors.Add("OffsetPosition", ProcessOffsetPosition);
- m_SOPXmlProcessors.Add("RotationOffset", ProcessRotationOffset);
- m_SOPXmlProcessors.Add("Velocity", ProcessVelocity);
- m_SOPXmlProcessors.Add("AngularVelocity", ProcessAngularVelocity);
- m_SOPXmlProcessors.Add("Acceleration", ProcessAcceleration);
- m_SOPXmlProcessors.Add("Description", ProcessDescription);
- m_SOPXmlProcessors.Add("Color", ProcessColor);
- m_SOPXmlProcessors.Add("Text", ProcessText);
- m_SOPXmlProcessors.Add("SitName", ProcessSitName);
- m_SOPXmlProcessors.Add("TouchName", ProcessTouchName);
- m_SOPXmlProcessors.Add("LinkNum", ProcessLinkNum);
- m_SOPXmlProcessors.Add("ClickAction", ProcessClickAction);
- m_SOPXmlProcessors.Add("Shape", ProcessShape);
- m_SOPXmlProcessors.Add("Scale", ProcessScale);
- m_SOPXmlProcessors.Add("SitTargetOrientation", ProcessSitTargetOrientation);
- m_SOPXmlProcessors.Add("SitTargetPosition", ProcessSitTargetPosition);
- m_SOPXmlProcessors.Add("SitTargetPositionLL", ProcessSitTargetPositionLL);
- m_SOPXmlProcessors.Add("SitTargetOrientationLL", ProcessSitTargetOrientationLL);
- m_SOPXmlProcessors.Add("ParentID", ProcessParentID);
- m_SOPXmlProcessors.Add("CreationDate", ProcessCreationDate);
- m_SOPXmlProcessors.Add("Category", ProcessCategory);
- m_SOPXmlProcessors.Add("SalePrice", ProcessSalePrice);
- m_SOPXmlProcessors.Add("ObjectSaleType", ProcessObjectSaleType);
- m_SOPXmlProcessors.Add("OwnershipCost", ProcessOwnershipCost);
- m_SOPXmlProcessors.Add("GroupID", ProcessGroupID);
- m_SOPXmlProcessors.Add("OwnerID", ProcessOwnerID);
- m_SOPXmlProcessors.Add("LastOwnerID", ProcessLastOwnerID);
- m_SOPXmlProcessors.Add("RezzerID", ProcessRezzerID);
- m_SOPXmlProcessors.Add("BaseMask", ProcessBaseMask);
- m_SOPXmlProcessors.Add("OwnerMask", ProcessOwnerMask);
- m_SOPXmlProcessors.Add("GroupMask", ProcessGroupMask);
- m_SOPXmlProcessors.Add("EveryoneMask", ProcessEveryoneMask);
- m_SOPXmlProcessors.Add("NextOwnerMask", ProcessNextOwnerMask);
- m_SOPXmlProcessors.Add("Flags", ProcessFlags);
- m_SOPXmlProcessors.Add("CollisionSound", ProcessCollisionSound);
- m_SOPXmlProcessors.Add("CollisionSoundVolume", ProcessCollisionSoundVolume);
- m_SOPXmlProcessors.Add("MediaUrl", ProcessMediaUrl);
- m_SOPXmlProcessors.Add("AttachedPos", ProcessAttachedPos);
- m_SOPXmlProcessors.Add("DynAttrs", ProcessDynAttrs);
- m_SOPXmlProcessors.Add("TextureAnimation", ProcessTextureAnimation);
- m_SOPXmlProcessors.Add("ParticleSystem", ProcessParticleSystem);
- m_SOPXmlProcessors.Add("PayPrice0", ProcessPayPrice0);
- m_SOPXmlProcessors.Add("PayPrice1", ProcessPayPrice1);
- m_SOPXmlProcessors.Add("PayPrice2", ProcessPayPrice2);
- m_SOPXmlProcessors.Add("PayPrice3", ProcessPayPrice3);
- m_SOPXmlProcessors.Add("PayPrice4", ProcessPayPrice4);
- m_SOPXmlProcessors.Add("Buoyancy", ProcessBuoyancy);
- m_SOPXmlProcessors.Add("Force", ProcessForce);
- m_SOPXmlProcessors.Add("Torque", ProcessTorque);
- m_SOPXmlProcessors.Add("VolumeDetectActive", ProcessVolumeDetectActive);
- m_SOPXmlProcessors.Add("Vehicle", ProcessVehicle);
- m_SOPXmlProcessors.Add("PhysicsInertia", ProcessPhysicsInertia);
- m_SOPXmlProcessors.Add("RotationAxisLocks", ProcessRotationAxisLocks);
- m_SOPXmlProcessors.Add("PhysicsShapeType", ProcessPhysicsShapeType);
- m_SOPXmlProcessors.Add("Density", ProcessDensity);
- m_SOPXmlProcessors.Add("Friction", ProcessFriction);
- m_SOPXmlProcessors.Add("Bounce", ProcessBounce);
- m_SOPXmlProcessors.Add("GravityModifier", ProcessGravityModifier);
- m_SOPXmlProcessors.Add("CameraEyeOffset", ProcessCameraEyeOffset);
- m_SOPXmlProcessors.Add("CameraAtOffset", ProcessCameraAtOffset);
- m_SOPXmlProcessors.Add("SoundID", ProcessSoundID);
- m_SOPXmlProcessors.Add("SoundGain", ProcessSoundGain);
- m_SOPXmlProcessors.Add("SoundFlags", ProcessSoundFlags);
- m_SOPXmlProcessors.Add("SoundRadius", ProcessSoundRadius);
- m_SOPXmlProcessors.Add("SoundQueueing", ProcessSoundQueueing);
- m_SOPXmlProcessors.Add("SOPAnims", ProcessSOPAnims);
- #endregion
- #region TaskInventoryXmlProcessors initialization
- m_TaskInventoryXmlProcessors.Add("AssetID", ProcessTIAssetID);
- m_TaskInventoryXmlProcessors.Add("BasePermissions", ProcessTIBasePermissions);
- m_TaskInventoryXmlProcessors.Add("CreationDate", ProcessTICreationDate);
- m_TaskInventoryXmlProcessors.Add("CreatorID", ProcessTICreatorID);
- m_TaskInventoryXmlProcessors.Add("CreatorData", ProcessTICreatorData);
- m_TaskInventoryXmlProcessors.Add("Description", ProcessTIDescription);
- m_TaskInventoryXmlProcessors.Add("EveryonePermissions", ProcessTIEveryonePermissions);
- m_TaskInventoryXmlProcessors.Add("Flags", ProcessTIFlags);
- m_TaskInventoryXmlProcessors.Add("GroupID", ProcessTIGroupID);
- m_TaskInventoryXmlProcessors.Add("GroupPermissions", ProcessTIGroupPermissions);
- m_TaskInventoryXmlProcessors.Add("InvType", ProcessTIInvType);
- m_TaskInventoryXmlProcessors.Add("ItemID", ProcessTIItemID);
- m_TaskInventoryXmlProcessors.Add("OldItemID", ProcessTIOldItemID);
- m_TaskInventoryXmlProcessors.Add("LastOwnerID", ProcessTILastOwnerID);
- m_TaskInventoryXmlProcessors.Add("Name", ProcessTIName);
- m_TaskInventoryXmlProcessors.Add("NextPermissions", ProcessTINextPermissions);
- m_TaskInventoryXmlProcessors.Add("OwnerID", ProcessTIOwnerID);
- m_TaskInventoryXmlProcessors.Add("CurrentPermissions", ProcessTICurrentPermissions);
- m_TaskInventoryXmlProcessors.Add("ParentID", ProcessTIParentID);
- m_TaskInventoryXmlProcessors.Add("ParentPartID", ProcessTIParentPartID);
- m_TaskInventoryXmlProcessors.Add("PermsGranter", ProcessTIPermsGranter);
- m_TaskInventoryXmlProcessors.Add("PermsMask", ProcessTIPermsMask);
- m_TaskInventoryXmlProcessors.Add("Type", ProcessTIType);
- m_TaskInventoryXmlProcessors.Add("OwnerChanged", ProcessTIOwnerChanged);
- #endregion
- #region ShapeXmlProcessors initialization
- m_ShapeXmlProcessors.Add("ProfileCurve", ProcessShpProfileCurve);
- m_ShapeXmlProcessors.Add("TextureEntry", ProcessShpTextureEntry);
- m_ShapeXmlProcessors.Add("ExtraParams", ProcessShpExtraParams);
- m_ShapeXmlProcessors.Add("PathBegin", ProcessShpPathBegin);
- m_ShapeXmlProcessors.Add("PathCurve", ProcessShpPathCurve);
- m_ShapeXmlProcessors.Add("PathEnd", ProcessShpPathEnd);
- m_ShapeXmlProcessors.Add("PathRadiusOffset", ProcessShpPathRadiusOffset);
- m_ShapeXmlProcessors.Add("PathRevolutions", ProcessShpPathRevolutions);
- m_ShapeXmlProcessors.Add("PathScaleX", ProcessShpPathScaleX);
- m_ShapeXmlProcessors.Add("PathScaleY", ProcessShpPathScaleY);
- m_ShapeXmlProcessors.Add("PathShearX", ProcessShpPathShearX);
- m_ShapeXmlProcessors.Add("PathShearY", ProcessShpPathShearY);
- m_ShapeXmlProcessors.Add("PathSkew", ProcessShpPathSkew);
- m_ShapeXmlProcessors.Add("PathTaperX", ProcessShpPathTaperX);
- m_ShapeXmlProcessors.Add("PathTaperY", ProcessShpPathTaperY);
- m_ShapeXmlProcessors.Add("PathTwist", ProcessShpPathTwist);
- m_ShapeXmlProcessors.Add("PathTwistBegin", ProcessShpPathTwistBegin);
- m_ShapeXmlProcessors.Add("PCode", ProcessShpPCode);
- m_ShapeXmlProcessors.Add("ProfileBegin", ProcessShpProfileBegin);
- m_ShapeXmlProcessors.Add("ProfileEnd", ProcessShpProfileEnd);
- m_ShapeXmlProcessors.Add("ProfileHollow", ProcessShpProfileHollow);
- m_ShapeXmlProcessors.Add("Scale", ProcessShpScale);
- m_ShapeXmlProcessors.Add("LastAttachPoint", ProcessShpLastAttach);
- m_ShapeXmlProcessors.Add("State", ProcessShpState);
- m_ShapeXmlProcessors.Add("ProfileShape", ProcessShpProfileShape);
- m_ShapeXmlProcessors.Add("HollowShape", ProcessShpHollowShape);
- m_ShapeXmlProcessors.Add("SculptTexture", ProcessShpSculptTexture);
- m_ShapeXmlProcessors.Add("SculptType", ProcessShpSculptType);
- // Ignore "SculptData"; this element is deprecated
- m_ShapeXmlProcessors.Add("FlexiSoftness", ProcessShpFlexiSoftness);
- m_ShapeXmlProcessors.Add("FlexiTension", ProcessShpFlexiTension);
- m_ShapeXmlProcessors.Add("FlexiDrag", ProcessShpFlexiDrag);
- m_ShapeXmlProcessors.Add("FlexiGravity", ProcessShpFlexiGravity);
- m_ShapeXmlProcessors.Add("FlexiWind", ProcessShpFlexiWind);
- m_ShapeXmlProcessors.Add("FlexiForceX", ProcessShpFlexiForceX);
- m_ShapeXmlProcessors.Add("FlexiForceY", ProcessShpFlexiForceY);
- m_ShapeXmlProcessors.Add("FlexiForceZ", ProcessShpFlexiForceZ);
- m_ShapeXmlProcessors.Add("LightColorR", ProcessShpLightColorR);
- m_ShapeXmlProcessors.Add("LightColorG", ProcessShpLightColorG);
- m_ShapeXmlProcessors.Add("LightColorB", ProcessShpLightColorB);
- m_ShapeXmlProcessors.Add("LightColorA", ProcessShpLightColorA);
- m_ShapeXmlProcessors.Add("LightRadius", ProcessShpLightRadius);
- m_ShapeXmlProcessors.Add("LightCutoff", ProcessShpLightCutoff);
- m_ShapeXmlProcessors.Add("LightFalloff", ProcessShpLightFalloff);
- m_ShapeXmlProcessors.Add("LightIntensity", ProcessShpLightIntensity);
- m_ShapeXmlProcessors.Add("FlexiEntry", ProcessShpFlexiEntry);
- m_ShapeXmlProcessors.Add("LightEntry", ProcessShpLightEntry);
- m_ShapeXmlProcessors.Add("SculptEntry", ProcessShpSculptEntry);
- m_ShapeXmlProcessors.Add("Media", ProcessShpMedia);
- #endregion
- }
- #region SOPXmlProcessors
- private static void ProcessAllowedDrop(SceneObjectPart obj, XmlReader reader)
- {
- obj.AllowedDrop = Util.ReadBoolean(reader);
- }
- private static void ProcessCreatorID(SceneObjectPart obj, XmlReader reader)
- {
- obj.CreatorID = Util.ReadUUID(reader, "CreatorID");
- }
- private static void ProcessCreatorData(SceneObjectPart obj, XmlReader reader)
- {
- obj.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty);
- }
- private static void ProcessFolderID(SceneObjectPart obj, XmlReader reader)
- {
- obj.FolderID = Util.ReadUUID(reader, "FolderID");
- }
- private static void ProcessInventorySerial(SceneObjectPart obj, XmlReader reader)
- {
- obj.InventorySerial = (uint)reader.ReadElementContentAsInt("InventorySerial", String.Empty);
- }
- private static void ProcessTaskInventory(SceneObjectPart obj, XmlReader reader)
- {
- obj.TaskInventory = ReadTaskInventory(reader, "TaskInventory");
- }
- private static void ProcessUUID(SceneObjectPart obj, XmlReader reader)
- {
- obj.UUID = Util.ReadUUID(reader, "UUID");
- }
- private static void ProcessLocalId(SceneObjectPart obj, XmlReader reader)
- {
- obj.LocalId = (uint)reader.ReadElementContentAsLong("LocalId", String.Empty);
- }
- private static void ProcessName(SceneObjectPart obj, XmlReader reader)
- {
- obj.Name = reader.ReadElementString("Name");
- }
- private static void ProcessMaterial(SceneObjectPart obj, XmlReader reader)
- {
- obj.Material = (byte)reader.ReadElementContentAsInt("Material", String.Empty);
- }
- private static void ProcessPassTouches(SceneObjectPart obj, XmlReader reader)
- {
- obj.PassTouches = Util.ReadBoolean(reader);
- }
- private static void ProcessPassCollisions(SceneObjectPart obj, XmlReader reader)
- {
- obj.PassCollisions = Util.ReadBoolean(reader);
- }
- private static void ProcessRegionHandle(SceneObjectPart obj, XmlReader reader)
- {
- obj.RegionHandle = (ulong)reader.ReadElementContentAsLong("RegionHandle", String.Empty);
- }
- private static void ProcessScriptAccessPin(SceneObjectPart obj, XmlReader reader)
- {
- obj.ScriptAccessPin = reader.ReadElementContentAsInt("ScriptAccessPin", String.Empty);
- }
- private static void ProcessGroupPosition(SceneObjectPart obj, XmlReader reader)
- {
- obj.GroupPosition = Util.ReadVector(reader, "GroupPosition");
- }
- private static void ProcessOffsetPosition(SceneObjectPart obj, XmlReader reader)
- {
- obj.OffsetPosition = Util.ReadVector(reader, "OffsetPosition"); ;
- }
- private static void ProcessRotationOffset(SceneObjectPart obj, XmlReader reader)
- {
- obj.RotationOffset = Util.ReadQuaternion(reader, "RotationOffset");
- }
- private static void ProcessVelocity(SceneObjectPart obj, XmlReader reader)
- {
- obj.Velocity = Util.ReadVector(reader, "Velocity");
- }
- private static void ProcessAngularVelocity(SceneObjectPart obj, XmlReader reader)
- {
- obj.AngularVelocity = Util.ReadVector(reader, "AngularVelocity");
- }
- private static void ProcessAcceleration(SceneObjectPart obj, XmlReader reader)
- {
- obj.Acceleration = Util.ReadVector(reader, "Acceleration");
- }
- private static void ProcessDescription(SceneObjectPart obj, XmlReader reader)
- {
- obj.Description = reader.ReadElementString("Description");
- }
- private static void ProcessColor(SceneObjectPart obj, XmlReader reader)
- {
- reader.ReadStartElement("Color");
- if (reader.Name == "R")
- {
- float r = reader.ReadElementContentAsFloat("R", String.Empty);
- float g = reader.ReadElementContentAsFloat("G", String.Empty);
- float b = reader.ReadElementContentAsFloat("B", String.Empty);
- float a = reader.ReadElementContentAsFloat("A", String.Empty);
- obj.Color = Color.FromArgb((int)a, (int)r, (int)g, (int)b);
- reader.ReadEndElement();
- }
- }
- private static void ProcessText(SceneObjectPart obj, XmlReader reader)
- {
- obj.Text = reader.ReadElementString("Text", String.Empty);
- }
- private static void ProcessSitName(SceneObjectPart obj, XmlReader reader)
- {
- obj.SitName = reader.ReadElementString("SitName", String.Empty);
- }
- private static void ProcessTouchName(SceneObjectPart obj, XmlReader reader)
- {
- obj.TouchName = reader.ReadElementString("TouchName", String.Empty);
- }
- private static void ProcessLinkNum(SceneObjectPart obj, XmlReader reader)
- {
- obj.LinkNum = reader.ReadElementContentAsInt("LinkNum", String.Empty);
- }
- private static void ProcessClickAction(SceneObjectPart obj, XmlReader reader)
- {
- obj.ClickAction = (byte)reader.ReadElementContentAsInt("ClickAction", String.Empty);
- }
- private static void ProcessRotationAxisLocks(SceneObjectPart obj, XmlReader reader)
- {
- obj.RotationAxisLocks = (byte)reader.ReadElementContentAsInt("RotationAxisLocks", String.Empty);
- }
- private static void ProcessPhysicsShapeType(SceneObjectPart obj, XmlReader reader)
- {
- obj.PhysicsShapeType = (byte)reader.ReadElementContentAsInt("PhysicsShapeType", String.Empty);
- }
- private static void ProcessDensity(SceneObjectPart obj, XmlReader reader)
- {
- obj.Density = reader.ReadElementContentAsFloat("Density", String.Empty);
- }
- private static void ProcessFriction(SceneObjectPart obj, XmlReader reader)
- {
- obj.Friction = reader.ReadElementContentAsFloat("Friction", String.Empty);
- }
- private static void ProcessBounce(SceneObjectPart obj, XmlReader reader)
- {
- obj.Restitution = reader.ReadElementContentAsFloat("Bounce", String.Empty);
- }
- private static void ProcessGravityModifier(SceneObjectPart obj, XmlReader reader)
- {
- obj.GravityModifier = reader.ReadElementContentAsFloat("GravityModifier", String.Empty);
- }
- private static void ProcessCameraEyeOffset(SceneObjectPart obj, XmlReader reader)
- {
- obj.SetCameraEyeOffset(Util.ReadVector(reader, "CameraEyeOffset"));
- }
- private static void ProcessCameraAtOffset(SceneObjectPart obj, XmlReader reader)
- {
- obj.SetCameraAtOffset(Util.ReadVector(reader, "CameraAtOffset"));
- }
- private static void ProcessSoundID(SceneObjectPart obj, XmlReader reader)
- {
- obj.Sound = Util.ReadUUID(reader, "SoundID");
- }
- private static void ProcessSoundGain(SceneObjectPart obj, XmlReader reader)
- {
- obj.SoundGain = reader.ReadElementContentAsDouble("SoundGain", String.Empty);
- }
- private static void ProcessSoundFlags(SceneObjectPart obj, XmlReader reader)
- {
- obj.SoundFlags = (byte)reader.ReadElementContentAsInt("SoundFlags", String.Empty);
- }
- private static void ProcessSoundRadius(SceneObjectPart obj, XmlReader reader)
- {
- obj.SoundRadius = reader.ReadElementContentAsDouble("SoundRadius", String.Empty);
- }
- private static void ProcessSoundQueueing(SceneObjectPart obj, XmlReader reader)
- {
- obj.SoundQueueing = Util.ReadBoolean(reader);
- }
- private static void ProcessVehicle(SceneObjectPart obj, XmlReader reader)
- {
- SOPVehicle vehicle = SOPVehicle.FromXml2(reader);
- if (vehicle == null)
- {
- obj.VehicleParams = null;
- m_log.DebugFormat(
- "[SceneObjectSerializer]: Parsing Vehicle for object part {0} {1} encountered errors. Please see earlier log entries.",
- obj.Name, obj.UUID);
- }
- else
- {
- obj.VehicleParams = vehicle;
- }
- }
- private static void ProcessPhysicsInertia(SceneObjectPart obj, XmlReader reader)
- {
- PhysicsInertiaData pdata = PhysicsInertiaData.FromXml2(reader);
- if (pdata == null)
- {
- obj.PhysicsInertia = null;
- m_log.DebugFormat(
- "[SceneObjectSerializer]: Parsing PhysicsInertiaData for object part {0} {1} encountered errors. Please see earlier log entries.",
- obj.Name, obj.UUID);
- }
- else
- {
- obj.PhysicsInertia = pdata;
- }
- }
- private static void ProcessSOPAnims(SceneObjectPart obj, XmlReader reader)
- {
- obj.Animations = null;
- try
- {
- string datastr;
- datastr = reader.ReadElementContentAsString();
- if(string.IsNullOrEmpty(datastr))
- return;
- byte[] pdata = Convert.FromBase64String(datastr);
- obj.DeSerializeAnimations(pdata);
- return;
- }
- catch {}
- m_log.DebugFormat(
- "[SceneObjectSerializer]: Parsing ProcessSOPAnims for object part {0} {1} encountered errors",
- obj.Name, obj.UUID);
- }
- private static void ProcessShape(SceneObjectPart obj, XmlReader reader)
- {
- List<string> errorNodeNames;
- obj.Shape = ReadShape(reader, "Shape", out errorNodeNames, obj);
- if (errorNodeNames != null)
- {
- m_log.DebugFormat(
- "[SceneObjectSerializer]: Parsing PrimitiveBaseShape for object part {0} {1} encountered errors in properties {2}.",
- obj.Name, obj.UUID, string.Join(", ", errorNodeNames.ToArray()));
- }
- }
- private static void ProcessScale(SceneObjectPart obj, XmlReader reader)
- {
- obj.Scale = Util.ReadVector(reader, "Scale");
- }
- private static void ProcessSitTargetOrientation(SceneObjectPart obj, XmlReader reader)
- {
- obj.SitTargetOrientation = Util.ReadQuaternion(reader, "SitTargetOrientation");
- }
- private static void ProcessSitTargetPosition(SceneObjectPart obj, XmlReader reader)
- {
- obj.SitTargetPosition = Util.ReadVector(reader, "SitTargetPosition");
- }
- private static void ProcessSitTargetPositionLL(SceneObjectPart obj, XmlReader reader)
- {
- obj.SitTargetPositionLL = Util.ReadVector(reader, "SitTargetPositionLL");
- }
- private static void ProcessSitTargetOrientationLL(SceneObjectPart obj, XmlReader reader)
- {
- obj.SitTargetOrientationLL = Util.ReadQuaternion(reader, "SitTargetOrientationLL");
- }
- private static void ProcessParentID(SceneObjectPart obj, XmlReader reader)
- {
- string str = reader.ReadElementContentAsString("ParentID", String.Empty);
- obj.ParentID = Convert.ToUInt32(str);
- }
- private static void ProcessCreationDate(SceneObjectPart obj, XmlReader reader)
- {
- obj.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty);
- }
- private static void ProcessCategory(SceneObjectPart obj, XmlReader reader)
- {
- obj.Category = (uint)reader.ReadElementContentAsInt("Category", String.Empty);
- }
- private static void ProcessSalePrice(SceneObjectPart obj, XmlReader reader)
- {
- obj.SalePrice = reader.ReadElementContentAsInt("SalePrice", String.Empty);
- }
- private static void ProcessObjectSaleType(SceneObjectPart obj, XmlReader reader)
- {
- obj.ObjectSaleType = (byte)reader.ReadElementContentAsInt("ObjectSaleType", String.Empty);
- }
- private static void ProcessOwnershipCost(SceneObjectPart obj, XmlReader reader)
- {
- obj.OwnershipCost = reader.ReadElementContentAsInt("OwnershipCost", String.Empty);
- }
- private static void ProcessGroupID(SceneObjectPart obj, XmlReader reader)
- {
- obj.GroupID = Util.ReadUUID(reader, "GroupID");
- }
- private static void ProcessOwnerID(SceneObjectPart obj, XmlReader reader)
- {
- obj.OwnerID = Util.ReadUUID(reader, "OwnerID");
- }
- private static void ProcessLastOwnerID(SceneObjectPart obj, XmlReader reader)
- {
- obj.LastOwnerID = Util.ReadUUID(reader, "LastOwnerID");
- }
- private static void ProcessRezzerID(SceneObjectPart obj, XmlReader reader)
- {
- obj.RezzerID = Util.ReadUUID(reader, "RezzerID");
- }
- private static void ProcessBaseMask(SceneObjectPart obj, XmlReader reader)
- {
- obj.BaseMask = (uint)reader.ReadElementContentAsInt("BaseMask", String.Empty);
- }
- private static void ProcessOwnerMask(SceneObjectPart obj, XmlReader reader)
- {
- obj.OwnerMask = (uint)reader.ReadElementContentAsInt("OwnerMask", String.Empty);
- }
- private static void ProcessGroupMask(SceneObjectPart obj, XmlReader reader)
- {
- obj.GroupMask = (uint)reader.ReadElementContentAsInt("GroupMask", String.Empty);
- }
- private static void ProcessEveryoneMask(SceneObjectPart obj, XmlReader reader)
- {
- obj.EveryoneMask = (uint)reader.ReadElementContentAsInt("EveryoneMask", String.Empty);
- }
- private static void ProcessNextOwnerMask(SceneObjectPart obj, XmlReader reader)
- {
- obj.NextOwnerMask = (uint)reader.ReadElementContentAsInt("NextOwnerMask", String.Empty);
- }
- private static void ProcessFlags(SceneObjectPart obj, XmlReader reader)
- {
- obj.Flags = Util.ReadEnum<PrimFlags>(reader, "Flags");
- }
- private static void ProcessCollisionSound(SceneObjectPart obj, XmlReader reader)
- {
- obj.CollisionSound = Util.ReadUUID(reader, "CollisionSound");
- }
- private static void ProcessCollisionSoundVolume(SceneObjectPart obj, XmlReader reader)
- {
- obj.CollisionSoundVolume = reader.ReadElementContentAsFloat("CollisionSoundVolume", String.Empty);
- }
- private static void ProcessMediaUrl(SceneObjectPart obj, XmlReader reader)
- {
- obj.MediaUrl = reader.ReadElementContentAsString("MediaUrl", String.Empty);
- }
- private static void ProcessAttachedPos(SceneObjectPart obj, XmlReader reader)
- {
- obj.AttachedPos = Util.ReadVector(reader, "AttachedPos");
- }
- private static void ProcessDynAttrs(SceneObjectPart obj, XmlReader reader)
- {
- DAMap waste = new DAMap();
- waste.ReadXml(reader);
- if(waste.CountNamespaces > 0)
- obj.DynAttrs = waste;
- else
- obj.DynAttrs = null;
- }
- private static void ProcessTextureAnimation(SceneObjectPart obj, XmlReader reader)
- {
- obj.TextureAnimation = Convert.FromBase64String(reader.ReadElementContentAsString("TextureAnimation", String.Empty));
- }
- private static void ProcessParticleSystem(SceneObjectPart obj, XmlReader reader)
- {
- obj.ParticleSystem = Convert.FromBase64String(reader.ReadElementContentAsString("ParticleSystem", String.Empty));
- }
- private static void ProcessPayPrice0(SceneObjectPart obj, XmlReader reader)
- {
- obj.PayPrice[0] = (int)reader.ReadElementContentAsInt("PayPrice0", String.Empty);
- }
- private static void ProcessPayPrice1(SceneObjectPart obj, XmlReader reader)
- {
- obj.PayPrice[1] = (int)reader.ReadElementContentAsInt("PayPrice1", String.Empty);
- }
- private static void ProcessPayPrice2(SceneObjectPart obj, XmlReader reader)
- {
- obj.PayPrice[2] = (int)reader.ReadElementContentAsInt("PayPrice2", String.Empty);
- }
- private static void ProcessPayPrice3(SceneObjectPart obj, XmlReader reader)
- {
- obj.PayPrice[3] = (int)reader.ReadElementContentAsInt("PayPrice3", String.Empty);
- }
- private static void ProcessPayPrice4(SceneObjectPart obj, XmlReader reader)
- {
- obj.PayPrice[4] = (int)reader.ReadElementContentAsInt("PayPrice4", String.Empty);
- }
- private static void ProcessBuoyancy(SceneObjectPart obj, XmlReader reader)
- {
- obj.Buoyancy = (float)reader.ReadElementContentAsFloat("Buoyancy", String.Empty);
- }
- private static void ProcessForce(SceneObjectPart obj, XmlReader reader)
- {
- obj.Force = Util.ReadVector(reader, "Force");
- }
- private static void ProcessTorque(SceneObjectPart obj, XmlReader reader)
- {
- obj.Torque = Util.ReadVector(reader, "Torque");
- }
- private static void ProcessVolumeDetectActive(SceneObjectPart obj, XmlReader reader)
- {
- obj.VolumeDetectActive = Util.ReadBoolean(reader);
- }
- #endregion
- #region TaskInventoryXmlProcessors
- private static void ProcessTIAssetID(TaskInventoryItem item, XmlReader reader)
- {
- item.AssetID = Util.ReadUUID(reader, "AssetID");
- }
- private static void ProcessTIBasePermissions(TaskInventoryItem item, XmlReader reader)
- {
- item.BasePermissions = (uint)reader.ReadElementContentAsInt("BasePermissions", String.Empty);
- }
- private static void ProcessTICreationDate(TaskInventoryItem item, XmlReader reader)
- {
- item.CreationDate = (uint)reader.ReadElementContentAsInt("CreationDate", String.Empty);
- }
- private static void ProcessTICreatorID(TaskInventoryItem item, XmlReader reader)
- {
- item.CreatorID = Util.ReadUUID(reader, "CreatorID");
- }
- private static void ProcessTICreatorData(TaskInventoryItem item, XmlReader reader)
- {
- item.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty);
- }
- private static void ProcessTIDescription(TaskInventoryItem item, XmlReader reader)
- {
- item.Description = reader.ReadElementContentAsString("Description", String.Empty);
- }
- private static void ProcessTIEveryonePermissions(TaskInventoryItem item, XmlReader reader)
- {
- item.EveryonePermissions = (uint)reader.ReadElementContentAsInt("EveryonePermissions", String.Empty);
- }
- private static void ProcessTIFlags(TaskInventoryItem item, XmlReader reader)
- {
- item.Flags = (uint)reader.ReadElementContentAsInt("Flags", String.Empty);
- }
- private static void ProcessTIGroupID(TaskInventoryItem item, XmlReader reader)
- {
- item.GroupID = Util.ReadUUID(reader, "GroupID");
- }
- private static void ProcessTIGroupPermissions(TaskInventoryItem item, XmlReader reader)
- {
- item.GroupPermissions = (uint)reader.ReadElementContentAsInt("GroupPermissions", String.Empty);
- }
- private static void ProcessTIInvType(TaskInventoryItem item, XmlReader reader)
- {
- item.InvType = reader.ReadElementContentAsInt("InvType", String.Empty);
- }
- private static void ProcessTIItemID(TaskInventoryItem item, XmlReader reader)
- {
- item.ItemID = Util.ReadUUID(reader, "ItemID");
- }
- private static void ProcessTIOldItemID(TaskInventoryItem item, XmlReader reader)
- {
- item.OldItemID = Util.ReadUUID(reader, "OldItemID");
- }
- private static void ProcessTILastOwnerID(TaskInventoryItem item, XmlReader reader)
- {
- item.LastOwnerID = Util.ReadUUID(reader, "LastOwnerID");
- }
- private static void ProcessTIName(TaskInventoryItem item, XmlReader reader)
- {
- item.Name = reader.ReadElementContentAsString("Name", String.Empty);
- }
- private static void ProcessTINextPermissions(TaskInventoryItem item, XmlReader reader)
- {
- item.NextPermissions = (uint)reader.ReadElementContentAsInt("NextPermissions", String.Empty);
- }
- private static void ProcessTIOwnerID(TaskInventoryItem item, XmlReader reader)
- {
- item.OwnerID = Util.ReadUUID(reader, "OwnerID");
- }
- private static void ProcessTICurrentPermissions(TaskInventoryItem item, XmlReader reader)
- {
- item.CurrentPermissions = (uint)reader.ReadElementContentAsInt("CurrentPermissions", String.Empty);
- }
- private static void ProcessTIParentID(TaskInventoryItem item, XmlReader reader)
- {
- item.ParentID = Util.ReadUUID(reader, "ParentID");
- }
- private static void ProcessTIParentPartID(TaskInventoryItem item, XmlReader reader)
- {
- item.ParentPartID = Util.ReadUUID(reader, "ParentPartID");
- }
- private static void ProcessTIPermsGranter(TaskInventoryItem item, XmlReader reader)
- {
- item.PermsGranter = Util.ReadUUID(reader, "PermsGranter");
- }
- private static void ProcessTIPermsMask(TaskInventoryItem item, XmlReader reader)
- {
- item.PermsMask = reader.ReadElementContentAsInt("PermsMask", String.Empty);
- }
- private static void ProcessTIType(TaskInventoryItem item, XmlReader reader)
- {
- item.Type = reader.ReadElementContentAsInt("Type", String.Empty);
- }
- private static void ProcessTIOwnerChanged(TaskInventoryItem item, XmlReader reader)
- {
- item.OwnerChanged = Util.ReadBoolean(reader);
- }
- #endregion
- #region ShapeXmlProcessors
- private static void ProcessShpProfileCurve(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.ProfileCurve = (byte)reader.ReadElementContentAsInt("ProfileCurve", String.Empty);
- }
- private static void ProcessShpTextureEntry(PrimitiveBaseShape shp, XmlReader reader)
- {
- byte[] teData = Convert.FromBase64String(reader.ReadElementString("TextureEntry"));
- shp.Textures = new Primitive.TextureEntry(teData, 0, teData.Length);
- }
- private static void ProcessShpExtraParams(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.ExtraParams = Convert.FromBase64String(reader.ReadElementString("ExtraParams"));
- }
- private static void ProcessShpPathBegin(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PathBegin = (ushort)reader.ReadElementContentAsInt("PathBegin", String.Empty);
- }
- private static void ProcessShpPathCurve(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PathCurve = (byte)reader.ReadElementContentAsInt("PathCurve", String.Empty);
- }
- private static void ProcessShpPathEnd(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PathEnd = (ushort)reader.ReadElementContentAsInt("PathEnd", String.Empty);
- }
- private static void ProcessShpPathRadiusOffset(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PathRadiusOffset = (sbyte)reader.ReadElementContentAsInt("PathRadiusOffset", String.Empty);
- }
- private static void ProcessShpPathRevolutions(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PathRevolutions = (byte)reader.ReadElementContentAsInt("PathRevolutions", String.Empty);
- }
- private static void ProcessShpPathScaleX(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PathScaleX = (byte)reader.ReadElementContentAsInt("PathScaleX", String.Empty);
- }
- private static void ProcessShpPathScaleY(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PathScaleY = (byte)reader.ReadElementContentAsInt("PathScaleY", String.Empty);
- }
- private static void ProcessShpPathShearX(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PathShearX = (byte)reader.ReadElementContentAsInt("PathShearX", String.Empty);
- }
- private static void ProcessShpPathShearY(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PathShearY = (byte)reader.ReadElementContentAsInt("PathShearY", String.Empty);
- }
- private static void ProcessShpPathSkew(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PathSkew = (sbyte)reader.ReadElementContentAsInt("PathSkew", String.Empty);
- }
- private static void ProcessShpPathTaperX(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PathTaperX = (sbyte)reader.ReadElementContentAsInt("PathTaperX", String.Empty);
- }
- private static void ProcessShpPathTaperY(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PathTaperY = (sbyte)reader.ReadElementContentAsInt("PathTaperY", String.Empty);
- }
- private static void ProcessShpPathTwist(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PathTwist = (sbyte)reader.ReadElementContentAsInt("PathTwist", String.Empty);
- }
- private static void ProcessShpPathTwistBegin(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PathTwistBegin = (sbyte)reader.ReadElementContentAsInt("PathTwistBegin", String.Empty);
- }
- private static void ProcessShpPCode(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.PCode = (byte)reader.ReadElementContentAsInt("PCode", String.Empty);
- }
- private static void ProcessShpProfileBegin(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.ProfileBegin = (ushort)reader.ReadElementContentAsInt("ProfileBegin", String.Empty);
- }
- private static void ProcessShpProfileEnd(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.ProfileEnd = (ushort)reader.ReadElementContentAsInt("ProfileEnd", String.Empty);
- }
- private static void ProcessShpProfileHollow(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.ProfileHollow = (ushort)reader.ReadElementContentAsInt("ProfileHollow", String.Empty);
- }
- private static void ProcessShpScale(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.Scale = Util.ReadVector(reader, "Scale");
- }
- private static void ProcessShpState(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.State = (byte)reader.ReadElementContentAsInt("State", String.Empty);
- }
- private static void ProcessShpLastAttach(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.LastAttachPoint = (byte)reader.ReadElementContentAsInt("LastAttachPoint", String.Empty);
- }
- private static void ProcessShpProfileShape(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.ProfileShape = Util.ReadEnum<ProfileShape>(reader, "ProfileShape");
- }
- private static void ProcessShpHollowShape(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.HollowShape = Util.ReadEnum<HollowShape>(reader, "HollowShape");
- }
- private static void ProcessShpSculptTexture(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.SculptTexture = Util.ReadUUID(reader, "SculptTexture");
- }
- private static void ProcessShpSculptType(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.SculptType = (byte)reader.ReadElementContentAsInt("SculptType", String.Empty);
- }
- private static void ProcessShpFlexiSoftness(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.FlexiSoftness = reader.ReadElementContentAsInt("FlexiSoftness", String.Empty);
- }
- private static void ProcessShpFlexiTension(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.FlexiTension = reader.ReadElementContentAsFloat("FlexiTension", String.Empty);
- }
- private static void ProcessShpFlexiDrag(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.FlexiDrag = reader.ReadElementContentAsFloat("FlexiDrag", String.Empty);
- }
- private static void ProcessShpFlexiGravity(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.FlexiGravity = reader.ReadElementContentAsFloat("FlexiGravity", String.Empty);
- }
- private static void ProcessShpFlexiWind(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.FlexiWind = reader.ReadElementContentAsFloat("FlexiWind", String.Empty);
- }
- private static void ProcessShpFlexiForceX(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.FlexiForceX = reader.ReadElementContentAsFloat("FlexiForceX", String.Empty);
- }
- private static void ProcessShpFlexiForceY(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.FlexiForceY = reader.ReadElementContentAsFloat("FlexiForceY", String.Empty);
- }
- private static void ProcessShpFlexiForceZ(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.FlexiForceZ = reader.ReadElementContentAsFloat("FlexiForceZ", String.Empty);
- }
- private static void ProcessShpLightColorR(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.LightColorR = reader.ReadElementContentAsFloat("LightColorR", String.Empty);
- }
- private static void ProcessShpLightColorG(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.LightColorG = reader.ReadElementContentAsFloat("LightColorG", String.Empty);
- }
- private static void ProcessShpLightColorB(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.LightColorB = reader.ReadElementContentAsFloat("LightColorB", String.Empty);
- }
- private static void ProcessShpLightColorA(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.LightColorA = reader.ReadElementContentAsFloat("LightColorA", String.Empty);
- }
- private static void ProcessShpLightRadius(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.LightRadius = reader.ReadElementContentAsFloat("LightRadius", String.Empty);
- }
- private static void ProcessShpLightCutoff(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.LightCutoff = reader.ReadElementContentAsFloat("LightCutoff", String.Empty);
- }
- private static void ProcessShpLightFalloff(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.LightFalloff = reader.ReadElementContentAsFloat("LightFalloff", String.Empty);
- }
- private static void ProcessShpLightIntensity(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.LightIntensity = reader.ReadElementContentAsFloat("LightIntensity", String.Empty);
- }
- private static void ProcessShpFlexiEntry(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.FlexiEntry = Util.ReadBoolean(reader);
- }
- private static void ProcessShpLightEntry(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.LightEntry = Util.ReadBoolean(reader);
- }
- private static void ProcessShpSculptEntry(PrimitiveBaseShape shp, XmlReader reader)
- {
- shp.SculptEntry = Util.ReadBoolean(reader);
- }
- private static void ProcessShpMedia(PrimitiveBaseShape shp, XmlReader reader)
- {
- string value = String.Empty;
- try
- {
- // The STANDARD content of Media elemet is escaped XML string (with > etc).
- value = reader.ReadElementContentAsString("Media", String.Empty);
- shp.Media = PrimitiveBaseShape.MediaList.FromXml(value);
- }
- catch (XmlException)
- {
- // There are versions of OAR files that contain unquoted XML.
- // ie ONE comercial fork that never wanted their oars to be read by our code
- try
- {
- value = reader.ReadInnerXml();
- shp.Media = PrimitiveBaseShape.MediaList.FromXml(value);
- }
- catch
- {
- m_log.ErrorFormat("[SERIALIZER] Failed parsing halcyon MOAP information");
- }
- }
- }
- #endregion
- ////////// Write /////////
- public static void SOGToXml2(XmlTextWriter writer, SceneObjectGroup sog, Dictionary<string, object>options)
- {
- writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty);
- SOPToXml2(writer, sog.RootPart, options);
- writer.WriteStartElement(String.Empty, "OtherParts", String.Empty);
- sog.ForEachPart(delegate(SceneObjectPart sop)
- {
- if (sop.UUID != sog.RootPart.UUID)
- SOPToXml2(writer, sop, options);
- });
- writer.WriteEndElement();
- if (sog.RootPart.KeyframeMotion != null)
- {
- Byte[] data = sog.RootPart.KeyframeMotion.Serialize();
- writer.WriteStartElement(String.Empty, "KeyframeMotion", String.Empty);
- writer.WriteBase64(data, 0, data.Length);
- writer.WriteEndElement();
- }
- writer.WriteEndElement();
- }
- public static void SOPToXml2(XmlTextWriter writer, SceneObjectPart sop, Dictionary<string, object> options)
- {
- writer.WriteStartElement("SceneObjectPart");
- writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
- writer.WriteAttributeString("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
- writer.WriteElementString("AllowedDrop", sop.AllowedDrop.ToString().ToLower());
- WriteUUID(writer, "CreatorID", sop.CreatorID, options);
- if (!string.IsNullOrEmpty(sop.CreatorData))
- writer.WriteElementString("CreatorData", sop.CreatorData);
- else if (options.ContainsKey("home"))
- {
- if (m_UserManagement == null)
- m_UserManagement = sop.ParentGroup.Scene.RequestModuleInterface<IUserManagement>();
- string name = m_UserManagement.GetUserName(sop.CreatorID);
- writer.WriteElementString("CreatorData", ExternalRepresentationUtils.CalcCreatorData((string)options["home"], name));
- }
- WriteUUID(writer, "FolderID", sop.FolderID, options);
- writer.WriteElementString("InventorySerial", sop.InventorySerial.ToString());
- WriteTaskInventory(writer, sop.TaskInventory, options, sop.ParentGroup.Scene);
- WriteUUID(writer, "UUID", sop.UUID, options);
- writer.WriteElementString("LocalId", sop.LocalId.ToString());
- writer.WriteElementString("Name", sop.Name);
- writer.WriteElementString("Material", sop.Material.ToString());
- writer.WriteElementString("PassTouches", sop.PassTouches.ToString().ToLower());
- writer.WriteElementString("PassCollisions", sop.PassCollisions.ToString().ToLower());
- writer.WriteElementString("RegionHandle", sop.RegionHandle.ToString());
- writer.WriteElementString("ScriptAccessPin", sop.ScriptAccessPin.ToString());
- WriteVector(writer, "GroupPosition", sop.GroupPosition);
- WriteVector(writer, "OffsetPosition", sop.OffsetPosition);
- WriteQuaternion(writer, "RotationOffset", sop.RotationOffset);
- WriteVector(writer, "Velocity", sop.Velocity);
- WriteVector(writer, "AngularVelocity", sop.AngularVelocity);
- WriteVector(writer, "Acceleration", sop.Acceleration);
- writer.WriteElementString("Description", sop.Description);
- writer.WriteStartElement("Color");
- writer.WriteElementString("R", sop.Color.R.ToString(Culture.FormatProvider));
- writer.WriteElementString("G", sop.Color.G.ToString(Culture.FormatProvider));
- writer.WriteElementString("B", sop.Color.B.ToString(Culture.FormatProvider));
- writer.WriteElementString("A", sop.Color.A.ToString(Culture.FormatProvider));
- writer.WriteEndElement();
- writer.WriteElementString("Text", sop.Text);
- writer.WriteElementString("SitName", sop.SitName);
- writer.WriteElementString("TouchName", sop.TouchName);
- writer.WriteElementString("LinkNum", sop.LinkNum.ToString());
- writer.WriteElementString("ClickAction", sop.ClickAction.ToString());
- WriteShape(writer, sop.Shape, options);
- WriteVector(writer, "Scale", sop.Scale);
- WriteQuaternion(writer, "SitTargetOrientation", sop.SitTargetOrientation);
- WriteVector(writer, "SitTargetPosition", sop.SitTargetPosition);
- WriteVector(writer, "SitTargetPositionLL", sop.SitTargetPositionLL);
- WriteQuaternion(writer, "SitTargetOrientationLL", sop.SitTargetOrientationLL);
- writer.WriteElementString("ParentID", sop.ParentID.ToString());
- writer.WriteElementString("CreationDate", sop.CreationDate.ToString());
- writer.WriteElementString("Category", sop.Category.ToString());
- writer.WriteElementString("SalePrice", sop.SalePrice.ToString());
- writer.WriteElementString("ObjectSaleType", sop.ObjectSaleType.ToString());
- writer.WriteElementString("OwnershipCost", sop.OwnershipCost.ToString());
- UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.GroupID;
- WriteUUID(writer, "GroupID", groupID, options);
- UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.OwnerID;
- WriteUUID(writer, "OwnerID", ownerID, options);
- UUID lastOwnerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.LastOwnerID;
- WriteUUID(writer, "LastOwnerID", lastOwnerID, options);
- UUID rezzerID = options.ContainsKey("wipe-owners") ? UUID.Zero : sop.RezzerID;
- WriteUUID(writer, "RezzerID", rezzerID, options);
- writer.WriteElementString("BaseMask", sop.BaseMask.ToString());
- writer.WriteElementString("OwnerMask", sop.OwnerMask.ToString());
- writer.WriteElementString("GroupMask", sop.GroupMask.ToString());
- writer.WriteElementString("EveryoneMask", sop.EveryoneMask.ToString());
- writer.WriteElementString("NextOwnerMask", sop.NextOwnerMask.ToString());
- WriteFlags(writer, "Flags", sop.Flags.ToString(), options);
- WriteUUID(writer, "CollisionSound", sop.CollisionSound, options);
- writer.WriteElementString("CollisionSoundVolume", sop.CollisionSoundVolume.ToString(Culture.FormatProvider));
- if (sop.MediaUrl != null)
- writer.WriteElementString("MediaUrl", sop.MediaUrl.ToString());
- WriteVector(writer, "AttachedPos", sop.AttachedPos);
- if (sop.DynAttrs != null && sop.DynAttrs.CountNamespaces > 0)
- {
- writer.WriteStartElement("DynAttrs");
- sop.DynAttrs.WriteXml(writer);
- writer.WriteEndElement();
- }
- WriteBytes(writer, "TextureAnimation", sop.TextureAnimation);
- WriteBytes(writer, "ParticleSystem", sop.ParticleSystem);
- writer.WriteElementString("PayPrice0", sop.PayPrice[0].ToString());
- writer.WriteElementString("PayPrice1", sop.PayPrice[1].ToString());
- writer.WriteElementString("PayPrice2", sop.PayPrice[2].ToString());
- writer.WriteElementString("PayPrice3", sop.PayPrice[3].ToString());
- writer.WriteElementString("PayPrice4", sop.PayPrice[4].ToString());
- writer.WriteElementString("Buoyancy", sop.Buoyancy.ToString(Culture.FormatProvider));
- WriteVector(writer, "Force", sop.Force);
- WriteVector(writer, "Torque", sop.Torque);
- writer.WriteElementString("VolumeDetectActive", sop.VolumeDetectActive.ToString().ToLower());
- if (sop.VehicleParams != null)
- sop.VehicleParams.ToXml2(writer);
- if (sop.PhysicsInertia != null)
- sop.PhysicsInertia.ToXml2(writer);
- if(sop.RotationAxisLocks != 0)
- writer.WriteElementString("RotationAxisLocks", sop.RotationAxisLocks.ToString().ToLower());
- writer.WriteElementString("PhysicsShapeType", sop.PhysicsShapeType.ToString().ToLower());
- if (sop.Density != 1000.0f)
- writer.WriteElementString("Density", sop.Density.ToString(Culture.FormatProvider));
- if (sop.Friction != 0.6f)
- writer.WriteElementString("Friction", sop.Friction.ToString(Culture.FormatProvider));
- if (sop.Restitution != 0.5f)
- writer.WriteElementString("Bounce", sop.Restitution.ToString(Culture.FormatProvider));
- if (sop.GravityModifier != 1.0f)
- writer.WriteElementString("GravityModifier", sop.GravityModifier.ToString(Culture.FormatProvider));
- WriteVector(writer, "CameraEyeOffset", sop.GetCameraEyeOffset());
- WriteVector(writer, "CameraAtOffset", sop.GetCameraAtOffset());
- // if (sop.Sound != UUID.Zero) force it till sop crossing does clear it on child prim
- {
- WriteUUID(writer, "SoundID", sop.Sound, options);
- writer.WriteElementString("SoundGain", sop.SoundGain.ToString(Culture.FormatProvider));
- writer.WriteElementString("SoundFlags", sop.SoundFlags.ToString().ToLower());
- writer.WriteElementString("SoundRadius", sop.SoundRadius.ToString(Culture.FormatProvider));
- }
- writer.WriteElementString("SoundQueueing", sop.SoundQueueing.ToString().ToLower());
- if (sop.Animations != null)
- {
- Byte[] data = sop.SerializeAnimations();
- if(data != null && data.Length > 0)
- writer.WriteElementString("SOPAnims", Convert.ToBase64String(data));
- }
- writer.WriteEndElement();
- }
- static void WriteUUID(XmlTextWriter writer, string name, UUID id, Dictionary<string, object> options)
- {
- writer.WriteStartElement(name);
- if (options.ContainsKey("old-guids"))
- writer.WriteElementString("Guid", id.ToString());
- else
- writer.WriteElementString("UUID", id.ToString());
- writer.WriteEndElement();
- }
- static void WriteVector(XmlTextWriter writer, string name, Vector3 vec)
- {
- writer.WriteStartElement(name);
- writer.WriteElementString("X", vec.X.ToString(Culture.FormatProvider));
- writer.WriteElementString("Y", vec.Y.ToString(Culture.FormatProvider));
- writer.WriteElementString("Z", vec.Z.ToString(Culture.FormatProvider));
- writer.WriteEndElement();
- }
- static void WriteQuaternion(XmlTextWriter writer, string name, Quaternion quat)
- {
- writer.WriteStartElement(name);
- writer.WriteElementString("X", quat.X.ToString(Culture.FormatProvider));
- writer.WriteElementString("Y", quat.Y.ToString(Culture.FormatProvider));
- writer.WriteElementString("Z", quat.Z.ToString(Culture.FormatProvider));
- writer.WriteElementString("W", quat.W.ToString(Culture.FormatProvider));
- writer.WriteEndElement();
- }
- static void WriteBytes(XmlTextWriter writer, string name, byte[] data)
- {
- writer.WriteStartElement(name);
- byte[] d;
- if (data != null)
- d = data;
- else
- d = Utils.EmptyBytes;
- writer.WriteBase64(d, 0, d.Length);
- writer.WriteEndElement(); // name
- }
- static void WriteFlags(XmlTextWriter writer, string name, string flagsStr, Dictionary<string, object> options)
- {
- // Older versions of serialization can't cope with commas, so we eliminate the commas
- writer.WriteElementString(name, flagsStr.Replace(",", ""));
- }
- public static void WriteTaskInventory(XmlTextWriter writer, TaskInventoryDictionary tinv, Dictionary<string, object> options, Scene scene)
- {
- if (tinv.Count > 0) // otherwise skip this
- {
- writer.WriteStartElement("TaskInventory");
- foreach (TaskInventoryItem item in tinv.Values)
- {
- writer.WriteStartElement("TaskInventoryItem");
- WriteUUID(writer, "AssetID", item.AssetID, options);
- writer.WriteElementString("BasePermissions", item.BasePermissions.ToString());
- writer.WriteElementString("CreationDate", item.CreationDate.ToString());
- WriteUUID(writer, "CreatorID", item.CreatorID, options);
- if (!string.IsNullOrEmpty(item.CreatorData))
- writer.WriteElementString("CreatorData", item.CreatorData);
- else if (options.ContainsKey("home"))
- {
- if (m_UserManagement == null)
- m_UserManagement = scene.RequestModuleInterface<IUserManagement>();
- string name = m_UserManagement.GetUserName(item.CreatorID);
- writer.WriteElementString("CreatorData", ExternalRepresentationUtils.CalcCreatorData((string)options["home"], name));
- }
- writer.WriteElementString("Description", item.Description);
- writer.WriteElementString("EveryonePermissions", item.EveryonePermissions.ToString());
- writer.WriteElementString("Flags", item.Flags.ToString());
- UUID groupID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.GroupID;
- WriteUUID(writer, "GroupID", groupID, options);
- writer.WriteElementString("GroupPermissions", item.GroupPermissions.ToString());
- writer.WriteElementString("InvType", item.InvType.ToString());
- WriteUUID(writer, "ItemID", item.ItemID, options);
- WriteUUID(writer, "OldItemID", item.OldItemID, options);
- UUID lastOwnerID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.LastOwnerID;
- WriteUUID(writer, "LastOwnerID", lastOwnerID, options);
- writer.WriteElementString("Name", item.Name);
- writer.WriteElementString("NextPermissions", item.NextPermissions.ToString());
- UUID ownerID = options.ContainsKey("wipe-owners") ? UUID.Zero : item.OwnerID;
- WriteUUID(writer, "OwnerID", ownerID, options);
- writer.WriteElementString("CurrentPermissions", item.CurrentPermissions.ToString());
- WriteUUID(writer, "ParentID", item.ParentID, options);
- WriteUUID(writer, "ParentPartID", item.ParentPartID, options);
- WriteUUID(writer, "PermsGranter", item.PermsGranter, options);
- writer.WriteElementString("PermsMask", item.PermsMask.ToString());
- writer.WriteElementString("Type", item.Type.ToString());
- bool ownerChanged = options.ContainsKey("wipe-owners") ? false : item.OwnerChanged;
- writer.WriteElementString("OwnerChanged", ownerChanged.ToString().ToLower());
- writer.WriteEndElement(); // TaskInventoryItem
- }
- writer.WriteEndElement(); // TaskInventory
- }
- }
- public static void WriteShape(XmlTextWriter writer, PrimitiveBaseShape shp, Dictionary<string, object> options)
- {
- if (shp != null)
- {
- writer.WriteStartElement("Shape");
- writer.WriteElementString("ProfileCurve", shp.ProfileCurve.ToString());
- writer.WriteStartElement("TextureEntry");
- byte[] te;
- if (shp.TextureEntry != null)
- te = shp.TextureEntry;
- else
- te = Utils.EmptyBytes;
- writer.WriteBase64(te, 0, te.Length);
- writer.WriteEndElement(); // TextureEntry
- writer.WriteStartElement("ExtraParams");
- byte[] ep;
- if (shp.ExtraParams != null)
- ep = shp.ExtraParams;
- else
- ep = Utils.EmptyBytes;
- writer.WriteBase64(ep, 0, ep.Length);
- writer.WriteEndElement(); // ExtraParams
- writer.WriteElementString("PathBegin", shp.PathBegin.ToString());
- writer.WriteElementString("PathCurve", shp.PathCurve.ToString());
- writer.WriteElementString("PathEnd", shp.PathEnd.ToString());
- writer.WriteElementString("PathRadiusOffset", shp.PathRadiusOffset.ToString());
- writer.WriteElementString("PathRevolutions", shp.PathRevolutions.ToString());
- writer.WriteElementString("PathScaleX", shp.PathScaleX.ToString());
- writer.WriteElementString("PathScaleY", shp.PathScaleY.ToString());
- writer.WriteElementString("PathShearX", shp.PathShearX.ToString());
- writer.WriteElementString("PathShearY", shp.PathShearY.ToString());
- writer.WriteElementString("PathSkew", shp.PathSkew.ToString());
- writer.WriteElementString("PathTaperX", shp.PathTaperX.ToString());
- writer.WriteElementString("PathTaperY", shp.PathTaperY.ToString());
- writer.WriteElementString("PathTwist", shp.PathTwist.ToString());
- writer.WriteElementString("PathTwistBegin", shp.PathTwistBegin.ToString());
- writer.WriteElementString("PCode", shp.PCode.ToString());
- writer.WriteElementString("ProfileBegin", shp.ProfileBegin.ToString());
- writer.WriteElementString("ProfileEnd", shp.ProfileEnd.ToString());
- writer.WriteElementString("ProfileHollow", shp.ProfileHollow.ToString());
- writer.WriteElementString("State", shp.State.ToString());
- writer.WriteElementString("LastAttachPoint", shp.LastAttachPoint.ToString());
- WriteFlags(writer, "ProfileShape", shp.ProfileShape.ToString(), options);
- WriteFlags(writer, "HollowShape", shp.HollowShape.ToString(), options);
- WriteUUID(writer, "SculptTexture", shp.SculptTexture, options);
- writer.WriteElementString("SculptType", shp.SculptType.ToString());
- // Don't serialize SculptData. It's just a copy of the asset, which can be loaded separately using 'SculptTexture'.
- writer.WriteElementString("FlexiSoftness", shp.FlexiSoftness.ToString());
- writer.WriteElementString("FlexiTension", shp.FlexiTension.ToString(Culture.FormatProvider));
- writer.WriteElementString("FlexiDrag", shp.FlexiDrag.ToString(Culture.FormatProvider));
- writer.WriteElementString("FlexiGravity", shp.FlexiGravity.ToString(Culture.FormatProvider));
- writer.WriteElementString("FlexiWind", shp.FlexiWind.ToString(Culture.FormatProvider));
- writer.WriteElementString("FlexiForceX", shp.FlexiForceX.ToString(Culture.FormatProvider));
- writer.WriteElementString("FlexiForceY", shp.FlexiForceY.ToString(Culture.FormatProvider));
- writer.WriteElementString("FlexiForceZ", shp.FlexiForceZ.ToString(Culture.FormatProvider));
- writer.WriteElementString("LightColorR", shp.LightColorR.ToString(Culture.FormatProvider));
- writer.WriteElementString("LightColorG", shp.LightColorG.ToString(Culture.FormatProvider));
- writer.WriteElementString("LightColorB", shp.LightColorB.ToString(Culture.FormatProvider));
- writer.WriteElementString("LightColorA", shp.LightColorA.ToString(Culture.FormatProvider));
- writer.WriteElementString("LightRadius", shp.LightRadius.ToString(Culture.FormatProvider));
- writer.WriteElementString("LightCutoff", shp.LightCutoff.ToString(Culture.FormatProvider));
- writer.WriteElementString("LightFalloff", shp.LightFalloff.ToString(Culture.FormatProvider));
- writer.WriteElementString("LightIntensity", shp.LightIntensity.ToString(Culture.FormatProvider));
- writer.WriteElementString("FlexiEntry", shp.FlexiEntry.ToString().ToLower());
- writer.WriteElementString("LightEntry", shp.LightEntry.ToString().ToLower());
- writer.WriteElementString("SculptEntry", shp.SculptEntry.ToString().ToLower());
- if (shp.Media != null)
- writer.WriteElementString("Media", shp.Media.ToXml());
- writer.WriteEndElement(); // Shape
- }
- }
- public static SceneObjectPart Xml2ToSOP(XmlReader reader)
- {
- SceneObjectPart obj = new SceneObjectPart();
- reader.ReadStartElement("SceneObjectPart");
- bool errors = ExternalRepresentationUtils.ExecuteReadProcessors(
- obj,
- m_SOPXmlProcessors,
- reader,
- (o, nodeName, e) => {
- m_log.Debug(string.Format("[SceneObjectSerializer]: Error while parsing element {0} in object {1} {2} ",
- nodeName, ((SceneObjectPart)o).Name, ((SceneObjectPart)o).UUID), e);
- });
- if (errors)
- throw new XmlException(string.Format("Error parsing object {0} {1}", obj.Name, obj.UUID));
- reader.ReadEndElement(); // SceneObjectPart
- obj.AggregateInnerPerms();
- // m_log.DebugFormat("[SceneObjectSerializer]: parsed SOP {0} {1}", obj.Name, obj.UUID);
- return obj;
- }
- public static TaskInventoryDictionary ReadTaskInventory(XmlReader reader, string name)
- {
- TaskInventoryDictionary tinv = new TaskInventoryDictionary();
- reader.ReadStartElement(name, String.Empty);
- while (reader.Name == "TaskInventoryItem")
- {
- reader.ReadStartElement("TaskInventoryItem", String.Empty); // TaskInventory
- TaskInventoryItem item = new TaskInventoryItem();
- ExternalRepresentationUtils.ExecuteReadProcessors(
- item,
- m_TaskInventoryXmlProcessors,
- reader);
- reader.ReadEndElement(); // TaskInventoryItem
- tinv.Add(item.ItemID, item);
- }
- if (reader.NodeType == XmlNodeType.EndElement)
- reader.ReadEndElement(); // TaskInventory
- return tinv;
- }
- /// <summary>
- /// Read a shape from xml input
- /// </summary>
- /// <param name="reader"></param>
- /// <param name="name">The name of the xml element containing the shape</param>
- /// <param name="errors">a list containing the failing node names. If no failures then null.</param>
- /// <returns>The shape parsed</returns>
- public static PrimitiveBaseShape ReadShape(XmlReader reader, string name, out List<string> errorNodeNames, SceneObjectPart obj)
- {
- List<string> internalErrorNodeNames = null;
- PrimitiveBaseShape shape = new PrimitiveBaseShape();
- if (reader.IsEmptyElement)
- {
- reader.Read();
- errorNodeNames = null;
- return shape;
- }
- reader.ReadStartElement(name, String.Empty); // Shape
- ExternalRepresentationUtils.ExecuteReadProcessors(
- shape,
- m_ShapeXmlProcessors,
- reader,
- (o, nodeName, e) => {
- m_log.Debug(string.Format("[SceneObjectSerializer]: Error while parsing element {0} in Shape property of object {1} {2} ",
- nodeName, obj.Name, obj.UUID), e);
- if (internalErrorNodeNames == null)
- internalErrorNodeNames = new List<string>();
- internalErrorNodeNames.Add(nodeName);
- });
- reader.ReadEndElement(); // Shape
- errorNodeNames = internalErrorNodeNames;
- return shape;
- }
- #endregion
- }
- }
|