aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs661
1 files changed, 349 insertions, 312 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index e1dc9f8..84ff60c 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -85,6 +85,7 @@ namespace OpenSim.Region.Physics.OdePlugin
85 private List<OdeCharacter> _characters = new List<OdeCharacter>(); 85 private List<OdeCharacter> _characters = new List<OdeCharacter>();
86 private List<OdePrim> _prims = new List<OdePrim>(); 86 private List<OdePrim> _prims = new List<OdePrim>();
87 private List<OdePrim> _activeprims = new List<OdePrim>(); 87 private List<OdePrim> _activeprims = new List<OdePrim>();
88 private List<OdePrim> _taintedPrim = new List<OdePrim>();
88 public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>(); 89 public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>();
89 public Dictionary<IntPtr, PhysicsActor> actor_name_map = new Dictionary<IntPtr, PhysicsActor>(); 90 public Dictionary<IntPtr, PhysicsActor> actor_name_map = new Dictionary<IntPtr, PhysicsActor>();
90 private d.ContactGeom[] contacts = new d.ContactGeom[30]; 91 private d.ContactGeom[] contacts = new d.ContactGeom[30];
@@ -326,13 +327,7 @@ namespace OpenSim.Region.Physics.OdePlugin
326 chr.CollidingGround = false; 327 chr.CollidingGround = false;
327 chr.CollidingObj = false; 328 chr.CollidingObj = false;
328 d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); 329 d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback);
329 foreach (OdeCharacter ch2 in _characters) 330
330 /// should be a separate space -- lots of avatars will be N**2 slow
331 {
332
333
334 //d.SpaceCollide2(chr.Shell, ch2.Shell, IntPtr.Zero, nearCallback);
335 }
336 331
337 } 332 }
338 // If the sim is running slow this frame, 333 // If the sim is running slow this frame,
@@ -345,20 +340,20 @@ namespace OpenSim.Region.Physics.OdePlugin
345 if (d.BodyIsEnabled(chr.Body)) 340 if (d.BodyIsEnabled(chr.Body))
346 { 341 {
347 d.SpaceCollide2(space, chr.prim_geom, IntPtr.Zero, nearCallback); 342 d.SpaceCollide2(space, chr.prim_geom, IntPtr.Zero, nearCallback);
348 foreach (OdePrim ch2 in _prims) 343 //foreach (OdePrim ch2 in _prims)
349 /// should be a separate space -- lots of avatars will be N**2 slow 344 /// should be a separate space -- lots of avatars will be N**2 slow
350 { 345 //{
351 if (ch2.IsPhysical && d.BodyIsEnabled(ch2.Body)) 346 //if (ch2.IsPhysical && d.BodyIsEnabled(ch2.Body))
352 { 347 //{
353 // Only test prim that are 0.03 meters away in one direction. 348 // Only test prim that are 0.03 meters away in one direction.
354 // This should be Optimized! 349 // This should be Optimized!
355 350
356 if ((Math.Abs(ch2.Position.X - chr.Position.X) < 0.03) || (Math.Abs(ch2.Position.Y - chr.Position.Y) < 0.03) || (Math.Abs(ch2.Position.X - chr.Position.X) < 0.03)) 351 //if ((Math.Abs(ch2.Position.X - chr.Position.X) < 0.03) || (Math.Abs(ch2.Position.Y - chr.Position.Y) < 0.03) || (Math.Abs(ch2.Position.X - chr.Position.X) < 0.03))
357 { 352 //{
358 d.SpaceCollide2(chr.prim_geom, ch2.prim_geom, IntPtr.Zero, nearCallback); 353 //d.SpaceCollide2(chr.prim_geom, ch2.prim_geom, IntPtr.Zero, nearCallback);
359 } 354 //}
360 } 355 //}
361 } 356 //}
362 } 357 }
363 } 358 }
364 } 359 }
@@ -404,60 +399,70 @@ namespace OpenSim.Region.Physics.OdePlugin
404 { 399 {
405 lock (OdeLock) 400 lock (OdeLock)
406 { 401 {
407 if (prim.IsPhysical) 402 OdePrim p = (OdePrim) prim;
408 { 403
409 OdePrim p; 404 p.setPrimForRemoval();
410 p = (OdePrim) prim; 405 AddPhysicsActorTaint(prim);
411 p.disableBody(); 406
412 } 407 }
413 // we don't want to remove the main space 408 }
414 if (((OdePrim)prim).m_targetSpace != space && ((OdePrim)prim).IsPhysical == false) 409 }
410 public void RemovePrimThreadLocked(OdePrim prim)
411 {
412 lock (OdeLock)
413 {
414
415 if (prim.IsPhysical)
416 {
417 prim.disableBody();
418 }
419 // we don't want to remove the main space
420 if (prim.m_targetSpace != space && prim.IsPhysical == false)
421 {
422 // If the geometry is in the targetspace, remove it from the target space
423 if (d.SpaceQuery(prim.m_targetSpace, prim.prim_geom))
415 { 424 {
416 // If the geometry is in the targetspace, remove it from the target space 425 if (!(prim.m_targetSpace.Equals(null)))
417 if (d.SpaceQuery(((OdePrim)prim).m_targetSpace, ((OdePrim)prim).prim_geom))
418 { 426 {
419 if (!(((OdePrim)prim).m_targetSpace.Equals(null))) 427 if (d.GeomIsSpace(prim.m_targetSpace))
428 {
429 d.SpaceRemove(prim.m_targetSpace, prim.prim_geom);
430 }
431 else
420 { 432 {
421 if (d.GeomIsSpace(((OdePrim)prim).m_targetSpace)) 433 OpenSim.Framework.Console.MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'removeprim from scene':" + ((OdePrim)prim).m_targetSpace.ToString());
422 {
423 d.SpaceRemove(((OdePrim)prim).m_targetSpace, ((OdePrim)prim).prim_geom);
424 }
425 else
426 {
427 OpenSim.Framework.Console.MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'removeprim from scene':" + ((OdePrim)prim).m_targetSpace.ToString());
428 }
429 } 434 }
430 } 435 }
436 }
437
431 438
432
433 439
434 //If there are no more geometries in the sub-space, we don't need it in the main space anymore 440 //If there are no more geometries in the sub-space, we don't need it in the main space anymore
435 if (d.SpaceGetNumGeoms(((OdePrim)prim).m_targetSpace) == 0) 441 if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0)
442 {
443 if (!(prim.m_targetSpace.Equals(null)))
436 { 444 {
437 if (!(((OdePrim)prim).m_targetSpace.Equals(null))) 445 if (d.GeomIsSpace(prim.m_targetSpace))
438 { 446 {
439 if (d.GeomIsSpace(((OdePrim)prim).m_targetSpace)) 447 d.SpaceRemove(space, prim.m_targetSpace);
440 { 448 // free up memory used by the space.
441 d.SpaceRemove(space, ((OdePrim)prim).m_targetSpace); 449 d.SpaceDestroy(prim.m_targetSpace);
442 // free up memory used by the space. 450 int[] xyspace = calculateSpaceArrayItemFromPos(prim.Position);
443 d.SpaceDestroy(((OdePrim)prim).m_targetSpace); 451 resetSpaceArrayItemToZero(xyspace[0], xyspace[1]);
444 int[] xyspace = calculateSpaceArrayItemFromPos(((OdePrim)prim).Position); 452 }
445 resetSpaceArrayItemToZero(xyspace[0],xyspace[1]); 453 else
446 } 454 {
447 else 455 OpenSim.Framework.Console.MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'removeprim from scene':" + ((OdePrim)prim).m_targetSpace.ToString());
448 {
449 OpenSim.Framework.Console.MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'removeprim from scene':" + ((OdePrim)prim).m_targetSpace.ToString());
450 }
451 } 456 }
452 } 457 }
453 } 458 }
454
455 d.GeomDestroy(((OdePrim)prim).prim_geom);
456
457 _prims.Remove((OdePrim)prim);
458
459 } 459 }
460
461 d.GeomDestroy(prim.prim_geom);
462
463 _prims.Remove(prim);
460 } 464 }
465
461 } 466 }
462 public void resetSpaceArrayItemToZero(IntPtr space) 467 public void resetSpaceArrayItemToZero(IntPtr space)
463 { 468 {
@@ -654,8 +659,9 @@ namespace OpenSim.Region.Physics.OdePlugin
654 lock (OdeLock) 659 lock (OdeLock)
655 { 660 {
656 newPrim = new OdePrim(name, this, targetspace, pos, siz, rot, mesh, pbs, isphysical); 661 newPrim = new OdePrim(name, this, targetspace, pos, siz, rot, mesh, pbs, isphysical);
662
663 _prims.Add(newPrim);
657 } 664 }
658 _prims.Add(newPrim);
659 665
660 return newPrim; 666 return newPrim;
661 } 667 }
@@ -761,20 +767,23 @@ namespace OpenSim.Region.Physics.OdePlugin
761 return result; 767 return result;
762 } 768 }
763 769
770 public override void AddPhysicsActorTaint(PhysicsActor prim)
771 {
772 if (prim is OdePrim)
773 {
774 OdePrim taintedprim = ((OdePrim)prim);
775 if (!(_taintedPrim.Contains(taintedprim)))
776 _taintedPrim.Add(taintedprim);
777
778 }
779 }
764 780
765 public override void Simulate(float timeStep) 781 public override void Simulate(float timeStep)
766 { 782 {
767 783
768 step_time += timeStep; 784 step_time += timeStep;
769 lock (OdeLock)
770 {
771 if (_characters.Count > 0 && RENDER_FLAG)
772 {
773 Console.WriteLine("RENDER: frame");
774 }
775
776
777 785
786
778 // If We're loaded down by something else, 787 // If We're loaded down by something else,
779 // or debugging with the Visual Studio project on pause 788 // or debugging with the Visual Studio project on pause
780 // skip a few frames to catch up gracefully. 789 // skip a few frames to catch up gracefully.
@@ -792,7 +801,8 @@ namespace OpenSim.Region.Physics.OdePlugin
792 { 801 {
793 m_physicsiterations = 10; 802 m_physicsiterations = 10;
794 } 803 }
795 804 lock (OdeLock)
805 {
796 // Process 10 frames if the sim is running normal.. 806 // Process 10 frames if the sim is running normal..
797 // process 5 frames if the sim is running slow 807 // process 5 frames if the sim is running slow
798 d.WorldSetQuickStepNumIterations(world, m_physicsiterations); 808 d.WorldSetQuickStepNumIterations(world, m_physicsiterations);
@@ -823,38 +833,23 @@ namespace OpenSim.Region.Physics.OdePlugin
823 foreach (OdeCharacter actor in _characters) 833 foreach (OdeCharacter actor in _characters)
824 { 834 {
825 actor.UpdatePositionAndVelocity(); 835 actor.UpdatePositionAndVelocity();
826 if (RENDER_FLAG) 836
837 }
838 bool processedtaints = false;
839 foreach (OdePrim prim in _taintedPrim)
840 {
841 prim.ProcessTaints(timeStep);
842 if (prim.m_taintremove)
827 { 843 {
828 /// debugging code 844 RemovePrimThreadLocked(prim);
829 float Zoff = -33.0f;
830 d.Matrix3 temp = d.BodyGetRotation(actor.Body);
831 //Console.WriteLine("RENDER: cylinder; " + // shape
832 //OdeCharacter.CAPSULE_RADIUS + ", " + OdeCharacter.CAPSULE_LENGTH + //size
833 //"; 0, 1, 0; " + // color
834 //(actor.Position.X - 128.0f) + ", " + (actor.Position.Y - 128.0f) + ", " +
835 //(actor.Position.Z + Zoff) + "; " + // position
836 //temp.M00 + "," + temp.M10 + "," + temp.M20 + ", " + // rotation
837 //temp.M01 + "," + temp.M11 + "," + temp.M21 + ", " +
838 //temp.M02 + "," + temp.M12 + "," + temp.M22);
839 d.Vector3 caphead;
840 //d.BodyGetRelPointPos(actor.Body, 0, 0, OdeCharacter.CAPSULE_LENGTH*.5f, out caphead);
841 d.Vector3 capfoot;
842 //d.BodyGetRelPointPos(actor.Body, 0, 0, -OdeCharacter.CAPSULE_LENGTH*.5f, out capfoot);
843 //Console.WriteLine("RENDER: sphere; " + OdeCharacter.CAPSULE_RADIUS + // shape, size
844 //"; 1, 0, 1; " + //color
845 //(caphead.X - 128.0f) + ", " + (caphead.Y - 128.0f) + ", " + (caphead.Z + Zoff) +
846 //"; " + // position
847 ///"1,0,0, 0,1,0, 0,0,1"); // rotation
848 // Console.WriteLine("RENDER: sphere; " + OdeCharacter.CAPSULE_RADIUS + // shape, size
849 //"; 1, 0, 0; " + //color
850 //(capfoot.X - 128.0f) + ", " + (capfoot.Y - 128.0f) + ", " + (capfoot.Z + Zoff) +
851 //"; " + // position
852 //"1,0,0, 0,1,0, 0,0,1"); // rotation
853 } 845 }
846 processedtaints = true;
854 } 847 }
848 if (processedtaints)
849 _taintedPrim = new List<OdePrim>();
850
855 if (timeStep < 0.2f) 851 if (timeStep < 0.2f)
856 { 852 {
857 OdePrim outofBoundsPrim = null;
858 foreach (OdePrim actor in _activeprims) 853 foreach (OdePrim actor in _activeprims)
859 { 854 {
860 if (actor.IsPhysical && (d.BodyIsEnabled(actor.Body) || !actor._zeroFlag)) 855 if (actor.IsPhysical && (d.BodyIsEnabled(actor.Body) || !actor._zeroFlag))
@@ -1410,6 +1405,12 @@ namespace OpenSim.Region.Physics.OdePlugin
1410 private PhysicsVector _size; 1405 private PhysicsVector _size;
1411 private PhysicsVector _acceleration; 1406 private PhysicsVector _acceleration;
1412 private Quaternion _orientation; 1407 private Quaternion _orientation;
1408 private PhysicsVector m_taintposition;
1409 private PhysicsVector m_taintsize;
1410 private Quaternion m_taintrot;
1411 private bool m_taintshape = false;
1412 private bool m_taintPhysics = false;
1413 public bool m_taintremove = false;
1413 1414
1414 private IMesh _mesh; 1415 private IMesh _mesh;
1415 private PrimitiveBaseShape _pbs; 1416 private PrimitiveBaseShape _pbs;
@@ -1441,30 +1442,33 @@ namespace OpenSim.Region.Physics.OdePlugin
1441 1442
1442 _velocity = new PhysicsVector(); 1443 _velocity = new PhysicsVector();
1443 _position = pos; 1444 _position = pos;
1444 1445 m_taintposition = pos;
1445 //if (_position.X > 257) 1446 if (_position.X > 257)
1446 //{ 1447 {
1447 // _position.X = 257; 1448 _position.X = 257;
1448 //} 1449 }
1449 //if (_position.X < 0) 1450 if (_position.X < 0)
1450 //{ 1451 {
1451 // _position.X = 0; 1452 _position.X = 0;
1452 //} 1453 }
1453 //if (_position.Y > 257) 1454 if (_position.Y > 257)
1454 //{ 1455 {
1455 // _position.Y = 257; 1456 _position.Y = 257;
1456 // } 1457 }
1457 //if (_position.Y < 0) 1458 if (_position.Y < 0)
1458 //{ 1459 {
1459 // _position.Y = 0; 1460 _position.Y = 0;
1460 //} 1461 }
1461 1462
1462 _size = size; 1463 _size = size;
1464 m_taintsize = _size;
1463 _acceleration = new PhysicsVector(); 1465 _acceleration = new PhysicsVector();
1464 m_rotationalVelocity = PhysicsVector.Zero; 1466 m_rotationalVelocity = PhysicsVector.Zero;
1465 _orientation = rotation; 1467 _orientation = rotation;
1468 m_taintrot = _orientation;
1466 _mesh = mesh; 1469 _mesh = mesh;
1467 _pbs = pbs; 1470 _pbs = pbs;
1471
1468 _parent_scene = parent_scene; 1472 _parent_scene = parent_scene;
1469 m_targetSpace = targetSpace; 1473 m_targetSpace = targetSpace;
1470 1474
@@ -1585,39 +1589,237 @@ namespace OpenSim.Region.Physics.OdePlugin
1585 enableBody(); 1589 enableBody();
1586 } 1590 }
1587 } 1591 }
1592 public void ProcessTaints(float timestep)
1593 {
1594 if (m_taintposition != _position)
1595 Move(timestep);
1588 1596
1589 public override bool IsPhysical 1597 if (m_taintrot != _orientation)
1598 rotate(timestep);
1599 //
1600
1601 if (m_taintPhysics != m_isphysical)
1602 changePhysicsStatus(timestep);
1603 //
1604
1605 if (m_taintsize != _size)
1606 changesize(timestep);
1607 //
1608
1609 if (m_taintshape)
1610 changeshape(timestep);
1611 //
1612
1613 }
1614 public void Move(float timestep)
1590 { 1615 {
1591 get { return m_isphysical; } 1616 if (m_isphysical)
1592 set { 1617 {
1593 1618 // This is a fallback.. May no longer be necessary.
1594 lock (OdeScene.OdeLock) 1619 if (Body == (IntPtr)0)
1620 enableBody();
1621 //Prim auto disable after 20 frames,
1622 ///if you move it, re-enable the prim manually.
1623 d.BodyEnable(Body);
1624 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
1625 }
1626 else
1627 {
1628 string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
1629 int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
1630 if (primScenAvatarIn == "0")
1595 { 1631 {
1596 if (m_isphysical == value) 1632 OpenSim.Framework.Console.MainLog.Instance.Verbose("Physics", "Prim " + m_primName + " in space with no prim: " + primScenAvatarIn + ". Expected to be at: " + m_targetSpace.ToString() + " . Arr:': " + arrayitem[0].ToString() + "," + arrayitem[1].ToString());
1597 { 1633 }
1598 // If the object is already what the user checked 1634 else
1599 1635 {
1600 return; 1636 OpenSim.Framework.Console.MainLog.Instance.Verbose("Physics", "Prim " + m_primName + " in Prim space with prim: " + primScenAvatarIn + ". Expected to be at: " + m_targetSpace.ToString() + ". Arr:" + arrayitem[0].ToString() + "," + arrayitem[1].ToString());
1601 } 1637 }
1602 if (value == true) 1638 m_targetSpace = _parent_scene.recalculateSpaceForGeom(prim_geom, _position, m_targetSpace);
1603 { 1639 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1604 if (Body == (IntPtr)0) 1640 d.SpaceAdd(m_targetSpace, prim_geom);
1605 { 1641 }
1606 enableBody();
1607 }
1608 1642
1609 } 1643 m_taintposition = _position;
1610 else if (value == false) 1644 }
1611 { 1645 public void rotate(float timestep)
1612 if (Body != (IntPtr)0) 1646 {
1613 { 1647
1614 disableBody(); 1648 d.Quaternion myrot = new d.Quaternion();
1615 } 1649 myrot.W = _orientation.w;
1616 } 1650 myrot.X = _orientation.x;
1617 m_isphysical = value; 1651 myrot.Y = _orientation.y;
1652 myrot.Z = _orientation.z;
1653 d.GeomSetQuaternion(prim_geom, ref myrot);
1654 if (m_isphysical && Body != (IntPtr)0)
1655 {
1656 d.BodySetQuaternion(Body, ref myrot);
1657 }
1658
1659 m_taintrot = _orientation;
1660 }
1661 public void changePhysicsStatus(float timestap)
1662 {
1663 if (m_isphysical == true)
1664 {
1665 if (Body == (IntPtr)0)
1666 {
1667 enableBody();
1618 } 1668 }
1619 1669
1620 } 1670 }
1671 else
1672 {
1673 if (Body != (IntPtr)0)
1674 {
1675 disableBody();
1676 }
1677 }
1678
1679
1680 m_taintPhysics = m_isphysical;
1681 }
1682 public void changesize(float timestamp)
1683 {
1684 string oldname = _parent_scene.geom_name_map[prim_geom];
1685
1686 // Cleanup of old prim geometry
1687 if (_mesh != null)
1688 {
1689 // Cleanup meshing here
1690 }
1691 //kill body to rebuild
1692 if (IsPhysical && Body != (IntPtr)0)
1693 {
1694 disableBody();
1695 }
1696 if (d.SpaceQuery(m_targetSpace, prim_geom))
1697 {
1698 d.SpaceRemove(m_targetSpace, prim_geom);
1699 }
1700 d.GeomDestroy(prim_geom);
1701
1702 // we don't need to do space calculation because the client sends a position update also.
1703
1704 // Construction of new prim
1705 if (this._parent_scene.needsMeshing(_pbs))
1706 {
1707
1708
1709 // Don't need to re-enable body.. it's done in SetMesh
1710 IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size);
1711 // createmesh returns null when it's a shape that isn't a cube.
1712 if (mesh != null)
1713 {
1714 setMesh(_parent_scene, mesh);
1715 }
1716 else
1717 {
1718 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
1719 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1720 d.Quaternion myrot = new d.Quaternion();
1721 myrot.W = _orientation.w;
1722 myrot.X = _orientation.x;
1723 myrot.Y = _orientation.y;
1724 myrot.Z = _orientation.z;
1725 d.GeomSetQuaternion(prim_geom, ref myrot);
1726
1727
1728 }
1729 }
1730 else
1731 {
1732 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
1733 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1734 d.Quaternion myrot = new d.Quaternion();
1735 myrot.W = _orientation.w;
1736 myrot.X = _orientation.x;
1737 myrot.Y = _orientation.y;
1738 myrot.Z = _orientation.z;
1739 d.GeomSetQuaternion(prim_geom, ref myrot);
1740
1741
1742 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
1743 if (IsPhysical && Body == (IntPtr)0)
1744 {
1745 // Re creates body on size.
1746 // EnableBody also does setMass()
1747 enableBody();
1748 d.BodyEnable(Body);
1749 }
1750
1751 }
1752
1753
1754 _parent_scene.geom_name_map[prim_geom] = oldname;
1755
1756
1757 m_taintsize = _size;
1758 }
1759 public void changeshape(float timestamp)
1760 {
1761 string oldname = _parent_scene.geom_name_map[prim_geom];
1762
1763 // Cleanup of old prim geometry and Bodies
1764 if (IsPhysical && Body != (IntPtr)0)
1765 {
1766 disableBody();
1767 }
1768 d.GeomDestroy(prim_geom);
1769 if (_mesh != null)
1770 {
1771
1772 d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
1773
1774 }
1775
1776 // Construction of new prim
1777 if (this._parent_scene.needsMeshing(_pbs))
1778 {
1779 IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size);
1780 if (mesh != null)
1781 {
1782 setMesh(_parent_scene, mesh);
1783 }
1784 else
1785 {
1786 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
1787 }
1788 }
1789 else
1790 {
1791 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
1792 }
1793 if (IsPhysical && Body == (IntPtr)0)
1794 {
1795 //re-create new body
1796 enableBody();
1797 }
1798 else
1799 {
1800 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1801 d.Quaternion myrot = new d.Quaternion();
1802 myrot.W = _orientation.w;
1803 myrot.X = _orientation.x;
1804 myrot.Y = _orientation.y;
1805 myrot.Z = _orientation.z;
1806 d.GeomSetQuaternion(prim_geom, ref myrot);
1807 }
1808 _parent_scene.geom_name_map[prim_geom] = oldname;
1809
1810
1811
1812
1813 m_taintshape = false;
1814 }
1815 public override bool IsPhysical
1816 {
1817 get { return m_isphysical; }
1818 set{ m_isphysical = value;}
1819 }
1820 public void setPrimForRemoval()
1821 {
1822 m_taintremove = true;
1621 } 1823 }
1622 1824
1623 public override bool Flying 1825 public override bool Flying
@@ -1656,36 +1858,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1656 set 1858 set
1657 { 1859 {
1658 _position = value; 1860 _position = value;
1659 lock (OdeScene.OdeLock) 1861
1660 {
1661 if (m_isphysical)
1662 {
1663 // This is a fallback.. May no longer be necessary.
1664 if (Body == (IntPtr)0)
1665 enableBody();
1666 //Prim auto disable after 20 frames,
1667 ///if you move it, re-enable the prim manually.
1668 d.BodyEnable(Body);
1669 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
1670 }
1671 else
1672 {
1673 string primScenAvatarIn = _parent_scene.whichspaceamIin(_position);
1674 int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
1675 if (primScenAvatarIn == "0")
1676 {
1677 OpenSim.Framework.Console.MainLog.Instance.Verbose("Physics", "Prim " + m_primName + " in space with no prim: " + primScenAvatarIn + ". Expected to be at: " + m_targetSpace.ToString() + " . Arr:': " + arrayitem[0].ToString() + "," + arrayitem[1].ToString());
1678 }
1679 else
1680 {
1681 OpenSim.Framework.Console.MainLog.Instance.Verbose("Physics", "Prim " + m_primName + " in Prim space with prim: " + primScenAvatarIn + ". Expected to be at: " + m_targetSpace.ToString() + ". Arr:" + arrayitem[0].ToString() + "," + arrayitem[1].ToString());
1682 }
1683 m_targetSpace = _parent_scene.recalculateSpaceForGeom(prim_geom, _position, m_targetSpace);
1684 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1685 d.SpaceAdd(m_targetSpace, prim_geom);
1686 }
1687
1688 }
1689 } 1862 }
1690 } 1863 }
1691 1864
@@ -1695,78 +1868,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1695 set 1868 set
1696 { 1869 {
1697 _size = value; 1870 _size = value;
1698 lock (OdeScene.OdeLock) 1871
1699 {
1700 string oldname = _parent_scene.geom_name_map[prim_geom];
1701
1702 // Cleanup of old prim geometry
1703 if (_mesh != null)
1704 {
1705 // Cleanup meshing here
1706 }
1707 //kill body to rebuild
1708 if (IsPhysical && Body != (IntPtr)0)
1709 {
1710 disableBody();
1711 }
1712 if (d.SpaceQuery(m_targetSpace,prim_geom)) {
1713 d.SpaceRemove(m_targetSpace,prim_geom);
1714 }
1715 d.GeomDestroy(prim_geom);
1716
1717 // we don't need to do space calculation because the client sends a position update also.
1718
1719 // Construction of new prim
1720 if (this._parent_scene.needsMeshing(_pbs))
1721 {
1722
1723
1724 // Don't need to re-enable body.. it's done in SetMesh
1725 IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size);
1726 // createmesh returns null when it's a shape that isn't a cube.
1727 if (mesh != null)
1728 {
1729 setMesh(_parent_scene, mesh);
1730 }
1731 else
1732 {
1733 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
1734 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1735 d.Quaternion myrot = new d.Quaternion();
1736 myrot.W = _orientation.w;
1737 myrot.X = _orientation.x;
1738 myrot.Y = _orientation.y;
1739 myrot.Z = _orientation.z;
1740 d.GeomSetQuaternion(prim_geom, ref myrot);
1741
1742
1743 }
1744 } else {
1745 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
1746 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1747 d.Quaternion myrot = new d.Quaternion();
1748 myrot.W = _orientation.w;
1749 myrot.X = _orientation.x;
1750 myrot.Y = _orientation.y;
1751 myrot.Z = _orientation.z;
1752 d.GeomSetQuaternion(prim_geom, ref myrot);
1753
1754
1755 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
1756 if (IsPhysical && Body == (IntPtr)0)
1757 {
1758 // Re creates body on size.
1759 // EnableBody also does setMass()
1760 enableBody();
1761 d.BodyEnable(Body);
1762 }
1763
1764 }
1765
1766
1767 _parent_scene.geom_name_map[prim_geom] = oldname;
1768
1769 }
1770 } 1872 }
1771 } 1873 }
1772 1874
@@ -1775,58 +1877,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1775 set 1877 set
1776 { 1878 {
1777 _pbs = value; 1879 _pbs = value;
1778 lock (OdeScene.OdeLock) 1880
1779 {
1780 string oldname = _parent_scene.geom_name_map[prim_geom];
1781
1782 // Cleanup of old prim geometry and Bodies
1783 if (IsPhysical && Body != (IntPtr)0)
1784 {
1785 disableBody();
1786 }
1787 d.GeomDestroy(prim_geom);
1788 if (_mesh != null)
1789 {
1790
1791 d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
1792
1793 }
1794
1795 // Construction of new prim
1796 if (this._parent_scene.needsMeshing(_pbs))
1797 {
1798 IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size);
1799 if (mesh != null)
1800 {
1801 setMesh(_parent_scene, mesh);
1802 }
1803 else
1804 {
1805 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
1806 }
1807 } else {
1808 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
1809 }
1810 if (IsPhysical && Body == (IntPtr)0)
1811 {
1812 //re-create new body
1813 enableBody();
1814 }
1815 else
1816 {
1817 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1818 d.Quaternion myrot = new d.Quaternion();
1819 myrot.W = _orientation.w;
1820 myrot.X = _orientation.x;
1821 myrot.Y = _orientation.y;
1822 myrot.Z = _orientation.z;
1823 d.GeomSetQuaternion(prim_geom, ref myrot);
1824 }
1825 _parent_scene.geom_name_map[prim_geom] = oldname;
1826
1827
1828
1829 }
1830 } 1881 }
1831 } 1882 }
1832 1883
@@ -1856,19 +1907,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1856 set 1907 set
1857 { 1908 {
1858 _orientation = value; 1909 _orientation = value;
1859 lock (OdeScene.OdeLock) 1910
1860 {
1861 d.Quaternion myrot = new d.Quaternion();
1862 myrot.W = _orientation.w;
1863 myrot.X = _orientation.x;
1864 myrot.Y = _orientation.y;
1865 myrot.Z = _orientation.z;
1866 d.GeomSetQuaternion(prim_geom, ref myrot);
1867 if (m_isphysical && Body != (IntPtr)0)
1868 {
1869 d.BodySetQuaternion(Body, ref myrot);
1870 }
1871 }
1872 } 1911 }
1873 } 1912 }
1874 1913
@@ -1886,10 +1925,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1886 public override void AddForce(PhysicsVector force) 1925 public override void AddForce(PhysicsVector force)
1887 { 1926 {
1888 } 1927 }
1889 public void Move(float timestep) 1928
1890 {
1891
1892 }
1893 public override PhysicsVector RotationalVelocity 1929 public override PhysicsVector RotationalVelocity
1894 { 1930 {
1895 get{ return m_rotationalVelocity;} 1931 get{ return m_rotationalVelocity;}
@@ -1928,18 +1964,19 @@ namespace OpenSim.Region.Physics.OdePlugin
1928 1964
1929 1965
1930 1966
1931 IsPhysical = false; 1967 //IsPhysical = false;
1968 base.RaiseOutOfBounds(_position);
1932 _velocity.X = 0; 1969 _velocity.X = 0;
1933 _velocity.Y = 0; 1970 _velocity.Y = 0;
1934 _velocity.Z = 0; 1971 _velocity.Z = 0;
1935 m_rotationalVelocity.X = 0; 1972 m_rotationalVelocity.X = 0;
1936 m_rotationalVelocity.Y = 0; 1973 m_rotationalVelocity.Y = 0;
1937 m_rotationalVelocity.Z = 0; 1974 m_rotationalVelocity.Z = 0;
1938 //base.RequestPhysicsterseUpdate(); 1975 base.RequestPhysicsterseUpdate();
1939 m_throttleUpdates = false; 1976 m_throttleUpdates = false;
1940 throttleCounter = 0; 1977 throttleCounter = 0;
1941 _zeroFlag = true; 1978 _zeroFlag = true;
1942 outofBounds = true; 1979 //outofBounds = true;
1943 } 1980 }
1944 1981
1945 if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02) 1982 if ((Math.Abs(m_lastposition.X - l_position.X) < 0.02)