change a Actor's texture. Fail

def main6():            #BBB change texture
    bbb = Pet.Pet("pet", Pet.PET_TYPE_NPC_BBB, "character/bbb/baibaobei.egg")
    myTexture = loader.loadTexture("character/bbb/baibaobei1.png")
    
    ts = TextureStage.TextureStage('ts')
    ts.setMode(TextureStage.MReplace)
    
    bbb.actor.setTexture(ts, myTexture)
    
    #bbb.actor.clearTexture(ts)
    
    
    Pet.setupLights()
    base.camera.setPos(0,-20,0)
    #base.disableMouse()
    run()

baibaobei.egg have two textures whose name are baibaobei.png(in the egg file default) & baibaobei1.png

When I changing her(baibaobei is a woman) texture to baibaobei1.png, the picture show is just darker than original. Why ? I have used TextureStage.MReplace.

without the model it’s hard to say. but i’d try:

actor.setTexture(ts, myTexture, 1)

afaik a priority above 0 is required to replace a texture that is defined within a egg.

because you can have multiple textures on a object, defining replace doesnt automaticallly mean the previous texture is removed. It’s depending on the rendering order of the textures. also you have to check which textureStage you are modifying, iirc you have to get the correct textureStage name, othervise you will add another textureStage to the object.

you may want to play around with ts.setSort(…) if the above doesnt help.

Note that you should create a new TextureStage only if you really want to have both textures applied to the model at the same time. TextureStages are used for multitexturing, so when you create a new TextureStage, you are asking Panda to multitexture your new texture on top of the existing one.

If all you want to do is replace the previous texture with a new one, just do this:

bbb.actor.setTexture(myTexture, 1)

David

I had tried this,but failed ,too.
That’s the effection
Original:

and changed:

and the codes:

def main6():            #BBB change texture
    bbb = Pet.Pet("pet", Pet.PET_TYPE_NPC_BBB, "character/bbb/baibaobei.egg")
    myTexture = loader.loadTexture("character/bbb/baibaobei1.png")
 
    bbb.actor.setTexture(myTexture, 1)
 
    Pet.setupLights()
    base.camera.setPos(0,-20,0)
    #base.disableMouse()
    run()

When I changed the texture in egg file to “baibaobei1.png”, pview it ,that is ok.

So what’s wrong?

I bet your egg file has a non-standard UV name. Most egg files don’t specify a name for the UV coordinates; they look like this:

<UV> { 0.5 0.5 }

Some egg files specify a name for the UV coordinates. They look like this:

<UV> customName { 0.5 0.5 }

If your egg file specifies a name, it means you need to use the same name to override your texture. This makes it more complicated. There are two ways to solve it.

(a) hand-edit your egg file to remove references to the UV name, or use a different option on the converter in the first place so that those UV names don’t get in there, or:

(b) keep the UV name in there, and use code like this:

ts = bbb.actor.findTextureStage('*')
bbb.actor.setTexture(ts, myTexture, 1)

This code will find the existing TextureStage from the model (which has the custom UV name already encoded into it), and will use it to assign the new texture. This only works well if all of the UV’s on your model have the same UV name.

David

Yes, you got it.

I have solved it. The name of the UV is “m1” in my egg file.

Thanks.