Adds globalscripts/BicubicInterpolation.js, the corresponding license_mit.txt and points to it for other files with the same license in LICENSE.txt - reviewed by Philip and Itms. Uses that to fix an interpolation issue in gaia.js and also fixes a "fail by one" there - reviewed by elexis. Fixes #4174
This was SVN commit r18710.
This commit is contained in:
parent
a673a330a5
commit
64b1da0ddf
13
LICENSE.txt
13
LICENSE.txt
@ -37,7 +37,7 @@ in particular, let us know and we can try to clarify it.
|
|||||||
BSD
|
BSD
|
||||||
|
|
||||||
/build/premake/*.lua
|
/build/premake/*.lua
|
||||||
MIT
|
MIT - see license_mit.txt
|
||||||
|
|
||||||
/docs
|
/docs
|
||||||
Various (unspecified)
|
Various (unspecified)
|
||||||
@ -49,7 +49,7 @@ in particular, let us know and we can try to clarify it.
|
|||||||
GPL version 2 (or later) - see license_gpl-2.0.txt
|
GPL version 2 (or later) - see license_gpl-2.0.txt
|
||||||
|
|
||||||
/source/lib
|
/source/lib
|
||||||
MIT
|
MIT - see license_mit.txt
|
||||||
|
|
||||||
/source/scriptinterface/third_party
|
/source/scriptinterface/third_party
|
||||||
MPL 2.0
|
MPL 2.0
|
||||||
@ -60,16 +60,16 @@ in particular, let us know and we can try to clarify it.
|
|||||||
/source/third_party/encryption
|
/source/third_party/encryption
|
||||||
GPL version 2 (or later)
|
GPL version 2 (or later)
|
||||||
ISC (pkcs5_pbkdf2.cpp)
|
ISC (pkcs5_pbkdf2.cpp)
|
||||||
MIT (pkcs5_pbkdf2.h)
|
MIT (pkcs5_pbkdf2.h) - see license_mit.txt
|
||||||
|
|
||||||
/source/third-party/jsonspirit
|
/source/third-party/jsonspirit
|
||||||
MIT
|
MIT - see license_mit.txt
|
||||||
|
|
||||||
/source/third_party/mikktspace
|
/source/third_party/mikktspace
|
||||||
zlib
|
zlib
|
||||||
|
|
||||||
/source/third_party/mongoose
|
/source/third_party/mongoose
|
||||||
MIT
|
MIT - see license_mit.txt
|
||||||
|
|
||||||
/source/third_party/tinygettext
|
/source/third_party/tinygettext
|
||||||
zlib
|
zlib
|
||||||
@ -79,3 +79,6 @@ in particular, let us know and we can try to clarify it.
|
|||||||
|
|
||||||
/source/tools/atlas
|
/source/tools/atlas
|
||||||
GPL version 2 (or later) - see license_gpl-2.0.txt
|
GPL version 2 (or later) - see license_gpl-2.0.txt
|
||||||
|
|
||||||
|
/binaries/data/mods/public/globalscripts/BicubicInterpolation.js
|
||||||
|
MIT 2013 Hugh Kennedy - see license_mit.txt
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* From https://github.com/hughsk/bicubic licensed under MIT 2013 Hugh Kennedy - see /license_mit.txt
|
||||||
|
* Two dimensional interpolation within a square grid using polynomials of 3rd degree.
|
||||||
|
* @param {float} xf - X coordinate within the subgrid (see below) of the point to interpolate the value for
|
||||||
|
* @param {float} yf - y coordinate within the subgrid (see below) of the point to interpolate the value for
|
||||||
|
* @param {float} p00 - Value of the property to calculate at the origin of the naighbor grid
|
||||||
|
* @param {float} pxy - Value at naighbor grid coordinates x/y, x/y in {0, 1, 2, 3}
|
||||||
|
* @return {float} - Value at the given float coordinates in the small grid interpolated from it's values
|
||||||
|
*/
|
||||||
|
function bicubicInterpolation(
|
||||||
|
xf, yf,
|
||||||
|
p00, p01, p02, p03,
|
||||||
|
p10, p11, p12, p13,
|
||||||
|
p20, p21, p22, p23,
|
||||||
|
p30, p31, p32, p33
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var yf2 = yf * yf;
|
||||||
|
var xf2 = xf * xf;
|
||||||
|
var xf3 = xf * xf2;
|
||||||
|
|
||||||
|
var x00 = p03 - p02 - p00 + p01;
|
||||||
|
var x01 = p00 - p01 - x00;
|
||||||
|
var x02 = p02 - p00;
|
||||||
|
var x0 = x00*xf3 + x01*xf2 + x02*xf + p01;
|
||||||
|
|
||||||
|
var x10 = p13 - p12 - p10 + p11;
|
||||||
|
var x11 = p10 - p11 - x10;
|
||||||
|
var x12 = p12 - p10;
|
||||||
|
var x1 = x10*xf3 + x11*xf2 + x12*xf + p11;
|
||||||
|
|
||||||
|
var x20 = p23 - p22 - p20 + p21;
|
||||||
|
var x21 = p20 - p21 - x20;
|
||||||
|
var x22 = p22 - p20;
|
||||||
|
var x2 = x20*xf3 + x21*xf2 + x22*xf + p21;
|
||||||
|
|
||||||
|
var x30 = p33 - p32 - p30 + p31;
|
||||||
|
var x31 = p30 - p31 - x30;
|
||||||
|
var x32 = p32 - p30;
|
||||||
|
var x3 = x30*xf3 + x31*xf2 + x32*xf + p31;
|
||||||
|
|
||||||
|
var y0 = x3 - x2 - x0 + x1;
|
||||||
|
var y1 = x0 - x1 - y0;
|
||||||
|
var y2 = x2 - x0;
|
||||||
|
|
||||||
|
return y0*yf*yf2 + y1*yf2 + y2*yf + x1;
|
||||||
|
}
|
@ -1274,43 +1274,51 @@ function getRandomDeviation(base, deviation)
|
|||||||
* @param heightmap - An array with a square number of heights
|
* @param heightmap - An array with a square number of heights
|
||||||
* @param tilemap - The IDs of the palletmap to be painted for each heightmap tile
|
* @param tilemap - The IDs of the palletmap to be painted for each heightmap tile
|
||||||
* @param pallet - The tile texture names used by the tilemap.
|
* @param pallet - The tile texture names used by the tilemap.
|
||||||
* @returns the ratio of heightmap tiles per map size tiles
|
* @return the ratio of heightmap tiles per map size tiles
|
||||||
*/
|
*/
|
||||||
function paintHeightmap(heightmap, tilemap, pallet, func = undefined)
|
function paintHeightmap(heightmap, tilemap, pallet, func = undefined)
|
||||||
{
|
{
|
||||||
let lastI = -1;
|
let mapSize = getMapSize(); // Width of the map in terrain tiles
|
||||||
let mapSize = getMapSize();
|
|
||||||
let hmSize = Math.sqrt(heightmap.length);
|
let hmSize = Math.sqrt(heightmap.length);
|
||||||
let scale = hmSize / mapSize;
|
let scale = hmSize / (mapSize + 1); // There are mapSize + 1 vertices (each 1 tile is surrounded by 2x2 vertices)
|
||||||
|
|
||||||
for (let y = 0; y < mapSize; ++y)
|
for (let x = 0; x <= mapSize; ++x)
|
||||||
for (let x = 0; x < mapSize; ++x)
|
for (let y = 0; y <= mapSize; ++y)
|
||||||
{
|
{
|
||||||
let i = Math.floor(x * scale) * hmSize + Math.floor(y * scale);
|
let hmPoint = { "x": x * scale, "y": y * scale };
|
||||||
|
let hmTile = { "x": Math.floor(hmPoint.x), "y": Math.floor(hmPoint.y) };
|
||||||
|
let shift = { "x": 0, "y": 0 };
|
||||||
|
|
||||||
let height = heightmap[i];
|
if (hmTile.x == 0)
|
||||||
|
shift.x = 1;
|
||||||
|
else if (hmTile.x == hmSize - 1)
|
||||||
|
shift.x = - 2;
|
||||||
|
else if (hmTile.x == hmSize - 2)
|
||||||
|
shift.x = - 1;
|
||||||
|
|
||||||
|
if (hmTile.y == 0)
|
||||||
|
shift.y = 1;
|
||||||
|
else if (hmTile.y == hmSize - 1)
|
||||||
|
shift.y = - 2;
|
||||||
|
else if (hmTile.y == hmSize - 2)
|
||||||
|
shift.y = - 1;
|
||||||
|
|
||||||
|
let neighbors = [];
|
||||||
|
for (let localYi = 0; localYi < 4; ++localYi)
|
||||||
|
for (let localXi = 0; localXi < 4; ++localXi)
|
||||||
|
neighbors.push(heightmap[(hmTile.x + localXi + shift.x - 1) * hmSize + (hmTile.y + localYi + shift.y - 1)]);
|
||||||
|
|
||||||
|
setHeight(x, y, bicubicInterpolation(hmPoint.x - hmTile.x - shift.x, hmPoint.y - hmTile.y - shift.y, ...neighbors) / scale);
|
||||||
|
|
||||||
|
if (x < mapSize && y < mapSize)
|
||||||
|
{
|
||||||
|
let i = hmTile.x * hmSize + hmTile.y;
|
||||||
let tile = pallet[tilemap[i]];
|
let tile = pallet[tilemap[i]];
|
||||||
|
|
||||||
if (i == lastI)
|
|
||||||
{
|
|
||||||
let nearby = [i];
|
|
||||||
|
|
||||||
if (i + hmSize < heightmap.length)
|
|
||||||
{
|
|
||||||
nearby.push(i + hmSize);
|
|
||||||
height = (heightmap[nearby[0]] + heightmap[nearby[1]]) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
tile = pallet[tilemap[nearby[randInt(0, nearby.length - 1)]]];
|
|
||||||
}
|
|
||||||
|
|
||||||
setHeight(x, y, height / scale);
|
|
||||||
placeTerrain(x, y, tile);
|
placeTerrain(x, y, tile);
|
||||||
|
|
||||||
if (func)
|
if (func)
|
||||||
func(tile, x, y);
|
func(tile, x, y);
|
||||||
|
}
|
||||||
lastI = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return scale;
|
return scale;
|
||||||
|
19
license_mit.txt
Normal file
19
license_mit.txt
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
Loading…
Reference in New Issue
Block a user