aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs234
-rw-r--r--OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs4
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs2
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsScene.cs4
-rw-r--r--OpenSim/Region/Physics/Manager/VehicleConstants.cs2
-rw-r--r--OpenSim/Region/Physics/Meshing/Mesh.cs87
-rw-r--r--OpenSim/Region/Physics/Meshing/Meshmerizer.cs69
-rw-r--r--OpenSim/Region/Physics/Meshing/PrimMesher.cs27
-rw-r--r--OpenSim/Region/Physics/Meshing/SculptMesh.cs14
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODECharacter.cs132
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs17
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs2
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs10
13 files changed, 341 insertions, 263 deletions
diff --git a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs
index 7ab8b98..f22ea71 100644
--- a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs
+++ b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs
@@ -204,7 +204,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
204 tempAngularVelocity2 = new btVector3(0, 0, 0); 204 tempAngularVelocity2 = new btVector3(0, 0, 0);
205 tempInertia1 = new btVector3(0, 0, 0); 205 tempInertia1 = new btVector3(0, 0, 0);
206 tempInertia2 = new btVector3(0, 0, 0); 206 tempInertia2 = new btVector3(0, 0, 0);
207 tempOrientation1 = new btQuaternion(0,0,0,1); 207 tempOrientation1 = new btQuaternion(0, 0, 0, 1);
208 tempOrientation2 = new btQuaternion(0, 0, 0, 1); 208 tempOrientation2 = new btQuaternion(0, 0, 0, 1);
209 _parent_scene = parent_scene; 209 _parent_scene = parent_scene;
210 tempTransform1 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero); 210 tempTransform1 = new btTransform(_parent_scene.QuatIdentity, _parent_scene.VectorZero);
@@ -216,10 +216,10 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
216 tempMotionState2 = new btDefaultMotionState(_parent_scene.TransZero); 216 tempMotionState2 = new btDefaultMotionState(_parent_scene.TransZero);
217 tempMotionState3 = new btDefaultMotionState(_parent_scene.TransZero); 217 tempMotionState3 = new btDefaultMotionState(_parent_scene.TransZero);
218 218
219 219
220 AxisLockLinearLow = new btVector3(-1 * (int)Constants.RegionSize, -1 * (int)Constants.RegionSize, -1 * (int)Constants.RegionSize); 220 AxisLockLinearLow = new btVector3(-1 * (int)Constants.RegionSize, -1 * (int)Constants.RegionSize, -1 * (int)Constants.RegionSize);
221 int regionsize = (int) Constants.RegionSize; 221 int regionsize = (int)Constants.RegionSize;
222 222
223 if (regionsize == 256) 223 if (regionsize == 256)
224 regionsize = 512; 224 regionsize = 512;
225 225
@@ -611,7 +611,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
611 DisableAxisMotor(); 611 DisableAxisMotor();
612 DisposeOfBody(); 612 DisposeOfBody();
613 SetCollisionShape(null); 613 SetCollisionShape(null);
614 614
615 if (tempMotionState3 != null && tempMotionState3.Handle != IntPtr.Zero) 615 if (tempMotionState3 != null && tempMotionState3.Handle != IntPtr.Zero)
616 { 616 {
617 tempMotionState3.Dispose(); 617 tempMotionState3.Dispose();
@@ -677,8 +677,8 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
677 tempInertia2.Dispose(); 677 tempInertia2.Dispose();
678 tempInertia1 = null; 678 tempInertia1 = null;
679 } 679 }
680 680
681 681
682 if (tempAngularVelocity2 != null && tempAngularVelocity2.Handle != IntPtr.Zero) 682 if (tempAngularVelocity2 != null && tempAngularVelocity2.Handle != IntPtr.Zero)
683 { 683 {
684 tempAngularVelocity2.Dispose(); 684 tempAngularVelocity2.Dispose();
@@ -802,7 +802,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
802 changesize(timestep); 802 changesize(timestep);
803 } 803 }
804 804
805 // 805 //
806 806
807 if (m_taintshape) 807 if (m_taintshape)
808 { 808 {
@@ -1001,7 +1001,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1001 else 1001 else
1002 SetBody(0); 1002 SetBody(0);
1003 changeSelectedStatus(timestep); 1003 changeSelectedStatus(timestep);
1004 1004
1005 resetCollisionAccounting(); 1005 resetCollisionAccounting();
1006 m_taintPhysics = m_isphysical; 1006 m_taintPhysics = m_isphysical;
1007 } 1007 }
@@ -1012,7 +1012,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1012 { 1012 {
1013 if (_parent_scene.needsMeshing(_pbs)) 1013 if (_parent_scene.needsMeshing(_pbs))
1014 { 1014 {
1015 ProcessGeomCreationAsTriMesh(PhysicsVector.Zero,Quaternion.Identity); 1015 ProcessGeomCreationAsTriMesh(PhysicsVector.Zero, Quaternion.Identity);
1016 // createmesh returns null when it doesn't mesh. 1016 // createmesh returns null when it doesn't mesh.
1017 CreateGeom(IntPtr.Zero, _mesh); 1017 CreateGeom(IntPtr.Zero, _mesh);
1018 } 1018 }
@@ -1038,32 +1038,32 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1038 meshlod = _parent_scene.MeshSculptphysicalLOD; 1038 meshlod = _parent_scene.MeshSculptphysicalLOD;
1039 1039
1040 IMesh mesh = _parent_scene.mesher.CreateMesh(SOPName, _pbs, _size, meshlod, IsPhysical); 1040 IMesh mesh = _parent_scene.mesher.CreateMesh(SOPName, _pbs, _size, meshlod, IsPhysical);
1041 if (!positionOffset.IsIdentical(PhysicsVector.Zero,0.001f) || orientation != Quaternion.Identity) 1041 if (!positionOffset.IsIdentical(PhysicsVector.Zero, 0.001f) || orientation != Quaternion.Identity)
1042 { 1042 {
1043 1043
1044 float[] xyz = new float[3]; 1044 float[] xyz = new float[3];
1045 xyz[0] = positionOffset.X; 1045 xyz[0] = positionOffset.X;
1046 xyz[1] = positionOffset.Y; 1046 xyz[1] = positionOffset.Y;
1047 xyz[2] = positionOffset.Z; 1047 xyz[2] = positionOffset.Z;
1048 1048
1049 Matrix4 m4 = Matrix4.CreateFromQuaternion(orientation); 1049 Matrix4 m4 = Matrix4.CreateFromQuaternion(orientation);
1050 1050
1051 float[,] matrix = new float[3,3]; 1051 float[,] matrix = new float[3, 3];
1052 1052
1053 matrix[0, 0] = m4.M11; 1053 matrix[0, 0] = m4.M11;
1054 matrix[0, 1] = m4.M12; 1054 matrix[0, 1] = m4.M12;
1055 matrix[0, 2] = m4.M13; 1055 matrix[0, 2] = m4.M13;
1056 matrix[1, 0] = m4.M21; 1056 matrix[1, 0] = m4.M21;
1057 matrix[1, 1] = m4.M22; 1057 matrix[1, 1] = m4.M22;
1058 matrix[1, 2] = m4.M23; 1058 matrix[1, 2] = m4.M23;
1059 matrix[2, 0] = m4.M31; 1059 matrix[2, 0] = m4.M31;
1060 matrix[2, 1] = m4.M32; 1060 matrix[2, 1] = m4.M32;
1061 matrix[2, 2] = m4.M33; 1061 matrix[2, 2] = m4.M33;
1062 1062
1063 1063
1064 mesh.TransformLinear(matrix, xyz); 1064 mesh.TransformLinear(matrix, xyz);
1065 1065
1066 1066
1067 1067
1068 } 1068 }
1069 1069
@@ -1088,12 +1088,12 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1088 SetCollisionShape(null); 1088 SetCollisionShape(null);
1089 // Construction of new prim 1089 // Construction of new prim
1090 ProcessGeomCreation(); 1090 ProcessGeomCreation();
1091 1091
1092 if (IsPhysical) 1092 if (IsPhysical)
1093 SetBody(Mass); 1093 SetBody(Mass);
1094 else 1094 else
1095 SetBody(0); 1095 SetBody(0);
1096 1096
1097 m_taintsize = _size; 1097 m_taintsize = _size;
1098 1098
1099 } 1099 }
@@ -1136,7 +1136,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1136 //prim_geom = IntPtr.Zero; 1136 //prim_geom = IntPtr.Zero;
1137 m_log.Error("[PHYSICS]: PrimGeom dead"); 1137 m_log.Error("[PHYSICS]: PrimGeom dead");
1138 } 1138 }
1139 1139
1140 // we don't need to do space calculation because the client sends a position update also. 1140 // we don't need to do space calculation because the client sends a position update also.
1141 if (_size.X <= 0) _size.X = 0.01f; 1141 if (_size.X <= 0) _size.X = 0.01f;
1142 if (_size.Y <= 0) _size.Y = 0.01f; 1142 if (_size.Y <= 0) _size.Y = 0.01f;
@@ -1153,8 +1153,8 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1153 tempTransform1.Dispose(); 1153 tempTransform1.Dispose();
1154 tempTransform1 = new btTransform(tempOrientation1, tempPosition1); 1154 tempTransform1 = new btTransform(tempOrientation1, tempPosition1);
1155 1155
1156 1156
1157 1157
1158 1158
1159 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z); 1159 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
1160 if (IsPhysical) 1160 if (IsPhysical)
@@ -1162,7 +1162,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1162 SetBody(Mass); 1162 SetBody(Mass);
1163 // Re creates body on size. 1163 // Re creates body on size.
1164 // EnableBody also does setMass() 1164 // EnableBody also does setMass()
1165 1165
1166 } 1166 }
1167 else 1167 else
1168 { 1168 {
@@ -1179,7 +1179,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1179 } 1179 }
1180 } 1180 }
1181 resetCollisionAccounting(); 1181 resetCollisionAccounting();
1182 1182
1183 m_taintshape = false; 1183 m_taintshape = false;
1184 } 1184 }
1185 1185
@@ -1291,7 +1291,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1291 { 1291 {
1292 Body.setCollisionFlags((int)ContactFlags.CF_NO_CONTACT_RESPONSE); 1292 Body.setCollisionFlags((int)ContactFlags.CF_NO_CONTACT_RESPONSE);
1293 disableBodySoft(); 1293 disableBodySoft();
1294 1294
1295 } 1295 }
1296 else 1296 else
1297 { 1297 {
@@ -1299,7 +1299,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1299 enableBodySoft(); 1299 enableBodySoft();
1300 } 1300 }
1301 m_isSelected = m_taintselected; 1301 m_isSelected = m_taintselected;
1302 1302
1303 } 1303 }
1304 1304
1305 private void changevelocity(float timestep) 1305 private void changevelocity(float timestep)
@@ -1368,7 +1368,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1368 _parent = m_taintparent; 1368 _parent = m_taintparent;
1369 1369
1370 m_taintPhysics = m_isphysical; 1370 m_taintPhysics = m_isphysical;
1371 1371
1372 } 1372 }
1373 1373
1374 private void changefloatonwater(float timestep) 1374 private void changefloatonwater(float timestep)
@@ -1627,7 +1627,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1627 { 1627 {
1628 if (m_zeroPosition == null) 1628 if (m_zeroPosition == null)
1629 m_zeroPosition = new PhysicsVector(0, 0, 0); 1629 m_zeroPosition = new PhysicsVector(0, 0, 0);
1630 m_zeroPosition.setValues(_position.X,_position.Y,_position.Z); 1630 m_zeroPosition.setValues(_position.X, _position.Y, _position.Z);
1631 return; 1631 return;
1632 } 1632 }
1633 } 1633 }
@@ -1981,7 +1981,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1981 //_mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical); 1981 //_mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical);
1982 _mesh = p_mesh; 1982 _mesh = p_mesh;
1983 setMesh(_parent_scene, _mesh); 1983 setMesh(_parent_scene, _mesh);
1984 1984
1985 } 1985 }
1986 else 1986 else
1987 { 1987 {
@@ -1994,15 +1994,15 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
1994 //SetGeom to a Regular Sphere 1994 //SetGeom to a Regular Sphere
1995 if (tempSize1 == null) 1995 if (tempSize1 == null)
1996 tempSize1 = new btVector3(0, 0, 0); 1996 tempSize1 = new btVector3(0, 0, 0);
1997 tempSize1.setValue(_size.X * 0.5f,_size.Y * 0.5f, _size.Z * 0.5f); 1997 tempSize1.setValue(_size.X * 0.5f, _size.Y * 0.5f, _size.Z * 0.5f);
1998 SetCollisionShape(new btSphereShape(_size.X*0.5f)); 1998 SetCollisionShape(new btSphereShape(_size.X * 0.5f));
1999 } 1999 }
2000 else 2000 else
2001 { 2001 {
2002 // uses halfextents 2002 // uses halfextents
2003 if (tempSize1 == null) 2003 if (tempSize1 == null)
2004 tempSize1 = new btVector3(0, 0, 0); 2004 tempSize1 = new btVector3(0, 0, 0);
2005 tempSize1.setValue(_size.X*0.5f, _size.Y*0.5f, _size.Z*0.5f); 2005 tempSize1.setValue(_size.X * 0.5f, _size.Y * 0.5f, _size.Z * 0.5f);
2006 SetCollisionShape(new btBoxShape(tempSize1)); 2006 SetCollisionShape(new btBoxShape(tempSize1));
2007 } 2007 }
2008 } 2008 }
@@ -2052,14 +2052,24 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2052 } 2052 }
2053 } 2053 }
2054 2054
2055 //IMesh oldMesh = primMesh;
2056
2057 //primMesh = mesh;
2058
2059 //float[] vertexList = primMesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
2060 //int[] indexList = primMesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
2061 ////Array.Reverse(indexList);
2062 //primMesh.releaseSourceMeshData(); // free up the original mesh data to save memory
2063
2055 IMesh oldMesh = primMesh; 2064 IMesh oldMesh = primMesh;
2056 2065
2057 primMesh = mesh; 2066 primMesh = mesh;
2058 2067
2059 float[] vertexList = primMesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory 2068 float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
2060 int[] indexList = primMesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage 2069 int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
2061 //Array.Reverse(indexList); 2070 //Array.Reverse(indexList);
2062 primMesh.releaseSourceMeshData(); // free up the original mesh data to save memory 2071 mesh.releaseSourceMeshData(); // free up the original mesh data to save memory
2072
2063 2073
2064 int VertexCount = vertexList.GetLength(0) / 3; 2074 int VertexCount = vertexList.GetLength(0) / 3;
2065 int IndexCount = indexList.GetLength(0); 2075 int IndexCount = indexList.GetLength(0);
@@ -2068,17 +2078,17 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2068 btshapeArray.Dispose(); 2078 btshapeArray.Dispose();
2069 //Array.Reverse(indexList); 2079 //Array.Reverse(indexList);
2070 btshapeArray = new btTriangleIndexVertexArray(IndexCount / 3, indexList, (3 * sizeof(int)), 2080 btshapeArray = new btTriangleIndexVertexArray(IndexCount / 3, indexList, (3 * sizeof(int)),
2071 VertexCount, vertexList, 3*sizeof (float)); 2081 VertexCount, vertexList, 3 * sizeof(float));
2072 SetCollisionShape(new btGImpactMeshShape(btshapeArray)); 2082 SetCollisionShape(new btGImpactMeshShape(btshapeArray));
2073 //((btGImpactMeshShape) prim_geom).updateBound(); 2083 //((btGImpactMeshShape) prim_geom).updateBound();
2074 ((btGImpactMeshShape)prim_geom).setLocalScaling(new btVector3(1,1, 1)); 2084 ((btGImpactMeshShape)prim_geom).setLocalScaling(new btVector3(1, 1, 1));
2075 ((btGImpactMeshShape)prim_geom).updateBound(); 2085 ((btGImpactMeshShape)prim_geom).updateBound();
2076 _parent_scene.SetUsingGImpact(); 2086 _parent_scene.SetUsingGImpact();
2077 if (oldMesh != null) 2087 //if (oldMesh != null)
2078 { 2088 //{
2079 oldMesh.releasePinned(); 2089 // oldMesh.releasePinned();
2080 oldMesh = null; 2090 // oldMesh = null;
2081 } 2091 //}
2082 2092
2083 } 2093 }
2084 2094
@@ -2102,7 +2112,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2102 } 2112 }
2103 */ 2113 */
2104 prim_geom = shape; 2114 prim_geom = shape;
2105 2115
2106 //Body.set 2116 //Body.set
2107 } 2117 }
2108 2118
@@ -2143,8 +2153,8 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2143 2153
2144 if (prim_geom is btGImpactMeshShape) 2154 if (prim_geom is btGImpactMeshShape)
2145 { 2155 {
2146 ((btGImpactMeshShape) prim_geom).setLocalScaling(new btVector3(1, 1, 1)); 2156 ((btGImpactMeshShape)prim_geom).setLocalScaling(new btVector3(1, 1, 1));
2147 ((btGImpactMeshShape) prim_geom).updateBound(); 2157 ((btGImpactMeshShape)prim_geom).updateBound();
2148 } 2158 }
2149 //Body.setCollisionFlags(Body.getCollisionFlags() | (int)ContactFlags.CF_CUSTOM_MATERIAL_CALLBACK); 2159 //Body.setCollisionFlags(Body.getCollisionFlags() | (int)ContactFlags.CF_CUSTOM_MATERIAL_CALLBACK);
2150 //Body.setUserPointer((IntPtr) (int)m_localID); 2160 //Body.setUserPointer((IntPtr) (int)m_localID);
@@ -2159,7 +2169,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2159 { 2169 {
2160 if (chld == null) 2170 if (chld == null)
2161 continue; 2171 continue;
2162 2172
2163 // if (chld.NeedsMeshing()) 2173 // if (chld.NeedsMeshing())
2164 // hasTrimesh = true; 2174 // hasTrimesh = true;
2165 } 2175 }
@@ -2167,40 +2177,40 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2167 2177
2168 //if (hasTrimesh) 2178 //if (hasTrimesh)
2169 //{ 2179 //{
2170 ProcessGeomCreationAsTriMesh(PhysicsVector.Zero, Quaternion.Identity); 2180 ProcessGeomCreationAsTriMesh(PhysicsVector.Zero, Quaternion.Identity);
2171 // createmesh returns null when it doesn't mesh. 2181 // createmesh returns null when it doesn't mesh.
2172
2173 /*
2174 if (_mesh is Mesh)
2175 {
2176 }
2177 else
2178 {
2179 m_log.Warn("[PHYSICS]: Can't link a OpenSim.Region.Physics.Meshing.Mesh object");
2180 return;
2181 }
2182 */
2183 2182
2184 2183 /*
2185 2184 if (_mesh is Mesh)
2186 foreach (BulletDotNETPrim chld in childrenPrim) 2185 {
2187 { 2186 }
2188 if (chld == null) 2187 else
2189 continue; 2188 {
2190 PhysicsVector offset = chld.Position - Position; 2189 m_log.Warn("[PHYSICS]: Can't link a OpenSim.Region.Physics.Meshing.Mesh object");
2191 Vector3 pos = new Vector3(offset.X, offset.Y, offset.Z); 2190 return;
2192 pos *= Quaternion.Inverse(Orientation); 2191 }
2193 //pos *= Orientation; 2192 */
2194 offset.setValues(pos.X, pos.Y, pos.Z);
2195 chld.ProcessGeomCreationAsTriMesh(offset, chld.Orientation);
2196
2197 _mesh.Append(chld._mesh);
2198
2199 2193
2200 } 2194
2201 setMesh(_parent_scene, _mesh); 2195
2202 2196 foreach (BulletDotNETPrim chld in childrenPrim)
2203 //} 2197 {
2198 if (chld == null)
2199 continue;
2200 PhysicsVector offset = chld.Position - Position;
2201 Vector3 pos = new Vector3(offset.X, offset.Y, offset.Z);
2202 pos *= Quaternion.Inverse(Orientation);
2203 //pos *= Orientation;
2204 offset.setValues(pos.X, pos.Y, pos.Z);
2205 chld.ProcessGeomCreationAsTriMesh(offset, chld.Orientation);
2206
2207 _mesh.Append(chld._mesh);
2208
2209
2210 }
2211 setMesh(_parent_scene, _mesh);
2212
2213 //}
2204 2214
2205 if (tempMotionState1 != null && tempMotionState1.Handle != IntPtr.Zero) 2215 if (tempMotionState1 != null && tempMotionState1.Handle != IntPtr.Zero)
2206 tempMotionState1.Dispose(); 2216 tempMotionState1.Dispose();
@@ -2238,7 +2248,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2238 ((btGImpactMeshShape)prim_geom).updateBound(); 2248 ((btGImpactMeshShape)prim_geom).updateBound();
2239 } 2249 }
2240 _parent_scene.AddPrimToScene(this); 2250 _parent_scene.AddPrimToScene(this);
2241 2251
2242 } 2252 }
2243 2253
2244 if (IsPhysical) 2254 if (IsPhysical)
@@ -2252,7 +2262,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2252 if (Body.Handle != IntPtr.Zero) 2262 if (Body.Handle != IntPtr.Zero)
2253 { 2263 {
2254 DisableAxisMotor(); 2264 DisableAxisMotor();
2255 _parent_scene.removeFromWorld(this,Body); 2265 _parent_scene.removeFromWorld(this, Body);
2256 Body.Dispose(); 2266 Body.Dispose();
2257 } 2267 }
2258 Body = null; 2268 Body = null;
@@ -2305,7 +2315,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2305 return; 2315 return;
2306 2316
2307 2317
2308 2318
2309 lock (childrenPrim) 2319 lock (childrenPrim)
2310 { 2320 {
2311 if (!childrenPrim.Contains(prm)) 2321 if (!childrenPrim.Contains(prm))
@@ -2313,8 +2323,8 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2313 childrenPrim.Add(prm); 2323 childrenPrim.Add(prm);
2314 } 2324 }
2315 } 2325 }
2316 2326
2317 2327
2318 } 2328 }
2319 2329
2320 public void disableBody() 2330 public void disableBody()
@@ -2386,7 +2396,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2386 { 2396 {
2387 Body.clearForces(); 2397 Body.clearForces();
2388 Body.forceActivationState(0); 2398 Body.forceActivationState(0);
2389 2399
2390 } 2400 }
2391 2401
2392 } 2402 }
@@ -2400,7 +2410,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2400 Body.clearForces(); 2410 Body.clearForces();
2401 Body.forceActivationState(4); 2411 Body.forceActivationState(4);
2402 forceenable = true; 2412 forceenable = true;
2403 2413
2404 } 2414 }
2405 m_disabled = false; 2415 m_disabled = false;
2406 } 2416 }
@@ -2415,7 +2425,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2415 SetBody(Mass); 2425 SetBody(Mass);
2416 else 2426 else
2417 SetBody(0); 2427 SetBody(0);
2418 2428
2419 // TODO: Set Collision Category Bits and Flags 2429 // TODO: Set Collision Category Bits and Flags
2420 // TODO: Set Auto Disable data 2430 // TODO: Set Auto Disable data
2421 2431
@@ -2587,10 +2597,10 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2587 _velocity.Y = tempLinearVelocity1.getY(); 2597 _velocity.Y = tempLinearVelocity1.getY();
2588 _velocity.Z = tempLinearVelocity1.getZ(); 2598 _velocity.Z = tempLinearVelocity1.getZ();
2589 2599
2590 _acceleration = ((_velocity - m_lastVelocity)/0.1f); 2600 _acceleration = ((_velocity - m_lastVelocity) / 0.1f);
2591 _acceleration = new PhysicsVector(_velocity.X - m_lastVelocity.X/0.1f, 2601 _acceleration = new PhysicsVector(_velocity.X - m_lastVelocity.X / 0.1f,
2592 _velocity.Y - m_lastVelocity.Y/0.1f, 2602 _velocity.Y - m_lastVelocity.Y / 0.1f,
2593 _velocity.Z - m_lastVelocity.Z/0.1f); 2603 _velocity.Z - m_lastVelocity.Z / 0.1f);
2594 //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString()); 2604 //m_log.Info("[PHYSICS]: V1: " + _velocity + " V2: " + m_lastVelocity + " Acceleration: " + _acceleration.ToString());
2595 2605
2596 if (_velocity.IsIdentical(pv, 0.5f)) 2606 if (_velocity.IsIdentical(pv, 0.5f))
@@ -2669,7 +2679,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2669 if (AxisLockAngleHigh != null && AxisLockAngleHigh.Handle != IntPtr.Zero) 2679 if (AxisLockAngleHigh != null && AxisLockAngleHigh.Handle != IntPtr.Zero)
2670 AxisLockAngleHigh.Dispose(); 2680 AxisLockAngleHigh.Dispose();
2671 2681
2672 2682
2673 2683
2674 m_aMotor = new btGeneric6DofConstraint(Body, _parent_scene.TerrainBody, _parent_scene.TransZero, 2684 m_aMotor = new btGeneric6DofConstraint(Body, _parent_scene.TerrainBody, _parent_scene.TransZero,
2675 _parent_scene.TransZero, false); 2685 _parent_scene.TransZero, false);
@@ -2683,7 +2693,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2683 m_aMotor.setLinearUpperLimit(AxisLockLinearHigh); 2693 m_aMotor.setLinearUpperLimit(AxisLockLinearHigh);
2684 _parent_scene.getBulletWorld().addConstraint((btTypedConstraint)m_aMotor); 2694 _parent_scene.getBulletWorld().addConstraint((btTypedConstraint)m_aMotor);
2685 //m_aMotor. 2695 //m_aMotor.
2686 2696
2687 2697
2688 } 2698 }
2689 internal void DisableAxisMotor() 2699 internal void DisableAxisMotor()
@@ -2698,4 +2708,4 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
2698 2708
2699 } 2709 }
2700} 2710}
2701 2711
diff --git a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs
index e0f856a..18d4bab 100644
--- a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs
+++ b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETScene.cs
@@ -528,7 +528,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
528 { 528 {
529 // Teravus: Kitto, this code causes recurring errors that stall physics permenantly unless 529 // Teravus: Kitto, this code causes recurring errors that stall physics permenantly unless
530 // the values are checked, so checking below. 530 // the values are checked, so checking below.
531 // Is there any reason that we don't do this in ScenePresence? 531 // Is there any reason that we don't do this in ScenePresence?
532 // The only physics engine that benefits from it in the physics plugin is this one 532 // The only physics engine that benefits from it in the physics plugin is this one
533 533
534 if (x > (int)Constants.RegionSize || y > (int)Constants.RegionSize || 534 if (x > (int)Constants.RegionSize || y > (int)Constants.RegionSize ||
@@ -650,7 +650,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin
650 650
651 if (iPropertiesNotSupportedDefault == 0) 651 if (iPropertiesNotSupportedDefault == 0)
652 { 652 {
653#if SPAM 653#if SPAM
654 m_log.Warn("NonMesh"); 654 m_log.Warn("NonMesh");
655#endif 655#endif
656 return false; 656 return false;
diff --git a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
index ce52744..7130a3e 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
@@ -55,7 +55,7 @@ namespace OpenSim.Region.Physics.Manager
55 plugHard = new ZeroMesherPlugin(); 55 plugHard = new ZeroMesherPlugin();
56 _MeshPlugins.Add(plugHard.GetName(), plugHard); 56 _MeshPlugins.Add(plugHard.GetName(), plugHard);
57 57
58 m_log.Info("[PHYSICS]: Added meshing engine: " + plugHard.GetName()); 58 m_log.Info("[PHYSICS]: Added meshing engine: " + plugHard.GetName());
59 } 59 }
60 60
61 /// <summary> 61 /// <summary>
diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
index 8a07f71..6dd26bb 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
@@ -178,12 +178,12 @@ namespace OpenSim.Region.Physics.Manager
178 } 178 }
179 179
180 /// <summary> 180 /// <summary>
181 /// Queue a raycast against the physics scene. 181 /// Queue a raycast against the physics scene.
182 /// The provided callback method will be called when the raycast is complete 182 /// The provided callback method will be called when the raycast is complete
183 /// 183 ///
184 /// Many physics engines don't support collision testing at the same time as 184 /// Many physics engines don't support collision testing at the same time as
185 /// manipulating the physics scene, so we queue the request up and callback 185 /// manipulating the physics scene, so we queue the request up and callback
186 /// a custom method when the raycast is complete. 186 /// a custom method when the raycast is complete.
187 /// This allows physics engines that give an immediate result to callback immediately 187 /// This allows physics engines that give an immediate result to callback immediately
188 /// and ones that don't, to callback when it gets a result back. 188 /// and ones that don't, to callback when it gets a result back.
189 /// 189 ///
diff --git a/OpenSim/Region/Physics/Manager/VehicleConstants.cs b/OpenSim/Region/Physics/Manager/VehicleConstants.cs
index 97f66d3..532e55e 100644
--- a/OpenSim/Region/Physics/Manager/VehicleConstants.cs
+++ b/OpenSim/Region/Physics/Manager/VehicleConstants.cs
@@ -93,7 +93,7 @@ namespace OpenSim.Region.Physics.Manager
93 BANKING_TIMESCALE = 40, 93 BANKING_TIMESCALE = 40,
94 REFERENCE_FRAME = 44 94 REFERENCE_FRAME = 44
95 95
96 } 96 }
97 97
98 [Flags] 98 [Flags]
99 public enum VehicleFlag 99 public enum VehicleFlag
diff --git a/OpenSim/Region/Physics/Meshing/Mesh.cs b/OpenSim/Region/Physics/Meshing/Mesh.cs
index ceafaad..aae8871 100644
--- a/OpenSim/Region/Physics/Meshing/Mesh.cs
+++ b/OpenSim/Region/Physics/Meshing/Mesh.cs
@@ -40,7 +40,6 @@ namespace OpenSim.Region.Physics.Meshing
40 private List<Triangle> triangles; 40 private List<Triangle> triangles;
41 GCHandle pinnedVirtexes; 41 GCHandle pinnedVirtexes;
42 GCHandle pinnedIndex; 42 GCHandle pinnedIndex;
43 public PrimMesh primMesh = null;
44 public float[] normals; 43 public float[] normals;
45 44
46 public Mesh() 45 public Mesh()
@@ -63,6 +62,8 @@ namespace OpenSim.Region.Physics.Meshing
63 62
64 public void Add(Triangle triangle) 63 public void Add(Triangle triangle)
65 { 64 {
65 if (pinnedIndex.IsAllocated || pinnedVirtexes.IsAllocated)
66 throw new NotSupportedException("Attempt to Add to a pinned Mesh");
66 // If a vertex of the triangle is not yet in the vertices list, 67 // If a vertex of the triangle is not yet in the vertices list,
67 // add it and set its index to the current index count 68 // add it and set its index to the current index count
68 if (!vertices.ContainsKey(triangle.v1)) 69 if (!vertices.ContainsKey(triangle.v1))
@@ -148,40 +149,22 @@ namespace OpenSim.Region.Physics.Meshing
148 149
149 public float[] getVertexListAsFloatLocked() 150 public float[] getVertexListAsFloatLocked()
150 { 151 {
152 if (pinnedVirtexes.IsAllocated)
153 return (float[])(pinnedVirtexes.Target);
151 float[] result; 154 float[] result;
152 155
153 if (primMesh == null) 156 //m_log.WarnFormat("vertices.Count = {0}", vertices.Count);
157 result = new float[vertices.Count * 3];
158 foreach (KeyValuePair<Vertex, int> kvp in vertices)
154 { 159 {
155 //m_log.WarnFormat("vertices.Count = {0}", vertices.Count); 160 Vertex v = kvp.Key;
156 result = new float[vertices.Count * 3]; 161 int i = kvp.Value;
157 foreach (KeyValuePair<Vertex, int> kvp in vertices) 162 //m_log.WarnFormat("kvp.Value = {0}", i);
158 { 163 result[3 * i + 0] = v.X;
159 Vertex v = kvp.Key; 164 result[3 * i + 1] = v.Y;
160 int i = kvp.Value; 165 result[3 * i + 2] = v.Z;
161 //m_log.WarnFormat("kvp.Value = {0}", i);
162 result[3 * i + 0] = v.X;
163 result[3 * i + 1] = v.Y;
164 result[3 * i + 2] = v.Z;
165 }
166 pinnedVirtexes = GCHandle.Alloc(result, GCHandleType.Pinned);
167 }
168 else
169 {
170 int count = primMesh.coords.Count;
171 result = new float[count * 3];
172 for (int i = 0; i < count; i++)
173 {
174 Coord c = primMesh.coords[i];
175 {
176 int resultIndex = 3 * i;
177 result[resultIndex] = c.X;
178 result[resultIndex + 1] = c.Y;
179 result[resultIndex + 2] = c.Z;
180 }
181
182 }
183 pinnedVirtexes = GCHandle.Alloc(result, GCHandleType.Pinned);
184 } 166 }
167 pinnedVirtexes = GCHandle.Alloc(result, GCHandleType.Pinned);
185 return result; 168 return result;
186 } 169 }
187 170
@@ -189,33 +172,13 @@ namespace OpenSim.Region.Physics.Meshing
189 { 172 {
190 int[] result; 173 int[] result;
191 174
192 if (primMesh == null) 175 result = new int[triangles.Count * 3];
193 { 176 for (int i = 0; i < triangles.Count; i++)
194 result = new int[triangles.Count * 3];
195 for (int i = 0; i < triangles.Count; i++)
196 {
197 Triangle t = triangles[i];
198 result[3 * i + 0] = vertices[t.v1];
199 result[3 * i + 1] = vertices[t.v2];
200 result[3 * i + 2] = vertices[t.v3];
201 }
202 }
203 else
204 { 177 {
205 int numFaces = primMesh.faces.Count; 178 Triangle t = triangles[i];
206 result = new int[numFaces * 3]; 179 result[3 * i + 0] = vertices[t.v1];
207 for (int i = 0; i < numFaces; i++) 180 result[3 * i + 1] = vertices[t.v2];
208 { 181 result[3 * i + 2] = vertices[t.v3];
209 Face f = primMesh.faces[i];
210// Coord c1 = primMesh.coords[f.v1];
211// Coord c2 = primMesh.coords[f.v2];
212// Coord c3 = primMesh.coords[f.v3];
213
214 int resultIndex = i * 3;
215 result[resultIndex] = f.v1;
216 result[resultIndex + 1] = f.v2;
217 result[resultIndex + 2] = f.v3;
218 }
219 } 182 }
220 return result; 183 return result;
221 } 184 }
@@ -226,6 +189,9 @@ namespace OpenSim.Region.Physics.Meshing
226 /// <returns></returns> 189 /// <returns></returns>
227 public int[] getIndexListAsIntLocked() 190 public int[] getIndexListAsIntLocked()
228 { 191 {
192 if (pinnedIndex.IsAllocated)
193 return (int[])(pinnedIndex.Target);
194
229 int[] result = getIndexListAsInt(); 195 int[] result = getIndexListAsInt();
230 pinnedIndex = GCHandle.Alloc(result, GCHandleType.Pinned); 196 pinnedIndex = GCHandle.Alloc(result, GCHandleType.Pinned);
231 197
@@ -245,11 +211,13 @@ namespace OpenSim.Region.Physics.Meshing
245 { 211 {
246 triangles = null; 212 triangles = null;
247 vertices = null; 213 vertices = null;
248 primMesh = null;
249 } 214 }
250 215
251 public void Append(IMesh newMesh) 216 public void Append(IMesh newMesh)
252 { 217 {
218 if (pinnedIndex.IsAllocated || pinnedVirtexes.IsAllocated)
219 throw new NotSupportedException("Attempt to Append to a pinned Mesh");
220
253 if (!(newMesh is Mesh)) 221 if (!(newMesh is Mesh))
254 return; 222 return;
255 223
@@ -260,6 +228,9 @@ namespace OpenSim.Region.Physics.Meshing
260 // Do a linear transformation of mesh. 228 // Do a linear transformation of mesh.
261 public void TransformLinear(float[,] matrix, float[] offset) 229 public void TransformLinear(float[,] matrix, float[] offset)
262 { 230 {
231 if (pinnedIndex.IsAllocated || pinnedVirtexes.IsAllocated)
232 throw new NotSupportedException("Attempt to TransformLinear a pinned Mesh");
233
263 foreach (Vertex v in vertices.Keys) 234 foreach (Vertex v in vertices.Keys)
264 { 235 {
265 if (v == null) 236 if (v == null)
diff --git a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
index aa8df23..d56ddc8 100644
--- a/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/Meshing/Meshmerizer.cs
@@ -76,6 +76,7 @@ namespace OpenSim.Region.Physics.Meshing
76 76
77 private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh 77 private float minSizeForComplexMesh = 0.2f; // prims with all dimensions smaller than this will have a bounding box mesh
78 78
79 private Dictionary<ulong, Mesh> m_uniqueMeshes = new Dictionary<ulong, Mesh>();
79 80
80 public Meshmerizer() 81 public Meshmerizer()
81 { 82 {
@@ -184,9 +185,62 @@ namespace OpenSim.Region.Physics.Meshing
184 185
185 } 186 }
186 187
187 public Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod) 188 private ulong GetMeshKey(PrimitiveBaseShape pbs, PhysicsVector size, float lod)
189 {
190 ulong hash = 5381;
191
192 hash = djb2(hash, pbs.PathCurve);
193 hash = djb2(hash, (byte)((byte)pbs.HollowShape | (byte)pbs.ProfileShape));
194 hash = djb2(hash, pbs.PathBegin);
195 hash = djb2(hash, pbs.PathEnd);
196 hash = djb2(hash, pbs.PathScaleX);
197 hash = djb2(hash, pbs.PathScaleY);
198 hash = djb2(hash, pbs.PathShearX);
199 hash = djb2(hash, pbs.PathShearY);
200 hash = djb2(hash, (byte)pbs.PathTwist);
201 hash = djb2(hash, (byte)pbs.PathTwistBegin);
202 hash = djb2(hash, (byte)pbs.PathRadiusOffset);
203 hash = djb2(hash, (byte)pbs.PathTaperX);
204 hash = djb2(hash, (byte)pbs.PathTaperY);
205 hash = djb2(hash, pbs.PathRevolutions);
206 hash = djb2(hash, (byte)pbs.PathSkew);
207 hash = djb2(hash, pbs.ProfileBegin);
208 hash = djb2(hash, pbs.ProfileEnd);
209 hash = djb2(hash, pbs.ProfileHollow);
210
211 // TODO: Separate scale out from the primitive shape data (after
212 // scaling is supported at the physics engine level)
213 byte[] scaleBytes = size.GetBytes();
214 for (int i = 0; i < scaleBytes.Length; i++)
215 hash = djb2(hash, scaleBytes[i]);
216
217 // Include LOD in hash, accounting for endianness
218 byte[] lodBytes = new byte[4];
219 Buffer.BlockCopy(BitConverter.GetBytes(lod), 0, lodBytes, 0, 4);
220 if (!BitConverter.IsLittleEndian)
221 {
222 Array.Reverse(lodBytes, 0, 4);
223 }
224 for (int i = 0; i < lodBytes.Length; i++)
225 hash = djb2(hash, lodBytes[i]);
226
227 return hash;
228 }
229
230 private ulong djb2(ulong hash, byte c)
231 {
232 return ((hash << 5) + hash) + (ulong)c;
233 }
234
235 private ulong djb2(ulong hash, ushort c)
236 {
237 hash = ((hash << 5) + hash) + (ulong)((byte)c);
238 return ((hash << 5) + hash) + (ulong)(c >> 8);
239 }
240
241
242 private Mesh CreateMeshFromPrimMesher(string primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod)
188 { 243 {
189 Mesh mesh = new Mesh();
190 PrimMesh primMesh; 244 PrimMesh primMesh;
191 PrimMesher.SculptMesh sculptMesh; 245 PrimMesher.SculptMesh sculptMesh;
192 246
@@ -399,8 +453,6 @@ namespace OpenSim.Region.Physics.Meshing
399 453
400 coords = primMesh.coords; 454 coords = primMesh.coords;
401 faces = primMesh.faces; 455 faces = primMesh.faces;
402
403
404 } 456 }
405 457
406 458
@@ -415,13 +467,13 @@ namespace OpenSim.Region.Physics.Meshing
415 vertices.Add(new Vertex(c.X, c.Y, c.Z)); 467 vertices.Add(new Vertex(c.X, c.Y, c.Z));
416 } 468 }
417 469
470 Mesh mesh = new Mesh();
418 // Add the corresponding triangles to the mesh 471 // Add the corresponding triangles to the mesh
419 for (int i = 0; i < numFaces; i++) 472 for (int i = 0; i < numFaces; i++)
420 { 473 {
421 Face f = faces[i]; 474 Face f = faces[i];
422 mesh.Add(new Triangle(vertices[f.v1], vertices[f.v2], vertices[f.v3])); 475 mesh.Add(new Triangle(vertices[f.v1], vertices[f.v2], vertices[f.v3]));
423 } 476 }
424
425 return mesh; 477 return mesh;
426 } 478 }
427 479
@@ -432,7 +484,12 @@ namespace OpenSim.Region.Physics.Meshing
432 484
433 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod, bool isPhysical) 485 public IMesh CreateMesh(String primName, PrimitiveBaseShape primShape, PhysicsVector size, float lod, bool isPhysical)
434 { 486 {
487 // If this mesh has been created already, return it instead of creating another copy
488 // For large regions with 100k+ prims and hundreds of copies of each, this can save a GB or more of memory
489 ulong key = GetMeshKey(primShape, size, lod);
435 Mesh mesh = null; 490 Mesh mesh = null;
491 if (m_uniqueMeshes.TryGetValue(key, out mesh))
492 return mesh;
436 493
437 if (size.X < 0.01f) size.X = 0.01f; 494 if (size.X < 0.01f) size.X = 0.01f;
438 if (size.Y < 0.01f) size.Y = 0.01f; 495 if (size.Y < 0.01f) size.Y = 0.01f;
@@ -455,7 +512,7 @@ namespace OpenSim.Region.Physics.Meshing
455 // trim the vertex and triangle lists to free up memory 512 // trim the vertex and triangle lists to free up memory
456 mesh.TrimExcess(); 513 mesh.TrimExcess();
457 } 514 }
458 515 m_uniqueMeshes.Add(key, mesh);
459 return mesh; 516 return mesh;
460 } 517 }
461 } 518 }
diff --git a/OpenSim/Region/Physics/Meshing/PrimMesher.cs b/OpenSim/Region/Physics/Meshing/PrimMesher.cs
index 0d19c01..abfd400 100644
--- a/OpenSim/Region/Physics/Meshing/PrimMesher.cs
+++ b/OpenSim/Region/Physics/Meshing/PrimMesher.cs
@@ -345,6 +345,21 @@ namespace PrimMesher
345 this.v3.Z *= z; 345 this.v3.Z *= z;
346 } 346 }
347 347
348 public void AddPos(float x, float y, float z)
349 {
350 this.v1.X += x;
351 this.v2.X += x;
352 this.v3.X += x;
353
354 this.v1.Y += y;
355 this.v2.Y += y;
356 this.v3.Y += y;
357
358 this.v1.Z += z;
359 this.v2.Z += z;
360 this.v3.Z += z;
361 }
362
348 public void AddRot(Quat q) 363 public void AddRot(Quat q)
349 { 364 {
350 this.v1 *= q; 365 this.v1 *= q;
@@ -2141,6 +2156,18 @@ namespace PrimMesher
2141 vert.Z += z; 2156 vert.Z += z;
2142 this.coords[i] = vert; 2157 this.coords[i] = vert;
2143 } 2158 }
2159
2160 if (this.viewerFaces != null)
2161 {
2162 int numViewerFaces = this.viewerFaces.Count;
2163
2164 for (i = 0; i < numViewerFaces; i++)
2165 {
2166 ViewerFace v = this.viewerFaces[i];
2167 v.AddPos(x, y, z);
2168 this.viewerFaces[i] = v;
2169 }
2170 }
2144 } 2171 }
2145 2172
2146 /// <summary> 2173 /// <summary>
diff --git a/OpenSim/Region/Physics/Meshing/SculptMesh.cs b/OpenSim/Region/Physics/Meshing/SculptMesh.cs
index bf42fee..bd63aef 100644
--- a/OpenSim/Region/Physics/Meshing/SculptMesh.cs
+++ b/OpenSim/Region/Physics/Meshing/SculptMesh.cs
@@ -494,6 +494,18 @@ namespace PrimMesher
494 vert.Z += z; 494 vert.Z += z;
495 this.coords[i] = vert; 495 this.coords[i] = vert;
496 } 496 }
497
498 if (this.viewerFaces != null)
499 {
500 int numViewerFaces = this.viewerFaces.Count;
501
502 for (i = 0; i < numViewerFaces; i++)
503 {
504 ViewerFace v = this.viewerFaces[i];
505 v.AddPos(x, y, z);
506 this.viewerFaces[i] = v;
507 }
508 }
497 } 509 }
498 510
499 /// <summary> 511 /// <summary>
@@ -556,7 +568,7 @@ namespace PrimMesher
556 if (path == null) 568 if (path == null)
557 return; 569 return;
558 String fileName = name + "_" + title + ".raw"; 570 String fileName = name + "_" + title + ".raw";
559 String completePath = Path.Combine(path, fileName); 571 String completePath = System.IO.Path.Combine(path, fileName);
560 StreamWriter sw = new StreamWriter(completePath); 572 StreamWriter sw = new StreamWriter(completePath);
561 573
562 for (int i = 0; i < this.faces.Count; i++) 574 for (int i = 0; i < this.faces.Count; i++)
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index dd58a4e..a00ba11 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -107,6 +107,7 @@ namespace OpenSim.Region.Physics.OdePlugin
107 public float MinimumGroundFlightOffset = 3f; 107 public float MinimumGroundFlightOffset = 3f;
108 108
109 private float m_tainted_CAPSULE_LENGTH; // set when the capsule length changes. 109 private float m_tainted_CAPSULE_LENGTH; // set when the capsule length changes.
110 private float m_tiltMagnitudeWhenProjectedOnXYPlane = 0.1131371f; // used to introduce a fixed tilt because a straight-up capsule falls through terrain, probably a bug in terrain collider
110 111
111 112
112 private float m_buoyancy = 0f; 113 private float m_buoyancy = 0f;
@@ -477,7 +478,71 @@ namespace OpenSim.Region.Physics.OdePlugin
477 } 478 }
478 } 479 }
479 } 480 }
480 481
482 private void AlignAvatarTiltWithCurrentDirectionOfMovement(PhysicsVector movementVector)
483 {
484 movementVector.Z = 0f;
485 float magnitude = (float)Math.Sqrt((double)(movementVector.X * movementVector.X + movementVector.Y * movementVector.Y));
486 if (magnitude < 0.1f) return;
487
488 // normalize the velocity vector
489 float invMagnitude = 1.0f / magnitude;
490 movementVector.X *= invMagnitude;
491 movementVector.Y *= invMagnitude;
492
493 // if we change the capsule heading too often, the capsule can fall down
494 // therefore we snap movement vector to just 1 of 4 predefined directions (ne, nw, se, sw),
495 // meaning only 4 possible capsule tilt orientations
496 if (movementVector.X > 0)
497 {
498 // east
499 if (movementVector.Y > 0)
500 {
501 // northeast
502 movementVector.X = (float)Math.Sqrt(2.0);
503 movementVector.Y = (float)Math.Sqrt(2.0);
504 }
505 else
506 {
507 // southeast
508 movementVector.X = (float)Math.Sqrt(2.0);
509 movementVector.Y = -(float)Math.Sqrt(2.0);
510 }
511 }
512 else
513 {
514 // west
515 if (movementVector.Y > 0)
516 {
517 // northwest
518 movementVector.X = -(float)Math.Sqrt(2.0);
519 movementVector.Y = (float)Math.Sqrt(2.0);
520 }
521 else
522 {
523 // southwest
524 movementVector.X = -(float)Math.Sqrt(2.0);
525 movementVector.Y = -(float)Math.Sqrt(2.0);
526 }
527 }
528
529
530 // movementVector.Z is zero
531
532 // calculate tilt components based on desired amount of tilt and current (snapped) heading.
533 // the "-" sign is to force the tilt to be OPPOSITE the direction of movement.
534 float xTiltComponent = -movementVector.X * m_tiltMagnitudeWhenProjectedOnXYPlane;
535 float yTiltComponent = -movementVector.Y * m_tiltMagnitudeWhenProjectedOnXYPlane;
536
537 //m_log.Debug("[PHYSICS] changing avatar tilt");
538 d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, xTiltComponent);
539 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, xTiltComponent); // must be same as lowstop, else a different, spurious tilt is introduced
540 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, yTiltComponent);
541 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, yTiltComponent); // same as lowstop
542 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, 0f);
543 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop
544 }
545
481 /// <summary> 546 /// <summary>
482 /// This creates the Avatar's physical Surrogate at the position supplied 547 /// This creates the Avatar's physical Surrogate at the position supplied
483 /// </summary> 548 /// </summary>
@@ -576,71 +641,13 @@ namespace OpenSim.Region.Physics.OdePlugin
576 // (with -0..0 motor stops) falls into the terrain for reasons yet 641 // (with -0..0 motor stops) falls into the terrain for reasons yet
577 // to be comprehended in their entirety. 642 // to be comprehended in their entirety.
578 #endregion 643 #endregion
644 AlignAvatarTiltWithCurrentDirectionOfMovement(new PhysicsVector(0,0,0));
579 d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f); 645 d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, 0.08f);
580 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f); 646 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -0f);
581 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0.08f); 647 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, 0.08f);
582 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.08f); // must be same as lowstop, else a different, spurious tilt is introduced 648 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 0.08f); // must be same as lowstop, else a different, spurious tilt is introduced
583 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop 649 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 0f); // same as lowstop
584 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.08f); // same as lowstop 650 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 0.08f); // same as lowstop
585 #region Documentation of capsule motor StopERP and StopCFM parameters
586 // In addition to the above tilt, we allow a dynamic tilt, or
587 // wobble, to emerge as the capsule is pushed around the environment.
588 // We do this with an experimentally determined combination of
589 // StopERP and StopCFM which make the above motor stops soft.
590 // The softness of the stops should be tweaked according to two
591 // requirements:
592 //
593 // 1. Motor stops should be weak enough to allow enough wobble such
594 // that the capsule can tilt slightly more when moving, to allow
595 // "gliding" over obstacles:
596 //
597 //
598 // .-.
599 // / /
600 // / /
601 // _ / / _
602 // / \ .-. / / / \
603 // | | ----> / / / / | |
604 // | | / / `-' | |
605 // | | / / +------+ | |
606 // | | / / | | | |
607 // | | / / | | | |
608 // \_/ `-' +------+ \_/
609 // ----------------------------------------------------------
610 //
611 // Note that requirement 1 is made complicated by the ever-present
612 // slight avatar tilt (assigned in the above code to prevent avatar
613 // from falling through terrain), which introduces a direction-dependent
614 // bias into the wobble (wobbling against the existing tilt is harder
615 // than wobbling with the tilt), which makes it easier to walk over
616 // prims from some directions. I have tried to minimize this effect by
617 // minimizing the avatar tilt to the minimum that prevents the avatar from
618 // falling through the terrain.
619 //
620 // 2. Motor stops should be strong enough to prevent the capsule
621 // from being forced all the way to the ground; otherwise the
622 // capsule could slip underneath obstacles like this:
623 // _ _
624 // / \ +------+ / \
625 // | | ----> | | | |
626 // | | | | | |
627 // | | .--.___ +------+ | |
628 // | | `--.__`--.__ | |
629 // | | `--.__`--. | |
630 // \_/ `--' \_/
631 // ----------------------------------------------------------
632 //
633 //
634 // It is strongly recommended you enable USE_DRAWSTUFF if you want to
635 // tweak these values, to see how the capsule is reacting in various
636 // situations.
637 #endregion
638 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM, 0.0035f);
639 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM2, 0.0035f);
640 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM3, 0.0035f);
641 d.JointSetAMotorParam(Amotor, (int)dParam.StopERP, 0.8f);
642 d.JointSetAMotorParam(Amotor, (int)dParam.StopERP2, 0.8f);
643 d.JointSetAMotorParam(Amotor, (int)dParam.StopERP3, 0.8f);
644 } 651 }
645 652
646 // Fudge factor is 1f by default, we're setting it to 0. We don't want it to Fudge or the 653 // Fudge factor is 1f by default, we're setting it to 0. We don't want it to Fudge or the
@@ -939,6 +946,7 @@ namespace OpenSim.Region.Physics.OdePlugin
939 946
940 PhysicsVector vec = new PhysicsVector(); 947 PhysicsVector vec = new PhysicsVector();
941 d.Vector3 vel = d.BodyGetLinearVel(Body); 948 d.Vector3 vel = d.BodyGetLinearVel(Body);
949
942 float movementdivisor = 1f; 950 float movementdivisor = 1f;
943 951
944 if (!m_alwaysRun) 952 if (!m_alwaysRun)
@@ -1052,6 +1060,10 @@ namespace OpenSim.Region.Physics.OdePlugin
1052 if (PhysicsVector.isFinite(vec)) 1060 if (PhysicsVector.isFinite(vec))
1053 { 1061 {
1054 doForce(vec); 1062 doForce(vec);
1063 if (!_zeroFlag)
1064 {
1065 AlignAvatarTiltWithCurrentDirectionOfMovement(new PhysicsVector(vec.X, vec.Y, vec.Z));
1066 }
1055 } 1067 }
1056 else 1068 else
1057 { 1069 {
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 673ae39..032b5df 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -82,7 +82,6 @@ namespace OpenSim.Region.Physics.OdePlugin
82 82
83 // private float m_tensor = 5f; 83 // private float m_tensor = 5f;
84 private int body_autodisable_frames = 20; 84 private int body_autodisable_frames = 20;
85 private IMesh primMesh = null;
86 85
87 86
88 private const CollisionCategories m_default_collisionFlags = (CollisionCategories.Geom 87 private const CollisionCategories m_default_collisionFlags = (CollisionCategories.Geom
@@ -814,14 +813,10 @@ namespace OpenSim.Region.Physics.OdePlugin
814 } 813 }
815 } 814 }
816 815
817 IMesh oldMesh = primMesh; 816 float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
817 int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
818 818
819 primMesh = mesh; 819 mesh.releaseSourceMeshData(); // free up the original mesh data to save memory
820
821 float[] vertexList = primMesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
822 int[] indexList = primMesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
823
824 primMesh.releaseSourceMeshData(); // free up the original mesh data to save memory
825 820
826 int VertexCount = vertexList.GetLength(0)/3; 821 int VertexCount = vertexList.GetLength(0)/3;
827 int IndexCount = indexList.GetLength(0); 822 int IndexCount = indexList.GetLength(0);
@@ -847,12 +842,6 @@ namespace OpenSim.Region.Physics.OdePlugin
847 return; 842 return;
848 } 843 }
849 844
850 if (oldMesh != null)
851 {
852 oldMesh.releasePinned();
853 oldMesh = null;
854 }
855
856 // if (IsPhysical && Body == (IntPtr) 0) 845 // if (IsPhysical && Body == (IntPtr) 0)
857 // { 846 // {
858 // Recreate the body 847 // Recreate the body
diff --git a/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs b/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
index d9f4951..c8ae229 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODERayCastRequestManager.cs
@@ -228,7 +228,7 @@ namespace OpenSim.Region.Physics.OdePlugin
228 mono [0x81d28b6] 228 mono [0x81d28b6]
229 mono [0x81ea2c6] 229 mono [0x81ea2c6]
230 /lib/i686/cmov/libpthread.so.0 [0xb7e744c0] 230 /lib/i686/cmov/libpthread.so.0 [0xb7e744c0]
231 /lib/i686/cmov/libc.so.6(clone+0x5e) [0xb7dcd6de] 231 /lib/i686/cmov/libc.so.6(clone+0x5e) [0xb7dcd6de]
232 */ 232 */
233 233
234 // Exclude heightfield geom 234 // Exclude heightfield geom
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 94223d8..0769c90 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -2536,7 +2536,7 @@ namespace OpenSim.Region.Physics.OdePlugin
2536 2536
2537 if (iPropertiesNotSupportedDefault == 0) 2537 if (iPropertiesNotSupportedDefault == 0)
2538 { 2538 {
2539#if SPAM 2539#if SPAM
2540 m_log.Warn("NonMesh"); 2540 m_log.Warn("NonMesh");
2541#endif 2541#endif
2542 return false; 2542 return false;
@@ -3334,7 +3334,7 @@ namespace OpenSim.Region.Physics.OdePlugin
3334 { 3334 {
3335 // this._heightmap[i] = (double)heightMap[i]; 3335 // this._heightmap[i] = (double)heightMap[i];
3336 // dbm (danx0r) -- creating a buffer zone of one extra sample all around 3336 // dbm (danx0r) -- creating a buffer zone of one extra sample all around
3337 //_origheightmap = heightMap; 3337 //_origheightmap = heightMap;
3338 3338
3339 float[] _heightmap; 3339 float[] _heightmap;
3340 3340
@@ -3520,16 +3520,16 @@ namespace OpenSim.Region.Physics.OdePlugin
3520 3520
3521 d.GeomDestroy(g); 3521 d.GeomDestroy(g);
3522 //removingHeightField = new float[0]; 3522 //removingHeightField = new float[0];
3523 } 3523 }
3524 } 3524 }
3525 } 3525 }
3526 else 3526 else
3527 { 3527 {
3528 m_log.Warn("[PHYSICS]: Couldn't proceed with UnCombine. Region has inconsistant data."); 3528 m_log.Warn("[PHYSICS]: Couldn't proceed with UnCombine. Region has inconsistant data.");
3529 } 3529 }
3530 } 3530 }
3531 } 3531 }
3532 } 3532 }
3533 3533
3534 public override void SetWaterLevel(float baseheight) 3534 public override void SetWaterLevel(float baseheight)
3535 { 3535 {