1
$\begingroup$

I have a script that list vertices and faces but now I need to get the texture associated with each face, known that only one texture is in each material , only one mesh is in the scene and it is selected . I only found the way to list the texture associated using the uv image editor ...

Thanks

$\endgroup$

1 Answer 1

4
$\begingroup$

Using blender internal, a material can use up to 18 textures to get it's final appearance. An objects face can have one material assigned to it, any and all textures in that material are used by the face.

In object mode you can get the texture used by each face with

obj = bpy.context.object
for f in obj.data.polygons:
    for t in obj.material_slots[f.material_index].material.texture_slots:
        if t is not None:
            print("Face %d uses texture %s"%(f.index,t.name))

Of course this is using Blender Internal, for cycles you will need to walk through the nodetree to find the nodes your interested in.

$\endgroup$
2
  • $\begingroup$ It's almost that. It displays the texture name, I didn't say but I need the texture "filename", I don't find how to get it now... $\endgroup$
    – Entretoize
    Commented Mar 11, 2015 at 8:23
  • $\begingroup$ I just find that obj.material_slots.material.texture_slots[0].texture.image.name give me the texture name with .00X for dupplicate, I think I can work with it... $\endgroup$
    – Entretoize
    Commented Mar 11, 2015 at 8:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .