diff options
author | Robert Adams | 2012-11-20 20:36:49 -0800 |
---|---|---|
committer | Robert Adams | 2012-11-21 16:43:21 -0800 |
commit | 34cbc738a84b7946a87e8bfd3bb04869519b3dee (patch) | |
tree | 1e0c0891022162f4aac9793ef5937c254bbaa2fa | |
parent | BulletSim: pull heightmap implementation out of the terrain manager so a mesh... (diff) | |
download | opensim-SC-34cbc738a84b7946a87e8bfd3bb04869519b3dee.zip opensim-SC-34cbc738a84b7946a87e8bfd3bb04869519b3dee.tar.gz opensim-SC-34cbc738a84b7946a87e8bfd3bb04869519b3dee.tar.bz2 opensim-SC-34cbc738a84b7946a87e8bfd3bb04869519b3dee.tar.xz |
BulletSim: enablement and debugging of mesh terrain.
Diffstat (limited to '')
4 files changed, 253 insertions, 36 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs index 3bb63cd..e9fd0cb 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainHeightmap.cs | |||
@@ -44,10 +44,11 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
44 | { | 44 | { |
45 | static string LogHeader = "[BULLETSIM TERRAIN HEIGHTMAP]"; | 45 | static string LogHeader = "[BULLETSIM TERRAIN HEIGHTMAP]"; |
46 | 46 | ||
47 | BulletHeightMapInfo m_mapInfo; | 47 | BulletHeightMapInfo m_mapInfo = null; |
48 | 48 | ||
49 | public BSTerrainHeightmap(BSScene physicsScene, uint id, Vector3 regionSize) | 49 | // Constructor to build a default, flat heightmap terrain. |
50 | : base(physicsScene) | 50 | public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize) |
51 | : base(physicsScene, regionBase, id) | ||
51 | { | 52 | { |
52 | Vector3 minTerrainCoords = new Vector3(0f, 0f, BSTerrainManager.HEIGHT_INITIALIZATION - BSTerrainManager.HEIGHT_EQUAL_FUDGE); | 53 | Vector3 minTerrainCoords = new Vector3(0f, 0f, BSTerrainManager.HEIGHT_INITIALIZATION - BSTerrainManager.HEIGHT_EQUAL_FUDGE); |
53 | Vector3 maxTerrainCoords = new Vector3(regionSize.X, regionSize.Y, BSTerrainManager.HEIGHT_INITIALIZATION); | 54 | Vector3 maxTerrainCoords = new Vector3(regionSize.X, regionSize.Y, BSTerrainManager.HEIGHT_INITIALIZATION); |
@@ -60,21 +61,23 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
60 | m_mapInfo = new BulletHeightMapInfo(id, initialMap, IntPtr.Zero); | 61 | m_mapInfo = new BulletHeightMapInfo(id, initialMap, IntPtr.Zero); |
61 | m_mapInfo.minCoords = minTerrainCoords; | 62 | m_mapInfo.minCoords = minTerrainCoords; |
62 | m_mapInfo.maxCoords = maxTerrainCoords; | 63 | m_mapInfo.maxCoords = maxTerrainCoords; |
64 | m_mapInfo.terrainRegionBase = TerrainBase; | ||
63 | // Don't have to free any previous since we just got here. | 65 | // Don't have to free any previous since we just got here. |
64 | BuildHeightmapTerrain(); | 66 | BuildHeightmapTerrain(); |
65 | } | 67 | } |
66 | 68 | ||
67 | // This minCoords and maxCoords passed in give the size of the terrain (min and max Z | 69 | // This minCoords and maxCoords passed in give the size of the terrain (min and max Z |
68 | // are the high and low points of the heightmap). | 70 | // are the high and low points of the heightmap). |
69 | public BSTerrainHeightmap(BSScene physicsScene, uint id, float[] initialMap, | 71 | public BSTerrainHeightmap(BSScene physicsScene, Vector3 regionBase, uint id, float[] initialMap, |
70 | Vector3 minCoords, Vector3 maxCoords) | 72 | Vector3 minCoords, Vector3 maxCoords) |
71 | : base(physicsScene) | 73 | : base(physicsScene, regionBase, id) |
72 | { | 74 | { |
73 | m_mapInfo = new BulletHeightMapInfo(id, initialMap, IntPtr.Zero); | 75 | m_mapInfo = new BulletHeightMapInfo(id, initialMap, IntPtr.Zero); |
74 | m_mapInfo.minCoords = minCoords; | 76 | m_mapInfo.minCoords = minCoords; |
75 | m_mapInfo.maxCoords = maxCoords; | 77 | m_mapInfo.maxCoords = maxCoords; |
76 | m_mapInfo.minZ = minCoords.Z; | 78 | m_mapInfo.minZ = minCoords.Z; |
77 | m_mapInfo.maxZ = maxCoords.Z; | 79 | m_mapInfo.maxZ = maxCoords.Z; |
80 | m_mapInfo.terrainRegionBase = TerrainBase; | ||
78 | 81 | ||
79 | // Don't have to free any previous since we just got here. | 82 | // Don't have to free any previous since we just got here. |
80 | BuildHeightmapTerrain(); | 83 | BuildHeightmapTerrain(); |
@@ -135,12 +138,10 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
135 | { | 138 | { |
136 | if (m_mapInfo.terrainBody.ptr != IntPtr.Zero) | 139 | if (m_mapInfo.terrainBody.ptr != IntPtr.Zero) |
137 | { | 140 | { |
138 | if (BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr)) | 141 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); |
139 | { | 142 | // Frees both the body and the shape. |
140 | // Frees both the body and the shape. | 143 | BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); |
141 | BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_mapInfo.terrainBody.ptr); | 144 | BulletSimAPI.ReleaseHeightMapInfo2(m_mapInfo.Ptr); |
142 | BulletSimAPI.ReleaseHeightMapInfo2(m_mapInfo.Ptr); | ||
143 | } | ||
144 | } | 145 | } |
145 | } | 146 | } |
146 | m_mapInfo = null; | 147 | m_mapInfo = null; |
@@ -165,10 +166,5 @@ public sealed class BSTerrainHeightmap : BSTerrainPhys | |||
165 | } | 166 | } |
166 | return ret; | 167 | return ret; |
167 | } | 168 | } |
168 | |||
169 | public override Vector3 TerrainBase | ||
170 | { | ||
171 | get { return m_mapInfo.terrainRegionBase; } | ||
172 | } | ||
173 | } | 169 | } |
174 | } | 170 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs index db04299..ed0dfa8 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainManager.cs | |||
@@ -45,14 +45,18 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
45 | public abstract class BSTerrainPhys : IDisposable | 45 | public abstract class BSTerrainPhys : IDisposable |
46 | { | 46 | { |
47 | public BSScene PhysicsScene { get; private set; } | 47 | public BSScene PhysicsScene { get; private set; } |
48 | // Base of the region in world coordinates. Coordinates inside the region are relative to this. | ||
49 | public Vector3 TerrainBase { get; private set; } | ||
50 | public uint ID { get; private set; } | ||
48 | 51 | ||
49 | public BSTerrainPhys(BSScene physicsScene) | 52 | public BSTerrainPhys(BSScene physicsScene, Vector3 regionBase, uint id) |
50 | { | 53 | { |
51 | PhysicsScene = physicsScene; | 54 | PhysicsScene = physicsScene; |
55 | TerrainBase = regionBase; | ||
56 | ID = id; | ||
52 | } | 57 | } |
53 | public abstract void Dispose(); | 58 | public abstract void Dispose(); |
54 | public abstract float GetHeightAtXYZ(Vector3 pos); | 59 | public abstract float GetHeightAtXYZ(Vector3 pos); |
55 | public abstract Vector3 TerrainBase { get; } | ||
56 | } | 60 | } |
57 | 61 | ||
58 | // ========================================================================================== | 62 | // ========================================================================================== |
@@ -133,7 +137,7 @@ public sealed class BSTerrainManager | |||
133 | (uint)CollisionFilterGroups.GroundPlaneFilter, (uint)CollisionFilterGroups.GroundPlaneMask); | 137 | (uint)CollisionFilterGroups.GroundPlaneFilter, (uint)CollisionFilterGroups.GroundPlaneMask); |
134 | 138 | ||
135 | // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain. | 139 | // Build an initial terrain and put it in the world. This quickly gets replaced by the real region terrain. |
136 | BSTerrainPhys initialTerrain = new BSTerrainHeightmap(PhysicsScene, BSScene.TERRAIN_ID, DefaultRegionSize); | 140 | BSTerrainPhys initialTerrain = new BSTerrainHeightmap(PhysicsScene, Vector3.Zero, BSScene.TERRAIN_ID, DefaultRegionSize); |
137 | m_terrains.Add(Vector3.Zero, initialTerrain); | 141 | m_terrains.Add(Vector3.Zero, initialTerrain); |
138 | } | 142 | } |
139 | 143 | ||
@@ -208,10 +212,9 @@ public sealed class BSTerrainManager | |||
208 | BSScene.DetailLogZero, minCoords, maxCoords, inTaintTime); | 212 | BSScene.DetailLogZero, minCoords, maxCoords, inTaintTime); |
209 | 213 | ||
210 | // Find high and low points of passed heightmap. | 214 | // Find high and low points of passed heightmap. |
211 | // The min and max passed in are usually the region objects can exist in (maximum | 215 | // The min and max passed in is usually the area objects can be in (maximum |
212 | // object height, for instance). The terrain wants the bounding box for the | 216 | // object height, for instance). The terrain wants the bounding box for the |
213 | // terrain so we replace passed min and max Z with the actual terrain min/max Z. | 217 | // terrain so we replace passed min and max Z with the actual terrain min/max Z. |
214 | // limit, for | ||
215 | float minZ = float.MaxValue; | 218 | float minZ = float.MaxValue; |
216 | float maxZ = float.MinValue; | 219 | float maxZ = float.MinValue; |
217 | foreach (float height in heightMap) | 220 | foreach (float height in heightMap) |
@@ -219,6 +222,11 @@ public sealed class BSTerrainManager | |||
219 | if (height < minZ) minZ = height; | 222 | if (height < minZ) minZ = height; |
220 | if (height > maxZ) maxZ = height; | 223 | if (height > maxZ) maxZ = height; |
221 | } | 224 | } |
225 | if (minZ == maxZ) | ||
226 | { | ||
227 | // If min and max are the same, reduce min a little bit so a good bounding box is created. | ||
228 | minZ -= BSTerrainManager.HEIGHT_EQUAL_FUDGE; | ||
229 | } | ||
222 | minCoords.Z = minZ; | 230 | minCoords.Z = minZ; |
223 | maxCoords.Z = maxZ; | 231 | maxCoords.Z = maxZ; |
224 | 232 | ||
@@ -240,7 +248,9 @@ public sealed class BSTerrainManager | |||
240 | 248 | ||
241 | if (MegaRegionParentPhysicsScene == null) | 249 | if (MegaRegionParentPhysicsScene == null) |
242 | { | 250 | { |
243 | BSTerrainPhys newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, id, | 251 | // BSTerrainPhys newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, terrainRegionBase, id, |
252 | // heightMap, minCoords, maxCoords); | ||
253 | BSTerrainPhys newTerrainPhys = new BSTerrainMesh(PhysicsScene, terrainRegionBase, id, | ||
244 | heightMap, minCoords, maxCoords); | 254 | heightMap, minCoords, maxCoords); |
245 | m_terrains.Add(terrainRegionBase, newTerrainPhys); | 255 | m_terrains.Add(terrainRegionBase, newTerrainPhys); |
246 | 256 | ||
@@ -282,8 +292,8 @@ public sealed class BSTerrainManager | |||
282 | { | 292 | { |
283 | DetailLog("{0},UpdateTerrain:NewTerrain,taint,baseX={1},baseY={2}", | 293 | DetailLog("{0},UpdateTerrain:NewTerrain,taint,baseX={1},baseY={2}", |
284 | BSScene.DetailLogZero, minCoordsX.X, minCoordsX.Y); | 294 | BSScene.DetailLogZero, minCoordsX.X, minCoordsX.Y); |
285 | BSTerrainPhys newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, newTerrainID, | 295 | BSTerrainPhys newTerrainPhys = new BSTerrainHeightmap(PhysicsScene, terrainRegionBase, |
286 | heightMapX, minCoordsX, maxCoordsX); | 296 | newTerrainID, heightMapX, minCoordsX, maxCoordsX); |
287 | m_terrains.Add(terrainRegionBase, newTerrainPhys); | 297 | m_terrains.Add(terrainRegionBase, newTerrainPhys); |
288 | 298 | ||
289 | m_terrainModified = true; | 299 | m_terrainModified = true; |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs index 387c78b..bbb014a 100755 --- a/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSTerrainMesh.cs | |||
@@ -44,30 +44,241 @@ public sealed class BSTerrainMesh : BSTerrainPhys | |||
44 | { | 44 | { |
45 | static string LogHeader = "[BULLETSIM TERRAIN MESH]"; | 45 | static string LogHeader = "[BULLETSIM TERRAIN MESH]"; |
46 | 46 | ||
47 | public BSTerrainMesh(BSScene physicsScene, uint id, Vector3 regionSize) | 47 | private float[] m_savedHeightMap; |
48 | : base(physicsScene) | 48 | int m_sizeX; |
49 | int m_sizeY; | ||
50 | |||
51 | BulletShape m_terrainShape; | ||
52 | BulletBody m_terrainBody; | ||
53 | |||
54 | public BSTerrainMesh(BSScene physicsScene, Vector3 regionBase, uint id, Vector3 regionSize) | ||
55 | : base(physicsScene, regionBase, id) | ||
49 | { | 56 | { |
50 | } | 57 | } |
51 | 58 | ||
52 | public BSTerrainMesh(BSScene physicsScene /* parameters for making mesh */) | 59 | public BSTerrainMesh(BSScene physicsScene, Vector3 regionBase, uint id /* parameters for making mesh */) |
53 | : base(physicsScene) | 60 | : base(physicsScene, regionBase, id) |
54 | { | 61 | { |
55 | } | 62 | } |
56 | 63 | ||
64 | // Create terrain mesh from a heightmap. | ||
65 | public BSTerrainMesh(BSScene physicsScene, Vector3 regionBase, uint id, float[] initialMap, | ||
66 | Vector3 minCoords, Vector3 maxCoords) | ||
67 | : base(physicsScene, regionBase, id) | ||
68 | { | ||
69 | int indicesCount; | ||
70 | int[] indices; | ||
71 | int verticesCount; | ||
72 | float[] vertices; | ||
73 | |||
74 | m_savedHeightMap = initialMap; | ||
75 | |||
76 | m_sizeX = (int)(maxCoords.X - minCoords.X); | ||
77 | m_sizeY = (int)(maxCoords.Y - minCoords.Y); | ||
78 | |||
79 | if (!BSTerrainMesh.ConvertHeightmapToMesh(PhysicsScene, initialMap, m_sizeX, m_sizeY, | ||
80 | (float)m_sizeX, (float)m_sizeY, | ||
81 | Vector3.Zero, 1.0f, | ||
82 | out indicesCount, out indices, out verticesCount, out vertices)) | ||
83 | { | ||
84 | // DISASTER!! | ||
85 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,failedConversionOfHeightmap", ID); | ||
86 | PhysicsScene.Logger.ErrorFormat("{0} Failed conversion of heightmap to mesh! base={1}", LogHeader, TerrainBase); | ||
87 | // Something is very messed up and a crash is in our future. | ||
88 | return; | ||
89 | } | ||
90 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,afterConvertHeightmapToMesh,ver={1},ind={2}", | ||
91 | ID, verticesCount, indicesCount); | ||
92 | |||
93 | m_terrainShape = new BulletShape(BulletSimAPI.CreateMeshShape2(PhysicsScene.World.ptr, | ||
94 | indicesCount, indices, verticesCount, vertices), | ||
95 | PhysicsShapeType.SHAPE_MESH); | ||
96 | if (m_terrainShape.ptr == IntPtr.Zero) | ||
97 | { | ||
98 | // DISASTER!! | ||
99 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,failedCreationOfShape", ID); | ||
100 | physicsScene.Logger.ErrorFormat("{0} Failed creation of terrain mesh! base={1}", LogHeader, TerrainBase); | ||
101 | // Something is very messed up and a crash is in our future. | ||
102 | return; | ||
103 | } | ||
104 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,afterCreateShape,shape={1}", ID, m_terrainShape); | ||
105 | |||
106 | // The terrain object initial position is at the center of the object | ||
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; | ||
112 | |||
113 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,creatingBody,centerPos={1},rot={2}", ID, centerPos, rot); | ||
114 | m_terrainBody = new BulletBody(id, BulletSimAPI.CreateBodyWithDefaultMotionState2( | ||
115 | m_terrainShape.ptr, ID, centerPos, rot)); | ||
116 | if (m_terrainBody.ptr == IntPtr.Zero) | ||
117 | { | ||
118 | // DISASTER!! | ||
119 | physicsScene.Logger.ErrorFormat("{0} Failed creation of terrain body! base={1}", LogHeader, TerrainBase); | ||
120 | // Something is very messed up and a crash is in our future. | ||
121 | return; | ||
122 | } | ||
123 | PhysicsScene.DetailLog("{0},BSTerrainMesh.create,afterCreateBody,body={1}", ID, m_terrainBody); | ||
124 | |||
125 | // Set current terrain attributes | ||
126 | BulletSimAPI.SetFriction2(m_terrainBody.ptr, PhysicsScene.Params.terrainFriction); | ||
127 | BulletSimAPI.SetHitFraction2(m_terrainBody.ptr, PhysicsScene.Params.terrainHitFraction); | ||
128 | BulletSimAPI.SetRestitution2(m_terrainBody.ptr, PhysicsScene.Params.terrainRestitution); | ||
129 | BulletSimAPI.SetCollisionFlags2(m_terrainBody.ptr, CollisionFlags.CF_STATIC_OBJECT); | ||
130 | |||
131 | // Static objects are not very massive. | ||
132 | BulletSimAPI.SetMassProps2(m_terrainBody.ptr, 0f, Vector3.Zero); | ||
133 | |||
134 | // Return the new terrain to the world of physical objects | ||
135 | BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr); | ||
136 | |||
137 | // redo its bounding box now that it is in the world | ||
138 | BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, m_terrainBody.ptr); | ||
139 | |||
140 | BulletSimAPI.SetCollisionFilterMask2(m_terrainBody.ptr, | ||
141 | (uint)CollisionFilterGroups.TerrainFilter, | ||
142 | (uint)CollisionFilterGroups.TerrainMask); | ||
143 | |||
144 | // Make it so the terrain will not move or be considered for movement. | ||
145 | BulletSimAPI.ForceActivationState2(m_terrainBody.ptr, ActivationState.DISABLE_SIMULATION); | ||
146 | } | ||
147 | |||
57 | public override void Dispose() | 148 | public override void Dispose() |
58 | { | 149 | { |
59 | return; | 150 | if (m_terrainBody.ptr != IntPtr.Zero) |
151 | { | ||
152 | BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, m_terrainBody.ptr); | ||
153 | // Frees both the body and the shape. | ||
154 | BulletSimAPI.DestroyObject2(PhysicsScene.World.ptr, m_terrainBody.ptr); | ||
155 | } | ||
60 | } | 156 | } |
61 | 157 | ||
62 | public override float GetHeightAtXYZ(Vector3 pos) | 158 | public override float GetHeightAtXYZ(Vector3 pos) |
63 | { | 159 | { |
64 | return 12345f; | 160 | // For the moment use the saved heightmap to get the terrain height. |
161 | // TODO: raycast downward to find the true terrain below the position. | ||
162 | float ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET; | ||
163 | |||
164 | int mapIndex = (int)pos.Y * m_sizeY + (int)pos.X; | ||
165 | try | ||
166 | { | ||
167 | ret = m_savedHeightMap[mapIndex]; | ||
168 | } | ||
169 | catch | ||
170 | { | ||
171 | // Sometimes they give us wonky values of X and Y. Give a warning and return something. | ||
172 | PhysicsScene.Logger.WarnFormat("{0} Bad request for terrain height. terrainBase={1}, pos={2}", | ||
173 | LogHeader, TerrainBase, pos); | ||
174 | ret = BSTerrainManager.HEIGHT_GETHEIGHT_RET; | ||
175 | } | ||
176 | return ret; | ||
65 | } | 177 | } |
66 | 178 | ||
67 | public override Vector3 TerrainBase | 179 | // Convert the passed heightmap to mesh information suitable for CreateMeshShape2(). |
180 | // Return 'true' if successfully created. | ||
181 | public static bool ConvertHeightmapToMesh( | ||
182 | BSScene physicsScene, | ||
183 | float[] heightMap, int sizeX, int sizeY, // parameters of incoming heightmap | ||
184 | float extentX, float extentY, // zero based range for output vertices | ||
185 | Vector3 extentBase, // base to be added to all vertices | ||
186 | float magnification, // number of vertices to create between heightMap coords | ||
187 | out int indicesCountO, out int[] indicesO, | ||
188 | out int verticesCountO, out float[] verticesO) | ||
68 | { | 189 | { |
69 | get { return Vector3.Zero; } | 190 | bool ret = false; |
70 | } | 191 | |
192 | int indicesCount = 0; | ||
193 | int verticesCount = 0; | ||
194 | int[] indices = new int[0]; | ||
195 | float[] vertices = new float[0]; | ||
71 | 196 | ||
197 | // Simple mesh creation which assumes magnification == 1, sizeX == extentX and sizeY == extentY. | ||
198 | // TODO: do a more general solution that scales, adds new vertices and smoothes the result. | ||
199 | |||
200 | try | ||
201 | { | ||
202 | // One vertice per heightmap value plus the vertices off the top and bottom edge. | ||
203 | int totalVertices = (sizeX + 1) * (sizeY + 1); | ||
204 | vertices = new float[totalVertices * 3]; | ||
205 | int totalIndices = sizeX * sizeY * 6; | ||
206 | indices = new int[totalIndices]; | ||
207 | |||
208 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,totVert={1},totInd={2}", | ||
209 | BSScene.DetailLogZero, totalVertices, totalIndices); | ||
210 | float magX = (float)sizeX / extentX; | ||
211 | float magY = (float)sizeY / extentY; | ||
212 | // 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++) | ||
214 | { | ||
215 | for (int xx = 0; xx <= sizeX; xx++) // Hint: the "<=" means we got through sizeX + 1 times | ||
216 | { | ||
217 | int offset = yy * sizeX + xx; | ||
218 | // Extend the height from the height from the last row or column | ||
219 | if (yy == sizeY) offset -= sizeX; | ||
220 | if (xx == sizeX) offset -= 1; | ||
221 | float height = heightMap[offset]; | ||
222 | vertices[verticesCount + 0] = (float)xx * magX + extentBase.X; | ||
223 | vertices[verticesCount + 1] = (float)yy * magY + extentBase.Y; | ||
224 | 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; | ||
235 | } | ||
236 | } | ||
237 | verticesCount = verticesCount / 3; | ||
238 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,completeVerts,verCount={1}", | ||
239 | BSScene.DetailLogZero, verticesCount); | ||
240 | |||
241 | for (int yy = 0; yy < sizeY; yy++) | ||
242 | { | ||
243 | for (int xx = 0; xx < sizeX; xx++) | ||
244 | { | ||
245 | int offset = yy * sizeX + xx; | ||
246 | // Each vertices is presumed to be the upper left corner of a box of two triangles | ||
247 | indices[indicesCount + 0] = offset; | ||
248 | indices[indicesCount + 1] = offset + 1; | ||
249 | indices[indicesCount + 2] = offset + sizeX + 1; // accounting for the extra column | ||
250 | indices[indicesCount + 3] = offset + 1; | ||
251 | indices[indicesCount + 4] = offset + sizeX + 2; | ||
252 | 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; | ||
264 | } | ||
265 | } | ||
266 | physicsScene.DetailLog("{0},BSTerrainMesh.ConvertHeightMapToMesh,completeIndices,indCount={1}", // DEEBUG DEBUG DEBUG | ||
267 | LogHeader, indicesCount); // DEBUG | ||
268 | ret = true; | ||
269 | } | ||
270 | catch (Exception e) | ||
271 | { | ||
272 | physicsScene.Logger.ErrorFormat("{0} Failed conversion of heightmap to mesh. Base={1}, e={2}", | ||
273 | LogHeader, extentBase, e); | ||
274 | } | ||
275 | |||
276 | indicesCountO = indicesCount; | ||
277 | indicesO = indices; | ||
278 | verticesCountO = verticesCount; | ||
279 | verticesO = vertices; | ||
280 | |||
281 | return ret; | ||
282 | } | ||
72 | } | 283 | } |
73 | } | 284 | } |
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs index bab3b3d..a2271a9 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BulletSimAPI.cs | |||
@@ -391,13 +391,13 @@ public enum CollisionFilterGroups : uint | |||
391 | ObjectFilter = BSolidFilter, | 391 | ObjectFilter = BSolidFilter, |
392 | ObjectMask = BAllFilter, | 392 | ObjectMask = BAllFilter, |
393 | StaticObjectFilter = BStaticFilter, | 393 | StaticObjectFilter = BStaticFilter, |
394 | StaticObjectMask = BAllFilter, | 394 | StaticObjectMask = BAllFilter & ~BStaticFilter, // static objects don't collide with each other |
395 | LinksetFilter = BLinksetFilter, | 395 | LinksetFilter = BLinksetFilter, |
396 | LinksetMask = BAllFilter & ~BLinksetFilter, | 396 | LinksetMask = BAllFilter & ~BLinksetFilter, // linkset objects don't collide with each other |
397 | VolumeDetectFilter = BSensorTrigger, | 397 | VolumeDetectFilter = BSensorTrigger, |
398 | VolumeDetectMask = ~BSensorTrigger, | 398 | VolumeDetectMask = ~BSensorTrigger, |
399 | TerrainFilter = BTerrainFilter, | 399 | TerrainFilter = BTerrainFilter, |
400 | TerrainMask = BAllFilter & ~BStaticFilter, | 400 | TerrainMask = BAllFilter & ~BStaticFilter, // static objects on the ground don't collide |
401 | GroundPlaneFilter = BGroundPlaneFilter, | 401 | GroundPlaneFilter = BGroundPlaneFilter, |
402 | GroundPlaneMask = BAllFilter | 402 | GroundPlaneMask = BAllFilter |
403 | 403 | ||