I am trying to load a specific mesh with texture into blender using bpy. With a lot of help from this community, I have managed to load both the mesh and texture.

Our question

1) When we try to render the image, we end up with a very poor quality image. Why does this happen?

2) It is one thing if the image was just a bit blurry because of resolution issues but in this case it looks like the shape + texture is resulting in a significantly different face image which suggests that something is off with the rendering.

My best bet is that I have a bunch of "dummy vertices" at 0,0,0. My polygonal meshing algorithm includes this vertex in many cases. This can be seen in one of the attached images. Somehow this is affecting the final output?

I can post how I preprocessed data and loaded/created the mesh for interested aides.

Thank you!

3D view of mesh + texture

Rendered view of mesh + texture

Artifact of my choice of vertices and polygonal meshing

This is the code for rendering

      #Fuck it let's start new
      import scipy.io as scio
    import sys
    import numpy as np
    import bpy
    from math import radians
    import random
    import pdb

    faces = faces-1

    for object in bpy.data.objects:
        if object.name != 'Lamp' and object.name !='Camera':
            object.select = True
    objs = [l for l in bpy.data.objects]

    #Deleting existing object

    #Creating a new mesh
    mesh_3d= bpy.data.meshes.new("Human_Face")

    #converting stuff to int and making a list out of a numpy array...fuuuuuck
    #Remember that these are matlab indices, somethign to worry about
    for ii in range(vertices.shape[0]):

    #converting more stuff to int, same thing except here out of face data where face == triangles
    for ii in range(faces.shape[0]):

    #This lets us create our own mesh of an object
    mesh_3d.from_pydata(vertex, [], face)
    #We update the scene
    #creating a new object to link the object
    obj = bpy.data.objects.new("My_Object", mesh_3d)
    #we take the context
    scene = bpy.context.scene

    vertex_colors = mesh_3d.vertex_colors

    if len(vertex_colors)==0:

    color_layer = vertex_colors['Col']
    i = 0
    non_zero = np.nonzero(texture)

    face_flat = faces.flatten()
    for ii in range(face_flat.shape[0]):
        color_layer.data[ii].color = list(texture[face_flat[ii],:]/255.0)

    mat = bpy.data.materials.new('vertex_material')
    mat.use_vertex_color_paint = True
    mat.use_vertex_color_light = True

    #Experimenting with trying to set active object, seems more or less useless or a duplicate of the previous statements
    for object in bpy.data.objects:
        if object.name != 'Lamp' and object.name !='Camera':
            object.select = True
            bpy.context.scene.objects.active = object

    myObj = bpy.context.selected_objects[0]
    #Not sure what these next pair of statements do but they are important to edit object

    myObj.scale = ((0.05,0.05,0.05))

    bpy.data.objects['Camera'].location = (0.0,0.0,10.0)
    bpy.data.objects['Camera'].rotation_euler = (radians(0.0),radians(0.0),radians(0.0))

    ##Move the Lamp aka Light    
    bpy.data.objects["Lamp"].location = (0.0,0.0,15.0)

    scene.camera.data.angle = fov*(np.pi/180.0)

    #Rendering file
    path = "load_face2.png"
    bpy.data.scenes['Scene'].render.filepath = path
  • $\begingroup$ Hmm. Apologies if things were not clear. We really tried hard to make it very clear. Could the users who put us on hold be a bit more specific with regards to questions? What we are trying to understand is -- why is the object very clear (resolution/sharpness) in the 3D view and so poorly rendered when viewed as an image? $\endgroup$ – Mayur Feb 4 '15 at 19:52
  • $\begingroup$ To be even more concise -- why is Image 1 so drastically different from Image 2? (above) $\endgroup$ – Mayur Feb 4 '15 at 20:07
  • $\begingroup$ What is your render resolution set to? The percentage under the image dimensions? $\endgroup$ – VRM Feb 4 '15 at 20:41
  • $\begingroup$ It is at 50%. I experimented with setting 100% and it did not help. I also experimented with multiple image sizes to render and that made no difference. $\endgroup$ – Mayur Feb 5 '15 at 0:56
  • 1
    $\begingroup$ Okay, I fixed it. Turns out the shader was the problem. When you iterate through the objects and turn the "shadeless = True" option ON or just change the specularity it went through fine. $\endgroup$ – Mayur Feb 9 '15 at 20:45

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.