aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneObjectPart.cs')
-rw-r--r--OpenSim/Region/Framework/Scenes/SceneObjectPart.cs1716
1 files changed, 1204 insertions, 512 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index 7a97e5f..143a339 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -62,7 +62,8 @@ namespace OpenSim.Region.Framework.Scenes
62 TELEPORT = 512, 62 TELEPORT = 512,
63 REGION_RESTART = 1024, 63 REGION_RESTART = 1024,
64 MEDIA = 2048, 64 MEDIA = 2048,
65 ANIMATION = 16384 65 ANIMATION = 16384,
66 POSITION = 32768
66 } 67 }
67 68
68 // I don't really know where to put this except here. 69 // I don't really know where to put this except here.
@@ -121,7 +122,18 @@ namespace OpenSim.Region.Framework.Scenes
121 /// Denote all sides of the prim 122 /// Denote all sides of the prim
122 /// </value> 123 /// </value>
123 public const int ALL_SIDES = -1; 124 public const int ALL_SIDES = -1;
124 125
126 private const scriptEvents PhysicsNeededSubsEvents = (
127 scriptEvents.collision | scriptEvents.collision_start | scriptEvents.collision_end |
128 scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end
129 );
130 private const scriptEvents PhyscicsPhantonSubsEvents = (
131 scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end
132 );
133 private const scriptEvents PhyscicsVolumeDtcSubsEvents = (
134 scriptEvents.collision_start | scriptEvents.collision_end
135 );
136
125 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 137 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
126 138
127 /// <value> 139 /// <value>
@@ -191,12 +203,25 @@ namespace OpenSim.Region.Framework.Scenes
191 203
192 public double SoundRadius; 204 public double SoundRadius;
193 205
206
194 public uint TimeStampFull; 207 public uint TimeStampFull;
195 208
196 public uint TimeStampLastActivity; // Will be used for AutoReturn 209 public uint TimeStampLastActivity; // Will be used for AutoReturn
197 210
198 public uint TimeStampTerse; 211 public uint TimeStampTerse;
199 212
213 // The following two are to hold the attachment data
214 // while an object is inworld
215 [XmlIgnore]
216 public byte AttachPoint = 0;
217
218 [XmlIgnore]
219 public Vector3 AttachOffset = Vector3.Zero;
220
221 [XmlIgnore]
222 public Quaternion AttachRotation = Quaternion.Identity;
223
224 [XmlIgnore]
200 public int STATUS_ROTATE_X; 225 public int STATUS_ROTATE_X;
201 226
202 public int STATUS_ROTATE_Y; 227 public int STATUS_ROTATE_Y;
@@ -223,8 +248,7 @@ namespace OpenSim.Region.Framework.Scenes
223 248
224 public Vector3 RotationAxis = Vector3.One; 249 public Vector3 RotationAxis = Vector3.One;
225 250
226 public bool VolumeDetectActive; // XmlIgnore set to avoid problems with persistance until I come to care for this 251 public bool VolumeDetectActive;
227 // Certainly this must be a persistant setting finally
228 252
229 public bool IsWaitingForFirstSpinUpdatePacket; 253 public bool IsWaitingForFirstSpinUpdatePacket;
230 254
@@ -264,10 +288,10 @@ namespace OpenSim.Region.Framework.Scenes
264 private Quaternion m_sitTargetOrientation = Quaternion.Identity; 288 private Quaternion m_sitTargetOrientation = Quaternion.Identity;
265 private Vector3 m_sitTargetPosition; 289 private Vector3 m_sitTargetPosition;
266 private string m_sitAnimation = "SIT"; 290 private string m_sitAnimation = "SIT";
291 private bool m_occupied; // KF if any av is sitting on this prim
267 private string m_text = String.Empty; 292 private string m_text = String.Empty;
268 private string m_touchName = String.Empty; 293 private string m_touchName = String.Empty;
269 private readonly List<UndoState> m_undo = new List<UndoState>(5); 294 private UndoRedoState m_UndoRedo = null;
270 private readonly List<UndoState> m_redo = new List<UndoState>(5);
271 295
272 private bool m_passTouches = false; 296 private bool m_passTouches = false;
273 private bool m_passCollisions = false; 297 private bool m_passCollisions = false;
@@ -296,7 +320,19 @@ namespace OpenSim.Region.Framework.Scenes
296 protected Vector3 m_lastAcceleration; 320 protected Vector3 m_lastAcceleration;
297 protected Vector3 m_lastAngularVelocity; 321 protected Vector3 m_lastAngularVelocity;
298 protected int m_lastTerseSent; 322 protected int m_lastTerseSent;
299 323 protected float m_buoyancy = 0.0f;
324 protected Vector3 m_force;
325 protected Vector3 m_torque;
326
327 protected byte m_physicsShapeType = (byte)PhysShapeType.prim;
328 protected float m_density = 1000.0f; // in kg/m^3
329 protected float m_gravitymod = 1.0f;
330 protected float m_friction = 0.6f; // wood
331 protected float m_bounce = 0.5f; // wood
332
333
334 protected bool m_isSelected = false;
335
300 /// <summary> 336 /// <summary>
301 /// Stores media texture data 337 /// Stores media texture data
302 /// </summary> 338 /// </summary>
@@ -308,10 +344,25 @@ namespace OpenSim.Region.Framework.Scenes
308 private Vector3 m_cameraAtOffset; 344 private Vector3 m_cameraAtOffset;
309 private bool m_forceMouselook; 345 private bool m_forceMouselook;
310 346
311 // TODO: Collision sound should have default. 347
348 // 0 for default collision sounds, -1 for script disabled sound 1 for script defined sound
349 private sbyte m_collisionSoundType;
312 private UUID m_collisionSound; 350 private UUID m_collisionSound;
313 private float m_collisionSoundVolume; 351 private float m_collisionSoundVolume;
314 352
353 private int LastColSoundSentTime;
354
355
356 private SOPVehicle m_vehicleParams = null;
357
358 private KeyframeMotion m_keyframeMotion = null;
359
360 public KeyframeMotion KeyframeMotion
361 {
362 get; set;
363 }
364
365
315 #endregion Fields 366 #endregion Fields
316 367
317// ~SceneObjectPart() 368// ~SceneObjectPart()
@@ -340,6 +391,7 @@ namespace OpenSim.Region.Framework.Scenes
340 // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from 391 // this appears to have the same UUID (!) as the prim. If this isn't the case, one can't drag items from
341 // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log 392 // the prim into an agent inventory (Linden client reports that the "Object not found for drop" in its log
342 m_inventory = new SceneObjectPartInventory(this); 393 m_inventory = new SceneObjectPartInventory(this);
394 LastColSoundSentTime = Util.EnvironmentTickCount();
343 } 395 }
344 396
345 /// <summary> 397 /// <summary>
@@ -354,7 +406,7 @@ namespace OpenSim.Region.Framework.Scenes
354 UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition, 406 UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition,
355 Quaternion rotationOffset, Vector3 offsetPosition) : this() 407 Quaternion rotationOffset, Vector3 offsetPosition) : this()
356 { 408 {
357 m_name = "Primitive"; 409 m_name = "Object";
358 410
359 CreationDate = (int)Utils.DateTimeToUnixTime(Rezzed); 411 CreationDate = (int)Utils.DateTimeToUnixTime(Rezzed);
360 LastOwnerID = CreatorID = OwnerID = ownerID; 412 LastOwnerID = CreatorID = OwnerID = ownerID;
@@ -393,7 +445,7 @@ namespace OpenSim.Region.Framework.Scenes
393 private uint _ownerMask = (uint)PermissionMask.All; 445 private uint _ownerMask = (uint)PermissionMask.All;
394 private uint _groupMask = (uint)PermissionMask.None; 446 private uint _groupMask = (uint)PermissionMask.None;
395 private uint _everyoneMask = (uint)PermissionMask.None; 447 private uint _everyoneMask = (uint)PermissionMask.None;
396 private uint _nextOwnerMask = (uint)PermissionMask.All; 448 private uint _nextOwnerMask = (uint)(PermissionMask.Move | PermissionMask.Modify | PermissionMask.Transfer);
397 private PrimFlags _flags = PrimFlags.None; 449 private PrimFlags _flags = PrimFlags.None;
398 private DateTime m_expires; 450 private DateTime m_expires;
399 private DateTime m_rezzed; 451 private DateTime m_rezzed;
@@ -487,12 +539,16 @@ namespace OpenSim.Region.Framework.Scenes
487 } 539 }
488 540
489 /// <value> 541 /// <value>
490 /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes 542 /// Get the inventory list
491 /// </value> 543 /// </value>
492 public TaskInventoryDictionary TaskInventory 544 public TaskInventoryDictionary TaskInventory
493 { 545 {
494 get { return m_inventory.Items; } 546 get {
495 set { m_inventory.Items = value; } 547 return m_inventory.Items;
548 }
549 set {
550 m_inventory.Items = value;
551 }
496 } 552 }
497 553
498 /// <summary> 554 /// <summary>
@@ -542,20 +598,6 @@ namespace OpenSim.Region.Framework.Scenes
542 } 598 }
543 } 599 }
544 600
545 public byte Material
546 {
547 get { return (byte) m_material; }
548 set
549 {
550 m_material = (Material)value;
551
552 PhysicsActor pa = PhysActor;
553
554 if (pa != null)
555 pa.SetMaterial((int)value);
556 }
557 }
558
559 [XmlIgnore] 601 [XmlIgnore]
560 public bool PassTouches 602 public bool PassTouches
561 { 603 {
@@ -581,6 +623,18 @@ namespace OpenSim.Region.Framework.Scenes
581 } 623 }
582 } 624 }
583 625
626 public bool IsSelected
627 {
628 get { return m_isSelected; }
629 set
630 {
631 m_isSelected = value;
632 if (ParentGroup != null)
633 ParentGroup.PartSelectChanged(value);
634 }
635 }
636
637
584 public Dictionary<int, string> CollisionFilter 638 public Dictionary<int, string> CollisionFilter
585 { 639 {
586 get { return m_CollisionFilter; } 640 get { return m_CollisionFilter; }
@@ -649,14 +703,12 @@ namespace OpenSim.Region.Framework.Scenes
649 set { m_LoopSoundSlavePrims = value; } 703 set { m_LoopSoundSlavePrims = value; }
650 } 704 }
651 705
652
653 public Byte[] TextureAnimation 706 public Byte[] TextureAnimation
654 { 707 {
655 get { return m_TextureAnimation; } 708 get { return m_TextureAnimation; }
656 set { m_TextureAnimation = value; } 709 set { m_TextureAnimation = value; }
657 } 710 }
658 711
659
660 public Byte[] ParticleSystem 712 public Byte[] ParticleSystem
661 { 713 {
662 get { return m_particleSystem; } 714 get { return m_particleSystem; }
@@ -693,9 +745,12 @@ namespace OpenSim.Region.Framework.Scenes
693 { 745 {
694 // If this is a linkset, we don't want the physics engine mucking up our group position here. 746 // If this is a linkset, we don't want the physics engine mucking up our group position here.
695 PhysicsActor actor = PhysActor; 747 PhysicsActor actor = PhysActor;
696 // If physical and the root prim of a linkset, the position of the group is what physics thinks. 748 if (ParentID == 0)
697 if (actor != null && ParentID == 0) 749 {
698 m_groupPosition = actor.Position; 750 if (actor != null)
751 m_groupPosition = actor.Position;
752 return m_groupPosition;
753 }
699 754
700 // If I'm an attachment, my position is reported as the position of who I'm attached to 755 // If I'm an attachment, my position is reported as the position of who I'm attached to
701 if (ParentGroup.IsAttachment) 756 if (ParentGroup.IsAttachment)
@@ -705,14 +760,16 @@ namespace OpenSim.Region.Framework.Scenes
705 return sp.AbsolutePosition; 760 return sp.AbsolutePosition;
706 } 761 }
707 762
763 // use root prim's group position. Physics may have updated it
764 if (ParentGroup.RootPart != this)
765 m_groupPosition = ParentGroup.RootPart.GroupPosition;
708 return m_groupPosition; 766 return m_groupPosition;
709 } 767 }
710 set 768 set
711 { 769 {
712 m_groupPosition = value; 770 m_groupPosition = value;
713
714 PhysicsActor actor = PhysActor; 771 PhysicsActor actor = PhysActor;
715 if (actor != null) 772 if (actor != null && ParentGroup.Scene.PhysicsScene != null)
716 { 773 {
717 try 774 try
718 { 775 {
@@ -736,16 +793,6 @@ namespace OpenSim.Region.Framework.Scenes
736 m_log.ErrorFormat("[SCENEOBJECTPART]: GROUP POSITION. {0}", e); 793 m_log.ErrorFormat("[SCENEOBJECTPART]: GROUP POSITION. {0}", e);
737 } 794 }
738 } 795 }
739
740 // TODO if we decide to do sitting in a more SL compatible way (multiple avatars per prim), this has to be fixed, too
741 if (SitTargetAvatar != UUID.Zero)
742 {
743 ScenePresence avatar;
744 if (ParentGroup.Scene.TryGetScenePresence(SitTargetAvatar, out avatar))
745 {
746 avatar.ParentPosition = GetWorldPosition();
747 }
748 }
749 } 796 }
750 } 797 }
751 798
@@ -754,7 +801,7 @@ namespace OpenSim.Region.Framework.Scenes
754 get { return m_offsetPosition; } 801 get { return m_offsetPosition; }
755 set 802 set
756 { 803 {
757// StoreUndoState(); 804 Vector3 oldpos = m_offsetPosition;
758 m_offsetPosition = value; 805 m_offsetPosition = value;
759 806
760 if (ParentGroup != null && !ParentGroup.IsDeleted) 807 if (ParentGroup != null && !ParentGroup.IsDeleted)
@@ -766,10 +813,25 @@ namespace OpenSim.Region.Framework.Scenes
766 actor.Orientation = GetWorldRotation(); 813 actor.Orientation = GetWorldRotation();
767 814
768 // Tell the physics engines that this prim changed. 815 // Tell the physics engines that this prim changed.
769 if (ParentGroup.Scene != null) 816 if (ParentGroup.Scene != null && ParentGroup.Scene.PhysicsScene != null)
770 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor); 817 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
771 } 818 }
819
820 if (!m_parentGroup.m_dupeInProgress)
821 {
822 List<ScenePresence> avs = ParentGroup.GetLinkedAvatars();
823 foreach (ScenePresence av in avs)
824 {
825 if (av.ParentID == m_localId)
826 {
827 Vector3 offset = (m_offsetPosition - oldpos);
828 av.AbsolutePosition += offset;
829 av.SendAvatarDataToAllAgents();
830 }
831 }
832 }
772 } 833 }
834 TriggerScriptChangedEvent(Changed.POSITION);
773 } 835 }
774 } 836 }
775 837
@@ -820,7 +882,7 @@ namespace OpenSim.Region.Framework.Scenes
820 882
821 set 883 set
822 { 884 {
823 StoreUndoState(); 885// StoreUndoState();
824 m_rotationOffset = value; 886 m_rotationOffset = value;
825 887
826 PhysicsActor actor = PhysActor; 888 PhysicsActor actor = PhysActor;
@@ -908,19 +970,36 @@ namespace OpenSim.Region.Framework.Scenes
908 get 970 get
909 { 971 {
910 PhysicsActor actor = PhysActor; 972 PhysicsActor actor = PhysActor;
911 if ((actor != null) && actor.IsPhysical) 973 if ((actor != null) && actor.IsPhysical && ParentGroup.RootPart == this)
912 { 974 {
913 m_angularVelocity = actor.RotationalVelocity; 975 m_angularVelocity = actor.RotationalVelocity;
914 } 976 }
915 return m_angularVelocity; 977 return m_angularVelocity;
916 } 978 }
917 set { m_angularVelocity = value; } 979 set
980 {
981 m_angularVelocity = value;
982 PhysicsActor actor = PhysActor;
983 if ((actor != null) && actor.IsPhysical && ParentGroup.RootPart == this && VehicleType == (int)Vehicle.TYPE_NONE)
984 {
985 actor.RotationalVelocity = m_angularVelocity;
986 }
987 }
918 } 988 }
919 989
920 /// <summary></summary> 990 /// <summary></summary>
921 public Vector3 Acceleration 991 public Vector3 Acceleration
922 { 992 {
923 get { return m_acceleration; } 993 get
994 {
995 PhysicsActor actor = PhysActor;
996 if (actor != null)
997 {
998 m_acceleration = actor.Acceleration;
999 }
1000 return m_acceleration;
1001 }
1002
924 set { m_acceleration = value; } 1003 set { m_acceleration = value; }
925 } 1004 }
926 1005
@@ -988,7 +1067,10 @@ namespace OpenSim.Region.Framework.Scenes
988 public PrimitiveBaseShape Shape 1067 public PrimitiveBaseShape Shape
989 { 1068 {
990 get { return m_shape; } 1069 get { return m_shape; }
991 set { m_shape = value;} 1070 set
1071 {
1072 m_shape = value;
1073 }
992 } 1074 }
993 1075
994 /// <summary> 1076 /// <summary>
@@ -1001,7 +1083,6 @@ namespace OpenSim.Region.Framework.Scenes
1001 { 1083 {
1002 if (m_shape != null) 1084 if (m_shape != null)
1003 { 1085 {
1004 StoreUndoState();
1005 1086
1006 m_shape.Scale = value; 1087 m_shape.Scale = value;
1007 1088
@@ -1028,6 +1109,7 @@ namespace OpenSim.Region.Framework.Scenes
1028 } 1109 }
1029 1110
1030 public UpdateRequired UpdateFlag { get; set; } 1111 public UpdateRequired UpdateFlag { get; set; }
1112 public bool UpdatePhysRequired { get; set; }
1031 1113
1032 /// <summary> 1114 /// <summary>
1033 /// Used for media on a prim. 1115 /// Used for media on a prim.
@@ -1068,10 +1150,7 @@ namespace OpenSim.Region.Framework.Scenes
1068 { 1150 {
1069 get 1151 get
1070 { 1152 {
1071 if (ParentGroup.IsAttachment) 1153 return GroupPosition + (m_offsetPosition * ParentGroup.RootPart.RotationOffset);
1072 return GroupPosition;
1073
1074 return m_offsetPosition + m_groupPosition;
1075 } 1154 }
1076 } 1155 }
1077 1156
@@ -1249,6 +1328,13 @@ namespace OpenSim.Region.Framework.Scenes
1249 _flags = value; 1328 _flags = value;
1250 } 1329 }
1251 } 1330 }
1331
1332 [XmlIgnore]
1333 public bool IsOccupied // KF If an av is sittingon this prim
1334 {
1335 get { return m_occupied; }
1336 set { m_occupied = value; }
1337 }
1252 1338
1253 /// <summary> 1339 /// <summary>
1254 /// ID of the avatar that is sat on us if we have a sit target. If there is no such avatar then is UUID.Zero 1340 /// ID of the avatar that is sat on us if we have a sit target. If there is no such avatar then is UUID.Zero
@@ -1299,12 +1385,41 @@ namespace OpenSim.Region.Framework.Scenes
1299 set { m_sitAnimation = value; } 1385 set { m_sitAnimation = value; }
1300 } 1386 }
1301 1387
1388 public UUID invalidCollisionSoundUUID = new UUID("ffffffff-ffff-ffff-ffff-ffffffffffff");
1389
1390 // 0 for default collision sounds, -1 for script disabled sound 1 for script defined sound
1391 // runtime thing.. do not persist
1392 [XmlIgnore]
1393 public sbyte CollisionSoundType
1394 {
1395 get
1396 {
1397 return m_collisionSoundType;
1398 }
1399 set
1400 {
1401 m_collisionSoundType = value;
1402 if (value == -1)
1403 m_collisionSound = invalidCollisionSoundUUID;
1404 else if (value == 0)
1405 m_collisionSound = UUID.Zero;
1406 }
1407 }
1408
1302 public UUID CollisionSound 1409 public UUID CollisionSound
1303 { 1410 {
1304 get { return m_collisionSound; } 1411 get { return m_collisionSound; }
1305 set 1412 set
1306 { 1413 {
1307 m_collisionSound = value; 1414 m_collisionSound = value;
1415
1416 if (value == invalidCollisionSoundUUID)
1417 m_collisionSoundType = -1;
1418 else if (value == UUID.Zero)
1419 m_collisionSoundType = 0;
1420 else
1421 m_collisionSoundType = 1;
1422
1308 aggregateScriptEvents(); 1423 aggregateScriptEvents();
1309 } 1424 }
1310 } 1425 }
@@ -1315,6 +1430,324 @@ namespace OpenSim.Region.Framework.Scenes
1315 set { m_collisionSoundVolume = value; } 1430 set { m_collisionSoundVolume = value; }
1316 } 1431 }
1317 1432
1433 public float Buoyancy
1434 {
1435 get
1436 {
1437 if (ParentGroup.RootPart == this)
1438 return m_buoyancy;
1439
1440 return ParentGroup.RootPart.Buoyancy;
1441 }
1442 set
1443 {
1444 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1445 {
1446 ParentGroup.RootPart.Buoyancy = value;
1447 return;
1448 }
1449 m_buoyancy = value;
1450 if (PhysActor != null)
1451 PhysActor.Buoyancy = value;
1452 }
1453 }
1454
1455 public Vector3 Force
1456 {
1457 get
1458 {
1459 if (ParentGroup.RootPart == this)
1460 return m_force;
1461
1462 return ParentGroup.RootPart.Force;
1463 }
1464
1465 set
1466 {
1467 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1468 {
1469 ParentGroup.RootPart.Force = value;
1470 return;
1471 }
1472 m_force = value;
1473 if (PhysActor != null)
1474 PhysActor.Force = value;
1475 }
1476 }
1477
1478 public Vector3 Torque
1479 {
1480 get
1481 {
1482 if (ParentGroup.RootPart == this)
1483 return m_torque;
1484
1485 return ParentGroup.RootPart.Torque;
1486 }
1487
1488 set
1489 {
1490 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1491 {
1492 ParentGroup.RootPart.Torque = value;
1493 return;
1494 }
1495 m_torque = value;
1496 if (PhysActor != null)
1497 PhysActor.Torque = value;
1498 }
1499 }
1500
1501 public byte Material
1502 {
1503 get { return (byte)m_material; }
1504 set
1505 {
1506 if (value >= 0 && value <= (byte)SOPMaterialData.MaxMaterial)
1507 {
1508 bool update = false;
1509
1510 if (m_material != (Material)value)
1511 {
1512 update = true;
1513 m_material = (Material)value;
1514 }
1515
1516 if (m_friction != SOPMaterialData.friction(m_material))
1517 {
1518 update = true;
1519 m_friction = SOPMaterialData.friction(m_material);
1520 }
1521
1522 if (m_bounce != SOPMaterialData.bounce(m_material))
1523 {
1524 update = true;
1525 m_bounce = SOPMaterialData.bounce(m_material);
1526 }
1527
1528 if (update)
1529 {
1530 if (PhysActor != null)
1531 {
1532 PhysActor.SetMaterial((int)value);
1533 }
1534 if(ParentGroup != null)
1535 ParentGroup.HasGroupChanged = true;
1536 ScheduleFullUpdateIfNone();
1537 UpdatePhysRequired = true;
1538 }
1539 }
1540 }
1541 }
1542
1543 // not a propriety to move to methods place later
1544 private bool HasMesh()
1545 {
1546 if (Shape != null && (Shape.SculptType == (byte)SculptType.Mesh))
1547 return true;
1548 return false;
1549 }
1550
1551 // not a propriety to move to methods place later
1552 public byte DefaultPhysicsShapeType()
1553 {
1554 byte type;
1555
1556 if (Shape != null && (Shape.SculptType == (byte)SculptType.Mesh))
1557 type = (byte)PhysShapeType.convex;
1558 else
1559 type = (byte)PhysShapeType.prim;
1560
1561 return type;
1562 }
1563
1564 [XmlIgnore]
1565 public bool UsesComplexCost
1566 {
1567 get
1568 {
1569 byte pst = PhysicsShapeType;
1570 if(pst == (byte) PhysShapeType.none || pst == (byte) PhysShapeType.convex || HasMesh())
1571 return true;
1572 return false;
1573 }
1574 }
1575
1576 [XmlIgnore]
1577 public float PhysicsCost
1578 {
1579 get
1580 {
1581 if(PhysicsShapeType == (byte)PhysShapeType.none)
1582 return 0;
1583
1584 float cost = 0.1f;
1585 if (PhysActor != null)
1586 cost = PhysActor.PhysicsCost;
1587 else
1588 cost = 0.1f;
1589
1590 if ((Flags & PrimFlags.Physics) != 0)
1591 cost *= (1.0f + 0.01333f * Scale.LengthSquared()); // 0.01333 == 0.04/3
1592 return cost;
1593 }
1594 }
1595
1596 [XmlIgnore]
1597 public float StreamingCost
1598 {
1599 get
1600 {
1601 float cost;
1602 if (PhysActor != null)
1603 cost = PhysActor.StreamCost;
1604 else
1605 cost = 1.0f;
1606 return 1.0f;
1607 }
1608 }
1609
1610 [XmlIgnore]
1611 public float SimulationCost
1612 {
1613 get
1614 {
1615 // ignoring scripts. Don't like considering them for this
1616 if((Flags & PrimFlags.Physics) != 0)
1617 return 1.0f;
1618
1619 return 0.5f;
1620 }
1621 }
1622
1623 public byte PhysicsShapeType
1624 {
1625 get { return m_physicsShapeType; }
1626 set
1627 {
1628 byte oldv = m_physicsShapeType;
1629
1630 if (value >= 0 && value <= (byte)PhysShapeType.convex)
1631 {
1632 if (value == (byte)PhysShapeType.none && ParentGroup != null && ParentGroup.RootPart == this)
1633 m_physicsShapeType = DefaultPhysicsShapeType();
1634 else
1635 m_physicsShapeType = value;
1636 }
1637 else
1638 m_physicsShapeType = DefaultPhysicsShapeType();
1639
1640 if (m_physicsShapeType != oldv && ParentGroup != null)
1641 {
1642 if (m_physicsShapeType == (byte)PhysShapeType.none)
1643 {
1644 if (PhysActor != null)
1645 {
1646 Velocity = new Vector3(0, 0, 0);
1647 Acceleration = new Vector3(0, 0, 0);
1648 if (ParentGroup.RootPart == this)
1649 AngularVelocity = new Vector3(0, 0, 0);
1650 ParentGroup.Scene.RemovePhysicalPrim(1);
1651 RemoveFromPhysics();
1652 }
1653 }
1654 else if (PhysActor == null)
1655 {
1656 ApplyPhysics((uint)Flags, VolumeDetectActive, false);
1657 UpdatePhysicsSubscribedEvents();
1658 }
1659 else
1660 {
1661 PhysActor.PhysicsShapeType = m_physicsShapeType;
1662// if (Shape.SculptEntry)
1663// CheckSculptAndLoad();
1664 }
1665
1666 if (ParentGroup != null)
1667 ParentGroup.HasGroupChanged = true;
1668 }
1669
1670 if (m_physicsShapeType != value)
1671 {
1672 UpdatePhysRequired = true;
1673 }
1674 }
1675 }
1676
1677 public float Density // in kg/m^3
1678 {
1679 get { return m_density; }
1680 set
1681 {
1682 if (value >=1 && value <= 22587.0)
1683 {
1684 m_density = value;
1685 UpdatePhysRequired = true;
1686 }
1687
1688 ScheduleFullUpdateIfNone();
1689
1690 if (ParentGroup != null)
1691 ParentGroup.HasGroupChanged = true;
1692 }
1693 }
1694
1695 public float GravityModifier
1696 {
1697 get { return m_gravitymod; }
1698 set
1699 {
1700 if( value >= -1 && value <=28.0f)
1701 {
1702 m_gravitymod = value;
1703 UpdatePhysRequired = true;
1704 }
1705
1706 ScheduleFullUpdateIfNone();
1707
1708 if (ParentGroup != null)
1709 ParentGroup.HasGroupChanged = true;
1710
1711 }
1712 }
1713
1714 public float Friction
1715 {
1716 get { return m_friction; }
1717 set
1718 {
1719 if (value >= 0 && value <= 255.0f)
1720 {
1721 m_friction = value;
1722 UpdatePhysRequired = true;
1723 }
1724
1725 ScheduleFullUpdateIfNone();
1726
1727 if (ParentGroup != null)
1728 ParentGroup.HasGroupChanged = true;
1729 }
1730 }
1731
1732 public float Bounciness
1733 {
1734 get { return m_bounce; }
1735 set
1736 {
1737 if (value >= 0 && value <= 1.0f)
1738 {
1739 m_bounce = value;
1740 UpdatePhysRequired = true;
1741 }
1742
1743 ScheduleFullUpdateIfNone();
1744
1745 if (ParentGroup != null)
1746 ParentGroup.HasGroupChanged = true;
1747 }
1748 }
1749
1750
1318 #endregion Public Properties with only Get 1751 #endregion Public Properties with only Get
1319 1752
1320 private uint ApplyMask(uint val, bool set, uint mask) 1753 private uint ApplyMask(uint val, bool set, uint mask)
@@ -1460,6 +1893,61 @@ namespace OpenSim.Region.Framework.Scenes
1460 } 1893 }
1461 } 1894 }
1462 1895
1896 // SetVelocity for LSL llSetVelocity.. may need revision if having other uses in future
1897 public void SetVelocity(Vector3 pVel, bool localGlobalTF)
1898 {
1899 if (ParentGroup == null || ParentGroup.IsDeleted)
1900 return;
1901
1902 if (ParentGroup.IsAttachment)
1903 return; // don't work on attachments (for now ??)
1904
1905 SceneObjectPart root = ParentGroup.RootPart;
1906
1907 if (root.VehicleType != (int)Vehicle.TYPE_NONE) // don't mess with vehicles
1908 return;
1909
1910 PhysicsActor pa = root.PhysActor;
1911
1912 if (pa == null || !pa.IsPhysical)
1913 return;
1914
1915 if (localGlobalTF)
1916 {
1917 pVel = pVel * GetWorldRotation();
1918 }
1919
1920 ParentGroup.Velocity = pVel;
1921 }
1922
1923 // SetAngularVelocity for LSL llSetAngularVelocity.. may need revision if having other uses in future
1924 public void SetAngularVelocity(Vector3 pAngVel, bool localGlobalTF)
1925 {
1926 if (ParentGroup == null || ParentGroup.IsDeleted)
1927 return;
1928
1929 if (ParentGroup.IsAttachment)
1930 return; // don't work on attachments (for now ??)
1931
1932 SceneObjectPart root = ParentGroup.RootPart;
1933
1934 if (root.VehicleType != (int)Vehicle.TYPE_NONE) // don't mess with vehicles
1935 return;
1936
1937 PhysicsActor pa = root.PhysActor;
1938
1939 if (pa == null || !pa.IsPhysical)
1940 return;
1941
1942 if (localGlobalTF)
1943 {
1944 pAngVel = pAngVel * GetWorldRotation();
1945 }
1946
1947 root.AngularVelocity = pAngVel;
1948 }
1949
1950
1463 /// <summary> 1951 /// <summary>
1464 /// hook to the physics scene to apply angular impulse 1952 /// hook to the physics scene to apply angular impulse
1465 /// This is sent up to the group, which then finds the root prim 1953 /// This is sent up to the group, which then finds the root prim
@@ -1480,7 +1968,7 @@ namespace OpenSim.Region.Framework.Scenes
1480 impulse = newimpulse; 1968 impulse = newimpulse;
1481 } 1969 }
1482 1970
1483 ParentGroup.applyAngularImpulse(impulse); 1971 ParentGroup.ApplyAngularImpulse(impulse);
1484 } 1972 }
1485 1973
1486 /// <summary> 1974 /// <summary>
@@ -1490,20 +1978,24 @@ namespace OpenSim.Region.Framework.Scenes
1490 /// </summary> 1978 /// </summary>
1491 /// <param name="impulsei">Vector force</param> 1979 /// <param name="impulsei">Vector force</param>
1492 /// <param name="localGlobalTF">true for the local frame, false for the global frame</param> 1980 /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
1493 public void SetAngularImpulse(Vector3 impulsei, bool localGlobalTF) 1981
1982 // this is actualy Set Torque.. keeping naming so not to edit lslapi also
1983 public void SetAngularImpulse(Vector3 torquei, bool localGlobalTF)
1494 { 1984 {
1495 Vector3 impulse = impulsei; 1985 Vector3 torque = torquei;
1496 1986
1497 if (localGlobalTF) 1987 if (localGlobalTF)
1498 { 1988 {
1989/*
1499 Quaternion grot = GetWorldRotation(); 1990 Quaternion grot = GetWorldRotation();
1500 Quaternion AXgrot = grot; 1991 Quaternion AXgrot = grot;
1501 Vector3 AXimpulsei = impulsei; 1992 Vector3 AXimpulsei = impulsei;
1502 Vector3 newimpulse = AXimpulsei * AXgrot; 1993 Vector3 newimpulse = AXimpulsei * AXgrot;
1503 impulse = newimpulse; 1994 */
1995 torque *= GetWorldRotation();
1504 } 1996 }
1505 1997
1506 ParentGroup.setAngularImpulse(impulse); 1998 Torque = torque;
1507 } 1999 }
1508 2000
1509 /// <summary> 2001 /// <summary>
@@ -1511,17 +2003,23 @@ namespace OpenSim.Region.Framework.Scenes
1511 /// </summary> 2003 /// </summary>
1512 /// <param name="rootObjectFlags"></param> 2004 /// <param name="rootObjectFlags"></param>
1513 /// <param name="VolumeDetectActive"></param> 2005 /// <param name="VolumeDetectActive"></param>
1514 public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive) 2006 /// <param name="building"></param>
2007
2008 public void ApplyPhysics(uint _ObjectFlags, bool _VolumeDetectActive, bool building)
1515 { 2009 {
2010 VolumeDetectActive = _VolumeDetectActive;
2011
1516 if (!ParentGroup.Scene.CollidablePrims) 2012 if (!ParentGroup.Scene.CollidablePrims)
1517 return; 2013 return;
1518 2014
1519// m_log.DebugFormat( 2015 if (PhysicsShapeType == (byte)PhysShapeType.none)
1520// "[SCENE OBJECT PART]: Applying physics to {0} {1}, m_physicalPrim {2}", 2016 return;
1521// Name, LocalId, UUID, m_physicalPrim);
1522 2017
1523 bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0; 2018 bool isPhysical = (_ObjectFlags & (uint) PrimFlags.Physics) != 0;
1524 bool isPhantom = (rootObjectFlags & (uint) PrimFlags.Phantom) != 0; 2019 bool isPhantom = (_ObjectFlags & (uint)PrimFlags.Phantom) != 0;
2020
2021 if (_VolumeDetectActive)
2022 isPhantom = true;
1525 2023
1526 if (IsJoint()) 2024 if (IsJoint())
1527 { 2025 {
@@ -1529,22 +2027,14 @@ namespace OpenSim.Region.Framework.Scenes
1529 } 2027 }
1530 else 2028 else
1531 { 2029 {
1532 // Special case for VolumeDetection: If VolumeDetection is set, the phantom flag is locally ignored 2030 if ((!isPhantom || isPhysical || _VolumeDetectActive) && !ParentGroup.IsAttachment
1533 if (VolumeDetectActive) 2031 && !(Shape.PathCurve == (byte)Extrusion.Flexible))
1534 isPhantom = false;
1535
1536 // The only time the physics scene shouldn't know about the prim is if it's phantom or an attachment, which is phantom by definition
1537 // or flexible
1538 if (!isPhantom && !ParentGroup.IsAttachment && !(Shape.PathCurve == (byte)Extrusion.Flexible))
1539 { 2032 {
1540 // Added clarification.. since A rigid body is an object that you can kick around, etc. 2033 AddToPhysics(isPhysical, isPhantom, building, isPhysical);
1541 bool rigidBody = isPhysical && !isPhantom; 2034 UpdatePhysicsSubscribedEvents(); // not sure if appliable here
1542
1543 PhysicsActor pa = AddToPhysics(rigidBody);
1544
1545 if (pa != null)
1546 pa.SetVolumeDetect(VolumeDetectActive ? 1 : 0);
1547 } 2035 }
2036 else
2037 PhysActor = null; // just to be sure
1548 } 2038 }
1549 } 2039 }
1550 2040
@@ -1596,6 +2086,12 @@ namespace OpenSim.Region.Framework.Scenes
1596 dupe.Category = Category; 2086 dupe.Category = Category;
1597 dupe.m_rezzed = m_rezzed; 2087 dupe.m_rezzed = m_rezzed;
1598 2088
2089 dupe.m_UndoRedo = null;
2090 dupe.m_isSelected = false;
2091
2092 dupe.IgnoreUndoUpdate = false;
2093 dupe.Undoing = false;
2094
1599 dupe.m_inventory = new SceneObjectPartInventory(dupe); 2095 dupe.m_inventory = new SceneObjectPartInventory(dupe);
1600 dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone(); 2096 dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone();
1601 2097
@@ -1611,6 +2107,7 @@ namespace OpenSim.Region.Framework.Scenes
1611 2107
1612 // Move afterwards ResetIDs as it clears the localID 2108 // Move afterwards ResetIDs as it clears the localID
1613 dupe.LocalId = localID; 2109 dupe.LocalId = localID;
2110
1614 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated. 2111 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
1615 dupe.LastOwnerID = OwnerID; 2112 dupe.LastOwnerID = OwnerID;
1616 2113
@@ -1618,6 +2115,9 @@ namespace OpenSim.Region.Framework.Scenes
1618 Array.Copy(Shape.ExtraParams, extraP, extraP.Length); 2115 Array.Copy(Shape.ExtraParams, extraP, extraP.Length);
1619 dupe.Shape.ExtraParams = extraP; 2116 dupe.Shape.ExtraParams = extraP;
1620 2117
2118 // safeguard actual copy is done in sog.copy
2119 dupe.KeyframeMotion = null;
2120
1621 if (userExposed) 2121 if (userExposed)
1622 { 2122 {
1623/* 2123/*
@@ -1629,8 +2129,12 @@ namespace OpenSim.Region.Framework.Scenes
1629*/ 2129*/
1630 bool UsePhysics = ((dupe.Flags & PrimFlags.Physics) != 0); 2130 bool UsePhysics = ((dupe.Flags & PrimFlags.Physics) != 0);
1631 dupe.DoPhysicsPropertyUpdate(UsePhysics, true); 2131 dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
2132// dupe.UpdatePhysicsSubscribedEvents(); // not sure...
1632 } 2133 }
1633 2134
2135 if (dupe.PhysActor != null)
2136 dupe.PhysActor.LocalID = localID;
2137
1634 ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed); 2138 ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed);
1635 2139
1636// m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID); 2140// m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID);
@@ -1649,10 +2153,10 @@ namespace OpenSim.Region.Framework.Scenes
1649 { 2153 {
1650 if (asset != null) 2154 if (asset != null)
1651 SculptTextureCallback(asset); 2155 SculptTextureCallback(asset);
1652 else 2156// else
1653 m_log.WarnFormat( 2157// m_log.WarnFormat(
1654 "[SCENE OBJECT PART]: Part {0} {1} requested mesh/sculpt data for asset id {2} from asset service but received no data", 2158// "[SCENE OBJECT PART]: Part {0} {1} requested mesh/sculpt data for asset id {2} from asset service but received no data",
1655 Name, UUID, id); 2159// Name, UUID, id);
1656 } 2160 }
1657*/ 2161*/
1658 /// <summary> 2162 /// <summary>
@@ -1751,6 +2255,7 @@ namespace OpenSim.Region.Framework.Scenes
1751 2255
1752 /// <summary> 2256 /// <summary>
1753 /// Do a physics propery update for this part. 2257 /// Do a physics propery update for this part.
2258 /// now also updates phantom and volume detector
1754 /// </summary> 2259 /// </summary>
1755 /// <param name="UsePhysics"></param> 2260 /// <param name="UsePhysics"></param>
1756 /// <param name="isNew"></param> 2261 /// <param name="isNew"></param>
@@ -1776,61 +2281,69 @@ namespace OpenSim.Region.Framework.Scenes
1776 { 2281 {
1777 if (pa.IsPhysical) // implies UsePhysics==false for this block 2282 if (pa.IsPhysical) // implies UsePhysics==false for this block
1778 { 2283 {
1779 if (!isNew) 2284 if (!isNew) // implies UsePhysics==false for this block
2285 {
1780 ParentGroup.Scene.RemovePhysicalPrim(1); 2286 ParentGroup.Scene.RemovePhysicalPrim(1);
1781 2287
1782 pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate; 2288 Velocity = new Vector3(0, 0, 0);
1783 pa.OnOutOfBounds -= PhysicsOutOfBounds; 2289 Acceleration = new Vector3(0, 0, 0);
1784 pa.delink(); 2290 if (ParentGroup.RootPart == this)
2291 AngularVelocity = new Vector3(0, 0, 0);
1785 2292
1786 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints && (!isNew)) 2293 if (pa.Phantom && !VolumeDetectActive)
1787 { 2294 {
1788 // destroy all joints connected to this now deactivated body 2295 RemoveFromPhysics();
1789 ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(pa); 2296 return;
1790 } 2297 }
1791 2298
1792 // stop client-side interpolation of all joint proxy objects that have just been deleted 2299 pa.IsPhysical = UsePhysics;
1793 // this is done because RemoveAllJointsConnectedToActor invokes the OnJointDeactivated callback, 2300 pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
1794 // which stops client-side interpolation of deactivated joint proxy objects. 2301 pa.OnOutOfBounds -= PhysicsOutOfBounds;
2302 pa.delink();
2303 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
2304 {
2305 // destroy all joints connected to this now deactivated body
2306 ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(pa);
2307 }
2308 }
1795 } 2309 }
1796 2310
1797 if (!UsePhysics && !isNew) 2311 if (pa.IsPhysical != UsePhysics)
1798 { 2312 pa.IsPhysical = UsePhysics;
1799 // reset velocity to 0 on physics switch-off. Without that, the client thinks the
1800 // prim still has velocity and continues to interpolate its position along the old
1801 // velocity-vector.
1802 Velocity = new Vector3(0, 0, 0);
1803 Acceleration = new Vector3(0, 0, 0);
1804 AngularVelocity = new Vector3(0, 0, 0);
1805 //RotationalVelocity = new Vector3(0, 0, 0);
1806 }
1807 2313
1808 pa.IsPhysical = UsePhysics; 2314 if (UsePhysics)
2315 {
2316 if (ParentGroup.RootPart.KeyframeMotion != null)
2317 ParentGroup.RootPart.KeyframeMotion.Stop();
2318 ParentGroup.RootPart.KeyframeMotion = null;
2319 ParentGroup.Scene.AddPhysicalPrim(1);
1809 2320
1810 // If we're not what we're supposed to be in the physics scene, recreate ourselves. 2321 PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
1811 //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor); 2322 PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
1812 /// that's not wholesome. Had to make Scene public
1813 //PhysActor = null;
1814 2323
1815 if ((Flags & PrimFlags.Phantom) == 0) 2324 if (ParentID != 0 && ParentID != LocalId)
1816 {
1817 if (UsePhysics)
1818 { 2325 {
1819 ParentGroup.Scene.AddPhysicalPrim(1); 2326 PhysicsActor parentPa = ParentGroup.RootPart.PhysActor;
1820 2327
1821 pa.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate; 2328 if (parentPa != null)
1822 pa.OnOutOfBounds += PhysicsOutOfBounds;
1823 if (ParentID != 0 && ParentID != LocalId)
1824 { 2329 {
1825 PhysicsActor parentPa = ParentGroup.RootPart.PhysActor; 2330 pa.link(parentPa);
1826
1827 if (parentPa != null)
1828 {
1829 pa.link(parentPa);
1830 }
1831 } 2331 }
1832 } 2332 }
1833 } 2333 }
2334 }
2335
2336 bool phan = ((Flags & PrimFlags.Phantom) != 0);
2337 if (pa.Phantom != phan)
2338 pa.Phantom = phan;
2339
2340// some engines dont' have this check still
2341// if (VolumeDetectActive != pa.IsVolumeDtc)
2342 {
2343 if (VolumeDetectActive)
2344 pa.SetVolumeDetect(1);
2345 else
2346 pa.SetVolumeDetect(0);
1834 } 2347 }
1835 2348
1836 // If this part is a sculpt then delay the physics update until we've asynchronously loaded the 2349 // If this part is a sculpt then delay the physics update until we've asynchronously loaded the
@@ -1949,12 +2462,26 @@ namespace OpenSim.Region.Framework.Scenes
1949 2462
1950 public Vector3 GetGeometricCenter() 2463 public Vector3 GetGeometricCenter()
1951 { 2464 {
1952 PhysicsActor pa = PhysActor; 2465 // this is not real geometric center but a average of positions relative to root prim acording to
1953 2466 // http://wiki.secondlife.com/wiki/llGetGeometricCenter
1954 if (pa != null) 2467 // ignoring tortured prims details since sl also seems to ignore
1955 return new Vector3(pa.CenterOfMass.X, pa.CenterOfMass.Y, pa.CenterOfMass.Z); 2468 // so no real use in doing it on physics
1956 else 2469 if (ParentGroup.IsDeleted)
1957 return new Vector3(0, 0, 0); 2470 return new Vector3(0, 0, 0);
2471
2472 return ParentGroup.GetGeometricCenter();
2473
2474 /*
2475 PhysicsActor pa = PhysActor;
2476
2477 if (pa != null)
2478 {
2479 Vector3 vtmp = pa.CenterOfMass;
2480 return vtmp;
2481 }
2482 else
2483 return new Vector3(0, 0, 0);
2484 */
1958 } 2485 }
1959 2486
1960 public float GetMass() 2487 public float GetMass()
@@ -1967,14 +2494,43 @@ namespace OpenSim.Region.Framework.Scenes
1967 return 0; 2494 return 0;
1968 } 2495 }
1969 2496
1970 public Vector3 GetForce() 2497 public Vector3 GetCenterOfMass()
2498 {
2499 if (ParentGroup.RootPart == this)
2500 {
2501 if (ParentGroup.IsDeleted)
2502 return AbsolutePosition;
2503 return ParentGroup.GetCenterOfMass();
2504 }
2505
2506 PhysicsActor pa = PhysActor;
2507
2508 if (pa != null)
2509 {
2510 Vector3 tmp = pa.CenterOfMass;
2511 return tmp;
2512 }
2513 else
2514 return AbsolutePosition;
2515 }
2516
2517 public Vector3 GetPartCenterOfMass()
1971 { 2518 {
1972 PhysicsActor pa = PhysActor; 2519 PhysicsActor pa = PhysActor;
1973 2520
1974 if (pa != null) 2521 if (pa != null)
1975 return pa.Force; 2522 {
2523 Vector3 tmp = pa.CenterOfMass;
2524 return tmp;
2525 }
1976 else 2526 else
1977 return Vector3.Zero; 2527 return AbsolutePosition;
2528 }
2529
2530
2531 public Vector3 GetForce()
2532 {
2533 return Force;
1978 } 2534 }
1979 2535
1980 /// <summary> 2536 /// <summary>
@@ -2189,15 +2745,25 @@ namespace OpenSim.Region.Framework.Scenes
2189 2745
2190 private void SendLandCollisionEvent(scriptEvents ev, ScriptCollidingNotification notify) 2746 private void SendLandCollisionEvent(scriptEvents ev, ScriptCollidingNotification notify)
2191 { 2747 {
2192 if ((ParentGroup.RootPart.ScriptEvents & ev) != 0) 2748 bool sendToRoot = true;
2193 { 2749
2194 ColliderArgs LandCollidingMessage = new ColliderArgs(); 2750 ColliderArgs LandCollidingMessage = new ColliderArgs();
2195 List<DetectedObject> colliding = new List<DetectedObject>(); 2751 List<DetectedObject> colliding = new List<DetectedObject>();
2196 2752
2197 colliding.Add(CreateDetObjectForGround()); 2753 colliding.Add(CreateDetObjectForGround());
2198 LandCollidingMessage.Colliders = colliding; 2754 LandCollidingMessage.Colliders = colliding;
2199 2755
2756 if (Inventory.ContainsScripts())
2757 {
2758 if (!PassCollisions)
2759 sendToRoot = false;
2760 }
2761 if ((ScriptEvents & ev) != 0)
2200 notify(LocalId, LandCollidingMessage); 2762 notify(LocalId, LandCollidingMessage);
2763
2764 if ((ParentGroup.RootPart.ScriptEvents & ev) != 0 && sendToRoot)
2765 {
2766 notify(ParentGroup.RootPart.LocalId, LandCollidingMessage);
2201 } 2767 }
2202 } 2768 }
2203 2769
@@ -2213,57 +2779,120 @@ namespace OpenSim.Region.Framework.Scenes
2213 List<uint> endedColliders = new List<uint>(); 2779 List<uint> endedColliders = new List<uint>();
2214 List<uint> startedColliders = new List<uint>(); 2780 List<uint> startedColliders = new List<uint>();
2215 2781
2216 // calculate things that started colliding this time 2782 if (collissionswith.Count == 0)
2217 // and build up list of colliders this time
2218 foreach (uint localid in collissionswith.Keys)
2219 { 2783 {
2220 thisHitColliders.Add(localid); 2784 if (m_lastColliders.Count == 0)
2221 if (!m_lastColliders.Contains(localid)) 2785 return; // nothing to do
2222 startedColliders.Add(localid);
2223 }
2224 2786
2225 // calculate things that ended colliding 2787 foreach (uint localID in m_lastColliders)
2226 foreach (uint localID in m_lastColliders) 2788 {
2227 {
2228 if (!thisHitColliders.Contains(localID))
2229 endedColliders.Add(localID); 2789 endedColliders.Add(localID);
2790 }
2791 m_lastColliders.Clear();
2230 } 2792 }
2231 2793
2232 //add the items that started colliding this time to the last colliders list. 2794 else
2233 foreach (uint localID in startedColliders) 2795 {
2234 m_lastColliders.Add(localID); 2796 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
2235 2797
2236 // remove things that ended colliding from the last colliders list 2798 // calculate things that started colliding this time
2237 foreach (uint localID in endedColliders) 2799 // and build up list of colliders this time
2238 m_lastColliders.Remove(localID); 2800 if (!VolumeDetectActive && CollisionSoundType >= 0)
2801 {
2802 CollisionForSoundInfo soundinfo;
2803 ContactPoint curcontact;
2239 2804
2240 // play the sound. 2805 foreach (uint id in collissionswith.Keys)
2241 if (startedColliders.Count > 0 && CollisionSound != UUID.Zero && CollisionSoundVolume > 0.0f) 2806 {
2242 { 2807 thisHitColliders.Add(id);
2243 ISoundModule soundModule = ParentGroup.Scene.RequestModuleInterface<ISoundModule>(); 2808 if (!m_lastColliders.Contains(id))
2244 if (soundModule != null) 2809 {
2810 startedColliders.Add(id);
2811
2812 curcontact = collissionswith[id];
2813 if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
2814 {
2815 soundinfo = new CollisionForSoundInfo();
2816 soundinfo.colliderID = id;
2817 soundinfo.position = curcontact.Position;
2818 soundinfo.relativeVel = curcontact.RelativeSpeed;
2819 soundinfolist.Add(soundinfo);
2820 }
2821 }
2822 }
2823 }
2824 else
2825 {
2826 foreach (uint id in collissionswith.Keys)
2827 {
2828 thisHitColliders.Add(id);
2829 if (!m_lastColliders.Contains(id))
2830 startedColliders.Add(id);
2831 }
2832 }
2833
2834 // calculate things that ended colliding
2835 foreach (uint localID in m_lastColliders)
2245 { 2836 {
2246 soundModule.SendSound(UUID, CollisionSound, 2837 if (!thisHitColliders.Contains(localID))
2247 CollisionSoundVolume, true, (byte)0, 0, false, 2838 endedColliders.Add(localID);
2248 false);
2249 } 2839 }
2840
2841 //add the items that started colliding this time to the last colliders list.
2842 foreach (uint localID in startedColliders)
2843 m_lastColliders.Add(localID);
2844
2845 // remove things that ended colliding from the last colliders list
2846 foreach (uint localID in endedColliders)
2847 m_lastColliders.Remove(localID);
2848
2849 // play sounds.
2850 if (soundinfolist.Count > 0)
2851 CollisionSounds.PartCollisionSound(this, soundinfolist);
2250 } 2852 }
2251 2853
2252 SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart); 2854 SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart);
2253 SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding); 2855 if (!VolumeDetectActive)
2856 SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding);
2254 SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd); 2857 SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd);
2255 2858
2256 if (startedColliders.Contains(0)) 2859 if (startedColliders.Contains(0))
2257 { 2860 SendLandCollisionEvent(scriptEvents.land_collision_start, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingStart);
2258 if (m_lastColliders.Contains(0)) 2861 if (m_lastColliders.Contains(0))
2259 SendLandCollisionEvent(scriptEvents.land_collision, ParentGroup.Scene.EventManager.TriggerScriptLandColliding); 2862 SendLandCollisionEvent(scriptEvents.land_collision, ParentGroup.Scene.EventManager.TriggerScriptLandColliding);
2260 else
2261 SendLandCollisionEvent(scriptEvents.land_collision_start, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingStart);
2262 }
2263 if (endedColliders.Contains(0)) 2863 if (endedColliders.Contains(0))
2264 SendLandCollisionEvent(scriptEvents.land_collision_end, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd); 2864 SendLandCollisionEvent(scriptEvents.land_collision_end, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd);
2265 } 2865 }
2266 2866
2867 // The Collision sounds code calls this
2868 public void SendCollisionSound(UUID soundID, double volume, Vector3 position)
2869 {
2870 if (soundID == UUID.Zero)
2871 return;
2872
2873 ISoundModule soundModule = ParentGroup.Scene.RequestModuleInterface<ISoundModule>();
2874 if (soundModule == null)
2875 return;
2876
2877 if (volume > 1)
2878 volume = 1;
2879 if (volume < 0)
2880 volume = 0;
2881
2882 int now = Util.EnvironmentTickCount();
2883 if(Util.EnvironmentTickCountSubtract(now,LastColSoundSentTime) <200)
2884 return;
2885
2886 LastColSoundSentTime = now;
2887
2888 UUID ownerID = OwnerID;
2889 UUID objectID = ParentGroup.RootPart.UUID;
2890 UUID parentID = ParentGroup.UUID;
2891 ulong regionHandle = ParentGroup.Scene.RegionInfo.RegionHandle;
2892
2893 soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle, 0 );
2894 }
2895
2267 public void PhysicsOutOfBounds(Vector3 pos) 2896 public void PhysicsOutOfBounds(Vector3 pos)
2268 { 2897 {
2269 // Note: This is only being called on the root prim at this time. 2898 // Note: This is only being called on the root prim at this time.
@@ -2285,9 +2914,9 @@ namespace OpenSim.Region.Framework.Scenes
2285 Vector3 newpos = new Vector3(pa.Position.GetBytes(), 0); 2914 Vector3 newpos = new Vector3(pa.Position.GetBytes(), 0);
2286 2915
2287 if (ParentGroup.Scene.TestBorderCross(newpos, Cardinals.N) 2916 if (ParentGroup.Scene.TestBorderCross(newpos, Cardinals.N)
2288 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.S) 2917 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.S)
2289 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.E) 2918 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.E)
2290 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.W)) 2919 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.W))
2291 { 2920 {
2292 ParentGroup.AbsolutePosition = newpos; 2921 ParentGroup.AbsolutePosition = newpos;
2293 return; 2922 return;
@@ -2414,6 +3043,19 @@ namespace OpenSim.Region.Framework.Scenes
2414 APIDTarget = Quaternion.Identity; 3043 APIDTarget = Quaternion.Identity;
2415 } 3044 }
2416 3045
3046
3047
3048 public void ScheduleFullUpdateIfNone()
3049 {
3050 if (ParentGroup == null)
3051 return;
3052
3053// ??? ParentGroup.HasGroupChanged = true;
3054
3055 if (UpdateFlag != UpdateRequired.FULL)
3056 ScheduleFullUpdate();
3057 }
3058
2417 /// <summary> 3059 /// <summary>
2418 /// Schedules this prim for a full update 3060 /// Schedules this prim for a full update
2419 /// </summary> 3061 /// </summary>
@@ -2617,8 +3259,8 @@ namespace OpenSim.Region.Framework.Scenes
2617 { 3259 {
2618 const float ROTATION_TOLERANCE = 0.01f; 3260 const float ROTATION_TOLERANCE = 0.01f;
2619 const float VELOCITY_TOLERANCE = 0.001f; 3261 const float VELOCITY_TOLERANCE = 0.001f;
2620 const float POSITION_TOLERANCE = 0.05f; 3262 const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
2621 const int TIME_MS_TOLERANCE = 3000; 3263 const int TIME_MS_TOLERANCE = 200; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
2622 3264
2623 switch (UpdateFlag) 3265 switch (UpdateFlag)
2624 { 3266 {
@@ -2660,6 +3302,9 @@ namespace OpenSim.Region.Framework.Scenes
2660 /// </summary> 3302 /// </summary>
2661 public void SendTerseUpdateToAllClients() 3303 public void SendTerseUpdateToAllClients()
2662 { 3304 {
3305 if (ParentGroup == null || ParentGroup.Scene == null)
3306 return;
3307
2663 ParentGroup.Scene.ForEachClient(delegate(IClientAPI client) 3308 ParentGroup.Scene.ForEachClient(delegate(IClientAPI client)
2664 { 3309 {
2665 SendTerseUpdateToClient(client); 3310 SendTerseUpdateToClient(client);
@@ -2683,10 +3328,13 @@ namespace OpenSim.Region.Framework.Scenes
2683 3328
2684 public void SetBuoyancy(float fvalue) 3329 public void SetBuoyancy(float fvalue)
2685 { 3330 {
2686 PhysicsActor pa = PhysActor; 3331 Buoyancy = fvalue;
2687 3332/*
2688 if (pa != null) 3333 if (PhysActor != null)
2689 pa.Buoyancy = fvalue; 3334 {
3335 PhysActor.Buoyancy = fvalue;
3336 }
3337 */
2690 } 3338 }
2691 3339
2692 public void SetDieAtEdge(bool p) 3340 public void SetDieAtEdge(bool p)
@@ -2702,47 +3350,111 @@ namespace OpenSim.Region.Framework.Scenes
2702 PhysicsActor pa = PhysActor; 3350 PhysicsActor pa = PhysActor;
2703 3351
2704 if (pa != null) 3352 if (pa != null)
2705 pa.FloatOnWater = floatYN == 1; 3353 pa.FloatOnWater = (floatYN == 1);
2706 } 3354 }
2707 3355
2708 public void SetForce(Vector3 force) 3356 public void SetForce(Vector3 force)
2709 { 3357 {
2710 PhysicsActor pa = PhysActor; 3358 Force = force;
3359 }
2711 3360
2712 if (pa != null) 3361 public SOPVehicle VehicleParams
2713 pa.Force = force; 3362 {
3363 get
3364 {
3365 return m_vehicleParams;
3366 }
3367 set
3368 {
3369 m_vehicleParams = value;
3370 }
3371 }
3372
3373
3374 public int VehicleType
3375 {
3376 get
3377 {
3378 if (m_vehicleParams == null)
3379 return (int)Vehicle.TYPE_NONE;
3380 else
3381 return (int)m_vehicleParams.Type;
3382 }
3383 set
3384 {
3385 SetVehicleType(value);
3386 }
2714 } 3387 }
2715 3388
2716 public void SetVehicleType(int type) 3389 public void SetVehicleType(int type)
2717 { 3390 {
2718 PhysicsActor pa = PhysActor; 3391 m_vehicleParams = null;
3392
3393 if (type == (int)Vehicle.TYPE_NONE)
3394 {
3395 if (_parentID ==0 && PhysActor != null)
3396 PhysActor.VehicleType = (int)Vehicle.TYPE_NONE;
3397 return;
3398 }
3399 m_vehicleParams = new SOPVehicle();
3400 m_vehicleParams.ProcessTypeChange((Vehicle)type);
3401 {
3402 if (_parentID ==0 && PhysActor != null)
3403 PhysActor.VehicleType = type;
3404 return;
3405 }
3406 }
2719 3407
2720 if (pa != null) 3408 public void SetVehicleFlags(int param, bool remove)
2721 pa.VehicleType = type; 3409 {
3410 if (m_vehicleParams == null)
3411 return;
3412
3413 m_vehicleParams.ProcessVehicleFlags(param, remove);
3414
3415 if (_parentID ==0 && PhysActor != null)
3416 {
3417 PhysActor.VehicleFlags(param, remove);
3418 }
2722 } 3419 }
2723 3420
2724 public void SetVehicleFloatParam(int param, float value) 3421 public void SetVehicleFloatParam(int param, float value)
2725 { 3422 {
2726 PhysicsActor pa = PhysActor; 3423 if (m_vehicleParams == null)
3424 return;
2727 3425
2728 if (pa != null) 3426 m_vehicleParams.ProcessFloatVehicleParam((Vehicle)param, value);
2729 pa.VehicleFloatParam(param, value); 3427
3428 if (_parentID == 0 && PhysActor != null)
3429 {
3430 PhysActor.VehicleFloatParam(param, value);
3431 }
2730 } 3432 }
2731 3433
2732 public void SetVehicleVectorParam(int param, Vector3 value) 3434 public void SetVehicleVectorParam(int param, Vector3 value)
2733 { 3435 {
2734 PhysicsActor pa = PhysActor; 3436 if (m_vehicleParams == null)
3437 return;
2735 3438
2736 if (pa != null) 3439 m_vehicleParams.ProcessVectorVehicleParam((Vehicle)param, value);
2737 pa.VehicleVectorParam(param, value); 3440
3441 if (_parentID == 0 && PhysActor != null)
3442 {
3443 PhysActor.VehicleVectorParam(param, value);
3444 }
2738 } 3445 }
2739 3446
2740 public void SetVehicleRotationParam(int param, Quaternion rotation) 3447 public void SetVehicleRotationParam(int param, Quaternion rotation)
2741 { 3448 {
2742 PhysicsActor pa = PhysActor; 3449 if (m_vehicleParams == null)
3450 return;
2743 3451
2744 if (pa != null) 3452 m_vehicleParams.ProcessRotationVehicleParam((Vehicle)param, rotation);
2745 pa.VehicleRotationParam(param, rotation); 3453
3454 if (_parentID == 0 && PhysActor != null)
3455 {
3456 PhysActor.VehicleRotationParam(param, rotation);
3457 }
2746 } 3458 }
2747 3459
2748 /// <summary> 3460 /// <summary>
@@ -2943,14 +3655,6 @@ namespace OpenSim.Region.Framework.Scenes
2943 hasProfileCut = hasDimple; // is it the same thing? 3655 hasProfileCut = hasDimple; // is it the same thing?
2944 } 3656 }
2945 3657
2946 public void SetVehicleFlags(int param, bool remove)
2947 {
2948 PhysicsActor pa = PhysActor;
2949
2950 if (pa != null)
2951 pa.VehicleFlags(param, remove);
2952 }
2953
2954 public void SetGroup(UUID groupID, IClientAPI client) 3658 public void SetGroup(UUID groupID, IClientAPI client)
2955 { 3659 {
2956 // Scene.AddNewPrims() calls with client == null so can't use this. 3660 // Scene.AddNewPrims() calls with client == null so can't use this.
@@ -3054,67 +3758,16 @@ namespace OpenSim.Region.Framework.Scenes
3054 //ParentGroup.ScheduleGroupForFullUpdate(); 3758 //ParentGroup.ScheduleGroupForFullUpdate();
3055 } 3759 }
3056 3760
3057 public void StoreUndoState() 3761 public void StoreUndoState(ObjectChangeType change)
3058 {
3059 StoreUndoState(false);
3060 }
3061
3062 public void StoreUndoState(bool forGroup)
3063 { 3762 {
3064 if (ParentGroup == null || ParentGroup.Scene == null) 3763 if (m_UndoRedo == null)
3065 return; 3764 m_UndoRedo = new UndoRedoState(5);
3066
3067 if (Undoing)
3068 {
3069// m_log.DebugFormat(
3070// "[SCENE OBJECT PART]: Ignoring undo store for {0} {1} since already undoing", Name, LocalId);
3071 return;
3072 }
3073
3074 if (IgnoreUndoUpdate)
3075 {
3076// m_log.DebugFormat("[SCENE OBJECT PART]: Ignoring undo store for {0} {1}", Name, LocalId);
3077 return;
3078 }
3079 3765
3080 lock (m_undo) 3766 lock (m_UndoRedo)
3081 { 3767 {
3082 if (m_undo.Count > 0) 3768 if (!Undoing && !IgnoreUndoUpdate && ParentGroup != null) // just to read better - undo is in progress, or suspended
3083 { 3769 {
3084 UndoState last = m_undo[m_undo.Count - 1]; 3770 m_UndoRedo.StoreUndo(this, change);
3085 if (last != null)
3086 {
3087 // TODO: May need to fix for group comparison
3088 if (last.Compare(this))
3089 {
3090// m_log.DebugFormat(
3091// "[SCENE OBJECT PART]: Not storing undo for {0} {1} since current state is same as last undo state, initial stack size {2}",
3092// Name, LocalId, m_undo.Count);
3093
3094 return;
3095 }
3096 }
3097 }
3098
3099// m_log.DebugFormat(
3100// "[SCENE OBJECT PART]: Storing undo state for {0} {1}, forGroup {2}, initial stack size {3}",
3101// Name, LocalId, forGroup, m_undo.Count);
3102
3103 if (ParentGroup.Scene.MaxUndoCount > 0)
3104 {
3105 UndoState nUndo = new UndoState(this, forGroup);
3106
3107 m_undo.Add(nUndo);
3108
3109 if (m_undo.Count > ParentGroup.Scene.MaxUndoCount)
3110 m_undo.RemoveAt(0);
3111
3112 if (m_redo.Count > 0)
3113 m_redo.Clear();
3114
3115// m_log.DebugFormat(
3116// "[SCENE OBJECT PART]: Stored undo state for {0} {1}, forGroup {2}, stack size now {3}",
3117// Name, LocalId, forGroup, m_undo.Count);
3118 } 3771 }
3119 } 3772 }
3120 } 3773 }
@@ -3126,88 +3779,46 @@ namespace OpenSim.Region.Framework.Scenes
3126 { 3779 {
3127 get 3780 get
3128 { 3781 {
3129 lock (m_undo) 3782 if (m_UndoRedo == null)
3130 return m_undo.Count; 3783 return 0;
3784 return m_UndoRedo.Count;
3131 } 3785 }
3132 } 3786 }
3133 3787
3134 public void Undo() 3788 public void Undo()
3135 { 3789 {
3136 lock (m_undo) 3790 if (m_UndoRedo == null || Undoing || ParentGroup == null)
3137 { 3791 return;
3138// m_log.DebugFormat(
3139// "[SCENE OBJECT PART]: Handling undo request for {0} {1}, stack size {2}",
3140// Name, LocalId, m_undo.Count);
3141
3142 if (m_undo.Count > 0)
3143 {
3144 UndoState goback = m_undo[m_undo.Count - 1];
3145 m_undo.RemoveAt(m_undo.Count - 1);
3146
3147 UndoState nUndo = null;
3148
3149 if (ParentGroup.Scene.MaxUndoCount > 0)
3150 {
3151 nUndo = new UndoState(this, goback.ForGroup);
3152 }
3153
3154 goback.PlaybackState(this);
3155
3156 if (nUndo != null)
3157 {
3158 m_redo.Add(nUndo);
3159
3160 if (m_redo.Count > ParentGroup.Scene.MaxUndoCount)
3161 m_redo.RemoveAt(0);
3162 }
3163 }
3164 3792
3165// m_log.DebugFormat( 3793 lock (m_UndoRedo)
3166// "[SCENE OBJECT PART]: Handled undo request for {0} {1}, stack size now {2}", 3794 {
3167// Name, LocalId, m_undo.Count); 3795 Undoing = true;
3796 m_UndoRedo.Undo(this);
3797 Undoing = false;
3168 } 3798 }
3169 } 3799 }
3170 3800
3171 public void Redo() 3801 public void Redo()
3172 { 3802 {
3173 lock (m_undo) 3803 if (m_UndoRedo == null || Undoing || ParentGroup == null)
3174 { 3804 return;
3175// m_log.DebugFormat(
3176// "[SCENE OBJECT PART]: Handling redo request for {0} {1}, stack size {2}",
3177// Name, LocalId, m_redo.Count);
3178
3179 if (m_redo.Count > 0)
3180 {
3181 UndoState gofwd = m_redo[m_redo.Count - 1];
3182 m_redo.RemoveAt(m_redo.Count - 1);
3183
3184 if (ParentGroup.Scene.MaxUndoCount > 0)
3185 {
3186 UndoState nUndo = new UndoState(this, gofwd.ForGroup);
3187
3188 m_undo.Add(nUndo);
3189
3190 if (m_undo.Count > ParentGroup.Scene.MaxUndoCount)
3191 m_undo.RemoveAt(0);
3192 }
3193
3194 gofwd.PlayfwdState(this);
3195 3805
3196// m_log.DebugFormat( 3806 lock (m_UndoRedo)
3197// "[SCENE OBJECT PART]: Handled redo request for {0} {1}, stack size now {2}", 3807 {
3198// Name, LocalId, m_redo.Count); 3808 Undoing = true;
3199 } 3809 m_UndoRedo.Redo(this);
3810 Undoing = false;
3200 } 3811 }
3201 } 3812 }
3202 3813
3203 public void ClearUndoState() 3814 public void ClearUndoState()
3204 { 3815 {
3205// m_log.DebugFormat("[SCENE OBJECT PART]: Clearing undo and redo stacks in {0} {1}", Name, LocalId); 3816 if (m_UndoRedo == null || Undoing)
3817 return;
3206 3818
3207 lock (m_undo) 3819 lock (m_UndoRedo)
3208 { 3820 {
3209 m_undo.Clear(); 3821 m_UndoRedo.Clear();
3210 m_redo.Clear();
3211 } 3822 }
3212 } 3823 }
3213 3824
@@ -3757,7 +4368,7 @@ namespace OpenSim.Region.Framework.Scenes
3757 if (god) 4368 if (god)
3758 { 4369 {
3759 BaseMask = ApplyMask(BaseMask, set, mask); 4370 BaseMask = ApplyMask(BaseMask, set, mask);
3760 Inventory.ApplyGodPermissions(_baseMask); 4371 Inventory.ApplyGodPermissions(BaseMask);
3761 } 4372 }
3762 4373
3763 break; 4374 break;
@@ -3776,7 +4387,7 @@ namespace OpenSim.Region.Framework.Scenes
3776 case 16: 4387 case 16:
3777 NextOwnerMask = ApplyMask(NextOwnerMask, set, mask) & 4388 NextOwnerMask = ApplyMask(NextOwnerMask, set, mask) &
3778 baseMask; 4389 baseMask;
3779 // Prevent the client from creating no mod, no copy 4390 // Prevent the client from creating no copy, no transfer
3780 // objects 4391 // objects
3781 if ((NextOwnerMask & (uint)PermissionMask.Copy) == 0) 4392 if ((NextOwnerMask & (uint)PermissionMask.Copy) == 0)
3782 NextOwnerMask |= (uint)PermissionMask.Transfer; 4393 NextOwnerMask |= (uint)PermissionMask.Transfer;
@@ -3794,20 +4405,20 @@ namespace OpenSim.Region.Framework.Scenes
3794 { 4405 {
3795 bool update = false; 4406 bool update = false;
3796 4407
3797 if (BaseMask != source.BaseMask || 4408 uint prevOwnerMask = OwnerMask;
3798 OwnerMask != source.OwnerMask || 4409 uint prevGroupMask = GroupMask;
3799 GroupMask != source.GroupMask || 4410 uint prevEveryoneMask = EveryoneMask;
3800 EveryoneMask != source.EveryoneMask || 4411 uint prevNextOwnerMask = NextOwnerMask;
3801 NextOwnerMask != source.NextOwnerMask)
3802 update = true;
3803 4412
3804 BaseMask = source.BaseMask; 4413 OwnerMask = source.OwnerMask & BaseMask;
3805 OwnerMask = source.OwnerMask; 4414 GroupMask = source.GroupMask & BaseMask;
3806 GroupMask = source.GroupMask; 4415 EveryoneMask = source.EveryoneMask & BaseMask;
3807 EveryoneMask = source.EveryoneMask; 4416 NextOwnerMask = source.NextOwnerMask & BaseMask;
3808 NextOwnerMask = source.NextOwnerMask;
3809 4417
3810 if (update) 4418 if (OwnerMask != prevOwnerMask ||
4419 GroupMask != prevGroupMask ||
4420 EveryoneMask != prevEveryoneMask ||
4421 NextOwnerMask != prevNextOwnerMask)
3811 SendFullUpdateToAllClients(); 4422 SendFullUpdateToAllClients();
3812 } 4423 }
3813 4424
@@ -3858,6 +4469,27 @@ namespace OpenSim.Region.Framework.Scenes
3858 } 4469 }
3859 } 4470 }
3860 4471
4472
4473 public void UpdateExtraPhysics(ExtraPhysicsData physdata)
4474 {
4475 if (physdata.PhysShapeType == PhysShapeType.invalid || ParentGroup == null)
4476 return;
4477
4478 if (PhysicsShapeType != (byte)physdata.PhysShapeType)
4479 {
4480 PhysicsShapeType = (byte)physdata.PhysShapeType;
4481
4482 }
4483
4484 if(Density != physdata.Density)
4485 Density = physdata.Density;
4486 if(GravityModifier != physdata.GravitationModifier)
4487 GravityModifier = physdata.GravitationModifier;
4488 if(Friction != physdata.Friction)
4489 Friction = physdata.Friction;
4490 if(Bounciness != physdata.Bounce)
4491 Bounciness = physdata.Bounce;
4492 }
3861 /// <summary> 4493 /// <summary>
3862 /// Update the flags on this prim. This covers properties such as phantom, physics and temporary. 4494 /// Update the flags on this prim. This covers properties such as phantom, physics and temporary.
3863 /// </summary> 4495 /// </summary>
@@ -3865,7 +4497,7 @@ namespace OpenSim.Region.Framework.Scenes
3865 /// <param name="SetTemporary"></param> 4497 /// <param name="SetTemporary"></param>
3866 /// <param name="SetPhantom"></param> 4498 /// <param name="SetPhantom"></param>
3867 /// <param name="SetVD"></param> 4499 /// <param name="SetVD"></param>
3868 public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD) 4500 public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD, bool building)
3869 { 4501 {
3870 bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0); 4502 bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0);
3871 bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0); 4503 bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0);
@@ -3875,214 +4507,230 @@ namespace OpenSim.Region.Framework.Scenes
3875 if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD)) 4507 if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD))
3876 return; 4508 return;
3877 4509
3878 PhysicsActor pa = PhysActor; 4510 VolumeDetectActive = SetVD;
3879
3880 // Special cases for VD. VD can only be called from a script
3881 // and can't be combined with changes to other states. So we can rely
3882 // that...
3883 // ... if VD is changed, all others are not.
3884 // ... if one of the others is changed, VD is not.
3885 if (SetVD) // VD is active, special logic applies
3886 {
3887 // State machine logic for VolumeDetect
3888 // More logic below
3889 bool phanReset = (SetPhantom != wasPhantom) && !SetPhantom;
3890
3891 if (phanReset) // Phantom changes from on to off switch VD off too
3892 {
3893 SetVD = false; // Switch it of for the course of this routine
3894 VolumeDetectActive = false; // and also permanently
3895
3896 if (pa != null)
3897 pa.SetVolumeDetect(0); // Let physics know about it too
3898 }
3899 else
3900 {
3901 // If volumedetect is active we don't want phantom to be applied.
3902 // If this is a new call to VD out of the state "phantom"
3903 // this will also cause the prim to be visible to physics
3904 SetPhantom = false;
3905 }
3906 }
3907 4511
3908 if (UsePhysics && IsJoint()) 4512 // volume detector implies phantom
3909 { 4513 if (VolumeDetectActive)
3910 SetPhantom = true; 4514 SetPhantom = true;
3911 }
3912 4515
3913 if (UsePhysics) 4516 if (UsePhysics)
3914 {
3915 AddFlag(PrimFlags.Physics); 4517 AddFlag(PrimFlags.Physics);
3916 if (!wasUsingPhysics)
3917 {
3918 DoPhysicsPropertyUpdate(UsePhysics, false);
3919 }
3920 }
3921 else 4518 else
3922 {
3923 RemFlag(PrimFlags.Physics); 4519 RemFlag(PrimFlags.Physics);
3924 if (wasUsingPhysics)
3925 {
3926 DoPhysicsPropertyUpdate(UsePhysics, false);
3927 }
3928 }
3929 4520
3930 if (SetPhantom 4521 if (SetPhantom)
3931 || ParentGroup.IsAttachment
3932 || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints
3933 {
3934 AddFlag(PrimFlags.Phantom); 4522 AddFlag(PrimFlags.Phantom);
3935 4523 else
3936 if (PhysActor != null)
3937 {
3938 RemoveFromPhysics();
3939 pa = null;
3940 }
3941 }
3942 else // Not phantom
3943 {
3944 RemFlag(PrimFlags.Phantom); 4524 RemFlag(PrimFlags.Phantom);
3945 4525
3946 if (ParentGroup.Scene == null) 4526 if (SetTemporary)
3947 return; 4527 AddFlag(PrimFlags.TemporaryOnRez);
4528 else
4529 RemFlag(PrimFlags.TemporaryOnRez);
3948 4530
3949 if (ParentGroup.Scene.CollidablePrims && pa == null)
3950 {
3951 pa = AddToPhysics(UsePhysics);
3952 4531
3953 if (pa != null) 4532 if (ParentGroup.Scene == null)
3954 { 4533 return;
3955 pa.SetMaterial(Material); 4534
3956 DoPhysicsPropertyUpdate(UsePhysics, true); 4535 PhysicsActor pa = PhysActor;
3957
3958 if (
3959 ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
3960 ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
3961 ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
3962 ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
3963 ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
3964 ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
3965 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision) != 0) ||
3966 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
3967 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
3968 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
3969 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
3970 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
3971 (CollisionSound != UUID.Zero)
3972 )
3973 {
3974 pa.OnCollisionUpdate += PhysicsCollision;
3975 pa.SubscribeEvents(1000);
3976 }
3977 }
3978 }
3979 else // it already has a physical representation
3980 {
3981 DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status. If it's phantom this will remove the prim
3982 }
3983 }
3984 4536
3985 if (SetVD) 4537 if (pa != null && building && pa.Building != building)
4538 pa.Building = building;
4539
4540 if ((SetPhantom && !UsePhysics && !SetVD) || ParentGroup.IsAttachment || PhysicsShapeType == (byte)PhysShapeType.none
4541 || (Shape.PathCurve == (byte)Extrusion.Flexible))
3986 { 4542 {
3987 // If the above logic worked (this is urgent candidate to unit tests!)
3988 // we now have a physicsactor.
3989 // Defensive programming calls for a check here.
3990 // Better would be throwing an exception that could be catched by a unit test as the internal
3991 // logic should make sure, this Physactor is always here.
3992 if (pa != null) 4543 if (pa != null)
3993 { 4544 {
3994 pa.SetVolumeDetect(1); 4545 if(wasUsingPhysics)
3995 AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active 4546 ParentGroup.Scene.RemovePhysicalPrim(1);
3996 VolumeDetectActive = true; 4547 RemoveFromPhysics();
3997 } 4548 }
4549
4550 Velocity = new Vector3(0, 0, 0);
4551 Acceleration = new Vector3(0, 0, 0);
4552 if (ParentGroup.RootPart == this)
4553 AngularVelocity = new Vector3(0, 0, 0);
3998 } 4554 }
3999 else if (SetVD != wasVD) 4555 else if (SetVD != wasVD)
4000 { 4556 {
4001 // Remove VolumeDetect in any case. Note, it's safe to call SetVolumeDetect as often as you like 4557 if (ParentGroup.Scene.CollidablePrims)
4002 // (mumbles, well, at least if you have infinte CPU powers :-)) 4558 {
4003 if (pa != null) 4559 if (pa == null)
4004 pa.SetVolumeDetect(0); 4560 {
4561 AddToPhysics(UsePhysics, SetPhantom, building, false);
4562 pa = PhysActor;
4563/*
4564 if (pa != null)
4565 {
4566 if (
4567// ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
4568// ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4569// ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4570// ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4571// ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4572// ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4573 ((AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) ||
4574 ((ParentGroup.RootPart.AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) ||
4575 (CollisionSound != UUID.Zero)
4576 )
4577 {
4578 pa.OnCollisionUpdate += PhysicsCollision;
4579 pa.SubscribeEvents(1000);
4580 }
4581 }
4582*/
4583 }
4584 else // it already has a physical representation
4585 {
4586 DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status.
4587/* moved into DoPhysicsPropertyUpdate
4588 if(VolumeDetectActive)
4589 pa.SetVolumeDetect(1);
4590 else
4591 pa.SetVolumeDetect(0);
4592*/
4005 4593
4006 RemFlag(PrimFlags.Phantom); 4594 if (pa.Building != building)
4007 VolumeDetectActive = false; 4595 pa.Building = building;
4008 } 4596 }
4009 4597
4010 if (SetTemporary) 4598 UpdatePhysicsSubscribedEvents();
4011 { 4599 }
4012 AddFlag(PrimFlags.TemporaryOnRez); 4600 }
4013 }
4014 else
4015 {
4016 RemFlag(PrimFlags.TemporaryOnRez);
4017 }
4018 4601
4019 // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString()); 4602 // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString());
4020 4603
4604 // and last in case we have a new actor and not building
4605
4021 if (ParentGroup != null) 4606 if (ParentGroup != null)
4022 { 4607 {
4023 ParentGroup.HasGroupChanged = true; 4608 ParentGroup.HasGroupChanged = true;
4024 ScheduleFullUpdate(); 4609 ScheduleFullUpdate();
4025 } 4610 }
4026 4611
4027// m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags); 4612// m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags);
4028 } 4613 }
4029 4614
4030 /// <summary> 4615 /// <summary>
4031 /// Adds this part to the physics scene. 4616 /// Adds this part to the physics scene.
4617 /// and sets the PhysActor property
4032 /// </summary> 4618 /// </summary>
4033 /// <remarks>This method also sets the PhysActor property.</remarks> 4619 /// <param name="isPhysical">Add this prim as physical.</param>
4034 /// <param name="rigidBody">Add this prim with a rigid body.</param> 4620 /// <param name="isPhantom">Add this prim as phantom.</param>
4035 /// <returns> 4621 /// <param name="building">tells physics to delay full construction of object</param>
4036 /// The physics actor. null if there was a failure. 4622 /// <param name="applyDynamics">applies velocities, force and torque</param>
4037 /// </returns> 4623 private void AddToPhysics(bool isPhysical, bool isPhantom, bool building, bool applyDynamics)
4038 private PhysicsActor AddToPhysics(bool rigidBody) 4624 {
4039 {
4040 PhysicsActor pa; 4625 PhysicsActor pa;
4041 4626
4627 Vector3 velocity = Velocity;
4628 Vector3 rotationalVelocity = AngularVelocity;;
4629
4042 try 4630 try
4043 { 4631 {
4044 pa = ParentGroup.Scene.PhysicsScene.AddPrimShape( 4632 pa = ParentGroup.Scene.PhysicsScene.AddPrimShape(
4045 string.Format("{0}/{1}", Name, UUID), 4633 string.Format("{0}/{1}", Name, UUID),
4046 Shape, 4634 Shape,
4047 AbsolutePosition, 4635 AbsolutePosition,
4048 Scale, 4636 Scale,
4049 RotationOffset, 4637 GetWorldRotation(),
4050 rigidBody, 4638 isPhysical,
4051 m_localId); 4639 isPhantom,
4640 PhysicsShapeType,
4641 m_localId);
4052 } 4642 }
4053 catch 4643 catch (Exception ex)
4054 { 4644 {
4055 m_log.ErrorFormat("[SCENE]: caught exception meshing object {0}. Object set to phantom.", m_uuid); 4645 m_log.ErrorFormat("[SCENE]: AddToPhysics object {0} failed: {1}", m_uuid, ex.Message);
4056 pa = null; 4646 pa = null;
4057 } 4647 }
4058 4648
4059 // FIXME: Ideally we wouldn't set the property here to reduce situations where threads changing physical
4060 // properties can stop on each other. However, DoPhysicsPropertyUpdate() currently relies on PhysActor
4061 // being set.
4062 PhysActor = pa;
4063
4064 // Basic Physics can also return null as well as an exception catch.
4065 if (pa != null) 4649 if (pa != null)
4066 { 4650 {
4067 pa.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info 4651 pa.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info
4068 pa.SetMaterial(Material); 4652 pa.SetMaterial(Material);
4069 DoPhysicsPropertyUpdate(rigidBody, true); 4653
4654 if (VolumeDetectActive) // change if not the default only
4655 pa.SetVolumeDetect(1);
4656
4657 if (m_vehicleParams != null && LocalId == ParentGroup.RootPart.LocalId)
4658 m_vehicleParams.SetVehicle(pa);
4659
4660 // we are going to tell rest of code about physics so better have this here
4661 PhysActor = pa;
4662
4663 // DoPhysicsPropertyUpdate(isPhysical, true);
4664 // lets expand it here just with what it really needs to do
4665
4666 if (isPhysical)
4667 {
4668 if (ParentGroup.RootPart.KeyframeMotion != null)
4669 ParentGroup.RootPart.KeyframeMotion.Stop();
4670 ParentGroup.RootPart.KeyframeMotion = null;
4671 ParentGroup.Scene.AddPhysicalPrim(1);
4672
4673 pa.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
4674 pa.OnOutOfBounds += PhysicsOutOfBounds;
4675
4676 if (ParentID != 0 && ParentID != LocalId)
4677 {
4678 PhysicsActor parentPa = ParentGroup.RootPart.PhysActor;
4679
4680 if (parentPa != null)
4681 {
4682 pa.link(parentPa);
4683 }
4684 }
4685 }
4686
4687 if (applyDynamics)
4688 // do independent of isphysical so parameters get setted (at least some)
4689 {
4690 Velocity = velocity;
4691 AngularVelocity = rotationalVelocity;
4692// pa.Velocity = velocity;
4693 pa.RotationalVelocity = rotationalVelocity;
4694
4695 // if not vehicle and root part apply force and torque
4696 if ((m_vehicleParams == null || m_vehicleParams.Type == Vehicle.TYPE_NONE)
4697 && LocalId == ParentGroup.RootPart.LocalId)
4698 {
4699 pa.Force = Force;
4700 pa.Torque = Torque;
4701 }
4702 }
4703
4704// if (Shape.SculptEntry)
4705// CheckSculptAndLoad();
4706// else
4707 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
4708
4709 if (!building)
4710 pa.Building = false;
4070 } 4711 }
4071 4712
4072 return pa; 4713 PhysActor = pa;
4073 } 4714 }
4074 4715
4075 /// <summary> 4716 /// <summary>
4076 /// This removes the part from the physics scene. 4717 /// This removes the part from the physics scene.
4077 /// </summary> 4718 /// </summary>
4078 /// <remarks> 4719 /// <remarks>
4079 /// This isn't the same as turning off physical, since even without being physical the prim has a physics 4720 /// This isn't the same as turning off physical, since even without being physical the prim has a physics
4080 /// representation for collision detection. Rather, this would be used in situations such as making a prim 4721 /// representation for collision detection.
4081 /// phantom.
4082 /// </remarks> 4722 /// </remarks>
4083 public void RemoveFromPhysics() 4723 public void RemoveFromPhysics()
4084 { 4724 {
4085 ParentGroup.Scene.PhysicsScene.RemovePrim(PhysActor); 4725 PhysicsActor pa = PhysActor;
4726 if (pa != null)
4727 {
4728 pa.OnCollisionUpdate -= PhysicsCollision;
4729 pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
4730 pa.OnOutOfBounds -= PhysicsOutOfBounds;
4731
4732 ParentGroup.Scene.PhysicsScene.RemovePrim(pa);
4733 }
4086 PhysActor = null; 4734 PhysActor = null;
4087 } 4735 }
4088 4736
@@ -4214,6 +4862,8 @@ namespace OpenSim.Region.Framework.Scenes
4214 { 4862 {
4215// m_log.DebugFormat("Processing CheckSculptAndLoad for {0} {1}", Name, LocalId); 4863// m_log.DebugFormat("Processing CheckSculptAndLoad for {0} {1}", Name, LocalId);
4216 4864
4865 return;
4866
4217 if (ParentGroup.IsDeleted) 4867 if (ParentGroup.IsDeleted)
4218 return; 4868 return;
4219 4869
@@ -4294,6 +4944,44 @@ namespace OpenSim.Region.Framework.Scenes
4294 ScheduleFullUpdate(); 4944 ScheduleFullUpdate();
4295 } 4945 }
4296 4946
4947
4948 private void UpdatePhysicsSubscribedEvents()
4949 {
4950 PhysicsActor pa = PhysActor;
4951 if (pa == null)
4952 return;
4953
4954 pa.OnCollisionUpdate -= PhysicsCollision;
4955
4956 bool hassound = (!VolumeDetectActive && CollisionSoundType >= 0 && ((Flags & PrimFlags.Physics) != 0));
4957
4958 scriptEvents CombinedEvents = AggregateScriptEvents;
4959
4960 // merge with root part
4961 if (ParentGroup != null && ParentGroup.RootPart != null)
4962 CombinedEvents |= ParentGroup.RootPart.AggregateScriptEvents;
4963
4964 // submit to this part case
4965 if (VolumeDetectActive)
4966 CombinedEvents &= PhyscicsVolumeDtcSubsEvents;
4967 else if ((Flags & PrimFlags.Phantom) != 0)
4968 CombinedEvents &= PhyscicsPhantonSubsEvents;
4969 else
4970 CombinedEvents &= PhysicsNeededSubsEvents;
4971
4972 if (hassound || CombinedEvents != 0)
4973 {
4974 // subscribe to physics updates.
4975 pa.OnCollisionUpdate += PhysicsCollision;
4976 pa.SubscribeEvents(50); // 20 reports per second
4977 }
4978 else
4979 {
4980 pa.UnSubscribeEvents();
4981 }
4982 }
4983
4984
4297 public void aggregateScriptEvents() 4985 public void aggregateScriptEvents()
4298 { 4986 {
4299 if (ParentGroup == null || ParentGroup.RootPart == null) 4987 if (ParentGroup == null || ParentGroup.RootPart == null)
@@ -4330,40 +5018,32 @@ namespace OpenSim.Region.Framework.Scenes
4330 { 5018 {
4331 objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop; 5019 objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop;
4332 } 5020 }
4333 5021/*
4334 PhysicsActor pa = PhysActor; 5022 PhysicsActor pa = PhysActor;
4335 5023 if (pa != null)
4336 if (
4337 ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
4338 ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4339 ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4340 ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4341 ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4342 ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4343 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision) != 0) ||
4344 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4345 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4346 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4347 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4348 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4349 (CollisionSound != UUID.Zero)
4350 )
4351 { 5024 {
4352 // subscribe to physics updates. 5025 if (
4353 if (pa != null) 5026// ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
5027// ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
5028// ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
5029// ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
5030// ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
5031// ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
5032 ((AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) || ((ParentGroup.RootPart.AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) || (CollisionSound != UUID.Zero)
5033 )
4354 { 5034 {
5035 // subscribe to physics updates.
4355 pa.OnCollisionUpdate += PhysicsCollision; 5036 pa.OnCollisionUpdate += PhysicsCollision;
4356 pa.SubscribeEvents(1000); 5037 pa.SubscribeEvents(1000);
4357 } 5038 }
4358 } 5039 else
4359 else
4360 {
4361 if (pa != null)
4362 { 5040 {
4363 pa.UnSubscribeEvents(); 5041 pa.UnSubscribeEvents();
4364 pa.OnCollisionUpdate -= PhysicsCollision; 5042 pa.OnCollisionUpdate -= PhysicsCollision;
4365 } 5043 }
4366 } 5044 }
5045 */
5046 UpdatePhysicsSubscribedEvents();
4367 5047
4368 //if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0) 5048 //if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0)
4369 //{ 5049 //{
@@ -4494,6 +5174,18 @@ namespace OpenSim.Region.Framework.Scenes
4494 return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A)); 5174 return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A));
4495 } 5175 }
4496 5176
5177 public void ResetOwnerChangeFlag()
5178 {
5179 List<UUID> inv = Inventory.GetInventoryList();
5180
5181 foreach (UUID itemID in inv)
5182 {
5183 TaskInventoryItem item = Inventory.GetInventoryItem(itemID);
5184 item.OwnerChanged = false;
5185 Inventory.UpdateInventoryItem(item, false, false);
5186 }
5187 }
5188
4497 /// <summary> 5189 /// <summary>
4498 /// Record an avatar sitting on this part. 5190 /// Record an avatar sitting on this part.
4499 /// </summary> 5191 /// </summary>