From 2dc92e7de11086c7649d3ee0f8adc974efce6805 Mon Sep 17 00:00:00 2001 From: Aleric Inglewood Date: Sun, 4 Aug 2013 19:19:11 +0200 Subject: Preserve attachment point & position when attachment is rezzed in world Patch taken from http://opensimulator.org/mantis/view.php?id=4905 originally by Greg C. Fixed to apply to r/23314 commit ba9daf849e7c8db48e7c03e7cdedb77776b2052f (cherry picked from commit 4ff9fbca441110cc2b93edc7286e0e9339e61cbe) --- .../ClientStack/Linden/Caps/ObjectCaps/ObjectAdd.cs | 4 ++++ .../Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs | 1 + OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs | 1 + .../Avatar/Attachments/AttachmentsModule.cs | 18 +++++++++++++++++- .../Framework/InventoryAccess/InventoryAccessModule.cs | 8 ++++++++ OpenSim/Region/Framework/Scenes/Scene.Inventory.cs | 7 +++++++ .../Scenes/Serialization/SceneObjectSerializer.cs | 14 ++++++++++++++ 7 files changed, 52 insertions(+), 1 deletion(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/ObjectAdd.cs b/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/ObjectAdd.cs index 92805e2..94f8bc1 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/ObjectAdd.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/ObjectAdd.cs @@ -155,6 +155,7 @@ namespace OpenSim.Region.ClientStack.Linden Quaternion rotation = Quaternion.Identity; Vector3 scale = Vector3.Zero; int state = 0; + int lastattach = 0; if (r.Type != OSDType.Map) // not a proper req return responsedata; @@ -224,6 +225,7 @@ namespace OpenSim.Region.ClientStack.Linden ray_target_id = ObjMap["RayTargetId"].AsUUID(); state = ObjMap["State"].AsInteger(); + lastattach = ObjMap["LastAttachPoint"].AsInteger(); try { ray_end = ((OSDArray)ObjMap["RayEnd"]).AsVector3(); @@ -290,6 +292,7 @@ namespace OpenSim.Region.ClientStack.Linden //session_id = rm["session_id"].AsUUID(); state = rm["state"].AsInteger(); + lastattach = rm["last_attach_point"].AsInteger(); try { ray_end = ((OSDArray)rm["ray_end"]).AsVector3(); @@ -331,6 +334,7 @@ namespace OpenSim.Region.ClientStack.Linden pbs.ProfileEnd = (ushort)profile_end; pbs.Scale = scale; pbs.State = (byte)state; + pbs.LastAttachPoint = (byte)lastattach; SceneObjectGroup obj = null; ; diff --git a/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs index 55a503e..769fe28 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/UploadObjectAssetModule.cs @@ -277,6 +277,7 @@ namespace OpenSim.Region.ClientStack.Linden pbs.ProfileEnd = (ushort) obj.ProfileEnd; pbs.Scale = obj.Scale; pbs.State = (byte) 0; + pbs.LastAttachPoint = (byte) 0; SceneObjectPart prim = new SceneObjectPart(); prim.UUID = UUID.Random(); prim.CreatorID = AgentId; diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index 1b091bf..3609ec1 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -12188,6 +12188,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP shape.PCode = addPacket.ObjectData.PCode; shape.State = addPacket.ObjectData.State; + shape.LastAttachPoint = addPacket.ObjectData.State; shape.PathBegin = addPacket.ObjectData.PathBegin; shape.PathEnd = addPacket.ObjectData.PathEnd; shape.PathScaleX = addPacket.ObjectData.PathScaleX; diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index 2818712..d0e0b35 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -422,6 +422,13 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments attachPos = Vector3.Zero; } + // if the attachment point is the same as previous, make sure we get the saved + // position info. + if (attachmentPt != 0 && attachmentPt == group.RootPart.Shape.LastAttachPoint) + { + attachPos = group.RootPart.AttachedPos; + } + // AttachmentPt 0 means the client chose to 'wear' the attachment. if (attachmentPt == (uint)AttachmentPoint.Default) { @@ -429,6 +436,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments attachmentPt = group.AttachmentPoint; } + // if we didn't find an attach point, look for where it was last attached + if (attachmentPt == 0) + { + attachmentPt = (uint)group.RootPart.Shape.LastAttachPoint; + attachPos = group.RootPart.AttachedPos; + group.HasGroupChanged = true; + } + // if we still didn't find a suitable attachment point....... if (attachmentPt == 0) { @@ -619,6 +634,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments so.ClearPartAttachmentData(); rootPart.ApplyPhysics(rootPart.GetEffectiveObjectFlags(), rootPart.VolumeDetectActive); so.HasGroupChanged = true; + so.RootPart.Shape.LastAttachPoint = (byte)so.AttachmentPoint; rootPart.Rezzed = DateTime.Now; rootPart.RemFlag(PrimFlags.TemporaryOnRez); so.AttachToBackup(); @@ -1210,4 +1226,4 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments #endregion } -} \ No newline at end of file +} diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs index 68e4e26..0ec9575 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs @@ -836,6 +836,14 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess m_log.Debug("[INVENTORY ACCESS MODULE]: Object has UUID.Zero! Position 3"); } + // if this was previously an attachment and is now being rezzed, + // save the old attachment info. + if (group.IsAttachment == false && group.RootPart.Shape.State != 0) + { + group.RootPart.AttachedPos = group.AbsolutePosition; + group.RootPart.Shape.LastAttachPoint = (byte)group.AttachmentPoint; + } + foreach (SceneObjectPart part in group.Parts) { // Make the rezzer the owner, as this is not necessarily set correctly in the serialized asset. diff --git a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs index 69b5f43..4bebbe8 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.Inventory.cs @@ -2230,6 +2230,13 @@ namespace OpenSim.Region.Framework.Scenes sourcePart.Inventory.RemoveInventoryItem(item.ItemID); } + + if (group.IsAttachment == false && group.RootPart.Shape.State != 0) + { + group.RootPart.AttachedPos = group.AbsolutePosition; + group.RootPart.Shape.LastAttachPoint = (byte)group.AttachmentPoint; + } + group.FromPartID = sourcePart.UUID; AddNewSceneObject(group, true, pos, rot, vel); diff --git a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs index 945745e..3ea936c 100644 --- a/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs +++ b/OpenSim/Region/Framework/Scenes/Serialization/SceneObjectSerializer.cs @@ -365,6 +365,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization 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); @@ -433,6 +434,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization 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); @@ -761,6 +763,11 @@ namespace OpenSim.Region.Framework.Scenes.Serialization obj.MediaUrl = reader.ReadElementContentAsString("MediaUrl", String.Empty); } + private static void ProcessAttachedPos(SceneObjectPart obj, XmlTextReader reader) + { + obj.AttachedPos = Util.ReadVector(reader, "AttachedPos"); + } + private static void ProcessDynAttrs(SceneObjectPart obj, XmlTextReader reader) { obj.DynAttrs.ReadXml(reader); @@ -1043,6 +1050,11 @@ namespace OpenSim.Region.Framework.Scenes.Serialization shp.State = (byte)reader.ReadElementContentAsInt("State", String.Empty); } + private static void ProcessShpLastAttach(PrimitiveBaseShape shp, XmlTextReader reader) + { + shp.LastAttachPoint = (byte)reader.ReadElementContentAsInt("LastAttachPoint", String.Empty); + } + private static void ProcessShpProfileShape(PrimitiveBaseShape shp, XmlTextReader reader) { shp.ProfileShape = Util.ReadEnum(reader, "ProfileShape"); @@ -1289,6 +1301,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization writer.WriteElementString("CollisionSoundVolume", sop.CollisionSoundVolume.ToString()); if (sop.MediaUrl != null) writer.WriteElementString("MediaUrl", sop.MediaUrl.ToString()); + WriteVector(writer, "AttachedPos", sop.AttachedPos); if (sop.DynAttrs.CountNamespaces > 0) { @@ -1471,6 +1484,7 @@ namespace OpenSim.Region.Framework.Scenes.Serialization 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); -- cgit v1.1