setTexture on a BAM model not properly applied

I just converted a really simple Minecraft Character from Blender to a BAM file using blend2bam character.blend character.bam

I’ve applied a texture image for that character in Blender and it looked fine. When importing the BAM file into Panda3d it looks all fine as well. However, when trying to change the texture to the exact same texture image I used in Blender (yes, it doesn’t make sense to change the texture to the same one but I am just doing this for testing - different textures will be applied when it works at all), but this time using code in Panda3d, the character’s texture seems to be blended with an anthracite color.

Then I saved my character.blend without a texture applied. When I then tried to set a texture using Panda3d, the whole character got an anthracite color.

I think it could be possible that the texture is somehow misaligned, because the texture image I’m trying to apply has that anthracite color in it. But then, why has the whole character that color? And why would this even happen if the same texture applied in Blender and exported to BAM would work?

Could you help me?

This is the relevant code:

    m = loader.loadModel("character.bam")
    ts = m.findTextureStage("*")
    m.setTexture(ts, loader.loadTexture("skin_adventurer.png"), 1)

This shows all the relevant Blender stuff:

And this is my BAM file:

Possible things going on:

  • You’re applying the texture to the whole model when you mean to apply it to a sub-part. You can use find() to find the right part, or you can use the more convenient model.replaceTexture() to replace a known texture with another texture.
  • The model has specifically-named sets of UV coordinates, and by using the default TextureStage, it’s not selecting the correct one. You could instead create a TextureStage that targets the right UV set (using setTexcoordName, I think) and then apply it using that TextureStage.
  • It might be that when you’re exporting it without texture, no UV coordinates are added to the model at all.
1 Like

Thank you and thank you! Your last two points did it for me. So I needed to analyze which UV Map name my BAM file used and then create a new texture.

For anyone who comes across this, just follow these steps to make it work:

  • Run “bam2egg your_model.bam your_model.egg” - you most probably have bam2egg already installed
  • Open up the egg file in a text editor and search for the <Texture> section.
  • In this section, search for " uv-name { 0 }" . The “0” is the actual UV Map name - so yours might be different. That’s why we’re having that texturing problem!
  • If your BAM model came with a texture preconfigured, remove it in Blender first: remove it from every object you exported. And, of course, re-export your blend file to bam then.
  • Use the following code to apply a texture to your BAM model:
    model = loader.loadModel("your_model_which_has_no_texture.bam"
    texture = loader.loadTexture("your_preferred_texture.png")
    ts = TextureStage("stage1")
    ts.setTexcoordName("0") # Instead of "0", insert the name you found in your egg's uv-name {...} (see above)
    model.setTexture(ts, texture, 1)

This should do the job. Another good-to-know post. Hopefully it helps anyone fiddling with it. Thank you to @rdb!