aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs566
1 files changed, 502 insertions, 64 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
index 8860764..48a870e 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs
@@ -24,11 +24,12 @@
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Drawing; 30using System.Drawing;
31using System.IO; 31using System.IO;
32using System.Diagnostics;
32using System.Linq; 33using System.Linq;
33using System.Threading; 34using System.Threading;
34using System.Xml; 35using System.Xml;
@@ -105,8 +106,29 @@ namespace OpenSim.Region.Framework.Scenes
105 /// since the group's last persistent backup 106 /// since the group's last persistent backup
106 /// </summary> 107 /// </summary>
107 private bool m_hasGroupChanged = false; 108 private bool m_hasGroupChanged = false;
108 private long timeFirstChanged; 109 private long timeFirstChanged = 0;
109 private long timeLastChanged; 110 private long timeLastChanged = 0;
111 private long m_maxPersistTime = 0;
112 private long m_minPersistTime = 0;
113 private Random m_rand;
114 private bool m_suspendUpdates;
115 private List<ScenePresence> m_linkedAvatars = new List<ScenePresence>();
116
117 public bool areUpdatesSuspended
118 {
119 get
120 {
121 return m_suspendUpdates;
122 }
123 set
124 {
125 m_suspendUpdates = value;
126 if (!value)
127 {
128 QueueForUpdateCheck();
129 }
130 }
131 }
110 132
111 public bool HasGroupChanged 133 public bool HasGroupChanged
112 { 134 {
@@ -114,9 +136,39 @@ namespace OpenSim.Region.Framework.Scenes
114 { 136 {
115 if (value) 137 if (value)
116 { 138 {
139 if (m_isBackedUp)
140 {
141 m_scene.SceneGraph.FireChangeBackup(this);
142 }
117 timeLastChanged = DateTime.Now.Ticks; 143 timeLastChanged = DateTime.Now.Ticks;
118 if (!m_hasGroupChanged) 144 if (!m_hasGroupChanged)
119 timeFirstChanged = DateTime.Now.Ticks; 145 timeFirstChanged = DateTime.Now.Ticks;
146 if (m_rootPart != null && m_rootPart.UUID != null && m_scene != null)
147 {
148 if (m_rand == null)
149 {
150 byte[] val = new byte[16];
151 m_rootPart.UUID.ToBytes(val, 0);
152 m_rand = new Random(BitConverter.ToInt32(val, 0));
153 }
154
155 if (m_scene.GetRootAgentCount() == 0)
156 {
157 //If the region is empty, this change has been made by an automated process
158 //and thus we delay the persist time by a random amount between 1.5 and 2.5.
159
160 float factor = 1.5f + (float)(m_rand.NextDouble());
161 m_maxPersistTime = (long)((float)m_scene.m_persistAfter * factor);
162 m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * factor);
163 }
164 else
165 {
166 //If the region is not empty, we want to obey the minimum and maximum persist times
167 //but add a random factor so we stagger the object persistance a little
168 m_maxPersistTime = (long)((float)m_scene.m_persistAfter * (1.0d - (m_rand.NextDouble() / 5.0d))); //Multiply by 1.0-1.5
169 m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * (1.0d + (m_rand.NextDouble() / 2.0d))); //Multiply by 0.8-1.0
170 }
171 }
120 } 172 }
121 m_hasGroupChanged = value; 173 m_hasGroupChanged = value;
122 174
@@ -131,7 +183,7 @@ namespace OpenSim.Region.Framework.Scenes
131 /// Has the group changed due to an unlink operation? We record this in order to optimize deletion, since 183 /// Has the group changed due to an unlink operation? We record this in order to optimize deletion, since
132 /// an unlinked group currently has to be persisted to the database before we can perform an unlink operation. 184 /// an unlinked group currently has to be persisted to the database before we can perform an unlink operation.
133 /// </summary> 185 /// </summary>
134 public bool HasGroupChangedDueToDelink { get; private set; } 186 public bool HasGroupChangedDueToDelink { get; set; }
135 187
136 private bool isTimeToPersist() 188 private bool isTimeToPersist()
137 { 189 {
@@ -141,8 +193,19 @@ namespace OpenSim.Region.Framework.Scenes
141 return false; 193 return false;
142 if (m_scene.ShuttingDown) 194 if (m_scene.ShuttingDown)
143 return true; 195 return true;
196
197 if (m_minPersistTime == 0 || m_maxPersistTime == 0)
198 {
199 m_maxPersistTime = m_scene.m_persistAfter;
200 m_minPersistTime = m_scene.m_dontPersistBefore;
201 }
202
144 long currentTime = DateTime.Now.Ticks; 203 long currentTime = DateTime.Now.Ticks;
145 if (currentTime - timeLastChanged > m_scene.m_dontPersistBefore || currentTime - timeFirstChanged > m_scene.m_persistAfter) 204
205 if (timeLastChanged == 0) timeLastChanged = currentTime;
206 if (timeFirstChanged == 0) timeFirstChanged = currentTime;
207
208 if (currentTime - timeLastChanged > m_minPersistTime || currentTime - timeFirstChanged > m_maxPersistTime)
146 return true; 209 return true;
147 return false; 210 return false;
148 } 211 }
@@ -247,10 +310,10 @@ namespace OpenSim.Region.Framework.Scenes
247 310
248 private bool m_scriptListens_atTarget; 311 private bool m_scriptListens_atTarget;
249 private bool m_scriptListens_notAtTarget; 312 private bool m_scriptListens_notAtTarget;
250
251 private bool m_scriptListens_atRotTarget; 313 private bool m_scriptListens_atRotTarget;
252 private bool m_scriptListens_notAtRotTarget; 314 private bool m_scriptListens_notAtRotTarget;
253 315
316 public bool m_dupeInProgress = false;
254 internal Dictionary<UUID, string> m_savedScriptState; 317 internal Dictionary<UUID, string> m_savedScriptState;
255 318
256 #region Properties 319 #region Properties
@@ -281,6 +344,16 @@ namespace OpenSim.Region.Framework.Scenes
281 get { return m_parts.Count; } 344 get { return m_parts.Count; }
282 } 345 }
283 346
347// protected Quaternion m_rotation = Quaternion.Identity;
348//
349// public virtual Quaternion Rotation
350// {
351// get { return m_rotation; }
352// set {
353// m_rotation = value;
354// }
355// }
356
284 public Quaternion GroupRotation 357 public Quaternion GroupRotation
285 { 358 {
286 get { return m_rootPart.RotationOffset; } 359 get { return m_rootPart.RotationOffset; }
@@ -389,7 +462,11 @@ namespace OpenSim.Region.Framework.Scenes
389 m_scene.CrossPrimGroupIntoNewRegion(val, this, true); 462 m_scene.CrossPrimGroupIntoNewRegion(val, this, true);
390 } 463 }
391 } 464 }
392 465
466 foreach (SceneObjectPart part in m_parts.GetArray())
467 {
468 part.IgnoreUndoUpdate = true;
469 }
393 if (RootPart.GetStatusSandbox()) 470 if (RootPart.GetStatusSandbox())
394 { 471 {
395 if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10) 472 if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10)
@@ -403,10 +480,29 @@ namespace OpenSim.Region.Framework.Scenes
403 return; 480 return;
404 } 481 }
405 } 482 }
406
407 SceneObjectPart[] parts = m_parts.GetArray(); 483 SceneObjectPart[] parts = m_parts.GetArray();
408 for (int i = 0; i < parts.Length; i++) 484 foreach (SceneObjectPart part in parts)
409 parts[i].GroupPosition = val; 485 {
486 part.GroupPosition = val;
487 if (!m_dupeInProgress)
488 {
489 part.TriggerScriptChangedEvent(Changed.POSITION);
490 }
491 }
492 if (!m_dupeInProgress)
493 {
494 foreach (ScenePresence av in m_linkedAvatars)
495 {
496 SceneObjectPart p = m_scene.GetSceneObjectPart(av.ParentID);
497 if (m_parts.TryGetValue(p.UUID, out p))
498 {
499 Vector3 offset = p.GetWorldPosition() - av.ParentPosition;
500 av.AbsolutePosition += offset;
501 av.ParentPosition = p.GetWorldPosition(); //ParentPosition gets cleared by AbsolutePosition
502 av.SendAvatarDataToAllAgents();
503 }
504 }
505 }
410 506
411 //if (m_rootPart.PhysActor != null) 507 //if (m_rootPart.PhysActor != null)
412 //{ 508 //{
@@ -565,6 +661,7 @@ namespace OpenSim.Region.Framework.Scenes
565 /// </summary> 661 /// </summary>
566 public SceneObjectGroup() 662 public SceneObjectGroup()
567 { 663 {
664
568 } 665 }
569 666
570 /// <summary> 667 /// <summary>
@@ -581,7 +678,7 @@ namespace OpenSim.Region.Framework.Scenes
581 /// Constructor. This object is added to the scene later via AttachToScene() 678 /// Constructor. This object is added to the scene later via AttachToScene()
582 /// </summary> 679 /// </summary>
583 public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape) 680 public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape)
584 { 681 {
585 SetRootPart(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero)); 682 SetRootPart(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero));
586 } 683 }
587 684
@@ -629,6 +726,9 @@ namespace OpenSim.Region.Framework.Scenes
629 /// </summary> 726 /// </summary>
630 public virtual void AttachToBackup() 727 public virtual void AttachToBackup()
631 { 728 {
729 if (IsAttachment) return;
730 m_scene.SceneGraph.FireAttachToBackup(this);
731
632 if (InSceneBackup) 732 if (InSceneBackup)
633 { 733 {
634 //m_log.DebugFormat( 734 //m_log.DebugFormat(
@@ -671,6 +771,9 @@ namespace OpenSim.Region.Framework.Scenes
671 771
672 ApplyPhysics(); 772 ApplyPhysics();
673 773
774 if (RootPart.PhysActor != null)
775 RootPart.Buoyancy = RootPart.Buoyancy;
776
674 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled 777 // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled
675 // for the same object with very different properties. The caller must schedule the update. 778 // for the same object with very different properties. The caller must schedule the update.
676 //ScheduleGroupForFullUpdate(); 779 //ScheduleGroupForFullUpdate();
@@ -686,6 +789,10 @@ namespace OpenSim.Region.Framework.Scenes
686 EntityIntersection result = new EntityIntersection(); 789 EntityIntersection result = new EntityIntersection();
687 790
688 SceneObjectPart[] parts = m_parts.GetArray(); 791 SceneObjectPart[] parts = m_parts.GetArray();
792
793 // Find closest hit here
794 float idist = float.MaxValue;
795
689 for (int i = 0; i < parts.Length; i++) 796 for (int i = 0; i < parts.Length; i++)
690 { 797 {
691 SceneObjectPart part = parts[i]; 798 SceneObjectPart part = parts[i];
@@ -700,11 +807,6 @@ namespace OpenSim.Region.Framework.Scenes
700 807
701 EntityIntersection inter = part.TestIntersectionOBB(hRay, parentrotation, frontFacesOnly, faceCenters); 808 EntityIntersection inter = part.TestIntersectionOBB(hRay, parentrotation, frontFacesOnly, faceCenters);
702 809
703 // This may need to be updated to the maximum draw distance possible..
704 // We might (and probably will) be checking for prim creation from other sims
705 // when the camera crosses the border.
706 float idist = Constants.RegionSize;
707
708 if (inter.HitTF) 810 if (inter.HitTF)
709 { 811 {
710 // We need to find the closest prim to return to the testcaller along the ray 812 // We need to find the closest prim to return to the testcaller along the ray
@@ -715,10 +817,11 @@ namespace OpenSim.Region.Framework.Scenes
715 result.obj = part; 817 result.obj = part;
716 result.normal = inter.normal; 818 result.normal = inter.normal;
717 result.distance = inter.distance; 819 result.distance = inter.distance;
820
821 idist = inter.distance;
718 } 822 }
719 } 823 }
720 } 824 }
721
722 return result; 825 return result;
723 } 826 }
724 827
@@ -738,17 +841,19 @@ namespace OpenSim.Region.Framework.Scenes
738 minZ = 8192f; 841 minZ = 8192f;
739 842
740 SceneObjectPart[] parts = m_parts.GetArray(); 843 SceneObjectPart[] parts = m_parts.GetArray();
741 for (int i = 0; i < parts.Length; i++) 844 foreach (SceneObjectPart part in parts)
742 { 845 {
743 SceneObjectPart part = parts[i];
744
745 Vector3 worldPos = part.GetWorldPosition(); 846 Vector3 worldPos = part.GetWorldPosition();
746 Vector3 offset = worldPos - AbsolutePosition; 847 Vector3 offset = worldPos - AbsolutePosition;
747 Quaternion worldRot; 848 Quaternion worldRot;
748 if (part.ParentID == 0) 849 if (part.ParentID == 0)
850 {
749 worldRot = part.RotationOffset; 851 worldRot = part.RotationOffset;
852 }
750 else 853 else
854 {
751 worldRot = part.GetWorldRotation(); 855 worldRot = part.GetWorldRotation();
856 }
752 857
753 Vector3 frontTopLeft; 858 Vector3 frontTopLeft;
754 Vector3 frontTopRight; 859 Vector3 frontTopRight;
@@ -760,6 +865,8 @@ namespace OpenSim.Region.Framework.Scenes
760 Vector3 backBottomLeft; 865 Vector3 backBottomLeft;
761 Vector3 backBottomRight; 866 Vector3 backBottomRight;
762 867
868 // Vector3[] corners = new Vector3[8];
869
763 Vector3 orig = Vector3.Zero; 870 Vector3 orig = Vector3.Zero;
764 871
765 frontTopLeft.X = orig.X - (part.Scale.X / 2); 872 frontTopLeft.X = orig.X - (part.Scale.X / 2);
@@ -794,6 +901,38 @@ namespace OpenSim.Region.Framework.Scenes
794 backBottomRight.Y = orig.Y + (part.Scale.Y / 2); 901 backBottomRight.Y = orig.Y + (part.Scale.Y / 2);
795 backBottomRight.Z = orig.Z - (part.Scale.Z / 2); 902 backBottomRight.Z = orig.Z - (part.Scale.Z / 2);
796 903
904
905
906 //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z);
907 //m_log.InfoFormat("pre corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z);
908 //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
909 //m_log.InfoFormat("pre corner 4 is {0} {1} {2}", frontBottomLeft.X, frontBottomLeft.Y, frontBottomLeft.Z);
910 //m_log.InfoFormat("pre corner 5 is {0} {1} {2}", backTopLeft.X, backTopLeft.Y, backTopLeft.Z);
911 //m_log.InfoFormat("pre corner 6 is {0} {1} {2}", backTopRight.X, backTopRight.Y, backTopRight.Z);
912 //m_log.InfoFormat("pre corner 7 is {0} {1} {2}", backBottomRight.X, backBottomRight.Y, backBottomRight.Z);
913 //m_log.InfoFormat("pre corner 8 is {0} {1} {2}", backBottomLeft.X, backBottomLeft.Y, backBottomLeft.Z);
914
915 //for (int i = 0; i < 8; i++)
916 //{
917 // corners[i] = corners[i] * worldRot;
918 // corners[i] += offset;
919
920 // if (corners[i].X > maxX)
921 // maxX = corners[i].X;
922 // if (corners[i].X < minX)
923 // minX = corners[i].X;
924
925 // if (corners[i].Y > maxY)
926 // maxY = corners[i].Y;
927 // if (corners[i].Y < minY)
928 // minY = corners[i].Y;
929
930 // if (corners[i].Z > maxZ)
931 // maxZ = corners[i].Y;
932 // if (corners[i].Z < minZ)
933 // minZ = corners[i].Z;
934 //}
935
797 frontTopLeft = frontTopLeft * worldRot; 936 frontTopLeft = frontTopLeft * worldRot;
798 frontTopRight = frontTopRight * worldRot; 937 frontTopRight = frontTopRight * worldRot;
799 frontBottomLeft = frontBottomLeft * worldRot; 938 frontBottomLeft = frontBottomLeft * worldRot;
@@ -815,6 +954,15 @@ namespace OpenSim.Region.Framework.Scenes
815 backTopLeft += offset; 954 backTopLeft += offset;
816 backTopRight += offset; 955 backTopRight += offset;
817 956
957 //m_log.InfoFormat("corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z);
958 //m_log.InfoFormat("corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z);
959 //m_log.InfoFormat("corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z);
960 //m_log.InfoFormat("corner 4 is {0} {1} {2}", frontBottomLeft.X, frontBottomLeft.Y, frontBottomLeft.Z);
961 //m_log.InfoFormat("corner 5 is {0} {1} {2}", backTopLeft.X, backTopLeft.Y, backTopLeft.Z);
962 //m_log.InfoFormat("corner 6 is {0} {1} {2}", backTopRight.X, backTopRight.Y, backTopRight.Z);
963 //m_log.InfoFormat("corner 7 is {0} {1} {2}", backBottomRight.X, backBottomRight.Y, backBottomRight.Z);
964 //m_log.InfoFormat("corner 8 is {0} {1} {2}", backBottomLeft.X, backBottomLeft.Y, backBottomLeft.Z);
965
818 if (frontTopRight.X > maxX) 966 if (frontTopRight.X > maxX)
819 maxX = frontTopRight.X; 967 maxX = frontTopRight.X;
820 if (frontTopLeft.X > maxX) 968 if (frontTopLeft.X > maxX)
@@ -960,15 +1108,20 @@ namespace OpenSim.Region.Framework.Scenes
960 1108
961 public void SaveScriptedState(XmlTextWriter writer) 1109 public void SaveScriptedState(XmlTextWriter writer)
962 { 1110 {
1111 SaveScriptedState(writer, false);
1112 }
1113
1114 public void SaveScriptedState(XmlTextWriter writer, bool oldIDs)
1115 {
963 XmlDocument doc = new XmlDocument(); 1116 XmlDocument doc = new XmlDocument();
964 Dictionary<UUID,string> states = new Dictionary<UUID,string>(); 1117 Dictionary<UUID,string> states = new Dictionary<UUID,string>();
965 1118
966 SceneObjectPart[] parts = m_parts.GetArray(); 1119 SceneObjectPart[] parts = m_parts.GetArray();
967 for (int i = 0; i < parts.Length; i++) 1120 for (int i = 0; i < parts.Length; i++)
968 { 1121 {
969 Dictionary<UUID, string> pstates = parts[i].Inventory.GetScriptStates(); 1122 Dictionary<UUID, string> pstates = parts[i].Inventory.GetScriptStates(oldIDs);
970 foreach (KeyValuePair<UUID, string> kvp in pstates) 1123 foreach (KeyValuePair<UUID, string> kvp in pstates)
971 states.Add(kvp.Key, kvp.Value); 1124 states[kvp.Key] = kvp.Value;
972 } 1125 }
973 1126
974 if (states.Count > 0) 1127 if (states.Count > 0)
@@ -988,6 +1141,168 @@ namespace OpenSim.Region.Framework.Scenes
988 } 1141 }
989 1142
990 /// <summary> 1143 /// <summary>
1144 /// Add the avatar to this linkset (avatar is sat).
1145 /// </summary>
1146 /// <param name="agentID"></param>
1147 public void AddAvatar(UUID agentID)
1148 {
1149 ScenePresence presence;
1150 if (m_scene.TryGetScenePresence(agentID, out presence))
1151 {
1152 if (!m_linkedAvatars.Contains(presence))
1153 {
1154 m_linkedAvatars.Add(presence);
1155 }
1156 }
1157 }
1158
1159 /// <summary>
1160 /// Delete the avatar from this linkset (avatar is unsat).
1161 /// </summary>
1162 /// <param name="agentID"></param>
1163 public void DeleteAvatar(UUID agentID)
1164 {
1165 ScenePresence presence;
1166 if (m_scene.TryGetScenePresence(agentID, out presence))
1167 {
1168 if (m_linkedAvatars.Contains(presence))
1169 {
1170 m_linkedAvatars.Remove(presence);
1171 }
1172 }
1173 }
1174
1175 /// <summary>
1176 /// Returns the list of linked presences (avatars sat on this group)
1177 /// </summary>
1178 /// <param name="agentID"></param>
1179 public List<ScenePresence> GetLinkedAvatars()
1180 {
1181 return m_linkedAvatars;
1182 }
1183
1184 /// <summary>
1185 /// Attach this scene object to the given avatar.
1186 /// </summary>
1187 /// <param name="agentID"></param>
1188 /// <param name="attachmentpoint"></param>
1189 /// <param name="AttachOffset"></param>
1190 private void AttachToAgent(
1191 ScenePresence avatar, SceneObjectGroup so, uint attachmentpoint, Vector3 attachOffset, bool silent)
1192 {
1193 if (avatar != null)
1194 {
1195 // don't attach attachments to child agents
1196 if (avatar.IsChildAgent) return;
1197
1198 // Remove from database and parcel prim count
1199 m_scene.DeleteFromStorage(so.UUID);
1200 m_scene.EventManager.TriggerParcelPrimCountTainted();
1201
1202 so.AttachedAvatar = avatar.UUID;
1203
1204 if (so.RootPart.PhysActor != null)
1205 {
1206 m_scene.PhysicsScene.RemovePrim(so.RootPart.PhysActor);
1207 so.RootPart.PhysActor = null;
1208 }
1209
1210 so.AbsolutePosition = attachOffset;
1211 so.RootPart.AttachedPos = attachOffset;
1212 so.IsAttachment = true;
1213 so.RootPart.SetParentLocalId(avatar.LocalId);
1214 so.AttachmentPoint = attachmentpoint;
1215
1216 avatar.AddAttachment(this);
1217
1218 if (!silent)
1219 {
1220 // Killing it here will cause the client to deselect it
1221 // It then reappears on the avatar, deselected
1222 // through the full update below
1223 //
1224 if (IsSelected)
1225 {
1226 m_scene.SendKillObject(new List<uint> { m_rootPart.LocalId });
1227 }
1228
1229 IsSelected = false; // fudge....
1230 ScheduleGroupForFullUpdate();
1231 }
1232 }
1233 else
1234 {
1235 m_log.WarnFormat(
1236 "[SOG]: Tried to add attachment {0} to avatar with UUID {1} in region {2} but the avatar is not present",
1237 UUID, avatar.ControllingClient.AgentId, Scene.RegionInfo.RegionName);
1238 }
1239 }
1240
1241 public byte GetAttachmentPoint()
1242 {
1243 return m_rootPart.Shape.State;
1244 }
1245
1246 public void DetachToGround()
1247 {
1248 ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
1249 if (avatar == null)
1250 return;
1251
1252 avatar.RemoveAttachment(this);
1253
1254 Vector3 detachedpos = new Vector3(127f,127f,127f);
1255 if (avatar == null)
1256 return;
1257
1258 detachedpos = avatar.AbsolutePosition;
1259 RootPart.FromItemID = UUID.Zero;
1260
1261 AbsolutePosition = detachedpos;
1262 AttachedAvatar = UUID.Zero;
1263
1264 //SceneObjectPart[] parts = m_parts.GetArray();
1265 //for (int i = 0; i < parts.Length; i++)
1266 // parts[i].AttachedAvatar = UUID.Zero;
1267
1268 m_rootPart.SetParentLocalId(0);
1269 AttachmentPoint = (byte)0;
1270 m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive);
1271 HasGroupChanged = true;
1272 RootPart.Rezzed = DateTime.Now;
1273 RootPart.RemFlag(PrimFlags.TemporaryOnRez);
1274 AttachToBackup();
1275 m_scene.EventManager.TriggerParcelPrimCountTainted();
1276 m_rootPart.ScheduleFullUpdate();
1277 m_rootPart.ClearUndoState();
1278 }
1279
1280 public void DetachToInventoryPrep()
1281 {
1282 ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
1283 //Vector3 detachedpos = new Vector3(127f, 127f, 127f);
1284 if (avatar != null)
1285 {
1286 //detachedpos = avatar.AbsolutePosition;
1287 avatar.RemoveAttachment(this);
1288 }
1289
1290 AttachedAvatar = UUID.Zero;
1291
1292 /*SceneObjectPart[] parts = m_parts.GetArray();
1293 for (int i = 0; i < parts.Length; i++)
1294 parts[i].AttachedAvatar = UUID.Zero;*/
1295
1296 m_rootPart.SetParentLocalId(0);
1297 //m_rootPart.SetAttachmentPoint((byte)0);
1298 IsAttachment = false;
1299 AbsolutePosition = m_rootPart.AttachedPos;
1300 //m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_scene.m_physicalPrim);
1301 //AttachToBackup();
1302 //m_rootPart.ScheduleFullUpdate();
1303 }
1304
1305 /// <summary>
991 /// 1306 ///
992 /// </summary> 1307 /// </summary>
993 /// <param name="part"></param> 1308 /// <param name="part"></param>
@@ -1037,7 +1352,10 @@ namespace OpenSim.Region.Framework.Scenes
1037 public void AddPart(SceneObjectPart part) 1352 public void AddPart(SceneObjectPart part)
1038 { 1353 {
1039 part.SetParent(this); 1354 part.SetParent(this);
1040 part.LinkNum = m_parts.Add(part.UUID, part); 1355 m_parts.Add(part.UUID, part);
1356
1357 part.LinkNum = m_parts.Count;
1358
1041 if (part.LinkNum == 2) 1359 if (part.LinkNum == 2)
1042 RootPart.LinkNum = 1; 1360 RootPart.LinkNum = 1;
1043 } 1361 }
@@ -1145,6 +1463,11 @@ namespace OpenSim.Region.Framework.Scenes
1145 /// <param name="silent">If true then deletion is not broadcast to clients</param> 1463 /// <param name="silent">If true then deletion is not broadcast to clients</param>
1146 public void DeleteGroupFromScene(bool silent) 1464 public void DeleteGroupFromScene(bool silent)
1147 { 1465 {
1466 // We need to keep track of this state in case this group is still queued for backup.
1467 IsDeleted = true;
1468
1469 DetachFromBackup();
1470
1148 SceneObjectPart[] parts = m_parts.GetArray(); 1471 SceneObjectPart[] parts = m_parts.GetArray();
1149 for (int i = 0; i < parts.Length; i++) 1472 for (int i = 0; i < parts.Length; i++)
1150 { 1473 {
@@ -1167,6 +1490,8 @@ namespace OpenSim.Region.Framework.Scenes
1167 } 1490 }
1168 }); 1491 });
1169 } 1492 }
1493
1494
1170 } 1495 }
1171 1496
1172 public void AddScriptLPS(int count) 1497 public void AddScriptLPS(int count)
@@ -1262,7 +1587,12 @@ namespace OpenSim.Region.Framework.Scenes
1262 1587
1263 public void SetOwnerId(UUID userId) 1588 public void SetOwnerId(UUID userId)
1264 { 1589 {
1265 ForEachPart(delegate(SceneObjectPart part) { part.OwnerID = userId; }); 1590 ForEachPart(delegate(SceneObjectPart part)
1591 {
1592
1593 part.OwnerID = userId;
1594
1595 });
1266 } 1596 }
1267 1597
1268 public void ForEachPart(Action<SceneObjectPart> whatToDo) 1598 public void ForEachPart(Action<SceneObjectPart> whatToDo)
@@ -1294,11 +1624,17 @@ namespace OpenSim.Region.Framework.Scenes
1294 return; 1624 return;
1295 } 1625 }
1296 1626
1627 if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0)
1628 return;
1629
1297 // Since this is the top of the section of call stack for backing up a particular scene object, don't let 1630 // Since this is the top of the section of call stack for backing up a particular scene object, don't let
1298 // any exception propogate upwards. 1631 // any exception propogate upwards.
1299 try 1632 try
1300 { 1633 {
1301 if (!m_scene.ShuttingDown) // if shutting down then there will be nothing to handle the return so leave till next restart 1634 if (!m_scene.ShuttingDown || // if shutting down then there will be nothing to handle the return so leave till next restart
1635 m_scene.LoginsDisabled || // We're starting up or doing maintenance, don't mess with things
1636 m_scene.LoadingPrims) // Land may not be valid yet
1637
1302 { 1638 {
1303 ILandObject parcel = m_scene.LandChannel.GetLandObject( 1639 ILandObject parcel = m_scene.LandChannel.GetLandObject(
1304 m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y); 1640 m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y);
@@ -1325,6 +1661,7 @@ namespace OpenSim.Region.Framework.Scenes
1325 } 1661 }
1326 } 1662 }
1327 } 1663 }
1664
1328 } 1665 }
1329 1666
1330 if (m_scene.UseBackup && HasGroupChanged) 1667 if (m_scene.UseBackup && HasGroupChanged)
@@ -1332,6 +1669,20 @@ namespace OpenSim.Region.Framework.Scenes
1332 // don't backup while it's selected or you're asking for changes mid stream. 1669 // don't backup while it's selected or you're asking for changes mid stream.
1333 if (isTimeToPersist() || forcedBackup) 1670 if (isTimeToPersist() || forcedBackup)
1334 { 1671 {
1672 if (m_rootPart.PhysActor != null &&
1673 (!m_rootPart.PhysActor.IsPhysical))
1674 {
1675 // Possible ghost prim
1676 if (m_rootPart.PhysActor.Position != m_rootPart.GroupPosition)
1677 {
1678 foreach (SceneObjectPart part in m_parts.GetArray())
1679 {
1680 // Re-set physics actor positions and
1681 // orientations
1682 part.GroupPosition = m_rootPart.GroupPosition;
1683 }
1684 }
1685 }
1335// m_log.DebugFormat( 1686// m_log.DebugFormat(
1336// "[SCENE]: Storing {0}, {1} in {2}", 1687// "[SCENE]: Storing {0}, {1} in {2}",
1337// Name, UUID, m_scene.RegionInfo.RegionName); 1688// Name, UUID, m_scene.RegionInfo.RegionName);
@@ -1415,7 +1766,7 @@ namespace OpenSim.Region.Framework.Scenes
1415 // This is only necessary when userExposed is false! 1766 // This is only necessary when userExposed is false!
1416 1767
1417 bool previousAttachmentStatus = dupe.IsAttachment; 1768 bool previousAttachmentStatus = dupe.IsAttachment;
1418 1769
1419 if (!userExposed) 1770 if (!userExposed)
1420 dupe.IsAttachment = true; 1771 dupe.IsAttachment = true;
1421 1772
@@ -1433,11 +1784,11 @@ namespace OpenSim.Region.Framework.Scenes
1433 dupe.m_rootPart.TrimPermissions(); 1784 dupe.m_rootPart.TrimPermissions();
1434 1785
1435 List<SceneObjectPart> partList = new List<SceneObjectPart>(m_parts.GetArray()); 1786 List<SceneObjectPart> partList = new List<SceneObjectPart>(m_parts.GetArray());
1436 1787
1437 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) 1788 partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2)
1438 { 1789 {
1439 return p1.LinkNum.CompareTo(p2.LinkNum); 1790 return p1.LinkNum.CompareTo(p2.LinkNum);
1440 } 1791 }
1441 ); 1792 );
1442 1793
1443 foreach (SceneObjectPart part in partList) 1794 foreach (SceneObjectPart part in partList)
@@ -1457,7 +1808,7 @@ namespace OpenSim.Region.Framework.Scenes
1457 if (part.PhysActor != null && userExposed) 1808 if (part.PhysActor != null && userExposed)
1458 { 1809 {
1459 PrimitiveBaseShape pbs = newPart.Shape; 1810 PrimitiveBaseShape pbs = newPart.Shape;
1460 1811
1461 newPart.PhysActor 1812 newPart.PhysActor
1462 = m_scene.PhysicsScene.AddPrimShape( 1813 = m_scene.PhysicsScene.AddPrimShape(
1463 string.Format("{0}/{1}", newPart.Name, newPart.UUID), 1814 string.Format("{0}/{1}", newPart.Name, newPart.UUID),
@@ -1467,11 +1818,11 @@ namespace OpenSim.Region.Framework.Scenes
1467 newPart.RotationOffset, 1818 newPart.RotationOffset,
1468 part.PhysActor.IsPhysical, 1819 part.PhysActor.IsPhysical,
1469 newPart.LocalId); 1820 newPart.LocalId);
1470 1821
1471 newPart.DoPhysicsPropertyUpdate(part.PhysActor.IsPhysical, true); 1822 newPart.DoPhysicsPropertyUpdate(part.PhysActor.IsPhysical, true);
1472 } 1823 }
1473 } 1824 }
1474 1825
1475 if (userExposed) 1826 if (userExposed)
1476 { 1827 {
1477 dupe.UpdateParentIDs(); 1828 dupe.UpdateParentIDs();
@@ -1586,6 +1937,7 @@ namespace OpenSim.Region.Framework.Scenes
1586 return Vector3.Zero; 1937 return Vector3.Zero;
1587 } 1938 }
1588 1939
1940 // This is used by both Double-Click Auto-Pilot and llMoveToTarget() in an attached object
1589 public void moveToTarget(Vector3 target, float tau) 1941 public void moveToTarget(Vector3 target, float tau)
1590 { 1942 {
1591 if (IsAttachment) 1943 if (IsAttachment)
@@ -1613,10 +1965,44 @@ namespace OpenSim.Region.Framework.Scenes
1613 RootPart.PhysActor.PIDActive = false; 1965 RootPart.PhysActor.PIDActive = false;
1614 } 1966 }
1615 1967
1968 public void rotLookAt(Quaternion target, float strength, float damping)
1969 {
1970 SceneObjectPart rootpart = m_rootPart;
1971 if (rootpart != null)
1972 {
1973 if (IsAttachment)
1974 {
1975 /*
1976 ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar);
1977 if (avatar != null)
1978 {
1979 Rotate the Av?
1980 } */
1981 }
1982 else
1983 {
1984 if (rootpart.PhysActor != null)
1985 { // APID must be implemented in your physics system for this to function.
1986 rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W);
1987 rootpart.PhysActor.APIDStrength = strength;
1988 rootpart.PhysActor.APIDDamping = damping;
1989 rootpart.PhysActor.APIDActive = true;
1990 }
1991 }
1992 }
1993 }
1994
1616 public void stopLookAt() 1995 public void stopLookAt()
1617 { 1996 {
1618 if (RootPart.PhysActor != null) 1997 SceneObjectPart rootpart = m_rootPart;
1619 RootPart.PhysActor.APIDActive = false; 1998 if (rootpart != null)
1999 {
2000 if (rootpart.PhysActor != null)
2001 { // APID must be implemented in your physics system for this to function.
2002 rootpart.PhysActor.APIDActive = false;
2003 }
2004 }
2005
1620 } 2006 }
1621 2007
1622 /// <summary> 2008 /// <summary>
@@ -1674,6 +2060,8 @@ namespace OpenSim.Region.Framework.Scenes
1674 public SceneObjectPart CopyPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed) 2060 public SceneObjectPart CopyPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed)
1675 { 2061 {
1676 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); 2062 SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed);
2063 newPart.SetParent(this);
2064
1677 AddPart(newPart); 2065 AddPart(newPart);
1678 2066
1679 SetPartAsNonRoot(newPart); 2067 SetPartAsNonRoot(newPart);
@@ -1802,11 +2190,11 @@ namespace OpenSim.Region.Framework.Scenes
1802 /// Immediately send a full update for this scene object. 2190 /// Immediately send a full update for this scene object.
1803 /// </summary> 2191 /// </summary>
1804 public void SendGroupFullUpdate() 2192 public void SendGroupFullUpdate()
1805 { 2193 {
1806 if (IsDeleted) 2194 if (IsDeleted)
1807 return; 2195 return;
1808 2196
1809// m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID); 2197// m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID);
1810 2198
1811 RootPart.SendFullUpdateToAllClients(); 2199 RootPart.SendFullUpdateToAllClients();
1812 2200
@@ -2007,7 +2395,7 @@ namespace OpenSim.Region.Framework.Scenes
2007 objectGroup.IsDeleted = true; 2395 objectGroup.IsDeleted = true;
2008 2396
2009 objectGroup.m_parts.Clear(); 2397 objectGroup.m_parts.Clear();
2010 2398
2011 // Can't do this yet since backup still makes use of the root part without any synchronization 2399 // Can't do this yet since backup still makes use of the root part without any synchronization
2012// objectGroup.m_rootPart = null; 2400// objectGroup.m_rootPart = null;
2013 2401
@@ -2141,6 +2529,7 @@ namespace OpenSim.Region.Framework.Scenes
2141 /// <param name="objectGroup"></param> 2529 /// <param name="objectGroup"></param>
2142 public virtual void DetachFromBackup() 2530 public virtual void DetachFromBackup()
2143 { 2531 {
2532 m_scene.SceneGraph.FireDetachFromBackup(this);
2144 if (m_isBackedUp && Scene != null) 2533 if (m_isBackedUp && Scene != null)
2145 m_scene.EventManager.OnBackup -= ProcessBackup; 2534 m_scene.EventManager.OnBackup -= ProcessBackup;
2146 2535
@@ -2159,7 +2548,8 @@ namespace OpenSim.Region.Framework.Scenes
2159 2548
2160 axPos *= parentRot; 2549 axPos *= parentRot;
2161 part.OffsetPosition = axPos; 2550 part.OffsetPosition = axPos;
2162 part.GroupPosition = oldGroupPosition + part.OffsetPosition; 2551 Vector3 newPos = oldGroupPosition + part.OffsetPosition;
2552 part.GroupPosition = newPos;
2163 part.OffsetPosition = Vector3.Zero; 2553 part.OffsetPosition = Vector3.Zero;
2164 part.RotationOffset = worldRot; 2554 part.RotationOffset = worldRot;
2165 2555
@@ -2170,7 +2560,7 @@ namespace OpenSim.Region.Framework.Scenes
2170 2560
2171 part.LinkNum = linkNum; 2561 part.LinkNum = linkNum;
2172 2562
2173 part.OffsetPosition = part.GroupPosition - AbsolutePosition; 2563 part.OffsetPosition = newPos - AbsolutePosition;
2174 2564
2175 Quaternion rootRotation = m_rootPart.RotationOffset; 2565 Quaternion rootRotation = m_rootPart.RotationOffset;
2176 2566
@@ -2180,7 +2570,7 @@ namespace OpenSim.Region.Framework.Scenes
2180 2570
2181 parentRot = m_rootPart.RotationOffset; 2571 parentRot = m_rootPart.RotationOffset;
2182 oldRot = part.RotationOffset; 2572 oldRot = part.RotationOffset;
2183 Quaternion newRot = Quaternion.Inverse(parentRot) * oldRot; 2573 Quaternion newRot = Quaternion.Inverse(parentRot) * worldRot;
2184 part.RotationOffset = newRot; 2574 part.RotationOffset = newRot;
2185 } 2575 }
2186 2576
@@ -2427,8 +2817,12 @@ namespace OpenSim.Region.Framework.Scenes
2427 } 2817 }
2428 } 2818 }
2429 2819
2820 RootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect);
2430 for (int i = 0; i < parts.Length; i++) 2821 for (int i = 0; i < parts.Length; i++)
2431 parts[i].UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect); 2822 {
2823 if (parts[i] != RootPart)
2824 parts[i].UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect);
2825 }
2432 } 2826 }
2433 } 2827 }
2434 2828
@@ -2441,6 +2835,17 @@ namespace OpenSim.Region.Framework.Scenes
2441 } 2835 }
2442 } 2836 }
2443 2837
2838
2839
2840 /// <summary>
2841 /// Gets the number of parts
2842 /// </summary>
2843 /// <returns></returns>
2844 public int GetPartCount()
2845 {
2846 return Parts.Count();
2847 }
2848
2444 /// <summary> 2849 /// <summary>
2445 /// Update the texture entry for this part 2850 /// Update the texture entry for this part
2446 /// </summary> 2851 /// </summary>
@@ -2502,7 +2907,6 @@ namespace OpenSim.Region.Framework.Scenes
2502 { 2907 {
2503// m_log.DebugFormat( 2908// m_log.DebugFormat(
2504// "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, scale); 2909// "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, scale);
2505
2506 RootPart.StoreUndoState(true); 2910 RootPart.StoreUndoState(true);
2507 2911
2508 scale.X = Math.Min(scale.X, Scene.m_maxNonphys); 2912 scale.X = Math.Min(scale.X, Scene.m_maxNonphys);
@@ -2603,7 +3007,6 @@ namespace OpenSim.Region.Framework.Scenes
2603 prevScale.X *= x; 3007 prevScale.X *= x;
2604 prevScale.Y *= y; 3008 prevScale.Y *= y;
2605 prevScale.Z *= z; 3009 prevScale.Z *= z;
2606
2607// RootPart.IgnoreUndoUpdate = true; 3010// RootPart.IgnoreUndoUpdate = true;
2608 RootPart.Resize(prevScale); 3011 RootPart.Resize(prevScale);
2609// RootPart.IgnoreUndoUpdate = false; 3012// RootPart.IgnoreUndoUpdate = false;
@@ -2634,7 +3037,9 @@ namespace OpenSim.Region.Framework.Scenes
2634 } 3037 }
2635 3038
2636// obPart.IgnoreUndoUpdate = false; 3039// obPart.IgnoreUndoUpdate = false;
2637// obPart.StoreUndoState(); 3040 HasGroupChanged = true;
3041 m_rootPart.TriggerScriptChangedEvent(Changed.SCALE);
3042 ScheduleGroupForTerseUpdate();
2638 } 3043 }
2639 3044
2640// m_log.DebugFormat( 3045// m_log.DebugFormat(
@@ -2694,9 +3099,9 @@ namespace OpenSim.Region.Framework.Scenes
2694 { 3099 {
2695 SceneObjectPart part = GetChildPart(localID); 3100 SceneObjectPart part = GetChildPart(localID);
2696 3101
2697// SceneObjectPart[] parts = m_parts.GetArray(); 3102 SceneObjectPart[] parts = m_parts.GetArray();
2698// for (int i = 0; i < parts.Length; i++) 3103 for (int i = 0; i < parts.Length; i++)
2699// parts[i].StoreUndoState(); 3104 parts[i].StoreUndoState();
2700 3105
2701 if (part != null) 3106 if (part != null)
2702 { 3107 {
@@ -2752,10 +3157,27 @@ namespace OpenSim.Region.Framework.Scenes
2752 obPart.OffsetPosition = obPart.OffsetPosition + diff; 3157 obPart.OffsetPosition = obPart.OffsetPosition + diff;
2753 } 3158 }
2754 3159
2755 AbsolutePosition = newPos; 3160 //We have to set undoing here because otherwise an undo state will be saved
3161 if (!m_rootPart.Undoing)
3162 {
3163 m_rootPart.Undoing = true;
3164 AbsolutePosition = newPos;
3165 m_rootPart.Undoing = false;
3166 }
3167 else
3168 {
3169 AbsolutePosition = newPos;
3170 }
2756 3171
2757 HasGroupChanged = true; 3172 HasGroupChanged = true;
2758 ScheduleGroupForTerseUpdate(); 3173 if (m_rootPart.Undoing)
3174 {
3175 ScheduleGroupForFullUpdate();
3176 }
3177 else
3178 {
3179 ScheduleGroupForTerseUpdate();
3180 }
2759 } 3181 }
2760 3182
2761 #endregion 3183 #endregion
@@ -2832,10 +3254,7 @@ namespace OpenSim.Region.Framework.Scenes
2832 public void UpdateSingleRotation(Quaternion rot, uint localID) 3254 public void UpdateSingleRotation(Quaternion rot, uint localID)
2833 { 3255 {
2834 SceneObjectPart part = GetChildPart(localID); 3256 SceneObjectPart part = GetChildPart(localID);
2835
2836 SceneObjectPart[] parts = m_parts.GetArray(); 3257 SceneObjectPart[] parts = m_parts.GetArray();
2837 for (int i = 0; i < parts.Length; i++)
2838 parts[i].StoreUndoState();
2839 3258
2840 if (part != null) 3259 if (part != null)
2841 { 3260 {
@@ -2873,7 +3292,16 @@ namespace OpenSim.Region.Framework.Scenes
2873 if (part.UUID == m_rootPart.UUID) 3292 if (part.UUID == m_rootPart.UUID)
2874 { 3293 {
2875 UpdateRootRotation(rot); 3294 UpdateRootRotation(rot);
2876 AbsolutePosition = pos; 3295 if (!m_rootPart.Undoing)
3296 {
3297 m_rootPart.Undoing = true;
3298 AbsolutePosition = pos;
3299 m_rootPart.Undoing = false;
3300 }
3301 else
3302 {
3303 AbsolutePosition = pos;
3304 }
2877 } 3305 }
2878 else 3306 else
2879 { 3307 {
@@ -2897,9 +3325,10 @@ namespace OpenSim.Region.Framework.Scenes
2897 3325
2898 Quaternion axRot = rot; 3326 Quaternion axRot = rot;
2899 Quaternion oldParentRot = m_rootPart.RotationOffset; 3327 Quaternion oldParentRot = m_rootPart.RotationOffset;
2900
2901 m_rootPart.StoreUndoState(); 3328 m_rootPart.StoreUndoState();
2902 m_rootPart.UpdateRotation(rot); 3329
3330 //Don't use UpdateRotation because it schedules an update prematurely
3331 m_rootPart.RotationOffset = rot;
2903 if (m_rootPart.PhysActor != null) 3332 if (m_rootPart.PhysActor != null)
2904 { 3333 {
2905 m_rootPart.PhysActor.Orientation = m_rootPart.RotationOffset; 3334 m_rootPart.PhysActor.Orientation = m_rootPart.RotationOffset;
@@ -2913,15 +3342,17 @@ namespace OpenSim.Region.Framework.Scenes
2913 if (prim.UUID != m_rootPart.UUID) 3342 if (prim.UUID != m_rootPart.UUID)
2914 { 3343 {
2915 prim.IgnoreUndoUpdate = true; 3344 prim.IgnoreUndoUpdate = true;
3345
3346 Quaternion NewRot = oldParentRot * prim.RotationOffset;
3347 NewRot = Quaternion.Inverse(axRot) * NewRot;
3348 prim.RotationOffset = NewRot;
3349
2916 Vector3 axPos = prim.OffsetPosition; 3350 Vector3 axPos = prim.OffsetPosition;
3351
2917 axPos *= oldParentRot; 3352 axPos *= oldParentRot;
2918 axPos *= Quaternion.Inverse(axRot); 3353 axPos *= Quaternion.Inverse(axRot);
2919 prim.OffsetPosition = axPos; 3354 prim.OffsetPosition = axPos;
2920 Quaternion primsRot = prim.RotationOffset; 3355
2921 Quaternion newRot = oldParentRot * primsRot;
2922 newRot = Quaternion.Inverse(axRot) * newRot;
2923 prim.RotationOffset = newRot;
2924 prim.ScheduleTerseUpdate();
2925 prim.IgnoreUndoUpdate = false; 3356 prim.IgnoreUndoUpdate = false;
2926 } 3357 }
2927 } 3358 }
@@ -2935,8 +3366,8 @@ namespace OpenSim.Region.Framework.Scenes
2935//// childpart.StoreUndoState(); 3366//// childpart.StoreUndoState();
2936// } 3367// }
2937// } 3368// }
2938 3369 HasGroupChanged = true;
2939 m_rootPart.ScheduleTerseUpdate(); 3370 ScheduleGroupForFullUpdate();
2940 3371
2941// m_log.DebugFormat( 3372// m_log.DebugFormat(
2942// "[SCENE OBJECT GROUP]: Updated root rotation of {0} {1} to {2}", 3373// "[SCENE OBJECT GROUP]: Updated root rotation of {0} {1} to {2}",
@@ -3164,7 +3595,6 @@ namespace OpenSim.Region.Framework.Scenes
3164 public float GetMass() 3595 public float GetMass()
3165 { 3596 {
3166 float retmass = 0f; 3597 float retmass = 0f;
3167
3168 SceneObjectPart[] parts = m_parts.GetArray(); 3598 SceneObjectPart[] parts = m_parts.GetArray();
3169 for (int i = 0; i < parts.Length; i++) 3599 for (int i = 0; i < parts.Length; i++)
3170 retmass += parts[i].GetMass(); 3600 retmass += parts[i].GetMass();
@@ -3260,6 +3690,14 @@ namespace OpenSim.Region.Framework.Scenes
3260 SetFromItemID(uuid); 3690 SetFromItemID(uuid);
3261 } 3691 }
3262 3692
3693 public void ResetOwnerChangeFlag()
3694 {
3695 ForEachPart(delegate(SceneObjectPart part)
3696 {
3697 part.ResetOwnerChangeFlag();
3698 });
3699 }
3700
3263 #endregion 3701 #endregion
3264 } 3702 }
3265} 3703}