From 28e5abd9176aeba3b5004d07748ae88cccbcd57a Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 4 Jun 2012 21:05:56 +0200 Subject: Fix llAttachToAvatar and "Attach" viewer option to preserve saved attach positions. --- .../Avatar/Attachments/AttachmentsModule.cs | 26 ++++++++++++++++++---- .../Attachments/Tests/AttachmentsModuleTests.cs | 4 ++-- .../Framework/Interfaces/IAttachmentsModule.cs | 2 +- OpenSim/Region/Framework/Scenes/Scene.cs | 2 +- .../Shared/Api/Implementation/LSL_Api.cs | 2 +- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index d7c7283..fd7cad2 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -227,7 +227,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments sp.ClearAttachments(); } - public bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent) + public bool AttachObject(IScenePresence sp, SceneObjectGroup group, uint attachmentPt, bool silent, bool useAttachData) { lock (sp.AttachmentsSyncLock) { @@ -273,9 +273,27 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments attachPos = Vector3.Zero; } + if (useAttachData) + { + group.RootPart.RotationOffset = group.RootPart.AttachRotation; + attachPos = group.RootPart.AttachOffset; + if (attachmentPt == 0) + { + attachmentPt = group.RootPart.AttachPoint; + if (attachmentPt == 0) + { + attachmentPt = (uint)AttachmentPoint.LeftHand; + attachPos = Vector3.Zero; + } + } + else if (group.RootPart.AttachPoint != attachmentPt) + { + attachPos = Vector3.Zero; + } + } group.AttachmentPoint = attachmentPt; group.AbsolutePosition = attachPos; - + // We also don't want to do any of the inventory operations for an NPC. if (sp.PresenceType != PresenceType.Npc) { @@ -792,7 +810,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments // This will throw if the attachment fails try { - AttachObject(sp, objatt, attachmentPt, false); + AttachObject(sp, objatt, attachmentPt, false, false); } catch (Exception e) { @@ -947,7 +965,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments AttachmentPt &= 0x7f; // Calls attach with a Zero position - if (AttachObject(sp, part.ParentGroup, AttachmentPt, false)) + if (AttachObject(sp, part.ParentGroup, AttachmentPt, false, true)) { m_scene.EventManager.TriggerOnAttach(objectLocalID, part.ParentGroup.FromItemID, remoteClient.AgentId); diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs index bfe5e4a..7119ad2 100644 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/Tests/AttachmentsModuleTests.cs @@ -106,7 +106,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, attName).ParentGroup; - m_attMod.AttachObject(m_presence, so, (uint)AttachmentPoint.Chest, false); + m_attMod.AttachObject(m_presence, so, (uint)AttachmentPoint.Chest, false, false); // Check status on scene presence Assert.That(m_presence.HasAttachments(), Is.True); @@ -317,4 +317,4 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests // Assert.That(presence.HasAttachments(), Is.True, "Presence has not received new objects"); // } } -} \ No newline at end of file +} diff --git a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs index 69ce967..0516cb1 100644 --- a/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs +++ b/OpenSim/Region/Framework/Interfaces/IAttachmentsModule.cs @@ -65,7 +65,7 @@ namespace OpenSim.Region.Framework.Interfaces /// /// /// true if the object was successfully attached, false otherwise - bool AttachObject(IScenePresence sp, SceneObjectGroup grp, uint AttachmentPt, bool silent); + bool AttachObject(IScenePresence sp, SceneObjectGroup grp, uint AttachmentPt, bool silent, bool useAttachmentInfo); /// /// Rez an attachment from user inventory and change inventory status to match. diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index a9a4cda..6a120c1 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2692,7 +2692,7 @@ namespace OpenSim.Region.Framework.Scenes RootPrim.RemFlag(PrimFlags.TemporaryOnRez); if (AttachmentsModule != null) - AttachmentsModule.AttachObject(sp, grp, 0, false); + AttachmentsModule.AttachObject(sp, grp, 0, false, false); } else { diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index ec0966b..ec44da0 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -3344,7 +3344,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule; if (attachmentsModule != null) - attachmentsModule.AttachObject(presence, grp, (uint)attachment, false); + attachmentsModule.AttachObject(presence, grp, (uint)attachment, false, true); } } -- cgit v1.1