2
$\begingroup$

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:

enter image description here

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:

enter image description here

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.

$\endgroup$
  • $\begingroup$ Object or global coordinates will not work as the texture will not follow the deformation of the shape. You would need to assign UVs on the program that is generating the geometry, that way the texture would stretch or contract with the geometry, like it does on the real world. $\endgroup$ – user1853 Feb 20 '19 at 16:22
  • $\begingroup$ How do you assign UVs? Any link or a tutorial would help. I am new to this and not familiar with the basics. And... I have little control over how the mesh is being generated. It is part of a FEM simulation software. Don't think its possible to add texture there. $\endgroup$ – metsburg Feb 20 '19 at 16:27
  • 1
    $\begingroup$ Then you need to import the undeformed object into blender, create a UV map and assign the texture mapping using those coordinates. It should work as long as the number of vertices and order are the same in the deformed objects. There are plenty of "tutorials" online on how to unwrap and generate UVs. If you get stuck ask another question on this site. $\endgroup$ – user1853 Feb 20 '19 at 16:30
  • 1
    $\begingroup$ Related: how can I mark the seams to unwrap a torus $\endgroup$ – user1853 Feb 20 '19 at 16:31
  • $\begingroup$ Number of vertices are not the same, in fact... there can be topological changes in the model too, such as cutting or splitting of a part of the model. And when multiple vertices gets squeezed together, they get replaced by one vertex. So the number of vertices are not guaranteed to be the same. $\endgroup$ – metsburg Feb 20 '19 at 16:33
2
$\begingroup$

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.

|improve this answer|||||
$\endgroup$
1
$\begingroup$

My understanding of your problem: mesh deformations dont seem to affect the texture, giving you an-always perfectly spread image over the surface.

I believe it's a UV problem. Does each one of your objects have its own UV layout specifically unwrapped for that object?

If that's the case, it means (at least in my mind) that each UV layout adjusted itself around the mesh deformations, giving you an always-even distribution of vertices, preventing the texture from stretching. Which, in turn, also mitigates the appearance of the mesh deformations.

Anyway, I would check UVs.

|improve this answer|||||
$\endgroup$
  • 1
    $\begingroup$ "Does each one of your objects have its own UV layout specifically unwrapped for that object?" ..... No, they don't. That seems to be the problem. I'm new to Blender (and graphics, in general) and don't understand UV mapping. I just wishfully thought it will be straightforward. But it seems like I need to do some homework. $\endgroup$ – metsburg Feb 20 '19 at 16:55
  • $\begingroup$ @metsburg It's been a while, but if you're still studying the matter I'd gladly help you get up and running with 3D modeling/texturing. I'd use some knowledge review and explaining the subject to a newcomer would serve the purpose. $\endgroup$ – Steamy_Steve Apr 25 '19 at 13:16

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.