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.cs1709
1 files changed, 1192 insertions, 517 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index 411dcc7..8e419f9 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 Stack<UndoState> m_undo = new Stack<UndoState>(5); 294 private UndoRedoState m_UndoRedo = null;
270 private readonly Stack<UndoState> m_redo = new Stack<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)
@@ -769,7 +816,22 @@ namespace OpenSim.Region.Framework.Scenes
769 if (ParentGroup.Scene != null) 816 if (ParentGroup.Scene != 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,319 @@ 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.Cost;
1587
1588 if ((Flags & PrimFlags.Physics) != 0)
1589 cost *= (1.0f + 0.01333f * Scale.LengthSquared()); // 0.01333 == 0.04/3
1590 return cost;
1591 }
1592 }
1593
1594 [XmlIgnore]
1595 public float StreamingCost
1596 {
1597 get
1598 {
1599
1600
1601 return 0.1f;
1602 }
1603 }
1604
1605 [XmlIgnore]
1606 public float SimulationCost
1607 {
1608 get
1609 {
1610 // ignoring scripts. Don't like considering them for this
1611 if((Flags & PrimFlags.Physics) != 0)
1612 return 1.0f;
1613
1614 return 0.5f;
1615 }
1616 }
1617
1618 public byte PhysicsShapeType
1619 {
1620 get { return m_physicsShapeType; }
1621 set
1622 {
1623 byte oldv = m_physicsShapeType;
1624
1625 if (value >= 0 && value <= (byte)PhysShapeType.convex)
1626 {
1627 if (value == (byte)PhysShapeType.none && ParentGroup != null && ParentGroup.RootPart == this)
1628 m_physicsShapeType = DefaultPhysicsShapeType();
1629 else
1630 m_physicsShapeType = value;
1631 }
1632 else
1633 m_physicsShapeType = DefaultPhysicsShapeType();
1634
1635 if (m_physicsShapeType != oldv && ParentGroup != null)
1636 {
1637 if (m_physicsShapeType == (byte)PhysShapeType.none)
1638 {
1639 if (PhysActor != null)
1640 {
1641 Velocity = new Vector3(0, 0, 0);
1642 Acceleration = new Vector3(0, 0, 0);
1643 if (ParentGroup.RootPart == this)
1644 AngularVelocity = new Vector3(0, 0, 0);
1645 ParentGroup.Scene.RemovePhysicalPrim(1);
1646 RemoveFromPhysics();
1647 }
1648 }
1649 else if (PhysActor == null)
1650 {
1651 ApplyPhysics((uint)Flags, VolumeDetectActive, false);
1652 UpdatePhysicsSubscribedEvents();
1653 }
1654 else
1655 {
1656 PhysActor.PhysicsShapeType = m_physicsShapeType;
1657 if (Shape.SculptEntry)
1658 CheckSculptAndLoad();
1659 }
1660
1661 if (ParentGroup != null)
1662 ParentGroup.HasGroupChanged = true;
1663 }
1664
1665 if (m_physicsShapeType != value)
1666 {
1667 UpdatePhysRequired = true;
1668 }
1669 }
1670 }
1671
1672 public float Density // in kg/m^3
1673 {
1674 get { return m_density; }
1675 set
1676 {
1677 if (value >=1 && value <= 22587.0)
1678 {
1679 m_density = value;
1680 UpdatePhysRequired = true;
1681 }
1682
1683 ScheduleFullUpdateIfNone();
1684
1685 if (ParentGroup != null)
1686 ParentGroup.HasGroupChanged = true;
1687 }
1688 }
1689
1690 public float GravityModifier
1691 {
1692 get { return m_gravitymod; }
1693 set
1694 {
1695 if( value >= -1 && value <=28.0f)
1696 {
1697 m_gravitymod = value;
1698 UpdatePhysRequired = true;
1699 }
1700
1701 ScheduleFullUpdateIfNone();
1702
1703 if (ParentGroup != null)
1704 ParentGroup.HasGroupChanged = true;
1705
1706 }
1707 }
1708
1709 public float Friction
1710 {
1711 get { return m_friction; }
1712 set
1713 {
1714 if (value >= 0 && value <= 255.0f)
1715 {
1716 m_friction = value;
1717 UpdatePhysRequired = true;
1718 }
1719
1720 ScheduleFullUpdateIfNone();
1721
1722 if (ParentGroup != null)
1723 ParentGroup.HasGroupChanged = true;
1724 }
1725 }
1726
1727 public float Bounciness
1728 {
1729 get { return m_bounce; }
1730 set
1731 {
1732 if (value >= 0 && value <= 1.0f)
1733 {
1734 m_bounce = value;
1735 UpdatePhysRequired = true;
1736 }
1737
1738 ScheduleFullUpdateIfNone();
1739
1740 if (ParentGroup != null)
1741 ParentGroup.HasGroupChanged = true;
1742 }
1743 }
1744
1745
1318 #endregion Public Properties with only Get 1746 #endregion Public Properties with only Get
1319 1747
1320 private uint ApplyMask(uint val, bool set, uint mask) 1748 private uint ApplyMask(uint val, bool set, uint mask)
@@ -1460,6 +1888,61 @@ namespace OpenSim.Region.Framework.Scenes
1460 } 1888 }
1461 } 1889 }
1462 1890
1891 // SetVelocity for LSL llSetVelocity.. may need revision if having other uses in future
1892 public void SetVelocity(Vector3 pVel, bool localGlobalTF)
1893 {
1894 if (ParentGroup == null || ParentGroup.IsDeleted)
1895 return;
1896
1897 if (ParentGroup.IsAttachment)
1898 return; // don't work on attachments (for now ??)
1899
1900 SceneObjectPart root = ParentGroup.RootPart;
1901
1902 if (root.VehicleType != (int)Vehicle.TYPE_NONE) // don't mess with vehicles
1903 return;
1904
1905 PhysicsActor pa = root.PhysActor;
1906
1907 if (pa == null || !pa.IsPhysical)
1908 return;
1909
1910 if (localGlobalTF)
1911 {
1912 pVel = pVel * GetWorldRotation();
1913 }
1914
1915 ParentGroup.Velocity = pVel;
1916 }
1917
1918 // SetAngularVelocity for LSL llSetAngularVelocity.. may need revision if having other uses in future
1919 public void SetAngularVelocity(Vector3 pAngVel, bool localGlobalTF)
1920 {
1921 if (ParentGroup == null || ParentGroup.IsDeleted)
1922 return;
1923
1924 if (ParentGroup.IsAttachment)
1925 return; // don't work on attachments (for now ??)
1926
1927 SceneObjectPart root = ParentGroup.RootPart;
1928
1929 if (root.VehicleType != (int)Vehicle.TYPE_NONE) // don't mess with vehicles
1930 return;
1931
1932 PhysicsActor pa = root.PhysActor;
1933
1934 if (pa == null || !pa.IsPhysical)
1935 return;
1936
1937 if (localGlobalTF)
1938 {
1939 pAngVel = pAngVel * GetWorldRotation();
1940 }
1941
1942 root.AngularVelocity = pAngVel;
1943 }
1944
1945
1463 /// <summary> 1946 /// <summary>
1464 /// hook to the physics scene to apply angular impulse 1947 /// hook to the physics scene to apply angular impulse
1465 /// This is sent up to the group, which then finds the root prim 1948 /// This is sent up to the group, which then finds the root prim
@@ -1480,7 +1963,7 @@ namespace OpenSim.Region.Framework.Scenes
1480 impulse = newimpulse; 1963 impulse = newimpulse;
1481 } 1964 }
1482 1965
1483 ParentGroup.applyAngularImpulse(impulse); 1966 ParentGroup.ApplyAngularImpulse(impulse);
1484 } 1967 }
1485 1968
1486 /// <summary> 1969 /// <summary>
@@ -1490,20 +1973,24 @@ namespace OpenSim.Region.Framework.Scenes
1490 /// </summary> 1973 /// </summary>
1491 /// <param name="impulsei">Vector force</param> 1974 /// <param name="impulsei">Vector force</param>
1492 /// <param name="localGlobalTF">true for the local frame, false for the global frame</param> 1975 /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
1493 public void SetAngularImpulse(Vector3 impulsei, bool localGlobalTF) 1976
1977 // this is actualy Set Torque.. keeping naming so not to edit lslapi also
1978 public void SetAngularImpulse(Vector3 torquei, bool localGlobalTF)
1494 { 1979 {
1495 Vector3 impulse = impulsei; 1980 Vector3 torque = torquei;
1496 1981
1497 if (localGlobalTF) 1982 if (localGlobalTF)
1498 { 1983 {
1984/*
1499 Quaternion grot = GetWorldRotation(); 1985 Quaternion grot = GetWorldRotation();
1500 Quaternion AXgrot = grot; 1986 Quaternion AXgrot = grot;
1501 Vector3 AXimpulsei = impulsei; 1987 Vector3 AXimpulsei = impulsei;
1502 Vector3 newimpulse = AXimpulsei * AXgrot; 1988 Vector3 newimpulse = AXimpulsei * AXgrot;
1503 impulse = newimpulse; 1989 */
1990 torque *= GetWorldRotation();
1504 } 1991 }
1505 1992
1506 ParentGroup.setAngularImpulse(impulse); 1993 Torque = torque;
1507 } 1994 }
1508 1995
1509 /// <summary> 1996 /// <summary>
@@ -1511,17 +1998,23 @@ namespace OpenSim.Region.Framework.Scenes
1511 /// </summary> 1998 /// </summary>
1512 /// <param name="rootObjectFlags"></param> 1999 /// <param name="rootObjectFlags"></param>
1513 /// <param name="VolumeDetectActive"></param> 2000 /// <param name="VolumeDetectActive"></param>
1514 public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive) 2001 /// <param name="building"></param>
2002
2003 public void ApplyPhysics(uint _ObjectFlags, bool _VolumeDetectActive, bool building)
1515 { 2004 {
2005 VolumeDetectActive = _VolumeDetectActive;
2006
1516 if (!ParentGroup.Scene.CollidablePrims) 2007 if (!ParentGroup.Scene.CollidablePrims)
1517 return; 2008 return;
1518 2009
1519// m_log.DebugFormat( 2010 if (PhysicsShapeType == (byte)PhysShapeType.none)
1520// "[SCENE OBJECT PART]: Applying physics to {0} {1}, m_physicalPrim {2}", 2011 return;
1521// Name, LocalId, UUID, m_physicalPrim);
1522 2012
1523 bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0; 2013 bool isPhysical = (_ObjectFlags & (uint) PrimFlags.Physics) != 0;
1524 bool isPhantom = (rootObjectFlags & (uint) PrimFlags.Phantom) != 0; 2014 bool isPhantom = (_ObjectFlags & (uint)PrimFlags.Phantom) != 0;
2015
2016 if (_VolumeDetectActive)
2017 isPhantom = true;
1525 2018
1526 if (IsJoint()) 2019 if (IsJoint())
1527 { 2020 {
@@ -1529,22 +2022,14 @@ namespace OpenSim.Region.Framework.Scenes
1529 } 2022 }
1530 else 2023 else
1531 { 2024 {
1532 // Special case for VolumeDetection: If VolumeDetection is set, the phantom flag is locally ignored 2025 if ((!isPhantom || isPhysical || _VolumeDetectActive) && !ParentGroup.IsAttachment
1533 if (VolumeDetectActive) 2026 && !(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 { 2027 {
1540 // Added clarification.. since A rigid body is an object that you can kick around, etc. 2028 AddToPhysics(isPhysical, isPhantom, building, isPhysical);
1541 bool rigidBody = isPhysical && !isPhantom; 2029 UpdatePhysicsSubscribedEvents(); // not sure if appliable here
1542
1543 PhysicsActor pa = AddToPhysics(rigidBody);
1544
1545 if (pa != null)
1546 pa.SetVolumeDetect(VolumeDetectActive ? 1 : 0);
1547 } 2030 }
2031 else
2032 PhysActor = null; // just to be sure
1548 } 2033 }
1549 } 2034 }
1550 2035
@@ -1596,6 +2081,12 @@ namespace OpenSim.Region.Framework.Scenes
1596 dupe.Category = Category; 2081 dupe.Category = Category;
1597 dupe.m_rezzed = m_rezzed; 2082 dupe.m_rezzed = m_rezzed;
1598 2083
2084 dupe.m_UndoRedo = null;
2085 dupe.m_isSelected = false;
2086
2087 dupe.IgnoreUndoUpdate = false;
2088 dupe.Undoing = false;
2089
1599 dupe.m_inventory = new SceneObjectPartInventory(dupe); 2090 dupe.m_inventory = new SceneObjectPartInventory(dupe);
1600 dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone(); 2091 dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone();
1601 2092
@@ -1611,6 +2102,7 @@ namespace OpenSim.Region.Framework.Scenes
1611 2102
1612 // Move afterwards ResetIDs as it clears the localID 2103 // Move afterwards ResetIDs as it clears the localID
1613 dupe.LocalId = localID; 2104 dupe.LocalId = localID;
2105
1614 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated. 2106 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
1615 dupe.LastOwnerID = OwnerID; 2107 dupe.LastOwnerID = OwnerID;
1616 2108
@@ -1618,6 +2110,9 @@ namespace OpenSim.Region.Framework.Scenes
1618 Array.Copy(Shape.ExtraParams, extraP, extraP.Length); 2110 Array.Copy(Shape.ExtraParams, extraP, extraP.Length);
1619 dupe.Shape.ExtraParams = extraP; 2111 dupe.Shape.ExtraParams = extraP;
1620 2112
2113 if (KeyframeMotion != null)
2114 dupe.KeyframeMotion = KeyframeMotion.Copy(null);
2115
1621 if (userExposed) 2116 if (userExposed)
1622 { 2117 {
1623 if (dupe.m_shape.SculptEntry && dupe.m_shape.SculptTexture != UUID.Zero) 2118 if (dupe.m_shape.SculptEntry && dupe.m_shape.SculptTexture != UUID.Zero)
@@ -1628,8 +2123,12 @@ namespace OpenSim.Region.Framework.Scenes
1628 2123
1629 bool UsePhysics = ((dupe.Flags & PrimFlags.Physics) != 0); 2124 bool UsePhysics = ((dupe.Flags & PrimFlags.Physics) != 0);
1630 dupe.DoPhysicsPropertyUpdate(UsePhysics, true); 2125 dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
2126// dupe.UpdatePhysicsSubscribedEvents(); // not sure...
1631 } 2127 }
1632 2128
2129 if (dupe.PhysActor != null)
2130 dupe.PhysActor.LocalID = localID;
2131
1633 ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed); 2132 ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed);
1634 2133
1635// m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID); 2134// m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID);
@@ -1749,6 +2248,7 @@ namespace OpenSim.Region.Framework.Scenes
1749 2248
1750 /// <summary> 2249 /// <summary>
1751 /// Do a physics propery update for this part. 2250 /// Do a physics propery update for this part.
2251 /// now also updates phantom and volume detector
1752 /// </summary> 2252 /// </summary>
1753 /// <param name="UsePhysics"></param> 2253 /// <param name="UsePhysics"></param>
1754 /// <param name="isNew"></param> 2254 /// <param name="isNew"></param>
@@ -1774,61 +2274,69 @@ namespace OpenSim.Region.Framework.Scenes
1774 { 2274 {
1775 if (pa.IsPhysical) // implies UsePhysics==false for this block 2275 if (pa.IsPhysical) // implies UsePhysics==false for this block
1776 { 2276 {
1777 if (!isNew) 2277 if (!isNew) // implies UsePhysics==false for this block
2278 {
1778 ParentGroup.Scene.RemovePhysicalPrim(1); 2279 ParentGroup.Scene.RemovePhysicalPrim(1);
1779 2280
1780 pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate; 2281 Velocity = new Vector3(0, 0, 0);
1781 pa.OnOutOfBounds -= PhysicsOutOfBounds; 2282 Acceleration = new Vector3(0, 0, 0);
1782 pa.delink(); 2283 if (ParentGroup.RootPart == this)
2284 AngularVelocity = new Vector3(0, 0, 0);
1783 2285
1784 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints && (!isNew)) 2286 if (pa.Phantom && !VolumeDetectActive)
1785 { 2287 {
1786 // destroy all joints connected to this now deactivated body 2288 RemoveFromPhysics();
1787 ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(pa); 2289 return;
1788 } 2290 }
1789 2291
1790 // stop client-side interpolation of all joint proxy objects that have just been deleted 2292 pa.IsPhysical = UsePhysics;
1791 // this is done because RemoveAllJointsConnectedToActor invokes the OnJointDeactivated callback, 2293 pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
1792 // which stops client-side interpolation of deactivated joint proxy objects. 2294 pa.OnOutOfBounds -= PhysicsOutOfBounds;
2295 pa.delink();
2296 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
2297 {
2298 // destroy all joints connected to this now deactivated body
2299 ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(pa);
2300 }
2301 }
1793 } 2302 }
1794 2303
1795 if (!UsePhysics && !isNew) 2304 if (pa.IsPhysical != UsePhysics)
1796 { 2305 pa.IsPhysical = UsePhysics;
1797 // reset velocity to 0 on physics switch-off. Without that, the client thinks the
1798 // prim still has velocity and continues to interpolate its position along the old
1799 // velocity-vector.
1800 Velocity = new Vector3(0, 0, 0);
1801 Acceleration = new Vector3(0, 0, 0);
1802 AngularVelocity = new Vector3(0, 0, 0);
1803 //RotationalVelocity = new Vector3(0, 0, 0);
1804 }
1805 2306
1806 pa.IsPhysical = UsePhysics; 2307 if (UsePhysics)
2308 {
2309 if (ParentGroup.RootPart.KeyframeMotion != null)
2310 ParentGroup.RootPart.KeyframeMotion.Stop();
2311 ParentGroup.RootPart.KeyframeMotion = null;
2312 ParentGroup.Scene.AddPhysicalPrim(1);
1807 2313
1808 // If we're not what we're supposed to be in the physics scene, recreate ourselves. 2314 PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
1809 //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor); 2315 PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
1810 /// that's not wholesome. Had to make Scene public
1811 //PhysActor = null;
1812 2316
1813 if ((Flags & PrimFlags.Phantom) == 0) 2317 if (ParentID != 0 && ParentID != LocalId)
1814 {
1815 if (UsePhysics)
1816 { 2318 {
1817 ParentGroup.Scene.AddPhysicalPrim(1); 2319 PhysicsActor parentPa = ParentGroup.RootPart.PhysActor;
1818 2320
1819 pa.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate; 2321 if (parentPa != null)
1820 pa.OnOutOfBounds += PhysicsOutOfBounds;
1821 if (ParentID != 0 && ParentID != LocalId)
1822 { 2322 {
1823 PhysicsActor parentPa = ParentGroup.RootPart.PhysActor; 2323 pa.link(parentPa);
1824
1825 if (parentPa != null)
1826 {
1827 pa.link(parentPa);
1828 }
1829 } 2324 }
1830 } 2325 }
1831 } 2326 }
2327 }
2328
2329 bool phan = ((Flags & PrimFlags.Phantom) != 0);
2330 if (pa.Phantom != phan)
2331 pa.Phantom = phan;
2332
2333// some engines dont' have this check still
2334// if (VolumeDetectActive != pa.IsVolumeDtc)
2335 {
2336 if (VolumeDetectActive)
2337 pa.SetVolumeDetect(1);
2338 else
2339 pa.SetVolumeDetect(0);
1832 } 2340 }
1833 2341
1834 // If this part is a sculpt then delay the physics update until we've asynchronously loaded the 2342 // If this part is a sculpt then delay the physics update until we've asynchronously loaded the
@@ -1947,12 +2455,26 @@ namespace OpenSim.Region.Framework.Scenes
1947 2455
1948 public Vector3 GetGeometricCenter() 2456 public Vector3 GetGeometricCenter()
1949 { 2457 {
1950 PhysicsActor pa = PhysActor; 2458 // this is not real geometric center but a average of positions relative to root prim acording to
1951 2459 // http://wiki.secondlife.com/wiki/llGetGeometricCenter
1952 if (pa != null) 2460 // ignoring tortured prims details since sl also seems to ignore
1953 return new Vector3(pa.CenterOfMass.X, pa.CenterOfMass.Y, pa.CenterOfMass.Z); 2461 // so no real use in doing it on physics
1954 else 2462 if (ParentGroup.IsDeleted)
1955 return new Vector3(0, 0, 0); 2463 return new Vector3(0, 0, 0);
2464
2465 return ParentGroup.GetGeometricCenter();
2466
2467 /*
2468 PhysicsActor pa = PhysActor;
2469
2470 if (pa != null)
2471 {
2472 Vector3 vtmp = pa.CenterOfMass;
2473 return vtmp;
2474 }
2475 else
2476 return new Vector3(0, 0, 0);
2477 */
1956 } 2478 }
1957 2479
1958 public float GetMass() 2480 public float GetMass()
@@ -1965,14 +2487,43 @@ namespace OpenSim.Region.Framework.Scenes
1965 return 0; 2487 return 0;
1966 } 2488 }
1967 2489
1968 public Vector3 GetForce() 2490 public Vector3 GetCenterOfMass()
1969 { 2491 {
2492 if (ParentGroup.RootPart == this)
2493 {
2494 if (ParentGroup.IsDeleted)
2495 return AbsolutePosition;
2496 return ParentGroup.GetCenterOfMass();
2497 }
2498
1970 PhysicsActor pa = PhysActor; 2499 PhysicsActor pa = PhysActor;
1971 2500
1972 if (pa != null) 2501 if (pa != null)
1973 return pa.Force; 2502 {
2503 Vector3 tmp = pa.CenterOfMass;
2504 return tmp;
2505 }
1974 else 2506 else
1975 return Vector3.Zero; 2507 return AbsolutePosition;
2508 }
2509
2510 public Vector3 GetPartCenterOfMass()
2511 {
2512 PhysicsActor pa = PhysActor;
2513
2514 if (pa != null)
2515 {
2516 Vector3 tmp = pa.CenterOfMass;
2517 return tmp;
2518 }
2519 else
2520 return AbsolutePosition;
2521 }
2522
2523
2524 public Vector3 GetForce()
2525 {
2526 return Force;
1976 } 2527 }
1977 2528
1978 /// <summary> 2529 /// <summary>
@@ -2187,15 +2738,25 @@ namespace OpenSim.Region.Framework.Scenes
2187 2738
2188 private void SendLandCollisionEvent(scriptEvents ev, ScriptCollidingNotification notify) 2739 private void SendLandCollisionEvent(scriptEvents ev, ScriptCollidingNotification notify)
2189 { 2740 {
2190 if ((ParentGroup.RootPart.ScriptEvents & ev) != 0) 2741 bool sendToRoot = true;
2191 { 2742
2192 ColliderArgs LandCollidingMessage = new ColliderArgs(); 2743 ColliderArgs LandCollidingMessage = new ColliderArgs();
2193 List<DetectedObject> colliding = new List<DetectedObject>(); 2744 List<DetectedObject> colliding = new List<DetectedObject>();
2194 2745
2195 colliding.Add(CreateDetObjectForGround()); 2746 colliding.Add(CreateDetObjectForGround());
2196 LandCollidingMessage.Colliders = colliding; 2747 LandCollidingMessage.Colliders = colliding;
2197 2748
2749 if (Inventory.ContainsScripts())
2750 {
2751 if (!PassCollisions)
2752 sendToRoot = false;
2753 }
2754 if ((ScriptEvents & ev) != 0)
2198 notify(LocalId, LandCollidingMessage); 2755 notify(LocalId, LandCollidingMessage);
2756
2757 if ((ParentGroup.RootPart.ScriptEvents & ev) != 0 && sendToRoot)
2758 {
2759 notify(ParentGroup.RootPart.LocalId, LandCollidingMessage);
2199 } 2760 }
2200 } 2761 }
2201 2762
@@ -2211,45 +2772,87 @@ namespace OpenSim.Region.Framework.Scenes
2211 List<uint> endedColliders = new List<uint>(); 2772 List<uint> endedColliders = new List<uint>();
2212 List<uint> startedColliders = new List<uint>(); 2773 List<uint> startedColliders = new List<uint>();
2213 2774
2214 // calculate things that started colliding this time 2775 if (collissionswith.Count == 0)
2215 // and build up list of colliders this time
2216 foreach (uint localid in collissionswith.Keys)
2217 { 2776 {
2218 thisHitColliders.Add(localid); 2777 if (m_lastColliders.Count == 0)
2219 if (!m_lastColliders.Contains(localid)) 2778 return; // nothing to do
2220 startedColliders.Add(localid);
2221 }
2222 2779
2223 // calculate things that ended colliding 2780 foreach (uint localID in m_lastColliders)
2224 foreach (uint localID in m_lastColliders) 2781 {
2225 {
2226 if (!thisHitColliders.Contains(localID))
2227 endedColliders.Add(localID); 2782 endedColliders.Add(localID);
2783 }
2784 m_lastColliders.Clear();
2228 } 2785 }
2229 2786
2230 //add the items that started colliding this time to the last colliders list. 2787 else
2231 foreach (uint localID in startedColliders) 2788 {
2232 m_lastColliders.Add(localID); 2789 List<CollisionForSoundInfo> soundinfolist = new List<CollisionForSoundInfo>();
2790
2791 // calculate things that started colliding this time
2792 // and build up list of colliders this time
2793 if (!VolumeDetectActive && CollisionSoundType >= 0)
2794 {
2795 CollisionForSoundInfo soundinfo;
2796 ContactPoint curcontact;
2797
2798 foreach (uint id in collissionswith.Keys)
2799 {
2800 thisHitColliders.Add(id);
2801 if (!m_lastColliders.Contains(id))
2802 {
2803 startedColliders.Add(id);
2804
2805 curcontact = collissionswith[id];
2806 if (Math.Abs(curcontact.RelativeSpeed) > 0.2)
2807 {
2808 soundinfo = new CollisionForSoundInfo();
2809 soundinfo.colliderID = id;
2810 soundinfo.position = curcontact.Position;
2811 soundinfo.relativeVel = curcontact.RelativeSpeed;
2812 soundinfolist.Add(soundinfo);
2813 }
2814 }
2815 }
2816 }
2817 else
2818 {
2819 foreach (uint id in collissionswith.Keys)
2820 {
2821 thisHitColliders.Add(id);
2822 if (!m_lastColliders.Contains(id))
2823 startedColliders.Add(id);
2824 }
2825 }
2826
2827 // calculate things that ended colliding
2828 foreach (uint localID in m_lastColliders)
2829 {
2830 if (!thisHitColliders.Contains(localID))
2831 endedColliders.Add(localID);
2832 }
2233 2833
2234 // remove things that ended colliding from the last colliders list 2834 //add the items that started colliding this time to the last colliders list.
2235 foreach (uint localID in endedColliders) 2835 foreach (uint localID in startedColliders)
2236 m_lastColliders.Remove(localID); 2836 m_lastColliders.Add(localID);
2237 2837
2238 // play the sound. 2838 // remove things that ended colliding from the last colliders list
2239 if (startedColliders.Count > 0 && CollisionSound != UUID.Zero && CollisionSoundVolume > 0.0f) 2839 foreach (uint localID in endedColliders)
2240 SendSound(CollisionSound.ToString(), CollisionSoundVolume, true, (byte)0, 0, false, false); 2840 m_lastColliders.Remove(localID);
2841
2842 // play sounds.
2843 if (soundinfolist.Count > 0)
2844 CollisionSounds.PartCollisionSound(this, soundinfolist);
2845 }
2241 2846
2242 SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart); 2847 SendCollisionEvent(scriptEvents.collision_start, startedColliders, ParentGroup.Scene.EventManager.TriggerScriptCollidingStart);
2243 SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding); 2848 if (!VolumeDetectActive)
2849 SendCollisionEvent(scriptEvents.collision , m_lastColliders , ParentGroup.Scene.EventManager.TriggerScriptColliding);
2244 SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd); 2850 SendCollisionEvent(scriptEvents.collision_end , endedColliders , ParentGroup.Scene.EventManager.TriggerScriptCollidingEnd);
2245 2851
2246 if (startedColliders.Contains(0)) 2852 if (startedColliders.Contains(0))
2247 { 2853 SendLandCollisionEvent(scriptEvents.land_collision_start, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingStart);
2248 if (m_lastColliders.Contains(0)) 2854 if (m_lastColliders.Contains(0))
2249 SendLandCollisionEvent(scriptEvents.land_collision, ParentGroup.Scene.EventManager.TriggerScriptLandColliding); 2855 SendLandCollisionEvent(scriptEvents.land_collision, ParentGroup.Scene.EventManager.TriggerScriptLandColliding);
2250 else
2251 SendLandCollisionEvent(scriptEvents.land_collision_start, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingStart);
2252 }
2253 if (endedColliders.Contains(0)) 2856 if (endedColliders.Contains(0))
2254 SendLandCollisionEvent(scriptEvents.land_collision_end, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd); 2857 SendLandCollisionEvent(scriptEvents.land_collision_end, ParentGroup.Scene.EventManager.TriggerScriptLandCollidingEnd);
2255 } 2858 }
@@ -2272,9 +2875,9 @@ namespace OpenSim.Region.Framework.Scenes
2272 Vector3 newpos = new Vector3(pa.Position.GetBytes(), 0); 2875 Vector3 newpos = new Vector3(pa.Position.GetBytes(), 0);
2273 2876
2274 if (ParentGroup.Scene.TestBorderCross(newpos, Cardinals.N) 2877 if (ParentGroup.Scene.TestBorderCross(newpos, Cardinals.N)
2275 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.S) 2878 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.S)
2276 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.E) 2879 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.E)
2277 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.W)) 2880 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.W))
2278 { 2881 {
2279 ParentGroup.AbsolutePosition = newpos; 2882 ParentGroup.AbsolutePosition = newpos;
2280 return; 2883 return;
@@ -2296,17 +2899,18 @@ namespace OpenSim.Region.Framework.Scenes
2296 //Trys to fetch sound id from prim's inventory. 2899 //Trys to fetch sound id from prim's inventory.
2297 //Prim's inventory doesn't support non script items yet 2900 //Prim's inventory doesn't support non script items yet
2298 2901
2299 lock (TaskInventory) 2902 TaskInventory.LockItemsForRead(true);
2903
2904 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2300 { 2905 {
2301 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 2906 if (item.Value.Name == sound)
2302 { 2907 {
2303 if (item.Value.Name == sound) 2908 soundID = item.Value.ItemID;
2304 { 2909 break;
2305 soundID = item.Value.ItemID;
2306 break;
2307 }
2308 } 2910 }
2309 } 2911 }
2912
2913 TaskInventory.LockItemsForRead(false);
2310 } 2914 }
2311 2915
2312 ParentGroup.Scene.ForEachRootScenePresence(delegate(ScenePresence sp) 2916 ParentGroup.Scene.ForEachRootScenePresence(delegate(ScenePresence sp)
@@ -2428,6 +3032,19 @@ namespace OpenSim.Region.Framework.Scenes
2428 APIDTarget = Quaternion.Identity; 3032 APIDTarget = Quaternion.Identity;
2429 } 3033 }
2430 3034
3035
3036
3037 public void ScheduleFullUpdateIfNone()
3038 {
3039 if (ParentGroup == null)
3040 return;
3041
3042// ??? ParentGroup.HasGroupChanged = true;
3043
3044 if (UpdateFlag != UpdateRequired.FULL)
3045 ScheduleFullUpdate();
3046 }
3047
2431 /// <summary> 3048 /// <summary>
2432 /// Schedules this prim for a full update 3049 /// Schedules this prim for a full update
2433 /// </summary> 3050 /// </summary>
@@ -2630,8 +3247,8 @@ namespace OpenSim.Region.Framework.Scenes
2630 { 3247 {
2631 const float ROTATION_TOLERANCE = 0.01f; 3248 const float ROTATION_TOLERANCE = 0.01f;
2632 const float VELOCITY_TOLERANCE = 0.001f; 3249 const float VELOCITY_TOLERANCE = 0.001f;
2633 const float POSITION_TOLERANCE = 0.05f; 3250 const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
2634 const int TIME_MS_TOLERANCE = 3000; 3251 const int TIME_MS_TOLERANCE = 200; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
2635 3252
2636 switch (UpdateFlag) 3253 switch (UpdateFlag)
2637 { 3254 {
@@ -2693,17 +3310,16 @@ namespace OpenSim.Region.Framework.Scenes
2693 if (!UUID.TryParse(sound, out soundID)) 3310 if (!UUID.TryParse(sound, out soundID))
2694 { 3311 {
2695 // search sound file from inventory 3312 // search sound file from inventory
2696 lock (TaskInventory) 3313 TaskInventory.LockItemsForRead(true);
3314 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2697 { 3315 {
2698 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 3316 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
2699 { 3317 {
2700 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) 3318 soundID = item.Value.ItemID;
2701 { 3319 break;
2702 soundID = item.Value.ItemID;
2703 break;
2704 }
2705 } 3320 }
2706 } 3321 }
3322 TaskInventory.LockItemsForRead(false);
2707 } 3323 }
2708 3324
2709 if (soundID == UUID.Zero) 3325 if (soundID == UUID.Zero)
@@ -2760,11 +3376,43 @@ namespace OpenSim.Region.Framework.Scenes
2760 } 3376 }
2761 } 3377 }
2762 3378
3379 public void SendCollisionSound(UUID soundID, double volume, Vector3 position)
3380 {
3381 if (soundID == UUID.Zero)
3382 return;
3383
3384 ISoundModule soundModule = ParentGroup.Scene.RequestModuleInterface<ISoundModule>();
3385 if (soundModule == null)
3386 return;
3387
3388 if (volume > 1)
3389 volume = 1;
3390 if (volume < 0)
3391 volume = 0;
3392
3393 int now = Util.EnvironmentTickCount();
3394 if(Util.EnvironmentTickCountSubtract(now,LastColSoundSentTime) <200)
3395 return;
3396
3397 LastColSoundSentTime = now;
3398
3399 UUID ownerID = OwnerID;
3400 UUID objectID = ParentGroup.RootPart.UUID;
3401 UUID parentID = ParentGroup.UUID;
3402 ulong regionHandle = ParentGroup.Scene.RegionInfo.RegionHandle;
3403
3404 soundModule.TriggerSound(soundID, ownerID, objectID, parentID, volume, position, regionHandle, 0 );
3405 }
3406
3407
2763 /// <summary> 3408 /// <summary>
2764 /// Send a terse update to all clients 3409 /// Send a terse update to all clients
2765 /// </summary> 3410 /// </summary>
2766 public void SendTerseUpdateToAllClients() 3411 public void SendTerseUpdateToAllClients()
2767 { 3412 {
3413 if (ParentGroup == null || ParentGroup.Scene == null)
3414 return;
3415
2768 ParentGroup.Scene.ForEachClient(delegate(IClientAPI client) 3416 ParentGroup.Scene.ForEachClient(delegate(IClientAPI client)
2769 { 3417 {
2770 SendTerseUpdateToClient(client); 3418 SendTerseUpdateToClient(client);
@@ -2788,10 +3436,13 @@ namespace OpenSim.Region.Framework.Scenes
2788 3436
2789 public void SetBuoyancy(float fvalue) 3437 public void SetBuoyancy(float fvalue)
2790 { 3438 {
2791 PhysicsActor pa = PhysActor; 3439 Buoyancy = fvalue;
2792 3440/*
2793 if (pa != null) 3441 if (PhysActor != null)
2794 pa.Buoyancy = fvalue; 3442 {
3443 PhysActor.Buoyancy = fvalue;
3444 }
3445 */
2795 } 3446 }
2796 3447
2797 public void SetDieAtEdge(bool p) 3448 public void SetDieAtEdge(bool p)
@@ -2807,47 +3458,111 @@ namespace OpenSim.Region.Framework.Scenes
2807 PhysicsActor pa = PhysActor; 3458 PhysicsActor pa = PhysActor;
2808 3459
2809 if (pa != null) 3460 if (pa != null)
2810 pa.FloatOnWater = floatYN == 1; 3461 pa.FloatOnWater = (floatYN == 1);
2811 } 3462 }
2812 3463
2813 public void SetForce(Vector3 force) 3464 public void SetForce(Vector3 force)
2814 { 3465 {
2815 PhysicsActor pa = PhysActor; 3466 Force = force;
3467 }
2816 3468
2817 if (pa != null) 3469 public SOPVehicle VehicleParams
2818 pa.Force = force; 3470 {
3471 get
3472 {
3473 return m_vehicleParams;
3474 }
3475 set
3476 {
3477 m_vehicleParams = value;
3478 }
3479 }
3480
3481
3482 public int VehicleType
3483 {
3484 get
3485 {
3486 if (m_vehicleParams == null)
3487 return (int)Vehicle.TYPE_NONE;
3488 else
3489 return (int)m_vehicleParams.Type;
3490 }
3491 set
3492 {
3493 SetVehicleType(value);
3494 }
2819 } 3495 }
2820 3496
2821 public void SetVehicleType(int type) 3497 public void SetVehicleType(int type)
2822 { 3498 {
2823 PhysicsActor pa = PhysActor; 3499 m_vehicleParams = null;
3500
3501 if (type == (int)Vehicle.TYPE_NONE)
3502 {
3503 if (_parentID ==0 && PhysActor != null)
3504 PhysActor.VehicleType = (int)Vehicle.TYPE_NONE;
3505 return;
3506 }
3507 m_vehicleParams = new SOPVehicle();
3508 m_vehicleParams.ProcessTypeChange((Vehicle)type);
3509 {
3510 if (_parentID ==0 && PhysActor != null)
3511 PhysActor.VehicleType = type;
3512 return;
3513 }
3514 }
2824 3515
2825 if (pa != null) 3516 public void SetVehicleFlags(int param, bool remove)
2826 pa.VehicleType = type; 3517 {
3518 if (m_vehicleParams == null)
3519 return;
3520
3521 m_vehicleParams.ProcessVehicleFlags(param, remove);
3522
3523 if (_parentID ==0 && PhysActor != null)
3524 {
3525 PhysActor.VehicleFlags(param, remove);
3526 }
2827 } 3527 }
2828 3528
2829 public void SetVehicleFloatParam(int param, float value) 3529 public void SetVehicleFloatParam(int param, float value)
2830 { 3530 {
2831 PhysicsActor pa = PhysActor; 3531 if (m_vehicleParams == null)
3532 return;
2832 3533
2833 if (pa != null) 3534 m_vehicleParams.ProcessFloatVehicleParam((Vehicle)param, value);
2834 pa.VehicleFloatParam(param, value); 3535
3536 if (_parentID == 0 && PhysActor != null)
3537 {
3538 PhysActor.VehicleFloatParam(param, value);
3539 }
2835 } 3540 }
2836 3541
2837 public void SetVehicleVectorParam(int param, Vector3 value) 3542 public void SetVehicleVectorParam(int param, Vector3 value)
2838 { 3543 {
2839 PhysicsActor pa = PhysActor; 3544 if (m_vehicleParams == null)
3545 return;
2840 3546
2841 if (pa != null) 3547 m_vehicleParams.ProcessVectorVehicleParam((Vehicle)param, value);
2842 pa.VehicleVectorParam(param, value); 3548
3549 if (_parentID == 0 && PhysActor != null)
3550 {
3551 PhysActor.VehicleVectorParam(param, value);
3552 }
2843 } 3553 }
2844 3554
2845 public void SetVehicleRotationParam(int param, Quaternion rotation) 3555 public void SetVehicleRotationParam(int param, Quaternion rotation)
2846 { 3556 {
2847 PhysicsActor pa = PhysActor; 3557 if (m_vehicleParams == null)
3558 return;
2848 3559
2849 if (pa != null) 3560 m_vehicleParams.ProcessRotationVehicleParam((Vehicle)param, rotation);
2850 pa.VehicleRotationParam(param, rotation); 3561
3562 if (_parentID == 0 && PhysActor != null)
3563 {
3564 PhysActor.VehicleRotationParam(param, rotation);
3565 }
2851 } 3566 }
2852 3567
2853 /// <summary> 3568 /// <summary>
@@ -3048,14 +3763,6 @@ namespace OpenSim.Region.Framework.Scenes
3048 hasProfileCut = hasDimple; // is it the same thing? 3763 hasProfileCut = hasDimple; // is it the same thing?
3049 } 3764 }
3050 3765
3051 public void SetVehicleFlags(int param, bool remove)
3052 {
3053 PhysicsActor pa = PhysActor;
3054
3055 if (pa != null)
3056 pa.VehicleFlags(param, remove);
3057 }
3058
3059 public void SetGroup(UUID groupID, IClientAPI client) 3766 public void SetGroup(UUID groupID, IClientAPI client)
3060 { 3767 {
3061 // Scene.AddNewPrims() calls with client == null so can't use this. 3768 // Scene.AddNewPrims() calls with client == null so can't use this.
@@ -3159,68 +3866,18 @@ namespace OpenSim.Region.Framework.Scenes
3159 //ParentGroup.ScheduleGroupForFullUpdate(); 3866 //ParentGroup.ScheduleGroupForFullUpdate();
3160 } 3867 }
3161 3868
3162 public void StoreUndoState() 3869 public void StoreUndoState(ObjectChangeType change)
3163 { 3870 {
3164 StoreUndoState(false); 3871 if (m_UndoRedo == null)
3165 } 3872 m_UndoRedo = new UndoRedoState(5);
3166 3873
3167 public void StoreUndoState(bool forGroup) 3874 lock (m_UndoRedo)
3168 {
3169 if (!Undoing)
3170 { 3875 {
3171 if (!IgnoreUndoUpdate) 3876 if (!Undoing && !IgnoreUndoUpdate && ParentGroup != null) // just to read better - undo is in progress, or suspended
3172 { 3877 {
3173 if (ParentGroup != null) 3878 m_UndoRedo.StoreUndo(this, change);
3174 {
3175 lock (m_undo)
3176 {
3177 if (m_undo.Count > 0)
3178 {
3179 UndoState last = m_undo.Peek();
3180 if (last != null)
3181 {
3182 // TODO: May need to fix for group comparison
3183 if (last.Compare(this))
3184 {
3185 // m_log.DebugFormat(
3186 // "[SCENE OBJECT PART]: Not storing undo for {0} {1} since current state is same as last undo state, initial stack size {2}",
3187 // Name, LocalId, m_undo.Count);
3188
3189 return;
3190 }
3191 }
3192 }
3193
3194 // m_log.DebugFormat(
3195 // "[SCENE OBJECT PART]: Storing undo state for {0} {1}, forGroup {2}, initial stack size {3}",
3196 // Name, LocalId, forGroup, m_undo.Count);
3197
3198 if (ParentGroup.GetSceneMaxUndo() > 0)
3199 {
3200 UndoState nUndo = new UndoState(this, forGroup);
3201
3202 m_undo.Push(nUndo);
3203
3204 if (m_redo.Count > 0)
3205 m_redo.Clear();
3206
3207 // m_log.DebugFormat(
3208 // "[SCENE OBJECT PART]: Stored undo state for {0} {1}, forGroup {2}, stack size now {3}",
3209 // Name, LocalId, forGroup, m_undo.Count);
3210 }
3211 }
3212 }
3213 } 3879 }
3214// else
3215// {
3216// m_log.DebugFormat("[SCENE OBJECT PART]: Ignoring undo store for {0} {1}", Name, LocalId);
3217// }
3218 } 3880 }
3219// else
3220// {
3221// m_log.DebugFormat(
3222// "[SCENE OBJECT PART]: Ignoring undo store for {0} {1} since already undoing", Name, LocalId);
3223// }
3224 } 3881 }
3225 3882
3226 /// <summary> 3883 /// <summary>
@@ -3230,84 +3887,46 @@ namespace OpenSim.Region.Framework.Scenes
3230 { 3887 {
3231 get 3888 get
3232 { 3889 {
3233 lock (m_undo) 3890 if (m_UndoRedo == null)
3234 return m_undo.Count; 3891 return 0;
3892 return m_UndoRedo.Count;
3235 } 3893 }
3236 } 3894 }
3237 3895
3238 public void Undo() 3896 public void Undo()
3239 { 3897 {
3240 lock (m_undo) 3898 if (m_UndoRedo == null || Undoing || ParentGroup == null)
3241 { 3899 return;
3242// m_log.DebugFormat(
3243// "[SCENE OBJECT PART]: Handling undo request for {0} {1}, stack size {2}",
3244// Name, LocalId, m_undo.Count);
3245
3246 if (m_undo.Count > 0)
3247 {
3248 UndoState goback = m_undo.Pop();
3249
3250 if (goback != null)
3251 {
3252 UndoState nUndo = null;
3253
3254 if (ParentGroup.GetSceneMaxUndo() > 0)
3255 {
3256 nUndo = new UndoState(this, goback.ForGroup);
3257 }
3258
3259 goback.PlaybackState(this);
3260
3261 if (nUndo != null)
3262 m_redo.Push(nUndo);
3263 }
3264 }
3265 3900
3266// m_log.DebugFormat( 3901 lock (m_UndoRedo)
3267// "[SCENE OBJECT PART]: Handled undo request for {0} {1}, stack size now {2}", 3902 {
3268// Name, LocalId, m_undo.Count); 3903 Undoing = true;
3904 m_UndoRedo.Undo(this);
3905 Undoing = false;
3269 } 3906 }
3270 } 3907 }
3271 3908
3272 public void Redo() 3909 public void Redo()
3273 { 3910 {
3274 lock (m_undo) 3911 if (m_UndoRedo == null || Undoing || ParentGroup == null)
3275 { 3912 return;
3276// m_log.DebugFormat(
3277// "[SCENE OBJECT PART]: Handling redo request for {0} {1}, stack size {2}",
3278// Name, LocalId, m_redo.Count);
3279
3280 if (m_redo.Count > 0)
3281 {
3282 UndoState gofwd = m_redo.Pop();
3283
3284 if (gofwd != null)
3285 {
3286 if (ParentGroup.GetSceneMaxUndo() > 0)
3287 {
3288 UndoState nUndo = new UndoState(this, gofwd.ForGroup);
3289
3290 m_undo.Push(nUndo);
3291 }
3292
3293 gofwd.PlayfwdState(this);
3294 }
3295 3913
3296// m_log.DebugFormat( 3914 lock (m_UndoRedo)
3297// "[SCENE OBJECT PART]: Handled redo request for {0} {1}, stack size now {2}", 3915 {
3298// Name, LocalId, m_redo.Count); 3916 Undoing = true;
3299 } 3917 m_UndoRedo.Redo(this);
3918 Undoing = false;
3300 } 3919 }
3301 } 3920 }
3302 3921
3303 public void ClearUndoState() 3922 public void ClearUndoState()
3304 { 3923 {
3305// m_log.DebugFormat("[SCENE OBJECT PART]: Clearing undo and redo stacks in {0} {1}", Name, LocalId); 3924 if (m_UndoRedo == null || Undoing)
3925 return;
3306 3926
3307 lock (m_undo) 3927 lock (m_UndoRedo)
3308 { 3928 {
3309 m_undo.Clear(); 3929 m_UndoRedo.Clear();
3310 m_redo.Clear();
3311 } 3930 }
3312 } 3931 }
3313 3932
@@ -3958,6 +4577,27 @@ namespace OpenSim.Region.Framework.Scenes
3958 } 4577 }
3959 } 4578 }
3960 4579
4580
4581 public void UpdateExtraPhysics(ExtraPhysicsData physdata)
4582 {
4583 if (physdata.PhysShapeType == PhysShapeType.invalid || ParentGroup == null)
4584 return;
4585
4586 if (PhysicsShapeType != (byte)physdata.PhysShapeType)
4587 {
4588 PhysicsShapeType = (byte)physdata.PhysShapeType;
4589
4590 }
4591
4592 if(Density != physdata.Density)
4593 Density = physdata.Density;
4594 if(GravityModifier != physdata.GravitationModifier)
4595 GravityModifier = physdata.GravitationModifier;
4596 if(Friction != physdata.Friction)
4597 Friction = physdata.Friction;
4598 if(Bounciness != physdata.Bounce)
4599 Bounciness = physdata.Bounce;
4600 }
3961 /// <summary> 4601 /// <summary>
3962 /// Update the flags on this prim. This covers properties such as phantom, physics and temporary. 4602 /// Update the flags on this prim. This covers properties such as phantom, physics and temporary.
3963 /// </summary> 4603 /// </summary>
@@ -3965,7 +4605,7 @@ namespace OpenSim.Region.Framework.Scenes
3965 /// <param name="SetTemporary"></param> 4605 /// <param name="SetTemporary"></param>
3966 /// <param name="SetPhantom"></param> 4606 /// <param name="SetPhantom"></param>
3967 /// <param name="SetVD"></param> 4607 /// <param name="SetVD"></param>
3968 public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD) 4608 public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD, bool building)
3969 { 4609 {
3970 bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0); 4610 bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0);
3971 bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0); 4611 bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0);
@@ -3975,237 +4615,230 @@ namespace OpenSim.Region.Framework.Scenes
3975 if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD)) 4615 if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD))
3976 return; 4616 return;
3977 4617
3978 PhysicsActor pa = PhysActor; 4618 VolumeDetectActive = SetVD;
3979
3980 // Special cases for VD. VD can only be called from a script
3981 // and can't be combined with changes to other states. So we can rely
3982 // that...
3983 // ... if VD is changed, all others are not.
3984 // ... if one of the others is changed, VD is not.
3985 if (SetVD) // VD is active, special logic applies
3986 {
3987 // State machine logic for VolumeDetect
3988 // More logic below
3989 bool phanReset = (SetPhantom != wasPhantom) && !SetPhantom;
3990
3991 if (phanReset) // Phantom changes from on to off switch VD off too
3992 {
3993 SetVD = false; // Switch it of for the course of this routine
3994 VolumeDetectActive = false; // and also permanently
3995
3996 if (pa != null)
3997 pa.SetVolumeDetect(0); // Let physics know about it too
3998 }
3999 else
4000 {
4001 // If volumedetect is active we don't want phantom to be applied.
4002 // If this is a new call to VD out of the state "phantom"
4003 // this will also cause the prim to be visible to physics
4004 SetPhantom = false;
4005 }
4006 }
4007 4619
4008 if (UsePhysics && IsJoint()) 4620 // volume detector implies phantom
4009 { 4621 if (VolumeDetectActive)
4010 SetPhantom = true; 4622 SetPhantom = true;
4011 }
4012 4623
4013 if (UsePhysics) 4624 if (UsePhysics)
4014 {
4015 AddFlag(PrimFlags.Physics); 4625 AddFlag(PrimFlags.Physics);
4016 if (!wasUsingPhysics)
4017 {
4018 DoPhysicsPropertyUpdate(UsePhysics, false);
4019
4020 if (!ParentGroup.IsDeleted)
4021 {
4022 if (LocalId == ParentGroup.RootPart.LocalId)
4023 {
4024 ParentGroup.CheckSculptAndLoad();
4025 }
4026 }
4027 }
4028 }
4029 else 4626 else
4030 {
4031 RemFlag(PrimFlags.Physics); 4627 RemFlag(PrimFlags.Physics);
4032 if (wasUsingPhysics)
4033 {
4034 DoPhysicsPropertyUpdate(UsePhysics, false);
4035 }
4036 }
4037 4628
4038 if (SetPhantom 4629 if (SetPhantom)
4039 || ParentGroup.IsAttachment
4040 || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints
4041 {
4042 AddFlag(PrimFlags.Phantom); 4630 AddFlag(PrimFlags.Phantom);
4631 else
4632 RemFlag(PrimFlags.Phantom);
4043 4633
4044 if (PhysActor != null) 4634 if (SetTemporary)
4635 AddFlag(PrimFlags.TemporaryOnRez);
4636 else
4637 RemFlag(PrimFlags.TemporaryOnRez);
4638
4639
4640 if (ParentGroup.Scene == null)
4641 return;
4642
4643 PhysicsActor pa = PhysActor;
4644
4645 if (pa != null && building && pa.Building != building)
4646 pa.Building = building;
4647
4648 if ((SetPhantom && !UsePhysics && !SetVD) || ParentGroup.IsAttachment || PhysicsShapeType == (byte)PhysShapeType.none
4649 || (Shape.PathCurve == (byte)Extrusion.Flexible))
4650 {
4651 if (pa != null)
4045 { 4652 {
4653 if(wasUsingPhysics)
4654 ParentGroup.Scene.RemovePhysicalPrim(1);
4046 RemoveFromPhysics(); 4655 RemoveFromPhysics();
4047 pa = null;
4048 } 4656 }
4657
4658 Velocity = new Vector3(0, 0, 0);
4659 Acceleration = new Vector3(0, 0, 0);
4660 if (ParentGroup.RootPart == this)
4661 AngularVelocity = new Vector3(0, 0, 0);
4049 } 4662 }
4050 else // Not phantom 4663 else
4051 { 4664 {
4052 RemFlag(PrimFlags.Phantom); 4665 if (ParentGroup.Scene.CollidablePrims)
4053
4054 if (ParentGroup.Scene == null)
4055 return;
4056
4057 if (ParentGroup.Scene.CollidablePrims && pa == null)
4058 { 4666 {
4059 pa = AddToPhysics(UsePhysics); 4667 if (pa == null)
4060
4061 if (pa != null)
4062 { 4668 {
4063 pa.SetMaterial(Material); 4669 AddToPhysics(UsePhysics, SetPhantom, building, false);
4064 DoPhysicsPropertyUpdate(UsePhysics, true); 4670 pa = PhysActor;
4065 4671/*
4066 if (!ParentGroup.IsDeleted) 4672 if (pa != null)
4067 { 4673 {
4068 if (LocalId == ParentGroup.RootPart.LocalId) 4674 if (
4675// ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
4676// ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4677// ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4678// ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4679// ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4680// ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4681 ((AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) ||
4682 ((ParentGroup.RootPart.AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) ||
4683 (CollisionSound != UUID.Zero)
4684 )
4069 { 4685 {
4070 ParentGroup.CheckSculptAndLoad(); 4686 pa.OnCollisionUpdate += PhysicsCollision;
4687 pa.SubscribeEvents(1000);
4071 } 4688 }
4072 } 4689 }
4073 4690*/
4074 if (
4075 ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
4076 ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4077 ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4078 ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4079 ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4080 ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4081 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision) != 0) ||
4082 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4083 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4084 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4085 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4086 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4087 (CollisionSound != UUID.Zero)
4088 )
4089 {
4090 pa.OnCollisionUpdate += PhysicsCollision;
4091 pa.SubscribeEvents(1000);
4092 }
4093 } 4691 }
4094 } 4692 else // it already has a physical representation
4095 else // it already has a physical representation
4096 {
4097 DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status. If it's phantom this will remove the prim
4098
4099 if (!ParentGroup.IsDeleted)
4100 { 4693 {
4101 if (LocalId == ParentGroup.RootPart.LocalId) 4694 DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status.
4102 { 4695/* moved into DoPhysicsPropertyUpdate
4103 ParentGroup.CheckSculptAndLoad(); 4696 if(VolumeDetectActive)
4104 } 4697 pa.SetVolumeDetect(1);
4698 else
4699 pa.SetVolumeDetect(0);
4700*/
4701
4702 if (pa.Building != building)
4703 pa.Building = building;
4105 } 4704 }
4106 }
4107 }
4108 4705
4109 if (SetVD) 4706 UpdatePhysicsSubscribedEvents();
4110 {
4111 // If the above logic worked (this is urgent candidate to unit tests!)
4112 // we now have a physicsactor.
4113 // Defensive programming calls for a check here.
4114 // Better would be throwing an exception that could be catched by a unit test as the internal
4115 // logic should make sure, this Physactor is always here.
4116 if (pa != null)
4117 {
4118 pa.SetVolumeDetect(1);
4119 AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active
4120 VolumeDetectActive = true;
4121 } 4707 }
4122 } 4708 }
4123 else
4124 {
4125 // Remove VolumeDetect in any case. Note, it's safe to call SetVolumeDetect as often as you like
4126 // (mumbles, well, at least if you have infinte CPU powers :-))
4127 if (pa != null)
4128 pa.SetVolumeDetect(0);
4129
4130 VolumeDetectActive = false;
4131 }
4132
4133 if (SetTemporary)
4134 {
4135 AddFlag(PrimFlags.TemporaryOnRez);
4136 }
4137 else
4138 {
4139 RemFlag(PrimFlags.TemporaryOnRez);
4140 }
4141 4709
4142 // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString()); 4710 // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString());
4143 4711
4712 // and last in case we have a new actor and not building
4713
4144 if (ParentGroup != null) 4714 if (ParentGroup != null)
4145 { 4715 {
4146 ParentGroup.HasGroupChanged = true; 4716 ParentGroup.HasGroupChanged = true;
4147 ScheduleFullUpdate(); 4717 ScheduleFullUpdate();
4148 } 4718 }
4149 4719
4150// m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags); 4720// m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags);
4151 } 4721 }
4152 4722
4153 /// <summary> 4723 /// <summary>
4154 /// Adds this part to the physics scene. 4724 /// Adds this part to the physics scene.
4725 /// and sets the PhysActor property
4155 /// </summary> 4726 /// </summary>
4156 /// <remarks>This method also sets the PhysActor property.</remarks> 4727 /// <param name="isPhysical">Add this prim as physical.</param>
4157 /// <param name="rigidBody">Add this prim with a rigid body.</param> 4728 /// <param name="isPhantom">Add this prim as phantom.</param>
4158 /// <returns> 4729 /// <param name="building">tells physics to delay full construction of object</param>
4159 /// The physics actor. null if there was a failure. 4730 /// <param name="applyDynamics">applies velocities, force and torque</param>
4160 /// </returns> 4731 private void AddToPhysics(bool isPhysical, bool isPhantom, bool building, bool applyDynamics)
4161 private PhysicsActor AddToPhysics(bool rigidBody) 4732 {
4162 {
4163 PhysicsActor pa; 4733 PhysicsActor pa;
4164 4734
4735 Vector3 velocity = Velocity;
4736 Vector3 rotationalVelocity = AngularVelocity;;
4737
4165 try 4738 try
4166 { 4739 {
4167 pa = ParentGroup.Scene.PhysicsScene.AddPrimShape( 4740 pa = ParentGroup.Scene.PhysicsScene.AddPrimShape(
4168 string.Format("{0}/{1}", Name, UUID), 4741 string.Format("{0}/{1}", Name, UUID),
4169 Shape, 4742 Shape,
4170 AbsolutePosition, 4743 AbsolutePosition,
4171 Scale, 4744 Scale,
4172 RotationOffset, 4745 GetWorldRotation(),
4173 rigidBody, 4746 isPhysical,
4174 m_localId); 4747 isPhantom,
4748 PhysicsShapeType,
4749 m_localId);
4175 } 4750 }
4176 catch 4751 catch (Exception ex)
4177 { 4752 {
4178 m_log.ErrorFormat("[SCENE]: caught exception meshing object {0}. Object set to phantom.", m_uuid); 4753 m_log.ErrorFormat("[SCENE]: AddToPhysics object {0} failed: {1}", m_uuid, ex.Message);
4179 pa = null; 4754 pa = null;
4180 } 4755 }
4181 4756
4182 // FIXME: Ideally we wouldn't set the property here to reduce situations where threads changing physical
4183 // properties can stop on each other. However, DoPhysicsPropertyUpdate() currently relies on PhysActor
4184 // being set.
4185 PhysActor = pa;
4186
4187 // Basic Physics can also return null as well as an exception catch.
4188 if (pa != null) 4757 if (pa != null)
4189 { 4758 {
4190 pa.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info 4759 pa.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info
4191 pa.SetMaterial(Material); 4760 pa.SetMaterial(Material);
4192 DoPhysicsPropertyUpdate(rigidBody, true); 4761
4762 if (VolumeDetectActive) // change if not the default only
4763 pa.SetVolumeDetect(1);
4764
4765 if (m_vehicleParams != null && LocalId == ParentGroup.RootPart.LocalId)
4766 m_vehicleParams.SetVehicle(pa);
4767
4768 // we are going to tell rest of code about physics so better have this here
4769 PhysActor = pa;
4770
4771 // DoPhysicsPropertyUpdate(isPhysical, true);
4772 // lets expand it here just with what it really needs to do
4773
4774 if (isPhysical)
4775 {
4776 if (ParentGroup.RootPart.KeyframeMotion != null)
4777 ParentGroup.RootPart.KeyframeMotion.Stop();
4778 ParentGroup.RootPart.KeyframeMotion = null;
4779 ParentGroup.Scene.AddPhysicalPrim(1);
4780
4781 pa.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
4782 pa.OnOutOfBounds += PhysicsOutOfBounds;
4783
4784 if (ParentID != 0 && ParentID != LocalId)
4785 {
4786 PhysicsActor parentPa = ParentGroup.RootPart.PhysActor;
4787
4788 if (parentPa != null)
4789 {
4790 pa.link(parentPa);
4791 }
4792 }
4793 }
4794
4795 if (applyDynamics)
4796 // do independent of isphysical so parameters get setted (at least some)
4797 {
4798 Velocity = velocity;
4799 AngularVelocity = rotationalVelocity;
4800// pa.Velocity = velocity;
4801 pa.RotationalVelocity = rotationalVelocity;
4802
4803 // if not vehicle and root part apply force and torque
4804 if ((m_vehicleParams == null || m_vehicleParams.Type == Vehicle.TYPE_NONE)
4805 && LocalId == ParentGroup.RootPart.LocalId)
4806 {
4807 pa.Force = Force;
4808 pa.Torque = Torque;
4809 }
4810 }
4811
4812 if (Shape.SculptEntry)
4813 CheckSculptAndLoad();
4814 else
4815 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
4816
4817 if (!building)
4818 pa.Building = false;
4193 } 4819 }
4194 4820
4195 return pa; 4821 PhysActor = pa;
4196 } 4822 }
4197 4823
4198 /// <summary> 4824 /// <summary>
4199 /// This removes the part from the physics scene. 4825 /// This removes the part from the physics scene.
4200 /// </summary> 4826 /// </summary>
4201 /// <remarks> 4827 /// <remarks>
4202 /// This isn't the same as turning off physical, since even without being physical the prim has a physics 4828 /// This isn't the same as turning off physical, since even without being physical the prim has a physics
4203 /// representation for collision detection. Rather, this would be used in situations such as making a prim 4829 /// representation for collision detection.
4204 /// phantom.
4205 /// </remarks> 4830 /// </remarks>
4206 public void RemoveFromPhysics() 4831 public void RemoveFromPhysics()
4207 { 4832 {
4208 ParentGroup.Scene.PhysicsScene.RemovePrim(PhysActor); 4833 PhysicsActor pa = PhysActor;
4834 if (pa != null)
4835 {
4836 pa.OnCollisionUpdate -= PhysicsCollision;
4837 pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
4838 pa.OnOutOfBounds -= PhysicsOutOfBounds;
4839
4840 ParentGroup.Scene.PhysicsScene.RemovePrim(pa);
4841 }
4209 PhysActor = null; 4842 PhysActor = null;
4210 } 4843 }
4211 4844
@@ -4416,6 +5049,44 @@ namespace OpenSim.Region.Framework.Scenes
4416 ScheduleFullUpdate(); 5049 ScheduleFullUpdate();
4417 } 5050 }
4418 5051
5052
5053 private void UpdatePhysicsSubscribedEvents()
5054 {
5055 PhysicsActor pa = PhysActor;
5056 if (pa == null)
5057 return;
5058
5059 pa.OnCollisionUpdate -= PhysicsCollision;
5060
5061 bool hassound = (!VolumeDetectActive && CollisionSoundType >= 0 && ((Flags & PrimFlags.Physics) != 0));
5062
5063 scriptEvents CombinedEvents = AggregateScriptEvents;
5064
5065 // merge with root part
5066 if (ParentGroup != null && ParentGroup.RootPart != null)
5067 CombinedEvents |= ParentGroup.RootPart.AggregateScriptEvents;
5068
5069 // submit to this part case
5070 if (VolumeDetectActive)
5071 CombinedEvents &= PhyscicsVolumeDtcSubsEvents;
5072 else if ((Flags & PrimFlags.Phantom) != 0)
5073 CombinedEvents &= PhyscicsPhantonSubsEvents;
5074 else
5075 CombinedEvents &= PhysicsNeededSubsEvents;
5076
5077 if (hassound || CombinedEvents != 0)
5078 {
5079 // subscribe to physics updates.
5080 pa.OnCollisionUpdate += PhysicsCollision;
5081 pa.SubscribeEvents(50); // 20 reports per second
5082 }
5083 else
5084 {
5085 pa.UnSubscribeEvents();
5086 }
5087 }
5088
5089
4419 public void aggregateScriptEvents() 5090 public void aggregateScriptEvents()
4420 { 5091 {
4421 if (ParentGroup == null || ParentGroup.RootPart == null) 5092 if (ParentGroup == null || ParentGroup.RootPart == null)
@@ -4452,40 +5123,32 @@ namespace OpenSim.Region.Framework.Scenes
4452 { 5123 {
4453 objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop; 5124 objectflagupdate |= (uint) PrimFlags.AllowInventoryDrop;
4454 } 5125 }
4455 5126/*
4456 PhysicsActor pa = PhysActor; 5127 PhysicsActor pa = PhysActor;
4457 5128 if (pa != null)
4458 if (
4459 ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
4460 ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4461 ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4462 ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4463 ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4464 ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4465 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision) != 0) ||
4466 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4467 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4468 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4469 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4470 ((ParentGroup.RootPart.AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4471 (CollisionSound != UUID.Zero)
4472 )
4473 { 5129 {
4474 // subscribe to physics updates. 5130 if (
4475 if (pa != null) 5131// ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
5132// ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
5133// ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
5134// ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
5135// ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
5136// ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
5137 ((AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) || ((ParentGroup.RootPart.AggregateScriptEvents & PhysicsNeededSubsEvents) != 0) || (CollisionSound != UUID.Zero)
5138 )
4476 { 5139 {
5140 // subscribe to physics updates.
4477 pa.OnCollisionUpdate += PhysicsCollision; 5141 pa.OnCollisionUpdate += PhysicsCollision;
4478 pa.SubscribeEvents(1000); 5142 pa.SubscribeEvents(1000);
4479 } 5143 }
4480 } 5144 else
4481 else
4482 {
4483 if (pa != null)
4484 { 5145 {
4485 pa.UnSubscribeEvents(); 5146 pa.UnSubscribeEvents();
4486 pa.OnCollisionUpdate -= PhysicsCollision; 5147 pa.OnCollisionUpdate -= PhysicsCollision;
4487 } 5148 }
4488 } 5149 }
5150 */
5151 UpdatePhysicsSubscribedEvents();
4489 5152
4490 //if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0) 5153 //if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0)
4491 //{ 5154 //{
@@ -4615,6 +5278,18 @@ namespace OpenSim.Region.Framework.Scenes
4615 return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A)); 5278 return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A));
4616 } 5279 }
4617 5280
5281 public void ResetOwnerChangeFlag()
5282 {
5283 List<UUID> inv = Inventory.GetInventoryList();
5284
5285 foreach (UUID itemID in inv)
5286 {
5287 TaskInventoryItem item = Inventory.GetInventoryItem(itemID);
5288 item.OwnerChanged = false;
5289 Inventory.UpdateInventoryItem(item, false, false);
5290 }
5291 }
5292
4618 /// <summary> 5293 /// <summary>
4619 /// Record an avatar sitting on this part. 5294 /// Record an avatar sitting on this part.
4620 /// </summary> 5295 /// </summary>