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.cs1091
1 files changed, 767 insertions, 324 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index 439b718..85d2bee 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
@@ -950,7 +986,11 @@ namespace OpenSim.Region.Framework.Scenes
950 public PrimitiveBaseShape Shape 986 public PrimitiveBaseShape Shape
951 { 987 {
952 get { return m_shape; } 988 get { return m_shape; }
953 set { m_shape = value;} 989 set
990 {
991 m_shape = value;
992 m_physicsShapeType = DefaultPhysicsShapeType();
993 }
954 } 994 }
955 995
956 /// <summary> 996 /// <summary>
@@ -963,7 +1003,7 @@ namespace OpenSim.Region.Framework.Scenes
963 { 1003 {
964 if (m_shape != null) 1004 if (m_shape != null)
965 { 1005 {
966 StoreUndoState(); 1006// StoreUndoState();
967 1007
968 m_shape.Scale = value; 1008 m_shape.Scale = value;
969 1009
@@ -990,6 +1030,7 @@ namespace OpenSim.Region.Framework.Scenes
990 } 1030 }
991 1031
992 public UpdateRequired UpdateFlag { get; set; } 1032 public UpdateRequired UpdateFlag { get; set; }
1033 public bool UpdatePhysRequired { get; set; }
993 1034
994 /// <summary> 1035 /// <summary>
995 /// Used for media on a prim. 1036 /// Used for media on a prim.
@@ -1030,10 +1071,7 @@ namespace OpenSim.Region.Framework.Scenes
1030 { 1071 {
1031 get 1072 get
1032 { 1073 {
1033 if (ParentGroup.IsAttachment) 1074 return GroupPosition + (m_offsetPosition * ParentGroup.RootPart.RotationOffset);
1034 return GroupPosition;
1035
1036 return m_offsetPosition + m_groupPosition;
1037 } 1075 }
1038 } 1076 }
1039 1077
@@ -1203,6 +1241,13 @@ namespace OpenSim.Region.Framework.Scenes
1203 _flags = value; 1241 _flags = value;
1204 } 1242 }
1205 } 1243 }
1244
1245 [XmlIgnore]
1246 public bool IsOccupied // KF If an av is sittingon this prim
1247 {
1248 get { return m_occupied; }
1249 set { m_occupied = value; }
1250 }
1206 1251
1207 /// <summary> 1252 /// <summary>
1208 /// ID of the avatar that is sat on us. If there is no such avatar then is UUID.Zero 1253 /// ID of the avatar that is sat on us. If there is no such avatar then is UUID.Zero
@@ -1262,6 +1307,288 @@ namespace OpenSim.Region.Framework.Scenes
1262 set { m_collisionSoundVolume = value; } 1307 set { m_collisionSoundVolume = value; }
1263 } 1308 }
1264 1309
1310 public float Buoyancy
1311 {
1312 get
1313 {
1314 if (ParentGroup.RootPart == this)
1315 return m_buoyancy;
1316
1317 return ParentGroup.RootPart.Buoyancy;
1318 }
1319 set
1320 {
1321 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1322 {
1323 ParentGroup.RootPart.Buoyancy = value;
1324 return;
1325 }
1326 m_buoyancy = value;
1327 if (PhysActor != null)
1328 PhysActor.Buoyancy = value;
1329 }
1330 }
1331
1332 public Vector3 Force
1333 {
1334 get
1335 {
1336 if (ParentGroup.RootPart == this)
1337 return m_force;
1338
1339 return ParentGroup.RootPart.Force;
1340 }
1341
1342 set
1343 {
1344 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1345 {
1346 ParentGroup.RootPart.Force = value;
1347 return;
1348 }
1349 m_force = value;
1350 if (PhysActor != null)
1351 PhysActor.Force = value;
1352 }
1353 }
1354
1355 public Vector3 Torque
1356 {
1357 get
1358 {
1359 if (ParentGroup.RootPart == this)
1360 return m_torque;
1361
1362 return ParentGroup.RootPart.Torque;
1363 }
1364
1365 set
1366 {
1367 if (ParentGroup != null && ParentGroup.RootPart != null && ParentGroup.RootPart != this)
1368 {
1369 ParentGroup.RootPart.Torque = value;
1370 return;
1371 }
1372 m_torque = value;
1373 if (PhysActor != null)
1374 PhysActor.Torque = value;
1375 }
1376 }
1377
1378 public byte Material
1379 {
1380 get { return (byte)m_material; }
1381 set
1382 {
1383 if (value >= 0 && value <= (byte)SOPMaterialData.MaxMaterial)
1384 {
1385 bool update = false;
1386
1387 if (m_material != (Material)value)
1388 {
1389 update = true;
1390 m_material = (Material)value;
1391 }
1392
1393 if (m_friction != SOPMaterialData.friction(m_material))
1394 {
1395 update = true;
1396 m_friction = SOPMaterialData.friction(m_material);
1397 }
1398
1399 if (m_bounce != SOPMaterialData.bounce(m_material))
1400 {
1401 update = true;
1402 m_bounce = SOPMaterialData.bounce(m_material);
1403 }
1404
1405 if (update)
1406 {
1407 if (PhysActor != null)
1408 {
1409 PhysActor.SetMaterial((int)value);
1410 }
1411 if(ParentGroup != null)
1412 ParentGroup.HasGroupChanged = true;
1413 ScheduleFullUpdateIfNone();
1414 UpdatePhysRequired = true;
1415 }
1416 }
1417 }
1418 }
1419
1420 // not a propriety to move to methods place later
1421 private bool HasMesh()
1422 {
1423 if (Shape != null && (Shape.SculptType == (byte)SculptType.Mesh))
1424 return true;
1425 return false;
1426 }
1427
1428 // not a propriety to move to methods place later
1429 public byte DefaultPhysicsShapeType()
1430 {
1431 byte type;
1432
1433 if (Shape != null && (Shape.SculptType == (byte)SculptType.Mesh))
1434 type = (byte)PhysShapeType.convex;
1435 else
1436 type = (byte)PhysShapeType.prim;
1437
1438 return type;
1439 }
1440
1441 [XmlIgnore]
1442 public bool UsesComplexCost
1443 {
1444 get
1445 {
1446 byte pst = PhysicsShapeType;
1447 if(pst == (byte) PhysShapeType.none || pst == (byte) PhysShapeType.convex || HasMesh())
1448 return true;
1449 return false;
1450 }
1451 }
1452
1453 [XmlIgnore]
1454 public float PhysicsCost
1455 {
1456 get
1457 {
1458 if(PhysicsShapeType == (byte)PhysShapeType.none)
1459 return 0;
1460
1461 float cost = 0.1f;
1462 if (PhysActor != null)
1463// cost += PhysActor.Cost;
1464
1465 if ((Flags & PrimFlags.Physics) != 0)
1466 cost *= (1.0f + 0.01333f * Scale.LengthSquared()); // 0.01333 == 0.04/3
1467 return cost;
1468 }
1469 }
1470
1471 [XmlIgnore]
1472 public float StreamingCost
1473 {
1474 get
1475 {
1476
1477
1478 return 0.1f;
1479 }
1480 }
1481
1482 [XmlIgnore]
1483 public float SimulationCost
1484 {
1485 get
1486 {
1487 // ignoring scripts. Don't like considering them for this
1488 if((Flags & PrimFlags.Physics) != 0)
1489 return 1.0f;
1490
1491 return 0.5f;
1492 }
1493 }
1494
1495 public byte PhysicsShapeType
1496 {
1497 get { return m_physicsShapeType; }
1498 set
1499 {
1500 if (value >= 0 && value <= (byte)PhysShapeType.convex)
1501 {
1502 if (value == (byte)PhysShapeType.none && ParentGroup != null && ParentGroup.RootPart == this)
1503 m_physicsShapeType = DefaultPhysicsShapeType();
1504 else
1505 m_physicsShapeType = value;
1506 }
1507 else
1508 m_physicsShapeType = DefaultPhysicsShapeType();
1509
1510 if (ParentGroup != null)
1511 ParentGroup.HasGroupChanged = true;
1512
1513 if(m_physicsShapeType != value)
1514 UpdatePhysRequired = true;
1515 }
1516 }
1517
1518 public float Density // in kg/m^3
1519 {
1520 get { return m_density; }
1521 set
1522 {
1523 if (value >=1 && value <= 22587.0)
1524 {
1525 m_density = value;
1526 UpdatePhysRequired = true;
1527 }
1528
1529 ScheduleFullUpdateIfNone();
1530
1531 if (ParentGroup != null)
1532 ParentGroup.HasGroupChanged = true;
1533 }
1534 }
1535
1536 public float GravityModifier
1537 {
1538 get { return m_gravitymod; }
1539 set
1540 {
1541 if( value >= -1 && value <=28.0f)
1542 {
1543 m_gravitymod = value;
1544 UpdatePhysRequired = true;
1545 }
1546
1547 ScheduleFullUpdateIfNone();
1548
1549 if (ParentGroup != null)
1550 ParentGroup.HasGroupChanged = true;
1551
1552 }
1553 }
1554
1555 public float Friction
1556 {
1557 get { return m_friction; }
1558 set
1559 {
1560 if (value >= 0 && value <= 255.0f)
1561 {
1562 m_friction = value;
1563 UpdatePhysRequired = true;
1564 }
1565
1566 ScheduleFullUpdateIfNone();
1567
1568 if (ParentGroup != null)
1569 ParentGroup.HasGroupChanged = true;
1570 }
1571 }
1572
1573 public float Bounciness
1574 {
1575 get { return m_bounce; }
1576 set
1577 {
1578 if (value >= 0 && value <= 1.0f)
1579 {
1580 m_bounce = value;
1581 UpdatePhysRequired = true;
1582 }
1583
1584 ScheduleFullUpdateIfNone();
1585
1586 if (ParentGroup != null)
1587 ParentGroup.HasGroupChanged = true;
1588 }
1589 }
1590
1591
1265 #endregion Public Properties with only Get 1592 #endregion Public Properties with only Get
1266 1593
1267 private uint ApplyMask(uint val, bool set, uint mask) 1594 private uint ApplyMask(uint val, bool set, uint mask)
@@ -1437,20 +1764,24 @@ namespace OpenSim.Region.Framework.Scenes
1437 /// </summary> 1764 /// </summary>
1438 /// <param name="impulsei">Vector force</param> 1765 /// <param name="impulsei">Vector force</param>
1439 /// <param name="localGlobalTF">true for the local frame, false for the global frame</param> 1766 /// <param name="localGlobalTF">true for the local frame, false for the global frame</param>
1440 public void SetAngularImpulse(Vector3 impulsei, bool localGlobalTF) 1767
1768 // this is actualy Set Torque.. keeping naming so not to edit lslapi also
1769 public void SetAngularImpulse(Vector3 torquei, bool localGlobalTF)
1441 { 1770 {
1442 Vector3 impulse = impulsei; 1771 Vector3 torque = torquei;
1443 1772
1444 if (localGlobalTF) 1773 if (localGlobalTF)
1445 { 1774 {
1775/*
1446 Quaternion grot = GetWorldRotation(); 1776 Quaternion grot = GetWorldRotation();
1447 Quaternion AXgrot = grot; 1777 Quaternion AXgrot = grot;
1448 Vector3 AXimpulsei = impulsei; 1778 Vector3 AXimpulsei = impulsei;
1449 Vector3 newimpulse = AXimpulsei * AXgrot; 1779 Vector3 newimpulse = AXimpulsei * AXgrot;
1450 impulse = newimpulse; 1780 */
1781 torque *= GetWorldRotation();
1451 } 1782 }
1452 1783
1453 ParentGroup.setAngularImpulse(impulse); 1784 Torque = torque;
1454 } 1785 }
1455 1786
1456 /// <summary> 1787 /// <summary>
@@ -1458,18 +1789,19 @@ namespace OpenSim.Region.Framework.Scenes
1458 /// </summary> 1789 /// </summary>
1459 /// <param name="rootObjectFlags"></param> 1790 /// <param name="rootObjectFlags"></param>
1460 /// <param name="VolumeDetectActive"></param> 1791 /// <param name="VolumeDetectActive"></param>
1461 public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive) 1792
1793 public void ApplyPhysics(uint rootObjectFlags, bool VolumeDetectActive, bool building)
1462 { 1794 {
1463 if (!ParentGroup.Scene.CollidablePrims) 1795 if (!ParentGroup.Scene.CollidablePrims)
1464 return; 1796 return;
1465 1797
1466// m_log.DebugFormat( 1798 if (PhysicsShapeType == (byte)PhysShapeType.none)
1467// "[SCENE OBJECT PART]: Applying physics to {0} {1}, m_physicalPrim {2}", 1799 return;
1468// Name, LocalId, UUID, m_physicalPrim);
1469 1800
1470 bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0; 1801 bool isPhysical = (rootObjectFlags & (uint) PrimFlags.Physics) != 0;
1471 bool isPhantom = (rootObjectFlags & (uint) PrimFlags.Phantom) != 0; 1802 bool isPhantom = (rootObjectFlags & (uint) PrimFlags.Phantom) != 0;
1472 1803
1804
1473 if (IsJoint()) 1805 if (IsJoint())
1474 { 1806 {
1475 DoPhysicsPropertyUpdate(isPhysical, true); 1807 DoPhysicsPropertyUpdate(isPhysical, true);
@@ -1477,16 +1809,19 @@ namespace OpenSim.Region.Framework.Scenes
1477 else 1809 else
1478 { 1810 {
1479 // Special case for VolumeDetection: If VolumeDetection is set, the phantom flag is locally ignored 1811 // Special case for VolumeDetection: If VolumeDetection is set, the phantom flag is locally ignored
1480 if (VolumeDetectActive) 1812// if (VolumeDetectActive)
1481 isPhantom = false; 1813// isPhantom = false;
1482 1814
1483 // Added clarification.. since A rigid body is an object that you can kick around, etc. 1815 // Added clarification.. since A rigid body is an object that you can kick around, etc.
1484 bool RigidBody = isPhysical && !isPhantom; 1816// bool RigidBody = isPhysical && !isPhantom;
1485 1817
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 1818 // 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 1819 // or flexible
1488 if (!isPhantom && !ParentGroup.IsAttachment && !(Shape.PathCurve == (byte)Extrusion.Flexible)) 1820 // if (!isPhantom && !ParentGroup.IsAttachment && !(Shape.PathCurve == (byte)Extrusion.Flexible))
1821 if ((!isPhantom || isPhysical || VolumeDetectActive) && !ParentGroup.IsAttachment && !(Shape.PathCurve == (byte)Extrusion.Flexible))
1489 { 1822 {
1823 Vector3 velocity = Velocity;
1824 Vector3 rotationalVelocity = AngularVelocity;
1490 try 1825 try
1491 { 1826 {
1492 PhysActor = ParentGroup.Scene.PhysicsScene.AddPrimShape( 1827 PhysActor = ParentGroup.Scene.PhysicsScene.AddPrimShape(
@@ -1494,8 +1829,9 @@ namespace OpenSim.Region.Framework.Scenes
1494 Shape, 1829 Shape,
1495 AbsolutePosition, 1830 AbsolutePosition,
1496 Scale, 1831 Scale,
1497 RotationOffset, 1832 GetWorldRotation(),
1498 RigidBody, 1833 isPhysical,
1834 isPhantom,
1499 m_localId); 1835 m_localId);
1500 } 1836 }
1501 catch 1837 catch
@@ -1509,8 +1845,30 @@ namespace OpenSim.Region.Framework.Scenes
1509 { 1845 {
1510 PhysActor.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info 1846 PhysActor.SOPName = this.Name; // save object into the PhysActor so ODE internals know the joint/body info
1511 PhysActor.SetMaterial(Material); 1847 PhysActor.SetMaterial(Material);
1512 DoPhysicsPropertyUpdate(RigidBody, true); 1848
1513 PhysActor.SetVolumeDetect(VolumeDetectActive ? 1 : 0); 1849 // if root part apply vehicle
1850 if (m_vehicle != null && LocalId == ParentGroup.RootPart.LocalId)
1851 m_vehicle.SetVehicle(PhysActor);
1852
1853 DoPhysicsPropertyUpdate(isPhysical, true);
1854 if(VolumeDetectActive) // change if not the default only
1855 PhysActor.SetVolumeDetect(1);
1856
1857 if (!building)
1858 PhysActor.Building = false;
1859
1860 Velocity = velocity;
1861 AngularVelocity = rotationalVelocity;
1862 PhysActor.Velocity = velocity;
1863 PhysActor.RotationalVelocity = rotationalVelocity;
1864
1865 // if not vehicle and root part apply force and torque
1866 if ((m_vehicle == null || m_vehicle.Type == Vehicle.TYPE_NONE)
1867 && LocalId == ParentGroup.RootPart.LocalId)
1868 {
1869 PhysActor.Force = Force;
1870 PhysActor.Torque = Torque;
1871 }
1514 } 1872 }
1515 } 1873 }
1516 } 1874 }
@@ -1564,6 +1922,11 @@ namespace OpenSim.Region.Framework.Scenes
1564 dupe.Category = Category; 1922 dupe.Category = Category;
1565 dupe.m_rezzed = m_rezzed; 1923 dupe.m_rezzed = m_rezzed;
1566 1924
1925 dupe.m_UndoRedo = null;
1926
1927 dupe.IgnoreUndoUpdate = false;
1928 dupe.Undoing = false;
1929
1567 dupe.m_inventory = new SceneObjectPartInventory(dupe); 1930 dupe.m_inventory = new SceneObjectPartInventory(dupe);
1568 dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone(); 1931 dupe.m_inventory.Items = (TaskInventoryDictionary)m_inventory.Items.Clone();
1569 1932
@@ -1579,6 +1942,7 @@ namespace OpenSim.Region.Framework.Scenes
1579 1942
1580 // Move afterwards ResetIDs as it clears the localID 1943 // Move afterwards ResetIDs as it clears the localID
1581 dupe.LocalId = localID; 1944 dupe.LocalId = localID;
1945
1582 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated. 1946 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
1583 dupe.LastOwnerID = OwnerID; 1947 dupe.LastOwnerID = OwnerID;
1584 1948
@@ -1598,6 +1962,9 @@ namespace OpenSim.Region.Framework.Scenes
1598 dupe.DoPhysicsPropertyUpdate(UsePhysics, true); 1962 dupe.DoPhysicsPropertyUpdate(UsePhysics, true);
1599 } 1963 }
1600 1964
1965 if (dupe.PhysActor != null)
1966 dupe.PhysActor.LocalID = localID;
1967
1601 ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed); 1968 ParentGroup.Scene.EventManager.TriggerOnSceneObjectPartCopy(dupe, this, userExposed);
1602 1969
1603// m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID); 1970// m_log.DebugFormat("[SCENE OBJECT PART]: Clone of {0} {1} finished", Name, UUID);
@@ -1735,63 +2102,63 @@ namespace OpenSim.Region.Framework.Scenes
1735 { 2102 {
1736 if (UsePhysics != PhysActor.IsPhysical || isNew) 2103 if (UsePhysics != PhysActor.IsPhysical || isNew)
1737 { 2104 {
1738 if (PhysActor.IsPhysical) // implies UsePhysics==false for this block 2105 if (PhysActor.IsPhysical)
1739 { 2106 {
1740 if (!isNew) 2107 if (!isNew) // implies UsePhysics==false for this block
2108 {
1741 ParentGroup.Scene.RemovePhysicalPrim(1); 2109 ParentGroup.Scene.RemovePhysicalPrim(1);
1742 2110
1743 PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate; 2111 Velocity = new Vector3(0, 0, 0);
1744 PhysActor.OnOutOfBounds -= PhysicsOutOfBounds; 2112 Acceleration = new Vector3(0, 0, 0);
1745 PhysActor.delink(); 2113 if (ParentGroup.RootPart == this)
2114 AngularVelocity = new Vector3(0, 0, 0);
1746 2115
1747 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints && (!isNew)) 2116 if (PhysActor.Phantom)
1748 { 2117 {
1749 // destroy all joints connected to this now deactivated body 2118 RemoveFromPhysics();
1750 ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(PhysActor); 2119 return;
1751 } 2120 }
1752 2121
1753 // stop client-side interpolation of all joint proxy objects that have just been deleted 2122 PhysActor.IsPhysical = UsePhysics;
1754 // this is done because RemoveAllJointsConnectedToActor invokes the OnJointDeactivated callback, 2123 PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate;
1755 // which stops client-side interpolation of deactivated joint proxy objects. 2124 PhysActor.OnOutOfBounds -= PhysicsOutOfBounds;
2125 PhysActor.delink();
2126 if (ParentGroup.Scene.PhysicsScene.SupportsNINJAJoints)
2127 {
2128 // destroy all joints connected to this now deactivated body
2129 ParentGroup.Scene.PhysicsScene.RemoveAllJointsConnectedToActorThreadLocked(PhysActor);
2130 }
2131 }
1756 } 2132 }
1757 2133
1758 if (!UsePhysics && !isNew) 2134 if (PhysActor.IsPhysical != UsePhysics)
1759 { 2135 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 2136
1769 PhysActor.IsPhysical = UsePhysics; 2137 if (UsePhysics)
2138 {
2139 if (ParentGroup.RootPart.KeyframeMotion != null)
2140 ParentGroup.RootPart.KeyframeMotion.Stop();
2141 ParentGroup.RootPart.KeyframeMotion = null;
2142 ParentGroup.Scene.AddPhysicalPrim(1);
1770 2143
1771 // If we're not what we're supposed to be in the physics scene, recreate ourselves. 2144 PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
1772 //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor); 2145 PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
1773 /// that's not wholesome. Had to make Scene public
1774 //PhysActor = null;
1775 2146
1776 if ((Flags & PrimFlags.Phantom) == 0) 2147 if (ParentID != 0 && ParentID != LocalId)
1777 {
1778 if (UsePhysics)
1779 { 2148 {
1780 ParentGroup.Scene.AddPhysicalPrim(1); 2149 if (ParentGroup.RootPart.PhysActor != null)
1781
1782 PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate;
1783 PhysActor.OnOutOfBounds += PhysicsOutOfBounds;
1784 if (ParentID != 0 && ParentID != LocalId)
1785 { 2150 {
1786 if (ParentGroup.RootPart.PhysActor != null) 2151 PhysActor.link(ParentGroup.RootPart.PhysActor);
1787 {
1788 PhysActor.link(ParentGroup.RootPart.PhysActor);
1789 }
1790 } 2152 }
1791 } 2153 }
1792 } 2154 }
1793 } 2155 }
1794 2156
2157 bool phan = ((Flags & PrimFlags.Phantom) != 0);
2158 if (PhysActor.Phantom != phan)
2159 PhysActor.Phantom = phan;
2160
2161
1795 // If this part is a sculpt then delay the physics update until we've asynchronously loaded the 2162 // If this part is a sculpt then delay the physics update until we've asynchronously loaded the
1796 // mesh data. 2163 // mesh data.
1797 if (Shape.SculptEntry) 2164 if (Shape.SculptEntry)
@@ -1924,10 +2291,7 @@ namespace OpenSim.Region.Framework.Scenes
1924 2291
1925 public Vector3 GetForce() 2292 public Vector3 GetForce()
1926 { 2293 {
1927 if (PhysActor != null) 2294 return Force;
1928 return PhysActor.Force;
1929 else
1930 return Vector3.Zero;
1931 } 2295 }
1932 2296
1933 /// <summary> 2297 /// <summary>
@@ -2561,9 +2925,9 @@ namespace OpenSim.Region.Framework.Scenes
2561 Vector3 newpos = new Vector3(PhysActor.Position.GetBytes(), 0); 2925 Vector3 newpos = new Vector3(PhysActor.Position.GetBytes(), 0);
2562 2926
2563 if (ParentGroup.Scene.TestBorderCross(newpos, Cardinals.N) 2927 if (ParentGroup.Scene.TestBorderCross(newpos, Cardinals.N)
2564 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.S) 2928 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.S)
2565 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.E) 2929 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.E)
2566 | ParentGroup.Scene.TestBorderCross(newpos, Cardinals.W)) 2930 || ParentGroup.Scene.TestBorderCross(newpos, Cardinals.W))
2567 { 2931 {
2568 ParentGroup.AbsolutePosition = newpos; 2932 ParentGroup.AbsolutePosition = newpos;
2569 return; 2933 return;
@@ -2584,17 +2948,18 @@ namespace OpenSim.Region.Framework.Scenes
2584 //Trys to fetch sound id from prim's inventory. 2948 //Trys to fetch sound id from prim's inventory.
2585 //Prim's inventory doesn't support non script items yet 2949 //Prim's inventory doesn't support non script items yet
2586 2950
2587 lock (TaskInventory) 2951 TaskInventory.LockItemsForRead(true);
2952
2953 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2588 { 2954 {
2589 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 2955 if (item.Value.Name == sound)
2590 { 2956 {
2591 if (item.Value.Name == sound) 2957 soundID = item.Value.ItemID;
2592 { 2958 break;
2593 soundID = item.Value.ItemID;
2594 break;
2595 }
2596 } 2959 }
2597 } 2960 }
2961
2962 TaskInventory.LockItemsForRead(false);
2598 } 2963 }
2599 2964
2600 ParentGroup.Scene.ForEachRootScenePresence(delegate(ScenePresence sp) 2965 ParentGroup.Scene.ForEachRootScenePresence(delegate(ScenePresence sp)
@@ -2715,6 +3080,19 @@ namespace OpenSim.Region.Framework.Scenes
2715 APIDTarget = Quaternion.Identity; 3080 APIDTarget = Quaternion.Identity;
2716 } 3081 }
2717 3082
3083
3084
3085 public void ScheduleFullUpdateIfNone()
3086 {
3087 if (ParentGroup == null)
3088 return;
3089
3090// ??? ParentGroup.HasGroupChanged = true;
3091
3092 if (UpdateFlag != UpdateRequired.FULL)
3093 ScheduleFullUpdate();
3094 }
3095
2718 /// <summary> 3096 /// <summary>
2719 /// Schedules this prim for a full update 3097 /// Schedules this prim for a full update
2720 /// </summary> 3098 /// </summary>
@@ -2914,8 +3292,8 @@ namespace OpenSim.Region.Framework.Scenes
2914 { 3292 {
2915 const float ROTATION_TOLERANCE = 0.01f; 3293 const float ROTATION_TOLERANCE = 0.01f;
2916 const float VELOCITY_TOLERANCE = 0.001f; 3294 const float VELOCITY_TOLERANCE = 0.001f;
2917 const float POSITION_TOLERANCE = 0.05f; 3295 const float POSITION_TOLERANCE = 0.05f; // I don't like this, but I suppose it's necessary
2918 const int TIME_MS_TOLERANCE = 3000; 3296 const int TIME_MS_TOLERANCE = 200; //llSetPos has a 200ms delay. This should NOT be 3 seconds.
2919 3297
2920 switch (UpdateFlag) 3298 switch (UpdateFlag)
2921 { 3299 {
@@ -2977,17 +3355,16 @@ namespace OpenSim.Region.Framework.Scenes
2977 if (!UUID.TryParse(sound, out soundID)) 3355 if (!UUID.TryParse(sound, out soundID))
2978 { 3356 {
2979 // search sound file from inventory 3357 // search sound file from inventory
2980 lock (TaskInventory) 3358 TaskInventory.LockItemsForRead(true);
3359 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory)
2981 { 3360 {
2982 foreach (KeyValuePair<UUID, TaskInventoryItem> item in TaskInventory) 3361 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound)
2983 { 3362 {
2984 if (item.Value.Name == sound && item.Value.Type == (int)AssetType.Sound) 3363 soundID = item.Value.ItemID;
2985 { 3364 break;
2986 soundID = item.Value.ItemID;
2987 break;
2988 }
2989 } 3365 }
2990 } 3366 }
3367 TaskInventory.LockItemsForRead(false);
2991 } 3368 }
2992 3369
2993 if (soundID == UUID.Zero) 3370 if (soundID == UUID.Zero)
@@ -3072,10 +3449,13 @@ namespace OpenSim.Region.Framework.Scenes
3072 3449
3073 public void SetBuoyancy(float fvalue) 3450 public void SetBuoyancy(float fvalue)
3074 { 3451 {
3452 Buoyancy = fvalue;
3453/*
3075 if (PhysActor != null) 3454 if (PhysActor != null)
3076 { 3455 {
3077 PhysActor.Buoyancy = fvalue; 3456 PhysActor.Buoyancy = fvalue;
3078 } 3457 }
3458 */
3079 } 3459 }
3080 3460
3081 public void SetDieAtEdge(bool p) 3461 public void SetDieAtEdge(bool p)
@@ -3103,23 +3483,83 @@ namespace OpenSim.Region.Framework.Scenes
3103 3483
3104 public void SetForce(Vector3 force) 3484 public void SetForce(Vector3 force)
3105 { 3485 {
3486 Force = force;
3487/*
3106 if (PhysActor != null) 3488 if (PhysActor != null)
3107 { 3489 {
3108 PhysActor.Force = force; 3490 PhysActor.Force = force;
3109 } 3491 }
3492 */
3493 }
3494
3495 public SOPVehicle sopVehicle
3496 {
3497 get
3498 {
3499 return m_vehicle;
3500 }
3501 set
3502 {
3503 m_vehicle = value;
3504 }
3505 }
3506
3507
3508 public int VehicleType
3509 {
3510 get
3511 {
3512 if (m_vehicle == null)
3513 return (int)Vehicle.TYPE_NONE;
3514 else
3515 return (int)m_vehicle.Type;
3516 }
3517 set
3518 {
3519 SetVehicleType(value);
3520 }
3110 } 3521 }
3111 3522
3112 public void SetVehicleType(int type) 3523 public void SetVehicleType(int type)
3113 { 3524 {
3114 if (PhysActor != null) 3525 m_vehicle = null;
3526
3527 if (type == (int)Vehicle.TYPE_NONE)
3528 {
3529 if (_parentID ==0 && PhysActor != null)
3530 PhysActor.VehicleType = (int)Vehicle.TYPE_NONE;
3531 return;
3532 }
3533 m_vehicle = new SOPVehicle();
3534 m_vehicle.ProcessTypeChange((Vehicle)type);
3535 {
3536 if (_parentID ==0 && PhysActor != null)
3537 PhysActor.VehicleType = type;
3538 return;
3539 }
3540 }
3541
3542 public void SetVehicleFlags(int param, bool remove)
3543 {
3544 if (m_vehicle == null)
3545 return;
3546
3547 m_vehicle.ProcessVehicleFlags(param, remove);
3548
3549 if (_parentID ==0 && PhysActor != null)
3115 { 3550 {
3116 PhysActor.VehicleType = type; 3551 PhysActor.VehicleFlags(param, remove);
3117 } 3552 }
3118 } 3553 }
3119 3554
3120 public void SetVehicleFloatParam(int param, float value) 3555 public void SetVehicleFloatParam(int param, float value)
3121 { 3556 {
3122 if (PhysActor != null) 3557 if (m_vehicle == null)
3558 return;
3559
3560 m_vehicle.ProcessFloatVehicleParam((Vehicle)param, value);
3561
3562 if (_parentID == 0 && PhysActor != null)
3123 { 3563 {
3124 PhysActor.VehicleFloatParam(param, value); 3564 PhysActor.VehicleFloatParam(param, value);
3125 } 3565 }
@@ -3127,7 +3567,12 @@ namespace OpenSim.Region.Framework.Scenes
3127 3567
3128 public void SetVehicleVectorParam(int param, Vector3 value) 3568 public void SetVehicleVectorParam(int param, Vector3 value)
3129 { 3569 {
3130 if (PhysActor != null) 3570 if (m_vehicle == null)
3571 return;
3572
3573 m_vehicle.ProcessVectorVehicleParam((Vehicle)param, value);
3574
3575 if (_parentID == 0 && PhysActor != null)
3131 { 3576 {
3132 PhysActor.VehicleVectorParam(param, value); 3577 PhysActor.VehicleVectorParam(param, value);
3133 } 3578 }
@@ -3135,7 +3580,12 @@ namespace OpenSim.Region.Framework.Scenes
3135 3580
3136 public void SetVehicleRotationParam(int param, Quaternion rotation) 3581 public void SetVehicleRotationParam(int param, Quaternion rotation)
3137 { 3582 {
3138 if (PhysActor != null) 3583 if (m_vehicle == null)
3584 return;
3585
3586 m_vehicle.ProcessRotationVehicleParam((Vehicle)param, rotation);
3587
3588 if (_parentID == 0 && PhysActor != null)
3139 { 3589 {
3140 PhysActor.VehicleRotationParam(param, rotation); 3590 PhysActor.VehicleRotationParam(param, rotation);
3141 } 3591 }
@@ -3322,13 +3772,6 @@ namespace OpenSim.Region.Framework.Scenes
3322 hasProfileCut = hasDimple; // is it the same thing? 3772 hasProfileCut = hasDimple; // is it the same thing?
3323 } 3773 }
3324 3774
3325 public void SetVehicleFlags(int param, bool remove)
3326 {
3327 if (PhysActor != null)
3328 {
3329 PhysActor.VehicleFlags(param, remove);
3330 }
3331 }
3332 3775
3333 public void SetGroup(UUID groupID, IClientAPI client) 3776 public void SetGroup(UUID groupID, IClientAPI client)
3334 { 3777 {
@@ -3431,68 +3874,18 @@ namespace OpenSim.Region.Framework.Scenes
3431 //ParentGroup.ScheduleGroupForFullUpdate(); 3874 //ParentGroup.ScheduleGroupForFullUpdate();
3432 } 3875 }
3433 3876
3434 public void StoreUndoState() 3877 public void StoreUndoState(ObjectChangeType change)
3435 { 3878 {
3436 StoreUndoState(false); 3879 if (m_UndoRedo == null)
3437 } 3880 m_UndoRedo = new UndoRedoState(5);
3438 3881
3439 public void StoreUndoState(bool forGroup) 3882 lock (m_UndoRedo)
3440 {
3441 if (!Undoing)
3442 { 3883 {
3443 if (!IgnoreUndoUpdate) 3884 if (!Undoing && !IgnoreUndoUpdate && ParentGroup != null) // just to read better - undo is in progress, or suspended
3444 { 3885 {
3445 if (ParentGroup != null) 3886 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 } 3887 }
3486// else
3487// {
3488// m_log.DebugFormat("[SCENE OBJECT PART]: Ignoring undo store for {0} {1}", Name, LocalId);
3489// }
3490 } 3888 }
3491// else
3492// {
3493// m_log.DebugFormat(
3494// "[SCENE OBJECT PART]: Ignoring undo store for {0} {1} since already undoing", Name, LocalId);
3495// }
3496 } 3889 }
3497 3890
3498 /// <summary> 3891 /// <summary>
@@ -3502,84 +3895,46 @@ namespace OpenSim.Region.Framework.Scenes
3502 { 3895 {
3503 get 3896 get
3504 { 3897 {
3505 lock (m_undo) 3898 if (m_UndoRedo == null)
3506 return m_undo.Count; 3899 return 0;
3900 return m_UndoRedo.Count;
3507 } 3901 }
3508 } 3902 }
3509 3903
3510 public void Undo() 3904 public void Undo()
3511 { 3905 {
3512 lock (m_undo) 3906 if (m_UndoRedo == null || Undoing || ParentGroup == null)
3513 { 3907 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 3908
3538// m_log.DebugFormat( 3909 lock (m_UndoRedo)
3539// "[SCENE OBJECT PART]: Handled undo request for {0} {1}, stack size now {2}", 3910 {
3540// Name, LocalId, m_undo.Count); 3911 Undoing = true;
3912 m_UndoRedo.Undo(this);
3913 Undoing = false;
3541 } 3914 }
3542 } 3915 }
3543 3916
3544 public void Redo() 3917 public void Redo()
3545 { 3918 {
3546 lock (m_undo) 3919 if (m_UndoRedo == null || Undoing || ParentGroup == null)
3547 { 3920 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 3921
3568// m_log.DebugFormat( 3922 lock (m_UndoRedo)
3569// "[SCENE OBJECT PART]: Handled redo request for {0} {1}, stack size now {2}", 3923 {
3570// Name, LocalId, m_redo.Count); 3924 Undoing = true;
3571 } 3925 m_UndoRedo.Redo(this);
3926 Undoing = false;
3572 } 3927 }
3573 } 3928 }
3574 3929
3575 public void ClearUndoState() 3930 public void ClearUndoState()
3576 { 3931 {
3577// m_log.DebugFormat("[SCENE OBJECT PART]: Clearing undo and redo stacks in {0} {1}", Name, LocalId); 3932 if (m_UndoRedo == null || Undoing)
3933 return;
3578 3934
3579 lock (m_undo) 3935 lock (m_UndoRedo)
3580 { 3936 {
3581 m_undo.Clear(); 3937 m_UndoRedo.Clear();
3582 m_redo.Clear();
3583 } 3938 }
3584 } 3939 }
3585 3940
@@ -4209,6 +4564,41 @@ namespace OpenSim.Region.Framework.Scenes
4209 } 4564 }
4210 } 4565 }
4211 4566
4567
4568 public void UpdateExtraPhysics(ExtraPhysicsData physdata)
4569 {
4570 if (physdata.PhysShapeType == PhysShapeType.invalid || ParentGroup == null)
4571 return;
4572
4573 if (PhysicsShapeType != (byte)physdata.PhysShapeType)
4574 {
4575 PhysicsShapeType = (byte)physdata.PhysShapeType;
4576
4577 if (PhysicsShapeType == (byte)PhysShapeType.none)
4578 {
4579 if (PhysActor != null)
4580 {
4581 Velocity = new Vector3(0, 0, 0);
4582 Acceleration = new Vector3(0, 0, 0);
4583 if (ParentGroup.RootPart == this)
4584 AngularVelocity = new Vector3(0, 0, 0);
4585 ParentGroup.Scene.RemovePhysicalPrim(1);
4586 RemoveFromPhysics();
4587 }
4588 }
4589 else if (PhysActor == null)
4590 ApplyPhysics((uint)Flags, VolumeDetectActive, false);
4591 }
4592
4593 if(Density != physdata.Density)
4594 Density = physdata.Density;
4595 if(GravityModifier != physdata.GravitationModifier)
4596 GravityModifier = physdata.GravitationModifier;
4597 if(Friction != physdata.Friction)
4598 Friction = physdata.Friction;
4599 if(Bounciness != physdata.Bounce)
4600 Bounciness = physdata.Bounce;
4601 }
4212 /// <summary> 4602 /// <summary>
4213 /// Update the flags on this prim. This covers properties such as phantom, physics and temporary. 4603 /// Update the flags on this prim. This covers properties such as phantom, physics and temporary.
4214 /// </summary> 4604 /// </summary>
@@ -4216,7 +4606,8 @@ namespace OpenSim.Region.Framework.Scenes
4216 /// <param name="SetTemporary"></param> 4606 /// <param name="SetTemporary"></param>
4217 /// <param name="SetPhantom"></param> 4607 /// <param name="SetPhantom"></param>
4218 /// <param name="SetVD"></param> 4608 /// <param name="SetVD"></param>
4219 public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD) 4609// public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD)
4610 public void UpdatePrimFlags(bool UsePhysics, bool SetTemporary, bool SetPhantom, bool SetVD, bool building)
4220 { 4611 {
4221 bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0); 4612 bool wasUsingPhysics = ((Flags & PrimFlags.Physics) != 0);
4222 bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0); 4613 bool wasTemporary = ((Flags & PrimFlags.TemporaryOnRez) != 0);
@@ -4226,41 +4617,58 @@ namespace OpenSim.Region.Framework.Scenes
4226 if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD)) 4617 if ((UsePhysics == wasUsingPhysics) && (wasTemporary == SetTemporary) && (wasPhantom == SetPhantom) && (SetVD == wasVD))
4227 return; 4618 return;
4228 4619
4620 // do this first
4621 if (building && PhysActor != null && PhysActor.Building != building)
4622 PhysActor.Building = building;
4623
4229 // Special cases for VD. VD can only be called from a script 4624 // 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 4625 // and can't be combined with changes to other states. So we can rely
4231 // that... 4626 // that...
4232 // ... if VD is changed, all others are not. 4627 // ... if VD is changed, all others are not.
4233 // ... if one of the others is changed, VD is not. 4628 // ... if one of the others is changed, VD is not.
4629
4630/*
4234 if (SetVD) // VD is active, special logic applies 4631 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 4632
4240 if (phanReset) // Phantom changes from on to off switch VD off too 4633 volume detection is now independent of phantom in sl
4241 { 4634
4242 SetVD = false; // Switch it of for the course of this routine 4635 {
4243 VolumeDetectActive = false; // and also permanently 4636 // State machine logic for VolumeDetect
4244 if (PhysActor != null) 4637 // More logic below
4245 PhysActor.SetVolumeDetect(0); // Let physics know about it too 4638
4246 } 4639
4247 else 4640 bool phanReset = (SetPhantom != wasPhantom) && !SetPhantom;
4248 { 4641
4249 // If volumedetect is active we don't want phantom to be applied. 4642 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" 4643 {
4251 // this will also cause the prim to be visible to physics 4644 SetVD = false; // Switch it of for the course of this routine
4645 VolumeDetectActive = false; // and also permanently
4646 if (PhysActor != null)
4647 PhysActor.SetVolumeDetect(0); // Let physics know about it too
4648 }
4649 else
4650 {
4651 // If volumedetect is active we don't want phantom to be applied.
4652 // If this is a new call to VD out of the state "phantom"
4653 // this will also cause the prim to be visible to physics
4252 SetPhantom = false; 4654 SetPhantom = false;
4253 } 4655 }
4656 }
4657 else if (wasVD)
4658 {
4659 // Correspondingly, if VD is turned off, also turn off phantom
4660 SetPhantom = false;
4254 } 4661 }
4255 4662
4256 if (UsePhysics && IsJoint()) 4663 if (UsePhysics && IsJoint())
4257 { 4664 {
4258 SetPhantom = true; 4665 SetPhantom = true;
4259 } 4666 }
4260 4667*/
4261 if (UsePhysics) 4668 if (UsePhysics)
4262 { 4669 {
4263 AddFlag(PrimFlags.Physics); 4670 AddFlag(PrimFlags.Physics);
4671/*
4264 if (!wasUsingPhysics) 4672 if (!wasUsingPhysics)
4265 { 4673 {
4266 DoPhysicsPropertyUpdate(UsePhysics, false); 4674 DoPhysicsPropertyUpdate(UsePhysics, false);
@@ -4273,78 +4681,99 @@ namespace OpenSim.Region.Framework.Scenes
4273 } 4681 }
4274 } 4682 }
4275 } 4683 }
4684 */
4276 } 4685 }
4277 else 4686 else
4278 { 4687 {
4279 RemFlag(PrimFlags.Physics); 4688 RemFlag(PrimFlags.Physics);
4689/*
4280 if (wasUsingPhysics) 4690 if (wasUsingPhysics)
4281 { 4691 {
4282 DoPhysicsPropertyUpdate(UsePhysics, false); 4692 DoPhysicsPropertyUpdate(UsePhysics, false);
4283 } 4693 }
4284 } 4694*/
4695 }
4696
4697 if (SetPhantom)
4698 AddFlag(PrimFlags.Phantom);
4699 else
4700 RemFlag(PrimFlags.Phantom);
4285 4701
4286 if (SetPhantom 4702 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 4703 || (Shape.PathCurve == (byte)Extrusion.Flexible)) // note: this may have been changed above in the case of joints
4289 { 4704 {
4290 AddFlag(PrimFlags.Phantom); 4705// AddFlag(PrimFlags.Phantom);
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);
4291 4711
4292 if (PhysActor != null) 4712 if (PhysActor != null)
4713 {
4714 ParentGroup.Scene.RemovePhysicalPrim(1);
4293 RemoveFromPhysics(); 4715 RemoveFromPhysics();
4716 }
4294 } 4717 }
4295 else // Not phantom 4718 else
4296 { 4719 {
4297 RemFlag(PrimFlags.Phantom);
4298
4299 if (ParentGroup.Scene == null) 4720 if (ParentGroup.Scene == null)
4300 return; 4721 return;
4301 4722
4302 if (ParentGroup.Scene.CollidablePrims && PhysActor == null) 4723 if (ParentGroup.Scene.CollidablePrims)
4303 { 4724 {
4304 // It's not phantom anymore. So make sure the physics engine get's knowledge of it 4725 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 { 4726 {
4319 if (LocalId == ParentGroup.RootPart.LocalId) 4727 PhysActor = ParentGroup.Scene.PhysicsScene.AddPrimShape(
4728 string.Format("{0}/{1}", Name, UUID),
4729 Shape,
4730 AbsolutePosition,
4731 Scale,
4732 GetWorldRotation(), //physics wants world rotation like all other functions send
4733 UsePhysics,
4734 SetPhantom,
4735 m_localId);
4736
4737 PhysActor.SetMaterial(Material);
4738
4739 // if root part apply vehicle
4740 if (m_vehicle != null && LocalId == ParentGroup.RootPart.LocalId)
4741 m_vehicle.SetVehicle(PhysActor);
4742
4743 DoPhysicsPropertyUpdate(UsePhysics, true);
4744
4745 if (!ParentGroup.IsDeleted)
4320 { 4746 {
4321 ParentGroup.CheckSculptAndLoad(); 4747 if (LocalId == ParentGroup.RootPart.LocalId)
4748 {
4749 ParentGroup.CheckSculptAndLoad();
4750 }
4322 } 4751 }
4323 }
4324 4752
4325 if ( 4753 if (
4326 ((AggregateScriptEvents & scriptEvents.collision) != 0) || 4754 ((AggregateScriptEvents & scriptEvents.collision) != 0) ||
4327 ((AggregateScriptEvents & scriptEvents.collision_end) != 0) || 4755 ((AggregateScriptEvents & scriptEvents.collision_end) != 0) ||
4328 ((AggregateScriptEvents & scriptEvents.collision_start) != 0) || 4756 ((AggregateScriptEvents & scriptEvents.collision_start) != 0) ||
4329 ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) || 4757 ((AggregateScriptEvents & scriptEvents.land_collision_start) != 0) ||
4330 ((AggregateScriptEvents & scriptEvents.land_collision) != 0) || 4758 ((AggregateScriptEvents & scriptEvents.land_collision) != 0) ||
4331 ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) || 4759 ((AggregateScriptEvents & scriptEvents.land_collision_end) != 0) ||
4332 (CollisionSound != UUID.Zero) 4760 (CollisionSound != UUID.Zero)
4333 ) 4761 )
4334 { 4762 {
4335 PhysActor.OnCollisionUpdate += PhysicsCollision; 4763 PhysActor.OnCollisionUpdate += PhysicsCollision;
4336 PhysActor.SubscribeEvents(1000); 4764 PhysActor.SubscribeEvents(1000);
4765 }
4337 } 4766 }
4338 } 4767 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 { 4768 {
4345 if (LocalId == ParentGroup.RootPart.LocalId) 4769 DoPhysicsPropertyUpdate(UsePhysics, false); // Update physical status.
4770
4771 if (!ParentGroup.IsDeleted)
4346 { 4772 {
4347 ParentGroup.CheckSculptAndLoad(); 4773 if (LocalId == ParentGroup.RootPart.LocalId)
4774 {
4775 ParentGroup.CheckSculptAndLoad();
4776 }
4348 } 4777 }
4349 } 4778 }
4350 } 4779 }
@@ -4360,7 +4789,7 @@ namespace OpenSim.Region.Framework.Scenes
4360 if (this.PhysActor != null) 4789 if (this.PhysActor != null)
4361 { 4790 {
4362 PhysActor.SetVolumeDetect(1); 4791 PhysActor.SetVolumeDetect(1);
4363 AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active 4792// AddFlag(PrimFlags.Phantom); // We set this flag also if VD is active
4364 this.VolumeDetectActive = true; 4793 this.VolumeDetectActive = true;
4365 } 4794 }
4366 } 4795 }
@@ -4368,8 +4797,7 @@ namespace OpenSim.Region.Framework.Scenes
4368 { 4797 {
4369 // Remove VolumeDetect in any case. Note, it's safe to call SetVolumeDetect as often as you like 4798 // 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 :-)) 4799 // (mumbles, well, at least if you have infinte CPU powers :-))
4371 PhysicsActor pa = this.PhysActor; 4800 if (this.PhysActor != null)
4372 if (pa != null)
4373 { 4801 {
4374 PhysActor.SetVolumeDetect(0); 4802 PhysActor.SetVolumeDetect(0);
4375 } 4803 }
@@ -4387,12 +4815,15 @@ namespace OpenSim.Region.Framework.Scenes
4387 } 4815 }
4388 // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString()); 4816 // m_log.Debug("Update: PHY:" + UsePhysics.ToString() + ", T:" + IsTemporary.ToString() + ", PHA:" + IsPhantom.ToString() + " S:" + CastsShadows.ToString());
4389 4817
4818 // and last in case we have a new actor and not building
4819 if (PhysActor != null && PhysActor.Building != building)
4820 PhysActor.Building = building;
4390 if (ParentGroup != null) 4821 if (ParentGroup != null)
4391 { 4822 {
4392 ParentGroup.HasGroupChanged = true; 4823 ParentGroup.HasGroupChanged = true;
4393 ScheduleFullUpdate(); 4824 ScheduleFullUpdate();
4394 } 4825 }
4395 4826
4396// m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags); 4827// m_log.DebugFormat("[SCENE OBJECT PART]: Updated PrimFlags on {0} {1} to {2}", Name, LocalId, Flags);
4397 } 4828 }
4398 4829
@@ -4750,5 +5181,17 @@ namespace OpenSim.Region.Framework.Scenes
4750 Color color = Color; 5181 Color color = Color;
4751 return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A)); 5182 return new Color4(color.R, color.G, color.B, (byte)(0xFF - color.A));
4752 } 5183 }
5184
5185 public void ResetOwnerChangeFlag()
5186 {
5187 List<UUID> inv = Inventory.GetInventoryList();
5188
5189 foreach (UUID itemID in inv)
5190 {
5191 TaskInventoryItem item = Inventory.GetInventoryItem(itemID);
5192 item.OwnerChanged = false;
5193 Inventory.UpdateInventoryItem(item, false, false);
5194 }
5195 }
4753 } 5196 }
4754} 5197}