Texture Replacement Issue [SOLVED]

Hi all,
I’m having an issue with the .setTexture() function.

This is my normal code that I’ve used up to now to create my environment.

## load arena
arena = loader.loadModel("models/testarena.egg")
arena.setPos(10000,10000,0)
arena.reparentTo(render)

floor = loader.loadModel("models/court_floor.egg")
floor.setPos(10000,10000,0)
floor.reparentTo(render)

and this produces my initial environment fine.

However when I change my code to load a new texture in to replace my existing floor texture like this…

## load arena
arena = loader.loadModel("models/testarena.egg")
arena.setPos(10000,10000,0)
arena.reparentTo(render)

floor_alt = loader.loadTexture('models/court_sample_wooden.tga')

floor = loader.loadModel("models/court_floor.egg")
floor.setPos(10000,10000,0)
floor.reparentTo(render)
floor.setTexture(floor_alt,1)

this happens…

Its getting the colour from the image cus its supposed to be a wooden floor but it looks like the UVs have been lost :angry:

its doing it for the markers/players too but its more apparent to show with the floor as its a flat surface.

thanks in advance

I suspect your model uses custom-named UV’s, and therefore a non-standard texture stage. This means when you load the model, its texture is assigned not to the default texture stage, but to a custom texture stage created just for the model, and with the UV name set to the UV name used in your model.

The upshot is that when you use the above code, which applies a texture to the default texture stage, you are (a) adding a new texture, rather than replacing the original texture, and (b) since there are no default UV’s, the new texture ends up with no UV’s.

There are two possible solutions. (1) remove the named UV’s from your model, and use the default UV’s instead. (2) find the texture stage from your model (via model.findTextureStage(’*’)) and use that to apply the replacement texture, instead of the implicit default texture stage.

David

aha mate your a legend, I had no idea what the texture stage things were for, it read like welsh to an englishman lol.

Yeh this works great and I think i see room to solve other problems i had coming up too!

Double Kudos to you!