Continuous and coherent texture mapping on deforming objects I am new to Blender, and I am stuck with a problem in texture mapping.

I have got a series of model files (*.obj) that represents a non-rigid, deforming object. Each of the model file, represents an incremental deformation of the object and has been generated externally, using another software. These model files are textureless.

Here is an example:



I want to import these models into Blender sequentially (using Python), overlay a texture on them, add a background (and some lights) and export the complete animation. The texture that gets wrapped around the object is an image of 6000x4000 pixels. 

However, the texture mapping is not working properly. It seems as if the texture is loosely overlaid on the object and the deformation makes the surface smoothly glide and slide beneath the texture. It is not what one would expect from a real world object.

If you look at the following images carefully, you might be able to notice the discrepancy:



Here is the script I am using to assign the texture:

realpath = os.path.expanduser("/path/to/some/image.jpg")
try:
    img = bpy.data.images.load(realpath)
except:
    raise NameError("Cannot load image %s" % realpath)

# Create image texture from image
cTex = bpy.data.textures.new('material1', type='IMAGE')
cTex.image = img

# Create material
mat = bpy.data.materials.new('material1')

# Add texture slot for color texture
mtex = mat.texture_slots.add()
mtex.texture = cTex
mtex.texture_coords = 'OBJECT'
mtex.bump_method = 'BUMP_BEST_QUALITY'
mtex.reflection_factor = 0.8
mtex.use_map_diffuse = True
mtex.use_map_color_diffuse = True
mtex.use_map_color_emission = True
mtex.emission_color_factor = 0.0
mtex.use_map_density = True
mtex.mapping = 'FLAT'

mat.diffuse_intensity = 0.8
mat.diffuse_shader = 'OREN_NAYAR'


Using 

mtex.texture_coords = 'GLOBAL'


instead of 'OBJECT' helps a little, but the stretching and distortion of the texture looks unrealistic in the 'global' mode.

Please help me in figuring out the root cause behind the problem and how, if at all, can this be remedied.
If you want the texture to deform with the surface, you will have to use UV mapping. Every polygon corner gets assigned a location in UV (2D) space and textures use this information to map to surface. This mapping is not hard to create (see UV textures/ing tutorials), but it can be unique for every mesh, so the key is ensuring this UV mapping is the same in all your meshes.

There is a way to have only 1 mesh and to use all the others for creating mesh shape keys. You need Absolute shape keys that animate in a sequence. You do this by joining 2 meshes with Join as Shapes option. This way you can convert multiple meshes with the same vertex order into a single mesh with deformation animation.

In python with both selected and the target for animation active:

bpy.ops.object.join_shapes()


You might need to override the context.