0

I'm currently trying to create a GeoMipTerrain from heightmap png file and then apply texture to it, here's my code:

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

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        # Set up the GeoMipTerrain
        terrain = GeoMipTerrain("myDynamicTerrain")
        terrain.setHeightfield("heightmap.png")
        terrainTexture = self.loader.loadTexture("grass.png")
        terrainTexture.setWrapU(Texture.WM_repeat)
        terrainTexture.setWrapV(Texture.WM_repeat)

        # Set terrain properties
        terrain.setBlockSize(128)
        terrain.setNear(20)
        terrain.setFar(100)
        terrain.setFocalPoint(self.camera)

        # Store the root NodePath for convenience
        root = terrain.getRoot()
        root.reparentTo(self.render)
        root.setSz(100)

        # Generate it.
        terrain.setColorMap(terrainTexture)
        terrain.generate()

app = MyApp()
app.run()

Everything works without error, but I see no texture on a terrain, only pure white color. I can change the setColorMap line to this:

terrain.setColorMap("grass.png")

And it will work just fine, however, the textured is very blurry and not correctly resized. I would like to be able to manipulate the texture on a terrain so the first method would be prefered if somebody could help me figure out why the texture isn't rendered.

Thanks!

Zeerooth
  • 23
  • 1
  • 4

1 Answers1

1

Okay, so I finally figured it out, texture setting works differently on terrains:

from direct.showbase.ShowBase import ShowBase
from panda3d.core import GeoMipTerrain, Texture, TextureStage

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        # Set up the GeoMipTerrain
        terrain = GeoMipTerrain("myDynamicTerrain")
        terrain.setHeightfield("heightmap.png")
        terrainTexture = self.loader.loadTexture("grass.png")

        # Set terrain properties
        terrain.setBlockSize(32)
        terrain.setNear(20)
        terrain.setFar(100)
        terrain.setFocalPoint(self.camera)

        # Store the root NodePath for convenience
        root = terrain.getRoot()
        root.setTexture(TextureStage.getDefault(), terrainTexture)
        root.setTexScale(TextureStage.getDefault(), 100)
        root.reparentTo(self.render)
        root.setSz(1000)

        # Generate it.
        terrain.generate()

app = MyApp()
app.run()

Also, in the future I recommended to look for answers on https://discourse.panda3d.org/ as the community is much more active there

Zeerooth
  • 23
  • 1
  • 4