repeating a texture in a terrain

hi
how can i repeat a texture on a GeoMipTerrain?
when i want to create a terrain always my ground texture occupy my whole terrain height field and my ground terrain always has low quality.

Set a texture scale, look up setTexScale.

Thank you rdb
How can i use it?
i apply this function to node of the terrain but nothing changed?
Can you show me an example?

can any one help me?

Here’s an example:

node.setTexScale(TextureStage.getDefault(), 2)

Is that what you’re looking for?

David

Thank you David
i apply setTexScale(TextureStage.getDefault(), 2) to root of the terrain but there is always only one texture on the terrain and it dose not repeat to fill the terrain.
i want to repeat a texture on the terrain to fill the surface of the terrain.

Hi,

We need more information, does this terrain have multiple textures on it? Or just one?

If it has multiple textures, you may need to set the scale on all of the TextureStages of your model.

You could try this:

for ts in node.findAllTextureStages('*'):
    node.setTexScale(ts, 2) # or some other scale instead of 2, like 3.5, 4, 8, 2000, you get the idea

~powerpup118

Thank you powerpup118
I have only one texture and i is small (127 * 127) and my terrain is 1027 * 1027 pixels. i want to set multiple textures to fill the terrain.
In the code that i wrote, i see a terrain that the small texture is on it and and only one time.
i want to repeat the texture to fill the terrain.

I haven’t read the whole thread, but that’s always a red light.

Why not power of two?

well, it’s technically power of two + one according to the manual, still his terrain should be 1024 + 1 = 1025 by 1025

ahmadiakbari:
Does using the method I suggested do what you want? It should have made it so that your terrain, instead of having one large texture across it, would have two large textures stretched across it. You probably need to set the scale higher like I said earlier in the comment in the python code.

Make your heightfield power of 2 plus one, by setting the size of your heightfield to 1025 please, then do the following code, and let me know if it does what you want:

terrainSize = 1025
textureSize = 128

for ts in node.findAllTextureStages('*'):
    node.setTexScale(ts, terrainSize / textureSize) # the scale number I was talking about, which you can calculate using terrainSize / textureSize, giving you how many texture sizes you need to make it technically unit-perfect

Oh, also make your texture size power of two, by changing it’s size to 128x128 pixels, look up power of two on wikipedia for a list of power of two numbers, if they’re difficult for you at all.

Otherwise you might just want to change the scale number your self and see what number works best for you.

I’d try this code also, then:

terrainSize = 1025
textureSize = 128

for ts in node.findAllTextureStages('*'):
    node.setTexScale(ts, 16) # again, the scale number, this is how many times the texture will repeat, so instead of one image stretched across the terrain, we have 16

~powerpup118

Hi

try using setWrapU(WMRepeat) and setWrapV(WMRepeat)
on your texture. You can also play with the setXSize and setYSize to adjust the texture size itself to get different number of repeats across your terrain, I believe.

Thank you my friends

i set the size of the terrain to 1025 * 1025 and size of texture to 128 * 128 and apply the code that your code but nothing changed.part of my code is here:

terrain = GeoMipTerrain("terrain")
		terrain.setHeightfield(Filename("models/textures/heightmap.png"))
		terrain.setColorMap(Filename("models/textures/grass.jpg"))
		terrain.setBlockSize(16)
		terrain.setFocalPoint(base.camera)
		root = self.parent.terrain.getRoot()
		for ts in root.findAllTextureStages('*'):
			ts.setTexScale(ts, 2)
		#for ts in root.findAllTextureStages('*'):
			#root.setTexScale(ts, 20)
		root.setSz(50)

		root.reparentTo(self.parent.render)
		terrain.generate()
		terrain.setBruteforce(True)

i also try what tah said.

but it dose not work.here is my code.

terrain = GeoMipTerrain("terrain")
		terrain.setHeightfield(Filename("models/textures/heightmap.png"))
		terrain.setColorMap(Filename("models/textures/grass.jpg"))
		terrain.setBlockSize(16)
		terrain.setFocalPoint(base.camera)
		root = self.parent.terrain.getRoot()
		for ts in root.findAllTextureStages('*'):
			ts.setWrapU(WMRepeat)
			ts.setWrapV(WMRepeat)
			ts.setXSize(10)
			ts.setYSize(10)
		root.setSz(50)

any solution?

Hi

I don’t see where the textureStage is being applied to your terrain, is it there somewhere ? I know of the call nodePath.setTexture(ts,texture), but I see you are using terrain.setColorMap() to set the texture to the terrain nodePath. I’ve never used that, I’ve used TexturePool but using texture = loader.loadTexture(textureFile) does the same thing, then I use terrainNode.setTexture(ts,texture) after creating the ts (TextureStage). And actually I do all my coding in C++, but python looks like it has the same functions for this process.

setColorMap sets the vertex colours, don’t use it unless you need it for some special reason.

hi
Thank you for answering
How can i set a texture on a GeoMipTerrain?
i cant find anything in the manual.

i did it

self.terrain = GeoMipTerrain("terrain")
		self.terrain.setHeightfield(Filename("/Panda3D-1.7.2/models/textures/heightmap.png"))
		texture = self.loader.loadTexture("/Panda3D-1.7.2/models/textures/grass.jpg")
		self.terrain.setBlockSize(16)
		self.terrain.setFocalPoint(base.camera)
		root = self.terrain.getRoot()
		root.setTexture(TextureStage.getDefault(), texture)
		root.setTexScale(TextureStage.getDefault(), 100)
		root.setSz(40)