diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs | 1438 |
1 files changed, 1204 insertions, 234 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index 15795e5..0f5d116 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs | |||
@@ -24,12 +24,13 @@ | |||
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 | ||
28 | using System; | 28 | using System; |
29 | using System.ComponentModel; | 29 | using System.ComponentModel; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Drawing; | 31 | using System.Drawing; |
32 | using System.IO; | 32 | using System.IO; |
33 | using System.Diagnostics; | ||
33 | using System.Linq; | 34 | using System.Linq; |
34 | using System.Threading; | 35 | using System.Threading; |
35 | using System.Xml; | 36 | using System.Xml; |
@@ -43,6 +44,7 @@ using OpenSim.Region.Framework.Scenes.Serialization; | |||
43 | 44 | ||
44 | namespace OpenSim.Region.Framework.Scenes | 45 | namespace OpenSim.Region.Framework.Scenes |
45 | { | 46 | { |
47 | |||
46 | [Flags] | 48 | [Flags] |
47 | public enum scriptEvents | 49 | public enum scriptEvents |
48 | { | 50 | { |
@@ -77,14 +79,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
77 | object_rez = 4194304 | 79 | object_rez = 4194304 |
78 | } | 80 | } |
79 | 81 | ||
80 | struct scriptPosTarget | 82 | public struct scriptPosTarget |
81 | { | 83 | { |
82 | public Vector3 targetPos; | 84 | public Vector3 targetPos; |
83 | public float tolerance; | 85 | public float tolerance; |
84 | public uint handle; | 86 | public uint handle; |
85 | } | 87 | } |
86 | 88 | ||
87 | struct scriptRotTarget | 89 | public struct scriptRotTarget |
88 | { | 90 | { |
89 | public Quaternion targetRot; | 91 | public Quaternion targetRot; |
90 | public float tolerance; | 92 | public float tolerance; |
@@ -115,8 +117,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
115 | /// since the group's last persistent backup | 117 | /// since the group's last persistent backup |
116 | /// </summary> | 118 | /// </summary> |
117 | private bool m_hasGroupChanged = false; | 119 | private bool m_hasGroupChanged = false; |
118 | private long timeFirstChanged; | 120 | private long timeFirstChanged = 0; |
119 | private long timeLastChanged; | 121 | private long timeLastChanged = 0; |
122 | private long m_maxPersistTime = 0; | ||
123 | private long m_minPersistTime = 0; | ||
124 | // private Random m_rand; | ||
125 | private List<ScenePresence> m_linkedAvatars = new List<ScenePresence>(); | ||
120 | 126 | ||
121 | /// <summary> | 127 | /// <summary> |
122 | /// This indicates whether the object has changed such that it needs to be repersisted to permenant storage | 128 | /// This indicates whether the object has changed such that it needs to be repersisted to permenant storage |
@@ -133,9 +139,44 @@ namespace OpenSim.Region.Framework.Scenes | |||
133 | { | 139 | { |
134 | if (value) | 140 | if (value) |
135 | { | 141 | { |
142 | |||
143 | if (m_isBackedUp) | ||
144 | { | ||
145 | m_scene.SceneGraph.FireChangeBackup(this); | ||
146 | } | ||
136 | timeLastChanged = DateTime.Now.Ticks; | 147 | timeLastChanged = DateTime.Now.Ticks; |
137 | if (!m_hasGroupChanged) | 148 | if (!m_hasGroupChanged) |
138 | timeFirstChanged = DateTime.Now.Ticks; | 149 | timeFirstChanged = DateTime.Now.Ticks; |
150 | if (m_rootPart != null && m_rootPart.UUID != null && m_scene != null) | ||
151 | { | ||
152 | /* | ||
153 | if (m_rand == null) | ||
154 | { | ||
155 | byte[] val = new byte[16]; | ||
156 | m_rootPart.UUID.ToBytes(val, 0); | ||
157 | m_rand = new Random(BitConverter.ToInt32(val, 0)); | ||
158 | } | ||
159 | */ | ||
160 | if (m_scene.GetRootAgentCount() == 0) | ||
161 | { | ||
162 | //If the region is empty, this change has been made by an automated process | ||
163 | //and thus we delay the persist time by a random amount between 1.5 and 2.5. | ||
164 | |||
165 | // float factor = 1.5f + (float)(m_rand.NextDouble()); | ||
166 | float factor = 2.0f; | ||
167 | m_maxPersistTime = (long)((float)m_scene.m_persistAfter * factor); | ||
168 | m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * factor); | ||
169 | } | ||
170 | else | ||
171 | { | ||
172 | //If the region is not empty, we want to obey the minimum and maximum persist times | ||
173 | //but add a random factor so we stagger the object persistance a little | ||
174 | // m_maxPersistTime = (long)((float)m_scene.m_persistAfter * (1.0d - (m_rand.NextDouble() / 5.0d))); //Multiply by 1.0-1.5 | ||
175 | // m_minPersistTime = (long)((float)m_scene.m_dontPersistBefore * (1.0d + (m_rand.NextDouble() / 2.0d))); //Multiply by 0.8-1.0 | ||
176 | m_maxPersistTime = m_scene.m_persistAfter; | ||
177 | m_minPersistTime = m_scene.m_dontPersistBefore; | ||
178 | } | ||
179 | } | ||
139 | } | 180 | } |
140 | m_hasGroupChanged = value; | 181 | m_hasGroupChanged = value; |
141 | 182 | ||
@@ -150,7 +191,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
150 | /// Has the group changed due to an unlink operation? We record this in order to optimize deletion, since | 191 | /// Has the group changed due to an unlink operation? We record this in order to optimize deletion, since |
151 | /// an unlinked group currently has to be persisted to the database before we can perform an unlink operation. | 192 | /// an unlinked group currently has to be persisted to the database before we can perform an unlink operation. |
152 | /// </summary> | 193 | /// </summary> |
153 | public bool HasGroupChangedDueToDelink { get; private set; } | 194 | public bool HasGroupChangedDueToDelink { get; set; } |
154 | 195 | ||
155 | private bool isTimeToPersist() | 196 | private bool isTimeToPersist() |
156 | { | 197 | { |
@@ -160,8 +201,19 @@ namespace OpenSim.Region.Framework.Scenes | |||
160 | return false; | 201 | return false; |
161 | if (m_scene.ShuttingDown) | 202 | if (m_scene.ShuttingDown) |
162 | return true; | 203 | return true; |
204 | |||
205 | if (m_minPersistTime == 0 || m_maxPersistTime == 0) | ||
206 | { | ||
207 | m_maxPersistTime = m_scene.m_persistAfter; | ||
208 | m_minPersistTime = m_scene.m_dontPersistBefore; | ||
209 | } | ||
210 | |||
163 | long currentTime = DateTime.Now.Ticks; | 211 | long currentTime = DateTime.Now.Ticks; |
164 | if (currentTime - timeLastChanged > m_scene.m_dontPersistBefore || currentTime - timeFirstChanged > m_scene.m_persistAfter) | 212 | |
213 | if (timeLastChanged == 0) timeLastChanged = currentTime; | ||
214 | if (timeFirstChanged == 0) timeFirstChanged = currentTime; | ||
215 | |||
216 | if (currentTime - timeLastChanged > m_minPersistTime || currentTime - timeFirstChanged > m_maxPersistTime) | ||
165 | return true; | 217 | return true; |
166 | return false; | 218 | return false; |
167 | } | 219 | } |
@@ -264,26 +316,38 @@ namespace OpenSim.Region.Framework.Scenes | |||
264 | get { return RootPart.VolumeDetectActive; } | 316 | get { return RootPart.VolumeDetectActive; } |
265 | } | 317 | } |
266 | 318 | ||
267 | private Vector3 lastPhysGroupPos; | ||
268 | private Quaternion lastPhysGroupRot; | ||
269 | |||
270 | private bool m_isBackedUp; | 319 | private bool m_isBackedUp; |
271 | 320 | ||
321 | public bool IsBackedUp | ||
322 | { | ||
323 | get { return m_isBackedUp; } | ||
324 | } | ||
325 | |||
272 | protected MapAndArray<UUID, SceneObjectPart> m_parts = new MapAndArray<UUID, SceneObjectPart>(); | 326 | protected MapAndArray<UUID, SceneObjectPart> m_parts = new MapAndArray<UUID, SceneObjectPart>(); |
273 | 327 | ||
274 | protected ulong m_regionHandle; | 328 | protected ulong m_regionHandle; |
275 | protected SceneObjectPart m_rootPart; | 329 | protected SceneObjectPart m_rootPart; |
276 | // private Dictionary<UUID, scriptEvents> m_scriptEvents = new Dictionary<UUID, scriptEvents>(); | 330 | // private Dictionary<UUID, scriptEvents> m_scriptEvents = new Dictionary<UUID, scriptEvents>(); |
277 | 331 | ||
278 | private Dictionary<uint, scriptPosTarget> m_targets = new Dictionary<uint, scriptPosTarget>(); | 332 | private SortedDictionary<uint, scriptPosTarget> m_targets = new SortedDictionary<uint, scriptPosTarget>(); |
279 | private Dictionary<uint, scriptRotTarget> m_rotTargets = new Dictionary<uint, scriptRotTarget>(); | 333 | private SortedDictionary<uint, scriptRotTarget> m_rotTargets = new SortedDictionary<uint, scriptRotTarget>(); |
334 | |||
335 | public SortedDictionary<uint, scriptPosTarget> AtTargets | ||
336 | { | ||
337 | get { return m_targets; } | ||
338 | } | ||
339 | |||
340 | public SortedDictionary<uint, scriptRotTarget> RotTargets | ||
341 | { | ||
342 | get { return m_rotTargets; } | ||
343 | } | ||
280 | 344 | ||
281 | private bool m_scriptListens_atTarget; | 345 | private bool m_scriptListens_atTarget; |
282 | private bool m_scriptListens_notAtTarget; | 346 | private bool m_scriptListens_notAtTarget; |
283 | |||
284 | private bool m_scriptListens_atRotTarget; | 347 | private bool m_scriptListens_atRotTarget; |
285 | private bool m_scriptListens_notAtRotTarget; | 348 | private bool m_scriptListens_notAtRotTarget; |
286 | 349 | ||
350 | public bool m_dupeInProgress = false; | ||
287 | internal Dictionary<UUID, string> m_savedScriptState; | 351 | internal Dictionary<UUID, string> m_savedScriptState; |
288 | 352 | ||
289 | #region Properties | 353 | #region Properties |
@@ -320,6 +384,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
320 | get { return m_parts.Count; } | 384 | get { return m_parts.Count; } |
321 | } | 385 | } |
322 | 386 | ||
387 | // protected Quaternion m_rotation = Quaternion.Identity; | ||
388 | // | ||
389 | // public virtual Quaternion Rotation | ||
390 | // { | ||
391 | // get { return m_rotation; } | ||
392 | // set { | ||
393 | // m_rotation = value; | ||
394 | // } | ||
395 | // } | ||
396 | |||
323 | public Quaternion GroupRotation | 397 | public Quaternion GroupRotation |
324 | { | 398 | { |
325 | get { return m_rootPart.RotationOffset; } | 399 | get { return m_rootPart.RotationOffset; } |
@@ -426,7 +500,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
426 | { | 500 | { |
427 | return (IsAttachment || (m_rootPart.Shape.PCode == 9 && m_rootPart.Shape.State != 0)); | 501 | return (IsAttachment || (m_rootPart.Shape.PCode == 9 && m_rootPart.Shape.State != 0)); |
428 | } | 502 | } |
429 | 503 | ||
504 | |||
505 | |||
506 | private struct avtocrossInfo | ||
507 | { | ||
508 | public ScenePresence av; | ||
509 | public uint ParentID; | ||
510 | } | ||
511 | |||
430 | /// <summary> | 512 | /// <summary> |
431 | /// The absolute position of this scene object in the scene | 513 | /// The absolute position of this scene object in the scene |
432 | /// </summary> | 514 | /// </summary> |
@@ -454,10 +536,129 @@ namespace OpenSim.Region.Framework.Scenes | |||
454 | || Scene.TestBorderCross(val, Cardinals.S)) | 536 | || Scene.TestBorderCross(val, Cardinals.S)) |
455 | && !IsAttachmentCheckFull() && (!Scene.LoadingPrims)) | 537 | && !IsAttachmentCheckFull() && (!Scene.LoadingPrims)) |
456 | { | 538 | { |
457 | m_scene.CrossPrimGroupIntoNewRegion(val, this, true); | 539 | IEntityTransferModule entityTransfer = m_scene.RequestModuleInterface<IEntityTransferModule>(); |
540 | uint x = 0; | ||
541 | uint y = 0; | ||
542 | string version = String.Empty; | ||
543 | Vector3 newpos = Vector3.Zero; | ||
544 | OpenSim.Services.Interfaces.GridRegion destination = null; | ||
545 | |||
546 | if (m_rootPart.KeyframeMotion != null) | ||
547 | m_rootPart.KeyframeMotion.StartCrossingCheck(); | ||
548 | |||
549 | bool canCross = true; | ||
550 | foreach (ScenePresence av in m_linkedAvatars) | ||
551 | { | ||
552 | // We need to cross these agents. First, let's find | ||
553 | // out if any of them can't cross for some reason. | ||
554 | // We have to deny the crossing entirely if any | ||
555 | // of them are banned. Alternatively, we could | ||
556 | // unsit banned agents.... | ||
557 | |||
558 | |||
559 | // We set the avatar position as being the object | ||
560 | // position to get the region to send to | ||
561 | if ((destination = entityTransfer.GetDestination(m_scene, av.UUID, val, out x, out y, out version, out newpos)) == null) | ||
562 | { | ||
563 | canCross = false; | ||
564 | break; | ||
565 | } | ||
566 | |||
567 | m_log.DebugFormat("[SCENE OBJECT]: Avatar {0} needs to be crossed to {1}", av.Name, destination.RegionName); | ||
568 | } | ||
569 | |||
570 | if (canCross) | ||
571 | { | ||
572 | // We unparent the SP quietly so that it won't | ||
573 | // be made to stand up | ||
574 | |||
575 | List<avtocrossInfo> avsToCross = new List<avtocrossInfo>(); | ||
576 | |||
577 | foreach (ScenePresence av in m_linkedAvatars) | ||
578 | { | ||
579 | avtocrossInfo avinfo = new avtocrossInfo(); | ||
580 | SceneObjectPart parentPart = m_scene.GetSceneObjectPart(av.ParentID); | ||
581 | if (parentPart != null) | ||
582 | av.ParentUUID = parentPart.UUID; | ||
583 | |||
584 | avinfo.av = av; | ||
585 | avinfo.ParentID = av.ParentID; | ||
586 | avsToCross.Add(avinfo); | ||
587 | |||
588 | av.ParentID = 0; | ||
589 | } | ||
590 | |||
591 | // m_linkedAvatars.Clear(); | ||
592 | m_scene.CrossPrimGroupIntoNewRegion(val, this, true); | ||
593 | |||
594 | // Normalize | ||
595 | if (val.X >= Constants.RegionSize) | ||
596 | val.X -= Constants.RegionSize; | ||
597 | if (val.Y >= Constants.RegionSize) | ||
598 | val.Y -= Constants.RegionSize; | ||
599 | if (val.X < 0) | ||
600 | val.X += Constants.RegionSize; | ||
601 | if (val.Y < 0) | ||
602 | val.Y += Constants.RegionSize; | ||
603 | |||
604 | // If it's deleted, crossing was successful | ||
605 | if (IsDeleted) | ||
606 | { | ||
607 | // foreach (ScenePresence av in m_linkedAvatars) | ||
608 | foreach (avtocrossInfo avinfo in avsToCross) | ||
609 | { | ||
610 | ScenePresence av = avinfo.av; | ||
611 | if (!av.IsInTransit) // just in case... | ||
612 | { | ||
613 | m_log.DebugFormat("[SCENE OBJECT]: Crossing avatar {0} to {1}", av.Name, val); | ||
614 | |||
615 | av.IsInTransit = true; | ||
616 | |||
617 | CrossAgentToNewRegionDelegate d = entityTransfer.CrossAgentToNewRegionAsync; | ||
618 | d.BeginInvoke(av, val, destination, av.Flying, version, CrossAgentToNewRegionCompleted, d); | ||
619 | } | ||
620 | else | ||
621 | m_log.DebugFormat("[SCENE OBJECT]: Crossing avatar alreasy in transit {0} to {1}", av.Name, val); | ||
622 | } | ||
623 | avsToCross.Clear(); | ||
624 | return; | ||
625 | } | ||
626 | else // cross failed, put avas back ?? | ||
627 | { | ||
628 | foreach (avtocrossInfo avinfo in avsToCross) | ||
629 | { | ||
630 | ScenePresence av = avinfo.av; | ||
631 | av.ParentUUID = UUID.Zero; | ||
632 | av.ParentID = avinfo.ParentID; | ||
633 | // m_linkedAvatars.Add(av); | ||
634 | } | ||
635 | } | ||
636 | avsToCross.Clear(); | ||
637 | |||
638 | } | ||
639 | else | ||
640 | { | ||
641 | if (m_rootPart.KeyframeMotion != null) | ||
642 | m_rootPart.KeyframeMotion.CrossingFailure(); | ||
643 | |||
644 | if (RootPart.PhysActor != null) | ||
645 | { | ||
646 | RootPart.PhysActor.CrossingFailure(); | ||
647 | } | ||
648 | } | ||
649 | Vector3 oldp = AbsolutePosition; | ||
650 | val.X = Util.Clamp<float>(oldp.X, 0.5f, (float)Constants.RegionSize - 0.5f); | ||
651 | val.Y = Util.Clamp<float>(oldp.Y, 0.5f, (float)Constants.RegionSize - 0.5f); | ||
652 | val.Z = Util.Clamp<float>(oldp.Z, 0.5f, 4096.0f); | ||
458 | } | 653 | } |
459 | } | 654 | } |
460 | 655 | ||
656 | /* don't see the need but worse don't see where is restored to false if things stay in | ||
657 | foreach (SceneObjectPart part in m_parts.GetArray()) | ||
658 | { | ||
659 | part.IgnoreUndoUpdate = true; | ||
660 | } | ||
661 | */ | ||
461 | if (RootPart.GetStatusSandbox()) | 662 | if (RootPart.GetStatusSandbox()) |
462 | { | 663 | { |
463 | if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10) | 664 | if (Util.GetDistanceTo(RootPart.StatusSandboxPos, value) > 10) |
@@ -475,9 +676,38 @@ namespace OpenSim.Region.Framework.Scenes | |||
475 | // Restuff the new GroupPosition into each SOP of the linkset. | 676 | // Restuff the new GroupPosition into each SOP of the linkset. |
476 | // This has the affect of resetting and tainting the physics actors. | 677 | // This has the affect of resetting and tainting the physics actors. |
477 | SceneObjectPart[] parts = m_parts.GetArray(); | 678 | SceneObjectPart[] parts = m_parts.GetArray(); |
478 | for (int i = 0; i < parts.Length; i++) | 679 | bool triggerScriptEvent = m_rootPart.GroupPosition != val; |
479 | parts[i].GroupPosition = val; | 680 | if (m_dupeInProgress) |
681 | triggerScriptEvent = false; | ||
682 | foreach (SceneObjectPart part in parts) | ||
683 | { | ||
684 | part.GroupPosition = val; | ||
685 | if (triggerScriptEvent) | ||
686 | part.TriggerScriptChangedEvent(Changed.POSITION); | ||
687 | } | ||
480 | 688 | ||
689 | /* | ||
690 | This seems not needed and should not be needed: | ||
691 | sp absolute position depends on sit part absolute position fixed above. | ||
692 | sp ParentPosition is not used anywhere. | ||
693 | Since presence is sitting, viewer considers it 'linked' to root prim, so it will move/rotate it | ||
694 | Sending a extra packet with avatar position is not only bandwidth waste, but may cause jitter in viewers due to UPD nature. | ||
695 | |||
696 | if (!m_dupeInProgress) | ||
697 | { | ||
698 | foreach (ScenePresence av in m_linkedAvatars) | ||
699 | { | ||
700 | SceneObjectPart p = m_scene.GetSceneObjectPart(av.ParentID); | ||
701 | if (p != null && m_parts.TryGetValue(p.UUID, out p)) | ||
702 | { | ||
703 | Vector3 offset = p.GetWorldPosition() - av.ParentPosition; | ||
704 | av.AbsolutePosition += offset; | ||
705 | // av.ParentPosition = p.GetWorldPosition(); //ParentPosition gets cleared by AbsolutePosition | ||
706 | av.SendAvatarDataToAllAgents(); | ||
707 | } | ||
708 | } | ||
709 | } | ||
710 | */ | ||
481 | //if (m_rootPart.PhysActor != null) | 711 | //if (m_rootPart.PhysActor != null) |
482 | //{ | 712 | //{ |
483 | //m_rootPart.PhysActor.Position = | 713 | //m_rootPart.PhysActor.Position = |
@@ -491,6 +721,40 @@ namespace OpenSim.Region.Framework.Scenes | |||
491 | } | 721 | } |
492 | } | 722 | } |
493 | 723 | ||
724 | public override Vector3 Velocity | ||
725 | { | ||
726 | get { return RootPart.Velocity; } | ||
727 | set { RootPart.Velocity = value; } | ||
728 | } | ||
729 | |||
730 | private void CrossAgentToNewRegionCompleted(IAsyncResult iar) | ||
731 | { | ||
732 | CrossAgentToNewRegionDelegate icon = (CrossAgentToNewRegionDelegate)iar.AsyncState; | ||
733 | ScenePresence agent = icon.EndInvoke(iar); | ||
734 | |||
735 | //// If the cross was successful, this agent is a child agent | ||
736 | if (agent.IsChildAgent) | ||
737 | { | ||
738 | if (agent.ParentUUID != UUID.Zero) | ||
739 | { | ||
740 | agent.ParentPart = null; | ||
741 | // agent.ParentPosition = Vector3.Zero; | ||
742 | // agent.ParentUUID = UUID.Zero; | ||
743 | } | ||
744 | } | ||
745 | |||
746 | agent.ParentUUID = UUID.Zero; | ||
747 | |||
748 | // agent.Reset(); | ||
749 | // else // Not successful | ||
750 | // agent.RestoreInCurrentScene(); | ||
751 | |||
752 | // In any case | ||
753 | agent.IsInTransit = false; | ||
754 | |||
755 | m_log.DebugFormat("[SCENE OBJECT]: Crossing agent {0} {1} completed.", agent.Firstname, agent.Lastname); | ||
756 | } | ||
757 | |||
494 | public override uint LocalId | 758 | public override uint LocalId |
495 | { | 759 | { |
496 | get { return m_rootPart.LocalId; } | 760 | get { return m_rootPart.LocalId; } |
@@ -561,6 +825,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
561 | m_isSelected = value; | 825 | m_isSelected = value; |
562 | // Tell physics engine that group is selected | 826 | // Tell physics engine that group is selected |
563 | 827 | ||
828 | // this is not right | ||
829 | // but ode engines should only really need to know about root part | ||
830 | // so they can put entire object simulation on hold and not colliding | ||
831 | // keep as was for now | ||
832 | |||
564 | PhysicsActor pa = m_rootPart.PhysActor; | 833 | PhysicsActor pa = m_rootPart.PhysActor; |
565 | if (pa != null) | 834 | if (pa != null) |
566 | { | 835 | { |
@@ -577,6 +846,42 @@ namespace OpenSim.Region.Framework.Scenes | |||
577 | childPa.Selected = value; | 846 | childPa.Selected = value; |
578 | } | 847 | } |
579 | } | 848 | } |
849 | if (RootPart.KeyframeMotion != null) | ||
850 | RootPart.KeyframeMotion.Selected = value; | ||
851 | } | ||
852 | } | ||
853 | |||
854 | public void PartSelectChanged(bool partSelect) | ||
855 | { | ||
856 | // any part selected makes group selected | ||
857 | if (m_isSelected == partSelect) | ||
858 | return; | ||
859 | |||
860 | if (partSelect) | ||
861 | { | ||
862 | IsSelected = partSelect; | ||
863 | // if (!IsAttachment) | ||
864 | // ScheduleGroupForFullUpdate(); | ||
865 | } | ||
866 | else | ||
867 | { | ||
868 | // bad bad bad 2 heavy for large linksets | ||
869 | // since viewer does send lot of (un)selects | ||
870 | // this needs to be replaced by a specific list or count ? | ||
871 | // but that will require extra code in several places | ||
872 | |||
873 | SceneObjectPart[] parts = m_parts.GetArray(); | ||
874 | for (int i = 0; i < parts.Length; i++) | ||
875 | { | ||
876 | SceneObjectPart part = parts[i]; | ||
877 | if (part.IsSelected) | ||
878 | return; | ||
879 | } | ||
880 | IsSelected = partSelect; | ||
881 | if (!IsAttachment) | ||
882 | { | ||
883 | ScheduleGroupForFullUpdate(); | ||
884 | } | ||
580 | } | 885 | } |
581 | } | 886 | } |
582 | 887 | ||
@@ -674,6 +979,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
674 | /// </summary> | 979 | /// </summary> |
675 | public SceneObjectGroup() | 980 | public SceneObjectGroup() |
676 | { | 981 | { |
982 | |||
677 | } | 983 | } |
678 | 984 | ||
679 | /// <summary> | 985 | /// <summary> |
@@ -691,8 +997,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
691 | /// Constructor. This object is added to the scene later via AttachToScene() | 997 | /// Constructor. This object is added to the scene later via AttachToScene() |
692 | /// </summary> | 998 | /// </summary> |
693 | public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape) | 999 | public SceneObjectGroup(UUID ownerID, Vector3 pos, Quaternion rot, PrimitiveBaseShape shape) |
694 | :this(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero)) | 1000 | { |
695 | { | 1001 | SetRootPart(new SceneObjectPart(ownerID, shape, pos, rot, Vector3.Zero)); |
696 | } | 1002 | } |
697 | 1003 | ||
698 | /// <summary> | 1004 | /// <summary> |
@@ -727,6 +1033,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
727 | /// </summary> | 1033 | /// </summary> |
728 | public virtual void AttachToBackup() | 1034 | public virtual void AttachToBackup() |
729 | { | 1035 | { |
1036 | if (IsAttachment) return; | ||
1037 | m_scene.SceneGraph.FireAttachToBackup(this); | ||
1038 | |||
730 | if (InSceneBackup) | 1039 | if (InSceneBackup) |
731 | { | 1040 | { |
732 | //m_log.DebugFormat( | 1041 | //m_log.DebugFormat( |
@@ -769,6 +1078,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
769 | 1078 | ||
770 | ApplyPhysics(); | 1079 | ApplyPhysics(); |
771 | 1080 | ||
1081 | if (RootPart.PhysActor != null) | ||
1082 | RootPart.Force = RootPart.Force; | ||
1083 | if (RootPart.PhysActor != null) | ||
1084 | RootPart.Torque = RootPart.Torque; | ||
1085 | if (RootPart.PhysActor != null) | ||
1086 | RootPart.Buoyancy = RootPart.Buoyancy; | ||
1087 | |||
772 | // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled | 1088 | // Don't trigger the update here - otherwise some client issues occur when multiple updates are scheduled |
773 | // for the same object with very different properties. The caller must schedule the update. | 1089 | // for the same object with very different properties. The caller must schedule the update. |
774 | //ScheduleGroupForFullUpdate(); | 1090 | //ScheduleGroupForFullUpdate(); |
@@ -784,6 +1100,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
784 | EntityIntersection result = new EntityIntersection(); | 1100 | EntityIntersection result = new EntityIntersection(); |
785 | 1101 | ||
786 | SceneObjectPart[] parts = m_parts.GetArray(); | 1102 | SceneObjectPart[] parts = m_parts.GetArray(); |
1103 | |||
1104 | // Find closest hit here | ||
1105 | float idist = float.MaxValue; | ||
1106 | |||
787 | for (int i = 0; i < parts.Length; i++) | 1107 | for (int i = 0; i < parts.Length; i++) |
788 | { | 1108 | { |
789 | SceneObjectPart part = parts[i]; | 1109 | SceneObjectPart part = parts[i]; |
@@ -798,11 +1118,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
798 | 1118 | ||
799 | EntityIntersection inter = part.TestIntersectionOBB(hRay, parentrotation, frontFacesOnly, faceCenters); | 1119 | EntityIntersection inter = part.TestIntersectionOBB(hRay, parentrotation, frontFacesOnly, faceCenters); |
800 | 1120 | ||
801 | // This may need to be updated to the maximum draw distance possible.. | ||
802 | // We might (and probably will) be checking for prim creation from other sims | ||
803 | // when the camera crosses the border. | ||
804 | float idist = Constants.RegionSize; | ||
805 | |||
806 | if (inter.HitTF) | 1121 | if (inter.HitTF) |
807 | { | 1122 | { |
808 | // We need to find the closest prim to return to the testcaller along the ray | 1123 | // We need to find the closest prim to return to the testcaller along the ray |
@@ -813,10 +1128,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
813 | result.obj = part; | 1128 | result.obj = part; |
814 | result.normal = inter.normal; | 1129 | result.normal = inter.normal; |
815 | result.distance = inter.distance; | 1130 | result.distance = inter.distance; |
1131 | |||
1132 | idist = inter.distance; | ||
816 | } | 1133 | } |
817 | } | 1134 | } |
818 | } | 1135 | } |
819 | |||
820 | return result; | 1136 | return result; |
821 | } | 1137 | } |
822 | 1138 | ||
@@ -828,25 +1144,27 @@ namespace OpenSim.Region.Framework.Scenes | |||
828 | /// <returns></returns> | 1144 | /// <returns></returns> |
829 | public void GetAxisAlignedBoundingBoxRaw(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ) | 1145 | public void GetAxisAlignedBoundingBoxRaw(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ) |
830 | { | 1146 | { |
831 | maxX = -256f; | 1147 | maxX = float.MinValue; |
832 | maxY = -256f; | 1148 | maxY = float.MinValue; |
833 | maxZ = -256f; | 1149 | maxZ = float.MinValue; |
834 | minX = 256f; | 1150 | minX = float.MaxValue; |
835 | minY = 256f; | 1151 | minY = float.MaxValue; |
836 | minZ = 8192f; | 1152 | minZ = float.MaxValue; |
837 | 1153 | ||
838 | SceneObjectPart[] parts = m_parts.GetArray(); | 1154 | SceneObjectPart[] parts = m_parts.GetArray(); |
839 | for (int i = 0; i < parts.Length; i++) | 1155 | foreach (SceneObjectPart part in parts) |
840 | { | 1156 | { |
841 | SceneObjectPart part = parts[i]; | ||
842 | |||
843 | Vector3 worldPos = part.GetWorldPosition(); | 1157 | Vector3 worldPos = part.GetWorldPosition(); |
844 | Vector3 offset = worldPos - AbsolutePosition; | 1158 | Vector3 offset = worldPos - AbsolutePosition; |
845 | Quaternion worldRot; | 1159 | Quaternion worldRot; |
846 | if (part.ParentID == 0) | 1160 | if (part.ParentID == 0) |
1161 | { | ||
847 | worldRot = part.RotationOffset; | 1162 | worldRot = part.RotationOffset; |
1163 | } | ||
848 | else | 1164 | else |
1165 | { | ||
849 | worldRot = part.GetWorldRotation(); | 1166 | worldRot = part.GetWorldRotation(); |
1167 | } | ||
850 | 1168 | ||
851 | Vector3 frontTopLeft; | 1169 | Vector3 frontTopLeft; |
852 | Vector3 frontTopRight; | 1170 | Vector3 frontTopRight; |
@@ -858,6 +1176,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
858 | Vector3 backBottomLeft; | 1176 | Vector3 backBottomLeft; |
859 | Vector3 backBottomRight; | 1177 | Vector3 backBottomRight; |
860 | 1178 | ||
1179 | // Vector3[] corners = new Vector3[8]; | ||
1180 | |||
861 | Vector3 orig = Vector3.Zero; | 1181 | Vector3 orig = Vector3.Zero; |
862 | 1182 | ||
863 | frontTopLeft.X = orig.X - (part.Scale.X / 2); | 1183 | frontTopLeft.X = orig.X - (part.Scale.X / 2); |
@@ -892,6 +1212,38 @@ namespace OpenSim.Region.Framework.Scenes | |||
892 | backBottomRight.Y = orig.Y + (part.Scale.Y / 2); | 1212 | backBottomRight.Y = orig.Y + (part.Scale.Y / 2); |
893 | backBottomRight.Z = orig.Z - (part.Scale.Z / 2); | 1213 | backBottomRight.Z = orig.Z - (part.Scale.Z / 2); |
894 | 1214 | ||
1215 | |||
1216 | |||
1217 | //m_log.InfoFormat("pre corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z); | ||
1218 | //m_log.InfoFormat("pre corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z); | ||
1219 | //m_log.InfoFormat("pre corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z); | ||
1220 | //m_log.InfoFormat("pre corner 4 is {0} {1} {2}", frontBottomLeft.X, frontBottomLeft.Y, frontBottomLeft.Z); | ||
1221 | //m_log.InfoFormat("pre corner 5 is {0} {1} {2}", backTopLeft.X, backTopLeft.Y, backTopLeft.Z); | ||
1222 | //m_log.InfoFormat("pre corner 6 is {0} {1} {2}", backTopRight.X, backTopRight.Y, backTopRight.Z); | ||
1223 | //m_log.InfoFormat("pre corner 7 is {0} {1} {2}", backBottomRight.X, backBottomRight.Y, backBottomRight.Z); | ||
1224 | //m_log.InfoFormat("pre corner 8 is {0} {1} {2}", backBottomLeft.X, backBottomLeft.Y, backBottomLeft.Z); | ||
1225 | |||
1226 | //for (int i = 0; i < 8; i++) | ||
1227 | //{ | ||
1228 | // corners[i] = corners[i] * worldRot; | ||
1229 | // corners[i] += offset; | ||
1230 | |||
1231 | // if (corners[i].X > maxX) | ||
1232 | // maxX = corners[i].X; | ||
1233 | // if (corners[i].X < minX) | ||
1234 | // minX = corners[i].X; | ||
1235 | |||
1236 | // if (corners[i].Y > maxY) | ||
1237 | // maxY = corners[i].Y; | ||
1238 | // if (corners[i].Y < minY) | ||
1239 | // minY = corners[i].Y; | ||
1240 | |||
1241 | // if (corners[i].Z > maxZ) | ||
1242 | // maxZ = corners[i].Y; | ||
1243 | // if (corners[i].Z < minZ) | ||
1244 | // minZ = corners[i].Z; | ||
1245 | //} | ||
1246 | |||
895 | frontTopLeft = frontTopLeft * worldRot; | 1247 | frontTopLeft = frontTopLeft * worldRot; |
896 | frontTopRight = frontTopRight * worldRot; | 1248 | frontTopRight = frontTopRight * worldRot; |
897 | frontBottomLeft = frontBottomLeft * worldRot; | 1249 | frontBottomLeft = frontBottomLeft * worldRot; |
@@ -913,6 +1265,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
913 | backTopLeft += offset; | 1265 | backTopLeft += offset; |
914 | backTopRight += offset; | 1266 | backTopRight += offset; |
915 | 1267 | ||
1268 | //m_log.InfoFormat("corner 1 is {0} {1} {2}", frontTopLeft.X, frontTopLeft.Y, frontTopLeft.Z); | ||
1269 | //m_log.InfoFormat("corner 2 is {0} {1} {2}", frontTopRight.X, frontTopRight.Y, frontTopRight.Z); | ||
1270 | //m_log.InfoFormat("corner 3 is {0} {1} {2}", frontBottomRight.X, frontBottomRight.Y, frontBottomRight.Z); | ||
1271 | //m_log.InfoFormat("corner 4 is {0} {1} {2}", frontBottomLeft.X, frontBottomLeft.Y, frontBottomLeft.Z); | ||
1272 | //m_log.InfoFormat("corner 5 is {0} {1} {2}", backTopLeft.X, backTopLeft.Y, backTopLeft.Z); | ||
1273 | //m_log.InfoFormat("corner 6 is {0} {1} {2}", backTopRight.X, backTopRight.Y, backTopRight.Z); | ||
1274 | //m_log.InfoFormat("corner 7 is {0} {1} {2}", backBottomRight.X, backBottomRight.Y, backBottomRight.Z); | ||
1275 | //m_log.InfoFormat("corner 8 is {0} {1} {2}", backBottomLeft.X, backBottomLeft.Y, backBottomLeft.Z); | ||
1276 | |||
916 | if (frontTopRight.X > maxX) | 1277 | if (frontTopRight.X > maxX) |
917 | maxX = frontTopRight.X; | 1278 | maxX = frontTopRight.X; |
918 | if (frontTopLeft.X > maxX) | 1279 | if (frontTopLeft.X > maxX) |
@@ -1056,17 +1417,118 @@ namespace OpenSim.Region.Framework.Scenes | |||
1056 | 1417 | ||
1057 | #endregion | 1418 | #endregion |
1058 | 1419 | ||
1420 | public void GetResourcesCosts(SceneObjectPart apart, | ||
1421 | out float linksetResCost, out float linksetPhysCost, out float partCost, out float partPhysCost) | ||
1422 | { | ||
1423 | // this information may need to be cached | ||
1424 | |||
1425 | float cost; | ||
1426 | float tmpcost; | ||
1427 | |||
1428 | bool ComplexCost = false; | ||
1429 | |||
1430 | SceneObjectPart p; | ||
1431 | SceneObjectPart[] parts; | ||
1432 | |||
1433 | lock (m_parts) | ||
1434 | { | ||
1435 | parts = m_parts.GetArray(); | ||
1436 | } | ||
1437 | |||
1438 | int nparts = parts.Length; | ||
1439 | |||
1440 | |||
1441 | for (int i = 0; i < nparts; i++) | ||
1442 | { | ||
1443 | p = parts[i]; | ||
1444 | |||
1445 | if (p.UsesComplexCost) | ||
1446 | { | ||
1447 | ComplexCost = true; | ||
1448 | break; | ||
1449 | } | ||
1450 | } | ||
1451 | |||
1452 | if (ComplexCost) | ||
1453 | { | ||
1454 | linksetResCost = 0; | ||
1455 | linksetPhysCost = 0; | ||
1456 | partCost = 0; | ||
1457 | partPhysCost = 0; | ||
1458 | |||
1459 | for (int i = 0; i < nparts; i++) | ||
1460 | { | ||
1461 | p = parts[i]; | ||
1462 | |||
1463 | cost = p.StreamingCost; | ||
1464 | tmpcost = p.SimulationCost; | ||
1465 | if (tmpcost > cost) | ||
1466 | cost = tmpcost; | ||
1467 | tmpcost = p.PhysicsCost; | ||
1468 | if (tmpcost > cost) | ||
1469 | cost = tmpcost; | ||
1470 | |||
1471 | linksetPhysCost += tmpcost; | ||
1472 | linksetResCost += cost; | ||
1473 | |||
1474 | if (p == apart) | ||
1475 | { | ||
1476 | partCost = cost; | ||
1477 | partPhysCost = tmpcost; | ||
1478 | } | ||
1479 | } | ||
1480 | } | ||
1481 | else | ||
1482 | { | ||
1483 | partPhysCost = 1.0f; | ||
1484 | partCost = 1.0f; | ||
1485 | linksetResCost = (float)nparts; | ||
1486 | linksetPhysCost = linksetResCost; | ||
1487 | } | ||
1488 | } | ||
1489 | |||
1490 | public void GetSelectedCosts(out float PhysCost, out float StreamCost, out float SimulCost) | ||
1491 | { | ||
1492 | SceneObjectPart p; | ||
1493 | SceneObjectPart[] parts; | ||
1494 | |||
1495 | lock (m_parts) | ||
1496 | { | ||
1497 | parts = m_parts.GetArray(); | ||
1498 | } | ||
1499 | |||
1500 | int nparts = parts.Length; | ||
1501 | |||
1502 | PhysCost = 0; | ||
1503 | StreamCost = 0; | ||
1504 | SimulCost = 0; | ||
1505 | |||
1506 | for (int i = 0; i < nparts; i++) | ||
1507 | { | ||
1508 | p = parts[i]; | ||
1509 | |||
1510 | StreamCost += p.StreamingCost; | ||
1511 | SimulCost += p.SimulationCost; | ||
1512 | PhysCost += p.PhysicsCost; | ||
1513 | } | ||
1514 | } | ||
1515 | |||
1059 | public void SaveScriptedState(XmlTextWriter writer) | 1516 | public void SaveScriptedState(XmlTextWriter writer) |
1060 | { | 1517 | { |
1518 | SaveScriptedState(writer, false); | ||
1519 | } | ||
1520 | |||
1521 | public void SaveScriptedState(XmlTextWriter writer, bool oldIDs) | ||
1522 | { | ||
1061 | XmlDocument doc = new XmlDocument(); | 1523 | XmlDocument doc = new XmlDocument(); |
1062 | Dictionary<UUID,string> states = new Dictionary<UUID,string>(); | 1524 | Dictionary<UUID,string> states = new Dictionary<UUID,string>(); |
1063 | 1525 | ||
1064 | SceneObjectPart[] parts = m_parts.GetArray(); | 1526 | SceneObjectPart[] parts = m_parts.GetArray(); |
1065 | for (int i = 0; i < parts.Length; i++) | 1527 | for (int i = 0; i < parts.Length; i++) |
1066 | { | 1528 | { |
1067 | Dictionary<UUID, string> pstates = parts[i].Inventory.GetScriptStates(); | 1529 | Dictionary<UUID, string> pstates = parts[i].Inventory.GetScriptStates(oldIDs); |
1068 | foreach (KeyValuePair<UUID, string> kvp in pstates) | 1530 | foreach (KeyValuePair<UUID, string> kvp in pstates) |
1069 | states.Add(kvp.Key, kvp.Value); | 1531 | states[kvp.Key] = kvp.Value; |
1070 | } | 1532 | } |
1071 | 1533 | ||
1072 | if (states.Count > 0) | 1534 | if (states.Count > 0) |
@@ -1086,6 +1548,169 @@ namespace OpenSim.Region.Framework.Scenes | |||
1086 | } | 1548 | } |
1087 | 1549 | ||
1088 | /// <summary> | 1550 | /// <summary> |
1551 | /// Add the avatar to this linkset (avatar is sat). | ||
1552 | /// </summary> | ||
1553 | /// <param name="agentID"></param> | ||
1554 | public void AddAvatar(UUID agentID) | ||
1555 | { | ||
1556 | ScenePresence presence; | ||
1557 | if (m_scene.TryGetScenePresence(agentID, out presence)) | ||
1558 | { | ||
1559 | if (!m_linkedAvatars.Contains(presence)) | ||
1560 | { | ||
1561 | m_linkedAvatars.Add(presence); | ||
1562 | } | ||
1563 | } | ||
1564 | } | ||
1565 | |||
1566 | /// <summary> | ||
1567 | /// Delete the avatar from this linkset (avatar is unsat). | ||
1568 | /// </summary> | ||
1569 | /// <param name="agentID"></param> | ||
1570 | public void DeleteAvatar(UUID agentID) | ||
1571 | { | ||
1572 | ScenePresence presence; | ||
1573 | if (m_scene.TryGetScenePresence(agentID, out presence)) | ||
1574 | { | ||
1575 | if (m_linkedAvatars.Contains(presence)) | ||
1576 | { | ||
1577 | m_linkedAvatars.Remove(presence); | ||
1578 | } | ||
1579 | } | ||
1580 | } | ||
1581 | |||
1582 | /// <summary> | ||
1583 | /// Returns the list of linked presences (avatars sat on this group) | ||
1584 | /// </summary> | ||
1585 | /// <param name="agentID"></param> | ||
1586 | public List<ScenePresence> GetLinkedAvatars() | ||
1587 | { | ||
1588 | return m_linkedAvatars; | ||
1589 | } | ||
1590 | |||
1591 | /// <summary> | ||
1592 | /// Attach this scene object to the given avatar. | ||
1593 | /// </summary> | ||
1594 | /// <param name="agentID"></param> | ||
1595 | /// <param name="attachmentpoint"></param> | ||
1596 | /// <param name="AttachOffset"></param> | ||
1597 | private void AttachToAgent( | ||
1598 | ScenePresence avatar, SceneObjectGroup so, uint attachmentpoint, Vector3 attachOffset, bool silent) | ||
1599 | { | ||
1600 | if (avatar != null) | ||
1601 | { | ||
1602 | // don't attach attachments to child agents | ||
1603 | if (avatar.IsChildAgent) return; | ||
1604 | |||
1605 | // Remove from database and parcel prim count | ||
1606 | m_scene.DeleteFromStorage(so.UUID); | ||
1607 | m_scene.EventManager.TriggerParcelPrimCountTainted(); | ||
1608 | |||
1609 | so.AttachedAvatar = avatar.UUID; | ||
1610 | |||
1611 | if (so.RootPart.PhysActor != null) | ||
1612 | { | ||
1613 | m_scene.PhysicsScene.RemovePrim(so.RootPart.PhysActor); | ||
1614 | so.RootPart.PhysActor = null; | ||
1615 | } | ||
1616 | |||
1617 | so.AbsolutePosition = attachOffset; | ||
1618 | so.RootPart.AttachedPos = attachOffset; | ||
1619 | so.IsAttachment = true; | ||
1620 | so.RootPart.SetParentLocalId(avatar.LocalId); | ||
1621 | so.AttachmentPoint = attachmentpoint; | ||
1622 | |||
1623 | avatar.AddAttachment(this); | ||
1624 | |||
1625 | if (!silent) | ||
1626 | { | ||
1627 | // Killing it here will cause the client to deselect it | ||
1628 | // It then reappears on the avatar, deselected | ||
1629 | // through the full update below | ||
1630 | // | ||
1631 | if (IsSelected) | ||
1632 | { | ||
1633 | m_scene.SendKillObject(new List<uint> { m_rootPart.LocalId }); | ||
1634 | } | ||
1635 | |||
1636 | IsSelected = false; // fudge.... | ||
1637 | ScheduleGroupForFullUpdate(); | ||
1638 | } | ||
1639 | } | ||
1640 | else | ||
1641 | { | ||
1642 | m_log.WarnFormat( | ||
1643 | "[SOG]: Tried to add attachment {0} to avatar with UUID {1} in region {2} but the avatar is not present", | ||
1644 | UUID, avatar.ControllingClient.AgentId, Scene.RegionInfo.RegionName); | ||
1645 | } | ||
1646 | } | ||
1647 | |||
1648 | public byte GetAttachmentPoint() | ||
1649 | { | ||
1650 | return m_rootPart.Shape.State; | ||
1651 | } | ||
1652 | |||
1653 | public void DetachToGround() | ||
1654 | { | ||
1655 | ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); | ||
1656 | if (avatar == null) | ||
1657 | return; | ||
1658 | |||
1659 | avatar.RemoveAttachment(this); | ||
1660 | |||
1661 | Vector3 detachedpos = new Vector3(127f,127f,127f); | ||
1662 | if (avatar == null) | ||
1663 | return; | ||
1664 | |||
1665 | detachedpos = avatar.AbsolutePosition; | ||
1666 | FromItemID = UUID.Zero; | ||
1667 | |||
1668 | AbsolutePosition = detachedpos; | ||
1669 | AttachedAvatar = UUID.Zero; | ||
1670 | |||
1671 | //SceneObjectPart[] parts = m_parts.GetArray(); | ||
1672 | //for (int i = 0; i < parts.Length; i++) | ||
1673 | // parts[i].AttachedAvatar = UUID.Zero; | ||
1674 | |||
1675 | m_rootPart.SetParentLocalId(0); | ||
1676 | AttachmentPoint = (byte)0; | ||
1677 | // must check if buildind should be true or false here | ||
1678 | m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive,false); | ||
1679 | HasGroupChanged = true; | ||
1680 | RootPart.Rezzed = DateTime.Now; | ||
1681 | RootPart.RemFlag(PrimFlags.TemporaryOnRez); | ||
1682 | AttachToBackup(); | ||
1683 | m_scene.EventManager.TriggerParcelPrimCountTainted(); | ||
1684 | m_rootPart.ScheduleFullUpdate(); | ||
1685 | m_rootPart.ClearUndoState(); | ||
1686 | } | ||
1687 | |||
1688 | public void DetachToInventoryPrep() | ||
1689 | { | ||
1690 | ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); | ||
1691 | //Vector3 detachedpos = new Vector3(127f, 127f, 127f); | ||
1692 | if (avatar != null) | ||
1693 | { | ||
1694 | //detachedpos = avatar.AbsolutePosition; | ||
1695 | avatar.RemoveAttachment(this); | ||
1696 | } | ||
1697 | |||
1698 | AttachedAvatar = UUID.Zero; | ||
1699 | |||
1700 | /*SceneObjectPart[] parts = m_parts.GetArray(); | ||
1701 | for (int i = 0; i < parts.Length; i++) | ||
1702 | parts[i].AttachedAvatar = UUID.Zero;*/ | ||
1703 | |||
1704 | m_rootPart.SetParentLocalId(0); | ||
1705 | //m_rootPart.SetAttachmentPoint((byte)0); | ||
1706 | IsAttachment = false; | ||
1707 | AbsolutePosition = m_rootPart.AttachedPos; | ||
1708 | //m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_scene.m_physicalPrim); | ||
1709 | //AttachToBackup(); | ||
1710 | //m_rootPart.ScheduleFullUpdate(); | ||
1711 | } | ||
1712 | |||
1713 | /// <summary> | ||
1089 | /// | 1714 | /// |
1090 | /// </summary> | 1715 | /// </summary> |
1091 | /// <param name="part"></param> | 1716 | /// <param name="part"></param> |
@@ -1125,7 +1750,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
1125 | public void AddPart(SceneObjectPart part) | 1750 | public void AddPart(SceneObjectPart part) |
1126 | { | 1751 | { |
1127 | part.SetParent(this); | 1752 | part.SetParent(this); |
1128 | part.LinkNum = m_parts.Add(part.UUID, part); | 1753 | m_parts.Add(part.UUID, part); |
1754 | |||
1755 | part.LinkNum = m_parts.Count; | ||
1756 | |||
1129 | if (part.LinkNum == 2) | 1757 | if (part.LinkNum == 2) |
1130 | RootPart.LinkNum = 1; | 1758 | RootPart.LinkNum = 1; |
1131 | } | 1759 | } |
@@ -1151,6 +1779,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
1151 | parts[i].UUID = UUID.Random(); | 1779 | parts[i].UUID = UUID.Random(); |
1152 | } | 1780 | } |
1153 | 1781 | ||
1782 | // helper provided for parts. | ||
1783 | public int GetSceneMaxUndo() | ||
1784 | { | ||
1785 | if (m_scene != null) | ||
1786 | return m_scene.MaxUndoCount; | ||
1787 | return 5; | ||
1788 | } | ||
1789 | |||
1154 | // justincc: I don't believe this hack is needed any longer, especially since the physics | 1790 | // justincc: I don't believe this hack is needed any longer, especially since the physics |
1155 | // parts of set AbsolutePosition were already commented out. By changing HasGroupChanged to false | 1791 | // parts of set AbsolutePosition were already commented out. By changing HasGroupChanged to false |
1156 | // this method was preventing proper reload of scene objects. | 1792 | // this method was preventing proper reload of scene objects. |
@@ -1208,7 +1844,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1208 | // "[SCENE OBJECT GROUP]: Processing OnGrabPart for {0} on {1} {2}, offsetPos {3}", | 1844 | // "[SCENE OBJECT GROUP]: Processing OnGrabPart for {0} on {1} {2}, offsetPos {3}", |
1209 | // remoteClient.Name, part.Name, part.LocalId, offsetPos); | 1845 | // remoteClient.Name, part.Name, part.LocalId, offsetPos); |
1210 | 1846 | ||
1211 | part.StoreUndoState(); | 1847 | // part.StoreUndoState(); |
1212 | part.OnGrab(offsetPos, remoteClient); | 1848 | part.OnGrab(offsetPos, remoteClient); |
1213 | } | 1849 | } |
1214 | 1850 | ||
@@ -1228,6 +1864,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
1228 | /// <param name="silent">If true then deletion is not broadcast to clients</param> | 1864 | /// <param name="silent">If true then deletion is not broadcast to clients</param> |
1229 | public void DeleteGroupFromScene(bool silent) | 1865 | public void DeleteGroupFromScene(bool silent) |
1230 | { | 1866 | { |
1867 | // We need to keep track of this state in case this group is still queued for backup. | ||
1868 | IsDeleted = true; | ||
1869 | |||
1870 | DetachFromBackup(); | ||
1871 | |||
1231 | SceneObjectPart[] parts = m_parts.GetArray(); | 1872 | SceneObjectPart[] parts = m_parts.GetArray(); |
1232 | for (int i = 0; i < parts.Length; i++) | 1873 | for (int i = 0; i < parts.Length; i++) |
1233 | { | 1874 | { |
@@ -1251,6 +1892,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1251 | } | 1892 | } |
1252 | }); | 1893 | }); |
1253 | } | 1894 | } |
1895 | |||
1254 | } | 1896 | } |
1255 | 1897 | ||
1256 | public void AddScriptLPS(int count) | 1898 | public void AddScriptLPS(int count) |
@@ -1320,28 +1962,43 @@ namespace OpenSim.Region.Framework.Scenes | |||
1320 | /// </summary> | 1962 | /// </summary> |
1321 | public void ApplyPhysics() | 1963 | public void ApplyPhysics() |
1322 | { | 1964 | { |
1323 | // Apply physics to the root prim | ||
1324 | m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive); | ||
1325 | |||
1326 | // Apply physics to child prims | ||
1327 | SceneObjectPart[] parts = m_parts.GetArray(); | 1965 | SceneObjectPart[] parts = m_parts.GetArray(); |
1328 | if (parts.Length > 1) | 1966 | if (parts.Length > 1) |
1329 | { | 1967 | { |
1968 | ResetChildPrimPhysicsPositions(); | ||
1969 | |||
1970 | // Apply physics to the root prim | ||
1971 | m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, true); | ||
1972 | |||
1973 | |||
1330 | for (int i = 0; i < parts.Length; i++) | 1974 | for (int i = 0; i < parts.Length; i++) |
1331 | { | 1975 | { |
1332 | SceneObjectPart part = parts[i]; | 1976 | SceneObjectPart part = parts[i]; |
1333 | if (part.LocalId != m_rootPart.LocalId) | 1977 | if (part.LocalId != m_rootPart.LocalId) |
1334 | part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive); | 1978 | part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, true); |
1335 | } | 1979 | } |
1336 | |||
1337 | // Hack to get the physics scene geometries in the right spot | 1980 | // Hack to get the physics scene geometries in the right spot |
1338 | ResetChildPrimPhysicsPositions(); | 1981 | // ResetChildPrimPhysicsPositions(); |
1982 | if (m_rootPart.PhysActor != null) | ||
1983 | { | ||
1984 | m_rootPart.PhysActor.Building = false; | ||
1985 | } | ||
1986 | } | ||
1987 | else | ||
1988 | { | ||
1989 | // Apply physics to the root prim | ||
1990 | m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive, false); | ||
1339 | } | 1991 | } |
1340 | } | 1992 | } |
1341 | 1993 | ||
1342 | public void SetOwnerId(UUID userId) | 1994 | public void SetOwnerId(UUID userId) |
1343 | { | 1995 | { |
1344 | ForEachPart(delegate(SceneObjectPart part) { part.OwnerID = userId; }); | 1996 | ForEachPart(delegate(SceneObjectPart part) |
1997 | { | ||
1998 | |||
1999 | part.OwnerID = userId; | ||
2000 | |||
2001 | }); | ||
1345 | } | 2002 | } |
1346 | 2003 | ||
1347 | public void ForEachPart(Action<SceneObjectPart> whatToDo) | 2004 | public void ForEachPart(Action<SceneObjectPart> whatToDo) |
@@ -1373,11 +2030,17 @@ namespace OpenSim.Region.Framework.Scenes | |||
1373 | return; | 2030 | return; |
1374 | } | 2031 | } |
1375 | 2032 | ||
2033 | if ((RootPart.Flags & PrimFlags.TemporaryOnRez) != 0) | ||
2034 | return; | ||
2035 | |||
1376 | // Since this is the top of the section of call stack for backing up a particular scene object, don't let | 2036 | // Since this is the top of the section of call stack for backing up a particular scene object, don't let |
1377 | // any exception propogate upwards. | 2037 | // any exception propogate upwards. |
1378 | try | 2038 | try |
1379 | { | 2039 | { |
1380 | if (!m_scene.ShuttingDown) // if shutting down then there will be nothing to handle the return so leave till next restart | 2040 | if (!m_scene.ShuttingDown || // if shutting down then there will be nothing to handle the return so leave till next restart |
2041 | !m_scene.LoginsEnabled || // We're starting up or doing maintenance, don't mess with things | ||
2042 | m_scene.LoadingPrims) // Land may not be valid yet | ||
2043 | |||
1381 | { | 2044 | { |
1382 | ILandObject parcel = m_scene.LandChannel.GetLandObject( | 2045 | ILandObject parcel = m_scene.LandChannel.GetLandObject( |
1383 | m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y); | 2046 | m_rootPart.GroupPosition.X, m_rootPart.GroupPosition.Y); |
@@ -1404,6 +2067,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1404 | } | 2067 | } |
1405 | } | 2068 | } |
1406 | } | 2069 | } |
2070 | |||
1407 | } | 2071 | } |
1408 | 2072 | ||
1409 | if (m_scene.UseBackup && HasGroupChanged) | 2073 | if (m_scene.UseBackup && HasGroupChanged) |
@@ -1411,10 +2075,30 @@ namespace OpenSim.Region.Framework.Scenes | |||
1411 | // don't backup while it's selected or you're asking for changes mid stream. | 2075 | // don't backup while it's selected or you're asking for changes mid stream. |
1412 | if (isTimeToPersist() || forcedBackup) | 2076 | if (isTimeToPersist() || forcedBackup) |
1413 | { | 2077 | { |
2078 | if (m_rootPart.PhysActor != null && | ||
2079 | (!m_rootPart.PhysActor.IsPhysical)) | ||
2080 | { | ||
2081 | // Possible ghost prim | ||
2082 | if (m_rootPart.PhysActor.Position != m_rootPart.GroupPosition) | ||
2083 | { | ||
2084 | foreach (SceneObjectPart part in m_parts.GetArray()) | ||
2085 | { | ||
2086 | // Re-set physics actor positions and | ||
2087 | // orientations | ||
2088 | part.GroupPosition = m_rootPart.GroupPosition; | ||
2089 | } | ||
2090 | } | ||
2091 | } | ||
1414 | // m_log.DebugFormat( | 2092 | // m_log.DebugFormat( |
1415 | // "[SCENE]: Storing {0}, {1} in {2}", | 2093 | // "[SCENE]: Storing {0}, {1} in {2}", |
1416 | // Name, UUID, m_scene.RegionInfo.RegionName); | 2094 | // Name, UUID, m_scene.RegionInfo.RegionName); |
1417 | 2095 | ||
2096 | if (RootPart.Shape.PCode == 9 && RootPart.Shape.State != 0) | ||
2097 | { | ||
2098 | RootPart.Shape.State = 0; | ||
2099 | ScheduleGroupForFullUpdate(); | ||
2100 | } | ||
2101 | |||
1418 | SceneObjectGroup backup_group = Copy(false); | 2102 | SceneObjectGroup backup_group = Copy(false); |
1419 | backup_group.RootPart.Velocity = RootPart.Velocity; | 2103 | backup_group.RootPart.Velocity = RootPart.Velocity; |
1420 | backup_group.RootPart.Acceleration = RootPart.Acceleration; | 2104 | backup_group.RootPart.Acceleration = RootPart.Acceleration; |
@@ -1424,6 +2108,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
1424 | HasGroupChangedDueToDelink = false; | 2108 | HasGroupChangedDueToDelink = false; |
1425 | 2109 | ||
1426 | m_scene.EventManager.TriggerOnSceneObjectPreSave(backup_group, this); | 2110 | m_scene.EventManager.TriggerOnSceneObjectPreSave(backup_group, this); |
2111 | /* | ||
2112 | backup_group.ForEachPart(delegate(SceneObjectPart part) | ||
2113 | { | ||
2114 | if (part.KeyframeMotion != null) | ||
2115 | { | ||
2116 | part.KeyframeMotion = KeyframeMotion.FromData(backup_group, part.KeyframeMotion.Serialize()); | ||
2117 | // part.KeyframeMotion.UpdateSceneObject(this); | ||
2118 | } | ||
2119 | }); | ||
2120 | */ | ||
1427 | datastore.StoreObject(backup_group, m_scene.RegionInfo.RegionID); | 2121 | datastore.StoreObject(backup_group, m_scene.RegionInfo.RegionID); |
1428 | 2122 | ||
1429 | backup_group.ForEachPart(delegate(SceneObjectPart part) | 2123 | backup_group.ForEachPart(delegate(SceneObjectPart part) |
@@ -1480,10 +2174,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
1480 | /// <returns></returns> | 2174 | /// <returns></returns> |
1481 | public SceneObjectGroup Copy(bool userExposed) | 2175 | public SceneObjectGroup Copy(bool userExposed) |
1482 | { | 2176 | { |
2177 | m_dupeInProgress = true; | ||
1483 | SceneObjectGroup dupe = (SceneObjectGroup)MemberwiseClone(); | 2178 | SceneObjectGroup dupe = (SceneObjectGroup)MemberwiseClone(); |
1484 | dupe.m_isBackedUp = false; | 2179 | dupe.m_isBackedUp = false; |
1485 | dupe.m_parts = new MapAndArray<OpenMetaverse.UUID, SceneObjectPart>(); | 2180 | dupe.m_parts = new MapAndArray<OpenMetaverse.UUID, SceneObjectPart>(); |
1486 | 2181 | ||
2182 | // new group as no sitting avatars | ||
2183 | dupe.m_linkedAvatars = new List<ScenePresence>(); | ||
2184 | |||
1487 | // Warning, The following code related to previousAttachmentStatus is needed so that clones of | 2185 | // Warning, The following code related to previousAttachmentStatus is needed so that clones of |
1488 | // attachments do not bordercross while they're being duplicated. This is hacktastic! | 2186 | // attachments do not bordercross while they're being duplicated. This is hacktastic! |
1489 | // Normally, setting AbsolutePosition will bordercross a prim if it's outside the region! | 2187 | // Normally, setting AbsolutePosition will bordercross a prim if it's outside the region! |
@@ -1494,7 +2192,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1494 | // This is only necessary when userExposed is false! | 2192 | // This is only necessary when userExposed is false! |
1495 | 2193 | ||
1496 | bool previousAttachmentStatus = dupe.IsAttachment; | 2194 | bool previousAttachmentStatus = dupe.IsAttachment; |
1497 | 2195 | ||
1498 | if (!userExposed) | 2196 | if (!userExposed) |
1499 | dupe.IsAttachment = true; | 2197 | dupe.IsAttachment = true; |
1500 | 2198 | ||
@@ -1507,16 +2205,17 @@ namespace OpenSim.Region.Framework.Scenes | |||
1507 | 2205 | ||
1508 | dupe.CopyRootPart(m_rootPart, OwnerID, GroupID, userExposed); | 2206 | dupe.CopyRootPart(m_rootPart, OwnerID, GroupID, userExposed); |
1509 | dupe.m_rootPart.LinkNum = m_rootPart.LinkNum; | 2207 | dupe.m_rootPart.LinkNum = m_rootPart.LinkNum; |
2208 | |||
1510 | 2209 | ||
1511 | if (userExposed) | 2210 | if (userExposed) |
1512 | dupe.m_rootPart.TrimPermissions(); | 2211 | dupe.m_rootPart.TrimPermissions(); |
1513 | 2212 | ||
1514 | List<SceneObjectPart> partList = new List<SceneObjectPart>(m_parts.GetArray()); | 2213 | List<SceneObjectPart> partList = new List<SceneObjectPart>(m_parts.GetArray()); |
1515 | 2214 | ||
1516 | partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) | 2215 | partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) |
1517 | { | 2216 | { |
1518 | return p1.LinkNum.CompareTo(p2.LinkNum); | 2217 | return p1.LinkNum.CompareTo(p2.LinkNum); |
1519 | } | 2218 | } |
1520 | ); | 2219 | ); |
1521 | 2220 | ||
1522 | foreach (SceneObjectPart part in partList) | 2221 | foreach (SceneObjectPart part in partList) |
@@ -1526,41 +2225,56 @@ namespace OpenSim.Region.Framework.Scenes | |||
1526 | { | 2225 | { |
1527 | newPart = dupe.CopyPart(part, OwnerID, GroupID, userExposed); | 2226 | newPart = dupe.CopyPart(part, OwnerID, GroupID, userExposed); |
1528 | newPart.LinkNum = part.LinkNum; | 2227 | newPart.LinkNum = part.LinkNum; |
1529 | } | 2228 | if (userExposed) |
2229 | newPart.ParentID = dupe.m_rootPart.LocalId; | ||
2230 | } | ||
1530 | else | 2231 | else |
1531 | { | 2232 | { |
1532 | newPart = dupe.m_rootPart; | 2233 | newPart = dupe.m_rootPart; |
1533 | } | 2234 | } |
2235 | /* | ||
2236 | bool isphys = ((newPart.Flags & PrimFlags.Physics) != 0); | ||
2237 | bool isphan = ((newPart.Flags & PrimFlags.Phantom) != 0); | ||
1534 | 2238 | ||
1535 | // Need to duplicate the physics actor as well | 2239 | // Need to duplicate the physics actor as well |
1536 | PhysicsActor originalPartPa = part.PhysActor; | 2240 | if (userExposed && (isphys || !isphan || newPart.VolumeDetectActive)) |
1537 | if (originalPartPa != null && userExposed) | ||
1538 | { | 2241 | { |
1539 | PrimitiveBaseShape pbs = newPart.Shape; | 2242 | PrimitiveBaseShape pbs = newPart.Shape; |
1540 | |||
1541 | newPart.PhysActor | 2243 | newPart.PhysActor |
1542 | = m_scene.PhysicsScene.AddPrimShape( | 2244 | = m_scene.PhysicsScene.AddPrimShape( |
1543 | string.Format("{0}/{1}", newPart.Name, newPart.UUID), | 2245 | string.Format("{0}/{1}", newPart.Name, newPart.UUID), |
1544 | pbs, | 2246 | pbs, |
1545 | newPart.AbsolutePosition, | 2247 | newPart.AbsolutePosition, |
1546 | newPart.Scale, | 2248 | newPart.Scale, |
1547 | newPart.RotationOffset, | 2249 | newPart.GetWorldRotation(), |
1548 | originalPartPa.IsPhysical, | 2250 | isphys, |
2251 | isphan, | ||
1549 | newPart.LocalId); | 2252 | newPart.LocalId); |
1550 | 2253 | ||
1551 | newPart.DoPhysicsPropertyUpdate(originalPartPa.IsPhysical, true); | 2254 | newPart.DoPhysicsPropertyUpdate(isphys, true); |
1552 | } | 2255 | */ |
2256 | if (userExposed) | ||
2257 | newPart.ApplyPhysics((uint)newPart.Flags,newPart.VolumeDetectActive,true); | ||
2258 | // } | ||
2259 | // copy keyframemotion | ||
2260 | if (part.KeyframeMotion != null) | ||
2261 | newPart.KeyframeMotion = part.KeyframeMotion.Copy(dupe); | ||
1553 | } | 2262 | } |
1554 | 2263 | ||
1555 | if (userExposed) | 2264 | if (userExposed) |
1556 | { | 2265 | { |
1557 | dupe.UpdateParentIDs(); | 2266 | // done above dupe.UpdateParentIDs(); |
2267 | |||
2268 | if (dupe.m_rootPart.PhysActor != null) | ||
2269 | dupe.m_rootPart.PhysActor.Building = false; // tell physics to finish building | ||
2270 | |||
1558 | dupe.HasGroupChanged = true; | 2271 | dupe.HasGroupChanged = true; |
1559 | dupe.AttachToBackup(); | 2272 | dupe.AttachToBackup(); |
1560 | 2273 | ||
1561 | ScheduleGroupForFullUpdate(); | 2274 | ScheduleGroupForFullUpdate(); |
1562 | } | 2275 | } |
1563 | 2276 | ||
2277 | m_dupeInProgress = false; | ||
1564 | return dupe; | 2278 | return dupe; |
1565 | } | 2279 | } |
1566 | 2280 | ||
@@ -1572,11 +2286,24 @@ namespace OpenSim.Region.Framework.Scenes | |||
1572 | /// <param name="cGroupID"></param> | 2286 | /// <param name="cGroupID"></param> |
1573 | public void CopyRootPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed) | 2287 | public void CopyRootPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed) |
1574 | { | 2288 | { |
1575 | SetRootPart(part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, 0, userExposed)); | 2289 | // SetRootPart(part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, 0, userExposed)); |
2290 | // give newpart a new local ID lettng old part keep same | ||
2291 | SceneObjectPart newpart = part.Copy(part.LocalId, OwnerID, GroupID, 0, userExposed); | ||
2292 | newpart.LocalId = m_scene.AllocateLocalId(); | ||
2293 | |||
2294 | SetRootPart(newpart); | ||
2295 | if (userExposed) | ||
2296 | RootPart.Velocity = Vector3.Zero; // In case source is moving | ||
1576 | } | 2297 | } |
1577 | 2298 | ||
1578 | public void ScriptSetPhysicsStatus(bool usePhysics) | 2299 | public void ScriptSetPhysicsStatus(bool usePhysics) |
1579 | { | 2300 | { |
2301 | if (usePhysics) | ||
2302 | { | ||
2303 | if (RootPart.KeyframeMotion != null) | ||
2304 | RootPart.KeyframeMotion.Stop(); | ||
2305 | RootPart.KeyframeMotion = null; | ||
2306 | } | ||
1580 | UpdatePrimFlags(RootPart.LocalId, usePhysics, IsTemporary, IsPhantom, IsVolumeDetect); | 2307 | UpdatePrimFlags(RootPart.LocalId, usePhysics, IsTemporary, IsPhantom, IsVolumeDetect); |
1581 | } | 2308 | } |
1582 | 2309 | ||
@@ -1624,13 +2351,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
1624 | 2351 | ||
1625 | if (pa != null) | 2352 | if (pa != null) |
1626 | { | 2353 | { |
1627 | pa.AddForce(impulse, true); | 2354 | // false to be applied as a impulse |
2355 | pa.AddForce(impulse, false); | ||
1628 | m_scene.PhysicsScene.AddPhysicsActorTaint(pa); | 2356 | m_scene.PhysicsScene.AddPhysicsActorTaint(pa); |
1629 | } | 2357 | } |
1630 | } | 2358 | } |
1631 | } | 2359 | } |
1632 | 2360 | ||
1633 | public void applyAngularImpulse(Vector3 impulse) | 2361 | public void ApplyAngularImpulse(Vector3 impulse) |
1634 | { | 2362 | { |
1635 | PhysicsActor pa = RootPart.PhysActor; | 2363 | PhysicsActor pa = RootPart.PhysActor; |
1636 | 2364 | ||
@@ -1638,21 +2366,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
1638 | { | 2366 | { |
1639 | if (!IsAttachment) | 2367 | if (!IsAttachment) |
1640 | { | 2368 | { |
1641 | pa.AddAngularForce(impulse, true); | 2369 | // false to be applied as a impulse |
1642 | m_scene.PhysicsScene.AddPhysicsActorTaint(pa); | 2370 | pa.AddAngularForce(impulse, false); |
1643 | } | ||
1644 | } | ||
1645 | } | ||
1646 | |||
1647 | public void setAngularImpulse(Vector3 impulse) | ||
1648 | { | ||
1649 | PhysicsActor pa = RootPart.PhysActor; | ||
1650 | |||
1651 | if (pa != null) | ||
1652 | { | ||
1653 | if (!IsAttachment) | ||
1654 | { | ||
1655 | pa.Torque = impulse; | ||
1656 | m_scene.PhysicsScene.AddPhysicsActorTaint(pa); | 2371 | m_scene.PhysicsScene.AddPhysicsActorTaint(pa); |
1657 | } | 2372 | } |
1658 | } | 2373 | } |
@@ -1660,20 +2375,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
1660 | 2375 | ||
1661 | public Vector3 GetTorque() | 2376 | public Vector3 GetTorque() |
1662 | { | 2377 | { |
1663 | PhysicsActor pa = RootPart.PhysActor; | 2378 | return RootPart.Torque; |
1664 | |||
1665 | if (pa != null) | ||
1666 | { | ||
1667 | if (!IsAttachment) | ||
1668 | { | ||
1669 | Vector3 torque = pa.Torque; | ||
1670 | return torque; | ||
1671 | } | ||
1672 | } | ||
1673 | |||
1674 | return Vector3.Zero; | ||
1675 | } | 2379 | } |
1676 | 2380 | ||
2381 | // This is used by both Double-Click Auto-Pilot and llMoveToTarget() in an attached object | ||
1677 | public void moveToTarget(Vector3 target, float tau) | 2382 | public void moveToTarget(Vector3 target, float tau) |
1678 | { | 2383 | { |
1679 | if (IsAttachment) | 2384 | if (IsAttachment) |
@@ -1703,8 +2408,50 @@ namespace OpenSim.Region.Framework.Scenes | |||
1703 | 2408 | ||
1704 | if (pa != null) | 2409 | if (pa != null) |
1705 | pa.PIDActive = false; | 2410 | pa.PIDActive = false; |
2411 | |||
2412 | RootPart.ScheduleTerseUpdate(); // send a stop information | ||
1706 | } | 2413 | } |
1707 | 2414 | ||
2415 | public void rotLookAt(Quaternion target, float strength, float damping) | ||
2416 | { | ||
2417 | SceneObjectPart rootpart = m_rootPart; | ||
2418 | if (rootpart != null) | ||
2419 | { | ||
2420 | if (IsAttachment) | ||
2421 | { | ||
2422 | /* | ||
2423 | ScenePresence avatar = m_scene.GetScenePresence(rootpart.AttachedAvatar); | ||
2424 | if (avatar != null) | ||
2425 | { | ||
2426 | Rotate the Av? | ||
2427 | } */ | ||
2428 | } | ||
2429 | else | ||
2430 | { | ||
2431 | if (rootpart.PhysActor != null) | ||
2432 | { // APID must be implemented in your physics system for this to function. | ||
2433 | rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W); | ||
2434 | rootpart.PhysActor.APIDStrength = strength; | ||
2435 | rootpart.PhysActor.APIDDamping = damping; | ||
2436 | rootpart.PhysActor.APIDActive = true; | ||
2437 | } | ||
2438 | } | ||
2439 | } | ||
2440 | } | ||
2441 | |||
2442 | public void stopLookAt() | ||
2443 | { | ||
2444 | SceneObjectPart rootpart = m_rootPart; | ||
2445 | if (rootpart != null) | ||
2446 | { | ||
2447 | if (rootpart.PhysActor != null) | ||
2448 | { // APID must be implemented in your physics system for this to function. | ||
2449 | rootpart.PhysActor.APIDActive = false; | ||
2450 | } | ||
2451 | } | ||
2452 | |||
2453 | } | ||
2454 | |||
1708 | /// <summary> | 2455 | /// <summary> |
1709 | /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds. | 2456 | /// Uses a PID to attempt to clamp the object on the Z axis at the given height over tau seconds. |
1710 | /// </summary> | 2457 | /// </summary> |
@@ -1721,7 +2468,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1721 | { | 2468 | { |
1722 | pa.PIDHoverHeight = height; | 2469 | pa.PIDHoverHeight = height; |
1723 | pa.PIDHoverType = hoverType; | 2470 | pa.PIDHoverType = hoverType; |
1724 | pa.PIDTau = tau; | 2471 | pa.PIDHoverTau = tau; |
1725 | pa.PIDHoverActive = true; | 2472 | pa.PIDHoverActive = true; |
1726 | } | 2473 | } |
1727 | else | 2474 | else |
@@ -1761,7 +2508,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
1761 | /// <param name="cGroupID"></param> | 2508 | /// <param name="cGroupID"></param> |
1762 | public SceneObjectPart CopyPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed) | 2509 | public SceneObjectPart CopyPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed) |
1763 | { | 2510 | { |
1764 | SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); | 2511 | // give new ID to the new part, letting old keep original |
2512 | // SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); | ||
2513 | SceneObjectPart newPart = part.Copy(part.LocalId, OwnerID, GroupID, m_parts.Count, userExposed); | ||
2514 | newPart.LocalId = m_scene.AllocateLocalId(); | ||
2515 | newPart.SetParent(this); | ||
2516 | |||
1765 | AddPart(newPart); | 2517 | AddPart(newPart); |
1766 | 2518 | ||
1767 | SetPartAsNonRoot(newPart); | 2519 | SetPartAsNonRoot(newPart); |
@@ -1811,6 +2563,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1811 | 2563 | ||
1812 | #endregion | 2564 | #endregion |
1813 | 2565 | ||
2566 | |||
1814 | public override void Update() | 2567 | public override void Update() |
1815 | { | 2568 | { |
1816 | // Check that the group was not deleted before the scheduled update | 2569 | // Check that the group was not deleted before the scheduled update |
@@ -1829,19 +2582,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
1829 | // check to see if the physical position or rotation warrant an update. | 2582 | // check to see if the physical position or rotation warrant an update. |
1830 | if (m_rootPart.UpdateFlag == UpdateRequired.NONE) | 2583 | if (m_rootPart.UpdateFlag == UpdateRequired.NONE) |
1831 | { | 2584 | { |
1832 | bool UsePhysics = ((RootPart.Flags & PrimFlags.Physics) != 0); | 2585 | // rootpart SendScheduledUpdates will check if a update is needed |
1833 | 2586 | m_rootPart.UpdateFlag = UpdateRequired.TERSE; | |
1834 | if (UsePhysics && !AbsolutePosition.ApproxEquals(lastPhysGroupPos, 0.02f)) | ||
1835 | { | ||
1836 | m_rootPart.UpdateFlag = UpdateRequired.TERSE; | ||
1837 | lastPhysGroupPos = AbsolutePosition; | ||
1838 | } | ||
1839 | |||
1840 | if (UsePhysics && !GroupRotation.ApproxEquals(lastPhysGroupRot, 0.1f)) | ||
1841 | { | ||
1842 | m_rootPart.UpdateFlag = UpdateRequired.TERSE; | ||
1843 | lastPhysGroupRot = GroupRotation; | ||
1844 | } | ||
1845 | } | 2587 | } |
1846 | 2588 | ||
1847 | SceneObjectPart[] parts = m_parts.GetArray(); | 2589 | SceneObjectPart[] parts = m_parts.GetArray(); |
@@ -1900,11 +2642,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
1900 | /// Immediately send a full update for this scene object. | 2642 | /// Immediately send a full update for this scene object. |
1901 | /// </summary> | 2643 | /// </summary> |
1902 | public void SendGroupFullUpdate() | 2644 | public void SendGroupFullUpdate() |
1903 | { | 2645 | { |
1904 | if (IsDeleted) | 2646 | if (IsDeleted) |
1905 | return; | 2647 | return; |
1906 | 2648 | ||
1907 | // m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID); | 2649 | // m_log.DebugFormat("[SOG]: Sending immediate full group update for {0} {1}", Name, UUID); |
1908 | 2650 | ||
1909 | RootPart.SendFullUpdateToAllClients(); | 2651 | RootPart.SendFullUpdateToAllClients(); |
1910 | 2652 | ||
@@ -2060,6 +2802,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
2060 | // 'linkPart' == the root of the group being linked into this group | 2802 | // 'linkPart' == the root of the group being linked into this group |
2061 | SceneObjectPart linkPart = objectGroup.m_rootPart; | 2803 | SceneObjectPart linkPart = objectGroup.m_rootPart; |
2062 | 2804 | ||
2805 | if (m_rootPart.PhysActor != null) | ||
2806 | m_rootPart.PhysActor.Building = true; | ||
2807 | if (linkPart.PhysActor != null) | ||
2808 | linkPart.PhysActor.Building = true; | ||
2809 | |||
2063 | // physics flags from group to be applied to linked parts | 2810 | // physics flags from group to be applied to linked parts |
2064 | bool grpusephys = UsesPhysics; | 2811 | bool grpusephys = UsesPhysics; |
2065 | bool grptemporary = IsTemporary; | 2812 | bool grptemporary = IsTemporary; |
@@ -2085,12 +2832,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
2085 | Vector3 axPos = linkPart.OffsetPosition; | 2832 | Vector3 axPos = linkPart.OffsetPosition; |
2086 | // Rotate the linking root SOP's position to be relative to the new root prim | 2833 | // Rotate the linking root SOP's position to be relative to the new root prim |
2087 | Quaternion parentRot = m_rootPart.RotationOffset; | 2834 | Quaternion parentRot = m_rootPart.RotationOffset; |
2088 | axPos *= Quaternion.Inverse(parentRot); | 2835 | axPos *= Quaternion.Conjugate(parentRot); |
2089 | linkPart.OffsetPosition = axPos; | 2836 | linkPart.OffsetPosition = axPos; |
2090 | 2837 | ||
2091 | // Make the linking root SOP's rotation relative to the new root prim | 2838 | // Make the linking root SOP's rotation relative to the new root prim |
2092 | Quaternion oldRot = linkPart.RotationOffset; | 2839 | Quaternion oldRot = linkPart.RotationOffset; |
2093 | Quaternion newRot = Quaternion.Inverse(parentRot) * oldRot; | 2840 | Quaternion newRot = Quaternion.Conjugate(parentRot) * oldRot; |
2094 | linkPart.RotationOffset = newRot; | 2841 | linkPart.RotationOffset = newRot; |
2095 | 2842 | ||
2096 | // If there is only one SOP in a SOG, the LinkNum is zero. I.e., not a linkset. | 2843 | // If there is only one SOP in a SOG, the LinkNum is zero. I.e., not a linkset. |
@@ -2124,7 +2871,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2124 | linkPart.CreateSelected = true; | 2871 | linkPart.CreateSelected = true; |
2125 | 2872 | ||
2126 | // let physics know preserve part volume dtc messy since UpdatePrimFlags doesn't look to parent changes for now | 2873 | // let physics know preserve part volume dtc messy since UpdatePrimFlags doesn't look to parent changes for now |
2127 | linkPart.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (linkPart.Flags & PrimFlags.Phantom) != 0), linkPart.VolumeDetectActive); | 2874 | linkPart.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (linkPart.Flags & PrimFlags.Phantom) != 0), linkPart.VolumeDetectActive, true); |
2128 | 2875 | ||
2129 | // If the added SOP is physical, also tell the physics engine about the link relationship. | 2876 | // If the added SOP is physical, also tell the physics engine about the link relationship. |
2130 | if (linkPart.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical) | 2877 | if (linkPart.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical) |
@@ -2134,6 +2881,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2134 | } | 2881 | } |
2135 | 2882 | ||
2136 | linkPart.LinkNum = linkNum++; | 2883 | linkPart.LinkNum = linkNum++; |
2884 | linkPart.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect, false); | ||
2137 | 2885 | ||
2138 | // Get a list of the SOP's in the old group in order of their linknum's. | 2886 | // Get a list of the SOP's in the old group in order of their linknum's. |
2139 | SceneObjectPart[] ogParts = objectGroup.Parts; | 2887 | SceneObjectPart[] ogParts = objectGroup.Parts; |
@@ -2152,7 +2900,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2152 | 2900 | ||
2153 | // Update the physics flags for the newly added SOP | 2901 | // Update the physics flags for the newly added SOP |
2154 | // (Is this necessary? LinkNonRootPart() has already called UpdatePrimFlags but with different flags!??) | 2902 | // (Is this necessary? LinkNonRootPart() has already called UpdatePrimFlags but with different flags!??) |
2155 | part.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (part.Flags & PrimFlags.Phantom) != 0), part.VolumeDetectActive); | 2903 | part.UpdatePrimFlags(grpusephys, grptemporary, (IsPhantom || (part.Flags & PrimFlags.Phantom) != 0), part.VolumeDetectActive, true); |
2156 | 2904 | ||
2157 | // If the added SOP is physical, also tell the physics engine about the link relationship. | 2905 | // If the added SOP is physical, also tell the physics engine about the link relationship. |
2158 | if (part.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical) | 2906 | if (part.PhysActor != null && m_rootPart.PhysActor != null && m_rootPart.PhysActor.IsPhysical) |
@@ -2170,7 +2918,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2170 | objectGroup.IsDeleted = true; | 2918 | objectGroup.IsDeleted = true; |
2171 | 2919 | ||
2172 | objectGroup.m_parts.Clear(); | 2920 | objectGroup.m_parts.Clear(); |
2173 | 2921 | ||
2174 | // Can't do this yet since backup still makes use of the root part without any synchronization | 2922 | // Can't do this yet since backup still makes use of the root part without any synchronization |
2175 | // objectGroup.m_rootPart = null; | 2923 | // objectGroup.m_rootPart = null; |
2176 | 2924 | ||
@@ -2184,6 +2932,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
2184 | // unmoved prims! | 2932 | // unmoved prims! |
2185 | ResetChildPrimPhysicsPositions(); | 2933 | ResetChildPrimPhysicsPositions(); |
2186 | 2934 | ||
2935 | if (m_rootPart.PhysActor != null) | ||
2936 | m_rootPart.PhysActor.Building = false; | ||
2937 | |||
2187 | //HasGroupChanged = true; | 2938 | //HasGroupChanged = true; |
2188 | //ScheduleGroupForFullUpdate(); | 2939 | //ScheduleGroupForFullUpdate(); |
2189 | } | 2940 | } |
@@ -2251,7 +3002,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
2251 | // m_log.DebugFormat( | 3002 | // m_log.DebugFormat( |
2252 | // "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}", | 3003 | // "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}", |
2253 | // linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID); | 3004 | // linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID); |
2254 | 3005 | ||
3006 | if (m_rootPart.PhysActor != null) | ||
3007 | m_rootPart.PhysActor.Building = true; | ||
3008 | |||
2255 | linkPart.ClearUndoState(); | 3009 | linkPart.ClearUndoState(); |
2256 | 3010 | ||
2257 | Vector3 worldPos = linkPart.GetWorldPosition(); | 3011 | Vector3 worldPos = linkPart.GetWorldPosition(); |
@@ -2322,6 +3076,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
2322 | 3076 | ||
2323 | // When we delete a group, we currently have to force persist to the database if the object id has changed | 3077 | // When we delete a group, we currently have to force persist to the database if the object id has changed |
2324 | // (since delete works by deleting all rows which have a given object id) | 3078 | // (since delete works by deleting all rows which have a given object id) |
3079 | |||
3080 | // this is as it seems to be in sl now | ||
3081 | if(linkPart.PhysicsShapeType == (byte)PhysShapeType.none) | ||
3082 | linkPart.PhysicsShapeType = linkPart.DefaultPhysicsShapeType(); // root prims can't have type none for now | ||
3083 | |||
3084 | if (m_rootPart.PhysActor != null) | ||
3085 | m_rootPart.PhysActor.Building = false; | ||
3086 | |||
2325 | objectGroup.HasGroupChangedDueToDelink = true; | 3087 | objectGroup.HasGroupChangedDueToDelink = true; |
2326 | 3088 | ||
2327 | return objectGroup; | 3089 | return objectGroup; |
@@ -2333,6 +3095,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
2333 | /// <param name="objectGroup"></param> | 3095 | /// <param name="objectGroup"></param> |
2334 | public virtual void DetachFromBackup() | 3096 | public virtual void DetachFromBackup() |
2335 | { | 3097 | { |
3098 | if (m_scene != null) | ||
3099 | m_scene.SceneGraph.FireDetachFromBackup(this); | ||
2336 | if (m_isBackedUp && Scene != null) | 3100 | if (m_isBackedUp && Scene != null) |
2337 | m_scene.EventManager.OnBackup -= ProcessBackup; | 3101 | m_scene.EventManager.OnBackup -= ProcessBackup; |
2338 | 3102 | ||
@@ -2353,7 +3117,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
2353 | Vector3 axPos = part.OffsetPosition; | 3117 | Vector3 axPos = part.OffsetPosition; |
2354 | axPos *= parentRot; | 3118 | axPos *= parentRot; |
2355 | part.OffsetPosition = axPos; | 3119 | part.OffsetPosition = axPos; |
2356 | part.GroupPosition = oldGroupPosition + part.OffsetPosition; | 3120 | Vector3 newPos = oldGroupPosition + part.OffsetPosition; |
3121 | part.GroupPosition = newPos; | ||
2357 | part.OffsetPosition = Vector3.Zero; | 3122 | part.OffsetPosition = Vector3.Zero; |
2358 | 3123 | ||
2359 | // Compution our rotation to be not relative to the old parent | 3124 | // Compution our rotation to be not relative to the old parent |
@@ -2368,7 +3133,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2368 | part.LinkNum = linkNum; | 3133 | part.LinkNum = linkNum; |
2369 | 3134 | ||
2370 | // Compute the new position of this SOP relative to the group position | 3135 | // Compute the new position of this SOP relative to the group position |
2371 | part.OffsetPosition = part.GroupPosition - AbsolutePosition; | 3136 | part.OffsetPosition = newPos - AbsolutePosition; |
2372 | 3137 | ||
2373 | // (radams1 20120711: I don't know why part.OffsetPosition is set multiple times. | 3138 | // (radams1 20120711: I don't know why part.OffsetPosition is set multiple times. |
2374 | // It would have the affect of setting the physics engine position multiple | 3139 | // It would have the affect of setting the physics engine position multiple |
@@ -2378,18 +3143,19 @@ namespace OpenSim.Region.Framework.Scenes | |||
2378 | // Rotate the relative position by the rotation of the group | 3143 | // Rotate the relative position by the rotation of the group |
2379 | Quaternion rootRotation = m_rootPart.RotationOffset; | 3144 | Quaternion rootRotation = m_rootPart.RotationOffset; |
2380 | Vector3 pos = part.OffsetPosition; | 3145 | Vector3 pos = part.OffsetPosition; |
2381 | pos *= Quaternion.Inverse(rootRotation); | 3146 | pos *= Quaternion.Conjugate(rootRotation); |
2382 | part.OffsetPosition = pos; | 3147 | part.OffsetPosition = pos; |
2383 | 3148 | ||
2384 | // Compute the SOP's rotation relative to the rotation of the group. | 3149 | // Compute the SOP's rotation relative to the rotation of the group. |
2385 | parentRot = m_rootPart.RotationOffset; | 3150 | parentRot = m_rootPart.RotationOffset; |
2386 | oldRot = part.RotationOffset; | 3151 | oldRot = part.RotationOffset; |
2387 | Quaternion newRot = Quaternion.Inverse(parentRot) * oldRot; | 3152 | Quaternion newRot = Quaternion.Conjugate(parentRot) * worldRot; |
2388 | part.RotationOffset = newRot; | 3153 | part.RotationOffset = newRot; |
2389 | 3154 | ||
2390 | // Since this SOP's state has changed, push those changes into the physics engine | 3155 | // Since this SOP's state has changed, push those changes into the physics engine |
2391 | // and the simulator. | 3156 | // and the simulator. |
2392 | part.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect); | 3157 | // done on caller |
3158 | // part.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect, false); | ||
2393 | } | 3159 | } |
2394 | 3160 | ||
2395 | /// <summary> | 3161 | /// <summary> |
@@ -2411,10 +3177,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
2411 | { | 3177 | { |
2412 | if (!m_rootPart.BlockGrab) | 3178 | if (!m_rootPart.BlockGrab) |
2413 | { | 3179 | { |
2414 | Vector3 llmoveforce = pos - AbsolutePosition; | 3180 | /* Vector3 llmoveforce = pos - AbsolutePosition; |
2415 | Vector3 grabforce = llmoveforce; | 3181 | Vector3 grabforce = llmoveforce; |
2416 | grabforce = (grabforce / 10) * pa.Mass; | 3182 | grabforce = (grabforce / 10) * pa.Mass; |
2417 | pa.AddForce(grabforce, true); | 3183 | */ |
3184 | // empirically convert distance diference to a impulse | ||
3185 | Vector3 grabforce = pos - AbsolutePosition; | ||
3186 | grabforce = grabforce * (pa.Mass/ 10.0f); | ||
3187 | pa.AddForce(grabforce, false); | ||
2418 | m_scene.PhysicsScene.AddPhysicsActorTaint(pa); | 3188 | m_scene.PhysicsScene.AddPhysicsActorTaint(pa); |
2419 | } | 3189 | } |
2420 | } | 3190 | } |
@@ -2610,6 +3380,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
2610 | /// <param name="SetVolumeDetect"></param> | 3380 | /// <param name="SetVolumeDetect"></param> |
2611 | public void UpdatePrimFlags(uint localID, bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVolumeDetect) | 3381 | public void UpdatePrimFlags(uint localID, bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVolumeDetect) |
2612 | { | 3382 | { |
3383 | HasGroupChanged = true; | ||
3384 | |||
2613 | SceneObjectPart selectionPart = GetPart(localID); | 3385 | SceneObjectPart selectionPart = GetPart(localID); |
2614 | 3386 | ||
2615 | if (SetTemporary && Scene != null) | 3387 | if (SetTemporary && Scene != null) |
@@ -2640,8 +3412,22 @@ namespace OpenSim.Region.Framework.Scenes | |||
2640 | } | 3412 | } |
2641 | } | 3413 | } |
2642 | 3414 | ||
2643 | for (int i = 0; i < parts.Length; i++) | 3415 | if (parts.Length > 1) |
2644 | parts[i].UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect); | 3416 | { |
3417 | m_rootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, true); | ||
3418 | |||
3419 | for (int i = 0; i < parts.Length; i++) | ||
3420 | { | ||
3421 | |||
3422 | if (parts[i].UUID != m_rootPart.UUID) | ||
3423 | parts[i].UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, true); | ||
3424 | } | ||
3425 | |||
3426 | if (m_rootPart.PhysActor != null) | ||
3427 | m_rootPart.PhysActor.Building = false; | ||
3428 | } | ||
3429 | else | ||
3430 | m_rootPart.UpdatePrimFlags(UsePhysics, SetTemporary, SetPhantom, SetVolumeDetect, false); | ||
2645 | } | 3431 | } |
2646 | } | 3432 | } |
2647 | 3433 | ||
@@ -2654,6 +3440,17 @@ namespace OpenSim.Region.Framework.Scenes | |||
2654 | } | 3440 | } |
2655 | } | 3441 | } |
2656 | 3442 | ||
3443 | |||
3444 | |||
3445 | /// <summary> | ||
3446 | /// Gets the number of parts | ||
3447 | /// </summary> | ||
3448 | /// <returns></returns> | ||
3449 | public int GetPartCount() | ||
3450 | { | ||
3451 | return Parts.Count(); | ||
3452 | } | ||
3453 | |||
2657 | /// <summary> | 3454 | /// <summary> |
2658 | /// Update the texture entry for this part | 3455 | /// Update the texture entry for this part |
2659 | /// </summary> | 3456 | /// </summary> |
@@ -2670,11 +3467,20 @@ namespace OpenSim.Region.Framework.Scenes | |||
2670 | 3467 | ||
2671 | public void AdjustChildPrimPermissions() | 3468 | public void AdjustChildPrimPermissions() |
2672 | { | 3469 | { |
3470 | uint newOwnerMask = (uint)PermissionMask.All & 0xfffffff8; // Mask folded bits | ||
3471 | uint foldedPerms = RootPart.OwnerMask & 3; | ||
3472 | |||
2673 | ForEachPart(part => | 3473 | ForEachPart(part => |
2674 | { | 3474 | { |
3475 | newOwnerMask &= part.BaseMask; | ||
2675 | if (part != RootPart) | 3476 | if (part != RootPart) |
2676 | part.ClonePermissions(RootPart); | 3477 | part.ClonePermissions(RootPart); |
2677 | }); | 3478 | }); |
3479 | |||
3480 | uint lockMask = ~(uint)PermissionMask.Move; | ||
3481 | uint lockBit = RootPart.OwnerMask & (uint)PermissionMask.Move; | ||
3482 | RootPart.OwnerMask = (RootPart.OwnerMask & lockBit) | ((newOwnerMask | foldedPerms) & lockMask); | ||
3483 | RootPart.ScheduleFullUpdate(); | ||
2678 | } | 3484 | } |
2679 | 3485 | ||
2680 | public void UpdatePermissions(UUID AgentID, byte field, uint localID, | 3486 | public void UpdatePermissions(UUID AgentID, byte field, uint localID, |
@@ -2682,8 +3488,24 @@ namespace OpenSim.Region.Framework.Scenes | |||
2682 | { | 3488 | { |
2683 | RootPart.UpdatePermissions(AgentID, field, localID, mask, addRemTF); | 3489 | RootPart.UpdatePermissions(AgentID, field, localID, mask, addRemTF); |
2684 | 3490 | ||
3491 | bool god = Scene.Permissions.IsGod(AgentID); | ||
3492 | |||
3493 | if (field == 1 && god) | ||
3494 | { | ||
3495 | ForEachPart(part => | ||
3496 | { | ||
3497 | part.BaseMask = RootPart.BaseMask; | ||
3498 | }); | ||
3499 | } | ||
3500 | |||
2685 | AdjustChildPrimPermissions(); | 3501 | AdjustChildPrimPermissions(); |
2686 | 3502 | ||
3503 | if (field == 1 && god) // Base mask was set. Update all child part inventories | ||
3504 | { | ||
3505 | foreach (SceneObjectPart part in Parts) | ||
3506 | part.Inventory.ApplyGodPermissions(RootPart.BaseMask); | ||
3507 | } | ||
3508 | |||
2687 | HasGroupChanged = true; | 3509 | HasGroupChanged = true; |
2688 | 3510 | ||
2689 | // Send the group's properties to all clients once all parts are updated | 3511 | // Send the group's properties to all clients once all parts are updated |
@@ -2729,8 +3551,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
2729 | 3551 | ||
2730 | PhysicsActor pa = m_rootPart.PhysActor; | 3552 | PhysicsActor pa = m_rootPart.PhysActor; |
2731 | 3553 | ||
2732 | RootPart.StoreUndoState(true); | ||
2733 | |||
2734 | if (Scene != null) | 3554 | if (Scene != null) |
2735 | { | 3555 | { |
2736 | scale.X = Math.Max(Scene.m_minNonphys, Math.Min(Scene.m_maxNonphys, scale.X)); | 3556 | scale.X = Math.Max(Scene.m_minNonphys, Math.Min(Scene.m_maxNonphys, scale.X)); |
@@ -2758,7 +3578,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
2758 | SceneObjectPart obPart = parts[i]; | 3578 | SceneObjectPart obPart = parts[i]; |
2759 | if (obPart.UUID != m_rootPart.UUID) | 3579 | if (obPart.UUID != m_rootPart.UUID) |
2760 | { | 3580 | { |
2761 | // obPart.IgnoreUndoUpdate = true; | ||
2762 | Vector3 oldSize = new Vector3(obPart.Scale); | 3581 | Vector3 oldSize = new Vector3(obPart.Scale); |
2763 | 3582 | ||
2764 | float f = 1.0f; | 3583 | float f = 1.0f; |
@@ -2870,8 +3689,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
2870 | z *= a; | 3689 | z *= a; |
2871 | } | 3690 | } |
2872 | } | 3691 | } |
2873 | |||
2874 | // obPart.IgnoreUndoUpdate = false; | ||
2875 | } | 3692 | } |
2876 | } | 3693 | } |
2877 | } | 3694 | } |
@@ -2881,9 +3698,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
2881 | prevScale.Y *= y; | 3698 | prevScale.Y *= y; |
2882 | prevScale.Z *= z; | 3699 | prevScale.Z *= z; |
2883 | 3700 | ||
2884 | // RootPart.IgnoreUndoUpdate = true; | ||
2885 | RootPart.Resize(prevScale); | 3701 | RootPart.Resize(prevScale); |
2886 | // RootPart.IgnoreUndoUpdate = false; | ||
2887 | 3702 | ||
2888 | for (int i = 0; i < parts.Length; i++) | 3703 | for (int i = 0; i < parts.Length; i++) |
2889 | { | 3704 | { |
@@ -2891,8 +3706,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
2891 | 3706 | ||
2892 | if (obPart.UUID != m_rootPart.UUID) | 3707 | if (obPart.UUID != m_rootPart.UUID) |
2893 | { | 3708 | { |
2894 | obPart.IgnoreUndoUpdate = true; | ||
2895 | |||
2896 | Vector3 currentpos = new Vector3(obPart.OffsetPosition); | 3709 | Vector3 currentpos = new Vector3(obPart.OffsetPosition); |
2897 | currentpos.X *= x; | 3710 | currentpos.X *= x; |
2898 | currentpos.Y *= y; | 3711 | currentpos.Y *= y; |
@@ -2905,16 +3718,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
2905 | 3718 | ||
2906 | obPart.Resize(newSize); | 3719 | obPart.Resize(newSize); |
2907 | obPart.UpdateOffSet(currentpos); | 3720 | obPart.UpdateOffSet(currentpos); |
2908 | |||
2909 | obPart.IgnoreUndoUpdate = false; | ||
2910 | } | 3721 | } |
2911 | 3722 | ||
2912 | // obPart.IgnoreUndoUpdate = false; | 3723 | HasGroupChanged = true; |
2913 | // obPart.StoreUndoState(); | 3724 | m_rootPart.TriggerScriptChangedEvent(Changed.SCALE); |
3725 | ScheduleGroupForTerseUpdate(); | ||
2914 | } | 3726 | } |
2915 | |||
2916 | // m_log.DebugFormat( | ||
2917 | // "[SCENE OBJECT GROUP]: Finished group resizing {0} {1} to {2}", Name, LocalId, RootPart.Scale); | ||
2918 | } | 3727 | } |
2919 | 3728 | ||
2920 | #endregion | 3729 | #endregion |
@@ -2927,14 +3736,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
2927 | /// <param name="pos"></param> | 3736 | /// <param name="pos"></param> |
2928 | public void UpdateGroupPosition(Vector3 pos) | 3737 | public void UpdateGroupPosition(Vector3 pos) |
2929 | { | 3738 | { |
2930 | // m_log.DebugFormat("[SCENE OBJECT GROUP]: Updating group position on {0} {1} to {2}", Name, LocalId, pos); | ||
2931 | |||
2932 | RootPart.StoreUndoState(true); | ||
2933 | |||
2934 | // SceneObjectPart[] parts = m_parts.GetArray(); | ||
2935 | // for (int i = 0; i < parts.Length; i++) | ||
2936 | // parts[i].StoreUndoState(); | ||
2937 | |||
2938 | if (m_scene.EventManager.TriggerGroupMove(UUID, pos)) | 3739 | if (m_scene.EventManager.TriggerGroupMove(UUID, pos)) |
2939 | { | 3740 | { |
2940 | if (IsAttachment) | 3741 | if (IsAttachment) |
@@ -2967,21 +3768,17 @@ namespace OpenSim.Region.Framework.Scenes | |||
2967 | /// </summary> | 3768 | /// </summary> |
2968 | /// <param name="pos"></param> | 3769 | /// <param name="pos"></param> |
2969 | /// <param name="localID"></param> | 3770 | /// <param name="localID"></param> |
3771 | /// | ||
3772 | |||
2970 | public void UpdateSinglePosition(Vector3 pos, uint localID) | 3773 | public void UpdateSinglePosition(Vector3 pos, uint localID) |
2971 | { | 3774 | { |
2972 | SceneObjectPart part = GetPart(localID); | 3775 | SceneObjectPart part = GetPart(localID); |
2973 | 3776 | ||
2974 | // SceneObjectPart[] parts = m_parts.GetArray(); | ||
2975 | // for (int i = 0; i < parts.Length; i++) | ||
2976 | // parts[i].StoreUndoState(); | ||
2977 | |||
2978 | if (part != null) | 3777 | if (part != null) |
2979 | { | 3778 | { |
2980 | // m_log.DebugFormat( | 3779 | // unlock parts position change |
2981 | // "[SCENE OBJECT GROUP]: Updating single position of {0} {1} to {2}", part.Name, part.LocalId, pos); | 3780 | if (m_rootPart.PhysActor != null) |
2982 | 3781 | m_rootPart.PhysActor.Building = true; | |
2983 | part.StoreUndoState(false); | ||
2984 | part.IgnoreUndoUpdate = true; | ||
2985 | 3782 | ||
2986 | if (part.UUID == m_rootPart.UUID) | 3783 | if (part.UUID == m_rootPart.UUID) |
2987 | { | 3784 | { |
@@ -2992,8 +3789,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
2992 | part.UpdateOffSet(pos); | 3789 | part.UpdateOffSet(pos); |
2993 | } | 3790 | } |
2994 | 3791 | ||
3792 | if (m_rootPart.PhysActor != null) | ||
3793 | m_rootPart.PhysActor.Building = false; | ||
3794 | |||
2995 | HasGroupChanged = true; | 3795 | HasGroupChanged = true; |
2996 | part.IgnoreUndoUpdate = false; | ||
2997 | } | 3796 | } |
2998 | } | 3797 | } |
2999 | 3798 | ||
@@ -3003,13 +3802,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
3003 | /// <param name="pos"></param> | 3802 | /// <param name="pos"></param> |
3004 | public void UpdateRootPosition(Vector3 pos) | 3803 | public void UpdateRootPosition(Vector3 pos) |
3005 | { | 3804 | { |
3006 | // m_log.DebugFormat( | 3805 | // needs to be called with phys building true |
3007 | // "[SCENE OBJECT GROUP]: Updating root position of {0} {1} to {2}", Name, LocalId, pos); | ||
3008 | |||
3009 | // SceneObjectPart[] parts = m_parts.GetArray(); | ||
3010 | // for (int i = 0; i < parts.Length; i++) | ||
3011 | // parts[i].StoreUndoState(); | ||
3012 | |||
3013 | Vector3 newPos = new Vector3(pos.X, pos.Y, pos.Z); | 3806 | Vector3 newPos = new Vector3(pos.X, pos.Y, pos.Z); |
3014 | Vector3 oldPos = | 3807 | Vector3 oldPos = |
3015 | new Vector3(AbsolutePosition.X + m_rootPart.OffsetPosition.X, | 3808 | new Vector3(AbsolutePosition.X + m_rootPart.OffsetPosition.X, |
@@ -3032,7 +3825,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
3032 | AbsolutePosition = newPos; | 3825 | AbsolutePosition = newPos; |
3033 | 3826 | ||
3034 | HasGroupChanged = true; | 3827 | HasGroupChanged = true; |
3035 | ScheduleGroupForTerseUpdate(); | 3828 | if (m_rootPart.Undoing) |
3829 | { | ||
3830 | ScheduleGroupForFullUpdate(); | ||
3831 | } | ||
3832 | else | ||
3833 | { | ||
3834 | ScheduleGroupForTerseUpdate(); | ||
3835 | } | ||
3036 | } | 3836 | } |
3037 | 3837 | ||
3038 | #endregion | 3838 | #endregion |
@@ -3045,24 +3845,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
3045 | /// <param name="rot"></param> | 3845 | /// <param name="rot"></param> |
3046 | public void UpdateGroupRotationR(Quaternion rot) | 3846 | public void UpdateGroupRotationR(Quaternion rot) |
3047 | { | 3847 | { |
3048 | // m_log.DebugFormat( | ||
3049 | // "[SCENE OBJECT GROUP]: Updating group rotation R of {0} {1} to {2}", Name, LocalId, rot); | ||
3050 | |||
3051 | // SceneObjectPart[] parts = m_parts.GetArray(); | ||
3052 | // for (int i = 0; i < parts.Length; i++) | ||
3053 | // parts[i].StoreUndoState(); | ||
3054 | |||
3055 | m_rootPart.StoreUndoState(true); | ||
3056 | |||
3057 | m_rootPart.UpdateRotation(rot); | 3848 | m_rootPart.UpdateRotation(rot); |
3058 | 3849 | ||
3850 | /* this is done by rootpart RotationOffset set called by UpdateRotation | ||
3059 | PhysicsActor actor = m_rootPart.PhysActor; | 3851 | PhysicsActor actor = m_rootPart.PhysActor; |
3060 | if (actor != null) | 3852 | if (actor != null) |
3061 | { | 3853 | { |
3062 | actor.Orientation = m_rootPart.RotationOffset; | 3854 | actor.Orientation = m_rootPart.RotationOffset; |
3063 | m_scene.PhysicsScene.AddPhysicsActorTaint(actor); | 3855 | m_scene.PhysicsScene.AddPhysicsActorTaint(actor); |
3064 | } | 3856 | } |
3065 | 3857 | */ | |
3066 | HasGroupChanged = true; | 3858 | HasGroupChanged = true; |
3067 | ScheduleGroupForTerseUpdate(); | 3859 | ScheduleGroupForTerseUpdate(); |
3068 | } | 3860 | } |
@@ -3074,16 +3866,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
3074 | /// <param name="rot"></param> | 3866 | /// <param name="rot"></param> |
3075 | public void UpdateGroupRotationPR(Vector3 pos, Quaternion rot) | 3867 | public void UpdateGroupRotationPR(Vector3 pos, Quaternion rot) |
3076 | { | 3868 | { |
3077 | // m_log.DebugFormat( | ||
3078 | // "[SCENE OBJECT GROUP]: Updating group rotation PR of {0} {1} to {2}", Name, LocalId, rot); | ||
3079 | |||
3080 | // SceneObjectPart[] parts = m_parts.GetArray(); | ||
3081 | // for (int i = 0; i < parts.Length; i++) | ||
3082 | // parts[i].StoreUndoState(); | ||
3083 | |||
3084 | RootPart.StoreUndoState(true); | ||
3085 | RootPart.IgnoreUndoUpdate = true; | ||
3086 | |||
3087 | m_rootPart.UpdateRotation(rot); | 3869 | m_rootPart.UpdateRotation(rot); |
3088 | 3870 | ||
3089 | PhysicsActor actor = m_rootPart.PhysActor; | 3871 | PhysicsActor actor = m_rootPart.PhysActor; |
@@ -3102,8 +3884,6 @@ namespace OpenSim.Region.Framework.Scenes | |||
3102 | 3884 | ||
3103 | HasGroupChanged = true; | 3885 | HasGroupChanged = true; |
3104 | ScheduleGroupForTerseUpdate(); | 3886 | ScheduleGroupForTerseUpdate(); |
3105 | |||
3106 | RootPart.IgnoreUndoUpdate = false; | ||
3107 | } | 3887 | } |
3108 | 3888 | ||
3109 | /// <summary> | 3889 | /// <summary> |
@@ -3116,13 +3896,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
3116 | SceneObjectPart part = GetPart(localID); | 3896 | SceneObjectPart part = GetPart(localID); |
3117 | 3897 | ||
3118 | SceneObjectPart[] parts = m_parts.GetArray(); | 3898 | SceneObjectPart[] parts = m_parts.GetArray(); |
3119 | for (int i = 0; i < parts.Length; i++) | ||
3120 | parts[i].StoreUndoState(); | ||
3121 | 3899 | ||
3122 | if (part != null) | 3900 | if (part != null) |
3123 | { | 3901 | { |
3124 | // m_log.DebugFormat( | 3902 | if (m_rootPart.PhysActor != null) |
3125 | // "[SCENE OBJECT GROUP]: Updating single rotation of {0} {1} to {2}", part.Name, part.LocalId, rot); | 3903 | m_rootPart.PhysActor.Building = true; |
3126 | 3904 | ||
3127 | if (part.UUID == m_rootPart.UUID) | 3905 | if (part.UUID == m_rootPart.UUID) |
3128 | { | 3906 | { |
@@ -3132,6 +3910,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
3132 | { | 3910 | { |
3133 | part.UpdateRotation(rot); | 3911 | part.UpdateRotation(rot); |
3134 | } | 3912 | } |
3913 | |||
3914 | if (m_rootPart.PhysActor != null) | ||
3915 | m_rootPart.PhysActor.Building = false; | ||
3135 | } | 3916 | } |
3136 | } | 3917 | } |
3137 | 3918 | ||
@@ -3145,12 +3926,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
3145 | SceneObjectPart part = GetPart(localID); | 3926 | SceneObjectPart part = GetPart(localID); |
3146 | if (part != null) | 3927 | if (part != null) |
3147 | { | 3928 | { |
3148 | // m_log.DebugFormat( | 3929 | if (m_rootPart.PhysActor != null) |
3149 | // "[SCENE OBJECT GROUP]: Updating single position and rotation of {0} {1} to {2}", | 3930 | m_rootPart.PhysActor.Building = true; |
3150 | // part.Name, part.LocalId, rot); | ||
3151 | |||
3152 | part.StoreUndoState(); | ||
3153 | part.IgnoreUndoUpdate = true; | ||
3154 | 3931 | ||
3155 | if (part.UUID == m_rootPart.UUID) | 3932 | if (part.UUID == m_rootPart.UUID) |
3156 | { | 3933 | { |
@@ -3163,7 +3940,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
3163 | part.OffsetPosition = pos; | 3940 | part.OffsetPosition = pos; |
3164 | } | 3941 | } |
3165 | 3942 | ||
3166 | part.IgnoreUndoUpdate = false; | 3943 | if (m_rootPart.PhysActor != null) |
3944 | m_rootPart.PhysActor.Building = false; | ||
3167 | } | 3945 | } |
3168 | } | 3946 | } |
3169 | 3947 | ||
@@ -3173,15 +3951,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
3173 | /// <param name="rot"></param> | 3951 | /// <param name="rot"></param> |
3174 | public void UpdateRootRotation(Quaternion rot) | 3952 | public void UpdateRootRotation(Quaternion rot) |
3175 | { | 3953 | { |
3176 | // m_log.DebugFormat( | 3954 | // needs to be called with phys building true |
3177 | // "[SCENE OBJECT GROUP]: Updating root rotation of {0} {1} to {2}", | ||
3178 | // Name, LocalId, rot); | ||
3179 | |||
3180 | Quaternion axRot = rot; | 3955 | Quaternion axRot = rot; |
3181 | Quaternion oldParentRot = m_rootPart.RotationOffset; | 3956 | Quaternion oldParentRot = m_rootPart.RotationOffset; |
3182 | 3957 | ||
3183 | m_rootPart.StoreUndoState(); | 3958 | //Don't use UpdateRotation because it schedules an update prematurely |
3184 | m_rootPart.UpdateRotation(rot); | 3959 | m_rootPart.RotationOffset = rot; |
3185 | 3960 | ||
3186 | PhysicsActor pa = m_rootPart.PhysActor; | 3961 | PhysicsActor pa = m_rootPart.PhysActor; |
3187 | 3962 | ||
@@ -3197,35 +3972,145 @@ namespace OpenSim.Region.Framework.Scenes | |||
3197 | SceneObjectPart prim = parts[i]; | 3972 | SceneObjectPart prim = parts[i]; |
3198 | if (prim.UUID != m_rootPart.UUID) | 3973 | if (prim.UUID != m_rootPart.UUID) |
3199 | { | 3974 | { |
3200 | prim.IgnoreUndoUpdate = true; | 3975 | Quaternion NewRot = oldParentRot * prim.RotationOffset; |
3976 | NewRot = Quaternion.Inverse(axRot) * NewRot; | ||
3977 | prim.RotationOffset = NewRot; | ||
3978 | |||
3201 | Vector3 axPos = prim.OffsetPosition; | 3979 | Vector3 axPos = prim.OffsetPosition; |
3980 | |||
3202 | axPos *= oldParentRot; | 3981 | axPos *= oldParentRot; |
3203 | axPos *= Quaternion.Inverse(axRot); | 3982 | axPos *= Quaternion.Inverse(axRot); |
3204 | prim.OffsetPosition = axPos; | 3983 | prim.OffsetPosition = axPos; |
3205 | Quaternion primsRot = prim.RotationOffset; | 3984 | } |
3206 | Quaternion newRot = oldParentRot * primsRot; | 3985 | } |
3207 | newRot = Quaternion.Inverse(axRot) * newRot; | ||
3208 | prim.RotationOffset = newRot; | ||
3209 | prim.ScheduleTerseUpdate(); | ||
3210 | prim.IgnoreUndoUpdate = false; | ||
3211 | } | ||
3212 | } | ||
3213 | |||
3214 | // for (int i = 0; i < parts.Length; i++) | ||
3215 | // { | ||
3216 | // SceneObjectPart childpart = parts[i]; | ||
3217 | // if (childpart != m_rootPart) | ||
3218 | // { | ||
3219 | //// childpart.IgnoreUndoUpdate = false; | ||
3220 | //// childpart.StoreUndoState(); | ||
3221 | // } | ||
3222 | // } | ||
3223 | 3986 | ||
3224 | m_rootPart.ScheduleTerseUpdate(); | 3987 | HasGroupChanged = true; |
3988 | ScheduleGroupForFullUpdate(); | ||
3989 | } | ||
3225 | 3990 | ||
3226 | // m_log.DebugFormat( | 3991 | private enum updatetype :int |
3227 | // "[SCENE OBJECT GROUP]: Updated root rotation of {0} {1} to {2}", | 3992 | { |
3228 | // Name, LocalId, rot); | 3993 | none = 0, |
3994 | partterse = 1, | ||
3995 | partfull = 2, | ||
3996 | groupterse = 3, | ||
3997 | groupfull = 4 | ||
3998 | } | ||
3999 | |||
4000 | public void doChangeObject(SceneObjectPart part, ObjectChangeData data) | ||
4001 | { | ||
4002 | // TODO this still as excessive *.Schedule*Update()s | ||
4003 | |||
4004 | if (part != null && part.ParentGroup != null) | ||
4005 | { | ||
4006 | ObjectChangeType change = data.change; | ||
4007 | bool togroup = ((change & ObjectChangeType.Group) != 0); | ||
4008 | // bool uniform = ((what & ObjectChangeType.UniformScale) != 0); not in use | ||
4009 | |||
4010 | SceneObjectGroup group = part.ParentGroup; | ||
4011 | PhysicsActor pha = group.RootPart.PhysActor; | ||
4012 | |||
4013 | updatetype updateType = updatetype.none; | ||
4014 | |||
4015 | if (togroup) | ||
4016 | { | ||
4017 | // related to group | ||
4018 | if ((change & (ObjectChangeType.Rotation | ObjectChangeType.Position)) != 0) | ||
4019 | { | ||
4020 | if ((change & ObjectChangeType.Rotation) != 0) | ||
4021 | { | ||
4022 | group.RootPart.UpdateRotation(data.rotation); | ||
4023 | updateType = updatetype.none; | ||
4024 | } | ||
4025 | if ((change & ObjectChangeType.Position) != 0) | ||
4026 | { | ||
4027 | if (IsAttachment || m_scene.Permissions.CanObjectEntry(group.UUID, false, data.position)) | ||
4028 | UpdateGroupPosition(data.position); | ||
4029 | updateType = updatetype.groupterse; | ||
4030 | } | ||
4031 | else | ||
4032 | // ugly rotation update of all parts | ||
4033 | { | ||
4034 | group.ResetChildPrimPhysicsPositions(); | ||
4035 | } | ||
4036 | |||
4037 | } | ||
4038 | if ((change & ObjectChangeType.Scale) != 0) | ||
4039 | { | ||
4040 | if (pha != null) | ||
4041 | pha.Building = true; | ||
4042 | |||
4043 | group.GroupResize(data.scale); | ||
4044 | updateType = updatetype.none; | ||
4045 | |||
4046 | if (pha != null) | ||
4047 | pha.Building = false; | ||
4048 | } | ||
4049 | } | ||
4050 | else | ||
4051 | { | ||
4052 | // related to single prim in a link-set ( ie group) | ||
4053 | if (pha != null) | ||
4054 | pha.Building = true; | ||
4055 | |||
4056 | // root part is special | ||
4057 | // parts offset positions or rotations need to change also | ||
4058 | |||
4059 | if (part == group.RootPart) | ||
4060 | { | ||
4061 | if ((change & ObjectChangeType.Rotation) != 0) | ||
4062 | group.UpdateRootRotation(data.rotation); | ||
4063 | if ((change & ObjectChangeType.Position) != 0) | ||
4064 | group.UpdateRootPosition(data.position); | ||
4065 | if ((change & ObjectChangeType.Scale) != 0) | ||
4066 | part.Resize(data.scale); | ||
4067 | } | ||
4068 | else | ||
4069 | { | ||
4070 | if ((change & ObjectChangeType.Position) != 0) | ||
4071 | { | ||
4072 | part.OffsetPosition = data.position; | ||
4073 | updateType = updatetype.partterse; | ||
4074 | } | ||
4075 | if ((change & ObjectChangeType.Rotation) != 0) | ||
4076 | { | ||
4077 | part.UpdateRotation(data.rotation); | ||
4078 | updateType = updatetype.none; | ||
4079 | } | ||
4080 | if ((change & ObjectChangeType.Scale) != 0) | ||
4081 | { | ||
4082 | part.Resize(data.scale); | ||
4083 | updateType = updatetype.none; | ||
4084 | } | ||
4085 | } | ||
4086 | |||
4087 | if (pha != null) | ||
4088 | pha.Building = false; | ||
4089 | } | ||
4090 | |||
4091 | if (updateType != updatetype.none) | ||
4092 | { | ||
4093 | group.HasGroupChanged = true; | ||
4094 | |||
4095 | switch (updateType) | ||
4096 | { | ||
4097 | case updatetype.partterse: | ||
4098 | part.ScheduleTerseUpdate(); | ||
4099 | break; | ||
4100 | case updatetype.partfull: | ||
4101 | part.ScheduleFullUpdate(); | ||
4102 | break; | ||
4103 | case updatetype.groupterse: | ||
4104 | group.ScheduleGroupForTerseUpdate(); | ||
4105 | break; | ||
4106 | case updatetype.groupfull: | ||
4107 | group.ScheduleGroupForFullUpdate(); | ||
4108 | break; | ||
4109 | default: | ||
4110 | break; | ||
4111 | } | ||
4112 | } | ||
4113 | } | ||
3229 | } | 4114 | } |
3230 | 4115 | ||
3231 | #endregion | 4116 | #endregion |
@@ -3266,6 +4151,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
3266 | waypoint.handle = handle; | 4151 | waypoint.handle = handle; |
3267 | lock (m_rotTargets) | 4152 | lock (m_rotTargets) |
3268 | { | 4153 | { |
4154 | if (m_rotTargets.Count >= 8) | ||
4155 | m_rotTargets.Remove(m_rotTargets.ElementAt(0).Key); | ||
3269 | m_rotTargets.Add(handle, waypoint); | 4156 | m_rotTargets.Add(handle, waypoint); |
3270 | } | 4157 | } |
3271 | m_scene.AddGroupTarget(this); | 4158 | m_scene.AddGroupTarget(this); |
@@ -3291,6 +4178,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
3291 | waypoint.handle = handle; | 4178 | waypoint.handle = handle; |
3292 | lock (m_targets) | 4179 | lock (m_targets) |
3293 | { | 4180 | { |
4181 | if (m_targets.Count >= 8) | ||
4182 | m_targets.Remove(m_targets.ElementAt(0).Key); | ||
3294 | m_targets.Add(handle, waypoint); | 4183 | m_targets.Add(handle, waypoint); |
3295 | } | 4184 | } |
3296 | m_scene.AddGroupTarget(this); | 4185 | m_scene.AddGroupTarget(this); |
@@ -3324,10 +4213,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
3324 | scriptPosTarget target = m_targets[idx]; | 4213 | scriptPosTarget target = m_targets[idx]; |
3325 | if (Util.GetDistanceTo(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance) | 4214 | if (Util.GetDistanceTo(target.targetPos, m_rootPart.GroupPosition) <= target.tolerance) |
3326 | { | 4215 | { |
4216 | at_target = true; | ||
4217 | |||
3327 | // trigger at_target | 4218 | // trigger at_target |
3328 | if (m_scriptListens_atTarget) | 4219 | if (m_scriptListens_atTarget) |
3329 | { | 4220 | { |
3330 | at_target = true; | ||
3331 | scriptPosTarget att = new scriptPosTarget(); | 4221 | scriptPosTarget att = new scriptPosTarget(); |
3332 | att.targetPos = target.targetPos; | 4222 | att.targetPos = target.targetPos; |
3333 | att.tolerance = target.tolerance; | 4223 | att.tolerance = target.tolerance; |
@@ -3445,11 +4335,50 @@ namespace OpenSim.Region.Framework.Scenes | |||
3445 | } | 4335 | } |
3446 | } | 4336 | } |
3447 | } | 4337 | } |
3448 | 4338 | ||
4339 | public Vector3 GetGeometricCenter() | ||
4340 | { | ||
4341 | // this is not real geometric center but a average of positions relative to root prim acording to | ||
4342 | // http://wiki.secondlife.com/wiki/llGetGeometricCenter | ||
4343 | // ignoring tortured prims details since sl also seems to ignore | ||
4344 | // so no real use in doing it on physics | ||
4345 | |||
4346 | Vector3 gc = Vector3.Zero; | ||
4347 | |||
4348 | int nparts = m_parts.Count; | ||
4349 | if (nparts <= 1) | ||
4350 | return gc; | ||
4351 | |||
4352 | SceneObjectPart[] parts = m_parts.GetArray(); | ||
4353 | nparts = parts.Length; // just in case it changed | ||
4354 | if (nparts <= 1) | ||
4355 | return gc; | ||
4356 | |||
4357 | Quaternion parentRot = RootPart.RotationOffset; | ||
4358 | Vector3 pPos; | ||
4359 | |||
4360 | // average all parts positions | ||
4361 | for (int i = 0; i < nparts; i++) | ||
4362 | { | ||
4363 | // do it directly | ||
4364 | // gc += parts[i].GetWorldPosition(); | ||
4365 | if (parts[i] != RootPart) | ||
4366 | { | ||
4367 | pPos = parts[i].OffsetPosition; | ||
4368 | gc += pPos; | ||
4369 | } | ||
4370 | |||
4371 | } | ||
4372 | gc /= nparts; | ||
4373 | |||
4374 | // relative to root: | ||
4375 | // gc -= AbsolutePosition; | ||
4376 | return gc; | ||
4377 | } | ||
4378 | |||
3449 | public float GetMass() | 4379 | public float GetMass() |
3450 | { | 4380 | { |
3451 | float retmass = 0f; | 4381 | float retmass = 0f; |
3452 | |||
3453 | SceneObjectPart[] parts = m_parts.GetArray(); | 4382 | SceneObjectPart[] parts = m_parts.GetArray(); |
3454 | for (int i = 0; i < parts.Length; i++) | 4383 | for (int i = 0; i < parts.Length; i++) |
3455 | retmass += parts[i].GetMass(); | 4384 | retmass += parts[i].GetMass(); |
@@ -3457,6 +4386,39 @@ namespace OpenSim.Region.Framework.Scenes | |||
3457 | return retmass; | 4386 | return retmass; |
3458 | } | 4387 | } |
3459 | 4388 | ||
4389 | // center of mass of full object | ||
4390 | public Vector3 GetCenterOfMass() | ||
4391 | { | ||
4392 | PhysicsActor pa = RootPart.PhysActor; | ||
4393 | |||
4394 | if(((RootPart.Flags & PrimFlags.Physics) !=0) && pa !=null) | ||
4395 | { | ||
4396 | // physics knows better about center of mass of physical prims | ||
4397 | Vector3 tmp = pa.CenterOfMass; | ||
4398 | return tmp; | ||
4399 | } | ||
4400 | |||
4401 | Vector3 Ptot = Vector3.Zero; | ||
4402 | float totmass = 0f; | ||
4403 | float m; | ||
4404 | |||
4405 | SceneObjectPart[] parts = m_parts.GetArray(); | ||
4406 | for (int i = 0; i < parts.Length; i++) | ||
4407 | { | ||
4408 | m = parts[i].GetMass(); | ||
4409 | Ptot += parts[i].GetPartCenterOfMass() * m; | ||
4410 | totmass += m; | ||
4411 | } | ||
4412 | |||
4413 | if (totmass == 0) | ||
4414 | totmass = 0; | ||
4415 | else | ||
4416 | totmass = 1 / totmass; | ||
4417 | Ptot *= totmass; | ||
4418 | |||
4419 | return Ptot; | ||
4420 | } | ||
4421 | |||
3460 | /// <summary> | 4422 | /// <summary> |
3461 | /// If the object is a sculpt/mesh, retrieve the mesh data for each part and reinsert it into each shape so that | 4423 | /// If the object is a sculpt/mesh, retrieve the mesh data for each part and reinsert it into each shape so that |
3462 | /// the physics engine can use it. | 4424 | /// the physics engine can use it. |
@@ -3636,6 +4598,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
3636 | FromItemID = uuid; | 4598 | FromItemID = uuid; |
3637 | } | 4599 | } |
3638 | 4600 | ||
4601 | public void ResetOwnerChangeFlag() | ||
4602 | { | ||
4603 | ForEachPart(delegate(SceneObjectPart part) | ||
4604 | { | ||
4605 | part.ResetOwnerChangeFlag(); | ||
4606 | }); | ||
4607 | } | ||
4608 | |||
3639 | #endregion | 4609 | #endregion |
3640 | } | 4610 | } |
3641 | } | 4611 | } |