Heightfiled & Texture

Hello,

I am having a problem with one of the new features of Panda3d, the heightfield terrain. Using the following code I managed to create and display a heightfield, but I failed to give it a texture.

filename = Filename( 'models/terrain/elevation.png' )
tex = loader.loadTexture( 'models/terrain/grass.png' )

tesselator = HeightfieldTesselator( 'Terrain' )
tesselator.setHeightfield( filename )
tesselator.setFocalPoint( 0, 0 )

node = tesselator.generate( )
node.setTexture( tex )
node.reparentTo( render )

The terrain can be seen in the render window, but it is ‘monochrome’ and not textured. The colour could be one of the colours used in the texture, so I guess vertex colours work. I have tried to use TextureStages, but with the same result.

If anyone has an idea what I have done wrong when setting the texture, please tell me. Thanks in advance.
enn0x

The generated terrain doesn’t have texture coordinates. (I wonder if I should make that an option). Assuming you’re not using shaders, the easiest way to assign texture coordinates is using the method shown here:

nodePath.setTexGen(TextureStage.getDefault(), TexGenAttrib.MWorldPosition)

as documented here:

panda3d.org/manual/index.php/Autom … oordinates

Of course, then you probably want to scale the texture coordinates a bit, maybe using this:

nodePath.setTexScale(TextureStage.getDefault(), uScale, vScale);

as documented here:

panda3d.org/manual/index.php/Texture_Transforms

Thank you, terrain with texture is working now :slight_smile:

Maybe post a code snippet showing how you got it to work?

Aye, you should. How often is anyone going to render a heightfield mesh without texturing it?

Skip it … Here is my example … discourse.panda3d.org/viewtopic.php?p=9821#9821