Why can a mesh have more than one material slot. You are only able to have one active material on a face. What is the reason for having multiple material slots?
Is there a way so swap out the active material while a game is running. I found this code that will swap the material in slot 0 with the one is slot 1, but the texture of my object never changes.
a=bge.logic.getSceneList().objects.get('Bedrock') #select object Cube
print((a.meshes.materials ) ) #show its materials
mat=a.meshes.materials #copy current material
a.meshes.replaceMaterial(0, a.meshes.materials ) #replace first material with the second (which has different color of curse :-)
a.meshes.replaceMaterial(1, mat) #copy the 1st material to 2nd slot
print((a.meshes.materials ) ) #show materials list
This will swap material 0 and material 1, but the texture will not change.
This code below will change the texture on the active material.
ID = texture.materialID(a, 'MABedrock')
# create a texture object
object_texture = texture.Texture(a, ID)
# create a new source with an external image
url = logic.expandPath("//Textures/bedrock.png")
new_source = texture.ImageFFmpeg(url)
# the texture has to be stored in a permanent Python object
logic.texture = object_texture
# update/replace the texture
#logic.texture.source = new_source
How do I get the active material to change and have the texture of my object change to the one of the new active material?
The idea is that I will have 5+ blocks. They will all share the same model, but have different textures. So instead of creating 5+ models of the same cube and assigning a different materials, I was wondering if I could just create one block model and assign it the correct material when I spawn it into the world.