i’m admittingly new to blender and i’m trying to make a mesh in python.
everything is fine except a can’t seem to assign mutliple materials to different faces on my mesh.
I tried running this snippit i found here:
http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Materials_and_textures
changing “faces” to “tessfaces” and everything seems to work. but when you toggle between edit / object mode again, all of the materials revert back to just red.
i’m guessing that there’s a completely different way to do it in 2.6 but after searching for a while i still haven’t found anything.
I wrote some code to illustrate this further:
import bpy
def new_material():
bpy.ops.material.new()
return bpy.data.materials[-1]
def newMaterialToFace(faceIndex, colorVal):
newMaterial = new_material()
newMaterial.name = "m%i" % faceIndex
newMaterial.use_shadeless = True
newMaterial.diffuse_color = colorVal
objectMesh.materials.append(newMaterial)
objectMesh.update(calc_tessface=True)
objectMesh.tessfaces[faceIndex].material_index = len(objectMesh.materials) - 1
objectRef = bpy.context.scene.objects.active
objectMesh = objectRef.data
newMaterialToFace(0, (1, 0, 0))
newMaterialToFace(1, (0, 1, 0))
#objectMesh.update()
start out with a mesh selected with at least two faces and you should see my problem. the green face reverts back to red when you toggle between modes or when you uncomment that last line. is there a different update mode i should be calling to have my tessfaces’ material_index info saved?