0
$\begingroup$

I need some help making a mesh colorful. The image I add to a material does not show up on my mesh. A snippet of the code is below

# Create new mesh
mesh = bpy.data.meshes.new("Landscape_Data")

# Make a mesh from a list of verts/edges/faces.
mesh.from_pydata(verts, edges, faces)

# Update mesh geometry after adding stuff.
mesh.update(calc_edges=True)

obj = bpy.data.objects.new("Landscape", mesh)  
obj.data = mesh 

# Link mesh to scene
scene = bpy.context.scene  
scene.objects.link(obj)  
obj.select = True 

def material_for_texture(fname):
    img = bpy.data.images.load(fname)

    tex = bpy.data.textures.new(fname, 'IMAGE')
    tex.image = img

    mat = bpy.data.materials.new(fname)
    mat.texture_slots.add()
    ts = mat.texture_slots[0]
    ts.texture = tex
    ts.texture_coords = 'UV'
    return mat

obj = bpy.data.objects['Landscape']
mat = material_for_texture("C:\\Users\\Kyle\\Documents\\DTEEC_019358_2225_018857_2225_U01.ca.jpg")

if len(obj.data.materials)<1:
    obj.data.materials.append(mat)
else:
    obj.data.materials[0] = mat

Example: https://i.stack.imgur.com/jbNjK.png

The material looks like it loads the image but does not put it on the mesh Blender Grey Mesh Example

$\endgroup$
  • $\begingroup$ My first guess is around UV map or assigning faces to the material. But which render engine are you using here? $\endgroup$ – lemon Sep 11 '19 at 6:54
  • $\begingroup$ I am using the default, Blender render $\endgroup$ – Kyle Pearson Sep 11 '19 at 17:55
0
$\begingroup$

I can see you're using Blender Internal. Use Viewport shading enter image description here and select Material to see your image or texture in the viewport. And to achieve what you want, create new image in the UV editor, open the texture in it and unwrap the mesh. Scale down the UVs if necessary to have them inside the image area.

$\endgroup$
  • $\begingroup$ Ahhh, when I change the viewport to "Rendered" I see my texture but each face/triangle in my mesh has the texture. Is there an easy way to UV map it to stretch one copy across my whole mesh? $\endgroup$ – Kyle Pearson Sep 11 '19 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.