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