3

I am using Pandas3D 1.10 (with Python 3.6) and I am trying to generate terrain on the fly.

Currently, I was able to perform this:

enter image description here

Now, my idea is to add textures to this terrain. I plan to add different textures for different kinds of ground and biome, but when I try to add a texture, this is added on the whole terrain.

enter image description here

I only want to add the texture to certain parts of the mesh, so I can combine different textures (dirt, grass, sand, etc) and make a better terrain.

From this Panda3D documentation you can see an example of how to make the terrain:

from panda3d.core import ShaderTerrainMesh, Shader, load_prc_file_data

# Required for matrix calculations
load_prc_file_data("", "gl-coordinate-system default")

# ...

terrain_node = ShaderTerrainMesh()
terrain_node.heightfield_filename = "heightfield.png"  # This must be in gray scale, also you can make an image with PNMImage() with code.
terrain_node.target_triangle_width = 10.0
terrain_node.generate()

terrain_np = render.attach_new_node(terrain_node)
terrain_np.set_scale(1024, 1024, 60)

terrain_np.set_shader(Shader.load(Shader.SL_GLSL, "terrain.vert", "terrain.frag"))

In that link, there is also an example of both terrain.vert and terrain.frag.

I tried to apply this guide but it seem that doesn't work on ShaderMeshTerrain, or I think.

ts = TextureStage('ts')
myTexture = loader.loadTexture("textures/Grass.png")
terrain_np.setTexture(ts, myTexture)
terrain_np.setTexScale(ts, 10, 10)
terrain_np.setTexOffset(ts, -25, -25)

The output is the same. It doesn't matter how much I change the numbers of setTextScale and setTexOffset the output is always all with grass.

How can I only implement the texture on a certain part of the model?

Obviously, I can make the image on the fly and do all the modifications with PNMImage(), but it will be slow and difficult, and I am very sure it may be possible to do without re-made the texture each time.

EDIT

I've discovered that I can do this in order to only put a texture in a place:

ts = TextureStage('ts')
myTexture = loader.loadTexture("textures/Grass.png")
myTexture.setWrapU(Texture.WM_border_color)
myTexture.setWrapV(Texture.WM_border_color)
myTexture.setBorderColor(VBase4(0, 0, 0, 0))
terrain_np.setTexture(ts, myTexture)

enter image description here

The problem is that I am not able to change the location of this texture nor its size. Also, note that I don't want to reduce the scale of the texture, when I want to make a texture smaller I mean "cut" or "erase" all the parts that don't fit on the place, not reduce the overall texture size.

Sadly these commands aren't working:

myTexture.setTexScale(ts, LVecBase2(0.5, 250))
myTexture.setTexOffset(ts, LVecBase2(0.15, 0.5))
Ender Look
  • 2,303
  • 2
  • 17
  • 41

0 Answers0