Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to reproduce a textured head in Mathematica, and I'm using a kind of 'net' of a head which contains all the features on the face. The texture looks like this: enter image description here

which is supposed to look something like this:enter image description here

Here's the code I'm using.

ListSurfacePlot3D[Import["inputImage.obj", "VertexData"], 
PlotStyle -> Texture[texture], Mesh -> None, MaxPlotPoints -> 80, 
TextureCoordinateFunction -> ({#1, -#2, #3} &)]

which gives meenter image description here

Another problem is that the texture is reflected about the origin (ie the face is plastered on the back of the head as well). It should instead be black on the back of the head mesh. I suppose this is suppose to do with the head being centered at the origin. I also need to have the texture to 'follow' the head when I change the coordinates of the mesh later on.

I have attempted using

Graphics3D[
 {EdgeForm[],
  Texture[texture],
  GraphicsComplex[mesh,
   Polygon[polygon, VertexTextureCoordinates -> mesh]]}]

but it gives me this instead

enter image description here

I need to be able to reproduce this in Mathematica as I have some coordinate transformations which I need to apply, and thereafter, 'wrap' the mesh with the texture. Are these possible?

EDIT: The link to the model is located https://www.dropbox.com/s/3elv96e8mfodzou/fit_9D0F8093-5566-4EE4-88A7-00070C1D6305.zip

EDIT 2: I've tried converting the OBJ to PLY and I did this

Import["inputImage.ply", "UserExtensions"][[2]]
Import["inputImage.ply", "UserExtensions"][[3]]

which gave an output of

"texture_u" -> {..}
"texture_v" -> {..}

where .. was a bunch of numbers which had a Length of 3066 for both. My guess was that these are texture coordinates (where u is horizontal and v is vertical) as per the links provided by Rahul Narain.

I attempted to create a list of coordinates from these two list in the following manner

texturecoord = {Import["inputImage.ply", "UserExtensions"][[2]][[2]], 
   Import["inputImage.ply", "UserExtensions"][[3]][[2]]} // Transpose

Then, I tried doing

Graphics3D[
 {EdgeForm[],
  Texture[texture],
  GraphicsComplex[mesh,
   Polygon[polygon, VertexTextureCoordinates -> mesh]]}]

But that gives me this

enter image description here

share|improve this question
1  
Could you link to the texture and the face model as well? –  rm -rf Oct 16 '13 at 18:14
3  
ListSurfacePlot3D is quite appropriate for Halloween. That face is.... scary. –  István Zachar Oct 16 '13 at 22:09
    
I've added a link at the bottom. –  user10035 Oct 17 '13 at 1:52
1  
The problem is that the mesh in the OBJ file comes equipped with texture coordinates, but Mathematica throws them away when importing it. Thus it is not possible to correctly map the texture on the imported mesh, unless you write your own OBJ parser that retains the texture coordinates. Fortunately the OBJ file format is quite easy to parse, but someone with more free time than me should do it. –  Rahul Narain Oct 17 '13 at 23:55
    
I could convert it to PLY, would that help? –  user10035 Oct 19 '13 at 17:38
add comment

1 Answer

Not sure if this helps, but if you play with the texture function coordinates and change the lighting you can get something that looks reasonable:

ListSurfacePlot3D[
 Import["inputImage.obj", "VertexData"], 
 PlotStyle -> Texture[texture], Mesh -> None, MaxPlotPoints -> 80, 
 TextureCoordinateFunction -> (If[#3 > 0.3, {0.7 #1 + 0.15, -#2 - 0.06}, {0.5, 0.9}] &), 
 Lighting -> "Neutral"]

Change the 0.3 if you need more or less of the back colored black.

Mathematica graphics

Mathematica graphics

enter image description here

share|improve this answer
    
I have decided to make a switch to using Graphics3D, because it is computationally more efficient and I do not have to worry about rough edges. VertexTextureCoordinate is to GraphicsComplex as what TextureCoordinateFunction is to ListSurfacePlot3D. The main difference is that VertexTextureCoordinate uses a series of vertices as I understand it, to match the texture coordinate to the surface. Do you have any suggestions as to how I could tweak this code? `Graphics3D[ {EdgeForm[], Texture[texture], GraphicsComplex[mesh, Polygon[polygon, VertexTextureCoordinates -> mesh]]}] –  user10035 Oct 18 '13 at 8:24
    
I require an exact mapping. Would that be possible? –  user10035 Oct 21 '13 at 10:04
    
@user10035 See the comment of Rahul above. –  Sjoerd C. de Vries Oct 21 '13 at 10:31
    
I've converted the format to .PLY and managed to extract the texture coordinates and replotted the mesh as seen in the second edit in my original post. However, it still doesn't seem to work. Any insights on this? –  user10035 Oct 22 '13 at 10:53
    
@user10035 I would love to dive into this, but unfortunately don't have time to do that at this moment. –  Sjoerd C. de Vries Oct 22 '13 at 11:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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