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.cs936
1 files changed, 614 insertions, 322 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index 439b718..a68b3eb 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.
@@ -184,6 +185,15 @@ namespace OpenSim.Region.Framework.Scenes
184 185
185 public UUID FromFolderID; 186 public UUID FromFolderID;
186 187
188 // The following two are to hold the attachment data
189 // while an object is inworld
190 [XmlIgnore]
191 public byte AttachPoint = 0;
192
193 [XmlIgnore]
194 public Vector3 AttachOffset = Vector3.Zero;
195
196 [XmlIgnore]
187 public int STATUS_ROTATE_X; 197 public int STATUS_ROTATE_X;
188 198
189 public int STATUS_ROTATE_Y; 199 public int STATUS_ROTATE_Y;
@@ -210,8 +220,7 @@ namespace OpenSim.Region.Framework.Scenes
210 220
211 public Vector3 RotationAxis = Vector3.One; 221 public Vector3 RotationAxis = Vector3.One;
212 222
213 public bool VolumeDetectActive; // XmlIgnore set to avoid problems with persistance until I come to care for this 223 public bool VolumeDetectActive;
214 // Certainly this must be a persistant setting finally
215 224
216 public bool IsWaitingForFirstSpinUpdatePacket; 225 public bool IsWaitingForFirstSpinUpdatePacket;
217 226
@@ -251,10 +260,10 @@ namespace OpenSim.Region.Framework.Scenes
251 private Quaternion m_sitTargetOrientation = Quaternion.Identity; 260 private Quaternion m_sitTargetOrientation = Quaternion.Identity;
252 private Vector3 m_sitTargetPosition; 261 private Vector3 m_sitTargetPosition;
253 private string m_sitAnimation = "SIT"; 262 private string m_sitAnimation = "SIT";
263 private bool m_occupied; // KF if any av is sitting on this prim
254 private string m_text = String.Empty; 264 private string m_text = String.Empty;
255 private string m_touchName = String.Empty; 265 private string m_touchName = String.Empty;
256 private readonly Stack<UndoState> m_undo = new Stack<UndoState>(5); 266 private UndoRedoState m_UndoRedo = null;
257 private readonly Stack<UndoState> m_redo = new Stack<UndoState>(5);
258 267
259 private bool m_passTouches; 268 private bool m_passTouches;
260 269
@@ -283,7 +292,16 @@ namespace OpenSim.Region.Framework.Scenes
283 protected Vector3 m_lastAcceleration; 292 protected Vector3 m_lastAcceleration;
284 protected Vector3 m_lastAngularVelocity; 293 protected Vector3 m_lastAngularVelocity;
285 protected int m_lastTerseSent; 294 protected int m_lastTerseSent;
286 295 protected float m_buoyancy = 0.0f;
296 protected Vector3 m_force;
297 protected Vector3 m_torque;
298
299 protected byte m_physicsShapeType = (byte)PhysShapeType.prim;
300 protected float m_density = 1000.0f; // in kg/m^3
301 protected float m_gravitymod = 1.0f;
302 protected float m_friction = 0.6f; // wood
303 protected float m_bounce = 0.5f; // wood
304
287 /// <summary> 305 /// <summary>
288 /// Stores media texture data 306 /// Stores media texture data
289 /// </summary> 307 /// </summary>
@@ -299,6 +317,17 @@ namespace OpenSim.Region.Framework.Scenes
299 private UUID m_collisionSound; 317 private UUID m_collisionSound;
300 private float m_collisionSoundVolume; 318 private float m_collisionSoundVolume;
301 319
320
321 private SOPVehicle m_vehicle = null;
322
323 private KeyframeMotion m_keyframeMotion = null;
324
325 public KeyframeMotion KeyframeMotion
326 {
327 get; set;
328 }
329
330
302 #endregion Fields 331 #endregion Fields
303 332
304// ~SceneObjectPart() 333// ~SceneObjectPart()
@@ -341,7 +370,7 @@ namespace OpenSim.Region.Framework.Scenes
341 UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition, 370 UUID ownerID, PrimitiveBaseShape shape, Vector3 groupPosition,
342 Quaternion rotationOffset, Vector3 offsetPosition) : this() 371 Quaternion rotationOffset, Vector3 offsetPosition) : this()
343 { 372 {
344 m_name = "Primitive"; 373 m_name = "Object";
345 374
346 CreationDate = (int)Utils.DateTimeToUnixTime(Rezzed); 375 CreationDate = (int)Utils.DateTimeToUnixTime(Rezzed);
347 LastOwnerID = CreatorID = OwnerID = ownerID; 376 LastOwnerID = CreatorID = OwnerID = ownerID;
@@ -381,7 +410,7 @@ namespace OpenSim.Region.Framework.Scenes
381 private uint _ownerMask = (uint)PermissionMask.All; 410 private uint _ownerMask = (uint)PermissionMask.All;
382 private uint _groupMask = (uint)PermissionMask.None; 411 private uint _groupMask = (uint)PermissionMask.None;
383 private uint _everyoneMask = (uint)PermissionMask.None; 412 private uint _everyoneMask = (uint)PermissionMask.None;
384 private uint _nextOwnerMask = (uint)PermissionMask.All; 413 private uint _nextOwnerMask = (uint)(PermissionMask.Move | PermissionMask.Modify | PermissionMask.Transfer);
385 private PrimFlags _flags = PrimFlags.None; 414 private PrimFlags _flags = PrimFlags.None;
386 private DateTime m_expires; 415 private DateTime m_expires;
387 private DateTime m_rezzed; 416 private DateTime m_rezzed;
@@ -475,12 +504,16 @@ namespace OpenSim.Region.Framework.Scenes
475 } 504 }
476 505
477 /// <value> 506 /// <value>
478 /// Access should be via Inventory directly - this property temporarily remains for xml serialization purposes 507 /// Get the inventory list
479 /// </value> 508 /// </value>
480 public TaskInventoryDictionary TaskInventory 509 public TaskInventoryDictionary TaskInventory
481 { 510 {
482 get { return m_inventory.Items; } 511 get {
483 set { m_inventory.Items = value; } 512 return m_inventory.Items;
513 }
514 set {
515 m_inventory.Items = value;
516 }
484 } 517 }
485 518
486 /// <summary> 519 /// <summary>
@@ -529,19 +562,6 @@ namespace OpenSim.Region.Framework.Scenes
529 } 562 }
530 } 563 }
531 564
532 public byte Material
533 {
534 get { return (byte) m_material; }
535 set
536 {
537 m_material = (Material)value;
538 if (PhysActor != null)
539 {
540 PhysActor.SetMaterial((int)value);
541 }
542 }
543 }
544
545 public bool PassTouches 565 public bool PassTouches
546 { 566 {
547 get { return m_passTouches; } 567 get { return m_passTouches; }
@@ -624,14 +644,12 @@ namespace OpenSim.Region.Framework.Scenes
624 set { m_LoopSoundSlavePrims = value; } 644 set { m_LoopSoundSlavePrims = value; }
625 } 645 }
626 646
627
628 public Byte[] TextureAnimation 647 public Byte[] TextureAnimation
629 { 648 {
630 get { return m_TextureAnimation; } 649 get { return m_TextureAnimation; }
631 set { m_TextureAnimation = value; } 650 set { m_TextureAnimation = value; }
632 } 651 }
633 652
634
635 public Byte[] ParticleSystem 653 public Byte[] ParticleSystem
636 { 654 {
637 get { return m_particleSystem; } 655 get { return m_particleSystem; }
@@ -668,9 +686,11 @@ namespace OpenSim.Region.Framework.Scenes
668 { 686 {
669 // If this is a linkset, we don't want the physics engine mucking up our group position here. 687 // If this is a linkset, we don't want the physics engine mucking up our group position here.
670 PhysicsActor actor = PhysActor; 688 PhysicsActor actor = PhysActor;
671 if (actor != null && ParentID == 0) 689 if (ParentID == 0)
672 { 690 {
673 m_groupPosition = actor.Position; 691 if (actor != null)
692 m_groupPosition = actor.Position;
693 return m_groupPosition;
674 } 694 }
675 695
676 if (ParentGroup.IsAttachment) 696 if (ParentGroup.IsAttachment)
@@ -680,12 +700,14 @@ namespace OpenSim.Region.Framework.Scenes
680 return sp.AbsolutePosition; 700 return sp.AbsolutePosition;
681 } 701 }
682 702
703 // use root prim's group position. Physics may have updated it
704 if (ParentGroup.RootPart != this)
705 m_groupPosition = ParentGroup.RootPart.GroupPosition;
683 return m_groupPosition; 706 return m_groupPosition;
684 } 707 }
685 set 708 set
686 { 709 {
687 m_groupPosition = value; 710 m_groupPosition = value;
688
689 PhysicsActor actor = PhysActor; 711 PhysicsActor actor = PhysActor;
690 if (actor != null) 712 if (actor != null)
691 { 713 {
@@ -711,16 +733,6 @@ namespace OpenSim.Region.Framework.Scenes
711 m_log.Error("[SCENEOBJECTPART]: GROUP POSITION. " + e.Message); 733 m_log.Error("[SCENEOBJECTPART]: GROUP POSITION. " + e.Message);
712 } 734 }
713 } 735 }
714
715 // TODO if we decide to do sitting in a more SL compatible way (multiple avatars per prim), this has to be fixed, too
716 if (SitTargetAvatar != UUID.Zero)
717 {
718 ScenePresence avatar;
719 if (ParentGroup.Scene.TryGetScenePresence(SitTargetAvatar, out avatar))
720 {
721 avatar.ParentPosition = GetWorldPosition();
722 }
723 }
724 } 736 }
725 } 737 }
726 738
@@ -729,7 +741,7 @@ namespace OpenSim.Region.Framework.Scenes
729 get { return m_offsetPosition; } 741 get { return m_offsetPosition; }
730 set 742 set
731 { 743 {
732// StoreUndoState(); 744 Vector3 oldpos = m_offsetPosition;
733 m_offsetPosition = value; 745 m_offsetPosition = value;
734 746
735 if (ParentGroup != null && !ParentGroup.IsDeleted) 747 if (ParentGroup != null && !ParentGroup.IsDeleted)
@@ -744,7 +756,22 @@ namespace OpenSim.Region.Framework.Scenes
744 if (ParentGroup.Scene != null) 756 if (ParentGroup.Scene != null)
745 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor); 757 ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(actor);
746 } 758 }
759
760 if (!m_parentGroup.m_dupeInProgress)
761 {
762 List<ScenePresence> avs = ParentGroup.GetLinkedAvatars();
763 foreach (ScenePresence av in avs)
764 {
765 if (av.ParentID == m_localId)
766 {
767 Vector3 offset = (m_offsetPosition - oldpos);
768 av.AbsolutePosition += offset;
769 av.SendAvatarDataToAllAgents();
770 }
771 }
772 }
747 } 773 }
774 TriggerScriptChangedEvent(Changed.POSITION);
748 } 775 }
749 } 776 }
750 777
@@ -793,7 +820,7 @@ namespace OpenSim.Region.Framework.Scenes
793 820
794 set 821 set
795 { 822 {
796 StoreUndoState(); 823// StoreUndoState();
797 m_rotationOffset = value; 824 m_rotationOffset = value;
798 825
799 PhysicsActor actor = PhysActor; 826 PhysicsActor actor = PhysActor;
@@ -881,7 +908,7 @@ namespace OpenSim.Region.Framework.Scenes
881 get 908 get
882 { 909 {
883 PhysicsActor actor = PhysActor; 910 PhysicsActor actor = PhysActor;
884 if ((actor != null) && actor.IsPhysical) 911 if ((actor != null) && actor.IsPhysical && ParentGroup.RootPart == this)
885 { 912 {
886 m_angularVelocity = actor.RotationalVelocity; 913 m_angularVelocity = actor.RotationalVelocity;
887 } 914 }
@@ -893,7 +920,16 @@ namespace OpenSim.Region.Framework.Scenes
893 /// <summary></summary> 920 /// <summary></summary>
894 public Vector3 Acceleration 921 public Vector3 Acceleration
895 { 922 {
896 get { return m_acceleration; } 923 get
924 {
925 PhysicsActor actor = PhysActor;
926 if (actor != null)
927 {
928 m_acceleration = actor.Acceleration;
929 }
930 return m_acceleration;
931 }
932
897 set { m_acceleration = value; } 933 set { m_acceleration = value; }
898 } 934 }
899 935
@@ -963,7 +999,7 @@ namespace OpenSim.Region.Framework.Scenes
963 { 999 {
964 if (m_shape != null) 1000 if (m_shape != null)
965 { 1001 {
966 StoreUndoState(); 1002// StoreUndoState();
967 1003
968 m_shape.Scale = value; 1004 m_shape.Scale = value;
969 1005
@@ -1030,10 +1066,7 @@ namespace OpenSim.Region.Framework.Scenes
1030 { 1066 {
1031 get 1067 get
1032 { 1068 {
1033 if (ParentGroup.IsAttachment) 1069 return GroupPosition + (m_offsetPosition * ParentGroup.RootPart.RotationOffset);
1034 return GroupPosition;
1035
1036 return m_offsetPosition + m_groupPosition;
1037 } 1070 }
1038 } 1071 }
1039 1072
@@ -1203,6 +1236,13 @@ namespace OpenSim.Region.Framework.Scenes
1203 _flags = value; 1236 _flags = value;
1204 } 1237 }
1205 } 1238 }
1239
1240 [XmlIgnore]
1241 public bool IsOccupied // KF If an av is sittingon this prim
1242 {
1243 get { return m_occupied; }
1244 set { m_occupied = value; }
1245 }
1206 1246
1207 /// <summary> 1247 /// <summary>
1208 /// ID of the avatar that is sat on us. If there is no such avatar then is UUID.Zero 1248 /// ID of the avatar that is sat on us. If there is no such avatar then is UUID.Zero
@@ -1262,6 +1302,155 @@ namespace OpenSim.Region.Framework.Scenes
1262 set { m_collisionSoundVolume = value; } 1302 set { m_collisionSoundVolume = value; }
1263 } 1303 }
1264 1304
1305 public float Buoyancy
1306 {
1307 get
1308 {
1309 if (ParentGroup.RootPart == this)
1310 return m_buoyancy;
1311
1312 return ParentGroup.RootPart.Buoyancy;
1313 }
1314 set
1315 {
1316 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1317 {
1318 ParentGroup.RootPart.Buoyancy = value;
1319 return;
1320 }
1321 m_buoyancy = value;
1322 if (PhysActor != null)
1323 PhysActor.Buoyancy = value;
1324 }
1325 }
1326
1327 public Vector3 Force
1328 {
1329 get
1330 {
1331 if (ParentGroup.RootPart == this)
1332 return m_force;
1333
1334 return ParentGroup.RootPart.Force;
1335 }
1336
1337 set
1338 {
1339 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1340 {
1341 ParentGroup.RootPart.Force = value;
1342 return;
1343 }
1344 m_force = value;
1345 if (PhysActor != null)
1346 PhysActor.Force = value;
1347 }
1348 }
1349
1350 public Vector3 Torque
1351 {
1352 get
1353 {
1354 if (ParentGroup.RootPart == this)
1355 return m_torque;
1356
1357 return ParentGroup.RootPart.Torque;
1358 }
1359
1360 set
1361 {
1362 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1363 {
1364 ParentGroup.RootPart.Torque = value;
1365 return;
1366 }
1367 m_torque = value;
1368 if (PhysActor != null)
1369 PhysActor.Torque = value;
1370 }
1371 }
1372
1373 public byte Material
1374 {
1375 get { return (byte)m_material; }
1376 set
1377 {
1378 if (value >= 0 && value <= (byte)SOPMaterialData.MaxMaterial)
1379 {
1380 m_material = (Material)value;
1381 m_friction = SOPMaterialData.friction(m_material);
1382 m_bounce = SOPMaterialData.bounce(m_material);
1383 if (PhysActor != null)
1384 {
1385 PhysActor.SetMaterial((int)value);
1386 }
1387 }
1388 }
1389 }
1390
1391 public byte PhysicsShapeType
1392 {
1393 get { return m_physicsShapeType; }
1394 set
1395 {
1396 if (value < 0 || value >= (byte)PhysShapeType.convex)
1397 value = (byte)PhysShapeType.prim; //convex not supported ?
1398
1399 else if (value == (byte)PhysShapeType.none)
1400 {
1401 if (ParentGroup == null || ParentGroup.RootPart == this)
1402 value = (byte)PhysShapeType.prim;
1403 }
1404 m_physicsShapeType = value;
1405 }
1406 }
1407
1408 public float Density // in kg/m^3
1409 {
1410 get { return m_density; }
1411 set
1412 {
1413 if (value >=1 && value <= 22587.0)
1414 {
1415 m_density = value;
1416 }
1417 }
1418 }
1419
1420 public float GravityModifier
1421 {
1422 get { return m_gravitymod; }
1423 set
1424 { if( value >= -1 && value <=28.0f)
1425 m_gravitymod = value;
1426 }
1427 }
1428
1429 public float Friction
1430 {
1431 get { return m_friction; }
1432 set
1433 {
1434 if (value >= 0 && value <= 255.0f)
1435 {
1436 m_friction = value;
1437 }
1438 }
1439 }
1440
1441 public float Bounciness
1442 {
1443 get { return m_bounce; }
1444 set
1445 {
1446 if (value >= 0 && value <= 1.0f)
1447 {
1448 m_bounce = value;
1449 }
1450 }
1451 }
1452
1453
1265 #endregion Public Properties with only Get 1454 #endregion Public Properties with only Get
1266 1455
1267 private uint ApplyMask(uint val, bool set, uint mask) 1456 private uint ApplyMask(uint val, bool set, uint mask)
@@ -1437,20 +1626,24 @@ namespace OpenSim.Region.Framework.Scenes
1437 /// </summary> 1626 /// </summary>
1438 /// <param name="impulsei">Vector force</param> 1627 /// <param name="impulsei">Vector force</param>
1439 /// <param name="localGlobalTF">true for the local frame, false for the global frame</param> 1628 /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
1440 public void SetAngularImpulse(Vector3 impulsei, bool localGlobalTF) 1629
1630 // this is actualy Set Torque.. keeping naming so not to edit lslapi also
1631 public void SetAngularImpulse(Vector3 torquei, bool localGlobalTF)
1441 { 1632 {
1442 Vector3 impulse = impulsei; 1633 Vector3 torque = torquei;
1443 1634
1444 if (localGlobalTF) 1635 if (localGlobalTF)
1445 { 1636 {
1637/*
1446 Quaternion grot = GetWorldRotation(); 1638 Quaternion grot = GetWorldRotation();
1447 Quaternion AXgrot = grot; 1639 Quaternion AXgrot = grot;
1448 Vector3 AXimpulsei = impulsei; 1640 Vector3 AXimpulsei = impulsei;
1449 Vector3 newimpulse = AXimpulsei * AXgrot; 1641 Vector3 newimpulse = AXimpulsei * AXgrot;
1450 impulse = newimpulse; 1642 */
1643 torque *= GetWorldRotation();
1451 } 1644 }
1452 1645
1453 ParentGroup.setAngularImpulse(impulse); 1646 Torque = torque;
1454 } 1647 }
1455 1648
1456 /// <summary> 1649 /// <summary>
@@ -1458,18 +1651,19 @@ namespace OpenSim.Region.Framework.Scenes
1458 /// </summary> 1651 /// </summary>
1459 /// <param name="rootObjectFlags"></param> 1652 /// <param name="rootObjectFlags"></param>
1460 /// <param name="VolumeDetectActive"></param> 1653 /// <param name="VolumeDetectActive"></param>
1461 public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive) 1654
1655 public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive, bool building)
1462 { 1656 {
1463 if (!ParentGroup.Scene.CollidablePrims) 1657 if (!ParentGroup.Scene.CollidablePrims)
1464 return; 1658 return;
1465 1659
1466// m_log.DebugFormat( 1660 if (PhysicsShapeType == (byte)PhysShapeType.none)
1467// "[SCENE OBJECT PART]: Applying physics to {0} {1}, m_physicalPrim {2}", 1661 return;
1468// Name, LocalId, UUID, m_physicalPrim);
1469 1662
1470 bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0; 1663 bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0;
1471 bool isPhantom = (rootObjectFlags & (uint) PrimFlags.Phantom) != 0; 1664 bool isPhantom = (rootObjectFlags & (uint) PrimFlags.Phantom) != 0;
1472 1665
1666
1473 if (IsJoint()) 1667 if (IsJoint())
1474 { 1668 {
1475 DoPhysicsPropertyUpdate(isPhysical, true); 1669 DoPhysicsPropertyUpdate(isPhysical, true);
@@ -1477,16 +1671,19 @@ namespace OpenSim.Region.Framework.Scenes
1477 else 1671 else
1478 { 1672 {
1479 // Special case for VolumeDetection: If VolumeDetection is set, the phantom flag is locally ignored 1673 // Special case for VolumeDetection: If VolumeDetection is set, the phantom flag is locally ignored
1480 if (VolumeDetectActive) 1674// if (VolumeDetectActive)
1481 isPhantom = false; 1675// isPhantom = false;
1482 1676
1483 // Added clarification.. since A rigid body is an object that you can kick around, etc. 1677 // Added clarification.. since A rigid body is an object that you can kick around, etc.
1484 bool RigidBody = isPhysical && !isPhantom; 1678// bool RigidBody = isPhysical && !isPhantom;
1485 1679
1486 // 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 1680 // 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
1487 // or flexible 1681 // or flexible
1488 if (!isPhantom && !ParentGroup.IsAttachment && !(Shape.PathCurve == (byte)Extrusion.Flexible)) 1682 // if (!isPhantom && !ParentGroup.IsAttachment && !(Shape.PathCurve == (byte)Extrusion.Flexible))
1683 if ((!isPhantom || isPhysical || VolumeDetectActive) && !ParentGroup.IsAttachment && !(Shape.PathCurve == (byte)Extrusion.Flexible))
1489 { 1684 {
1685 Vector3 velocity = Velocity;
1686 Vector3 rotationalVelocity = AngularVelocity;
1490 try 1687 try
1491 { 1688 {
1492 PhysActor = ParentGroup.Scene.PhysicsScene.AddPrimShape( 1689 PhysActor = ParentGroup.Scene.PhysicsScene.AddPrimShape(
@@ -1494,8 +1691,9 @@ namespace OpenSim.Region.Framework.Scenes
1494 Shape, 1691 Shape,
1495 AbsolutePosition, 1692 AbsolutePosition,
1496 Scale, 1693 Scale,
1497 RotationOffset, 1694 GetWorldRotation(),
1498 RigidBody, 1695 isPhysical,
1696 isPhantom,
1499 m_localId); 1697 m_localId);
1500 } 1698 }
1501 catch 1699 catch
@@ -1509,8 +1707,30 @@ namespace OpenSim.Region.Framework.Scenes
1509 { 1707 {
1510 PhysActor.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info 1708 PhysActor.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info
1511 PhysActor.SetMaterial(Material); 1709 PhysActor.SetMaterial(Material);
1512 DoPhysicsPropertyUpdate(RigidBody, true); 1710
1513 PhysActor.SetVolumeDetect(VolumeDetectActive ? 1 : 0); 1711 // if root part apply vehicle
1712 if (m_vehicle != null && LocalId == ParentGroup.RootPart.LocalId)
1713 m_vehicle.SetVehicle(PhysActor);
1714
1715 DoPhysicsPropertyUpdate(isPhysical, true);
1716 if(VolumeDetectActive) // change if not the default only
1717 PhysActor.SetVolumeDetect(1);
1718
1719 if (!building)
1720 PhysActor.Building = false;
1721
1722 Velocity = velocity;
1723 AngularVelocity = rotationalVelocity;
1724 PhysActor.Velocity = velocity;
1725 PhysActor.RotationalVelocity = rotationalVelocity;
1726
1727 // if not vehicle and root part apply force and torque
1728 if ((m_vehicle == null || m_vehicle.Type == Vehicle.TYPE_NONE)
1729 && LocalId == ParentGroup.RootPart.LocalId)
1730 {
1731 PhysActor.Force = Force;
1732 PhysActor.Torque = Torque;
1733 }
1514 } 1734 }
1515 } 1735 }
1516 } 1736 }
@@ -1564,6 +1784,11 @@ namespace OpenSim.Region.Framework.Scenes
1564 dupe.Category = Category; 1784 dupe.Category = Category;
1565 dupe.m_rezzed = m_rezzed; 1785 dupe.m_rezzed = m_rezzed;
1566 1786
1787 dupe.m_UndoRedo = null;
1788
1789 dupe.IgnoreUndoUpdate = false;
1790 dupe.Undoing = false;
1791
1567 dupe.m_inventory = new SceneObjectPartInventory(dupe); 1792 dupe.m_inventory = new SceneObjectPartInventory(dupe);
1568 dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone(); 1793 dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone();
1569 1794
@@ -1579,6 +1804,7 @@ namespace OpenSim.Region.Framework.Scenes
1579 1804
1580 // Move afterwards ResetIDs as it clears the localID 1805 // Move afterwards ResetIDs as it clears the localID
1581 dupe.LocalId = localID; 1806 dupe.LocalId = localID;
1807
1582 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated. 1808 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
1583 dupe.LastOwnerID = OwnerID; 1809 dupe.LastOwnerID = OwnerID;
1584 1810
@@ -1598,6 +1824,9 @@ namespace OpenSim.Region.Framework.Scenes
1598 dupe.DoPhysicsPropertyUpdate(UsePhysics, true); 1824 dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
1599 } 1825 }
1600 1826
1827 if (dupe.PhysActor != null)
1828 dupe.PhysActor.LocalID = localID;
1829
1601 ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed); 1830 ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed);
1602 1831
1603// m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID); 1832// m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID);
@@ -1735,63 +1964,63 @@ namespace OpenSim.Region.Framework.Scenes
1735 { 1964 {
1736 if (UsePhysics != PhysActor.IsPhysical || isNew) 1965 if (UsePhysics != PhysActor.IsPhysical || isNew)
1737 { 1966 {
1738 if (PhysActor.IsPhysical) // implies UsePhysics==false for this block 1967 if (PhysActor.IsPhysical)
1739 { 1968 {
1740 if (!isNew) 1969 if (!isNew) // implies UsePhysics==false for this block
1970 {
1741 ParentGroup.Scene.RemovePhysicalPrim(1); 1971 ParentGroup.Scene.RemovePhysicalPrim(1);
1742 1972
1743 PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate; 1973 Velocity = new Vector3(0, 0, 0);
1744 PhysActor.OnOutOfBounds -= PhysicsOutOfBounds; 1974 Acceleration = new Vector3(0, 0, 0);
1745 PhysActor.delink(); 1975 if (ParentGroup.RootPart == this)
1976 AngularVelocity = new Vector3(0, 0, 0);
1746 1977
1747 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints && (!isNew)) 1978 if (PhysActor.Phantom)
1748 { 1979 {
1749 // destroy all joints connected to this now deactivated body 1980 RemoveFromPhysics();
1750 ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(PhysActor); 1981 return;
1751 } 1982 }
1752 1983
1753 // stop client-side interpolation of all joint proxy objects that have just been deleted 1984 PhysActor.IsPhysical = UsePhysics;
1754 // this is done because RemoveAllJointsConnectedToActor invokes the OnJointDeactivated callback, 1985 PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
1755 // which stops client-side interpolation of deactivated joint proxy objects. 1986 PhysActor.OnOutOfBounds -= PhysicsOutOfBounds;
1987 PhysActor.delink();
1988 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
1989 {
1990 // destroy all joints connected to this now deactivated body
1991 ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(PhysActor);
1992 }
1993 }
1756 } 1994 }
1757 1995
1758 if (!UsePhysics && !isNew) 1996 if (PhysActor.IsPhysical != UsePhysics)
1759 { 1997 PhysActor.IsPhysical = UsePhysics;
1760 // reset velocity to 0 on physics switch-off. Without that, the client thinks the
1761 // prim still has velocity and continues to interpolate its position along the old
1762 // velocity-vector.
1763 Velocity = new Vector3(0, 0, 0);
1764 Acceleration = new Vector3(0, 0, 0);
1765 AngularVelocity = new Vector3(0, 0, 0);
1766 //RotationalVelocity = new Vector3(0, 0, 0);
1767 }
1768 1998
1769 PhysActor.IsPhysical = UsePhysics; 1999 if (UsePhysics)
2000 {
2001 if (ParentGroup.RootPart.KeyframeMotion != null)
2002 ParentGroup.RootPart.KeyframeMotion.Stop();
2003 ParentGroup.RootPart.KeyframeMotion = null;
2004 ParentGroup.Scene.AddPhysicalPrim(1);
1770 2005
1771 // If we're not what we're supposed to be in the physics scene, recreate ourselves. 2006 PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
1772 //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor); 2007 PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
1773 /// that's not wholesome. Had to make Scene public
1774 //PhysActor = null;
1775 2008
1776 if ((Flags & PrimFlags.Phantom) == 0) 2009 if (ParentID != 0 && ParentID != LocalId)
1777 {
1778 if (UsePhysics)
1779 { 2010 {
1780 ParentGroup.Scene.AddPhysicalPrim(1); 2011 if (ParentGroup.RootPart.PhysActor != null)
1781
1782 PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
1783 PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
1784 if (ParentID != 0 && ParentID != LocalId)
1785 { 2012 {
1786 if (ParentGroup.RootPart.PhysActor != null) 2013 PhysActor.link(ParentGroup.RootPart.PhysActor);
1787 {
1788 PhysActor.link(ParentGroup.RootPart.PhysActor);
1789 }
1790 } 2014 }
1791 } 2015 }
1792 } 2016 }
1793 } 2017 }
1794 2018
2019 bool phan = ((Flags & PrimFlags.Phantom) != 0);
2020 if (PhysActor.Phantom != phan)
2021 PhysActor.Phantom = phan;
2022
2023
1795 // If this part is a sculpt then delay the physics update until we've asynchronously loaded the 2024 // If this part is a sculpt then delay the physics update until we've asynchronously loaded the
1796 // mesh data. 2025 // mesh data.
1797 if (Shape.SculptEntry) 2026 if (Shape.SculptEntry)
@@ -1924,10 +2153,7 @@ namespace OpenSim.Region.Framework.Scenes
1924 2153
1925 public Vector3 GetForce() 2154 public Vector3 GetForce()
1926 { 2155 {
1927 if (PhysActor != null) 2156 return Force;
1928 return PhysActor.Force;
1929 else
1930 return Vector3.Zero;
1931 } 2157 }
1932 2158
1933 /// <summary> 2159 /// <summary>
@@ -2561,9 +2787,9 @@ namespace OpenSim.Region.Framework.Scenes
2561 Vector3 newpos = new Vector3(PhysActor.Position.GetBytes(), 0); 2787 Vector3 newpos = new Vector3(PhysActor.Position.GetBytes(), 0);
2562 2788
2563 if (ParentGroup.Scene.TestBorderCross(newpos, Cardinals.N) 2789 if (ParentGroup.Scene.TestBorderCross(newpos, Cardinals.N)
2564 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.S) 2790 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.S)
2565 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.E) 2791 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.E)
2566 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.W)) 2792 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.W))
2567 { 2793 {
2568 ParentGroup.AbsolutePosition = newpos; 2794 ParentGroup.AbsolutePosition = newpos;
2569 return; 2795 return;
@@ -2584,17 +2810,18 @@ namespace OpenSim.Region.Framework.Scenes
2584 //Trys to fetch sound id from prim's inventory. 2810 //Trys to fetch sound id from prim's inventory.
2585 //Prim's inventory doesn't support non script items yet 2811 //Prim's inventory doesn't support non script items yet
2586 2812
2587 lock (TaskInventory) 2813 TaskInventory.LockItemsForRead(true);
2814
2815 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2588 { 2816 {
2589 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 2817 if (item.Value.Name == sound)
2590 { 2818 {
2591 if (item.Value.Name == sound) 2819 soundID = item.Value.ItemID;
2592 { 2820 break;
2593 soundID = item.Value.ItemID;
2594 break;
2595 }
2596 } 2821 }
2597 } 2822 }
2823
2824 TaskInventory.LockItemsForRead(false);
2598 } 2825 }
2599 2826
2600 ParentGroup.Scene.ForEachRootScenePresence(delegate(ScenePresence sp) 2827 ParentGroup.Scene.ForEachRootScenePresence(delegate(ScenePresence sp)
@@ -2914,8 +3141,8 @@ namespace OpenSim.Region.Framework.Scenes
2914 { 3141 {
2915 const float ROTATION_TOLERANCE = 0.01f; 3142 const float ROTATION_TOLERANCE = 0.01f;
2916 const float VELOCITY_TOLERANCE = 0.001f; 3143 const float VELOCITY_TOLERANCE = 0.001f;
2917 const float POSITION_TOLERANCE = 0.05f; 3144 const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
2918 const int TIME_MS_TOLERANCE = 3000; 3145 const int TIME_MS_TOLERANCE = 200; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
2919 3146
2920 switch (UpdateFlag) 3147 switch (UpdateFlag)
2921 { 3148 {
@@ -2977,17 +3204,16 @@ namespace OpenSim.Region.Framework.Scenes
2977 if (!UUID.TryParse(sound, out soundID)) 3204 if (!UUID.TryParse(sound, out soundID))
2978 { 3205 {
2979 // search sound file from inventory 3206 // search sound file from inventory
2980 lock (TaskInventory) 3207 TaskInventory.LockItemsForRead(true);
3208 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2981 { 3209 {
2982 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 3210 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
2983 { 3211 {
2984 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) 3212 soundID = item.Value.ItemID;
2985 { 3213 break;
2986 soundID = item.Value.ItemID;
2987 break;
2988 }
2989 } 3214 }
2990 } 3215 }
3216 TaskInventory.LockItemsForRead(false);
2991 } 3217 }
2992 3218
2993 if (soundID == UUID.Zero) 3219 if (soundID == UUID.Zero)
@@ -3072,10 +3298,13 @@ namespace OpenSim.Region.Framework.Scenes
3072 3298
3073 public void SetBuoyancy(float fvalue) 3299 public void SetBuoyancy(float fvalue)
3074 { 3300 {
3301 Buoyancy = fvalue;
3302/*
3075 if (PhysActor != null) 3303 if (PhysActor != null)
3076 { 3304 {
3077 PhysActor.Buoyancy = fvalue; 3305 PhysActor.Buoyancy = fvalue;
3078 } 3306 }
3307 */
3079 } 3308 }
3080 3309
3081 public void SetDieAtEdge(bool p) 3310 public void SetDieAtEdge(bool p)
@@ -3103,23 +3332,83 @@ namespace OpenSim.Region.Framework.Scenes
3103 3332
3104 public void SetForce(Vector3 force) 3333 public void SetForce(Vector3 force)
3105 { 3334 {
3335 Force = force;
3336/*
3106 if (PhysActor != null) 3337 if (PhysActor != null)
3107 { 3338 {
3108 PhysActor.Force = force; 3339 PhysActor.Force = force;
3109 } 3340 }
3341 */
3342 }
3343
3344 public SOPVehicle sopVehicle
3345 {
3346 get
3347 {
3348 return m_vehicle;
3349 }
3350 set
3351 {
3352 m_vehicle = value;
3353 }
3354 }
3355
3356
3357 public int VehicleType
3358 {
3359 get
3360 {
3361 if (m_vehicle == null)
3362 return (int)Vehicle.TYPE_NONE;
3363 else
3364 return (int)m_vehicle.Type;
3365 }
3366 set
3367 {
3368 SetVehicleType(value);
3369 }
3110 } 3370 }
3111 3371
3112 public void SetVehicleType(int type) 3372 public void SetVehicleType(int type)
3113 { 3373 {
3114 if (PhysActor != null) 3374 m_vehicle = null;
3375
3376 if (type == (int)Vehicle.TYPE_NONE)
3377 {
3378 if (_parentID ==0 && PhysActor != null)
3379 PhysActor.VehicleType = (int)Vehicle.TYPE_NONE;
3380 return;
3381 }
3382 m_vehicle = new SOPVehicle();
3383 m_vehicle.ProcessTypeChange((Vehicle)type);
3384 {
3385 if (_parentID ==0 && PhysActor != null)
3386 PhysActor.VehicleType = type;
3387 return;
3388 }
3389 }
3390
3391 public void SetVehicleFlags(int param, bool remove)
3392 {
3393 if (m_vehicle == null)
3394 return;
3395
3396 m_vehicle.ProcessVehicleFlags(param, remove);
3397
3398 if (_parentID ==0 && PhysActor != null)
3115 { 3399 {
3116 PhysActor.VehicleType = type; 3400 PhysActor.VehicleFlags(param, remove);
3117 } 3401 }
3118 } 3402 }
3119 3403
3120 public void SetVehicleFloatParam(int param, float value) 3404 public void SetVehicleFloatParam(int param, float value)
3121 { 3405 {
3122 if (PhysActor != null) 3406 if (m_vehicle == null)
3407 return;
3408
3409 m_vehicle.ProcessFloatVehicleParam((Vehicle)param, value);
3410
3411 if (_parentID == 0 && PhysActor != null)
3123 { 3412 {
3124 PhysActor.VehicleFloatParam(param, value); 3413 PhysActor.VehicleFloatParam(param, value);
3125 } 3414 }
@@ -3127,7 +3416,12 @@ namespace OpenSim.Region.Framework.Scenes
3127 3416
3128 public void SetVehicleVectorParam(int param, Vector3 value) 3417 public void SetVehicleVectorParam(int param, Vector3 value)
3129 { 3418 {
3130 if (PhysActor != null) 3419 if (m_vehicle == null)
3420 return;
3421
3422 m_vehicle.ProcessVectorVehicleParam((Vehicle)param, value);
3423
3424 if (_parentID == 0 && PhysActor != null)
3131 { 3425 {
3132 PhysActor.VehicleVectorParam(param, value); 3426 PhysActor.VehicleVectorParam(param, value);
3133 } 3427 }
@@ -3135,7 +3429,12 @@ namespace OpenSim.Region.Framework.Scenes
3135 3429
3136 public void SetVehicleRotationParam(int param, Quaternion rotation) 3430 public void SetVehicleRotationParam(int param, Quaternion rotation)
3137 { 3431 {
3138 if (PhysActor != null) 3432 if (m_vehicle == null)
3433 return;
3434
3435 m_vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation);
3436
3437 if (_parentID == 0 && PhysActor != null)
3139 { 3438 {
3140 PhysActor.VehicleRotationParam(param, rotation); 3439 PhysActor.VehicleRotationParam(param, rotation);
3141 } 3440 }
@@ -3322,13 +3621,6 @@ namespace OpenSim.Region.Framework.Scenes
3322 hasProfileCut = hasDimple; // is it the same thing? 3621 hasProfileCut = hasDimple; // is it the same thing?
3323 } 3622 }
3324 3623
3325 public void SetVehicleFlags(int param, bool remove)
3326 {
3327 if (PhysActor != null)
3328 {
3329 PhysActor.VehicleFlags(param, remove);
3330 }
3331 }
3332 3624
3333 public void SetGroup(UUID groupID, IClientAPI client) 3625 public void SetGroup(UUID groupID, IClientAPI client)
3334 { 3626 {
@@ -3431,68 +3723,18 @@ namespace OpenSim.Region.Framework.Scenes
3431 //ParentGroup.ScheduleGroupForFullUpdate(); 3723 //ParentGroup.ScheduleGroupForFullUpdate();
3432 } 3724 }
3433 3725
3434 public void StoreUndoState() 3726 public void StoreUndoState(ObjectChangeType change)
3435 { 3727 {
3436 StoreUndoState(false); 3728 if (m_UndoRedo == null)
3437 } 3729 m_UndoRedo = new UndoRedoState(5);
3438 3730
3439 public void StoreUndoState(bool forGroup) 3731 lock (m_UndoRedo)
3440 {
3441 if (!Undoing)
3442 { 3732 {
3443 if (!IgnoreUndoUpdate) 3733 if (!Undoing && !IgnoreUndoUpdate && ParentGroup != null) // just to read better - undo is in progress, or suspended
3444 { 3734 {
3445 if (ParentGroup != null) 3735 m_UndoRedo.StoreUndo(this, change);
3446 {
3447 lock (m_undo)
3448 {
3449 if (m_undo.Count > 0)
3450 {
3451 UndoState last = m_undo.Peek();
3452 if (last != null)
3453 {
3454 // TODO: May need to fix for group comparison
3455 if (last.Compare(this))
3456 {
3457 // m_log.DebugFormat(
3458 // "[SCENE OBJECT PART]: Not storing undo for {0} {1} since current state is same as last undo state, initial stack size {2}",
3459 // Name, LocalId, m_undo.Count);
3460
3461 return;
3462 }
3463 }
3464 }
3465
3466 // m_log.DebugFormat(
3467 // "[SCENE OBJECT PART]: Storing undo state for {0} {1}, forGroup {2}, initial stack size {3}",
3468 // Name, LocalId, forGroup, m_undo.Count);
3469
3470 if (ParentGroup.GetSceneMaxUndo() > 0)
3471 {
3472 UndoState nUndo = new UndoState(this, forGroup);
3473
3474 m_undo.Push(nUndo);
3475
3476 if (m_redo.Count > 0)
3477 m_redo.Clear();
3478
3479 // m_log.DebugFormat(
3480 // "[SCENE OBJECT PART]: Stored undo state for {0} {1}, forGroup {2}, stack size now {3}",
3481 // Name, LocalId, forGroup, m_undo.Count);
3482 }
3483 }
3484 }
3485 } 3736 }
3486// else
3487// {
3488// m_log.DebugFormat("[SCENE OBJECT PART]: Ignoring undo store for {0} {1}", Name, LocalId);
3489// }
3490 } 3737 }
3491// else
3492// {
3493// m_log.DebugFormat(
3494// "[SCENE OBJECT PART]: Ignoring undo store for {0} {1} since already undoing", Name, LocalId);
3495// }
3496 } 3738 }
3497 3739
3498 /// <summary> 3740 /// <summary>
@@ -3502,84 +3744,46 @@ namespace OpenSim.Region.Framework.Scenes
3502 { 3744 {
3503 get 3745 get
3504 { 3746 {
3505 lock (m_undo) 3747 if (m_UndoRedo == null)
3506 return m_undo.Count; 3748 return 0;
3749 return m_UndoRedo.Count;
3507 } 3750 }
3508 } 3751 }
3509 3752
3510 public void Undo() 3753 public void Undo()
3511 { 3754 {
3512 lock (m_undo) 3755 if (m_UndoRedo == null || Undoing || ParentGroup == null)
3513 { 3756 return;
3514// m_log.DebugFormat(
3515// "[SCENE OBJECT PART]: Handling undo request for {0} {1}, stack size {2}",
3516// Name, LocalId, m_undo.Count);
3517
3518 if (m_undo.Count > 0)
3519 {
3520 UndoState goback = m_undo.Pop();
3521
3522 if (goback != null)
3523 {
3524 UndoState nUndo = null;
3525
3526 if (ParentGroup.GetSceneMaxUndo() > 0)
3527 {
3528 nUndo = new UndoState(this, goback.ForGroup);
3529 }
3530
3531 goback.PlaybackState(this);
3532
3533 if (nUndo != null)
3534 m_redo.Push(nUndo);
3535 }
3536 }
3537 3757
3538// m_log.DebugFormat( 3758 lock (m_UndoRedo)
3539// "[SCENE OBJECT PART]: Handled undo request for {0} {1}, stack size now {2}", 3759 {
3540// Name, LocalId, m_undo.Count); 3760 Undoing = true;
3761 m_UndoRedo.Undo(this);
3762 Undoing = false;
3541 } 3763 }
3542 } 3764 }
3543 3765
3544 public void Redo() 3766 public void Redo()
3545 { 3767 {
3546 lock (m_undo) 3768 if (m_UndoRedo == null || Undoing || ParentGroup == null)
3547 { 3769 return;
3548// m_log.DebugFormat(
3549// "[SCENE OBJECT PART]: Handling redo request for {0} {1}, stack size {2}",
3550// Name, LocalId, m_redo.Count);
3551
3552 if (m_redo.Count > 0)
3553 {
3554 UndoState gofwd = m_redo.Pop();
3555
3556 if (gofwd != null)
3557 {
3558 if (ParentGroup.GetSceneMaxUndo() > 0)
3559 {
3560 UndoState nUndo = new UndoState(this, gofwd.ForGroup);
3561
3562 m_undo.Push(nUndo);
3563 }
3564
3565 gofwd.PlayfwdState(this);
3566 }
3567 3770
3568// m_log.DebugFormat( 3771 lock (m_UndoRedo)
3569// "[SCENE OBJECT PART]: Handled redo request for {0} {1}, stack size now {2}", 3772 {
3570// Name, LocalId, m_redo.Count); 3773 Undoing = true;
3571 } 3774 m_UndoRedo.Redo(this);
3775 Undoing = false;
3572 } 3776 }
3573 } 3777 }
3574 3778
3575 public void ClearUndoState() 3779 public void ClearUndoState()
3576 { 3780 {
3577// m_log.DebugFormat("[SCENE OBJECT PART]: Clearing undo and redo stacks in {0} {1}", Name, LocalId); 3781 if (m_UndoRedo == null || Undoing)
3782 return;
3578 3783
3579 lock (m_undo) 3784 lock (m_UndoRedo)
3580 { 3785 {
3581 m_undo.Clear(); 3786 m_UndoRedo.Clear();
3582 m_redo.Clear();
3583 } 3787 }
3584 } 3788 }
3585 3789
@@ -4209,6 +4413,41 @@ namespace OpenSim.Region.Framework.Scenes
4209 } 4413 }
4210 } 4414 }
4211 4415
4416
4417 public void UpdateExtraPhysics(ExtraPhysicsData physdata)
4418 {
4419 if (physdata.PhysShapeType == PhysShapeType.invalid || ParentGroup == null)
4420 return;
4421
4422 if (PhysicsShapeType != (byte)physdata.PhysShapeType)
4423 {
4424 PhysicsShapeType = (byte)physdata.PhysShapeType;
4425
4426 if (PhysicsShapeType == (byte)PhysShapeType.none)
4427 {
4428 if (PhysActor != null)
4429 {
4430 Velocity = new Vector3(0, 0, 0);
4431 Acceleration = new Vector3(0, 0, 0);
4432 if (ParentGroup.RootPart == this)
4433 AngularVelocity = new Vector3(0, 0, 0);
4434 ParentGroup.Scene.RemovePhysicalPrim(1);
4435 RemoveFromPhysics();
4436 }
4437 }
4438 else if (PhysActor == null)
4439 ApplyPhysics((uint)Flags, VolumeDetectActive, false);
4440 }
4441
4442 if(Density != physdata.Density)
4443 Density = physdata.Density;
4444 if(GravityModifier != physdata.GravitationModifier)
4445 GravityModifier = physdata.GravitationModifier;
4446 if(Friction != physdata.Friction)
4447 Friction = physdata.Friction;
4448 if(Bounciness != physdata.Bounce)
4449 Bounciness = physdata.Bounce;
4450 }
4212 /// <summary> 4451 /// <summary>
4213 /// Update the flags on this prim. This covers properties such as phantom, physics and temporary. 4452 /// Update the flags on this prim. This covers properties such as phantom, physics and temporary.
4214 /// </summary> 4453 /// </summary>
@@ -4216,7 +4455,8 @@ namespace OpenSim.Region.Framework.Scenes
4216 /// <param name="SetTemporary"></param> 4455 /// <param name="SetTemporary"></param>
4217 /// <param name="SetPhantom"></param> 4456 /// <param name="SetPhantom"></param>
4218 /// <param name="SetVD"></param> 4457 /// <param name="SetVD"></param>
4219 public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD) 4458// public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD)
4459 public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD, bool building)
4220 { 4460 {
4221 bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0); 4461 bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0);
4222 bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0); 4462 bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0);
@@ -4226,41 +4466,58 @@ namespace OpenSim.Region.Framework.Scenes
4226 if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD)) 4466 if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD))
4227 return; 4467 return;
4228 4468
4469 // do this first
4470 if (building && PhysActor != null && PhysActor.Building != building)
4471 PhysActor.Building = building;
4472
4229 // Special cases for VD. VD can only be called from a script 4473 // Special cases for VD. VD can only be called from a script
4230 // and can't be combined with changes to other states. So we can rely 4474 // and can't be combined with changes to other states. So we can rely
4231 // that... 4475 // that...
4232 // ... if VD is changed, all others are not. 4476 // ... if VD is changed, all others are not.
4233 // ... if one of the others is changed, VD is not. 4477 // ... if one of the others is changed, VD is not.
4478
4479/*
4234 if (SetVD) // VD is active, special logic applies 4480 if (SetVD) // VD is active, special logic applies
4235 {
4236 // State machine logic for VolumeDetect
4237 // More logic below
4238 bool phanReset = (SetPhantom != wasPhantom) && !SetPhantom;
4239 4481
4240 if (phanReset) // Phantom changes from on to off switch VD off too 4482 volume detection is now independent of phantom in sl
4241 { 4483
4242 SetVD = false; // Switch it of for the course of this routine 4484 {
4243 VolumeDetectActive = false; // and also permanently 4485 // State machine logic for VolumeDetect
4244 if (PhysActor != null) 4486 // More logic below
4245 PhysActor.SetVolumeDetect(0); // Let physics know about it too 4487
4246 } 4488
4247 else 4489 bool phanReset = (SetPhantom != wasPhantom) && !SetPhantom;
4248 { 4490
4249 // If volumedetect is active we don't want phantom to be applied. 4491 if (phanReset) // Phantom changes from on to off switch VD off too
4250 // If this is a new call to VD out of the state "phantom" 4492 {
4251 // this will also cause the prim to be visible to physics 4493 SetVD = false; // Switch it of for the course of this routine
4494 VolumeDetectActive = false; // and also permanently
4495 if (PhysActor != null)
4496 PhysActor.SetVolumeDetect(0); // Let physics know about it too
4497 }
4498 else
4499 {
4500 // If volumedetect is active we don't want phantom to be applied.
4501 // If this is a new call to VD out of the state "phantom"
4502 // this will also cause the prim to be visible to physics
4252 SetPhantom = false; 4503 SetPhantom = false;
4253 } 4504 }
4505 }
4506 else if (wasVD)
4507 {
4508 // Correspondingly, if VD is turned off, also turn off phantom
4509 SetPhantom = false;
4254 } 4510 }
4255 4511
4256 if (UsePhysics && IsJoint()) 4512 if (UsePhysics && IsJoint())
4257 { 4513 {
4258 SetPhantom = true; 4514 SetPhantom = true;
4259 } 4515 }
4260 4516*/
4261 if (UsePhysics) 4517 if (UsePhysics)
4262 { 4518 {
4263 AddFlag(PrimFlags.Physics); 4519 AddFlag(PrimFlags.Physics);
4520/*
4264 if (!wasUsingPhysics) 4521 if (!wasUsingPhysics)
4265 { 4522 {
4266 DoPhysicsPropertyUpdate(UsePhysics, false); 4523 DoPhysicsPropertyUpdate(UsePhysics, false);
@@ -4273,78 +4530,99 @@ namespace OpenSim.Region.Framework.Scenes
4273 } 4530 }
4274 } 4531 }
4275 } 4532 }
4533 */
4276 } 4534 }
4277 else 4535 else
4278 { 4536 {
4279 RemFlag(PrimFlags.Physics); 4537 RemFlag(PrimFlags.Physics);
4538/*
4280 if (wasUsingPhysics) 4539 if (wasUsingPhysics)
4281 { 4540 {
4282 DoPhysicsPropertyUpdate(UsePhysics, false); 4541 DoPhysicsPropertyUpdate(UsePhysics, false);
4283 } 4542 }
4284 } 4543*/
4544 }
4545
4546 if (SetPhantom)
4547 AddFlag(PrimFlags.Phantom);
4548 else
4549 RemFlag(PrimFlags.Phantom);
4285 4550
4286 if (SetPhantom 4551 if ((SetPhantom && !UsePhysics) || ParentGroup.IsAttachment || PhysicsShapeType == (byte)PhysShapeType.none
4287 || ParentGroup.IsAttachment
4288 || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints 4552 || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints
4289 { 4553 {
4290 AddFlag(PrimFlags.Phantom); 4554// AddFlag(PrimFlags.Phantom);
4555
4556 Velocity = new Vector3(0, 0, 0);
4557 Acceleration = new Vector3(0, 0, 0);
4558 if (ParentGroup.RootPart == this)
4559 AngularVelocity = new Vector3(0, 0, 0);
4291 4560
4292 if (PhysActor != null) 4561 if (PhysActor != null)
4562 {
4563 ParentGroup.Scene.RemovePhysicalPrim(1);
4293 RemoveFromPhysics(); 4564 RemoveFromPhysics();
4565 }
4294 } 4566 }
4295 else // Not phantom 4567 else
4296 { 4568 {
4297 RemFlag(PrimFlags.Phantom);
4298
4299 if (ParentGroup.Scene == null) 4569 if (ParentGroup.Scene == null)
4300 return; 4570 return;
4301 4571
4302 if (ParentGroup.Scene.CollidablePrims && PhysActor == null) 4572 if (ParentGroup.Scene.CollidablePrims)
4303 { 4573 {
4304 // It's not phantom anymore. So make sure the physics engine get's knowledge of it 4574 if (PhysActor == null)
4305 PhysActor = ParentGroup.Scene.PhysicsScene.AddPrimShape(
4306 string.Format("{0}/{1}", Name, UUID),
4307 Shape,
4308 AbsolutePosition,
4309 Scale,
4310 RotationOffset,
4311 UsePhysics,
4312 m_localId);
4313
4314 PhysActor.SetMaterial(Material);
4315 DoPhysicsPropertyUpdate(UsePhysics, true);
4316
4317 if (!ParentGroup.IsDeleted)
4318 { 4575 {
4319 if (LocalId == ParentGroup.RootPart.LocalId) 4576 PhysActor = ParentGroup.Scene.PhysicsScene.AddPrimShape(
4577 string.Format("{0}/{1}", Name, UUID),
4578 Shape,
4579 AbsolutePosition,
4580 Scale,
4581 GetWorldRotation(), //physics wants world rotation like all other functions send
4582 UsePhysics,
4583 SetPhantom,
4584 m_localId);
4585
4586 PhysActor.SetMaterial(Material);
4587
4588 // if root part apply vehicle
4589 if (m_vehicle != null && LocalId == ParentGroup.RootPart.LocalId)
4590 m_vehicle.SetVehicle(PhysActor);
4591
4592 DoPhysicsPropertyUpdate(UsePhysics, true);
4593
4594 if (!ParentGroup.IsDeleted)
4320 { 4595 {
4321 ParentGroup.CheckSculptAndLoad(); 4596 if (LocalId == ParentGroup.RootPart.LocalId)
4597 {
4598 ParentGroup.CheckSculptAndLoad();
4599 }
4322 } 4600 }
4323 }
4324 4601
4325 if ( 4602 if (
4326 ((AggregateScriptEvents & scriptEvents.collision) != 0) || 4603 ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
4327 ((AggregateScriptEvents & scriptEvents.collision_end) != 0) || 4604 ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4328 ((AggregateScriptEvents & scriptEvents.collision_start) != 0) || 4605 ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4329 ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) || 4606 ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4330 ((AggregateScriptEvents & scriptEvents.land_collision) != 0) || 4607 ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4331 ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) || 4608 ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4332 (CollisionSound != UUID.Zero) 4609 (CollisionSound != UUID.Zero)
4333 ) 4610 )
4334 { 4611 {
4335 PhysActor.OnCollisionUpdate += PhysicsCollision; 4612 PhysActor.OnCollisionUpdate += PhysicsCollision;
4336 PhysActor.SubscribeEvents(1000); 4613 PhysActor.SubscribeEvents(1000);
4614 }
4337 } 4615 }
4338 } 4616 else // it already has a physical representation
4339 else // it already has a physical representation
4340 {
4341 DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status. If it's phantom this will remove the prim
4342
4343 if (!ParentGroup.IsDeleted)
4344 { 4617 {
4345 if (LocalId == ParentGroup.RootPart.LocalId) 4618 DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status.
4619
4620 if (!ParentGroup.IsDeleted)
4346 { 4621 {
4347 ParentGroup.CheckSculptAndLoad(); 4622 if (LocalId == ParentGroup.RootPart.LocalId)
4623 {
4624 ParentGroup.CheckSculptAndLoad();
4625 }
4348 } 4626 }
4349 } 4627 }
4350 } 4628 }
@@ -4360,7 +4638,7 @@ namespace OpenSim.Region.Framework.Scenes
4360 if (this.PhysActor != null) 4638 if (this.PhysActor != null)
4361 { 4639 {
4362 PhysActor.SetVolumeDetect(1); 4640 PhysActor.SetVolumeDetect(1);
4363 AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active 4641// AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active
4364 this.VolumeDetectActive = true; 4642 this.VolumeDetectActive = true;
4365 } 4643 }
4366 } 4644 }
@@ -4368,8 +4646,7 @@ namespace OpenSim.Region.Framework.Scenes
4368 { 4646 {
4369 // Remove VolumeDetect in any case. Note, it's safe to call SetVolumeDetect as often as you like 4647 // Remove VolumeDetect in any case. Note, it's safe to call SetVolumeDetect as often as you like
4370 // (mumbles, well, at least if you have infinte CPU powers :-)) 4648 // (mumbles, well, at least if you have infinte CPU powers :-))
4371 PhysicsActor pa = this.PhysActor; 4649 if (this.PhysActor != null)
4372 if (pa != null)
4373 { 4650 {
4374 PhysActor.SetVolumeDetect(0); 4651 PhysActor.SetVolumeDetect(0);
4375 } 4652 }
@@ -4387,6 +4664,9 @@ namespace OpenSim.Region.Framework.Scenes
4387 } 4664 }
4388 // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString()); 4665 // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString());
4389 4666
4667 // and last in case we have a new actor and not building
4668 if (PhysActor != null && PhysActor.Building != building)
4669 PhysActor.Building = building;
4390 if (ParentGroup != null) 4670 if (ParentGroup != null)
4391 { 4671 {
4392 ParentGroup.HasGroupChanged = true; 4672 ParentGroup.HasGroupChanged = true;
@@ -4750,5 +5030,17 @@ namespace OpenSim.Region.Framework.Scenes
4750 Color color = Color; 5030 Color color = Color;
4751 return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A)); 5031 return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A));
4752 } 5032 }
5033
5034 public void ResetOwnerChangeFlag()
5035 {
5036 List<UUID> inv = Inventory.GetInventoryList();
5037
5038 foreach (UUID itemID in inv)
5039 {
5040 TaskInventoryItem item = Inventory.GetInventoryItem(itemID);
5041 item.OwnerChanged = false;
5042 Inventory.UpdateInventoryItem(item, false, false);
5043 }
5044 }
4753 } 5045 }
4754} 5046}