Fix hight-map readings

This commit is contained in:
Lukas Rieger (Blue) 2022-08-15 10:02:10 +02:00
parent bb4928c72f
commit a9d9cb991b
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
2 changed files with 11 additions and 3 deletions

View File

@ -405,8 +405,16 @@ export class Map {
const texture = tile.model.material.uniforms?.textureImage?.value?.image;
if (texture == null) continue;
const color = getPixel(texture, x - tileX * scaledTileSize.x, z - tileZ * scaledTileSize.z + this.data.lowres.tileSize.z);
return color[2];
const color = getPixel(texture, x - tileX * scaledTileSize.x, z - tileZ * scaledTileSize.z + this.data.lowres.tileSize.z + 1);
let heightUnsigned = color[1] * 256.0 + color[2];
if (heightUnsigned >= 32768.0) {
return -(65535.0 - heightUnsigned);
} else {
return heightUnsigned;
}
}
return false;

View File

@ -387,6 +387,6 @@ pixel.height = 1;
const pixelContext = pixel.getContext('2d');
export const getPixel = (img, x, y) => {
pixelContext.drawImage(img, x, y, 1, 1, 0, 0, 1, 1);
pixelContext.drawImage(img, Math.floor(x), Math.floor(y), 1, 1, 0, 0, 1, 1);
return pixelContext.getImageData(0, 0, 1, 1).data;
}