Skip to main content
Tweeted twitter.com/#!/StackBlender/status/368251982580314112

Blender 2.68a Python 3

I want to set texture for faces. I put (and googled) together a quick example using the "Cube", and having an existing BMP as the texture file on disk. I am object-modein Object Mode. I set the Viewport Shading to textureTexture.

The code is:

import bpy
import bmesh

texturak = bpy.data.textures
o = bpy.data.objects["Cube"]
me = o.data
ol = me.materials

img = bpy.data.images.load('d:\\canwall1.bmp')
texturak.new('ColorTex', type = 'IMAGE')
texturak[-1].image = img

mat = bpy.data.materials.new('TexMat')
mtex = mat.texture_slots.add()
mtex.texture = texturak[-1]
mtex.texture_coords = 'UV'
mtex.use_map_color_diffuse = True 
mtex.use_map_color_emission = True 
mtex.emission_color_factor = 0.5
mtex.use_map_density = True 
mtex.mapping = 'FLAT' 

if (len(me.uv_textures) == 0):
    me.uv_textures.new()
while (ol):
    ol.pop(0,update_data = True)
ol.append(mat)

for texlay in me.uv_textures:
    for tf in texlay.data:
        tf.image = img
    

I get the cube, then the texture, I additadd it as a material. Nahh well fromFrom there, I found no good examples on internet. OnlyThe only working stuff was for Blender 2.5 and some guesses from the answer of my previous question here.

So for this time I tried to set all face-imageimages to the image I load. But all I get is a purple cube. Now my guess is that "something happened" (woohoo), but as well as "somthing"something is missing" (no woohoo this time).

My question would be to those more experienced, that what is missed here actually, or is there a better way to set material / texture to a face / faces?

Edit: ToEdit: To extend my question: I want to have more textures per mesh,mesh; this is why I want to set the texture per face.

Blender 2.68a Python 3

I want to set texture for faces. I put (and googled) together a quick example using the "Cube", and having an existing BMP as texture file on disk. I am object-mode. I set the Viewport Shading to texture.

The code is:

import bpy
import bmesh

texturak = bpy.data.textures
o = bpy.data.objects["Cube"]
me = o.data
ol = me.materials

img = bpy.data.images.load('d:\\canwall1.bmp')
texturak.new('ColorTex', type = 'IMAGE')
texturak[-1].image = img

mat = bpy.data.materials.new('TexMat')
mtex = mat.texture_slots.add()
mtex.texture = texturak[-1]
mtex.texture_coords = 'UV'
mtex.use_map_color_diffuse = True 
mtex.use_map_color_emission = True 
mtex.emission_color_factor = 0.5
mtex.use_map_density = True 
mtex.mapping = 'FLAT' 

if (len(me.uv_textures) == 0):
    me.uv_textures.new()
while (ol):
    ol.pop(0,update_data = True)
ol.append(mat)

for texlay in me.uv_textures:
    for tf in texlay.data:
        tf.image = img
    

I get the cube, then the texture, I addit as a material. Nahh well from there I found no good examples on internet. Only working stuff was 2.5 and some guesses from the answer of my previous question here.

So for this time I tried to set all face-image to the image I load. But all I get is a purple cube. Now my guess is that "something happened" (woohoo), but as well as "somthing is missing" (no woohoo this time).

My question would be to those more experienced, that what is missed here actually, or is there a better way to set material / texture to a face / faces?

Edit: To extend my question: I want to have more textures per mesh, this is why I want to set the texture per face.

I want to set texture for faces. I put together a quick example using the "Cube" and an existing BMP as the texture file on disk. I am in Object Mode. I set the Viewport Shading to Texture.

The code is:

import bpy
import bmesh

texturak = bpy.data.textures
o = bpy.data.objects["Cube"]
me = o.data
ol = me.materials

img = bpy.data.images.load('d:\\canwall1.bmp')
texturak.new('ColorTex', type = 'IMAGE')
texturak[-1].image = img

mat = bpy.data.materials.new('TexMat')
mtex = mat.texture_slots.add()
mtex.texture = texturak[-1]
mtex.texture_coords = 'UV'
mtex.use_map_color_diffuse = True 
mtex.use_map_color_emission = True 
mtex.emission_color_factor = 0.5
mtex.use_map_density = True 
mtex.mapping = 'FLAT' 

if (len(me.uv_textures) == 0):
    me.uv_textures.new()
while (ol):
    ol.pop(0,update_data = True)
ol.append(mat)

for texlay in me.uv_textures:
    for tf in texlay.data:
        tf.image = img
    

I get the cube, then the texture, I add it as a material. From there, I found no good examples on internet. The only working stuff was for Blender 2.5 and some guesses from the answer of my previous question here.

So for this time I tried to set all face-images to the image I load. But all I get is a purple cube. Now my guess is that "something happened" (woohoo), but as well as "something is missing" (no woohoo this time).

My question would be to those more experienced, that what is missed here actually, or is there a better way to set material / texture to a face / faces?

Edit: To extend my question: I want to have more textures per mesh; this is why I want to set the texture per face.

Source Link
Zéiksz
  • 2k
  • 5
  • 23
  • 32

Set face texture

Blender 2.68a Python 3

I want to set texture for faces. I put (and googled) together a quick example using the "Cube", and having an existing BMP as texture file on disk. I am object-mode. I set the Viewport Shading to texture.

The code is:

import bpy
import bmesh

texturak = bpy.data.textures
o = bpy.data.objects["Cube"]
me = o.data
ol = me.materials

img = bpy.data.images.load('d:\\canwall1.bmp')
texturak.new('ColorTex', type = 'IMAGE')
texturak[-1].image = img

mat = bpy.data.materials.new('TexMat')
mtex = mat.texture_slots.add()
mtex.texture = texturak[-1]
mtex.texture_coords = 'UV'
mtex.use_map_color_diffuse = True 
mtex.use_map_color_emission = True 
mtex.emission_color_factor = 0.5
mtex.use_map_density = True 
mtex.mapping = 'FLAT' 

if (len(me.uv_textures) == 0):
    me.uv_textures.new()
while (ol):
    ol.pop(0,update_data = True)
ol.append(mat)

for texlay in me.uv_textures:
    for tf in texlay.data:
        tf.image = img
    

I get the cube, then the texture, I addit as a material. Nahh well from there I found no good examples on internet. Only working stuff was 2.5 and some guesses from the answer of my previous question here.

So for this time I tried to set all face-image to the image I load. But all I get is a purple cube. Now my guess is that "something happened" (woohoo), but as well as "somthing is missing" (no woohoo this time).

My question would be to those more experienced, that what is missed here actually, or is there a better way to set material / texture to a face / faces?

Edit: To extend my question: I want to have more textures per mesh, this is why I want to set the texture per face.