diff options
author | UbitUmarov | 2015-09-01 14:54:35 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 14:54:35 +0100 |
commit | 371c9dd2af01a2e7422ec901ee1f80757284a78c (patch) | |
tree | 058d2a513cacb12efcce0c0df0ae14ad135dbfe2 /OpenSim/Region/CoreModules/World/Warp3DMap | |
parent | remove lixo (diff) | |
parent | dont change camera on crossings (diff) | |
download | opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.zip opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.gz opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.bz2 opensim-SC_OLD-371c9dd2af01a2e7422ec901ee1f80757284a78c.tar.xz |
bad merge?
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Warp3DMap')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs | 122 | ||||
-rw-r--r-- | OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs | 64 |
2 files changed, 179 insertions, 7 deletions
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs index 9534ad3..77c10b8 100644 --- a/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs +++ b/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs | |||
@@ -79,9 +79,13 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
79 | /// <remarks>Based on the algorithm described at http://opensimulator.org/wiki/Terrain_Splatting | 79 | /// <remarks>Based on the algorithm described at http://opensimulator.org/wiki/Terrain_Splatting |
80 | /// Note we create a 256x256 dimension texture even if the actual terrain is larger. | 80 | /// Note we create a 256x256 dimension texture even if the actual terrain is larger. |
81 | /// </remarks> | 81 | /// </remarks> |
82 | <<<<<<< HEAD | ||
82 | public static Bitmap Splat(ITerrainChannel terrain, | 83 | public static Bitmap Splat(ITerrainChannel terrain, |
83 | UUID[] textureIDs, float[] startHeights, float[] heightRanges, | 84 | UUID[] textureIDs, float[] startHeights, float[] heightRanges, |
84 | Vector3d regionPosition, IAssetService assetService, bool textureTerrain) | 85 | Vector3d regionPosition, IAssetService assetService, bool textureTerrain) |
86 | ======= | ||
87 | public static Bitmap Splat(ITerrainChannel terrain, UUID[] textureIDs, float[] startHeights, float[] heightRanges, Vector3d regionPosition, IAssetService assetService, bool textureTerrain) | ||
88 | >>>>>>> avn/ubitvar | ||
85 | { | 89 | { |
86 | Debug.Assert(textureIDs.Length == 4); | 90 | Debug.Assert(textureIDs.Length == 4); |
87 | Debug.Assert(startHeights.Length == 4); | 91 | Debug.Assert(startHeights.Length == 4); |
@@ -195,12 +199,74 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
195 | using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i])) | 199 | using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i])) |
196 | gfx.FillRectangle(brush, 0, 0, 256, 256); | 200 | gfx.FillRectangle(brush, 0, 0, 256, 256); |
197 | } | 201 | } |
202 | else | ||
203 | { | ||
204 | if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256) | ||
205 | { | ||
206 | detailTexture[i] = ResizeBitmap(detailTexture[i], 256, 256); | ||
207 | } | ||
208 | } | ||
198 | } | 209 | } |
210 | <<<<<<< HEAD | ||
199 | else | 211 | else |
212 | ======= | ||
213 | |||
214 | #region Layer Map | ||
215 | |||
216 | float[,] layermap = new float[256 , 256]; | ||
217 | |||
218 | int xFactor = terrain.Width / 256; | ||
219 | int yFactor = terrain.Height / 256; | ||
220 | |||
221 | for (int y = 0; y < 256; y++) | ||
222 | >>>>>>> avn/ubitvar | ||
200 | { | 223 | { |
201 | if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256) | 224 | if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256) |
202 | { | 225 | { |
226 | <<<<<<< HEAD | ||
203 | detailTexture[i] = ResizeBitmap(detailTexture[i], 256, 256); | 227 | detailTexture[i] = ResizeBitmap(detailTexture[i], 256, 256); |
228 | ======= | ||
229 | float height = (float)terrain[x * xFactor, y * yFactor]; | ||
230 | |||
231 | float pctX = (float)x / 255f; | ||
232 | float pctY = (float)y / 255f; | ||
233 | |||
234 | // Use bilinear interpolation between the four corners of start height and | ||
235 | // height range to select the current values at this position | ||
236 | float startHeight = ImageUtils.Bilinear( | ||
237 | startHeights[0], | ||
238 | startHeights[2], | ||
239 | startHeights[1], | ||
240 | startHeights[3], | ||
241 | pctX, pctY); | ||
242 | startHeight = Utils.Clamp(startHeight, 0f, 255f); | ||
243 | |||
244 | float heightRange = ImageUtils.Bilinear( | ||
245 | heightRanges[0], | ||
246 | heightRanges[2], | ||
247 | heightRanges[1], | ||
248 | heightRanges[3], | ||
249 | pctX, pctY); | ||
250 | heightRange = Utils.Clamp(heightRange, 0f, 255f); | ||
251 | |||
252 | // Generate two frequencies of perlin noise based on our global position | ||
253 | // The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting | ||
254 | Vector3 vec = new Vector3 | ||
255 | ( | ||
256 | ((float)regionPosition.X + (x * xFactor)) * 0.20319f, | ||
257 | ((float)regionPosition.Y + (y * yFactor)) * 0.20319f, | ||
258 | height * 0.25f | ||
259 | ); | ||
260 | |||
261 | float lowFreq = Perlin.noise2(vec.X * 0.222222f, vec.Y * 0.222222f) * 6.5f; | ||
262 | float highFreq = Perlin.turbulence2(vec.X, vec.Y, 2f) * 2.25f; | ||
263 | float noise = (lowFreq + highFreq) * 2f; | ||
264 | |||
265 | // Combine the current height, generated noise, start height, and height range parameters, then scale all of it | ||
266 | float layer = ((height + noise - startHeight) / heightRange) * 4f; | ||
267 | if (Single.IsNaN(layer)) layer = 0f; | ||
268 | layermap[x,y] = Utils.Clamp(layer, 0f, 3f); | ||
269 | >>>>>>> avn/ubitvar | ||
204 | } | 270 | } |
205 | } | 271 | } |
206 | } | 272 | } |
@@ -220,6 +286,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
220 | { | 286 | { |
221 | for (int x = 0; x < 256; x++) | 287 | for (int x = 0; x < 256; x++) |
222 | { | 288 | { |
289 | <<<<<<< HEAD | ||
223 | float height = (float)terrain[x * xFactor, y * yFactor]; | 290 | float height = (float)terrain[x * xFactor, y * yFactor]; |
224 | 291 | ||
225 | float pctX = (float)x / 255f; | 292 | float pctX = (float)x / 255f; |
@@ -261,6 +328,58 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
261 | if (Single.IsNaN(layer)) | 328 | if (Single.IsNaN(layer)) |
262 | layer = 0f; | 329 | layer = 0f; |
263 | layermap[x, y] = Utils.Clamp(layer, 0f, 3f); | 330 | layermap[x, y] = Utils.Clamp(layer, 0f, 3f); |
331 | ======= | ||
332 | // Get handles to all of the texture data arrays | ||
333 | BitmapData[] datas = new BitmapData[] | ||
334 | { | ||
335 | detailTexture[0].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[0].PixelFormat), | ||
336 | detailTexture[1].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[1].PixelFormat), | ||
337 | detailTexture[2].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[2].PixelFormat), | ||
338 | detailTexture[3].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat) | ||
339 | }; | ||
340 | |||
341 | int[] comps = new int[] | ||
342 | { | ||
343 | (datas[0].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3, | ||
344 | (datas[1].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3, | ||
345 | (datas[2].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3, | ||
346 | (datas[3].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3 | ||
347 | }; | ||
348 | |||
349 | for (int y = 0; y < 256; y++) | ||
350 | { | ||
351 | for (int x = 0; x < 256; x++) | ||
352 | { | ||
353 | float layer = layermap[x, y]; | ||
354 | |||
355 | // Select two textures | ||
356 | int l0 = (int)Math.Floor(layer); | ||
357 | int l1 = Math.Min(l0 + 1, 3); | ||
358 | |||
359 | byte* ptrA = (byte*)datas[l0].Scan0 + y * datas[l0].Stride + x * comps[l0]; | ||
360 | byte* ptrB = (byte*)datas[l1].Scan0 + y * datas[l1].Stride + x * comps[l1]; | ||
361 | byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3; | ||
362 | |||
363 | float aB = *(ptrA + 0); | ||
364 | float aG = *(ptrA + 1); | ||
365 | float aR = *(ptrA + 2); | ||
366 | |||
367 | float bB = *(ptrB + 0); | ||
368 | float bG = *(ptrB + 1); | ||
369 | float bR = *(ptrB + 2); | ||
370 | |||
371 | float layerDiff = layer - l0; | ||
372 | |||
373 | // Interpolate between the two selected textures | ||
374 | *(ptrO + 0) = (byte)Math.Floor(aB + layerDiff * (bB - aB)); | ||
375 | *(ptrO + 1) = (byte)Math.Floor(aG + layerDiff * (bG - aG)); | ||
376 | *(ptrO + 2) = (byte)Math.Floor(aR + layerDiff * (bR - aR)); | ||
377 | } | ||
378 | } | ||
379 | |||
380 | for (int i = 0; i < 4; i++) | ||
381 | detailTexture[i].UnlockBits(datas[i]); | ||
382 | >>>>>>> avn/ubitvar | ||
264 | } | 383 | } |
265 | } | 384 | } |
266 | 385 | ||
@@ -352,7 +471,10 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
352 | b.Dispose(); | 471 | b.Dispose(); |
353 | return result; | 472 | return result; |
354 | } | 473 | } |
474 | <<<<<<< HEAD | ||
355 | 475 | ||
476 | ======= | ||
477 | >>>>>>> avn/ubitvar | ||
356 | public static Bitmap SplatSimple(float[] heightmap) | 478 | public static Bitmap SplatSimple(float[] heightmap) |
357 | { | 479 | { |
358 | const float BASE_HSV_H = 93f / 360f; | 480 | const float BASE_HSV_H = 93f / 360f; |
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs index dd91951..d8420d9 100644 --- a/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs +++ b/OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs | |||
@@ -80,6 +80,9 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
80 | 80 | ||
81 | private bool m_Enabled = false; | 81 | private bool m_Enabled = false; |
82 | 82 | ||
83 | private Bitmap lastImage = null; | ||
84 | private DateTime lastImageTime = DateTime.MinValue; | ||
85 | |||
83 | #region Region Module interface | 86 | #region Region Module interface |
84 | 87 | ||
85 | public void Initialise(IConfigSource source) | 88 | public void Initialise(IConfigSource source) |
@@ -118,14 +121,9 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
118 | 121 | ||
119 | List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory()); | 122 | List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory()); |
120 | if (renderers.Count > 0) | 123 | if (renderers.Count > 0) |
121 | { | 124 | m_log.Info("[MAPTILE]: Loaded prim mesher " + renderers[0]); |
122 | m_primMesher = RenderingLoader.LoadRenderer(renderers[0]); | ||
123 | m_log.DebugFormat("[WARP 3D IMAGE MODULE]: Loaded prim mesher {0}", m_primMesher); | ||
124 | } | ||
125 | else | 125 | else |
126 | { | 126 | m_log.Info("[MAPTILE]: No prim mesher loaded, prim rendering will be disabled"); |
127 | m_log.Debug("[WARP 3D IMAGE MODULE]: No prim mesher loaded, prim rendering will be disabled"); | ||
128 | } | ||
129 | 127 | ||
130 | m_scene.RegisterModuleInterface<IMapImageGenerator>(this); | 128 | m_scene.RegisterModuleInterface<IMapImageGenerator>(this); |
131 | } | 129 | } |
@@ -158,18 +156,50 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
158 | 156 | ||
159 | public Bitmap CreateMapTile() | 157 | public Bitmap CreateMapTile() |
160 | { | 158 | { |
159 | <<<<<<< HEAD | ||
161 | // Vector3 camPos = new Vector3(127.5f, 127.5f, 221.7025033688163f); | 160 | // Vector3 camPos = new Vector3(127.5f, 127.5f, 221.7025033688163f); |
162 | // Camera above the middle of the region | 161 | // Camera above the middle of the region |
163 | Vector3 camPos = new Vector3( | 162 | Vector3 camPos = new Vector3( |
164 | m_scene.RegionInfo.RegionSizeX/2 - 0.5f, | 163 | m_scene.RegionInfo.RegionSizeX/2 - 0.5f, |
165 | m_scene.RegionInfo.RegionSizeY/2 - 0.5f, | 164 | m_scene.RegionInfo.RegionSizeY/2 - 0.5f, |
165 | ======= | ||
166 | /* this must be on all map, not just its image | ||
167 | if ((DateTime.Now - lastImageTime).TotalSeconds < 3600) | ||
168 | { | ||
169 | return (Bitmap)lastImage.Clone(); | ||
170 | } | ||
171 | */ | ||
172 | |||
173 | List<string> renderers = RenderingLoader.ListRenderers(Util.ExecutingDirectory()); | ||
174 | if (renderers.Count > 0) | ||
175 | { | ||
176 | m_primMesher = RenderingLoader.LoadRenderer(renderers[0]); | ||
177 | } | ||
178 | |||
179 | Vector3 camPos = new Vector3( | ||
180 | m_scene.RegionInfo.RegionSizeX / 2 - 0.5f, | ||
181 | m_scene.RegionInfo.RegionSizeY / 2 - 0.5f, | ||
182 | >>>>>>> avn/ubitvar | ||
166 | 221.7025033688163f); | 183 | 221.7025033688163f); |
167 | // Viewport viewing down onto the region | 184 | // Viewport viewing down onto the region |
168 | Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f, | 185 | Viewport viewport = new Viewport(camPos, -Vector3.UnitZ, 1024f, 0.1f, |
169 | (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY, | 186 | (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY, |
187 | <<<<<<< HEAD | ||
170 | (float)m_scene.RegionInfo.RegionSizeX, (float)m_scene.RegionInfo.RegionSizeY ); | 188 | (float)m_scene.RegionInfo.RegionSizeX, (float)m_scene.RegionInfo.RegionSizeY ); |
171 | // Fill the viewport and return the image | 189 | // Fill the viewport and return the image |
172 | return CreateMapTile(viewport, false); | 190 | return CreateMapTile(viewport, false); |
191 | ======= | ||
192 | (float)m_scene.RegionInfo.RegionSizeX, (float)m_scene.RegionInfo.RegionSizeY); | ||
193 | |||
194 | Bitmap tile = CreateMapTile(viewport, false); | ||
195 | m_primMesher = null; | ||
196 | return tile; | ||
197 | /* | ||
198 | lastImage = tile; | ||
199 | lastImageTime = DateTime.Now; | ||
200 | return (Bitmap)lastImage.Clone(); | ||
201 | */ | ||
202 | >>>>>>> avn/ubitvar | ||
173 | } | 203 | } |
174 | 204 | ||
175 | public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float fov, int width, int height, bool useTextures) | 205 | public Bitmap CreateViewImage(Vector3 camPos, Vector3 camDir, float fov, int width, int height, bool useTextures) |
@@ -285,9 +315,15 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
285 | float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; | 315 | float waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight; |
286 | 316 | ||
287 | renderer.AddPlane("Water", m_scene.RegionInfo.RegionSizeX * 0.5f); | 317 | renderer.AddPlane("Water", m_scene.RegionInfo.RegionSizeX * 0.5f); |
318 | <<<<<<< HEAD | ||
288 | renderer.Scene.sceneobject("Water").setPos(m_scene.RegionInfo.RegionSizeX/2 - 0.5f, | 319 | renderer.Scene.sceneobject("Water").setPos(m_scene.RegionInfo.RegionSizeX/2 - 0.5f, |
289 | waterHeight, | 320 | waterHeight, |
290 | m_scene.RegionInfo.RegionSizeY/2 - 0.5f ); | 321 | m_scene.RegionInfo.RegionSizeY/2 - 0.5f ); |
322 | ======= | ||
323 | renderer.Scene.sceneobject("Water").setPos(m_scene.RegionInfo.RegionSizeX / 2 - 0.5f, | ||
324 | waterHeight, | ||
325 | m_scene.RegionInfo.RegionSizeY / 2 - 0.5f); | ||
326 | >>>>>>> avn/ubitvar | ||
291 | 327 | ||
292 | warp_Material waterColorMaterial = new warp_Material(ConvertColor(WATER_COLOR)); | 328 | warp_Material waterColorMaterial = new warp_Material(ConvertColor(WATER_COLOR)); |
293 | waterColorMaterial.setReflectivity(0); // match water color with standard map module thanks lkalif | 329 | waterColorMaterial.setReflectivity(0); // match water color with standard map module thanks lkalif |
@@ -316,7 +352,11 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
316 | warp_Vector pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]); | 352 | warp_Vector pos = ConvertVector(x, y, (float)terrain[(int)x, (int)y]); |
317 | obj.addVertex(new warp_Vertex(pos, | 353 | obj.addVertex(new warp_Vertex(pos, |
318 | x / (float)m_scene.RegionInfo.RegionSizeX, | 354 | x / (float)m_scene.RegionInfo.RegionSizeX, |
355 | <<<<<<< HEAD | ||
319 | (((float)m_scene.RegionInfo.RegionSizeY) - y) / m_scene.RegionInfo.RegionSizeY) ); | 356 | (((float)m_scene.RegionInfo.RegionSizeY) - y) / m_scene.RegionInfo.RegionSizeY) ); |
357 | ======= | ||
358 | (((float)m_scene.RegionInfo.RegionSizeY) - y) / m_scene.RegionInfo.RegionSizeY)); | ||
359 | >>>>>>> avn/ubitvar | ||
320 | } | 360 | } |
321 | } | 361 | } |
322 | 362 | ||
@@ -384,7 +424,12 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
384 | warp_Texture texture; | 424 | warp_Texture texture; |
385 | using ( | 425 | using ( |
386 | Bitmap image | 426 | Bitmap image |
427 | <<<<<<< HEAD | ||
387 | = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges, | 428 | = TerrainSplat.Splat(terrain, textureIDs, startHeights, heightRanges, |
429 | ======= | ||
430 | = TerrainSplat.Splat( | ||
431 | terrain, textureIDs, startHeights, heightRanges, | ||
432 | >>>>>>> avn/ubitvar | ||
388 | new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain)) | 433 | new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain)) |
389 | { | 434 | { |
390 | texture = new warp_Texture(image); | 435 | texture = new warp_Texture(image); |
@@ -660,6 +705,11 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
660 | #endregion Rendering Methods | 705 | #endregion Rendering Methods |
661 | 706 | ||
662 | #region Static Helpers | 707 | #region Static Helpers |
708 | // Note: axis change. | ||
709 | private static warp_Vector ConvertVector(float x, float y, float z) | ||
710 | { | ||
711 | return new warp_Vector(x, z, y); | ||
712 | } | ||
663 | 713 | ||
664 | // Note: axis change. | 714 | // Note: axis change. |
665 | private static warp_Vector ConvertVector(float x, float y, float z) | 715 | private static warp_Vector ConvertVector(float x, float y, float z) |