aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/PhysicsModules')
-rw-r--r--OpenSim/Region/PhysicsModules/BulletS/BSScene.cs19
-rw-r--r--OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs53
-rw-r--r--OpenSim/Region/PhysicsModules/Ode/OdeScene.cs31
-rw-r--r--OpenSim/Region/PhysicsModules/SharedBase/PhysicsActor.cs23
-rw-r--r--OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs9
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs52
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs179
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs15
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs283
-rw-r--r--OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs87
-rw-r--r--OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMap.cs20
11 files changed, 429 insertions, 342 deletions
diff --git a/OpenSim/Region/PhysicsModules/BulletS/BSScene.cs b/OpenSim/Region/PhysicsModules/BulletS/BSScene.cs
index 9b677be..ee57f0c 100644
--- a/OpenSim/Region/PhysicsModules/BulletS/BSScene.cs
+++ b/OpenSim/Region/PhysicsModules/BulletS/BSScene.cs
@@ -954,25 +954,6 @@ namespace OpenSim.Region.PhysicsModule.BulletS
954 // m_log.DebugFormat("{0}: DeleteTerrain()", LogHeader); 954 // m_log.DebugFormat("{0}: DeleteTerrain()", LogHeader);
955 } 955 }
956 956
957 // Although no one seems to check this, I do support combining.
958 public override bool SupportsCombining()
959 {
960 return TerrainManager.SupportsCombining();
961 }
962 // This call says I am a child to region zero in a mega-region. 'pScene' is that
963 // of region zero, 'offset' is my offset from regions zero's origin, and
964 // 'extents' is the largest XY that is handled in my region.
965 public override void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents)
966 {
967 TerrainManager.Combine(pScene, offset, extents);
968 }
969
970 // Unhook all the combining that I know about.
971 public override void UnCombine(PhysicsScene pScene)
972 {
973 TerrainManager.UnCombine(pScene);
974 }
975
976 #endregion // Terrain 957 #endregion // Terrain
977 958
978 public override Dictionary<uint, float> GetTopColliders() 959 public override Dictionary<uint, float> GetTopColliders()
diff --git a/OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs b/OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs
index b0bbfb9..72f2d6d 100644
--- a/OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs
+++ b/OpenSim/Region/PhysicsModules/ConvexDecompositionDotNet/HullUtils.cs
@@ -1074,14 +1074,27 @@ namespace OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet
1074 public static int maxdirfiltered(List<float3> p, int count, float3 dir, byte[] allow) 1074 public static int maxdirfiltered(List<float3> p, int count, float3 dir, byte[] allow)
1075 { 1075 {
1076 //Debug.Assert(count != 0); 1076 //Debug.Assert(count != 0);
1077 int m = 0; 1077 int m = -1;
1078 float currDotm = float3.dot(p[0], dir); 1078 float currDotm = 0;
1079 float currDoti; 1079 float currDoti;
1080 1080
1081 while (allow[m] == 0) 1081 for (int i = 0; i < count; i++)
1082 m++; 1082 {
1083 if (allow[i] != 0)
1084 {
1085 currDotm = float3.dot(p[i], dir);
1086 m = i;
1087 break;
1088 }
1089 }
1083 1090
1084 for (int i = 1; i < count; i++) 1091 if(m == -1)
1092 {
1093 Debug.Assert(false);
1094 return m;
1095 }
1096
1097 for (int i = m + 1; i < count; i++)
1085 { 1098 {
1086 if (allow[i] != 0) 1099 if (allow[i] != 0)
1087 { 1100 {
@@ -1093,7 +1106,8 @@ namespace OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet
1093 } 1106 }
1094 } 1107 }
1095 } 1108 }
1096 //Debug.Assert(m != -1); 1109
1110// Debug.Assert(m != -1);
1097 return m; 1111 return m;
1098 } 1112 }
1099 1113
@@ -1112,8 +1126,8 @@ namespace OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet
1112 { 1126 {
1113 int mb; 1127 int mb;
1114 { 1128 {
1115 float s = (float)Math.Sin((3.14159264f / 180.0f) * (x)); 1129 float s = (float)Math.Sin(0.01745329f * x);
1116 float c = (float)Math.Cos((3.14159264f / 180.0f) * (x)); 1130 float c = (float)Math.Cos(0.01745329f * x);
1117 mb = maxdirfiltered(p, count, dir + (u * s + v * c) * 0.025f, allow); 1131 mb = maxdirfiltered(p, count, dir + (u * s + v * c) * 0.025f, allow);
1118 } 1132 }
1119 if (ma == m && mb == m) 1133 if (ma == m && mb == m)
@@ -1126,8 +1140,8 @@ namespace OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet
1126 int mc = ma; 1140 int mc = ma;
1127 for (float xx = x - 40.0f; xx <= x; xx += 5.0f) 1141 for (float xx = x - 40.0f; xx <= x; xx += 5.0f)
1128 { 1142 {
1129 float s = (float)Math.Sin((3.14159264f / 180.0f) * (xx)); 1143 float s = (float)Math.Sin(0.01745329f * xx);
1130 float c = (float)Math.Cos((3.14159264f / 180.0f) * (xx)); 1144 float c = (float)Math.Cos(0.01745329f * xx);
1131 int md = maxdirfiltered(p, count, dir + (u * s + v * c) * 0.025f, allow); 1145 int md = maxdirfiltered(p, count, dir + (u * s + v * c) * 0.025f, allow);
1132 if (mc == m && md == m) 1146 if (mc == m && md == m)
1133 { 1147 {
@@ -1176,7 +1190,7 @@ namespace OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet
1176 Debug.Assert(!(p0 == p1 || p0 == p2 || p0 == p3 || p1 == p2 || p1 == p3 || p2 == p3)); 1190 Debug.Assert(!(p0 == p1 || p0 == p2 || p0 == p3 || p1 == p2 || p1 == p3 || p2 == p3));
1177 if (float3.dot(verts[p3] - verts[p0], float3.cross(verts[p1] - verts[p0], verts[p2] - verts[p0])) < 0) 1191 if (float3.dot(verts[p3] - verts[p0], float3.cross(verts[p1] - verts[p0], verts[p2] - verts[p0])) < 0)
1178 { 1192 {
1179 Swap(ref p2, ref p3); 1193 return new int4(p0, p1, p3, p2);
1180 } 1194 }
1181 return new int4(p0, p1, p2, p3); 1195 return new int4(p0, p1, p2, p3);
1182 } 1196 }
@@ -1207,12 +1221,12 @@ namespace OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet
1207 int j; 1221 int j;
1208 float3 bmin = new float3(verts[0]); 1222 float3 bmin = new float3(verts[0]);
1209 float3 bmax = new float3(verts[0]); 1223 float3 bmax = new float3(verts[0]);
1210 List<int> isextreme = new List<int>(verts.Count); 1224 byte[] isextreme = new byte[verts.Count];
1211 byte[] allow = new byte[verts.Count]; 1225 byte[] allow = new byte[verts.Count];
1212 for (j = 0; j < verts.Count; j++) 1226 for (j = 0; j < verts.Count; j++)
1213 { 1227 {
1214 allow[j] = 1; 1228 allow[j] = 1;
1215 isextreme.Add(0); 1229 isextreme[j] = 0;
1216 bmin = float3.VectorMin(bmin, verts[j]); 1230 bmin = float3.VectorMin(bmin, verts[j]);
1217 bmax = float3.VectorMax(bmax, verts[j]); 1231 bmax = float3.VectorMax(bmax, verts[j]);
1218 } 1232 }
@@ -1526,6 +1540,19 @@ namespace OpenSim.Region.PhysicsModules.ConvexDecompositionDotNet
1526 } 1540 }
1527 } 1541 }
1528 1542
1543 public static bool ComputeHull(List<float3> vertices, out List<int> indices)
1544 {
1545 List<HullTriangle> tris = new List<HullTriangle>();
1546
1547 bool ret = calchull(vertices, out indices, 0, tris);
1548 if (ret == false)
1549 {
1550 indices = new List<int>();
1551 return false;
1552 }
1553 return true;
1554 }
1555
1529 private static bool CleanupVertices(List<float3> svertices, out List<float3> vertices, float normalepsilon, out float3 scale) 1556 private static bool CleanupVertices(List<float3> svertices, out List<float3> vertices, float normalepsilon, out float3 scale)
1530 { 1557 {
1531 const float EPSILON = 0.000001f; 1558 const float EPSILON = 0.000001f;
diff --git a/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
index 8f9bccb..ed2aad4 100644
--- a/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
+++ b/OpenSim/Region/PhysicsModules/Ode/OdeScene.cs
@@ -258,8 +258,6 @@ namespace OpenSim.Region.PhysicsModule.ODE
258 258
259 private Random fluidRandomizer = new Random(Environment.TickCount); 259 private Random fluidRandomizer = new Random(Environment.TickCount);
260 260
261 public bool m_suportCombine = true;
262
263 private uint m_regionWidth = Constants.RegionSize; 261 private uint m_regionWidth = Constants.RegionSize;
264 private uint m_regionHeight = Constants.RegionSize; 262 private uint m_regionHeight = Constants.RegionSize;
265 263
@@ -542,8 +540,6 @@ namespace OpenSim.Region.PhysicsModule.ODE
542 WorldExtents.Y = regionExtent.Y; 540 WorldExtents.Y = regionExtent.Y;
543 m_regionHeight = (uint)regionExtent.Y; 541 m_regionHeight = (uint)regionExtent.Y;
544 542
545 m_suportCombine = false;
546
547 nearCallback = near; 543 nearCallback = near;
548 m_rayCastManager = new ODERayCastRequestManager(this); 544 m_rayCastManager = new ODERayCastRequestManager(this);
549 545
@@ -1627,15 +1623,6 @@ namespace OpenSim.Region.PhysicsModule.ODE
1627 1623
1628 #endregion 1624 #endregion
1629 1625
1630 public override void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents)
1631 {
1632 if (!m_suportCombine)
1633 return;
1634 m_worldOffset = offset;
1635 WorldExtents = new Vector2(extents.X, extents.Y);
1636 m_parentScene = pScene;
1637 }
1638
1639 // Recovered for use by fly height. Kitto Flora 1626 // Recovered for use by fly height. Kitto Flora
1640 internal float GetTerrainHeightAtXY(float x, float y) 1627 internal float GetTerrainHeightAtXY(float x, float y)
1641 { 1628 {
@@ -1643,12 +1630,6 @@ namespace OpenSim.Region.PhysicsModule.ODE
1643 int offsetX = 0; 1630 int offsetX = 0;
1644 int offsetY = 0; 1631 int offsetY = 0;
1645 1632
1646 if (m_suportCombine)
1647 {
1648 offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1649 offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1650 }
1651
1652 if(RegionTerrain.TryGetValue(new Vector3(offsetX,offsetY,0), out heightFieldGeom)) 1633 if(RegionTerrain.TryGetValue(new Vector3(offsetX,offsetY,0), out heightFieldGeom))
1653 { 1634 {
1654 if (heightFieldGeom != IntPtr.Zero) 1635 if (heightFieldGeom != IntPtr.Zero)
@@ -3387,11 +3368,6 @@ namespace OpenSim.Region.PhysicsModule.ODE
3387 return waterlevel; 3368 return waterlevel;
3388 } 3369 }
3389 3370
3390 public override bool SupportsCombining()
3391 {
3392 return m_suportCombine;
3393 }
3394
3395 public override void SetWaterLevel(float baseheight) 3371 public override void SetWaterLevel(float baseheight)
3396 { 3372 {
3397 waterlevel = baseheight; 3373 waterlevel = baseheight;
@@ -3452,6 +3428,11 @@ namespace OpenSim.Region.PhysicsModule.ODE
3452 } 3428 }
3453 } 3429 }
3454 3430
3431 private int compareByCollisionsDesc(OdePrim A, OdePrim B)
3432 {
3433 return -A.CollisionScore.CompareTo(B.CollisionScore);
3434 }
3435
3455 public override Dictionary<uint, float> GetTopColliders() 3436 public override Dictionary<uint, float> GetTopColliders()
3456 { 3437 {
3457 Dictionary<uint, float> topColliders; 3438 Dictionary<uint, float> topColliders;
@@ -3459,7 +3440,7 @@ namespace OpenSim.Region.PhysicsModule.ODE
3459 lock (_prims) 3440 lock (_prims)
3460 { 3441 {
3461 List<OdePrim> orderedPrims = new List<OdePrim>(_prims); 3442 List<OdePrim> orderedPrims = new List<OdePrim>(_prims);
3462 orderedPrims.OrderByDescending(p => p.CollisionScore); 3443 orderedPrims.Sort(compareByCollisionsDesc);
3463 topColliders = orderedPrims.Take(25).ToDictionary(p => p.LocalID, p => p.CollisionScore); 3444 topColliders = orderedPrims.Take(25).ToDictionary(p => p.LocalID, p => p.CollisionScore);
3464 3445
3465 foreach (OdePrim p in _prims) 3446 foreach (OdePrim p in _prims)
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsActor.cs b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsActor.cs
index 04ccbf0..250b155 100644
--- a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsActor.cs
+++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsActor.cs
@@ -55,6 +55,14 @@ namespace OpenSim.Region.PhysicsModules.SharedBase
55 Absolute 55 Absolute
56 } 56 }
57 57
58 public struct CameraData
59 {
60 public Quaternion CameraRotation;
61 public Vector3 CameraAtAxis;
62 public bool MouseLook;
63 public bool Valid;
64 }
65
58 public struct ContactPoint 66 public struct ContactPoint
59 { 67 {
60 public Vector3 Position; 68 public Vector3 Position;
@@ -159,13 +167,15 @@ namespace OpenSim.Region.PhysicsModules.SharedBase
159 public delegate void RequestTerseUpdate(); 167 public delegate void RequestTerseUpdate();
160 public delegate void CollisionUpdate(EventArgs e); 168 public delegate void CollisionUpdate(EventArgs e);
161 public delegate void OutOfBounds(Vector3 pos); 169 public delegate void OutOfBounds(Vector3 pos);
170 public delegate CameraData GetCameraData();
162 171
163// disable warning: public events 172 // disable warning: public events
164#pragma warning disable 67 173#pragma warning disable 67
165 public event PositionUpdate OnPositionUpdate; 174 public event PositionUpdate OnPositionUpdate;
166 public event VelocityUpdate OnVelocityUpdate; 175 public event VelocityUpdate OnVelocityUpdate;
167 public event OrientationUpdate OnOrientationUpdate; 176 public event OrientationUpdate OnOrientationUpdate;
168 public event RequestTerseUpdate OnRequestTerseUpdate; 177 public event RequestTerseUpdate OnRequestTerseUpdate;
178 public event GetCameraData OnPhysicsRequestingCameraData;
169 179
170 /// <summary> 180 /// <summary>
171 /// Subscribers to this event must synchronously handle the dictionary of collisions received, since the event 181 /// Subscribers to this event must synchronously handle the dictionary of collisions received, since the event
@@ -176,6 +186,17 @@ namespace OpenSim.Region.PhysicsModules.SharedBase
176 public event OutOfBounds OnOutOfBounds; 186 public event OutOfBounds OnOutOfBounds;
177#pragma warning restore 67 187#pragma warning restore 67
178 188
189 public CameraData TryGetCameraData()
190 {
191 GetCameraData handler = OnPhysicsRequestingCameraData;
192 if (handler != null)
193 {
194 return handler();
195 }
196
197 return new CameraData { Valid = false };
198 }
199
179 public static PhysicsActor Null 200 public static PhysicsActor Null
180 { 201 {
181 get { return new NullPhysicsActor(); } 202 get { return new NullPhysicsActor(); }
diff --git a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs
index 65d8867..aa51c4e 100644
--- a/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs
+++ b/OpenSim/Region/PhysicsModules/SharedBase/PhysicsScene.cs
@@ -332,15 +332,6 @@ namespace OpenSim.Region.PhysicsModules.SharedBase
332 return false; 332 return false;
333 } 333 }
334 334
335 public virtual bool SupportsCombining()
336 {
337 return false;
338 }
339
340 public virtual void Combine(PhysicsScene pScene, Vector3 offset, Vector3 extents) {}
341 public virtual void CombineTerrain(float[] heightMap, Vector3 pOffset) {}
342 public virtual void UnCombine(PhysicsScene pScene) {}
343
344 /// <summary> 335 /// <summary>
345 /// Queue a raycast against the physics scene. 336 /// Queue a raycast against the physics scene.
346 /// The provided callback method will be called when the raycast is complete 337 /// The provided callback method will be called when the raycast is complete
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs b/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs
index c9489d2..3a5a936 100644
--- a/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs
@@ -122,8 +122,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
122 private float m_buoyancy = 0f; 122 private float m_buoyancy = 0f;
123 123
124 private bool m_freemove = false; 124 private bool m_freemove = false;
125 // private CollisionLocker ode; 125
126
127// private string m_name = String.Empty; 126// private string m_name = String.Empty;
128 // other filter control 127 // other filter control
129 int m_colliderfilter = 0; 128 int m_colliderfilter = 0;
@@ -1571,11 +1570,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1571 { 1570 {
1572 if (CollisionEventsThisFrame != null) 1571 if (CollisionEventsThisFrame != null)
1573 { 1572 {
1574 lock (CollisionEventsThisFrame) 1573 CollisionEventsThisFrame.Clear();
1575 { 1574 CollisionEventsThisFrame = null;
1576 CollisionEventsThisFrame.Clear();
1577 CollisionEventsThisFrame = null;
1578 }
1579 } 1575 }
1580 m_eventsubscription = 0; 1576 m_eventsubscription = 0;
1581 _parent_scene.RemoveCollisionEventReporting(this); 1577 _parent_scene.RemoveCollisionEventReporting(this);
@@ -1585,11 +1581,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1585 { 1581 {
1586 if (CollisionEventsThisFrame == null) 1582 if (CollisionEventsThisFrame == null)
1587 CollisionEventsThisFrame = new CollisionEventUpdate(); 1583 CollisionEventsThisFrame = new CollisionEventUpdate();
1588 lock (CollisionEventsThisFrame) 1584 CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
1589 { 1585 _parent_scene.AddCollisionEventReporting(this);
1590 CollisionEventsThisFrame.AddCollider(CollidedWith, contact);
1591 _parent_scene.AddCollisionEventReporting(this);
1592 }
1593 } 1586 }
1594 1587
1595 public void SendCollisions(int timestep) 1588 public void SendCollisions(int timestep)
@@ -1600,28 +1593,25 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1600 if (CollisionEventsThisFrame == null) 1593 if (CollisionEventsThisFrame == null)
1601 return; 1594 return;
1602 1595
1603 lock (CollisionEventsThisFrame) 1596 if (m_cureventsubscription < m_eventsubscription)
1604 { 1597 return;
1605 if (m_cureventsubscription < m_eventsubscription)
1606 return;
1607 1598
1608 int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count; 1599 int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count;
1609 1600
1610 if (!SentEmptyCollisionsEvent || ncolisions > 0) 1601 if (!SentEmptyCollisionsEvent || ncolisions > 0)
1611 { 1602 {
1612 base.SendCollisionUpdate(CollisionEventsThisFrame); 1603 base.SendCollisionUpdate(CollisionEventsThisFrame);
1613 m_cureventsubscription = 0; 1604 m_cureventsubscription = 0;
1614 1605
1615 if (ncolisions == 0) 1606 if (ncolisions == 0)
1616 { 1607 {
1617 SentEmptyCollisionsEvent = true; 1608 SentEmptyCollisionsEvent = true;
1618// _parent_scene.RemoveCollisionEventReporting(this); 1609// _parent_scene.RemoveCollisionEventReporting(this);
1619 } 1610 }
1620 else 1611 else
1621 { 1612 {
1622 SentEmptyCollisionsEvent = false; 1613 SentEmptyCollisionsEvent = false;
1623 CollisionEventsThisFrame.Clear(); 1614 CollisionEventsThisFrame.Clear();
1624 }
1625 } 1615 }
1626 } 1616 }
1627 } 1617 }
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs
index d8a2272..fa32441 100644
--- a/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODEDynamics.cs
@@ -648,6 +648,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde
648 break; 648 break;
649 649
650 } 650 }
651 // disable mouse steering
652 m_flags &= ~(VehicleFlag.MOUSELOOK_STEER |
653 VehicleFlag.MOUSELOOK_BANK |
654 VehicleFlag.CAMERA_DECOUPLED);
651 655
652 m_lmDecay = (1.0f - 1.0f / m_linearMotorDecayTimescale); 656 m_lmDecay = (1.0f - 1.0f / m_linearMotorDecayTimescale);
653 m_amDecay = 1.0f - 1.0f / m_angularMotorDecayTimescale; 657 m_amDecay = 1.0f - 1.0f / m_angularMotorDecayTimescale;
@@ -794,6 +798,28 @@ namespace OpenSim.Region.PhysicsModule.ubOde
794 798
795 float ldampZ = 0; 799 float ldampZ = 0;
796 800
801 bool mousemode = false;
802 bool mousemodebank = false;
803
804 float bankingEfficiency;
805 float verticalAttractionTimescale = m_verticalAttractionTimescale;
806
807 if((m_flags & (VehicleFlag.MOUSELOOK_STEER | VehicleFlag.MOUSELOOK_BANK)) != 0 )
808 {
809 mousemode = true;
810 mousemodebank = (m_flags & VehicleFlag.MOUSELOOK_BANK) != 0;
811 if(mousemodebank)
812 {
813 bankingEfficiency = m_bankingEfficiency;
814 if(verticalAttractionTimescale < 149.9)
815 verticalAttractionTimescale *= 2.0f; // reduce current instability
816 }
817 else
818 bankingEfficiency = 0;
819 }
820 else
821 bankingEfficiency = m_bankingEfficiency;
822
797 // linear motor 823 // linear motor
798 if (m_lmEfect > 0.01 && m_linearMotorTimescale < 1000) 824 if (m_lmEfect > 0.01 && m_linearMotorTimescale < 1000)
799 { 825 {
@@ -930,12 +956,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
930 } 956 }
931 957
932 // vertical atractor 958 // vertical atractor
933 if (m_verticalAttractionTimescale < 300) 959 if (verticalAttractionTimescale < 300)
934 { 960 {
935 float roll; 961 float roll;
936 float pitch; 962 float pitch;
937 963
938 float ftmp = m_invtimestep / m_verticalAttractionTimescale / m_verticalAttractionTimescale; 964 float ftmp = m_invtimestep / verticalAttractionTimescale / verticalAttractionTimescale;
939 965
940 float ftmp2; 966 float ftmp2;
941 ftmp2 = 0.5f * m_verticalAttractionEfficiency * m_invtimestep; 967 ftmp2 = 0.5f * m_verticalAttractionEfficiency * m_invtimestep;
@@ -967,7 +993,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
967 torque.Y += effpitch * ftmp; 993 torque.Y += effpitch * ftmp;
968 } 994 }
969 995
970 if (m_bankingEfficiency != 0 && Math.Abs(effroll) > 0.01) 996 if (bankingEfficiency != 0 && Math.Abs(effroll) > 0.01)
971 { 997 {
972 998
973 float broll = effroll; 999 float broll = effroll;
@@ -1018,58 +1044,129 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1018 m_amdampZ = 1 / m_angularFrictionTimescale.Z; 1044 m_amdampZ = 1 / m_angularFrictionTimescale.Z;
1019 } 1045 }
1020 1046
1021 // angular motor 1047 if(mousemode)
1022 if (m_amEfect > 0.01 && m_angularMotorTimescale < 1000)
1023 { 1048 {
1024 tmpV = m_angularMotorDirection - curLocalAngVel; // velocity error 1049 CameraData cam = rootPrim.TryGetCameraData();
1025 tmpV *= m_amEfect / m_angularMotorTimescale; // error to correct in this timestep 1050 if(cam.Valid && cam.MouseLook)
1026 torque.X += tmpV.X * m_ampwr; 1051 {
1027 torque.Y += tmpV.Y * m_ampwr; 1052 Vector3 dirv = cam.CameraAtAxis * irotq;
1028 torque.Z += tmpV.Z;
1029 1053
1030 m_amEfect *= m_amDecay; 1054 float invamts = 1.0f/m_angularMotorTimescale;
1031 } 1055 float tmp;
1032 else
1033 m_amEfect = 0;
1034 1056
1035 // angular deflection 1057 // get out of x == 0 plane
1036 if (m_angularDeflectionEfficiency > 0) 1058 if(Math.Abs(dirv.X) < 0.001f)
1037 { 1059 dirv.X = 0.001f;
1038 Vector3 dirv; 1060
1039 1061 if (Math.Abs(dirv.Z) > 0.01)
1040 if (curLocalVel.X > 0.01f) 1062 {
1041 dirv = curLocalVel; 1063 tmp = -(float)Math.Atan2(dirv.Z, dirv.X) * m_angularMotorDirection.Y;
1042 else if (curLocalVel.X < -0.01f) 1064 if(tmp < -4f)
1043 // use oposite 1065 tmp = -4f;
1044 dirv = -curLocalVel; 1066 else if(tmp > 4f)
1067 tmp = 4f;
1068 torque.Y += (tmp - curLocalAngVel.Y) * invamts;
1069 torque.Y -= curLocalAngVel.Y * m_amdampY;
1070 }
1071 else
1072 torque.Y -= curLocalAngVel.Y * m_invtimestep;
1073
1074 if (Math.Abs(dirv.Y) > 0.01)
1075 {
1076 if(mousemodebank)
1077 {
1078 tmp = -(float)Math.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.X;
1079 if(tmp < -4f)
1080 tmp = -4f;
1081 else if(tmp > 4f)
1082 tmp = 4f;
1083 torque.X += (tmp - curLocalAngVel.X) * invamts;
1084 }
1085 else
1086 {
1087 tmp = (float)Math.Atan2(dirv.Y, dirv.X) * m_angularMotorDirection.Z;
1088 tmp *= invamts;
1089 if(tmp < -4f)
1090 tmp = -4f;
1091 else if(tmp > 4f)
1092 tmp = 4f;
1093 torque.Z += (tmp - curLocalAngVel.Z) * invamts;
1094 }
1095 torque.X -= curLocalAngVel.X * m_amdampX;
1096 torque.Z -= curLocalAngVel.Z * m_amdampZ;
1097 }
1098 else
1099 {
1100 if(mousemodebank)
1101 torque.X -= curLocalAngVel.X * m_invtimestep;
1102 else
1103 torque.Z -= curLocalAngVel.Z * m_invtimestep;
1104 }
1105 }
1045 else 1106 else
1046 { 1107 {
1047 // make it fall into small positive x case 1108 if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0)
1048 dirv.X = 0.01f; 1109 {
1049 dirv.Y = curLocalVel.Y; 1110 torque.X -= curLocalAngVel.X * 10f;
1050 dirv.Z = curLocalVel.Z; 1111 torque.Y -= curLocalAngVel.Y * 10f;
1112 torque.Z -= curLocalAngVel.Z * 10f;
1113 }
1051 } 1114 }
1115 }
1116 else
1117 {
1118 // angular motor
1119 if (m_amEfect > 0.01 && m_angularMotorTimescale < 1000)
1120 {
1121 tmpV = m_angularMotorDirection - curLocalAngVel; // velocity error
1122 tmpV *= m_amEfect / m_angularMotorTimescale; // error to correct in this timestep
1123 torque.X += tmpV.X * m_ampwr;
1124 torque.Y += tmpV.Y * m_ampwr;
1125 torque.Z += tmpV.Z;
1052 1126
1053 float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale; 1127 m_amEfect *= m_amDecay;
1128 }
1129 else
1130 m_amEfect = 0;
1054 1131
1055 if (Math.Abs(dirv.Z) > 0.01) 1132 // angular deflection
1133 if (m_angularDeflectionEfficiency > 0)
1056 { 1134 {
1057 torque.Y += - (float)Math.Atan2(dirv.Z, dirv.X) * ftmp; 1135 Vector3 dirv;
1136
1137 if (curLocalVel.X > 0.01f)
1138 dirv = curLocalVel;
1139 else if (curLocalVel.X < -0.01f)
1140 // use oposite
1141 dirv = -curLocalVel;
1142 else
1143 {
1144 // make it fall into small positive x case
1145 dirv.X = 0.01f;
1146 dirv.Y = curLocalVel.Y;
1147 dirv.Z = curLocalVel.Z;
1148 }
1149
1150 float ftmp = m_angularDeflectionEfficiency / m_angularDeflectionTimescale;
1151
1152 if (Math.Abs(dirv.Z) > 0.01)
1153 {
1154 torque.Y += - (float)Math.Atan2(dirv.Z, dirv.X) * ftmp;
1155 }
1156
1157 if (Math.Abs(dirv.Y) > 0.01)
1158 {
1159 torque.Z += (float)Math.Atan2(dirv.Y, dirv.X) * ftmp;
1160 }
1058 } 1161 }
1059 1162
1060 if (Math.Abs(dirv.Y) > 0.01) 1163 if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0)
1061 { 1164 {
1062 torque.Z += (float)Math.Atan2(dirv.Y, dirv.X) * ftmp; 1165 torque.X -= curLocalAngVel.X * m_amdampX;
1166 torque.Y -= curLocalAngVel.Y * m_amdampY;
1167 torque.Z -= curLocalAngVel.Z * m_amdampZ;
1063 } 1168 }
1064 } 1169 }
1065
1066 // angular friction
1067 if (curLocalAngVel.X != 0 || curLocalAngVel.Y != 0 || curLocalAngVel.Z != 0)
1068 {
1069 torque.X -= curLocalAngVel.X * m_amdampX;
1070 torque.Y -= curLocalAngVel.Y * m_amdampY;
1071 torque.Z -= curLocalAngVel.Z * m_amdampZ;
1072 }
1073 1170
1074 force *= dmass.mass; 1171 force *= dmass.mass;
1075 1172
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs
index 6f2cbbe..4adf87e 100644
--- a/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODEPrim.cs
@@ -306,7 +306,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
306 public override uint LocalID 306 public override uint LocalID
307 { 307 {
308 get { return m_localID; } 308 get { return m_localID; }
309 set { m_localID = value; } 309 set
310 {
311 uint oldid = m_localID;
312 m_localID = value;
313 _parent_scene.changePrimID(this, oldid);
314 }
310 } 315 }
311 316
312 public override PhysicsActor ParentActor 317 public override PhysicsActor ParentActor
@@ -1066,8 +1071,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1066 public OdePrim(String primName, ODEScene parent_scene, Vector3 pos, Vector3 size, 1071 public OdePrim(String primName, ODEScene parent_scene, Vector3 pos, Vector3 size,
1067 Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical,bool pisPhantom,byte _shapeType,uint plocalID) 1072 Quaternion rotation, PrimitiveBaseShape pbs, bool pisPhysical,bool pisPhantom,byte _shapeType,uint plocalID)
1068 { 1073 {
1074 _parent_scene = parent_scene;
1075
1069 Name = primName; 1076 Name = primName;
1070 LocalID = plocalID; 1077 m_localID = plocalID;
1071 1078
1072 m_vehicle = null; 1079 m_vehicle = null;
1073 1080
@@ -1113,7 +1120,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1113 1120
1114 _pbs = pbs; 1121 _pbs = pbs;
1115 1122
1116 _parent_scene = parent_scene;
1117 m_targetSpace = IntPtr.Zero; 1123 m_targetSpace = IntPtr.Zero;
1118 1124
1119 if (pos.Z < 0) 1125 if (pos.Z < 0)
@@ -1159,6 +1165,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1159 m_OBBOffset = repData.OBBOffset; 1165 m_OBBOffset = repData.OBBOffset;
1160 1166
1161 UpdatePrimBodyData(); 1167 UpdatePrimBodyData();
1168
1169 AddChange(changes.Add, null);
1162 } 1170 }
1163 1171
1164 private void resetCollisionAccounting() 1172 private void resetCollisionAccounting()
@@ -2441,6 +2449,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2441 2449
2442 private void changeadd() 2450 private void changeadd()
2443 { 2451 {
2452 _parent_scene.addToPrims(this);
2444 } 2453 }
2445 2454
2446 private void changeAngularLock(byte newLocks) 2455 private void changeAngularLock(byte newLocks)
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
index 6c5b405..e6aa7ef 100644
--- a/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODEScene.cs
@@ -30,6 +30,7 @@
30 30
31using System; 31using System;
32using System.Collections.Generic; 32using System.Collections.Generic;
33using System.Linq;
33using System.Reflection; 34using System.Reflection;
34using System.Runtime.InteropServices; 35using System.Runtime.InteropServices;
35using System.Threading; 36using System.Threading;
@@ -170,7 +171,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
170 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 171 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
171 172
172 public bool m_OSOdeLib = false; 173 public bool m_OSOdeLib = false;
173 public bool m_suportCombine = false; // mega suport not tested
174 public Scene m_frameWorkScene = null; 174 public Scene m_frameWorkScene = null;
175 175
176// private int threadid = 0; 176// private int threadid = 0;
@@ -258,9 +258,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
258 258
259 public ContactData[] m_materialContactsData = new ContactData[8]; 259 public ContactData[] m_materialContactsData = new ContactData[8];
260 260
261 private Dictionary<Vector3, IntPtr> RegionTerrain = new Dictionary<Vector3, IntPtr>(); 261 private IntPtr TerrainGeom;
262 private Dictionary<IntPtr, float[]> TerrainHeightFieldHeights = new Dictionary<IntPtr, float[]>(); 262 private float[] TerrainHeightFieldHeight;
263 private Dictionary<IntPtr, GCHandle> TerrainHeightFieldHeightsHandlers = new Dictionary<IntPtr, GCHandle>(); 263 private GCHandle TerrainHeightFieldHeightsHandler = new GCHandle();
264 264
265 private int m_physicsiterations = 15; 265 private int m_physicsiterations = 15;
266 private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag 266 private const float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag
@@ -302,9 +302,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
302 public int physics_logging_interval = 0; 302 public int physics_logging_interval = 0;
303 public bool physics_logging_append_existing_logfile = false; 303 public bool physics_logging_append_existing_logfile = false;
304 304
305 private Vector3 m_worldOffset = Vector3.Zero;
306 public Vector2 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize); 305 public Vector2 WorldExtents = new Vector2((int)Constants.RegionSize, (int)Constants.RegionSize);
307 private PhysicsScene m_parentScene = null;
308 306
309 private ODERayCastRequestManager m_rayCastManager; 307 private ODERayCastRequestManager m_rayCastManager;
310 public ODEMeshWorker m_meshWorker; 308 public ODEMeshWorker m_meshWorker;
@@ -379,8 +377,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
379 WorldExtents.Y = m_frameWorkScene.RegionInfo.RegionSizeY; 377 WorldExtents.Y = m_frameWorkScene.RegionInfo.RegionSizeY;
380 m_regionHeight = (uint)WorldExtents.Y; 378 m_regionHeight = (uint)WorldExtents.Y;
381 379
382 m_suportCombine = false;
383
384 lock (OdeLock) 380 lock (OdeLock)
385 { 381 {
386 // Create the world and the first space 382 // Create the world and the first space
@@ -803,14 +799,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
803 return; 799 return;
804 } 800 }
805 801
806 // update actors collision score
807 if (p1.CollisionScore >= float.MaxValue - count)
808 p1.CollisionScore = 0;
809 p1.CollisionScore += count;
810
811 if (p2.CollisionScore >= float.MaxValue - count)
812 p2.CollisionScore = 0;
813 p2.CollisionScore += count;
814 802
815 // get first contact 803 // get first contact
816 d.ContactGeom curContact = new d.ContactGeom(); 804 d.ContactGeom curContact = new d.ContactGeom();
@@ -1056,6 +1044,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1056 { 1044 {
1057 uint obj2LocalID = 0; 1045 uint obj2LocalID = 0;
1058 1046
1047 // update actors collision score
1048 if (p1.CollisionScore < float.MaxValue)
1049 p1.CollisionScore += 1.0f;
1050 if (p2.CollisionScore < float.MaxValue)
1051 p2.CollisionScore += 1.0f;
1052
1059 bool p1events = p1.SubscribedEvents(); 1053 bool p1events = p1.SubscribedEvents();
1060 bool p2events = p2.SubscribedEvents(); 1054 bool p2events = p2.SubscribedEvents();
1061 1055
@@ -1328,8 +1322,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1328 { 1322 {
1329 1323
1330 newPrim = new OdePrim(name, this, position, size, rotation, pbs, isphysical, isPhantom, shapeType, localID); 1324 newPrim = new OdePrim(name, this, position, size, rotation, pbs, isphysical, isPhantom, shapeType, localID);
1331 lock (_prims)
1332 _prims[newPrim.LocalID] = newPrim;
1333 } 1325 }
1334 return newPrim; 1326 return newPrim;
1335 } 1327 }
@@ -1350,7 +1342,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1350 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, 1342 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
1351 Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapeType, uint localid) 1343 Vector3 size, Quaternion rotation, bool isPhysical, bool isPhantom, byte shapeType, uint localid)
1352 { 1344 {
1353
1354 return AddPrim(primName, position, size, rotation, pbs, isPhysical,isPhantom, shapeType, localid); 1345 return AddPrim(primName, position, size, rotation, pbs, isPhysical,isPhantom, shapeType, localid);
1355 } 1346 }
1356 1347
@@ -1396,6 +1387,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1396 1387
1397 } 1388 }
1398 1389
1390 public void addToPrims(OdePrim prim)
1391 {
1392 lock (_prims)
1393 _prims[prim.LocalID] = prim;
1394 }
1395
1399 public OdePrim getPrim(uint id) 1396 public OdePrim getPrim(uint id)
1400 { 1397 {
1401 lock (_prims) 1398 lock (_prims)
@@ -1413,6 +1410,16 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1413 return _prims.ContainsKey(prm.LocalID); 1410 return _prims.ContainsKey(prm.LocalID);
1414 } 1411 }
1415 1412
1413 public void changePrimID(OdePrim prim,uint oldID)
1414 {
1415 lock (_prims)
1416 {
1417 if(_prims.ContainsKey(oldID))
1418 _prims.Remove(oldID);
1419 _prims[prim.LocalID] = prim;
1420 }
1421 }
1422
1416 public bool haveActor(PhysicsActor actor) 1423 public bool haveActor(PhysicsActor actor)
1417 { 1424 {
1418 if (actor is OdePrim) 1425 if (actor is OdePrim)
@@ -1922,30 +1929,15 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1922 1929
1923 public float GetTerrainHeightAtXY(float x, float y) 1930 public float GetTerrainHeightAtXY(float x, float y)
1924 { 1931 {
1925 1932 if (TerrainGeom == IntPtr.Zero)
1926 int offsetX = 0;
1927 int offsetY = 0;
1928
1929 if (m_suportCombine)
1930 {
1931 offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1932 offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
1933 }
1934
1935 // get region map
1936 IntPtr heightFieldGeom = IntPtr.Zero;
1937 if (!RegionTerrain.TryGetValue(new Vector3(offsetX, offsetY, 0), out heightFieldGeom))
1938 return 0f; 1933 return 0f;
1939 1934
1940 if (heightFieldGeom == IntPtr.Zero) 1935 if (TerrainHeightFieldHeight == null || TerrainHeightFieldHeight.Length == 0)
1941 return 0f;
1942
1943 if (!TerrainHeightFieldHeights.ContainsKey(heightFieldGeom))
1944 return 0f; 1936 return 0f;
1945 1937
1946 // TerrainHeightField for ODE as offset 1m 1938 // TerrainHeightField for ODE as offset 1m
1947 x += 1f - offsetX; 1939 x += 1f;
1948 y += 1f - offsetY; 1940 y += 1f;
1949 1941
1950 // make position fit into array 1942 // make position fit into array
1951 if (x < 0) 1943 if (x < 0)
@@ -2024,7 +2016,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2024 iy *= regsize; 2016 iy *= regsize;
2025 iy += ix; // all indexes have iy + ix 2017 iy += ix; // all indexes have iy + ix
2026 2018
2027 float[] heights = TerrainHeightFieldHeights[heightFieldGeom]; 2019 float[] heights = TerrainHeightFieldHeight;
2028 /* 2020 /*
2029 if ((dx + dy) <= 1.0f) 2021 if ((dx + dy) <= 1.0f)
2030 { 2022 {
@@ -2061,31 +2053,17 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2061 2053
2062 public Vector3 GetTerrainNormalAtXY(float x, float y) 2054 public Vector3 GetTerrainNormalAtXY(float x, float y)
2063 { 2055 {
2064 int offsetX = 0;
2065 int offsetY = 0;
2066
2067 if (m_suportCombine)
2068 {
2069 offsetX = ((int)(x / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
2070 offsetY = ((int)(y / (int)Constants.RegionSize)) * (int)Constants.RegionSize;
2071 }
2072
2073 // get region map
2074 IntPtr heightFieldGeom = IntPtr.Zero;
2075 Vector3 norm = new Vector3(0, 0, 1); 2056 Vector3 norm = new Vector3(0, 0, 1);
2076 2057
2077 if (!RegionTerrain.TryGetValue(new Vector3(offsetX, offsetY, 0), out heightFieldGeom)) 2058 if (TerrainGeom == IntPtr.Zero)
2078 return norm; ;
2079
2080 if (heightFieldGeom == IntPtr.Zero)
2081 return norm; 2059 return norm;
2082 2060
2083 if (!TerrainHeightFieldHeights.ContainsKey(heightFieldGeom)) 2061 if (TerrainHeightFieldHeight == null || TerrainHeightFieldHeight.Length == 0)
2084 return norm; 2062 return norm;
2085 2063
2086 // TerrainHeightField for ODE as offset 1m 2064 // TerrainHeightField for ODE as offset 1m
2087 x += 1f - offsetX; 2065 x += 1f;
2088 y += 1f - offsetY; 2066 y += 1f;
2089 2067
2090 // make position fit into array 2068 // make position fit into array
2091 if (x < 0) 2069 if (x < 0)
@@ -2172,7 +2150,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2172 iy *= regsize; 2150 iy *= regsize;
2173 iy += ix; // all indexes have iy + ix 2151 iy += ix; // all indexes have iy + ix
2174 2152
2175 float[] heights = TerrainHeightFieldHeights[heightFieldGeom]; 2153 float[] heights = TerrainHeightFieldHeight;
2176 2154
2177 if (firstTri) 2155 if (firstTri)
2178 { 2156 {
@@ -2199,34 +2177,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2199 2177
2200 public override void SetTerrain(float[] heightMap) 2178 public override void SetTerrain(float[] heightMap)
2201 { 2179 {
2202 if (m_worldOffset != Vector3.Zero && m_parentScene != null)
2203 {
2204 if (m_parentScene is ODEScene)
2205 {
2206 ((ODEScene)m_parentScene).SetTerrain(heightMap, m_worldOffset);
2207 }
2208 }
2209 else
2210 {
2211 SetTerrain(heightMap, m_worldOffset);
2212 }
2213 }
2214
2215 public override void CombineTerrain(float[] heightMap, Vector3 pOffset)
2216 {
2217 if(m_suportCombine)
2218 SetTerrain(heightMap, pOffset);
2219 }
2220
2221 public void SetTerrain(float[] heightMap, Vector3 pOffset)
2222 {
2223 if (m_OSOdeLib) 2180 if (m_OSOdeLib)
2224 OSSetTerrain(heightMap, pOffset); 2181 OSSetTerrain(heightMap);
2225 else 2182 else
2226 OriSetTerrain(heightMap, pOffset); 2183 OriSetTerrain(heightMap);
2227 } 2184 }
2228 2185
2229 public void OriSetTerrain(float[] heightMap, Vector3 pOffset) 2186 public void OriSetTerrain(float[] heightMap)
2230 { 2187 {
2231 // assumes 1m size grid and constante size square regions 2188 // assumes 1m size grid and constante size square regions
2232 // needs to know about sims around in future 2189 // needs to know about sims around in future
@@ -2291,45 +2248,40 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2291 { 2248 {
2292 d.AllocateODEDataForThread(~0U); 2249 d.AllocateODEDataForThread(~0U);
2293 2250
2294 IntPtr GroundGeom = IntPtr.Zero; 2251 if (TerrainGeom != IntPtr.Zero)
2295 if (RegionTerrain.TryGetValue(pOffset, out GroundGeom))
2296 { 2252 {
2297 RegionTerrain.Remove(pOffset); 2253 actor_name_map.Remove(TerrainGeom);
2298 if (GroundGeom != IntPtr.Zero) 2254 d.GeomDestroy(TerrainGeom);
2299 {
2300 actor_name_map.Remove(GroundGeom);
2301 d.GeomDestroy(GroundGeom);
2302 2255
2303 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom))
2304 {
2305 TerrainHeightFieldHeightsHandlers[GroundGeom].Free();
2306 TerrainHeightFieldHeightsHandlers.Remove(GroundGeom);
2307 TerrainHeightFieldHeights.Remove(GroundGeom);
2308 }
2309 }
2310 } 2256 }
2257
2258 if (TerrainHeightFieldHeightsHandler.IsAllocated)
2259 TerrainHeightFieldHeightsHandler.Free();
2260
2311 IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); 2261 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
2312 2262
2313 GCHandle _heightmaphandler = GCHandle.Alloc(_heightmap, GCHandleType.Pinned); 2263 GC.Collect(1);
2264
2265 TerrainHeightFieldHeightsHandler = GCHandle.Alloc(_heightmap, GCHandleType.Pinned);
2314 2266
2315 d.GeomHeightfieldDataBuildSingle(HeightmapData, _heightmaphandler.AddrOfPinnedObject(), 0, 2267 d.GeomHeightfieldDataBuildSingle(HeightmapData, TerrainHeightFieldHeightsHandler.AddrOfPinnedObject(), 0,
2316 heightmapHeight, heightmapWidth , 2268 heightmapHeight, heightmapWidth ,
2317 (int)heightmapHeightSamples, (int)heightmapWidthSamples, scale, 2269 (int)heightmapHeightSamples, (int)heightmapWidthSamples, scale,
2318 offset, thickness, wrap); 2270 offset, thickness, wrap);
2319 2271
2320 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); 2272 d.GeomHeightfieldDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
2321 2273
2322 GroundGeom = d.CreateHeightfield(GroundSpace, HeightmapData, 1); 2274 TerrainGeom = d.CreateHeightfield(GroundSpace, HeightmapData, 1);
2323 2275
2324 if (GroundGeom != IntPtr.Zero) 2276 if (TerrainGeom != IntPtr.Zero)
2325 { 2277 {
2326 d.GeomSetCategoryBits(GroundGeom, (uint)(CollisionCategories.Land)); 2278 d.GeomSetCategoryBits(TerrainGeom, (uint)(CollisionCategories.Land));
2327 d.GeomSetCollideBits(GroundGeom, 0); 2279 d.GeomSetCollideBits(TerrainGeom, 0);
2328 2280
2329 PhysicsActor pa = new NullPhysicsActor(); 2281 PhysicsActor pa = new NullPhysicsActor();
2330 pa.Name = "Terrain"; 2282 pa.Name = "Terrain";
2331 pa.PhysicsActorType = (int)ActorTypes.Ground; 2283 pa.PhysicsActorType = (int)ActorTypes.Ground;
2332 actor_name_map[GroundGeom] = pa; 2284 actor_name_map[TerrainGeom] = pa;
2333 2285
2334// geom_name_map[GroundGeom] = "Terrain"; 2286// geom_name_map[GroundGeom] = "Terrain";
2335 2287
@@ -2339,16 +2291,16 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2339 q.Z = 0.5f; 2291 q.Z = 0.5f;
2340 q.W = 0.5f; 2292 q.W = 0.5f;
2341 2293
2342 d.GeomSetQuaternion(GroundGeom, ref q); 2294 d.GeomSetQuaternion(TerrainGeom, ref q);
2343 d.GeomSetPosition(GroundGeom, pOffset.X + m_regionWidth * 0.5f, pOffset.Y + m_regionHeight * 0.5f, 0.0f); 2295 d.GeomSetPosition(TerrainGeom, m_regionWidth * 0.5f, m_regionHeight * 0.5f, 0.0f);
2344 RegionTerrain.Add(pOffset, GroundGeom); 2296 TerrainHeightFieldHeight = _heightmap;
2345 TerrainHeightFieldHeights.Add(GroundGeom, _heightmap);
2346 TerrainHeightFieldHeightsHandlers.Add(GroundGeom, _heightmaphandler);
2347 } 2297 }
2298 else
2299 TerrainHeightFieldHeightsHandler.Free();
2348 } 2300 }
2349 } 2301 }
2350 2302
2351 public void OSSetTerrain(float[] heightMap, Vector3 pOffset) 2303 public void OSSetTerrain(float[] heightMap)
2352 { 2304 {
2353 // assumes 1m size grid and constante size square regions 2305 // assumes 1m size grid and constante size square regions
2354 // needs to know about sims around in future 2306 // needs to know about sims around in future
@@ -2402,26 +2354,20 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2402 } 2354 }
2403 yt += heightmapWidthSamples; 2355 yt += heightmapWidthSamples;
2404 } 2356 }
2357
2405 lock (OdeLock) 2358 lock (OdeLock)
2406 { 2359 {
2407 IntPtr GroundGeom = IntPtr.Zero; 2360 if (TerrainGeom != IntPtr.Zero)
2408 if (RegionTerrain.TryGetValue(pOffset, out GroundGeom))
2409 { 2361 {
2410 RegionTerrain.Remove(pOffset); 2362 actor_name_map.Remove(TerrainGeom);
2411 if (GroundGeom != IntPtr.Zero) 2363 d.GeomDestroy(TerrainGeom);
2412 {
2413 actor_name_map.Remove(GroundGeom);
2414 d.GeomDestroy(GroundGeom);
2415
2416 if (TerrainHeightFieldHeights.ContainsKey(GroundGeom))
2417 {
2418 if (TerrainHeightFieldHeightsHandlers[GroundGeom].IsAllocated)
2419 TerrainHeightFieldHeightsHandlers[GroundGeom].Free();
2420 TerrainHeightFieldHeightsHandlers.Remove(GroundGeom);
2421 TerrainHeightFieldHeights.Remove(GroundGeom);
2422 }
2423 }
2424 } 2364 }
2365
2366 if (TerrainHeightFieldHeightsHandler.IsAllocated)
2367 TerrainHeightFieldHeightsHandler.Free();
2368
2369 TerrainHeightFieldHeight = null;
2370
2425 IntPtr HeightmapData = d.GeomOSTerrainDataCreate(); 2371 IntPtr HeightmapData = d.GeomOSTerrainDataCreate();
2426 2372
2427 const int wrap = 0; 2373 const int wrap = 0;
@@ -2429,32 +2375,31 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2429 if (thickness < 0) 2375 if (thickness < 0)
2430 thickness = 1; 2376 thickness = 1;
2431 2377
2432 GCHandle _heightmaphandler = GCHandle.Alloc(_heightmap, GCHandleType.Pinned); 2378 TerrainHeightFieldHeightsHandler = GCHandle.Alloc(_heightmap, GCHandleType.Pinned);
2433 2379
2434 d.GeomOSTerrainDataBuild(HeightmapData, _heightmaphandler.AddrOfPinnedObject(), 0, 1.0f, 2380 d.GeomOSTerrainDataBuild(HeightmapData, TerrainHeightFieldHeightsHandler.AddrOfPinnedObject(), 0, 1.0f,
2435 (int)heightmapWidthSamples, (int)heightmapHeightSamples, 2381 (int)heightmapWidthSamples, (int)heightmapHeightSamples,
2436 thickness, wrap); 2382 thickness, wrap);
2437 2383
2438// d.GeomOSTerrainDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1); 2384// d.GeomOSTerrainDataSetBounds(HeightmapData, hfmin - 1, hfmax + 1);
2439 GroundGeom = d.CreateOSTerrain(GroundSpace, HeightmapData, 1); 2385 TerrainGeom = d.CreateOSTerrain(GroundSpace, HeightmapData, 1);
2440 if (GroundGeom != IntPtr.Zero) 2386 if (TerrainGeom != IntPtr.Zero)
2441 { 2387 {
2442 d.GeomSetCategoryBits(GroundGeom, (uint)(CollisionCategories.Land)); 2388 d.GeomSetCategoryBits(TerrainGeom, (uint)(CollisionCategories.Land));
2443 d.GeomSetCollideBits(GroundGeom, 0); 2389 d.GeomSetCollideBits(TerrainGeom, 0);
2444
2445 2390
2446 PhysicsActor pa = new NullPhysicsActor(); 2391 PhysicsActor pa = new NullPhysicsActor();
2447 pa.Name = "Terrain"; 2392 pa.Name = "Terrain";
2448 pa.PhysicsActorType = (int)ActorTypes.Ground; 2393 pa.PhysicsActorType = (int)ActorTypes.Ground;
2449 actor_name_map[GroundGeom] = pa; 2394 actor_name_map[TerrainGeom] = pa;
2450 2395
2451// geom_name_map[GroundGeom] = "Terrain"; 2396// geom_name_map[GroundGeom] = "Terrain";
2452 2397
2453 d.GeomSetPosition(GroundGeom, pOffset.X + m_regionWidth * 0.5f, pOffset.Y + m_regionHeight * 0.5f, 0.0f); 2398 d.GeomSetPosition(TerrainGeom, m_regionWidth * 0.5f, m_regionHeight * 0.5f, 0.0f);
2454 RegionTerrain.Add(pOffset, GroundGeom); 2399 TerrainHeightFieldHeight = _heightmap;
2455 TerrainHeightFieldHeights.Add(GroundGeom, _heightmap); 2400 }
2456 TerrainHeightFieldHeightsHandlers.Add(GroundGeom, _heightmaphandler); 2401 else
2457 } 2402 TerrainHeightFieldHeightsHandler.Free();
2458 } 2403 }
2459 } 2404 }
2460 2405
@@ -2467,11 +2412,6 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2467 return waterlevel; 2412 return waterlevel;
2468 } 2413 }
2469 2414
2470 public override bool SupportsCombining()
2471 {
2472 return m_suportCombine;
2473 }
2474
2475 public override void SetWaterLevel(float baseheight) 2415 public override void SetWaterLevel(float baseheight)
2476 { 2416 {
2477 waterlevel = baseheight; 2417 waterlevel = baseheight;
@@ -2518,26 +2458,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2518 foreach (OdeCharacter ch in chtorem) 2458 foreach (OdeCharacter ch in chtorem)
2519 ch.DoAChange(changes.Remove, null); 2459 ch.DoAChange(changes.Remove, null);
2520 2460
2461 if (TerrainGeom != IntPtr.Zero)
2462 d.GeomDestroy(TerrainGeom);
2463 TerrainGeom = IntPtr.Zero;
2521 2464
2522 foreach (IntPtr GroundGeom in RegionTerrain.Values) 2465 if (TerrainHeightFieldHeightsHandler.IsAllocated)
2523 { 2466 TerrainHeightFieldHeightsHandler.Free();
2524 if (GroundGeom != IntPtr.Zero)
2525 d.GeomDestroy(GroundGeom);
2526 }
2527 2467
2528 RegionTerrain.Clear(); 2468 TerrainHeightFieldHeight = null;
2529
2530 if (TerrainHeightFieldHeightsHandlers.Count > 0)
2531 {
2532 foreach (GCHandle gch in TerrainHeightFieldHeightsHandlers.Values)
2533 {
2534 if (gch.IsAllocated)
2535 gch.Free();
2536 }
2537 }
2538
2539 TerrainHeightFieldHeightsHandlers.Clear();
2540 TerrainHeightFieldHeights.Clear();
2541 2469
2542 if (ContactgeomsArray != IntPtr.Zero) 2470 if (ContactgeomsArray != IntPtr.Zero)
2543 { 2471 {
@@ -2556,27 +2484,22 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2556 } 2484 }
2557 } 2485 }
2558 2486
2487 private int compareByCollisionsDesc(OdePrim A, OdePrim B)
2488 {
2489 return -A.CollisionScore.CompareTo(B.CollisionScore);
2490 }
2491
2559 public override Dictionary<uint, float> GetTopColliders() 2492 public override Dictionary<uint, float> GetTopColliders()
2560 { 2493 {
2561 Dictionary<uint, float> returncolliders = new Dictionary<uint, float>(); 2494 Dictionary<uint, float> topColliders;
2562 int cnt = 0; 2495 List<OdePrim> orderedPrims;
2563 lock (_prims) 2496 lock (_activeprims)
2564 { 2497 orderedPrims = new List<OdePrim>(_activeprims);
2565 foreach (OdePrim prm in _prims.Values) 2498
2566 { 2499 orderedPrims.Sort(compareByCollisionsDesc);
2567 if (prm.CollisionScore > 0) 2500 topColliders = orderedPrims.Take(25).ToDictionary(p => p.LocalID, p => p.CollisionScore);
2568 { 2501
2569 returncolliders.Add(prm.LocalID, prm.CollisionScore); 2502 return topColliders;
2570 cnt++;
2571 prm.CollisionScore = 0f;
2572 if (cnt > 25)
2573 {
2574 break;
2575 }
2576 }
2577 }
2578 }
2579 return returncolliders;
2580 } 2503 }
2581 2504
2582 public override bool SupportsRayCast() 2505 public override bool SupportsRayCast()
diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs
index 6e43cf8..d9544db 100644
--- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs
+++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/Meshmerizer.cs
@@ -121,9 +121,9 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
121 121
122 CacheExpire = TimeSpan.FromHours(fcache); 122 CacheExpire = TimeSpan.FromHours(fcache);
123 123
124 if(doMeshFileCache && cachePath != "") 124 lock (diskLock)
125 { 125 {
126 lock (diskLock) 126 if(doMeshFileCache && cachePath != "")
127 { 127 {
128 try 128 try
129 { 129 {
@@ -619,7 +619,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
619 vs.Clear(); 619 vs.Clear();
620 continue; 620 continue;
621 } 621 }
622 622/*
623 if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f)) 623 if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f))
624 { 624 {
625 vs.Clear(); 625 vs.Clear();
@@ -657,6 +657,45 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
657 f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3); 657 f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3);
658 faces.Add(f); 658 faces.Add(f);
659 } 659 }
660*/
661 List<int> indices;
662 if (!HullUtils.ComputeHull(vs, out indices))
663 {
664 vs.Clear();
665 continue;
666 }
667
668 nverts = vs.Count;
669 nindexs = indices.Count;
670
671 if (nindexs % 3 != 0)
672 {
673 vs.Clear();
674 continue;
675 }
676
677 for (i = 0; i < nverts; i++)
678 {
679 c.X = vs[i].x;
680 c.Y = vs[i].y;
681 c.Z = vs[i].z;
682 coords.Add(c);
683 }
684
685 for (i = 0; i < nindexs; i += 3)
686 {
687 t1 = indices[i];
688 if (t1 > nverts)
689 break;
690 t2 = indices[i + 1];
691 if (t2 > nverts)
692 break;
693 t3 = indices[i + 2];
694 if (t3 > nverts)
695 break;
696 f = new Face(vertsoffset + t1, vertsoffset + t2, vertsoffset + t3);
697 faces.Add(f);
698 }
660 vertsoffset += nverts; 699 vertsoffset += nverts;
661 vs.Clear(); 700 vs.Clear();
662 } 701 }
@@ -686,13 +725,15 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
686 vs.Add(f3); 725 vs.Add(f3);
687 } 726 }
688 727
689 if (vs.Count < 3) 728 nverts = vs.Count;
729
730 if (nverts < 3)
690 { 731 {
691 vs.Clear(); 732 vs.Clear();
692 return false; 733 return false;
693 } 734 }
694 735
695 if (vs.Count < 5) 736 if (nverts < 5)
696 { 737 {
697 foreach (float3 point in vs) 738 foreach (float3 point in vs)
698 { 739 {
@@ -701,10 +742,11 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
701 c.Z = point.z; 742 c.Z = point.z;
702 coords.Add(c); 743 coords.Add(c);
703 } 744 }
745
704 f = new Face(0, 1, 2); 746 f = new Face(0, 1, 2);
705 faces.Add(f); 747 faces.Add(f);
706 748
707 if (vs.Count == 4) 749 if (nverts == 4)
708 { 750 {
709 f = new Face(0, 2, 3); 751 f = new Face(0, 2, 3);
710 faces.Add(f); 752 faces.Add(f);
@@ -716,7 +758,7 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
716 vs.Clear(); 758 vs.Clear();
717 return true; 759 return true;
718 } 760 }
719 761/*
720 if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f)) 762 if (!HullUtils.ComputeHull(vs, ref hullr, 0, 0.0f))
721 return false; 763 return false;
722 764
@@ -747,7 +789,38 @@ namespace OpenSim.Region.PhysicsModule.ubODEMeshing
747 f = new Face(t1, t2, t3); 789 f = new Face(t1, t2, t3);
748 faces.Add(f); 790 faces.Add(f);
749 } 791 }
792*/
793 List<int> indices;
794 if (!HullUtils.ComputeHull(vs, out indices))
795 return false;
796
797 nindexs = indices.Count;
750 798
799 if (nindexs % 3 != 0)
800 return false;
801
802 for (i = 0; i < nverts; i++)
803 {
804 c.X = vs[i].x;
805 c.Y = vs[i].y;
806 c.Z = vs[i].z;
807 coords.Add(c);
808 }
809 for (i = 0; i < nindexs; i += 3)
810 {
811 t1 = indices[i];
812 if (t1 > nverts)
813 break;
814 t2 = indices[i + 1];
815 if (t2 > nverts)
816 break;
817 t3 = indices[i + 2];
818 if (t3 > nverts)
819 break;
820 f = new Face(t1, t2, t3);
821 faces.Add(f);
822 }
823 vs.Clear();
751 if (coords.Count > 0 && faces.Count > 0) 824 if (coords.Count > 0 && faces.Count > 0)
752 return true; 825 return true;
753 } 826 }
diff --git a/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMap.cs b/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMap.cs
index 1c75db6..2ca2af7 100644
--- a/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMap.cs
+++ b/OpenSim/Region/PhysicsModules/ubOdeMeshing/SculptMap.cs
@@ -57,7 +57,7 @@ namespace PrimMesher
57 int numLodPixels = lod * lod; // (32 * 2)^2 = 64^2 pixels for default sculpt map image 57 int numLodPixels = lod * lod; // (32 * 2)^2 = 64^2 pixels for default sculpt map image
58 58
59 bool needsScaling = false; 59 bool needsScaling = false;
60 bool smallMap = false; 60 bool smallMap = false;
61 61
62 width = bmW; 62 width = bmW;
63 height = bmH; 63 height = bmH;
@@ -69,16 +69,8 @@ namespace PrimMesher
69 needsScaling = true; 69 needsScaling = true;
70 } 70 }
71 71
72 try 72 if (needsScaling)
73 { 73 bm = ScaleImage(bm, width, height);
74 if (needsScaling)
75 bm = ScaleImage(bm, width, height);
76 }
77
78 catch (Exception e)
79 {
80 throw new Exception("Exception in ScaleImage(): e: " + e.ToString());
81 }
82 74
83 if (width * height > numLodPixels) 75 if (width * height > numLodPixels)
84 { 76 {
@@ -129,11 +121,15 @@ namespace PrimMesher
129 } 121 }
130 catch (Exception e) 122 catch (Exception e)
131 { 123 {
124 if (needsScaling)
125 bm.Dispose();
132 throw new Exception("Caught exception processing byte arrays in SculptMap(): e: " + e.ToString()); 126 throw new Exception("Caught exception processing byte arrays in SculptMap(): e: " + e.ToString());
133 } 127 }
134 128
135 width++; 129 width++;
136 height++; 130 height++;
131 if(needsScaling)
132 bm.Dispose();
137 } 133 }
138 134
139 public List<List<Coord>> ToRows(bool mirror) 135 public List<List<Coord>> ToRows(bool mirror)
@@ -168,11 +164,9 @@ namespace PrimMesher
168 164
169 private Bitmap ScaleImage(Bitmap srcImage, int destWidth, int destHeight) 165 private Bitmap ScaleImage(Bitmap srcImage, int destWidth, int destHeight)
170 { 166 {
171
172 Bitmap scaledImage = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb); 167 Bitmap scaledImage = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb);
173 168
174 Color c; 169 Color c;
175
176 170
177 // will let last step to be eventually diferent, as seems to be in sl 171 // will let last step to be eventually diferent, as seems to be in sl
178 172