From b59d9789f8cafdc64ebf4ecf4fec75d5589c97f7 Mon Sep 17 00:00:00 2001 From: MW Date: Mon, 13 Aug 2007 13:36:42 +0000 Subject: Partial Linking of prim groups should work (its partial as currently only the root prim of the child group will actually get linked, working on linking the rest now). Multiple prim groups are now stored in the sqlite database and are reloaded correctly. --- .../Region/Environment/Scenes/SceneObjectGroup.cs | 182 ++++++++++++++++----- 1 file changed, 141 insertions(+), 41 deletions(-) (limited to 'OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs') diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs index 39b7fb0..dae4b5f 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs @@ -1,5 +1,9 @@ using System.Collections.Generic; using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.IO; +using System; using Axiom.Math; using libsecondlife; using libsecondlife.Packets; @@ -22,6 +26,7 @@ namespace OpenSim.Region.Environment.Scenes public event PrimCountTaintedDelegate OnPrimCountTainted; + #region Properties /// /// /// @@ -111,6 +116,9 @@ namespace OpenSim.Region.Environment.Scenes set { m_isSelected = value; } } + #endregion + + #region Constructors /// /// /// @@ -122,6 +130,31 @@ namespace OpenSim.Region.Environment.Scenes /// /// /// + public SceneObjectGroup(Scene scene, ulong regionHandle, string xmlData) + { + m_scene = scene; + m_regionHandle = regionHandle; + + StringReader sr = new StringReader(xmlData); + XmlTextReader reader = new XmlTextReader(sr); + reader.ReadStartElement("SceneObjectGroup"); + reader.ReadStartElement("RootPart"); + this.m_rootPart = SceneObjectPart.FromXml(reader); + reader.ReadEndElement(); + //TODO: read and create rest of the parts + reader.ReadEndElement(); + reader.Close(); + sr.Close(); + + this.m_parts.Add(m_rootPart.UUID, m_rootPart); + this.m_rootPart.LocalID = m_scene.PrimIDAllocate(); + this.m_rootPart.RegionHandle = m_regionHandle; + m_scene.EventManager.OnBackup += this.ProcessBackup; + } + + /// + /// + /// public SceneObjectGroup(byte[] data) { @@ -142,7 +175,25 @@ namespace OpenSim.Region.Environment.Scenes this.SetPartAsRoot(newPart); m_scene.EventManager.OnBackup += this.ProcessBackup; } + #endregion + public string ToXmlString() + { + StringWriter sw = new StringWriter(); + //StreamWriter st = new StreamWriter("testxml.txt"); + XmlTextWriter writer = new XmlTextWriter(sw); + writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty); + writer.WriteStartElement(String.Empty, "RootPart", String.Empty); + m_rootPart.ToXml(writer); + writer.WriteEndElement(); + writer.WriteEndElement(); + writer.Close(); + // System.Console.WriteLine("prim: " + sw.ToString()); + return sw.ToString(); + // st.Close(); + // return ""; + + } #region Copying /// @@ -170,23 +221,6 @@ namespace OpenSim.Region.Environment.Scenes } /// - /// Added as a way for the storage provider to reset the scene, - /// most likely a better way to do this sort of thing but for now... - /// - /// - public void SetScene(Scene scene) - { - m_scene = scene; - m_scene.EventManager.OnBackup += this.ProcessBackup; - } - - public void AddPart(SceneObjectPart part) - { - part.SetParent(this); - this.m_parts.Add(part.UUID, part); - } - - /// /// /// /// @@ -209,6 +243,7 @@ namespace OpenSim.Region.Environment.Scenes } #endregion + #region Scheduling /// /// /// @@ -264,15 +299,9 @@ namespace OpenSim.Region.Environment.Scenes } } - /// - /// - /// - /// - public void LinkToGroup(SceneObjectGroup objectGroup) - { - - } + #endregion + #region SceneGroupPart Methods /// /// /// @@ -339,26 +368,37 @@ namespace OpenSim.Region.Environment.Scenes } return false; } + #endregion + #region Packet Handlers /// /// /// - public void TriggerTainted() - { - if (OnPrimCountTainted != null) - { - this.OnPrimCountTainted(); - } - } - - /// - /// Processes backup - /// - /// - public void ProcessBackup(OpenSim.Region.Interfaces.IRegionDataStore datastore) + /// + public void LinkToGroup(SceneObjectGroup objectGroup) { - datastore.StoreObject(this); + SceneObjectPart linkPart = objectGroup.m_rootPart; + linkPart.OffsetPosition = linkPart.GroupPosition - this.Pos; + linkPart.GroupPosition = this.Pos; + + Vector3 axPos = new Vector3(linkPart.OffsetPosition.X, linkPart.OffsetPosition.Y, linkPart.OffsetPosition.Z); + Quaternion parentRot = new Quaternion(this.m_rootPart.RotationOffset.W, this.m_rootPart.RotationOffset.X, this.m_rootPart.RotationOffset.Y, this.m_rootPart.RotationOffset.Z); + axPos = parentRot.Inverse() * axPos; + linkPart.OffsetPosition = new LLVector3(axPos.x, axPos.y, axPos.z); + Quaternion oldRot = new Quaternion(linkPart.RotationOffset.W, linkPart.RotationOffset.X, linkPart.RotationOffset.Y, linkPart.RotationOffset.Z); + Quaternion newRot = parentRot * oldRot; + linkPart.RotationOffset = new LLQuaternion(newRot.x, newRot.y, newRot.z, newRot.w); + linkPart.ParentID = this.m_rootPart.LocalID; + this.m_parts.Add(linkPart.UUID, linkPart); + linkPart.SetParent(this); + + //TODO: rest of parts + + m_scene.EventManager.OnBackup -= objectGroup.ProcessBackup; + m_scene.DeleteEntity(objectGroup.UUID); + this.ScheduleGroupForFullUpdate(); } + /// /// /// @@ -469,6 +509,7 @@ namespace OpenSim.Region.Environment.Scenes part.UpdateTextureEntry(textureEntry); } } + #endregion #region Shape /// @@ -485,6 +526,7 @@ namespace OpenSim.Region.Environment.Scenes } #endregion + #region Resize /// /// /// @@ -498,6 +540,7 @@ namespace OpenSim.Region.Environment.Scenes part.Resize(scale); } } + #endregion #region Position /// @@ -636,8 +679,6 @@ namespace OpenSim.Region.Environment.Scenes private void SetPartAsRoot(SceneObjectPart part) { this.m_rootPart = part; - //this.m_uuid= part.UUID; - // this.m_localId = part.LocalID; } /// @@ -658,6 +699,29 @@ namespace OpenSim.Region.Environment.Scenes return m_scene.RequestAvatarList(); } + #region Events + /// + /// + /// + public void TriggerTainted() + { + if (OnPrimCountTainted != null) + { + this.OnPrimCountTainted(); + } + } + + /// + /// Processes backup + /// + /// + public void ProcessBackup(OpenSim.Region.Interfaces.IRegionDataStore datastore) + { + datastore.StoreObject(this); + } + #endregion + + #region Client Updating public void SendFullUpdateToClient(IClientAPI remoteClient) { lock (this.m_parts) @@ -702,5 +766,41 @@ namespace OpenSim.Region.Environment.Scenes part.SendTerseUpdateToClient(remoteClient); } } + #endregion + + /// + /// Added as a way for the storage provider to reset the scene, + /// most likely a better way to do this sort of thing but for now... + /// + /// + public void SetScene(Scene scene) + { + m_scene = scene; + m_scene.EventManager.OnBackup += this.ProcessBackup; + } + + /// + /// + /// + /// + public void AddPart(SceneObjectPart part) + { + part.SetParent(this); + this.m_parts.Add(part.UUID, part); + } + + /// + /// + /// + public void UpdateParentIDs() + { + foreach (SceneObjectPart part in this.m_parts.Values) + { + if (part.UUID != this.m_rootPart.UUID) + { + part.ParentID = this.m_rootPart.LocalID; + } + } + } } } -- cgit v1.1