diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs index dca7150..7e93ab4 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs | |||
@@ -88,9 +88,11 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
88 | // 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. |
89 | return; | 89 | return; |
90 | } | 90 | } |
91 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,meshed,indices={1},indSz={2},vertices={3},vertSz={4}", | ||
92 | ID, indicesCount, indices.Length, verticesCount, vertices.Length); | ||
91 | 93 | ||
92 | m_terrainShape = new BulletShape(BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, | 94 | m_terrainShape = new BulletShape(BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, |
93 | indicesCount, indices, verticesCount, vertices), | 95 | indicesCount, indices, verticesCount, vertices), |
94 | BSPhysicsShapeType.SHAPE_MESH); | 96 | BSPhysicsShapeType.SHAPE_MESH); |
95 | if (m_terrainShape.ptr == IntPtr.Zero) | 97 | if (m_terrainShape.ptr == IntPtr.Zero) |
96 | { | 98 | { |
@@ -122,10 +124,10 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
122 | // Static objects are not very massive. | 124 | // Static objects are not very massive. |
123 | BulletSimAPI.SetMassProps2(m_terrainBody.ptr, 0f, Vector3.Zero); | 125 | BulletSimAPI.SetMassProps2(m_terrainBody.ptr, 0f, Vector3.Zero); |
124 | 126 | ||
125 | // Return the new terrain to the world of physical objects | 127 | // Put the new terrain to the world of physical objects |
126 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr); | 128 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr); |
127 | 129 | ||
128 | // redo its bounding box now that it is in the world | 130 | // Redo its bounding box now that it is in the world |
129 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_terrainBody.ptr); | 131 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_terrainBody.ptr); |
130 | 132 | ||
131 | BulletSimAPI.SetCollisionFilterMask2(m_terrainBody.ptr, | 133 | BulletSimAPI.SetCollisionFilterMask2(m_terrainBody.ptr, |
@@ -146,7 +148,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
146 | } | 148 | } |
147 | } | 149 | } |
148 | 150 | ||
149 | public override float GetHeightAtXYZ(Vector3 pos) | 151 | public override float GetTerrainHeightAtXYZ(Vector3 pos) |
150 | { | 152 | { |
151 | // For the moment use the saved heightmap to get the terrain height. | 153 | // For the moment use the saved heightmap to get the terrain height. |
152 | // TODO: raycast downward to find the true terrain below the position. | 154 | // TODO: raycast downward to find the true terrain below the position. |
@@ -167,6 +169,12 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
167 | return ret; | 169 | return ret; |
168 | } | 170 | } |
169 | 171 | ||
172 | // The passed position is relative to the base of the region. | ||
173 | public override float GetWaterLevelAtXYZ(Vector3 pos) | ||
174 | { | ||
175 | return PhysicsScene.SimpleWaterLevel; | ||
176 | } | ||
177 | |||
170 | // Convert the passed heightmap to mesh information suitable for CreateMeshShape2(). | 178 | // Convert the passed heightmap to mesh information suitable for CreateMeshShape2(). |
171 | // Return 'true' if successfully created. | 179 | // Return 'true' if successfully created. |
172 | public static bool ConvertHeightmapToMesh( | 180 | public static bool ConvertHeightmapToMesh( |
@@ -188,6 +196,11 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
188 | // Simple mesh creation which assumes magnification == 1. | 196 | // Simple mesh creation which assumes magnification == 1. |
189 | // TODO: do a more general solution that scales, adds new vertices and smoothes the result. | 197 | // TODO: do a more general solution that scales, adds new vertices and smoothes the result. |
190 | 198 | ||
199 | // Create an array of vertices that is sizeX+1 by sizeY+1 (note the loop | ||
200 | // from zero to <= sizeX). The triangle indices are then generated as two triangles | ||
201 | // per heightmap point. There are sizeX by sizeY of these squares. The extra row and | ||
202 | // column of vertices are used to complete the triangles of the last row and column | ||
203 | // of the heightmap. | ||
191 | try | 204 | try |
192 | { | 205 | { |
193 | // One vertice per heightmap value plus the vertices off the top and bottom edge. | 206 | // One vertice per heightmap value plus the vertices off the top and bottom edge. |
@@ -200,16 +213,18 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
200 | float magY = (float)sizeY / extentY; | 213 | float magY = (float)sizeY / extentY; |
201 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,totVert={1},totInd={2},extentBase={3},magX={4},magY={5}", | 214 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,totVert={1},totInd={2},extentBase={3},magX={4},magY={5}", |
202 | BSScene.DetailLogZero, totalVertices, totalIndices, extentBase, magX, magY); | 215 | BSScene.DetailLogZero, totalVertices, totalIndices, extentBase, magX, magY); |
216 | float minHeight = float.MaxValue; | ||
203 | // Note that sizeX+1 vertices are created since there is land between this and the next region. | 217 | // Note that sizeX+1 vertices are created since there is land between this and the next region. |
204 | for (int yy = 0; yy <= sizeY; yy++) | 218 | for (int yy = 0; yy <= sizeY; yy++) |
205 | { | 219 | { |
206 | for (int xx = 0; xx <= sizeX; xx++) // Hint: the "<=" means we got through sizeX + 1 times | 220 | for (int xx = 0; xx <= sizeX; xx++) // Hint: the "<=" means we go around sizeX + 1 times |
207 | { | 221 | { |
208 | int offset = yy * sizeX + xx; | 222 | int offset = yy * sizeX + xx; |
209 | // Extend the height from the height from the last row or column | 223 | // Extend the height with the height from the last row or column |
210 | if (yy == sizeY) offset -= sizeX; | 224 | if (yy == sizeY) offset -= sizeX; |
211 | if (xx == sizeX) offset -= 1; | 225 | if (xx == sizeX) offset -= 1; |
212 | float height = heightMap[offset]; | 226 | float height = heightMap[offset]; |
227 | minHeight = Math.Min(minHeight, height); | ||
213 | vertices[verticesCount + 0] = (float)xx * magX + extentBase.X; | 228 | vertices[verticesCount + 0] = (float)xx * magX + extentBase.X; |
214 | vertices[verticesCount + 1] = (float)yy * magY + extentBase.Y; | 229 | vertices[verticesCount + 1] = (float)yy * magY + extentBase.Y; |
215 | vertices[verticesCount + 2] = height + extentBase.Z; | 230 | vertices[verticesCount + 2] = height + extentBase.Z; |
@@ -217,14 +232,12 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
217 | } | 232 | } |
218 | } | 233 | } |
219 | verticesCount = verticesCount / 3; | 234 | verticesCount = verticesCount / 3; |
220 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,completeVerts,verCount={1}", | ||
221 | BSScene.DetailLogZero, verticesCount); | ||
222 | 235 | ||
223 | for (int yy = 0; yy < sizeY; yy++) | 236 | for (int yy = 0; yy < sizeY; yy++) |
224 | { | 237 | { |
225 | for (int xx = 0; xx < sizeX; xx++) | 238 | for (int xx = 0; xx < sizeX; xx++) |
226 | { | 239 | { |
227 | int offset = yy * sizeX + xx; | 240 | int offset = yy * (sizeX + 1) + xx; |
228 | // Each vertices is presumed to be the upper left corner of a box of two triangles | 241 | // Each vertices is presumed to be the upper left corner of a box of two triangles |
229 | indices[indicesCount + 0] = offset; | 242 | indices[indicesCount + 0] = offset; |
230 | indices[indicesCount + 1] = offset + 1; | 243 | indices[indicesCount + 1] = offset + 1; |
@@ -235,8 +248,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
235 | indicesCount += 6; | 248 | indicesCount += 6; |
236 | } | 249 | } |
237 | } | 250 | } |
238 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,completeIndices,indCount={1}", // DEEBUG DEBUG DEBUG | 251 | |
239 | LogHeader, indicesCount); // DEBUG | ||
240 | ret = true; | 252 | ret = true; |
241 | } | 253 | } |
242 | catch (Exception e) | 254 | catch (Exception e) |