panda3d 和 GeoMipTerrain - 在地形上加载纹理

panda3d and GeoMipTerrain - loading textures on a terrain

我目前正在尝试从高度图 png 文件创建 GeoMipTerrain,然后对其应用纹理,这是我的代码:

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()

一切正常,但我在地形上看不到纹理,只有纯白色。 我可以将 setColorMap 行更改为:

terrain.setColorMap("grass.png")

它会工作得很好,但是,纹理非常模糊并且没有正确调整大小。我希望能够在地形上操纵纹理,因此如果有人可以帮助我弄清楚为什么未渲染纹理,我会首选第一种方法。

谢谢!

好吧,我终于明白了,纹理设置在地形上的工作方式不同:

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()

此外,我建议以后在 https://discourse.panda3d.org/ 上寻找答案,因为那里的社区更加活跃