1
$\begingroup$

Hi: I keep trying to put a jpg image on a mesh, but its being far too complex, and I was thinking there must be an easier way.

I have tried to edit the following code to do that, but I keep failing (all the objects on the blend file will change their surface to their last image, and weird things happening)

imagen_original=bpy.data.images.load(filepath="D:\ERASE\LeoGoodOne\VoidRay_SC2_Rend1.jpg")  
# importa el archivo
nombre_textura = "nombre_textura_" + str(index)
# define el nombre de la textura
textura_creada = bpy.data.textures.new(nombre_textura, type = 'IMAGE')
# crea la textura
bpy.data.textures[nombre_textura].image = imagen_original
# asigna el archivo a la textura
textura_en_material = bpy.data.materials[nombre_material].texture_slots.add()
#agrega un slot para textura
textura_en_material.texture = textura_creada

So, the question is, which is the simplest way to add an image to a mesh in python, given we have the path and the mesh is selected:

filepath="D:\ERASE\LeoGoodOne\VoidRay_SC2_Rend1.jpg"
bpy.ops.mesh.primitive_plane_add(view_align=False, enter_editmode=False, location=(-5, 0, 0.3), layers=(True, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False))
bpy.context.scene.objects.active.select = True
$\endgroup$
  • $\begingroup$ Im wondering if I should have asked this on python stack or its fine here? =) $\endgroup$ – I want badges Dec 24 '13 at 11:48
  • 1
    $\begingroup$ This is the place. $\endgroup$ – Gunslinger Dec 24 '13 at 12:02
  • 1
    $\begingroup$ See the code of io_import_images_as_planes.py in blender-home/version/scripts/addons it contains all the methods you would need. $\endgroup$ – stacker Dec 24 '13 at 12:29
  • $\begingroup$ Thanks for the suggestion. I will study and try to answer this question through studying that, but after opening and examining the python file I realize that I will require far much more knowledge of both python and blender, so dont expect the answer any time soon. But I think this is so basic, someone should have already created a simple script to just add an image to his mesh? $\endgroup$ – I want badges Dec 24 '13 at 12:49
  • $\begingroup$ Getting this done from a script is a requirement of your project? If not you can do it the normal way. Select the object, go to edit mode, unwrap using the projection you estimate the best for your mesh, go to UV Image Editor, load the image you want. (this will make the image visible in textured view but not for rendering yet). Go to Material properties, create one if none exists. Go to Textures properties. Create one of type Image or Movie, load your image. wiki.blender.org/index.php/Doc:2.6/Manual/Textures/Mapping/UV/… $\endgroup$ – Hatoru Hansou Dec 24 '13 at 22:10

Your Answer

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

Browse other questions tagged or ask your own question.