0
$\begingroup$

how can I assign colours to a specific face/polygon in the python API? I have found a way of creating materials, but how can I use them through the API on chosen polygons of an object? Does an object have to be fully covered with a material before you can change that of individual parts?

Thank you for your time!

$\endgroup$
1

1 Answer 1

1
$\begingroup$

The mesh doesn't have to be fully covered with a material, but it does have to have material slots(at least two) if you want to be able to change individual parts.

import bpy

obj = bpy.data.objects['Cube']
mat = bpy.data.materials['Red']
mat_slots = obj.material_slots
polys = obj.data.polygons

#add a material slot using a material
obj.data.materials.append(mat)

#remove material from material slot
mat_slots[0].material = None

#add the material slot that will be used for individual face
obj.data.materials.append(mat)

#apply material to one face
polys[0].material_index = 1
$\endgroup$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.