missing updated files
parent
f6765b8668
commit
007adce081
|
@ -103,41 +103,39 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||||
|
|
||||||
public static float noise2(float x, float y)
|
public static float noise2(float x, float y)
|
||||||
{
|
{
|
||||||
int bx0, bx1, by0, by1, b00, b10, b01, b11;
|
int bx, by, b00, b10, b01, b11;
|
||||||
float rx0, rx1, ry0, ry1, sx, sy, a, b, t, u, v;
|
float rx0, rx1, ry0, ry1, sx, sy, a, b, t, u, v;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
t = x + N;
|
t = x + N;
|
||||||
bx0 = ((int)t) & BM;
|
|
||||||
bx1 = (bx0 + 1) & BM;
|
|
||||||
rx0 = t - (int)t;
|
rx0 = t - (int)t;
|
||||||
rx1 = rx0 - 1f;
|
bx = ((int)t) & BM;
|
||||||
|
i = p[bx];
|
||||||
|
bx = (bx + 1) & BM;
|
||||||
|
j = p[bx];
|
||||||
|
|
||||||
t = y + N;
|
t = y + N;
|
||||||
by0 = ((int)t) & BM;
|
|
||||||
by1 = (by0 + 1) & BM;
|
|
||||||
ry0 = t - (int)t;
|
ry0 = t - (int)t;
|
||||||
ry1 = ry0 - 1f;
|
by = ((int)t) & BM;
|
||||||
|
b00 = p[i + by];
|
||||||
|
b10 = p[j + by];
|
||||||
|
|
||||||
i = p[bx0];
|
by = (by + 1) & BM;
|
||||||
j = p[bx1];
|
b01 = p[i + by];
|
||||||
|
b11 = p[j + by];
|
||||||
b00 = p[i + by0];
|
|
||||||
b10 = p[j + by0];
|
|
||||||
b01 = p[i + by1];
|
|
||||||
b11 = p[j + by1];
|
|
||||||
|
|
||||||
sx = s_curve(rx0);
|
sx = s_curve(rx0);
|
||||||
sy = s_curve(ry0);
|
|
||||||
|
|
||||||
u = rx0 * g2[b00, 0] + ry0 * g2[b00, 1];
|
u = rx0 * g2[b00, 0] + ry0 * g2[b00, 1];
|
||||||
|
rx1 = rx0 - 1f;
|
||||||
v = rx1 * g2[b10, 0] + ry0 * g2[b10, 1];
|
v = rx1 * g2[b10, 0] + ry0 * g2[b10, 1];
|
||||||
a = Utils.Lerp(u, v, sx);
|
a = Utils.Lerp(u, v, sx);
|
||||||
|
|
||||||
|
ry1 = ry0 - 1f;
|
||||||
u = rx0 * g2[b01, 0] + ry1 * g2[b01, 1];
|
u = rx0 * g2[b01, 0] + ry1 * g2[b01, 1];
|
||||||
v = rx1 * g2[b11, 0] + ry1 * g2[b11, 1];
|
v = rx1 * g2[b11, 0] + ry1 * g2[b11, 1];
|
||||||
b = Utils.Lerp(u, v, sx);
|
b = Utils.Lerp(u, v, sx);
|
||||||
|
|
||||||
|
sy = s_curve(ry0);
|
||||||
return Utils.Lerp(a, b, sy);
|
return Utils.Lerp(a, b, sy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,12 +200,10 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||||
public static float turbulence1(float x, float freq)
|
public static float turbulence1(float x, float freq)
|
||||||
{
|
{
|
||||||
float t;
|
float t;
|
||||||
float v;
|
|
||||||
|
|
||||||
for (t = 0f; freq >= 1f; freq *= 0.5f)
|
for (t = 0f; freq >= 1f; freq *= 0.5f)
|
||||||
{
|
{
|
||||||
v = freq * x;
|
t += noise1(freq * x) / freq;
|
||||||
t += noise1(v) / freq;
|
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
@ -215,28 +211,20 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||||
public static float turbulence2(float x, float y, float freq)
|
public static float turbulence2(float x, float y, float freq)
|
||||||
{
|
{
|
||||||
float t;
|
float t;
|
||||||
Vector2 vec;
|
|
||||||
|
|
||||||
for (t = 0f; freq >= 1f; freq *= 0.5f)
|
for (t = 0f; freq >= 1f; freq *= 0.5f)
|
||||||
{
|
t += noise2(freq * x, freq * y) / freq;
|
||||||
vec.X = freq * x;
|
|
||||||
vec.Y = freq * y;
|
|
||||||
t += noise2(vec.X, vec.Y) / freq;
|
|
||||||
}
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float turbulence3(float x, float y, float z, float freq)
|
public static float turbulence3(float x, float y, float z, float freq)
|
||||||
{
|
{
|
||||||
float t;
|
float t;
|
||||||
Vector3 vec;
|
|
||||||
|
|
||||||
for (t = 0f; freq >= 1f; freq *= 0.5f)
|
for (t = 0f; freq >= 1f; freq *= 0.5f)
|
||||||
{
|
{
|
||||||
vec.X = freq * x;
|
t += noise3(freq * x, freq * y, freq * z) / freq;
|
||||||
vec.Y = freq * y;
|
|
||||||
vec.Z = freq * z;
|
|
||||||
t += noise3(vec.X, vec.Y, vec.Z) / freq;
|
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
@ -244,23 +232,28 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||||
private static void normalize2(float[,] v, int i)
|
private static void normalize2(float[,] v, int i)
|
||||||
{
|
{
|
||||||
float s;
|
float s;
|
||||||
|
float a = v[i, 0];
|
||||||
|
float b = v[i, 1];
|
||||||
|
|
||||||
s = (float)Math.Sqrt(v[i, 0] * v[i, 0] + v[i, 1] * v[i, 1]);
|
s = (float)Math.Sqrt(a * a + b * b);
|
||||||
s = 1.0f / s;
|
s = 1.0f / s;
|
||||||
v[i, 0] = v[i, 0] * s;
|
v[i, 0] = a * s;
|
||||||
v[i, 1] = v[i, 1] * s;
|
v[i, 1] = b * s;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void normalize3(float[,] v, int i)
|
private static void normalize3(float[,] v, int i)
|
||||||
{
|
{
|
||||||
float s;
|
float s;
|
||||||
|
float a = v[i, 0];
|
||||||
|
float b = v[i, 1];
|
||||||
|
float c = v[i, 2];
|
||||||
|
|
||||||
s = (float)Math.Sqrt(v[i, 0] * v[i, 0] + v[i, 1] * v[i, 1] + v[i, 2] * v[i, 2]);
|
s = (float)Math.Sqrt(a * a + b * b + c * c);
|
||||||
s = 1.0f / s;
|
s = 1.0f / s;
|
||||||
|
|
||||||
v[i, 0] = v[i, 0] * s;
|
v[i, 0] = a * s;
|
||||||
v[i, 1] = v[i, 1] * s;
|
v[i, 1] = b * s;
|
||||||
v[i, 2] = v[i, 2] * s;
|
v[i, 2] = c * s;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static float s_curve(float t)
|
private static float s_curve(float t)
|
||||||
|
|
|
@ -84,7 +84,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||||
float[] startHeights, float[] heightRanges,
|
float[] startHeights, float[] heightRanges,
|
||||||
uint regionPositionX, uint regionPositionY,
|
uint regionPositionX, uint regionPositionY,
|
||||||
IAssetService assetService, IJ2KDecoder decoder,
|
IAssetService assetService, IJ2KDecoder decoder,
|
||||||
bool textureTerrain, bool averagetextureTerrain, bool FlipedY,
|
bool textureTerrain, bool averagetextureTerrain,
|
||||||
int twidth, int theight)
|
int twidth, int theight)
|
||||||
{
|
{
|
||||||
Debug.Assert(textureIDs.Length == 4);
|
Debug.Assert(textureIDs.Length == 4);
|
||||||
|
@ -303,20 +303,21 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||||
float layerDiff;
|
float layerDiff;
|
||||||
int l0;
|
int l0;
|
||||||
int l1;
|
int l1;
|
||||||
|
uint yglobalpos;
|
||||||
|
|
||||||
if(usecolors)
|
if(usecolors)
|
||||||
{
|
{
|
||||||
float a;
|
float a;
|
||||||
float b;
|
float b;
|
||||||
if(FlipedY)
|
|
||||||
{
|
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
|
byte* ptrO;
|
||||||
for(int y = 0; y < theight; ++y)
|
for(int y = 0; y < theight; ++y)
|
||||||
{
|
{
|
||||||
ty = (int)(y * yFactor);
|
|
||||||
pcty = y * invtheightMinus1;
|
pcty = y * invtheightMinus1;
|
||||||
byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride;
|
ptrO = (byte*)outputData.Scan0 + y * outputData.Stride;
|
||||||
|
ty = (int)(y * yFactor);
|
||||||
|
yglobalpos = (uint)ty + regionPositionY;
|
||||||
|
|
||||||
for(int x = 0; x < twidth; ++x)
|
for(int x = 0; x < twidth; ++x)
|
||||||
{
|
{
|
||||||
|
@ -324,7 +325,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||||
pctx = x * invtwitdthMinus1;
|
pctx = x * invtwitdthMinus1;
|
||||||
height = (float)terrain[tx, ty];
|
height = (float)terrain[tx, ty];
|
||||||
layer = getLayerTex(height, pctx, pcty,
|
layer = getLayerTex(height, pctx, pcty,
|
||||||
(uint)tx + regionPositionX, (uint)ty + regionPositionY,
|
(uint)tx + regionPositionX, yglobalpos,
|
||||||
startHeights, heightRanges);
|
startHeights, heightRanges);
|
||||||
|
|
||||||
// Select two textures
|
// Select two textures
|
||||||
|
@ -349,46 +350,6 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
for(int y = 0; y < theight; ++y)
|
|
||||||
{
|
|
||||||
ty = (int)((theight - y -1) * yFactor);
|
|
||||||
pcty = 1.0f - y * invtheightMinus1;
|
|
||||||
byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride;
|
|
||||||
|
|
||||||
for(int x = 0; x < twidth; ++x)
|
|
||||||
{
|
|
||||||
tx = (int)(x * xFactor);
|
|
||||||
pctx = x * invtwitdthMinus1;
|
|
||||||
height = (float)terrain[tx, ty];
|
|
||||||
layer = getLayerTex(height, pctx , pcty,
|
|
||||||
(uint)tx + regionPositionX, (uint)ty + regionPositionY,
|
|
||||||
startHeights, heightRanges);
|
|
||||||
|
|
||||||
// Select two textures
|
|
||||||
l0 = (int)layer;
|
|
||||||
l1 = Math.Min(l0 + 1, 3);
|
|
||||||
|
|
||||||
layerDiff = layer - l0;
|
|
||||||
a = mapColorsRed[l0];
|
|
||||||
b = mapColorsRed[l1];
|
|
||||||
*(ptrO++) = (byte)(a + layerDiff * (b - a));
|
|
||||||
|
|
||||||
a = mapColorsGreen[l0];
|
|
||||||
b = mapColorsGreen[l1];
|
|
||||||
*(ptrO++) = (byte)(a + layerDiff * (b - a));
|
|
||||||
|
|
||||||
a = mapColorsBlue[l0];
|
|
||||||
b = mapColorsBlue[l1];
|
|
||||||
*(ptrO++) = (byte)(a + layerDiff * (b - a));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
float aB;
|
float aB;
|
||||||
float aG;
|
float aG;
|
||||||
|
@ -396,6 +357,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||||
float bB;
|
float bB;
|
||||||
float bG;
|
float bG;
|
||||||
float bR;
|
float bR;
|
||||||
|
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
// Get handles to all of the texture data arrays
|
// Get handles to all of the texture data arrays
|
||||||
|
@ -407,55 +369,15 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||||
detailTexture[3].LockBits(new Rectangle(0, 0, 16, 16), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat)
|
detailTexture[3].LockBits(new Rectangle(0, 0, 16, 16), ImageLockMode.ReadOnly, detailTexture[3].PixelFormat)
|
||||||
};
|
};
|
||||||
|
|
||||||
if(FlipedY)
|
byte* ptr;
|
||||||
{
|
byte* ptrO;
|
||||||
for(int y = 0; y < theight; y++)
|
for(int y = 0; y < theight; y++)
|
||||||
{
|
{
|
||||||
ty = (int)(y * yFactor);
|
|
||||||
pcty = y * invtheightMinus1;
|
pcty = y * invtheightMinus1;
|
||||||
int ypatch = ((int)(y * yFactor) & 0x0f) * datas[0].Stride;
|
int ypatch = ((int)(y * yFactor) & 0x0f) * datas[0].Stride;
|
||||||
for(int x = 0; x < twidth; x++)
|
ptrO = (byte*)outputData.Scan0 + y * outputData.Stride;
|
||||||
{
|
ty = (int)(y * yFactor);
|
||||||
tx = (int)(x * xFactor);
|
yglobalpos = (uint)ty + regionPositionY;
|
||||||
pctx = x * invtwitdthMinus1;
|
|
||||||
height = (float)terrain[tx, ty];
|
|
||||||
layer = getLayerTex(height, pctx, pcty,
|
|
||||||
(uint)tx + regionPositionX, (uint)ty + regionPositionY,
|
|
||||||
startHeights, heightRanges);
|
|
||||||
|
|
||||||
// Select two textures
|
|
||||||
l0 = (int)layer;
|
|
||||||
l1 = Math.Min(l0 + 1, 3);
|
|
||||||
|
|
||||||
int patchOffset = (tx & 0x0f) * 3 + ypatch;
|
|
||||||
byte* ptrA = (byte*)datas[l0].Scan0 + patchOffset;
|
|
||||||
byte* ptrB = (byte*)datas[l1].Scan0 + patchOffset;
|
|
||||||
byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3;
|
|
||||||
|
|
||||||
aB = *(ptrA + 0);
|
|
||||||
aG = *(ptrA + 1);
|
|
||||||
aR = *(ptrA + 2);
|
|
||||||
|
|
||||||
bB = *(ptrB + 0);
|
|
||||||
bG = *(ptrB + 1);
|
|
||||||
bR = *(ptrB + 2);
|
|
||||||
|
|
||||||
layerDiff = layer - l0;
|
|
||||||
|
|
||||||
// Interpolate between the two selected textures
|
|
||||||
*(ptrO + 0) = (byte)(aB + layerDiff * (bB - aB));
|
|
||||||
*(ptrO + 1) = (byte)(aG + layerDiff * (bG - aG));
|
|
||||||
*(ptrO + 2) = (byte)(aR + layerDiff * (bR - aR));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for(int y = 0; y < theight; y++)
|
|
||||||
{
|
|
||||||
ty = (int)((theight - y - 1) * yFactor);
|
|
||||||
pcty = 1.0f - y * invtheightMinus1;
|
|
||||||
int ypatch = ((int)(y * yFactor) & 0x0f) * datas[0].Stride;
|
|
||||||
|
|
||||||
for(int x = 0; x < twidth; x++)
|
for(int x = 0; x < twidth; x++)
|
||||||
{
|
{
|
||||||
|
@ -463,33 +385,31 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||||
pctx = x * invtwitdthMinus1;
|
pctx = x * invtwitdthMinus1;
|
||||||
height = (float)terrain[tx, ty];
|
height = (float)terrain[tx, ty];
|
||||||
layer = getLayerTex(height, pctx, pcty,
|
layer = getLayerTex(height, pctx, pcty,
|
||||||
(uint)tx + regionPositionX, (uint)ty + regionPositionY,
|
(uint)tx + regionPositionX, yglobalpos,
|
||||||
startHeights, heightRanges);
|
startHeights, heightRanges);
|
||||||
|
|
||||||
// Select two textures
|
// Select two textures
|
||||||
l0 = (int)layer;
|
l0 = (int)layer;
|
||||||
l1 = Math.Min(l0 + 1, 3);
|
|
||||||
|
|
||||||
int patchOffset = (tx & 0x0f) * 3 + ypatch;
|
|
||||||
byte* ptrA = (byte*)datas[l0].Scan0 + patchOffset;
|
|
||||||
byte* ptrB = (byte*)datas[l1].Scan0 + patchOffset;
|
|
||||||
byte* ptrO = (byte*)outputData.Scan0 + y * outputData.Stride + x * 3;
|
|
||||||
|
|
||||||
aB = *(ptrA + 0);
|
|
||||||
aG = *(ptrA + 1);
|
|
||||||
aR = *(ptrA + 2);
|
|
||||||
|
|
||||||
bB = *(ptrB + 0);
|
|
||||||
bG = *(ptrB + 1);
|
|
||||||
bR = *(ptrB + 2);
|
|
||||||
|
|
||||||
layerDiff = layer - l0;
|
layerDiff = layer - l0;
|
||||||
|
|
||||||
|
int patchOffset = (tx & 0x0f) * 3 + ypatch;
|
||||||
|
|
||||||
|
ptr = (byte*)datas[l0].Scan0 + patchOffset;
|
||||||
|
aB = *(ptr++);
|
||||||
|
aG = *(ptr++);
|
||||||
|
aR = *(ptr);
|
||||||
|
|
||||||
|
l1 = Math.Min(l0 + 1, 3);
|
||||||
|
ptr = (byte*)datas[l1].Scan0 + patchOffset;
|
||||||
|
bB = *(ptr++);
|
||||||
|
bG = *(ptr++);
|
||||||
|
bR = *(ptr);
|
||||||
|
|
||||||
|
|
||||||
// Interpolate between the two selected textures
|
// Interpolate between the two selected textures
|
||||||
*(ptrO + 0) = (byte)(aB + layerDiff * (bB - aB));
|
*(ptrO++) = (byte)(aB + layerDiff * (bB - aB));
|
||||||
*(ptrO + 1) = (byte)(aG + layerDiff * (bG - aG));
|
*(ptrO++) = (byte)(aG + layerDiff * (bG - aG));
|
||||||
*(ptrO + 2) = (byte)(aR + layerDiff * (bR - aR));
|
*(ptrO++) = (byte)(aR + layerDiff * (bR - aR));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,7 +432,7 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||||
}
|
}
|
||||||
|
|
||||||
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
|
||||||
private static float getLayerTex(float height, float pctX, float pctY, uint sourceX, uint sourceY,
|
private static float getLayerTex(float height, float pctX, float pctY, uint X, uint Y,
|
||||||
float[] startHeights, float[] heightRanges)
|
float[] startHeights, float[] heightRanges)
|
||||||
{
|
{
|
||||||
// Use bilinear interpolation between the four corners of start height and
|
// Use bilinear interpolation between the four corners of start height and
|
||||||
|
@ -533,15 +453,11 @@ namespace OpenSim.Region.CoreModules.World.Warp3DMap
|
||||||
|
|
||||||
// Generate two frequencies of perlin noise based on our global position
|
// Generate two frequencies of perlin noise based on our global position
|
||||||
// The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting
|
// The magic values were taken from http://opensimulator.org/wiki/Terrain_Splatting
|
||||||
Vector3 vec = new Vector3
|
float sX = X * 0.20319f;
|
||||||
(
|
float sY = Y * 0.20319f;
|
||||||
sourceX * 0.20319f,
|
|
||||||
sourceY * 0.20319f,
|
|
||||||
height * 0.25f
|
|
||||||
);
|
|
||||||
|
|
||||||
float noise = Perlin.noise2(vec.X * 0.222222f, vec.Y * 0.222222f) * 13.0f;
|
float noise = Perlin.noise2(sX * 0.222222f, sY * 0.222222f) * 13.0f;
|
||||||
noise += Perlin.turbulence2(vec.X, vec.Y, 2f) * 4.5f;
|
noise += Perlin.turbulence2(sX, sY, 2f) * 4.5f;
|
||||||
|
|
||||||
// Combine the current height, generated noise, start height, and height range parameters, then scale all of it
|
// Combine the current height, generated noise, start height, and height range parameters, then scale all of it
|
||||||
float layer = ((height + noise - startHeight) / heightRange) * 4f;
|
float layer = ((height + noise - startHeight) / heightRange) * 4f;
|
||||||
|
|
|
@ -172,7 +172,7 @@ namespace OpenSim.Region.DataSnapshot
|
||||||
if (m_snapStore == null)
|
if (m_snapStore == null)
|
||||||
{
|
{
|
||||||
m_hostname = scene.RegionInfo.ExternalHostName;
|
m_hostname = scene.RegionInfo.ExternalHostName;
|
||||||
m_snapStore = new SnapshotStore(m_snapsDir, m_gridinfo, m_listener_port, m_hostname);
|
m_snapStore = new SnapshotStore(m_snapsDir, m_gridinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_snapStore.AddScene(scene);
|
m_snapStore.AddScene(scene);
|
||||||
|
|
Loading…
Reference in New Issue