Converting heightmaps to 16bit

In case you want to try a 8bit heightmap with the shader terrain mesh (which only supports 16bit), here’s a small script to convert the heightmap to 16bit, just drag the file onto it or use "python script.py ":

import sys
from panda3d.core import PNMImage

if __name__ == "__main__":
    fname = sys.argv[1]
    img = PNMImage(fname)

    size = min(img.get_x_size(), img.get_y_size())
    dest = PNMImage(size, size, 1, 2**16 - 1)

    for x in range(size):
        for y in range(size):
            dest.set_gray(x, y, img.get_gray(x, y))

    new_name = fname.split(".")[0] + "-16bit.png"
    dest.write(new_name)

This should be faster:

img = PNMImage(fname)
img.set_maxval(0xffff)
img.write(fname)

Ah, well, good to know! Thats certainly faster