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.cs1361
1 files changed, 898 insertions, 463 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index 4bec2d4..843c426 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,6 +122,11 @@ 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;
125
126 private const scriptEvents PhyscicsNeededSubsEvents = (
127 scriptEvents.collision | scriptEvents.collision_start | scriptEvents.collision_end |
128 scriptEvents.land_collision | scriptEvents.land_collision_start | scriptEvents.land_collision_end
129 );
124 130
125 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 131 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
126 132
@@ -182,6 +188,18 @@ namespace OpenSim.Region.Framework.Scenes
182 188
183 public uint TimeStampTerse; 189 public uint TimeStampTerse;
184 190
191 // The following two are to hold the attachment data
192 // while an object is inworld
193 [XmlIgnore]
194 public byte AttachPoint = 0;
195
196 [XmlIgnore]
197 public Vector3 AttachOffset = Vector3.Zero;
198
199 [XmlIgnore]
200 public Quaternion AttachRotation = Quaternion.Identity;
201
202 [XmlIgnore]
185 public int STATUS_ROTATE_X; 203 public int STATUS_ROTATE_X;
186 204
187 public int STATUS_ROTATE_Y; 205 public int STATUS_ROTATE_Y;
@@ -208,8 +226,7 @@ namespace OpenSim.Region.Framework.Scenes
208 226
209 public Vector3 RotationAxis = Vector3.One; 227 public Vector3 RotationAxis = Vector3.One;
210 228
211 public bool VolumeDetectActive; // XmlIgnore set to avoid problems with persistance until I come to care for this 229 public bool VolumeDetectActive;
212 // Certainly this must be a persistant setting finally
213 230
214 public bool IsWaitingForFirstSpinUpdatePacket; 231 public bool IsWaitingForFirstSpinUpdatePacket;
215 232
@@ -249,10 +266,10 @@ namespace OpenSim.Region.Framework.Scenes
249 private Quaternion m_sitTargetOrientation = Quaternion.Identity; 266 private Quaternion m_sitTargetOrientation = Quaternion.Identity;
250 private Vector3 m_sitTargetPosition; 267 private Vector3 m_sitTargetPosition;
251 private string m_sitAnimation = "SIT"; 268 private string m_sitAnimation = "SIT";
269 private bool m_occupied; // KF if any av is sitting on this prim
252 private string m_text = String.Empty; 270 private string m_text = String.Empty;
253 private string m_touchName = String.Empty; 271 private string m_touchName = String.Empty;
254 private readonly Stack<UndoState> m_undo = new Stack<UndoState>(5); 272 private UndoRedoState m_UndoRedo = null;
255 private readonly Stack<UndoState> m_redo = new Stack<UndoState>(5);
256 273
257 private bool m_passTouches; 274 private bool m_passTouches;
258 275
@@ -280,7 +297,19 @@ namespace OpenSim.Region.Framework.Scenes
280 protected Vector3 m_lastAcceleration; 297 protected Vector3 m_lastAcceleration;
281 protected Vector3 m_lastAngularVelocity; 298 protected Vector3 m_lastAngularVelocity;
282 protected int m_lastTerseSent; 299 protected int m_lastTerseSent;
283 300 protected float m_buoyancy = 0.0f;
301 protected Vector3 m_force;
302 protected Vector3 m_torque;
303
304 protected byte m_physicsShapeType = (byte)PhysShapeType.prim;
305 protected float m_density = 1000.0f; // in kg/m^3
306 protected float m_gravitymod = 1.0f;
307 protected float m_friction = 0.6f; // wood
308 protected float m_bounce = 0.5f; // wood
309
310
311 protected bool m_isSelected = false;
312
284 /// <summary> 313 /// <summary>
285 /// Stores media texture data 314 /// Stores media texture data
286 /// </summary> 315 /// </summary>
@@ -296,6 +325,17 @@ namespace OpenSim.Region.Framework.Scenes
296 private UUID m_collisionSound; 325 private UUID m_collisionSound;
297 private float m_collisionSoundVolume; 326 private float m_collisionSoundVolume;
298 327
328
329 private SOPVehicle m_vehicle = null;
330
331 private KeyframeMotion m_keyframeMotion = null;
332
333 public KeyframeMotion KeyframeMotion
334 {
335 get; set;
336 }
337
338
299 #endregion Fields 339 #endregion Fields
300 340
301// ~SceneObjectPart() 341// ~SceneObjectPart()
@@ -338,7 +378,7 @@ namespace OpenSim.Region.Framework.Scenes
338 UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition, 378 UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition,
339 Quaternion rotationOffset, Vector3 offsetPosition) : this() 379 Quaternion rotationOffset, Vector3 offsetPosition) : this()
340 { 380 {
341 m_name = "Primitive"; 381 m_name = "Object";
342 382
343 CreationDate = (int)Utils.DateTimeToUnixTime(Rezzed); 383 CreationDate = (int)Utils.DateTimeToUnixTime(Rezzed);
344 LastOwnerID = CreatorID = OwnerID = ownerID; 384 LastOwnerID = CreatorID = OwnerID = ownerID;
@@ -378,7 +418,7 @@ namespace OpenSim.Region.Framework.Scenes
378 private uint _ownerMask = (uint)PermissionMask.All; 418 private uint _ownerMask = (uint)PermissionMask.All;
379 private uint _groupMask = (uint)PermissionMask.None; 419 private uint _groupMask = (uint)PermissionMask.None;
380 private uint _everyoneMask = (uint)PermissionMask.None; 420 private uint _everyoneMask = (uint)PermissionMask.None;
381 private uint _nextOwnerMask = (uint)PermissionMask.All; 421 private uint _nextOwnerMask = (uint)(PermissionMask.Move | PermissionMask.Modify | PermissionMask.Transfer);
382 private PrimFlags _flags = PrimFlags.None; 422 private PrimFlags _flags = PrimFlags.None;
383 private DateTime m_expires; 423 private DateTime m_expires;
384 private DateTime m_rezzed; 424 private DateTime m_rezzed;
@@ -472,12 +512,16 @@ namespace OpenSim.Region.Framework.Scenes
472 } 512 }
473 513
474 /// <value> 514 /// <value>
475 /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes 515 /// Get the inventory list
476 /// </value> 516 /// </value>
477 public TaskInventoryDictionary TaskInventory 517 public TaskInventoryDictionary TaskInventory
478 { 518 {
479 get { return m_inventory.Items; } 519 get {
480 set { m_inventory.Items = value; } 520 return m_inventory.Items;
521 }
522 set {
523 m_inventory.Items = value;
524 }
481 } 525 }
482 526
483 /// <summary> 527 /// <summary>
@@ -527,32 +571,28 @@ namespace OpenSim.Region.Framework.Scenes
527 } 571 }
528 } 572 }
529 573
530 public byte Material 574 public bool PassTouches
531 { 575 {
532 get { return (byte) m_material; } 576 get { return m_passTouches; }
533 set 577 set
534 { 578 {
535 m_material = (Material)value; 579 m_passTouches = value;
536
537 PhysicsActor pa = PhysActor;
538 580
539 if (pa != null) 581 if (ParentGroup != null)
540 pa.SetMaterial((int)value); 582 ParentGroup.HasGroupChanged = true;
541 } 583 }
542 } 584 }
543 585
544 public bool PassTouches 586 public bool IsSelected
545 { 587 {
546 get { return m_passTouches; } 588 get { return m_isSelected; }
547 set 589 set
548 { 590 {
549 m_passTouches = value; 591 m_isSelected = value;
550
551 if (ParentGroup != null) 592 if (ParentGroup != null)
552 ParentGroup.HasGroupChanged = true; 593 ParentGroup.PartSelectChanged(value);
553 } 594 }
554 } 595 }
555
556 596
557 597
558 public Dictionary<int, string> CollisionFilter 598 public Dictionary<int, string> CollisionFilter
@@ -623,14 +663,12 @@ namespace OpenSim.Region.Framework.Scenes
623 set { m_LoopSoundSlavePrims = value; } 663 set { m_LoopSoundSlavePrims = value; }
624 } 664 }
625 665
626
627 public Byte[] TextureAnimation 666 public Byte[] TextureAnimation
628 { 667 {
629 get { return m_TextureAnimation; } 668 get { return m_TextureAnimation; }
630 set { m_TextureAnimation = value; } 669 set { m_TextureAnimation = value; }
631 } 670 }
632 671
633
634 public Byte[] ParticleSystem 672 public Byte[] ParticleSystem
635 { 673 {
636 get { return m_particleSystem; } 674 get { return m_particleSystem; }
@@ -667,8 +705,12 @@ namespace OpenSim.Region.Framework.Scenes
667 { 705 {
668 // If this is a linkset, we don't want the physics engine mucking up our group position here. 706 // If this is a linkset, we don't want the physics engine mucking up our group position here.
669 PhysicsActor actor = PhysActor; 707 PhysicsActor actor = PhysActor;
670 if (actor != null && ParentID == 0) 708 if (ParentID == 0)
671 m_groupPosition = actor.Position; 709 {
710 if (actor != null)
711 m_groupPosition = actor.Position;
712 return m_groupPosition;
713 }
672 714
673 if (ParentGroup.IsAttachment) 715 if (ParentGroup.IsAttachment)
674 { 716 {
@@ -677,12 +719,14 @@ namespace OpenSim.Region.Framework.Scenes
677 return sp.AbsolutePosition; 719 return sp.AbsolutePosition;
678 } 720 }
679 721
722 // use root prim's group position. Physics may have updated it
723 if (ParentGroup.RootPart != this)
724 m_groupPosition = ParentGroup.RootPart.GroupPosition;
680 return m_groupPosition; 725 return m_groupPosition;
681 } 726 }
682 set 727 set
683 { 728 {
684 m_groupPosition = value; 729 m_groupPosition = value;
685
686 PhysicsActor actor = PhysActor; 730 PhysicsActor actor = PhysActor;
687 if (actor != null) 731 if (actor != null)
688 { 732 {
@@ -708,16 +752,6 @@ namespace OpenSim.Region.Framework.Scenes
708 m_log.Error("[SCENEOBJECTPART]: GROUP POSITION. " + e.Message); 752 m_log.Error("[SCENEOBJECTPART]: GROUP POSITION. " + e.Message);
709 } 753 }
710 } 754 }
711
712 // TODO if we decide to do sitting in a more SL compatible way (multiple avatars per prim), this has to be fixed, too
713 if (SitTargetAvatar != UUID.Zero)
714 {
715 ScenePresence avatar;
716 if (ParentGroup.Scene.TryGetScenePresence(SitTargetAvatar, out avatar))
717 {
718 avatar.ParentPosition = GetWorldPosition();
719 }
720 }
721 } 755 }
722 } 756 }
723 757
@@ -726,7 +760,7 @@ namespace OpenSim.Region.Framework.Scenes
726 get { return m_offsetPosition; } 760 get { return m_offsetPosition; }
727 set 761 set
728 { 762 {
729// StoreUndoState(); 763 Vector3 oldpos = m_offsetPosition;
730 m_offsetPosition = value; 764 m_offsetPosition = value;
731 765
732 if (ParentGroup != null && !ParentGroup.IsDeleted) 766 if (ParentGroup != null && !ParentGroup.IsDeleted)
@@ -741,7 +775,22 @@ namespace OpenSim.Region.Framework.Scenes
741 if (ParentGroup.Scene != null) 775 if (ParentGroup.Scene != null)
742 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor); 776 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
743 } 777 }
778
779 if (!m_parentGroup.m_dupeInProgress)
780 {
781 List<ScenePresence> avs = ParentGroup.GetLinkedAvatars();
782 foreach (ScenePresence av in avs)
783 {
784 if (av.ParentID == m_localId)
785 {
786 Vector3 offset = (m_offsetPosition - oldpos);
787 av.AbsolutePosition += offset;
788 av.SendAvatarDataToAllAgents();
789 }
790 }
791 }
744 } 792 }
793 TriggerScriptChangedEvent(Changed.POSITION);
745 } 794 }
746 } 795 }
747 796
@@ -790,7 +839,7 @@ namespace OpenSim.Region.Framework.Scenes
790 839
791 set 840 set
792 { 841 {
793 StoreUndoState(); 842// StoreUndoState();
794 m_rotationOffset = value; 843 m_rotationOffset = value;
795 844
796 PhysicsActor actor = PhysActor; 845 PhysicsActor actor = PhysActor;
@@ -878,7 +927,7 @@ namespace OpenSim.Region.Framework.Scenes
878 get 927 get
879 { 928 {
880 PhysicsActor actor = PhysActor; 929 PhysicsActor actor = PhysActor;
881 if ((actor != null) && actor.IsPhysical) 930 if ((actor != null) && actor.IsPhysical && ParentGroup.RootPart == this)
882 { 931 {
883 m_angularVelocity = actor.RotationalVelocity; 932 m_angularVelocity = actor.RotationalVelocity;
884 } 933 }
@@ -890,7 +939,16 @@ namespace OpenSim.Region.Framework.Scenes
890 /// <summary></summary> 939 /// <summary></summary>
891 public Vector3 Acceleration 940 public Vector3 Acceleration
892 { 941 {
893 get { return m_acceleration; } 942 get
943 {
944 PhysicsActor actor = PhysActor;
945 if (actor != null)
946 {
947 m_acceleration = actor.Acceleration;
948 }
949 return m_acceleration;
950 }
951
894 set { m_acceleration = value; } 952 set { m_acceleration = value; }
895 } 953 }
896 954
@@ -947,7 +1005,10 @@ namespace OpenSim.Region.Framework.Scenes
947 public PrimitiveBaseShape Shape 1005 public PrimitiveBaseShape Shape
948 { 1006 {
949 get { return m_shape; } 1007 get { return m_shape; }
950 set { m_shape = value;} 1008 set
1009 {
1010 m_shape = value;
1011 }
951 } 1012 }
952 1013
953 /// <summary> 1014 /// <summary>
@@ -960,7 +1021,6 @@ namespace OpenSim.Region.Framework.Scenes
960 { 1021 {
961 if (m_shape != null) 1022 if (m_shape != null)
962 { 1023 {
963 StoreUndoState();
964 1024
965 m_shape.Scale = value; 1025 m_shape.Scale = value;
966 1026
@@ -987,6 +1047,7 @@ namespace OpenSim.Region.Framework.Scenes
987 } 1047 }
988 1048
989 public UpdateRequired UpdateFlag { get; set; } 1049 public UpdateRequired UpdateFlag { get; set; }
1050 public bool UpdatePhysRequired { get; set; }
990 1051
991 /// <summary> 1052 /// <summary>
992 /// Used for media on a prim. 1053 /// Used for media on a prim.
@@ -1027,10 +1088,7 @@ namespace OpenSim.Region.Framework.Scenes
1027 { 1088 {
1028 get 1089 get
1029 { 1090 {
1030 if (ParentGroup.IsAttachment) 1091 return GroupPosition + (m_offsetPosition * ParentGroup.RootPart.RotationOffset);
1031 return GroupPosition;
1032
1033 return m_offsetPosition + m_groupPosition;
1034 } 1092 }
1035 } 1093 }
1036 1094
@@ -1208,6 +1266,13 @@ namespace OpenSim.Region.Framework.Scenes
1208 _flags = value; 1266 _flags = value;
1209 } 1267 }
1210 } 1268 }
1269
1270 [XmlIgnore]
1271 public bool IsOccupied // KF If an av is sittingon this prim
1272 {
1273 get { return m_occupied; }
1274 set { m_occupied = value; }
1275 }
1211 1276
1212 /// <summary> 1277 /// <summary>
1213 /// ID of the avatar that is sat on us. If there is no such avatar then is UUID.Zero 1278 /// ID of the avatar that is sat on us. If there is no such avatar then is UUID.Zero
@@ -1267,6 +1332,316 @@ namespace OpenSim.Region.Framework.Scenes
1267 set { m_collisionSoundVolume = value; } 1332 set { m_collisionSoundVolume = value; }
1268 } 1333 }
1269 1334
1335 public float Buoyancy
1336 {
1337 get
1338 {
1339 if (ParentGroup.RootPart == this)
1340 return m_buoyancy;
1341
1342 return ParentGroup.RootPart.Buoyancy;
1343 }
1344 set
1345 {
1346 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1347 {
1348 ParentGroup.RootPart.Buoyancy = value;
1349 return;
1350 }
1351 m_buoyancy = value;
1352 if (PhysActor != null)
1353 PhysActor.Buoyancy = value;
1354 }
1355 }
1356
1357 public Vector3 Force
1358 {
1359 get
1360 {
1361 if (ParentGroup.RootPart == this)
1362 return m_force;
1363
1364 return ParentGroup.RootPart.Force;
1365 }
1366
1367 set
1368 {
1369 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1370 {
1371 ParentGroup.RootPart.Force = value;
1372 return;
1373 }
1374 m_force = value;
1375 if (PhysActor != null)
1376 PhysActor.Force = value;
1377 }
1378 }
1379
1380 public Vector3 Torque
1381 {
1382 get
1383 {
1384 if (ParentGroup.RootPart == this)
1385 return m_torque;
1386
1387 return ParentGroup.RootPart.Torque;
1388 }
1389
1390 set
1391 {
1392 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1393 {
1394 ParentGroup.RootPart.Torque = value;
1395 return;
1396 }
1397 m_torque = value;
1398 if (PhysActor != null)
1399 PhysActor.Torque = value;
1400 }
1401 }
1402
1403 public byte Material
1404 {
1405 get { return (byte)m_material; }
1406 set
1407 {
1408 if (value >= 0 && value <= (byte)SOPMaterialData.MaxMaterial)
1409 {
1410 bool update = false;
1411
1412 if (m_material != (Material)value)
1413 {
1414 update = true;
1415 m_material = (Material)value;
1416 }
1417
1418 if (m_friction != SOPMaterialData.friction(m_material))
1419 {
1420 update = true;
1421 m_friction = SOPMaterialData.friction(m_material);
1422 }
1423
1424 if (m_bounce != SOPMaterialData.bounce(m_material))
1425 {
1426 update = true;
1427 m_bounce = SOPMaterialData.bounce(m_material);
1428 }
1429
1430 if (update)
1431 {
1432 if (PhysActor != null)
1433 {
1434 PhysActor.SetMaterial((int)value);
1435 }
1436 if(ParentGroup != null)
1437 ParentGroup.HasGroupChanged = true;
1438 ScheduleFullUpdateIfNone();
1439 UpdatePhysRequired = true;
1440 }
1441 }
1442 }
1443 }
1444
1445 // not a propriety to move to methods place later
1446 private bool HasMesh()
1447 {
1448 if (Shape != null && (Shape.SculptType == (byte)SculptType.Mesh))
1449 return true;
1450 return false;
1451 }
1452
1453 // not a propriety to move to methods place later
1454 public byte DefaultPhysicsShapeType()
1455 {
1456 byte type;
1457
1458 if (Shape != null && (Shape.SculptType == (byte)SculptType.Mesh))
1459 type = (byte)PhysShapeType.convex;
1460 else
1461 type = (byte)PhysShapeType.prim;
1462
1463 return type;
1464 }
1465
1466 [XmlIgnore]
1467 public bool UsesComplexCost
1468 {
1469 get
1470 {
1471 byte pst = PhysicsShapeType;
1472 if(pst == (byte) PhysShapeType.none || pst == (byte) PhysShapeType.convex || HasMesh())
1473 return true;
1474 return false;
1475 }
1476 }
1477
1478 [XmlIgnore]
1479 public float PhysicsCost
1480 {
1481 get
1482 {
1483 if(PhysicsShapeType == (byte)PhysShapeType.none)
1484 return 0;
1485
1486 float cost = 0.1f;
1487 if (PhysActor != null)
1488// cost += PhysActor.Cost;
1489
1490 if ((Flags & PrimFlags.Physics) != 0)
1491 cost *= (1.0f + 0.01333f * Scale.LengthSquared()); // 0.01333 == 0.04/3
1492 return cost;
1493 }
1494 }
1495
1496 [XmlIgnore]
1497 public float StreamingCost
1498 {
1499 get
1500 {
1501
1502
1503 return 0.1f;
1504 }
1505 }
1506
1507 [XmlIgnore]
1508 public float SimulationCost
1509 {
1510 get
1511 {
1512 // ignoring scripts. Don't like considering them for this
1513 if((Flags & PrimFlags.Physics) != 0)
1514 return 1.0f;
1515
1516 return 0.5f;
1517 }
1518 }
1519
1520 public byte PhysicsShapeType
1521 {
1522 get { return m_physicsShapeType; }
1523 set
1524 {
1525 byte oldv = m_physicsShapeType;
1526
1527 if (value >= 0 && value <= (byte)PhysShapeType.convex)
1528 {
1529 if (value == (byte)PhysShapeType.none && ParentGroup != null && ParentGroup.RootPart == this)
1530 m_physicsShapeType = DefaultPhysicsShapeType();
1531 else
1532 m_physicsShapeType = value;
1533 }
1534 else
1535 m_physicsShapeType = DefaultPhysicsShapeType();
1536
1537 if (m_physicsShapeType != oldv && ParentGroup != null)
1538 {
1539 if (m_physicsShapeType == (byte)PhysShapeType.none)
1540 {
1541 if (PhysActor != null)
1542 {
1543 Velocity = new Vector3(0, 0, 0);
1544 Acceleration = new Vector3(0, 0, 0);
1545 if (ParentGroup.RootPart == this)
1546 AngularVelocity = new Vector3(0, 0, 0);
1547 ParentGroup.Scene.RemovePhysicalPrim(1);
1548 RemoveFromPhysics();
1549 }
1550 }
1551 else if (PhysActor == null)
1552 ApplyPhysics((uint)Flags, VolumeDetectActive, false);
1553 else
1554 {
1555 PhysActor.PhysicsShapeType = m_physicsShapeType;
1556 if (Shape.SculptEntry)
1557 CheckSculptAndLoad();
1558 }
1559
1560 if (ParentGroup != null)
1561 ParentGroup.HasGroupChanged = true;
1562 }
1563
1564 if (m_physicsShapeType != value)
1565 {
1566 UpdatePhysRequired = true;
1567 }
1568 }
1569 }
1570
1571 public float Density // in kg/m^3
1572 {
1573 get { return m_density; }
1574 set
1575 {
1576 if (value >=1 && value <= 22587.0)
1577 {
1578 m_density = value;
1579 UpdatePhysRequired = true;
1580 }
1581
1582 ScheduleFullUpdateIfNone();
1583
1584 if (ParentGroup != null)
1585 ParentGroup.HasGroupChanged = true;
1586 }
1587 }
1588
1589 public float GravityModifier
1590 {
1591 get { return m_gravitymod; }
1592 set
1593 {
1594 if( value >= -1 && value <=28.0f)
1595 {
1596 m_gravitymod = value;
1597 UpdatePhysRequired = true;
1598 }
1599
1600 ScheduleFullUpdateIfNone();
1601
1602 if (ParentGroup != null)
1603 ParentGroup.HasGroupChanged = true;
1604
1605 }
1606 }
1607
1608 public float Friction
1609 {
1610 get { return m_friction; }
1611 set
1612 {
1613 if (value >= 0 && value <= 255.0f)
1614 {
1615 m_friction = value;
1616 UpdatePhysRequired = true;
1617 }
1618
1619 ScheduleFullUpdateIfNone();
1620
1621 if (ParentGroup != null)
1622 ParentGroup.HasGroupChanged = true;
1623 }
1624 }
1625
1626 public float Bounciness
1627 {
1628 get { return m_bounce; }
1629 set
1630 {
1631 if (value >= 0 && value <= 1.0f)
1632 {
1633 m_bounce = value;
1634 UpdatePhysRequired = true;
1635 }
1636
1637 ScheduleFullUpdateIfNone();
1638
1639 if (ParentGroup != null)
1640 ParentGroup.HasGroupChanged = true;
1641 }
1642 }
1643
1644
1270 #endregion Public Properties with only Get 1645 #endregion Public Properties with only Get
1271 1646
1272 private uint ApplyMask(uint val, bool set, uint mask) 1647 private uint ApplyMask(uint val, bool set, uint mask)
@@ -1432,7 +1807,7 @@ namespace OpenSim.Region.Framework.Scenes
1432 impulse = newimpulse; 1807 impulse = newimpulse;
1433 } 1808 }
1434 1809
1435 ParentGroup.applyAngularImpulse(impulse); 1810 ParentGroup.ApplyAngularImpulse(impulse);
1436 } 1811 }
1437 1812
1438 /// <summary> 1813 /// <summary>
@@ -1442,20 +1817,24 @@ namespace OpenSim.Region.Framework.Scenes
1442 /// </summary> 1817 /// </summary>
1443 /// <param name="impulsei">Vector force</param> 1818 /// <param name="impulsei">Vector force</param>
1444 /// <param name="localGlobalTF">true for the local frame, false for the global frame</param> 1819 /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
1445 public void SetAngularImpulse(Vector3 impulsei, bool localGlobalTF) 1820
1821 // this is actualy Set Torque.. keeping naming so not to edit lslapi also
1822 public void SetAngularImpulse(Vector3 torquei, bool localGlobalTF)
1446 { 1823 {
1447 Vector3 impulse = impulsei; 1824 Vector3 torque = torquei;
1448 1825
1449 if (localGlobalTF) 1826 if (localGlobalTF)
1450 { 1827 {
1828/*
1451 Quaternion grot = GetWorldRotation(); 1829 Quaternion grot = GetWorldRotation();
1452 Quaternion AXgrot = grot; 1830 Quaternion AXgrot = grot;
1453 Vector3 AXimpulsei = impulsei; 1831 Vector3 AXimpulsei = impulsei;
1454 Vector3 newimpulse = AXimpulsei * AXgrot; 1832 Vector3 newimpulse = AXimpulsei * AXgrot;
1455 impulse = newimpulse; 1833 */
1834 torque *= GetWorldRotation();
1456 } 1835 }
1457 1836
1458 ParentGroup.setAngularImpulse(impulse); 1837 Torque = torque;
1459 } 1838 }
1460 1839
1461 /// <summary> 1840 /// <summary>
@@ -1463,17 +1842,23 @@ namespace OpenSim.Region.Framework.Scenes
1463 /// </summary> 1842 /// </summary>
1464 /// <param name="rootObjectFlags"></param> 1843 /// <param name="rootObjectFlags"></param>
1465 /// <param name="VolumeDetectActive"></param> 1844 /// <param name="VolumeDetectActive"></param>
1466 public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive) 1845 /// <param name="building"></param>
1846
1847 public void ApplyPhysics(uint _ObjectFlags, bool _VolumeDetectActive, bool building)
1467 { 1848 {
1849 VolumeDetectActive = _VolumeDetectActive;
1850
1468 if (!ParentGroup.Scene.CollidablePrims) 1851 if (!ParentGroup.Scene.CollidablePrims)
1469 return; 1852 return;
1470 1853
1471// m_log.DebugFormat( 1854 if (PhysicsShapeType == (byte)PhysShapeType.none)
1472// "[SCENE OBJECT PART]: Applying physics to {0} {1}, m_physicalPrim {2}", 1855 return;
1473// Name, LocalId, UUID, m_physicalPrim);
1474 1856
1475 bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0; 1857 bool isPhysical = (_ObjectFlags & (uint) PrimFlags.Physics) != 0;
1476 bool isPhantom = (rootObjectFlags & (uint) PrimFlags.Phantom) != 0; 1858 bool isPhantom = (_ObjectFlags & (uint)PrimFlags.Phantom) != 0;
1859
1860 if (_VolumeDetectActive)
1861 isPhantom = true;
1477 1862
1478 if (IsJoint()) 1863 if (IsJoint())
1479 { 1864 {
@@ -1481,22 +1866,11 @@ namespace OpenSim.Region.Framework.Scenes
1481 } 1866 }
1482 else 1867 else
1483 { 1868 {
1484 // Special case for VolumeDetection: If VolumeDetection is set, the phantom flag is locally ignored 1869 if ((!isPhantom || isPhysical || _VolumeDetectActive) && !ParentGroup.IsAttachment
1485 if (VolumeDetectActive) 1870 && !(Shape.PathCurve == (byte)Extrusion.Flexible))
1486 isPhantom = false; 1871 AddToPhysics(isPhysical, isPhantom, building, isPhysical);
1487 1872 else
1488 // 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 1873 PhysActor = null; // just to be sure
1489 // or flexible
1490 if (!isPhantom && !ParentGroup.IsAttachment && !(Shape.PathCurve == (byte)Extrusion.Flexible))
1491 {
1492 // Added clarification.. since A rigid body is an object that you can kick around, etc.
1493 bool rigidBody = isPhysical && !isPhantom;
1494
1495 PhysicsActor pa = AddToPhysics(rigidBody);
1496
1497 if (pa != null)
1498 pa.SetVolumeDetect(VolumeDetectActive ? 1 : 0);
1499 }
1500 } 1874 }
1501 } 1875 }
1502 1876
@@ -1548,6 +1922,12 @@ namespace OpenSim.Region.Framework.Scenes
1548 dupe.Category = Category; 1922 dupe.Category = Category;
1549 dupe.m_rezzed = m_rezzed; 1923 dupe.m_rezzed = m_rezzed;
1550 1924
1925 dupe.m_UndoRedo = null;
1926 dupe.m_isSelected = false;
1927
1928 dupe.IgnoreUndoUpdate = false;
1929 dupe.Undoing = false;
1930
1551 dupe.m_inventory = new SceneObjectPartInventory(dupe); 1931 dupe.m_inventory = new SceneObjectPartInventory(dupe);
1552 dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone(); 1932 dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone();
1553 1933
@@ -1563,6 +1943,7 @@ namespace OpenSim.Region.Framework.Scenes
1563 1943
1564 // Move afterwards ResetIDs as it clears the localID 1944 // Move afterwards ResetIDs as it clears the localID
1565 dupe.LocalId = localID; 1945 dupe.LocalId = localID;
1946
1566 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated. 1947 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
1567 dupe.LastOwnerID = OwnerID; 1948 dupe.LastOwnerID = OwnerID;
1568 1949
@@ -1582,6 +1963,9 @@ namespace OpenSim.Region.Framework.Scenes
1582 dupe.DoPhysicsPropertyUpdate(UsePhysics, true); 1963 dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
1583 } 1964 }
1584 1965
1966 if (dupe.PhysActor != null)
1967 dupe.PhysActor.LocalID = localID;
1968
1585 ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed); 1969 ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed);
1586 1970
1587// m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID); 1971// m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID);
@@ -1701,6 +2085,7 @@ namespace OpenSim.Region.Framework.Scenes
1701 2085
1702 /// <summary> 2086 /// <summary>
1703 /// Do a physics propery update for this part. 2087 /// Do a physics propery update for this part.
2088 /// now also updates phantom and volume detector
1704 /// </summary> 2089 /// </summary>
1705 /// <param name="UsePhysics"></param> 2090 /// <param name="UsePhysics"></param>
1706 /// <param name="isNew"></param> 2091 /// <param name="isNew"></param>
@@ -1726,61 +2111,69 @@ namespace OpenSim.Region.Framework.Scenes
1726 { 2111 {
1727 if (pa.IsPhysical) // implies UsePhysics==false for this block 2112 if (pa.IsPhysical) // implies UsePhysics==false for this block
1728 { 2113 {
1729 if (!isNew) 2114 if (!isNew) // implies UsePhysics==false for this block
2115 {
1730 ParentGroup.Scene.RemovePhysicalPrim(1); 2116 ParentGroup.Scene.RemovePhysicalPrim(1);
1731 2117
1732 pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate; 2118 Velocity = new Vector3(0, 0, 0);
1733 pa.OnOutOfBounds -= PhysicsOutOfBounds; 2119 Acceleration = new Vector3(0, 0, 0);
1734 pa.delink(); 2120 if (ParentGroup.RootPart == this)
2121 AngularVelocity = new Vector3(0, 0, 0);
1735 2122
1736 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints && (!isNew)) 2123 if (pa.Phantom && !VolumeDetectActive)
1737 { 2124 {
1738 // destroy all joints connected to this now deactivated body 2125 RemoveFromPhysics();
1739 ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(pa); 2126 return;
1740 } 2127 }
1741 2128
1742 // stop client-side interpolation of all joint proxy objects that have just been deleted 2129 pa.IsPhysical = UsePhysics;
1743 // this is done because RemoveAllJointsConnectedToActor invokes the OnJointDeactivated callback, 2130 pa.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
1744 // which stops client-side interpolation of deactivated joint proxy objects. 2131 pa.OnOutOfBounds -= PhysicsOutOfBounds;
2132 pa.delink();
2133 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
2134 {
2135 // destroy all joints connected to this now deactivated body
2136 ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(pa);
2137 }
2138 }
1745 } 2139 }
1746 2140
1747 if (!UsePhysics && !isNew) 2141 if (pa.IsPhysical != UsePhysics)
1748 { 2142 pa.IsPhysical = UsePhysics;
1749 // reset velocity to 0 on physics switch-off. Without that, the client thinks the
1750 // prim still has velocity and continues to interpolate its position along the old
1751 // velocity-vector.
1752 Velocity = new Vector3(0, 0, 0);
1753 Acceleration = new Vector3(0, 0, 0);
1754 AngularVelocity = new Vector3(0, 0, 0);
1755 //RotationalVelocity = new Vector3(0, 0, 0);
1756 }
1757 2143
1758 pa.IsPhysical = UsePhysics; 2144 if (UsePhysics)
2145 {
2146 if (ParentGroup.RootPart.KeyframeMotion != null)
2147 ParentGroup.RootPart.KeyframeMotion.Stop();
2148 ParentGroup.RootPart.KeyframeMotion = null;
2149 ParentGroup.Scene.AddPhysicalPrim(1);
1759 2150
1760 // If we're not what we're supposed to be in the physics scene, recreate ourselves. 2151 PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
1761 //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor); 2152 PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
1762 /// that's not wholesome. Had to make Scene public
1763 //PhysActor = null;
1764 2153
1765 if ((Flags & PrimFlags.Phantom) == 0) 2154 if (ParentID != 0 && ParentID != LocalId)
1766 {
1767 if (UsePhysics)
1768 { 2155 {
1769 ParentGroup.Scene.AddPhysicalPrim(1); 2156 PhysicsActor parentPa = ParentGroup.RootPart.PhysActor;
1770 2157
1771 pa.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate; 2158 if (parentPa != null)
1772 pa.OnOutOfBounds += PhysicsOutOfBounds;
1773 if (ParentID != 0 && ParentID != LocalId)
1774 { 2159 {
1775 PhysicsActor parentPa = ParentGroup.RootPart.PhysActor; 2160 pa.link(parentPa);
1776
1777 if (parentPa != null)
1778 {
1779 pa.link(parentPa);
1780 }
1781 } 2161 }
1782 } 2162 }
1783 } 2163 }
2164 }
2165
2166 bool phan = ((Flags & PrimFlags.Phantom) != 0);
2167 if (pa.Phantom != phan)
2168 pa.Phantom = phan;
2169
2170// some engines dont' have this check still
2171// if (VolumeDetectActive != pa.IsVolumeDtc)
2172 {
2173 if (VolumeDetectActive)
2174 pa.SetVolumeDetect(1);
2175 else
2176 pa.SetVolumeDetect(0);
1784 } 2177 }
1785 2178
1786 // If this part is a sculpt then delay the physics update until we've asynchronously loaded the 2179 // If this part is a sculpt then delay the physics update until we've asynchronously loaded the
@@ -1899,12 +2292,26 @@ namespace OpenSim.Region.Framework.Scenes
1899 2292
1900 public Vector3 GetGeometricCenter() 2293 public Vector3 GetGeometricCenter()
1901 { 2294 {
1902 PhysicsActor pa = PhysActor; 2295 // this is not real geometric center but a average of positions relative to root prim acording to
1903 2296 // http://wiki.secondlife.com/wiki/llGetGeometricCenter
1904 if (pa != null) 2297 // ignoring tortured prims details since sl also seems to ignore
1905 return new Vector3(pa.CenterOfMass.X, pa.CenterOfMass.Y, pa.CenterOfMass.Z); 2298 // so no real use in doing it on physics
1906 else 2299 if (ParentGroup.IsDeleted)
1907 return new Vector3(0, 0, 0); 2300 return new Vector3(0, 0, 0);
2301
2302 return ParentGroup.GetGeometricCenter();
2303
2304 /*
2305 PhysicsActor pa = PhysActor;
2306
2307 if (pa != null)
2308 {
2309 Vector3 vtmp = pa.CenterOfMass;
2310 return vtmp;
2311 }
2312 else
2313 return new Vector3(0, 0, 0);
2314 */
1908 } 2315 }
1909 2316
1910 public float GetMass() 2317 public float GetMass()
@@ -1917,14 +2324,43 @@ namespace OpenSim.Region.Framework.Scenes
1917 return 0; 2324 return 0;
1918 } 2325 }
1919 2326
1920 public Vector3 GetForce() 2327 public Vector3 GetCenterOfMass()
1921 { 2328 {
2329 if (ParentGroup.RootPart == this)
2330 {
2331 if (ParentGroup.IsDeleted)
2332 return AbsolutePosition;
2333 return ParentGroup.GetCenterOfMass();
2334 }
2335
1922 PhysicsActor pa = PhysActor; 2336 PhysicsActor pa = PhysActor;
1923 2337
1924 if (pa != null) 2338 if (pa != null)
1925 return pa.Force; 2339 {
2340 Vector3 tmp = pa.CenterOfMass;
2341 return tmp;
2342 }
1926 else 2343 else
1927 return Vector3.Zero; 2344 return AbsolutePosition;
2345 }
2346
2347 public Vector3 GetPartCenterOfMass()
2348 {
2349 PhysicsActor pa = PhysActor;
2350
2351 if (pa != null)
2352 {
2353 Vector3 tmp = pa.CenterOfMass;
2354 return tmp;
2355 }
2356 else
2357 return AbsolutePosition;
2358 }
2359
2360
2361 public Vector3 GetForce()
2362 {
2363 return Force;
1928 } 2364 }
1929 2365
1930 /// <summary> 2366 /// <summary>
@@ -2560,9 +2996,9 @@ namespace OpenSim.Region.Framework.Scenes
2560 Vector3 newpos = new Vector3(pa.Position.GetBytes(), 0); 2996 Vector3 newpos = new Vector3(pa.Position.GetBytes(), 0);
2561 2997
2562 if (ParentGroup.Scene.TestBorderCross(newpos, Cardinals.N) 2998 if (ParentGroup.Scene.TestBorderCross(newpos, Cardinals.N)
2563 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.S) 2999 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.S)
2564 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.E) 3000 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.E)
2565 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.W)) 3001 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.W))
2566 { 3002 {
2567 ParentGroup.AbsolutePosition = newpos; 3003 ParentGroup.AbsolutePosition = newpos;
2568 return; 3004 return;
@@ -2584,17 +3020,18 @@ namespace OpenSim.Region.Framework.Scenes
2584 //Trys to fetch sound id from prim's inventory. 3020 //Trys to fetch sound id from prim's inventory.
2585 //Prim's inventory doesn't support non script items yet 3021 //Prim's inventory doesn't support non script items yet
2586 3022
2587 lock (TaskInventory) 3023 TaskInventory.LockItemsForRead(true);
3024
3025 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2588 { 3026 {
2589 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 3027 if (item.Value.Name == sound)
2590 { 3028 {
2591 if (item.Value.Name == sound) 3029 soundID = item.Value.ItemID;
2592 { 3030 break;
2593 soundID = item.Value.ItemID;
2594 break;
2595 }
2596 } 3031 }
2597 } 3032 }
3033
3034 TaskInventory.LockItemsForRead(false);
2598 } 3035 }
2599 3036
2600 ParentGroup.Scene.ForEachRootScenePresence(delegate(ScenePresence sp) 3037 ParentGroup.Scene.ForEachRootScenePresence(delegate(ScenePresence sp)
@@ -2717,6 +3154,19 @@ namespace OpenSim.Region.Framework.Scenes
2717 APIDTarget = Quaternion.Identity; 3154 APIDTarget = Quaternion.Identity;
2718 } 3155 }
2719 3156
3157
3158
3159 public void ScheduleFullUpdateIfNone()
3160 {
3161 if (ParentGroup == null)
3162 return;
3163
3164// ??? ParentGroup.HasGroupChanged = true;
3165
3166 if (UpdateFlag != UpdateRequired.FULL)
3167 ScheduleFullUpdate();
3168 }
3169
2720 /// <summary> 3170 /// <summary>
2721 /// Schedules this prim for a full update 3171 /// Schedules this prim for a full update
2722 /// </summary> 3172 /// </summary>
@@ -2918,8 +3368,8 @@ namespace OpenSim.Region.Framework.Scenes
2918 { 3368 {
2919 const float ROTATION_TOLERANCE = 0.01f; 3369 const float ROTATION_TOLERANCE = 0.01f;
2920 const float VELOCITY_TOLERANCE = 0.001f; 3370 const float VELOCITY_TOLERANCE = 0.001f;
2921 const float POSITION_TOLERANCE = 0.05f; 3371 const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
2922 const int TIME_MS_TOLERANCE = 3000; 3372 const int TIME_MS_TOLERANCE = 200; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
2923 3373
2924 switch (UpdateFlag) 3374 switch (UpdateFlag)
2925 { 3375 {
@@ -2981,17 +3431,16 @@ namespace OpenSim.Region.Framework.Scenes
2981 if (!UUID.TryParse(sound, out soundID)) 3431 if (!UUID.TryParse(sound, out soundID))
2982 { 3432 {
2983 // search sound file from inventory 3433 // search sound file from inventory
2984 lock (TaskInventory) 3434 TaskInventory.LockItemsForRead(true);
3435 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2985 { 3436 {
2986 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 3437 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
2987 { 3438 {
2988 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) 3439 soundID = item.Value.ItemID;
2989 { 3440 break;
2990 soundID = item.Value.ItemID;
2991 break;
2992 }
2993 } 3441 }
2994 } 3442 }
3443 TaskInventory.LockItemsForRead(false);
2995 } 3444 }
2996 3445
2997 if (soundID == UUID.Zero) 3446 if (soundID == UUID.Zero)
@@ -3076,10 +3525,13 @@ namespace OpenSim.Region.Framework.Scenes
3076 3525
3077 public void SetBuoyancy(float fvalue) 3526 public void SetBuoyancy(float fvalue)
3078 { 3527 {
3079 PhysicsActor pa = PhysActor; 3528 Buoyancy = fvalue;
3080 3529/*
3081 if (pa != null) 3530 if (PhysActor != null)
3082 pa.Buoyancy = fvalue; 3531 {
3532 PhysActor.Buoyancy = fvalue;
3533 }
3534 */
3083 } 3535 }
3084 3536
3085 public void SetDieAtEdge(bool p) 3537 public void SetDieAtEdge(bool p)
@@ -3095,47 +3547,111 @@ namespace OpenSim.Region.Framework.Scenes
3095 PhysicsActor pa = PhysActor; 3547 PhysicsActor pa = PhysActor;
3096 3548
3097 if (pa != null) 3549 if (pa != null)
3098 pa.FloatOnWater = floatYN == 1; 3550 pa.FloatOnWater = (floatYN == 1);
3099 } 3551 }
3100 3552
3101 public void SetForce(Vector3 force) 3553 public void SetForce(Vector3 force)
3102 { 3554 {
3103 PhysicsActor pa = PhysActor; 3555 Force = force;
3556 }
3104 3557
3105 if (pa != null) 3558 public SOPVehicle sopVehicle
3106 pa.Force = force; 3559 {
3560 get
3561 {
3562 return m_vehicle;
3563 }
3564 set
3565 {
3566 m_vehicle = value;
3567 }
3568 }
3569
3570
3571 public int VehicleType
3572 {
3573 get
3574 {
3575 if (m_vehicle == null)
3576 return (int)Vehicle.TYPE_NONE;
3577 else
3578 return (int)m_vehicle.Type;
3579 }
3580 set
3581 {
3582 SetVehicleType(value);
3583 }
3107 } 3584 }
3108 3585
3109 public void SetVehicleType(int type) 3586 public void SetVehicleType(int type)
3110 { 3587 {
3111 PhysicsActor pa = PhysActor; 3588 m_vehicle = null;
3589
3590 if (type == (int)Vehicle.TYPE_NONE)
3591 {
3592 if (_parentID ==0 && PhysActor != null)
3593 PhysActor.VehicleType = (int)Vehicle.TYPE_NONE;
3594 return;
3595 }
3596 m_vehicle = new SOPVehicle();
3597 m_vehicle.ProcessTypeChange((Vehicle)type);
3598 {
3599 if (_parentID ==0 && PhysActor != null)
3600 PhysActor.VehicleType = type;
3601 return;
3602 }
3603 }
3112 3604
3113 if (pa != null) 3605 public void SetVehicleFlags(int param, bool remove)
3114 pa.VehicleType = type; 3606 {
3607 if (m_vehicle == null)
3608 return;
3609
3610 m_vehicle.ProcessVehicleFlags(param, remove);
3611
3612 if (_parentID ==0 && PhysActor != null)
3613 {
3614 PhysActor.VehicleFlags(param, remove);
3615 }
3115 } 3616 }
3116 3617
3117 public void SetVehicleFloatParam(int param, float value) 3618 public void SetVehicleFloatParam(int param, float value)
3118 { 3619 {
3119 PhysicsActor pa = PhysActor; 3620 if (m_vehicle == null)
3621 return;
3120 3622
3121 if (pa != null) 3623 m_vehicle.ProcessFloatVehicleParam((Vehicle)param, value);
3122 pa.VehicleFloatParam(param, value); 3624
3625 if (_parentID == 0 && PhysActor != null)
3626 {
3627 PhysActor.VehicleFloatParam(param, value);
3628 }
3123 } 3629 }
3124 3630
3125 public void SetVehicleVectorParam(int param, Vector3 value) 3631 public void SetVehicleVectorParam(int param, Vector3 value)
3126 { 3632 {
3127 PhysicsActor pa = PhysActor; 3633 if (m_vehicle == null)
3634 return;
3128 3635
3129 if (pa != null) 3636 m_vehicle.ProcessVectorVehicleParam((Vehicle)param, value);
3130 pa.VehicleVectorParam(param, value); 3637
3638 if (_parentID == 0 && PhysActor != null)
3639 {
3640 PhysActor.VehicleVectorParam(param, value);
3641 }
3131 } 3642 }
3132 3643
3133 public void SetVehicleRotationParam(int param, Quaternion rotation) 3644 public void SetVehicleRotationParam(int param, Quaternion rotation)
3134 { 3645 {
3135 PhysicsActor pa = PhysActor; 3646 if (m_vehicle == null)
3647 return;
3136 3648
3137 if (pa != null) 3649 m_vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation);
3138 pa.VehicleRotationParam(param, rotation); 3650
3651 if (_parentID == 0 && PhysActor != null)
3652 {
3653 PhysActor.VehicleRotationParam(param, rotation);
3654 }
3139 } 3655 }
3140 3656
3141 /// <summary> 3657 /// <summary>
@@ -3319,13 +3835,6 @@ namespace OpenSim.Region.Framework.Scenes
3319 hasProfileCut = hasDimple; // is it the same thing? 3835 hasProfileCut = hasDimple; // is it the same thing?
3320 } 3836 }
3321 3837
3322 public void SetVehicleFlags(int param, bool remove)
3323 {
3324 if (PhysActor != null)
3325 {
3326 PhysActor.VehicleFlags(param, remove);
3327 }
3328 }
3329 3838
3330 public void SetGroup(UUID groupID, IClientAPI client) 3839 public void SetGroup(UUID groupID, IClientAPI client)
3331 { 3840 {
@@ -3428,68 +3937,18 @@ namespace OpenSim.Region.Framework.Scenes
3428 //ParentGroup.ScheduleGroupForFullUpdate(); 3937 //ParentGroup.ScheduleGroupForFullUpdate();
3429 } 3938 }
3430 3939
3431 public void StoreUndoState() 3940 public void StoreUndoState(ObjectChangeType change)
3432 { 3941 {
3433 StoreUndoState(false); 3942 if (m_UndoRedo == null)
3434 } 3943 m_UndoRedo = new UndoRedoState(5);
3435 3944
3436 public void StoreUndoState(bool forGroup) 3945 lock (m_UndoRedo)
3437 {
3438 if (!Undoing)
3439 { 3946 {
3440 if (!IgnoreUndoUpdate) 3947 if (!Undoing && !IgnoreUndoUpdate && ParentGroup != null) // just to read better - undo is in progress, or suspended
3441 { 3948 {
3442 if (ParentGroup != null) 3949 m_UndoRedo.StoreUndo(this, change);
3443 {
3444 lock (m_undo)
3445 {
3446 if (m_undo.Count > 0)
3447 {
3448 UndoState last = m_undo.Peek();
3449 if (last != null)
3450 {
3451 // TODO: May need to fix for group comparison
3452 if (last.Compare(this))
3453 {
3454 // m_log.DebugFormat(
3455 // "[SCENE OBJECT PART]: Not storing undo for {0} {1} since current state is same as last undo state, initial stack size {2}",
3456 // Name, LocalId, m_undo.Count);
3457
3458 return;
3459 }
3460 }
3461 }
3462
3463 // m_log.DebugFormat(
3464 // "[SCENE OBJECT PART]: Storing undo state for {0} {1}, forGroup {2}, initial stack size {3}",
3465 // Name, LocalId, forGroup, m_undo.Count);
3466
3467 if (ParentGroup.GetSceneMaxUndo() > 0)
3468 {
3469 UndoState nUndo = new UndoState(this, forGroup);
3470
3471 m_undo.Push(nUndo);
3472
3473 if (m_redo.Count > 0)
3474 m_redo.Clear();
3475
3476 // m_log.DebugFormat(
3477 // "[SCENE OBJECT PART]: Stored undo state for {0} {1}, forGroup {2}, stack size now {3}",
3478 // Name, LocalId, forGroup, m_undo.Count);
3479 }
3480 }
3481 }
3482 } 3950 }
3483// else
3484// {
3485// m_log.DebugFormat("[SCENE OBJECT PART]: Ignoring undo store for {0} {1}", Name, LocalId);
3486// }
3487 } 3951 }
3488// else
3489// {
3490// m_log.DebugFormat(
3491// "[SCENE OBJECT PART]: Ignoring undo store for {0} {1} since already undoing", Name, LocalId);
3492// }
3493 } 3952 }
3494 3953
3495 /// <summary> 3954 /// <summary>
@@ -3499,84 +3958,46 @@ namespace OpenSim.Region.Framework.Scenes
3499 { 3958 {
3500 get 3959 get
3501 { 3960 {
3502 lock (m_undo) 3961 if (m_UndoRedo == null)
3503 return m_undo.Count; 3962 return 0;
3963 return m_UndoRedo.Count;
3504 } 3964 }
3505 } 3965 }
3506 3966
3507 public void Undo() 3967 public void Undo()
3508 { 3968 {
3509 lock (m_undo) 3969 if (m_UndoRedo == null || Undoing || ParentGroup == null)
3510 { 3970 return;
3511// m_log.DebugFormat(
3512// "[SCENE OBJECT PART]: Handling undo request for {0} {1}, stack size {2}",
3513// Name, LocalId, m_undo.Count);
3514
3515 if (m_undo.Count > 0)
3516 {
3517 UndoState goback = m_undo.Pop();
3518
3519 if (goback != null)
3520 {
3521 UndoState nUndo = null;
3522
3523 if (ParentGroup.GetSceneMaxUndo() > 0)
3524 {
3525 nUndo = new UndoState(this, goback.ForGroup);
3526 }
3527
3528 goback.PlaybackState(this);
3529
3530 if (nUndo != null)
3531 m_redo.Push(nUndo);
3532 }
3533 }
3534 3971
3535// m_log.DebugFormat( 3972 lock (m_UndoRedo)
3536// "[SCENE OBJECT PART]: Handled undo request for {0} {1}, stack size now {2}", 3973 {
3537// Name, LocalId, m_undo.Count); 3974 Undoing = true;
3975 m_UndoRedo.Undo(this);
3976 Undoing = false;
3538 } 3977 }
3539 } 3978 }
3540 3979
3541 public void Redo() 3980 public void Redo()
3542 { 3981 {
3543 lock (m_undo) 3982 if (m_UndoRedo == null || Undoing || ParentGroup == null)
3544 { 3983 return;
3545// m_log.DebugFormat(
3546// "[SCENE OBJECT PART]: Handling redo request for {0} {1}, stack size {2}",
3547// Name, LocalId, m_redo.Count);
3548
3549 if (m_redo.Count > 0)
3550 {
3551 UndoState gofwd = m_redo.Pop();
3552
3553 if (gofwd != null)
3554 {
3555 if (ParentGroup.GetSceneMaxUndo() > 0)
3556 {
3557 UndoState nUndo = new UndoState(this, gofwd.ForGroup);
3558
3559 m_undo.Push(nUndo);
3560 }
3561
3562 gofwd.PlayfwdState(this);
3563 }
3564 3984
3565// m_log.DebugFormat( 3985 lock (m_UndoRedo)
3566// "[SCENE OBJECT PART]: Handled redo request for {0} {1}, stack size now {2}", 3986 {
3567// Name, LocalId, m_redo.Count); 3987 Undoing = true;
3568 } 3988 m_UndoRedo.Redo(this);
3989 Undoing = false;
3569 } 3990 }
3570 } 3991 }
3571 3992
3572 public void ClearUndoState() 3993 public void ClearUndoState()
3573 { 3994 {
3574// m_log.DebugFormat("[SCENE OBJECT PART]: Clearing undo and redo stacks in {0} {1}", Name, LocalId); 3995 if (m_UndoRedo == null || Undoing)
3996 return;
3575 3997
3576 lock (m_undo) 3998 lock (m_UndoRedo)
3577 { 3999 {
3578 m_undo.Clear(); 4000 m_UndoRedo.Clear();
3579 m_redo.Clear();
3580 } 4001 }
3581 } 4002 }
3582 4003
@@ -4206,6 +4627,27 @@ namespace OpenSim.Region.Framework.Scenes
4206 } 4627 }
4207 } 4628 }
4208 4629
4630
4631 public void UpdateExtraPhysics(ExtraPhysicsData physdata)
4632 {
4633 if (physdata.PhysShapeType == PhysShapeType.invalid || ParentGroup == null)
4634 return;
4635
4636 if (PhysicsShapeType != (byte)physdata.PhysShapeType)
4637 {
4638 PhysicsShapeType = (byte)physdata.PhysShapeType;
4639
4640 }
4641
4642 if(Density != physdata.Density)
4643 Density = physdata.Density;
4644 if(GravityModifier != physdata.GravitationModifier)
4645 GravityModifier = physdata.GravitationModifier;
4646 if(Friction != physdata.Friction)
4647 Friction = physdata.Friction;
4648 if(Bounciness != physdata.Bounce)
4649 Bounciness = physdata.Bounce;
4650 }
4209 /// <summary> 4651 /// <summary>
4210 /// Update the flags on this prim. This covers properties such as phantom, physics and temporary. 4652 /// Update the flags on this prim. This covers properties such as phantom, physics and temporary.
4211 /// </summary> 4653 /// </summary>
@@ -4213,7 +4655,7 @@ namespace OpenSim.Region.Framework.Scenes
4213 /// <param name="SetTemporary"></param> 4655 /// <param name="SetTemporary"></param>
4214 /// <param name="SetPhantom"></param> 4656 /// <param name="SetPhantom"></param>
4215 /// <param name="SetVD"></param> 4657 /// <param name="SetVD"></param>
4216 public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD) 4658 public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD, bool building)
4217 { 4659 {
4218 bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0); 4660 bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0);
4219 bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0); 4661 bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0);
@@ -4223,219 +4665,205 @@ namespace OpenSim.Region.Framework.Scenes
4223 if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD)) 4665 if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD))
4224 return; 4666 return;
4225 4667
4226 PhysicsActor pa = PhysActor; 4668 VolumeDetectActive = SetVD;
4227 4669
4228 // Special cases for VD. VD can only be called from a script 4670 // volume detector implies phantom
4229 // and can't be combined with changes to other states. So we can rely 4671 if (VolumeDetectActive)
4230 // that...
4231 // ... if VD is changed, all others are not.
4232 // ... if one of the others is changed, VD is not.
4233 if (SetVD) // VD is active, special logic applies
4234 {
4235 // State machine logic for VolumeDetect
4236 // More logic below
4237 bool phanReset = (SetPhantom != wasPhantom) && !SetPhantom;
4238
4239 if (phanReset) // Phantom changes from on to off switch VD off too
4240 {
4241 SetVD = false; // Switch it of for the course of this routine
4242 VolumeDetectActive = false; // and also permanently
4243
4244 if (pa != null)
4245 pa.SetVolumeDetect(0); // Let physics know about it too
4246 }
4247 else
4248 {
4249 // If volumedetect is active we don't want phantom to be applied.
4250 // If this is a new call to VD out of the state "phantom"
4251 // this will also cause the prim to be visible to physics
4252 SetPhantom = false;
4253 }
4254 }
4255
4256 if (UsePhysics && IsJoint())
4257 {
4258 SetPhantom = true; 4672 SetPhantom = true;
4259 }
4260 4673
4261 if (UsePhysics) 4674 if (UsePhysics)
4262 {
4263 AddFlag(PrimFlags.Physics); 4675 AddFlag(PrimFlags.Physics);
4264 if (!wasUsingPhysics)
4265 {
4266 DoPhysicsPropertyUpdate(UsePhysics, false);
4267
4268 if (!ParentGroup.IsDeleted)
4269 {
4270 if (LocalId == ParentGroup.RootPart.LocalId)
4271 {
4272 ParentGroup.CheckSculptAndLoad();
4273 }
4274 }
4275 }
4276 }
4277 else 4676 else
4278 {
4279 RemFlag(PrimFlags.Physics); 4677 RemFlag(PrimFlags.Physics);
4280 if (wasUsingPhysics)
4281 {
4282 DoPhysicsPropertyUpdate(UsePhysics, false);
4283 }
4284 }
4285 4678
4286 if (SetPhantom 4679 if (SetPhantom)
4287 || ParentGroup.IsAttachment
4288 || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints
4289 {
4290 AddFlag(PrimFlags.Phantom); 4680 AddFlag(PrimFlags.Phantom);
4681 else
4682 RemFlag(PrimFlags.Phantom);
4291 4683
4292 if (PhysActor != null) 4684 if (SetTemporary)
4685 AddFlag(PrimFlags.TemporaryOnRez);
4686 else
4687 RemFlag(PrimFlags.TemporaryOnRez);
4688
4689
4690 if (ParentGroup.Scene == null)
4691 return;
4692
4693 PhysicsActor pa = PhysActor;
4694
4695 if (pa != null && building && pa.Building != building)
4696 pa.Building = building;
4697
4698 if ((SetPhantom && !UsePhysics && !SetVD) || ParentGroup.IsAttachment || PhysicsShapeType == (byte)PhysShapeType.none
4699 || (Shape.PathCurve == (byte)Extrusion.Flexible))
4700 {
4701 if (pa != null)
4293 { 4702 {
4703 ParentGroup.Scene.RemovePhysicalPrim(1);
4294 RemoveFromPhysics(); 4704 RemoveFromPhysics();
4295 pa = null;
4296 } 4705 }
4706
4707 Velocity = new Vector3(0, 0, 0);
4708 Acceleration = new Vector3(0, 0, 0);
4709 if (ParentGroup.RootPart == this)
4710 AngularVelocity = new Vector3(0, 0, 0);
4297 } 4711 }
4298 else // Not phantom 4712 else
4299 { 4713 {
4300 RemFlag(PrimFlags.Phantom); 4714 if (ParentGroup.Scene.CollidablePrims)
4301
4302 if (ParentGroup.Scene == null)
4303 return;
4304
4305 if (ParentGroup.Scene.CollidablePrims && pa == null)
4306 { 4715 {
4307 pa = AddToPhysics(UsePhysics); 4716 if (pa == null)
4308
4309 if (pa != null)
4310 { 4717 {
4311 pa.SetMaterial(Material); 4718 AddToPhysics(UsePhysics, SetPhantom, building , false);
4312 DoPhysicsPropertyUpdate(UsePhysics, true); 4719 pa = PhysActor;
4313 4720
4314 if (!ParentGroup.IsDeleted) 4721 if (pa != null)
4315 { 4722 {
4316 if (LocalId == ParentGroup.RootPart.LocalId) 4723 if (
4724// ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
4725// ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4726// ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4727// ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4728// ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4729// ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4730 ((AggregateScriptEvents & PhyscicsNeededSubsEvents) != 0) || (CollisionSound != UUID.Zero)
4731// (CollisionSound != UUID.Zero)
4732 )
4317 { 4733 {
4318 ParentGroup.CheckSculptAndLoad(); 4734 pa.OnCollisionUpdate += PhysicsCollision;
4735 pa.SubscribeEvents(1000);
4319 } 4736 }
4320 } 4737 }
4321
4322 if (
4323 ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
4324 ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4325 ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4326 ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4327 ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4328 ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4329 (CollisionSound != UUID.Zero)
4330 )
4331 {
4332 pa.OnCollisionUpdate += PhysicsCollision;
4333 pa.SubscribeEvents(1000);
4334 }
4335 } 4738 }
4336 } 4739 else // it already has a physical representation
4337 else // it already has a physical representation
4338 {
4339 DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status. If it's phantom this will remove the prim
4340
4341 if (!ParentGroup.IsDeleted)
4342 { 4740 {
4343 if (LocalId == ParentGroup.RootPart.LocalId) 4741 DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status.
4344 { 4742 /* moved into DoPhysicsPropertyUpdate
4345 ParentGroup.CheckSculptAndLoad(); 4743 if(VolumeDetectActive)
4346 } 4744 pa.SetVolumeDetect(1);
4745 else
4746 pa.SetVolumeDetect(0);
4747 */
4748 if (pa.Building != building)
4749 pa.Building = building;
4347 } 4750 }
4348 } 4751 }
4349 } 4752 }
4350
4351 if (SetVD)
4352 {
4353 // If the above logic worked (this is urgent candidate to unit tests!)
4354 // we now have a physicsactor.
4355 // Defensive programming calls for a check here.
4356 // Better would be throwing an exception that could be catched by a unit test as the internal
4357 // logic should make sure, this Physactor is always here.
4358 if (pa != null)
4359 {
4360 pa.SetVolumeDetect(1);
4361 AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active
4362 VolumeDetectActive = true;
4363 }
4364 }
4365 else
4366 {
4367 // Remove VolumeDetect in any case. Note, it's safe to call SetVolumeDetect as often as you like
4368 // (mumbles, well, at least if you have infinte CPU powers :-))
4369 if (pa != null)
4370 pa.SetVolumeDetect(0);
4371
4372 VolumeDetectActive = false;
4373 }
4374
4375 if (SetTemporary)
4376 {
4377 AddFlag(PrimFlags.TemporaryOnRez);
4378 }
4379 else
4380 {
4381 RemFlag(PrimFlags.TemporaryOnRez);
4382 }
4383 4753
4384 // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString()); 4754 // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString());
4385 4755
4756 // and last in case we have a new actor and not building
4757
4386 if (ParentGroup != null) 4758 if (ParentGroup != null)
4387 { 4759 {
4388 ParentGroup.HasGroupChanged = true; 4760 ParentGroup.HasGroupChanged = true;
4389 ScheduleFullUpdate(); 4761 ScheduleFullUpdate();
4390 } 4762 }
4391 4763
4392// m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags); 4764// m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags);
4393 } 4765 }
4394 4766
4395 /// <summary> 4767 /// <summary>
4396 /// Adds this part to the physics scene. 4768 /// Adds this part to the physics scene.
4769 /// and sets the PhysActor property
4397 /// </summary> 4770 /// </summary>
4398 /// <remarks>This method also sets the PhysActor property.</remarks> 4771 /// <param name="isPhysical">Add this prim as physical.</param>
4399 /// <param name="rigidBody">Add this prim with a rigid body.</param> 4772 /// <param name="isPhantom">Add this prim as phantom.</param>
4400 /// <returns> 4773 /// <param name="building">tells physics to delay full construction of object</param>
4401 /// The physics actor. null if there was a failure. 4774 /// <param name="applyDynamics">applies velocities, force and torque</param>
4402 /// </returns> 4775 private void AddToPhysics(bool isPhysical, bool isPhantom, bool building, bool applyDynamics)
4403 private PhysicsActor AddToPhysics(bool rigidBody) 4776 {
4404 {
4405 PhysicsActor pa; 4777 PhysicsActor pa;
4406 4778
4779 Vector3 velocity = Velocity;
4780 Vector3 rotationalVelocity = AngularVelocity;;
4781
4407 try 4782 try
4408 { 4783 {
4409 pa = ParentGroup.Scene.PhysicsScene.AddPrimShape( 4784 pa = ParentGroup.Scene.PhysicsScene.AddPrimShape(
4410 string.Format("{0}/{1}", Name, UUID), 4785 string.Format("{0}/{1}", Name, UUID),
4411 Shape, 4786 Shape,
4412 AbsolutePosition, 4787 AbsolutePosition,
4413 Scale, 4788 Scale,
4414 RotationOffset, 4789 GetWorldRotation(),
4415 rigidBody, 4790 isPhysical,
4416 m_localId); 4791 isPhantom,
4792 PhysicsShapeType,
4793 m_localId);
4417 } 4794 }
4418 catch 4795 catch (Exception ex)
4419 { 4796 {
4420 m_log.ErrorFormat("[SCENE]: caught exception meshing object {0}. Object set to phantom.", m_uuid); 4797 m_log.ErrorFormat("[SCENE]: AddToPhysics object {0} failed: {1}", m_uuid, ex.Message);
4421 pa = null; 4798 pa = null;
4422 } 4799 }
4423 4800
4424 // FIXME: Ideally we wouldn't set the property here to reduce situations where threads changing physical
4425 // properties can stop on each other. However, DoPhysicsPropertyUpdate() currently relies on PhysActor
4426 // being set.
4427 PhysActor = pa;
4428
4429 // Basic Physics can also return null as well as an exception catch.
4430 if (pa != null) 4801 if (pa != null)
4431 { 4802 {
4432 pa.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info 4803 pa.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info
4433 pa.SetMaterial(Material); 4804 pa.SetMaterial(Material);
4434 DoPhysicsPropertyUpdate(rigidBody, true); 4805
4806 if (VolumeDetectActive) // change if not the default only
4807 pa.SetVolumeDetect(1);
4808
4809 if (m_vehicle != null && LocalId == ParentGroup.RootPart.LocalId)
4810 m_vehicle.SetVehicle(pa);
4811
4812 // we are going to tell rest of code about physics so better have this here
4813 PhysActor = pa;
4814
4815 // DoPhysicsPropertyUpdate(isPhysical, true);
4816 // lets expand it here just with what it really needs to do
4817
4818 if (isPhysical)
4819 {
4820 if (ParentGroup.RootPart.KeyframeMotion != null)
4821 ParentGroup.RootPart.KeyframeMotion.Stop();
4822 ParentGroup.RootPart.KeyframeMotion = null;
4823 ParentGroup.Scene.AddPhysicalPrim(1);
4824
4825 pa.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
4826 pa.OnOutOfBounds += PhysicsOutOfBounds;
4827
4828 if (ParentID != 0 && ParentID != LocalId)
4829 {
4830 PhysicsActor parentPa = ParentGroup.RootPart.PhysActor;
4831
4832 if (parentPa != null)
4833 {
4834 pa.link(parentPa);
4835 }
4836 }
4837 }
4838
4839 if (applyDynamics)
4840 // do independent of isphysical so parameters get setted (at least some)
4841 {
4842 Velocity = velocity;
4843 AngularVelocity = rotationalVelocity;
4844// pa.Velocity = velocity;
4845 pa.RotationalVelocity = rotationalVelocity;
4846
4847 // if not vehicle and root part apply force and torque
4848 if ((m_vehicle == null || m_vehicle.Type == Vehicle.TYPE_NONE)
4849 && LocalId == ParentGroup.RootPart.LocalId)
4850 {
4851 pa.Force = Force;
4852 pa.Torque = Torque;
4853 }
4854 }
4855
4856 if (Shape.SculptEntry)
4857 CheckSculptAndLoad();
4858 else
4859 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(pa);
4860
4861 if (!building)
4862 pa.Building = false;
4435 } 4863 }
4436 4864
4437 return pa; 4865 PhysActor = pa;
4438 } 4866 }
4439 4867
4440 /// <summary> 4868 /// <summary>
4441 /// This removes the part from the physics scene. 4869 /// This removes the part from the physics scene.
@@ -4642,33 +5070,28 @@ namespace OpenSim.Region.Framework.Scenes
4642 } 5070 }
4643 5071
4644 PhysicsActor pa = PhysActor; 5072 PhysicsActor pa = PhysActor;
4645 5073 if (pa != null)
4646 if (
4647 ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
4648 ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4649 ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4650 ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4651 ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4652 ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4653 (CollisionSound != UUID.Zero)
4654 )
4655 { 5074 {
4656 // subscribe to physics updates. 5075 if (
4657 if (pa != null) 5076// ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
5077// ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
5078// ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
5079// ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
5080// ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
5081// ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
5082 ((AggregateScriptEvents & PhyscicsNeededSubsEvents) != 0) || (CollisionSound != UUID.Zero)
5083 )
4658 { 5084 {
5085 // subscribe to physics updates.
4659 pa.OnCollisionUpdate += PhysicsCollision; 5086 pa.OnCollisionUpdate += PhysicsCollision;
4660 pa.SubscribeEvents(1000); 5087 pa.SubscribeEvents(1000);
4661 } 5088 }
4662 } 5089 else
4663 else
4664 {
4665 if (pa != null)
4666 { 5090 {
4667 pa.UnSubscribeEvents(); 5091 pa.UnSubscribeEvents();
4668 pa.OnCollisionUpdate -= PhysicsCollision; 5092 pa.OnCollisionUpdate -= PhysicsCollision;
4669 } 5093 }
4670 } 5094 }
4671
4672 //if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0) 5095 //if ((GetEffectiveObjectFlags() & (uint)PrimFlags.Scripted) != 0)
4673 //{ 5096 //{
4674 // ParentGroup.Scene.EventManager.OnScriptTimerEvent += handleTimerAccounting; 5097 // ParentGroup.Scene.EventManager.OnScriptTimerEvent += handleTimerAccounting;
@@ -4795,5 +5218,17 @@ namespace OpenSim.Region.Framework.Scenes
4795 Color color = Color; 5218 Color color = Color;
4796 return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A)); 5219 return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A));
4797 } 5220 }
5221
5222 public void ResetOwnerChangeFlag()
5223 {
5224 List<UUID> inv = Inventory.GetInventoryList();
5225
5226 foreach (UUID itemID in inv)
5227 {
5228 TaskInventoryItem item = Inventory.GetInventoryItem(itemID);
5229 item.OwnerChanged = false;
5230 Inventory.UpdateInventoryItem(item, false, false);
5231 }
5232 }
4798 } 5233 }
4799} 5234}