diff options
author | BlueWall | 2012-12-07 15:36:43 -0500 |
---|---|---|
committer | BlueWall | 2012-12-07 15:36:43 -0500 |
commit | 0b455d2882a51ce0841d003f12d4c35ad9edb753 (patch) | |
tree | c48c95f48786f8fe435fc5c90477ac3b7c9eaf6c /OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs | |
parent | Merge branch 'master' into connector_plugin (diff) | |
parent | Merge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff) | |
download | opensim-SC-0b455d2882a51ce0841d003f12d4c35ad9edb753.zip opensim-SC-0b455d2882a51ce0841d003f12d4c35ad9edb753.tar.gz opensim-SC-0b455d2882a51ce0841d003f12d4c35ad9edb753.tar.bz2 opensim-SC-0b455d2882a51ce0841d003f12d4c35ad9edb753.tar.xz |
Merge branch 'master' into connector_plugin
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs index d7afdeb..6ce767d 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,14 +124,14 @@ 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.SetCollisionGroupMask2(m_terrainBody.ptr, |
132 | (uint)CollisionFilterGroups.TerrainFilter, | 134 | (uint)CollisionFilterGroups.TerrainGroup, |
133 | (uint)CollisionFilterGroups.TerrainMask); | 135 | (uint)CollisionFilterGroups.TerrainMask); |
134 | 136 | ||
135 | // Make it so the terrain will not move or be considered for movement. | 137 | // Make it so the terrain will not move or be considered for movement. |
@@ -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; |
@@ -222,7 +237,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
222 | { | 237 | { |
223 | for (int xx = 0; xx < sizeX; xx++) | 238 | for (int xx = 0; xx < sizeX; xx++) |
224 | { | 239 | { |
225 | int offset = yy * sizeX + xx; | 240 | int offset = yy * (sizeX + 1) + xx; |
226 | // 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 |
227 | indices[indicesCount + 0] = offset; | 242 | indices[indicesCount + 0] = offset; |
228 | indices[indicesCount + 1] = offset + 1; | 243 | indices[indicesCount + 1] = offset + 1; |
@@ -233,6 +248,7 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
233 | indicesCount += 6; | 248 | indicesCount += 6; |
234 | } | 249 | } |
235 | } | 250 | } |
251 | |||
236 | ret = true; | 252 | ret = true; |
237 | } | 253 | } |
238 | catch (Exception e) | 254 | catch (Exception e) |