diff options
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs b/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs index df5ac92..91ca7e2 100644 --- a/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs +++ b/OpenSim/Region/CoreModules/World/Warp3DMap/TerrainSplat.cs | |||
@@ -32,6 +32,7 @@ using System.Drawing.Imaging; | |||
32 | using log4net; | 32 | using log4net; |
33 | using OpenMetaverse; | 33 | using OpenMetaverse; |
34 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
35 | using OpenSim.Region.Framework.Interfaces; | ||
35 | using OpenSim.Services.Interfaces; | 36 | using OpenSim.Services.Interfaces; |
36 | 37 | ||
37 | namespace OpenSim.Region.CoreModules.World.Warp3DMap | 38 | namespace OpenSim.Region.CoreModules.World.Warp3DMap |
@@ -66,6 +67,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
66 | #endregion Constants | 67 | #endregion Constants |
67 | 68 | ||
68 | private static readonly ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name); | 69 | private static readonly ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name); |
70 | private static string LogHeader = "[WARP3D TERRAIN SPLAT]"; | ||
69 | 71 | ||
70 | /// <summary> | 72 | /// <summary> |
71 | /// Builds a composited terrain texture given the region texture | 73 | /// Builds a composited terrain texture given the region texture |
@@ -76,9 +78,8 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
76 | /// <returns>A composited 256x256 RGB texture ready for rendering</returns> | 78 | /// <returns>A composited 256x256 RGB texture ready for rendering</returns> |
77 | /// <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 |
78 | /// </remarks> | 80 | /// </remarks> |
79 | public static Bitmap Splat(float[] heightmap, UUID[] textureIDs, float[] startHeights, float[] heightRanges, Vector3d regionPosition, IAssetService assetService, bool textureTerrain) | 81 | public static Bitmap Splat(ITerrainChannel terrain, UUID[] textureIDs, float[] startHeights, float[] heightRanges, Vector3d regionPosition, IAssetService assetService, bool textureTerrain) |
80 | { | 82 | { |
81 | Debug.Assert(heightmap.Length == 256 * 256); | ||
82 | Debug.Assert(textureIDs.Length == 4); | 83 | Debug.Assert(textureIDs.Length == 4); |
83 | Debug.Assert(startHeights.Length == 4); | 84 | Debug.Assert(startHeights.Length == 4); |
84 | Debug.Assert(heightRanges.Length == 4); | 85 | Debug.Assert(heightRanges.Length == 4); |
@@ -200,17 +201,27 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
200 | gfx.FillRectangle(brush, 0, 0, 256, 256); | 201 | gfx.FillRectangle(brush, 0, 0, 256, 256); |
201 | } | 202 | } |
202 | } | 203 | } |
204 | else | ||
205 | { | ||
206 | if (detailTexture[i].Width != 256 || detailTexture[i].Height != 256) | ||
207 | { | ||
208 | detailTexture[i] = ResizeBitmap(detailTexture[i], 256, 256); | ||
209 | } | ||
210 | } | ||
203 | } | 211 | } |
204 | 212 | ||
205 | #region Layer Map | 213 | #region Layer Map |
206 | 214 | ||
207 | float[] layermap = new float[256 * 256]; | 215 | float[,] layermap = new float[256 , 256]; |
216 | |||
217 | int xFactor = terrain.Width / 256; | ||
218 | int yFactor = terrain.Height / 256; | ||
208 | 219 | ||
209 | for (int y = 0; y < 256; y++) | 220 | for (int y = 0; y < 256; y++) |
210 | { | 221 | { |
211 | for (int x = 0; x < 256; x++) | 222 | for (int x = 0; x < 256; x++) |
212 | { | 223 | { |
213 | float height = heightmap[y * 256 + x]; | 224 | float height = (float)terrain[x * xFactor, y * yFactor]; |
214 | 225 | ||
215 | float pctX = (float)x / 255f; | 226 | float pctX = (float)x / 255f; |
216 | float pctY = (float)y / 255f; | 227 | float pctY = (float)y / 255f; |
@@ -237,8 +248,8 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
237 | // The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting | 248 | // The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting |
238 | Vector3 vec = new Vector3 | 249 | Vector3 vec = new Vector3 |
239 | ( | 250 | ( |
240 | ((float)regionPosition.X + x) * 0.20319f, | 251 | ((float)regionPosition.X + (x * xFactor)) * 0.20319f, |
241 | ((float)regionPosition.Y + y) * 0.20319f, | 252 | ((float)regionPosition.Y + (y * yFactor)) * 0.20319f, |
242 | height * 0.25f | 253 | height * 0.25f |
243 | ); | 254 | ); |
244 | 255 | ||
@@ -249,7 +260,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
249 | // Combine the current height, generated noise, start height, and height range parameters, then scale all of it | 260 | // Combine the current height, generated noise, start height, and height range parameters, then scale all of it |
250 | float layer = ((height + noise - startHeight) / heightRange) * 4f; | 261 | float layer = ((height + noise - startHeight) / heightRange) * 4f; |
251 | if (Single.IsNaN(layer)) layer = 0f; | 262 | if (Single.IsNaN(layer)) layer = 0f; |
252 | layermap[y * 256 + x] = Utils.Clamp(layer, 0f, 3f); | 263 | layermap[x,y] = Utils.Clamp(layer, 0f, 3f); |
253 | } | 264 | } |
254 | } | 265 | } |
255 | 266 | ||
@@ -283,7 +294,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
283 | { | 294 | { |
284 | for (int x = 0; x < 256; x++) | 295 | for (int x = 0; x < 256; x++) |
285 | { | 296 | { |
286 | float layer = layermap[y * 256 + x]; | 297 | float layer = layermap[x, y]; |
287 | 298 | ||
288 | // Select two textures | 299 | // Select two textures |
289 | int l0 = (int)Math.Floor(layer); | 300 | int l0 = (int)Math.Floor(layer); |
@@ -331,6 +342,16 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap | |||
331 | return output; | 342 | return output; |
332 | } | 343 | } |
333 | 344 | ||
345 | public static Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight) | ||
346 | { | ||
347 | m_log.DebugFormat("{0} ResizeBitmap. From <{1},{2}> to <{3},{4}>", | ||
348 | LogHeader, b.Width, b.Height, nWidth, nHeight); | ||
349 | Bitmap result = new Bitmap(nWidth, nHeight); | ||
350 | using (Graphics g = Graphics.FromImage(result)) | ||
351 | g.DrawImage(b, 0, 0, nWidth, nHeight); | ||
352 | b.Dispose(); | ||
353 | return result; | ||
354 | } | ||
334 | public static Bitmap SplatSimple(float[] heightmap) | 355 | public static Bitmap SplatSimple(float[] heightmap) |
335 | { | 356 | { |
336 | const float BASE_HSV_H = 93f / 360f; | 357 | const float BASE_HSV_H = 93f / 360f; |