ShaderTerrainMesh terrain engine draw road

Hello, i want to create ShaderTerrainMesh terrain with grass, wood and road.

I found how I can do this with GeoMipTerrain in panda documentation, but i don’t found for ShaderTerrainMesh.
I took the example again, but it doesn’t work.

i have this error:
AttributeError: ‘panda3d.core.ShaderTerrainMesh’ object has no attribute ‘getRoot’

at line 32

import direct.directbase.DirectStart
from pandac.PandaModules import Vec4
from pandac.PandaModules import TextureStage
from pandac.PandaModules import GeoMipTerrain
from pandac.PandaModules import AmbientLight
from panda3d.core import ShaderTerrainMesh, Shader, load_prc_file_data


render.setShaderAuto()


# add ambient light
ambient = Vec4(0.34, 0.3, 0.3, 1)
alight = AmbientLight('alight')
alight.setColor(ambient)
alnp = render.attachNewNode(alight)
render.setLight(alnp)


"""# Set up the GeoMipTerrain
terrain = GeoMipTerrain("genTerrain")
terrain.setHeightfield("./textures/generatedheight.png")"""

 
# Set up the ShaderTerrainMesh
terrain = ShaderTerrainMesh()
myTexture = loader.loadTexture("./textures/generatedheight.png")
terrain.setHeightfield(myTexture)
terrain.target_triangle_width = 10.0
 
# Store the root NodePath for convenience
root = terrain.getRoot()
root.reparentTo(render)
root.setSz(50)

# Generate it.
terrain.generate()





# Step 1: alpha maps - first two
ts = TextureStage("stage-basicalpha")
ts.setSort(00)
ts.setMode(TextureStage.MReplace)
root.setTexture(ts, loader.loadTexture("./textures/alpha2.jpg", "./textures/alpha4.jpg"))
ts.setSavedResult(True)

# Step 2: first texture - rocks go on everything
ts = TextureStage("stage-first")
ts.setSort(10)
ts.setMode(TextureStage.MReplace)
root.setTexture(ts, loader.loadTexture("./textures/rock.jpg"))
root.setTexScale(ts, 64, 64)


# Step 3: second texture grass go on alpha2
ts = TextureStage("stage-second")
ts.setSort(20)
ts.setCombineRgb(TextureStage.CMInterpolate, TextureStage.CSTexture, TextureStage.COSrcColor,
                                             TextureStage.CSPrevious, TextureStage.COSrcColor,
                                             TextureStage.CSLastSavedResult, TextureStage.COSrcColor)
root.setTexture(ts, loader.loadTexture("./textures/grass.jpg"))
root.setTexScale(ts, 32, 32)

## Step 5: third texture - road goes on alpha4
ts = TextureStage("stage-third")
ts.setSort(40)
root.setTexture(ts, loader.loadTexture("./textures/road.jpg"))
ts.setCombineRgb(TextureStage.CMInterpolate, TextureStage.CSTexture, TextureStage.COSrcColor,
                                             TextureStage.CSPrevious, TextureStage.COSrcColor,
                                             TextureStage.CSLastSavedResult, TextureStage.COSrcAlpha)

how can i make this ?
thanks for advance for your help.

The ShaderTerrainMesh class does not have a getRoot method, I believe thats a method of GeoMipTerrain.
The class behaves different from GeoMipTerrain. It does not support multitextures, but instead you will have to write your own shader for it. There is a sample showing how to use it: github.com/panda3d/panda3d/tree … er-terrain

ok but i search a solution for apply texture by heightmap,

like this for example, Is it possible to do it with a shader ?

in this example i want to apply water texture in black color

Because i generated my terrain with noise perlin