TextureStage weird error/bug

I’m placing a cubemap on a model that was painted in Blender.
I want the two blended together.

The following code works beautifully:

tex = loader.loadCubeMap('files#.png')
self.ts = TextureStage('ts')
self.ts.setMode(TextureStage.MDecal)
self.model = loader.loadModel("model.egg")
self.model.setTexGen(self.ts, TexGenAttrib.MWorldNormal)
self.model.setTexture(self.ts, tex)
self.model.reparentTo(render)

But when the ts lines and the model loading line are interchanged it loads the cubemap but overrides the painted texture from Blender.

tex = loader.loadCubeMap('files#.png')
self.model = loader.loadModel("model.egg")
self.ts = TextureStage('ts')
self.ts.setMode(TextureStage.MDecal)
self.model.setTexGen(self.ts, TexGenAttrib.MWorldNormal)
self.model.setTexture(self.ts, tex)
self.model.reparentTo(render)

Since I got it to work in a small test program I wanted to incorporate it into my project. The project loads in models dynamically based on other things happening- even so, I added the ts lines ahead of the model loading line but in the program the result I get is the cubemap overriding the Blender textures. I have it in a class that loads up the model character which is called many times during the course of the program- I don’t know if this would make any difference but then again I wouldn’t have guessed that changing the above lines would have such an effect.

Is there something I’m missing?

I’d really like to have this work right.

Since you haven’t specified a sort order on your TextureStage, both it and the default texture stage have the same sort value. Thus, the order in which they are applied is undefined, and may come out one way or the other based on the phase of the moon.

If you want your TextureStage to be applied always on top of the default texture stage, specify a sort value, like this:

self.ts.setSort(10)

David

First of all, Thanks for responding so quickly. I think it’s great that you help out the community with your expertize.

You’re right, I was missing the setSort(). Turns out though that I had to set the sort value to -1 to get it to work.

Thanks again.