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()[0].objects.get('Bedrock') #select object Cube
print((a.meshes[0].materials ) ) #show its materials
mat=a.meshes[0].materials[0] #copy current material
a.meshes[0].replaceMaterial(0, a.meshes[0].materials[1] ) #replace first material with the second (which has different color of curse :-)
a.meshes[0].replaceMaterial(1, mat) #copy the 1st material to 2nd slot
print((a.meshes[0].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
logic.texture.refresh(False)
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?