mirror of
https://github.com/opensim/opensim.git
synced 2026-08-06 01:06:30 +08:00
Merge branch 'master' into careminster
Conflicts: OpenSim/Region/CoreModules/World/Warp3DMap/Warp3DImageModule.cs OpenSim/Region/Framework/Scenes/Scene.cs OpenSim/Region/Framework/Scenes/SimStatsReporter.cs
This commit is contained in:
@@ -57,14 +57,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Profile
|
||||
|
||||
public void Initialise(IConfigSource config)
|
||||
{
|
||||
// This can be reduced later as the loader will determine
|
||||
// whether we are needed
|
||||
if (config.Configs["Profile"] != null)
|
||||
{
|
||||
if (config.Configs["Profile"].GetString("Module", string.Empty) != "BasicProfileModule")
|
||||
return;
|
||||
}
|
||||
|
||||
m_log.DebugFormat("[PROFILE MODULE]: Basic Profile Module enabled");
|
||||
m_Enabled = true;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
|
||||
"set terrain heights <corner> <min> <max> [<x>] [<y>]",
|
||||
"Sets the terrain texture heights on corner #<corner> to <min>/<max>, if <x> or <y> are specified, it will only " +
|
||||
"set it on regions with a matching coordinate. Specify -1 in <x> or <y> to wildcard" +
|
||||
" that coordinate. Corner # SW = 0, NW = 1, SE = 2, NE = 3.",
|
||||
" that coordinate. Corner # SW = 0, NW = 1, SE = 2, NE = 3, all corners = -1.",
|
||||
consoleSetTerrainHeights);
|
||||
|
||||
m_module.Scene.AddCommand(
|
||||
@@ -143,6 +143,16 @@ namespace OpenSim.Region.CoreModules.World.Estate
|
||||
|
||||
switch (corner)
|
||||
{
|
||||
case -1:
|
||||
m_module.Scene.RegionInfo.RegionSettings.Elevation1SW = lowValue;
|
||||
m_module.Scene.RegionInfo.RegionSettings.Elevation2SW = highValue;
|
||||
m_module.Scene.RegionInfo.RegionSettings.Elevation1NW = lowValue;
|
||||
m_module.Scene.RegionInfo.RegionSettings.Elevation2NW = highValue;
|
||||
m_module.Scene.RegionInfo.RegionSettings.Elevation1SE = lowValue;
|
||||
m_module.Scene.RegionInfo.RegionSettings.Elevation2SE = highValue;
|
||||
m_module.Scene.RegionInfo.RegionSettings.Elevation1NE = lowValue;
|
||||
m_module.Scene.RegionInfo.RegionSettings.Elevation2NE = highValue;
|
||||
break;
|
||||
case 0:
|
||||
m_module.Scene.RegionInfo.RegionSettings.Elevation1SW = lowValue;
|
||||
m_module.Scene.RegionInfo.RegionSettings.Elevation2SW = highValue;
|
||||
|
||||
@@ -178,8 +178,6 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FileLoaders
|
||||
// int sztmp = bs.ReadInt16() + 1;
|
||||
// fileWidth = sztmp;
|
||||
// fileHeight = sztmp;
|
||||
bs.ReadInt16();
|
||||
bs.ReadInt16();
|
||||
bs.ReadInt16();
|
||||
bs.ReadInt16();
|
||||
break;
|
||||
|
||||
@@ -84,218 +84,234 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||
Debug.Assert(heightRanges.Length == 4);
|
||||
|
||||
Bitmap[] detailTexture = new Bitmap[4];
|
||||
Bitmap output = null;
|
||||
BitmapData outputData = null;
|
||||
|
||||
if (textureTerrain)
|
||||
try
|
||||
{
|
||||
// Swap empty terrain textureIDs with default IDs
|
||||
for (int i = 0; i < textureIDs.Length; i++)
|
||||
if (textureTerrain)
|
||||
{
|
||||
if (textureIDs[i] == UUID.Zero)
|
||||
textureIDs[i] = DEFAULT_TERRAIN_DETAIL[i];
|
||||
}
|
||||
|
||||
#region Texture Fetching
|
||||
|
||||
if (assetService != null)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
// Swap empty terrain textureIDs with default IDs
|
||||
for (int i = 0; i < textureIDs.Length; i++)
|
||||
{
|
||||
AssetBase asset;
|
||||
UUID cacheID = UUID.Combine(TERRAIN_CACHE_MAGIC, textureIDs[i]);
|
||||
|
||||
// Try to fetch a cached copy of the decoded/resized version of this texture
|
||||
asset = assetService.GetCached(cacheID.ToString());
|
||||
if (asset != null)
|
||||
if (textureIDs[i] == UUID.Zero)
|
||||
textureIDs[i] = DEFAULT_TERRAIN_DETAIL[i];
|
||||
}
|
||||
|
||||
#region Texture Fetching
|
||||
|
||||
if (assetService != null)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(asset.Data))
|
||||
detailTexture[i] = (Bitmap)Image.FromStream(stream);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
m_log.Warn("Failed to decode cached terrain texture " + cacheID +
|
||||
" (textureID: " + textureIDs[i] + "): " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
if (detailTexture[i] == null)
|
||||
{
|
||||
// Try to fetch the original JPEG2000 texture, resize if needed, and cache as PNG
|
||||
asset = assetService.Get(textureIDs[i].ToString());
|
||||
AssetBase asset;
|
||||
UUID cacheID = UUID.Combine(TERRAIN_CACHE_MAGIC, textureIDs[i]);
|
||||
|
||||
// Try to fetch a cached copy of the decoded/resized version of this texture
|
||||
asset = assetService.GetCached(cacheID.ToString());
|
||||
if (asset != null)
|
||||
{
|
||||
try { detailTexture[i] = (Bitmap)CSJ2K.J2kImage.FromBytes(asset.Data); }
|
||||
try
|
||||
{
|
||||
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(asset.Data))
|
||||
detailTexture[i] = (Bitmap)Image.FromStream(stream);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
m_log.Warn("Failed to decode terrain texture " + asset.ID + ": " + ex.Message);
|
||||
m_log.Warn("Failed to decode cached terrain texture " + cacheID +
|
||||
" (textureID: " + textureIDs[i] + "): " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
if (detailTexture[i] != null)
|
||||
|
||||
if (detailTexture[i] == null)
|
||||
{
|
||||
Bitmap bitmap = detailTexture[i];
|
||||
|
||||
// Make sure this texture is the correct size, otherwise resize
|
||||
if (bitmap.Width != 256 || bitmap.Height != 256)
|
||||
bitmap = ImageUtils.ResizeImage(bitmap, 256, 256);
|
||||
|
||||
// Save the decoded and resized texture to the cache
|
||||
byte[] data;
|
||||
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
|
||||
// Try to fetch the original JPEG2000 texture, resize if needed, and cache as PNG
|
||||
asset = assetService.Get(textureIDs[i].ToString());
|
||||
if (asset != null)
|
||||
{
|
||||
bitmap.Save(stream, ImageFormat.Png);
|
||||
data = stream.ToArray();
|
||||
try { detailTexture[i] = (Bitmap)CSJ2K.J2kImage.FromBytes(asset.Data); }
|
||||
catch (Exception ex)
|
||||
{
|
||||
m_log.Warn("Failed to decode terrain texture " + asset.ID + ": " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
// Cache a PNG copy of this terrain texture
|
||||
AssetBase newAsset = new AssetBase
|
||||
|
||||
if (detailTexture[i] != null)
|
||||
{
|
||||
Data = data,
|
||||
Description = "PNG",
|
||||
Flags = AssetFlags.Collectable,
|
||||
FullID = cacheID,
|
||||
ID = cacheID.ToString(),
|
||||
Local = true,
|
||||
Name = String.Empty,
|
||||
Temporary = true,
|
||||
Type = (sbyte)AssetType.Unknown
|
||||
};
|
||||
newAsset.Metadata.ContentType = "image/png";
|
||||
assetService.Store(newAsset);
|
||||
Bitmap bitmap = detailTexture[i];
|
||||
|
||||
// Make sure this texture is the correct size, otherwise resize
|
||||
if (bitmap.Width != 256 || bitmap.Height != 256)
|
||||
{
|
||||
using (Bitmap origBitmap = bitmap)
|
||||
{
|
||||
bitmap = ImageUtils.ResizeImage(origBitmap, 256, 256);
|
||||
}
|
||||
}
|
||||
|
||||
// Save the decoded and resized texture to the cache
|
||||
byte[] data;
|
||||
using (System.IO.MemoryStream stream = new System.IO.MemoryStream())
|
||||
{
|
||||
bitmap.Save(stream, ImageFormat.Png);
|
||||
data = stream.ToArray();
|
||||
}
|
||||
|
||||
// Cache a PNG copy of this terrain texture
|
||||
AssetBase newAsset = new AssetBase
|
||||
{
|
||||
Data = data,
|
||||
Description = "PNG",
|
||||
Flags = AssetFlags.Collectable,
|
||||
FullID = cacheID,
|
||||
ID = cacheID.ToString(),
|
||||
Local = true,
|
||||
Name = String.Empty,
|
||||
Temporary = true,
|
||||
Type = (sbyte)AssetType.Unknown
|
||||
};
|
||||
newAsset.Metadata.ContentType = "image/png";
|
||||
assetService.Store(newAsset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Texture Fetching
|
||||
}
|
||||
|
||||
#endregion Texture Fetching
|
||||
}
|
||||
|
||||
// Fill in any missing textures with a solid color
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (detailTexture[i] == null)
|
||||
|
||||
// Fill in any missing textures with a solid color
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
// Create a solid color texture for this layer
|
||||
detailTexture[i] = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
|
||||
using (Graphics gfx = Graphics.FromImage(detailTexture[i]))
|
||||
if (detailTexture[i] == null)
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i]))
|
||||
gfx.FillRectangle(brush, 0, 0, 256, 256);
|
||||
// Create a solid color texture for this layer
|
||||
detailTexture[i] = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
|
||||
using (Graphics gfx = Graphics.FromImage(detailTexture[i]))
|
||||
{
|
||||
using (SolidBrush brush = new SolidBrush(DEFAULT_TERRAIN_COLOR[i]))
|
||||
gfx.FillRectangle(brush, 0, 0, 256, 256);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Layer Map
|
||||
|
||||
float[] layermap = new float[256 * 256];
|
||||
|
||||
for (int y = 0; y < 256; y++)
|
||||
{
|
||||
for (int x = 0; x < 256; x++)
|
||||
{
|
||||
float height = heightmap[y * 256 + x];
|
||||
|
||||
float pctX = (float)x / 255f;
|
||||
float pctY = (float)y / 255f;
|
||||
|
||||
// Use bilinear interpolation between the four corners of start height and
|
||||
// height range to select the current values at this position
|
||||
float startHeight = ImageUtils.Bilinear(
|
||||
startHeights[0],
|
||||
startHeights[2],
|
||||
startHeights[1],
|
||||
startHeights[3],
|
||||
pctX, pctY);
|
||||
startHeight = Utils.Clamp(startHeight, 0f, 255f);
|
||||
|
||||
float heightRange = ImageUtils.Bilinear(
|
||||
heightRanges[0],
|
||||
heightRanges[2],
|
||||
heightRanges[1],
|
||||
heightRanges[3],
|
||||
pctX, pctY);
|
||||
heightRange = Utils.Clamp(heightRange, 0f, 255f);
|
||||
|
||||
// Generate two frequencies of perlin noise based on our global position
|
||||
// The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting
|
||||
Vector3 vec = new Vector3
|
||||
(
|
||||
((float)regionPosition.X + x) * 0.20319f,
|
||||
((float)regionPosition.Y + y) * 0.20319f,
|
||||
height * 0.25f
|
||||
);
|
||||
|
||||
float lowFreq = Perlin.noise2(vec.X * 0.222222f, vec.Y * 0.222222f) * 6.5f;
|
||||
float highFreq = Perlin.turbulence2(vec.X, vec.Y, 2f) * 2.25f;
|
||||
float noise = (lowFreq + highFreq) * 2f;
|
||||
|
||||
// Combine the current height, generated noise, start height, and height range parameters, then scale all of it
|
||||
float layer = ((height + noise - startHeight) / heightRange) * 4f;
|
||||
if (Single.IsNaN(layer)) layer = 0f;
|
||||
layermap[y * 256 + x] = Utils.Clamp(layer, 0f, 3f);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Layer Map
|
||||
|
||||
#region Texture Compositing
|
||||
|
||||
Bitmap output = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
|
||||
BitmapData outputData = output.LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
|
||||
|
||||
unsafe
|
||||
{
|
||||
// Get handles to all of the texture data arrays
|
||||
BitmapData[] datas = new BitmapData[]
|
||||
{
|
||||
detailTexture[0].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[0].PixelFormat),
|
||||
detailTexture[1].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[1].PixelFormat),
|
||||
detailTexture[2].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[2].PixelFormat),
|
||||
detailTexture[3].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat)
|
||||
};
|
||||
|
||||
int[] comps = new int[]
|
||||
{
|
||||
(datas[0].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
|
||||
(datas[1].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
|
||||
(datas[2].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
|
||||
(datas[3].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3
|
||||
};
|
||||
|
||||
|
||||
#region Layer Map
|
||||
|
||||
float[] layermap = new float[256 * 256];
|
||||
|
||||
for (int y = 0; y < 256; y++)
|
||||
{
|
||||
for (int x = 0; x < 256; x++)
|
||||
{
|
||||
float layer = layermap[y * 256 + x];
|
||||
|
||||
// Select two textures
|
||||
int l0 = (int)Math.Floor(layer);
|
||||
int l1 = Math.Min(l0 + 1, 3);
|
||||
|
||||
byte* ptrA = (byte*)datas[l0].Scan0 + y * datas[l0].Stride + x * comps[l0];
|
||||
byte* ptrB = (byte*)datas[l1].Scan0 + y * datas[l1].Stride + x * comps[l1];
|
||||
byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3;
|
||||
|
||||
float aB = *(ptrA + 0);
|
||||
float aG = *(ptrA + 1);
|
||||
float aR = *(ptrA + 2);
|
||||
|
||||
float bB = *(ptrB + 0);
|
||||
float bG = *(ptrB + 1);
|
||||
float bR = *(ptrB + 2);
|
||||
|
||||
float layerDiff = layer - l0;
|
||||
|
||||
// Interpolate between the two selected textures
|
||||
*(ptrO + 0) = (byte)Math.Floor(aB + layerDiff * (bB - aB));
|
||||
*(ptrO + 1) = (byte)Math.Floor(aG + layerDiff * (bG - aG));
|
||||
*(ptrO + 2) = (byte)Math.Floor(aR + layerDiff * (bR - aR));
|
||||
float height = heightmap[y * 256 + x];
|
||||
|
||||
float pctX = (float)x / 255f;
|
||||
float pctY = (float)y / 255f;
|
||||
|
||||
// Use bilinear interpolation between the four corners of start height and
|
||||
// height range to select the current values at this position
|
||||
float startHeight = ImageUtils.Bilinear(
|
||||
startHeights[0],
|
||||
startHeights[2],
|
||||
startHeights[1],
|
||||
startHeights[3],
|
||||
pctX, pctY);
|
||||
startHeight = Utils.Clamp(startHeight, 0f, 255f);
|
||||
|
||||
float heightRange = ImageUtils.Bilinear(
|
||||
heightRanges[0],
|
||||
heightRanges[2],
|
||||
heightRanges[1],
|
||||
heightRanges[3],
|
||||
pctX, pctY);
|
||||
heightRange = Utils.Clamp(heightRange, 0f, 255f);
|
||||
|
||||
// Generate two frequencies of perlin noise based on our global position
|
||||
// The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting
|
||||
Vector3 vec = new Vector3
|
||||
(
|
||||
((float)regionPosition.X + x) * 0.20319f,
|
||||
((float)regionPosition.Y + y) * 0.20319f,
|
||||
height * 0.25f
|
||||
);
|
||||
|
||||
float lowFreq = Perlin.noise2(vec.X * 0.222222f, vec.Y * 0.222222f) * 6.5f;
|
||||
float highFreq = Perlin.turbulence2(vec.X, vec.Y, 2f) * 2.25f;
|
||||
float noise = (lowFreq + highFreq) * 2f;
|
||||
|
||||
// Combine the current height, generated noise, start height, and height range parameters, then scale all of it
|
||||
float layer = ((height + noise - startHeight) / heightRange) * 4f;
|
||||
if (Single.IsNaN(layer)) layer = 0f;
|
||||
layermap[y * 256 + x] = Utils.Clamp(layer, 0f, 3f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion Layer Map
|
||||
|
||||
#region Texture Compositing
|
||||
|
||||
output = new Bitmap(256, 256, PixelFormat.Format24bppRgb);
|
||||
outputData = output.LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
|
||||
|
||||
unsafe
|
||||
{
|
||||
// Get handles to all of the texture data arrays
|
||||
BitmapData[] datas = new BitmapData[]
|
||||
{
|
||||
detailTexture[0].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[0].PixelFormat),
|
||||
detailTexture[1].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[1].PixelFormat),
|
||||
detailTexture[2].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[2].PixelFormat),
|
||||
detailTexture[3].LockBits(new Rectangle(0, 0, 256, 256), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat)
|
||||
};
|
||||
|
||||
int[] comps = new int[]
|
||||
{
|
||||
(datas[0].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
|
||||
(datas[1].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
|
||||
(datas[2].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3,
|
||||
(datas[3].PixelFormat == PixelFormat.Format32bppArgb) ? 4 : 3
|
||||
};
|
||||
|
||||
for (int y = 0; y < 256; y++)
|
||||
{
|
||||
for (int x = 0; x < 256; x++)
|
||||
{
|
||||
float layer = layermap[y * 256 + x];
|
||||
|
||||
// Select two textures
|
||||
int l0 = (int)Math.Floor(layer);
|
||||
int l1 = Math.Min(l0 + 1, 3);
|
||||
|
||||
byte* ptrA = (byte*)datas[l0].Scan0 + y * datas[l0].Stride + x * comps[l0];
|
||||
byte* ptrB = (byte*)datas[l1].Scan0 + y * datas[l1].Stride + x * comps[l1];
|
||||
byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3;
|
||||
|
||||
float aB = *(ptrA + 0);
|
||||
float aG = *(ptrA + 1);
|
||||
float aR = *(ptrA + 2);
|
||||
|
||||
float bB = *(ptrB + 0);
|
||||
float bG = *(ptrB + 1);
|
||||
float bR = *(ptrB + 2);
|
||||
|
||||
float layerDiff = layer - l0;
|
||||
|
||||
// Interpolate between the two selected textures
|
||||
*(ptrO + 0) = (byte)Math.Floor(aB + layerDiff * (bB - aB));
|
||||
*(ptrO + 1) = (byte)Math.Floor(aG + layerDiff * (bG - aG));
|
||||
*(ptrO + 2) = (byte)Math.Floor(aR + layerDiff * (bR - aR));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
detailTexture[i].UnlockBits(datas[i]);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
detailTexture[i].UnlockBits(datas[i]);
|
||||
if (detailTexture[i] != null)
|
||||
detailTexture[i].Dispose();
|
||||
}
|
||||
|
||||
output.UnlockBits(outputData);
|
||||
|
||||
@@ -54,8 +54,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||
private static readonly UUID TEXTURE_METADATA_MAGIC = new UUID("802dc0e0-f080-4931-8b57-d1be8611c4f3");
|
||||
private static readonly Color4 WATER_COLOR = new Color4(29, 72, 96, 216);
|
||||
|
||||
private static readonly ILog m_log =
|
||||
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private Scene m_scene;
|
||||
private IRendering m_primMesher;
|
||||
@@ -164,7 +163,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||
}
|
||||
catch
|
||||
{
|
||||
m_log.Warn("[MAPTILE]: Failed to load StartupConfig");
|
||||
m_log.Warn("[WARP 3D IMAGE MODULE]: Failed to load StartupConfig");
|
||||
}
|
||||
|
||||
m_colors.Clear();
|
||||
@@ -218,7 +217,10 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||
Bitmap bitmap = renderer.Scene.getImage();
|
||||
|
||||
if (m_useAntiAliasing)
|
||||
bitmap = ImageUtils.ResizeImage(bitmap, viewport.Width, viewport.Height);
|
||||
{
|
||||
using (Bitmap origBitmap = bitmap)
|
||||
bitmap = ImageUtils.ResizeImage(origBitmap, viewport.Width, viewport.Height);
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
@@ -233,7 +235,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||
catch (Exception e)
|
||||
{
|
||||
// JPEG2000 encoder failed
|
||||
m_log.Error("[MAPTILE]: Failed generating terrain map: " + e);
|
||||
m_log.Error("[WARP 3D IMAGE MODULE]: Failed generating terrain map: ", e);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -332,8 +334,17 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||
uint globalX, globalY;
|
||||
Utils.LongToUInts(m_scene.RegionInfo.RegionHandle, out globalX, out globalY);
|
||||
|
||||
Bitmap image = TerrainSplat.Splat(heightmap, textureIDs, startHeights, heightRanges, new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain);
|
||||
warp_Texture texture = new warp_Texture(image);
|
||||
warp_Texture texture;
|
||||
|
||||
using (
|
||||
Bitmap image
|
||||
= TerrainSplat.Splat(
|
||||
heightmap, textureIDs, startHeights, heightRanges,
|
||||
new Vector3d(globalX, globalY, 0.0), m_scene.AssetService, textureTerrain))
|
||||
{
|
||||
texture = new warp_Texture(image);
|
||||
}
|
||||
|
||||
warp_Material material = new warp_Material(texture);
|
||||
material.setReflectivity(50);
|
||||
renderer.Scene.addMaterial("TerrainColor", material);
|
||||
@@ -560,42 +571,46 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||
{
|
||||
try
|
||||
{
|
||||
Bitmap bitmap = (Bitmap)J2kImage.FromStream(stream);
|
||||
width = bitmap.Width;
|
||||
height = bitmap.Height;
|
||||
int pixelBytes;
|
||||
|
||||
BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
||||
int pixelBytes = (bitmap.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
|
||||
|
||||
// Sum up the individual channels
|
||||
unsafe
|
||||
using (Bitmap bitmap = (Bitmap)J2kImage.FromStream(stream))
|
||||
{
|
||||
if (pixelBytes == 4)
|
||||
width = bitmap.Width;
|
||||
height = bitmap.Height;
|
||||
|
||||
BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, bitmap.PixelFormat);
|
||||
pixelBytes = (bitmap.PixelFormat == PixelFormat.Format24bppRgb) ? 3 : 4;
|
||||
|
||||
// Sum up the individual channels
|
||||
unsafe
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
if (pixelBytes == 4)
|
||||
{
|
||||
byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride);
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
b += row[x * pixelBytes + 0];
|
||||
g += row[x * pixelBytes + 1];
|
||||
r += row[x * pixelBytes + 2];
|
||||
a += row[x * pixelBytes + 3];
|
||||
byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride);
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
b += row[x * pixelBytes + 0];
|
||||
g += row[x * pixelBytes + 1];
|
||||
r += row[x * pixelBytes + 2];
|
||||
a += row[x * pixelBytes + 3];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
else
|
||||
{
|
||||
byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride);
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
b += row[x * pixelBytes + 0];
|
||||
g += row[x * pixelBytes + 1];
|
||||
r += row[x * pixelBytes + 2];
|
||||
byte* row = (byte*)bitmapData.Scan0 + (y * bitmapData.Stride);
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
b += row[x * pixelBytes + 0];
|
||||
g += row[x * pixelBytes + 1];
|
||||
r += row[x * pixelBytes + 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -617,7 +632,10 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
m_log.WarnFormat("[MAPTILE]: Error decoding JPEG2000 texture {0} ({1} bytes): {2}", textureID, j2kData.Length, ex.Message);
|
||||
m_log.WarnFormat(
|
||||
"[WARP 3D IMAGE MODULE]: Error decoding JPEG2000 texture {0} ({1} bytes): {2}",
|
||||
textureID, j2kData.Length, ex.Message);
|
||||
|
||||
width = 0;
|
||||
height = 0;
|
||||
return new Color4(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
@@ -1343,14 +1343,14 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
|
||||
if (terrain == null)
|
||||
return;
|
||||
|
||||
m_log.DebugFormat("[WORLDMAP]: Generating map image for {0}", m_scene.RegionInfo.RegionName);
|
||||
|
||||
byte[] data = terrain.WriteJpeg2000Image();
|
||||
if (data == null)
|
||||
return;
|
||||
|
||||
byte[] overlay = GenerateOverlay();
|
||||
|
||||
m_log.Debug("[WORLDMAP]: STORING MAPTILE IMAGE");
|
||||
|
||||
UUID terrainImageID = UUID.Random();
|
||||
UUID parcelImageID = UUID.Zero;
|
||||
|
||||
@@ -1365,7 +1365,8 @@ namespace OpenSim.Region.CoreModules.World.WorldMap
|
||||
asset.Flags = AssetFlags.Maptile;
|
||||
|
||||
// Store the new one
|
||||
m_log.DebugFormat("[WORLDMAP]: Storing map tile {0}", asset.ID);
|
||||
m_log.DebugFormat("[WORLDMAP]: Storing map tile {0} for {1}", asset.ID, m_scene.RegionInfo.RegionName);
|
||||
|
||||
m_scene.AssetService.Store(asset);
|
||||
|
||||
if (overlay != null)
|
||||
|
||||
Reference in New Issue
Block a user