diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs | 46 |
1 files changed, 9 insertions, 37 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs index a199078..3279b6f 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs | |||
@@ -76,7 +76,8 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
76 | m_sizeX = (int)(maxCoords.X - minCoords.X); | 76 | m_sizeX = (int)(maxCoords.X - minCoords.X); |
77 | m_sizeY = (int)(maxCoords.Y - minCoords.Y); | 77 | m_sizeY = (int)(maxCoords.Y - minCoords.Y); |
78 | 78 | ||
79 | if (!BSTerrainMesh.ConvertHeightmapToMesh(PhysicsScene, initialMap, m_sizeX, m_sizeY, | 79 | if (!BSTerrainMesh.ConvertHeightmapToMesh(PhysicsScene, initialMap, |
80 | m_sizeX, m_sizeY, | ||
80 | (float)m_sizeX, (float)m_sizeY, | 81 | (float)m_sizeX, (float)m_sizeY, |
81 | Vector3.Zero, 1.0f, | 82 | Vector3.Zero, 1.0f, |
82 | out indicesCount, out indices, out verticesCount, out vertices)) | 83 | out indicesCount, out indices, out verticesCount, out vertices)) |
@@ -87,8 +88,6 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
87 | // Something is very messed up and a crash is in our future. | 88 | // Something is very messed up and a crash is in our future. |
88 | return; | 89 | return; |
89 | } | 90 | } |
90 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,afterConvertHeightmapToMesh,ver={1},ind={2}", | ||
91 | ID, verticesCount, indicesCount); | ||
92 | 91 | ||
93 | m_terrainShape = new BulletShape(BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, | 92 | m_terrainShape = new BulletShape(BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, |
94 | indicesCount, indices, verticesCount, vertices), | 93 | indicesCount, indices, verticesCount, vertices), |
@@ -101,18 +100,11 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
101 | // Something is very messed up and a crash is in our future. | 100 | // Something is very messed up and a crash is in our future. |
102 | return; | 101 | return; |
103 | } | 102 | } |
104 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,afterCreateShape,shape={1}", ID, m_terrainShape); | ||
105 | 103 | ||
106 | // The terrain object initial position is at the center of the object | 104 | Vector3 pos = regionBase; |
107 | Vector3 centerPos; | ||
108 | centerPos.X = minCoords.X + (m_sizeX / 2f); | ||
109 | centerPos.Y = minCoords.Y + (m_sizeY / 2f); | ||
110 | centerPos.Z = minCoords.Z + ((maxCoords.Z - minCoords.Z) / 2f); | ||
111 | Quaternion rot = Quaternion.Identity; | 105 | Quaternion rot = Quaternion.Identity; |
112 | 106 | ||
113 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,creatingBody,centerPos={1},rot={2}", ID, centerPos, rot); | 107 | m_terrainBody = new BulletBody(id, BulletSimAPI.CreateBodyWithDefaultMotionState2( m_terrainShape.ptr, ID, pos, rot)); |
114 | m_terrainBody = new BulletBody(id, BulletSimAPI.CreateBodyWithDefaultMotionState2( | ||
115 | m_terrainShape.ptr, ID, centerPos, rot)); | ||
116 | if (m_terrainBody.ptr == IntPtr.Zero) | 108 | if (m_terrainBody.ptr == IntPtr.Zero) |
117 | { | 109 | { |
118 | // DISASTER!! | 110 | // DISASTER!! |
@@ -120,7 +112,6 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
120 | // Something is very messed up and a crash is in our future. | 112 | // Something is very messed up and a crash is in our future. |
121 | return; | 113 | return; |
122 | } | 114 | } |
123 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,afterCreateBody,body={1}", ID, m_terrainBody); | ||
124 | 115 | ||
125 | // Set current terrain attributes | 116 | // Set current terrain attributes |
126 | BulletSimAPI.SetFriction2(m_terrainBody.ptr, PhysicsScene.Params.terrainFriction); | 117 | BulletSimAPI.SetFriction2(m_terrainBody.ptr, PhysicsScene.Params.terrainFriction); |
@@ -194,7 +185,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
194 | int[] indices = new int[0]; | 185 | int[] indices = new int[0]; |
195 | float[] vertices = new float[0]; | 186 | float[] vertices = new float[0]; |
196 | 187 | ||
197 | // Simple mesh creation which assumes magnification == 1, sizeX == extentX and sizeY == extentY. | 188 | // Simple mesh creation which assumes magnification == 1. |
198 | // TODO: do a more general solution that scales, adds new vertices and smoothes the result. | 189 | // TODO: do a more general solution that scales, adds new vertices and smoothes the result. |
199 | 190 | ||
200 | try | 191 | try |
@@ -205,10 +196,10 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
205 | int totalIndices = sizeX * sizeY * 6; | 196 | int totalIndices = sizeX * sizeY * 6; |
206 | indices = new int[totalIndices]; | 197 | indices = new int[totalIndices]; |
207 | 198 | ||
208 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,totVert={1},totInd={2}", | ||
209 | BSScene.DetailLogZero, totalVertices, totalIndices); | ||
210 | float magX = (float)sizeX / extentX; | 199 | float magX = (float)sizeX / extentX; |
211 | float magY = (float)sizeY / extentY; | 200 | float magY = (float)sizeY / extentY; |
201 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,totVert={1},totInd={2},extentBase={3},magX={4},magY={5}", | ||
202 | BSScene.DetailLogZero, totalVertices, totalIndices, extentBase, magX, magY); | ||
212 | // Note that sizeX+1 vertices are created since there is land between this and the next region. | 203 | // Note that sizeX+1 vertices are created since there is land between this and the next region. |
213 | for (int yy = 0; yy <= sizeY; yy++) | 204 | for (int yy = 0; yy <= sizeY; yy++) |
214 | { | 205 | { |
@@ -222,15 +213,6 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
222 | vertices[verticesCount + 0] = (float)xx * magX + extentBase.X; | 213 | vertices[verticesCount + 0] = (float)xx * magX + extentBase.X; |
223 | vertices[verticesCount + 1] = (float)yy * magY + extentBase.Y; | 214 | vertices[verticesCount + 1] = (float)yy * magY + extentBase.Y; |
224 | vertices[verticesCount + 2] = height + extentBase.Z; | 215 | vertices[verticesCount + 2] = height + extentBase.Z; |
225 | if (physicsScene.PhysicsLogging.Enabled && verticesCount < 900) // DEBUG DEBUG DEBUG | ||
226 | { | ||
227 | Vector3 genVertex = new Vector3( | ||
228 | vertices[verticesCount + 0], | ||
229 | vertices[verticesCount + 1], | ||
230 | vertices[verticesCount + 2]); | ||
231 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,ii={1},vertex={2}", | ||
232 | BSScene.DetailLogZero, verticesCount/3, genVertex); | ||
233 | } | ||
234 | verticesCount += 3; | 216 | verticesCount += 3; |
235 | } | 217 | } |
236 | } | 218 | } |
@@ -250,16 +232,6 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
250 | indices[indicesCount + 3] = offset + 1; | 232 | indices[indicesCount + 3] = offset + 1; |
251 | indices[indicesCount + 4] = offset + sizeX + 2; | 233 | indices[indicesCount + 4] = offset + sizeX + 2; |
252 | indices[indicesCount + 5] = offset + sizeX + 1; | 234 | indices[indicesCount + 5] = offset + sizeX + 1; |
253 | if (indicesCount < (300 * 6)) // DEBUG DEBUG DEBUG | ||
254 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,i0={1},i1={2},i2={3},i3={4},i4={5},i5={6}", // DEEBUG DEBUG DEBUG | ||
255 | BSScene.DetailLogZero, | ||
256 | indices[indicesCount + 0], | ||
257 | indices[indicesCount + 1], | ||
258 | indices[indicesCount + 2], | ||
259 | indices[indicesCount + 3], | ||
260 | indices[indicesCount + 4], | ||
261 | indices[indicesCount + 5] | ||
262 | ); | ||
263 | indicesCount += 6; | 235 | indicesCount += 6; |
264 | } | 236 | } |
265 | } | 237 | } |
@@ -269,8 +241,8 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
269 | } | 241 | } |
270 | catch (Exception e) | 242 | catch (Exception e) |
271 | { | 243 | { |
272 | physicsScene.Logger.ErrorFormat("{0} Failed conversion of heightmap to mesh. Base={1}, e={2}", | 244 | physicsScene.Logger.ErrorFormat("{0} Failed conversion of heightmap to mesh. For={1}/{2}, e={3}", |
273 | LogHeader, extentBase, e); | 245 | LogHeader, physicsScene.RegionName, extentBase, e); |
274 | } | 246 | } |
275 | 247 | ||
276 | indicesCountO = indicesCount; | 248 | indicesCountO = indicesCount; |