panda3d和geomipterain在地形上加载纹理

2024-10-03 09:07:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从heightmap png文件创建Geomipterain,然后对其应用纹理,下面是我的代码:

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

它将工作得很好,但是,纹理是非常模糊,没有正确调整大小。我想能够在地形上操纵纹理,所以如果有人能帮我弄清楚为什么不渲染纹理,我会首选第一种方法。你知道吗

谢谢!你知道吗


Tags: fromimportselfpnginitrootmyapp纹理
1条回答
网友
1楼 · 发布于 2024-10-03 09:07:43

好吧,我终于明白了,纹理设置在地形上的效果不同:

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/上寻找答案,因为那里的社区更加活跃

相关问题 更多 >