diff options
author | Robert Adams | 2012-11-21 13:44:02 -0800 |
---|---|---|
committer | Robert Adams | 2012-11-21 16:43:45 -0800 |
commit | 4a0de0170412a939bade6cd149c94c7fd3ef020e (patch) | |
tree | b6ca9aff94d236590fe2237eba4d4cf41421939c /OpenSim/Region | |
parent | BulletSim: add terrainImplementation parameter with default to Mesh. (diff) | |
download | opensim-SC-4a0de0170412a939bade6cd149c94c7fd3ef020e.zip opensim-SC-4a0de0170412a939bade6cd149c94c7fd3ef020e.tar.gz opensim-SC-4a0de0170412a939bade6cd149c94c7fd3ef020e.tar.bz2 opensim-SC-4a0de0170412a939bade6cd149c94c7fd3ef020e.tar.xz |
BulletSim: Properly position mesh terrain on creation (fixes terrain not appearing to be working). Centralize terrain shape creation logic. Remove very chatty detail log messages.
Diffstat (limited to 'OpenSim/Region')
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs | 74 | ||||
-rwxr-xr-x | OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs | 46 |
2 files changed, 44 insertions, 76 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs index b88f561..097cd3e 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs | |||
@@ -241,38 +241,20 @@ public sealed class BSTerrainManager | |||
241 | BSTerrainPhys terrainPhys; | 241 | BSTerrainPhys terrainPhys; |
242 | if (m_terrains.TryGetValue(terrainRegionBase, out terrainPhys)) | 242 | if (m_terrains.TryGetValue(terrainRegionBase, out terrainPhys)) |
243 | { | 243 | { |
244 | // If this is terrain we know about, it's easy to update | 244 | // There is already a terrain in this spot. Free the old and build the new. |
245 | 245 | DetailLog("{0},UpdateTerrain:UpdateExisting,call,id={1},base={2},minC={3},maxC={4}", | |
246 | DetailLog("{0},UpdateTerrain:UpdateExisting,call,terrainBase={1}", BSScene.DetailLogZero, terrainRegionBase); | 246 | BSScene.DetailLogZero, id, terrainRegionBase, minCoords, minCoords); |
247 | 247 | ||
248 | PhysicsScene.TaintedObject(inTaintTime, "BSScene.UpdateTerrain:UpdateExisting", delegate() | 248 | PhysicsScene.TaintedObject(inTaintTime, "BSScene.UpdateTerrain:UpdateExisting", delegate() |
249 | { | 249 | { |
250 | // Remove old terrain from the collection | 250 | // Remove old terrain from the collection |
251 | m_terrains.Remove(terrainPhys.TerrainBase); | 251 | m_terrains.Remove(terrainRegionBase); |
252 | // Release any physical memory it may be using. | 252 | // Release any physical memory it may be using. |
253 | terrainPhys.Dispose(); | 253 | terrainPhys.Dispose(); |
254 | 254 | ||
255 | BSTerrainPhys newTerrainPhys = null; ; | ||
256 | if (MegaRegionParentPhysicsScene == null) | 255 | if (MegaRegionParentPhysicsScene == null) |
257 | { | 256 | { |
258 | // TODO: redo terrain implementation selection to be centralized (there is another | 257 | BSTerrainPhys newTerrainPhys = BuildPhysicalTerrain(terrainRegionBase, id, heightMap, minCoords, maxCoords); |
259 | // use below) and to accept an asset specification (for a mesh). | ||
260 | switch ((int)PhysicsScene.Params.terrainImplementation) | ||
261 | { | ||
262 | case (int)BSTerrainPhys.TerrainImplementation.Heightmap: | ||
263 | newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, terrainRegionBase, id, | ||
264 | heightMap, minCoords, maxCoords); | ||
265 | break; | ||
266 | case (int)BSTerrainPhys.TerrainImplementation.Mesh: | ||
267 | newTerrainPhys = new BSTerrainMesh(PhysicsScene, terrainRegionBase, id, | ||
268 | heightMap, minCoords, maxCoords); | ||
269 | break; | ||
270 | default: | ||
271 | PhysicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. type={1}/{2}", | ||
272 | LogHeader, (int)PhysicsScene.Params.terrainImplementation, PhysicsScene.Params.terrainImplementation); | ||
273 | break; | ||
274 | } | ||
275 | |||
276 | m_terrains.Add(terrainRegionBase, newTerrainPhys); | 258 | m_terrains.Add(terrainRegionBase, newTerrainPhys); |
277 | 259 | ||
278 | m_terrainModified = true; | 260 | m_terrainModified = true; |
@@ -313,22 +295,7 @@ public sealed class BSTerrainManager | |||
313 | { | 295 | { |
314 | DetailLog("{0},UpdateTerrain:NewTerrain,taint,baseX={1},baseY={2}", | 296 | DetailLog("{0},UpdateTerrain:NewTerrain,taint,baseX={1},baseY={2}", |
315 | BSScene.DetailLogZero, minCoordsX.X, minCoordsX.Y); | 297 | BSScene.DetailLogZero, minCoordsX.X, minCoordsX.Y); |
316 | BSTerrainPhys newTerrainPhys = null; | 298 | BSTerrainPhys newTerrainPhys = BuildPhysicalTerrain(terrainRegionBase, id, heightMap, minCoords, maxCoords); |
317 | switch ((int)PhysicsScene.Params.terrainImplementation) | ||
318 | { | ||
319 | case (int)BSTerrainPhys.TerrainImplementation.Heightmap: | ||
320 | newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, terrainRegionBase, id, | ||
321 | heightMap, minCoords, maxCoords); | ||
322 | break; | ||
323 | case (int)BSTerrainPhys.TerrainImplementation.Mesh: | ||
324 | newTerrainPhys = new BSTerrainMesh(PhysicsScene, terrainRegionBase, id, | ||
325 | heightMap, minCoords, maxCoords); | ||
326 | break; | ||
327 | default: | ||
328 | PhysicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. type={1}/{2}", | ||
329 | LogHeader, (int)PhysicsScene.Params.terrainImplementation, PhysicsScene.Params.terrainImplementation); | ||
330 | break; | ||
331 | } | ||
332 | m_terrains.Add(terrainRegionBase, newTerrainPhys); | 299 | m_terrains.Add(terrainRegionBase, newTerrainPhys); |
333 | 300 | ||
334 | m_terrainModified = true; | 301 | m_terrainModified = true; |
@@ -336,6 +303,35 @@ public sealed class BSTerrainManager | |||
336 | } | 303 | } |
337 | } | 304 | } |
338 | 305 | ||
306 | // TODO: redo terrain implementation selection to allow other base types than heightMap. | ||
307 | private BSTerrainPhys BuildPhysicalTerrain(Vector3 terrainRegionBase, uint id, float[] heightMap, Vector3 minCoords, Vector3 maxCoords) | ||
308 | { | ||
309 | PhysicsScene.Logger.DebugFormat("{0} Terrain for {1}/{2} created with {3}", | ||
310 | LogHeader, PhysicsScene.RegionName, terrainRegionBase, | ||
311 | PhysicsScene.Params.terrainImplementation); | ||
312 | BSTerrainPhys newTerrainPhys = null; | ||
313 | switch ((int)PhysicsScene.Params.terrainImplementation) | ||
314 | { | ||
315 | case (int)BSTerrainPhys.TerrainImplementation.Heightmap: | ||
316 | newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, terrainRegionBase, id, | ||
317 | heightMap, minCoords, maxCoords); | ||
318 | break; | ||
319 | case (int)BSTerrainPhys.TerrainImplementation.Mesh: | ||
320 | newTerrainPhys = new BSTerrainMesh(PhysicsScene, terrainRegionBase, id, | ||
321 | heightMap, minCoords, maxCoords); | ||
322 | break; | ||
323 | default: | ||
324 | PhysicsScene.Logger.ErrorFormat("{0} Bad terrain implementation specified. Type={1}/{2},Region={3}/{4}", | ||
325 | LogHeader, | ||
326 | (int)PhysicsScene.Params.terrainImplementation, | ||
327 | PhysicsScene.Params.terrainImplementation, | ||
328 | PhysicsScene.RegionName, terrainRegionBase); | ||
329 | break; | ||
330 | } | ||
331 | return newTerrainPhys; | ||
332 | } | ||
333 | |||
334 | |||
339 | // Given an X and Y, find the height of the terrain. | 335 | // Given an X and Y, find the height of the terrain. |
340 | // Since we could be handling multiple terrains for a mega-region, | 336 | // Since we could be handling multiple terrains for a mega-region, |
341 | // the base of the region is calcuated assuming all regions are | 337 | // the base of the region is calcuated assuming all regions are |
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; |