Problem with loading heightmap

Hello! Im trying to load heightmap image I’ve made in L3DT2.9, but im getting strange error:

:grutil(error): Failed to load heightfield image h.png!
:grutil(error): No valid heightfield image has been set!

h.png(heightmap) and t.jpg(texture) files are in the same folder as .py file.

code:

from direct.showbase.ShowBase import ShowBase   
from panda3d.core import GeoMipTerrain

       
 
class MyApp(ShowBase):                          
    def __init__(self):
        ShowBase.__init__(self)                        
        terrain = GeoMipTerrain("worldTerrain")
        terrain.setHeightfield("h.png")    
        terrain.setColorMap("t.jpg")           
        terrain.setBruteforce(True)                    
        root = terrain.getRoot()                       
        root.reparentTo(render)                        
        root.setSz(60)                                 
        terrain.generate()                             
 
app = MyApp()                                   
app.run()                      

files : LINK

Im using Panda 1.7, python 2.6, Win7x64

Could someone tell me what’s going on?

Thank You for your help.

Hi

Your code looks like the example in the manual. I wonder if the h.png is corrupted or is actually a .png file. I use L3DT 2.9 too with no problems, but code with C++.
Can you display t.png in a image viewer and does it look like a black and white version of what you made in L3DT ?

Thanks for replay.
h.png file looks fine. Tried to load heightmap using absolute path, but still nothing…

See what happens if you use this in your code.

image = PNMImage()
image.write(Filename("test.png"))
terrain.setHeightfield("test.png")               

Note that you can just do this:

image = PNMImage(513, 513)
terrain.setHeightfield(image)

That’s true, I do that for my terrain engine. I was just trying to recreate everything his code was already doing except for the specific .png file.

Still the same problem:

Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)
:grutil(error): Failed to load heightfield image test.png!
:grutil(error): No valid heightfield image has been set!

any ideas?

Oops, my mistake. Sorry it may not work with default parameters in PNMImage. :unamused: Try running this:

from direct.showbase.ShowBase import ShowBase
from panda3d.core import GeoMipTerrain
from panda3d.core import *

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        terrain = GeoMipTerrain("worldTerrain")
        image = PNMImage(513,513)
        image.write(Filename("test.png"))
        terrain.setHeightfield("test.png")
        terrain.setColorMap("t.jpg")    
        terrain.setBruteforce(True)
        root = terrain.getRoot()
        root.reparentTo(render)
        root.setSz(60)
        terrain.generate()

app = MyApp()
app.run()

Keep getting the same error ;/ But when I use rdb’s code:

image = PNMImage(513, 513) 
terrain.setHeightfield(image)

It runs without problem, and panda displays grey window.

Well it’s just a flat image, but looks like for some reason you can’t read files or the paths to find the file aren’t right. It didn’t work when you tried to write the simple image and then read it back in …

Huh… I agree with tah. I can’t possibly explain why you’re having this issue though. I also have win7x64 and I’ve never seen this issue before. Perhaps it might help to reinstall Panda3d or upgrade to 1.7.1.

It seems like pnm images can write to files still, maybe it can also read files. If that’s the case the problem can easily be worked around. See if the following works for you.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import GeoMipTerrain
from panda3d.core import *

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        terrain = GeoMipTerrain("worldTerrain")
        image = PNMImage(513,513)
        image.write(Filename("test.png"))
        image.read("test.png")
        terrain.setHeightfield(image)
        terrain.setColorMap("t.jpg")    
        terrain.setBruteforce(True)
        root = terrain.getRoot()
        root.reparentTo(render)
        root.setSz(60)
        terrain.generate()

app = MyApp()
app.run()

Thank you guys for helping me! :slight_smile: I’ve upgraded to 1.7.1, and tried to reinstall Panda serval times, and still nothing.

now console says:

:grutil(error): Specified image does not have a power-of-two-plus-one size!
:grutil(error): No valid heightfield image has been set

I’ve installed Debian, and everything works like a charm. There is still a problem with loading heightmap on Windows, but now i can continue with learning Panda.

If someone have idea how to make Panda load heightmap on Win, please let me know.

Thanks for help.

The heightfield size needs to be be a power of two plus one, so 513x513 or 129x1025 or so.

Also i remmber having a problem where L3DT gave me a gray scale png files. Panda3d cant read grayscale png files so i had to convert it to color and then it all worked.

First I’ve heard of this. I’ve never had any trouble reading grayscale png files in Panda. It just uses libpng, which supports all png file types, including grayscale.

David

Yeah, I’ve had no problem with L3DT’s grayscale images in particular either.

I when and checked schaik.com/pngsuite/#basic and drwr, you right it does load all the images i tried. Maybe what i was seen was that it would load a 16bit grayscale truncating that that to 8bit not making the things work?

16-bit grayscale is also fully supported. :wink:

David

Noticed that this thread was a little old but this worked for me.
use this for 1.7.2 (I’m sure panda3d.core will work for 1.7.1, still in the learning/experiment process):
from pandac.PandaModules import GeoMipterrain

and instead of using this:
terrain = GeoMipTerrain(“worldTerrain”)

you should try using the whole filepath:
/c/(file_location)/worldTerrain.png

That should load your heightmap for you

The name of a GeoMipTerrain has nothing to do with the path to the heightmap, so that won’t make any difference.