我目前正试图从heightmap 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/由于那里的社区更加活跃,