[importer] don't see textures in 3d view, but see them in the render?

EDIT:
Solution: assign face.material_index for each face too.

I’m writing a 3d format importer and the model file contains the texture data. I generate a Texture object from the data and assign it to a Material I created, but I can’t see the texture in the 3d view (if I enable “Textured” mode), only when I render a frame.

What am I doing wrong?

relevant parts of the code (simplified):


texture = bpy.data.textures.new('name', type = 'IMAGE')
texture.image = image
texture.use_alpha = True

material = bpy.data.materials.new('name')
mtex = material.texture_slots.add()
mtex.texture = texture
mtex.texture_coords = 'UV'

I can’t get textures on their materials of meshes to get rendered in 3d preview.

What about if you change the viewport to textured view

Still nothing (gray).

Though I’ll mention I never use that option, the one in the image seems to do the trick.

Still can’t find the issue

By my test this is also the case when you create an object in blender, add material to it, add texture to that material and set it’s mode to UV mapping. No matter what rendering option you use or if you enable textured mode or not, the object is white. Texture only visible if you load the image in the UV/Image editor or render a frame.

So this must be something obvious. Not limited to the Python API.

So help guys.