Jump to content

  • Log In with Google      Sign In   
  • Create Account


Texture mapping question


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 yasmin_bd   Members   -  Reputation: 121

Like
0Likes
Like

Posted 16 January 2013 - 11:54 AM

Hi, I posted a question in OpenGL, but as it is a bit beginner's question, i think it is relevant to this topic.

I have a curved shell-like (hollow) cylindrical surface which has been defined in obj file format. Originally obj file does not have texture. I have a jpeg image file which I would like to map to the interior of the curved surface.

Now I know texture (u,v) values range from (0.0, 0.0) to (1.0, 1.0). How can I map (u,v) values to vertices defined in the obj file manually?

 

Please provide some suggestions.

 



Sponsor:

#2 HAM   Members   -  Reputation: 176

Like
0Likes
Like

Posted 18 January 2013 - 03:31 AM

I'm not sure how far along you are on this but I would suggest tackling this step by step.

  1. Forget about obj files and cylinders.
  2. Draw an untextured quad on the screen. (Two triangles forming a square)
    1. Do this manually creating the vertex and index buffers and filling in the vertex data yourself.
  3. Load a texture.  In this case your jpeg.
  4. Now draw the quad with the texture mapped

At this point you will know what you need to deal with your problem. You'll know:

  1. How to deal with vertex and index buffers
  2. How to load an image and create a texture
  3. How to construct the vertex data and set UVs
  4. How to bind the texture and draw textured geometry.

Once you know all that, then all you have to do is find where the obj file is loaded and when it creates the vertex data from it.  Once you know that you can write your UVs into that data.  You may have to change the vertex type and declaration.  Then your last challenge would be to figure out the math to get your UVs correct.

 

However, even though I think you would learn alot from doing this I wouldn't suggest changing or adding UVs in this way.  I'm sure the obj file format can store your UVs and you should probably be setting up the UVs in the modeling package that exported the obj file.  

 

For simple shapes like boxes, quads, cylinders, spheres, I would suggest not using an obj file at all.  Create them yourself in code, if for no other reason other than to familiarize yourself with how to construct them and manipulate them.  

 

You would need this knowledge if you then wanted to go back and start manipulating the data from the obj file.


Edited by HAM, 18 January 2013 - 03:33 AM.


#3 BarrySkellern   Members   -  Reputation: 645

Like
1Likes
Like

Posted 18 January 2013 - 06:29 AM

In general any point on the surface of the cylinder (radius not being relevant here) can be uniquely identified by two numbers: the distance along the axis of the cylinder and the angle around the cylinder. Those coordinates will range from 0 to the length of the cylinder, and 0 to 2*pi in angle. If you scale them both by dividing by the relevant range you will get two coordinates running from 0 to 1. Those could be used as your texture coordinates to sample the image. You will need to make a choice of which end of the cylinder is the "bottom" (i.e. the end at u=0) and what angle should be the "seam" (i.e. at v=0 and v=2*pi). Notice that the angle coordinates will repeat at this seam, so your texture will have to repeat in the corresponding direction so as not to display a visible discontinuity.

 

For more info, see e.g. http://en.wikipedia.org/wiki/Cylindrical_coordinate_system

 

Hope that helps.


Edited by BarrySkellern, 18 January 2013 - 06:30 AM.

Visit http://www.mugsgames.com - Just released: Stroids, a retro style mini-game for Windows PC.

Mugs Games on Twitter: @MugsGames and Facebook: www.facebook.com/mugsgames

Me on Twitter @BarrySkellern

 


#4 yasmin_bd   Members   -  Reputation: 121

Like
0Likes
Like

Posted 18 January 2013 - 10:17 AM

Actually I was thinking whether the texture image can be mapped in a different way. The image can be divided into a number of contours as shown in the figure. Then grdually map it along the depth of the tube to get look alike effect. Can texture be mapped in that way?

 

 

 

Attached Thumbnails

  • texture_map_along_depth.jpg


#5 BarrySkellern   Members   -  Reputation: 645

Like
0Likes
Like

Posted 19 January 2013 - 01:19 AM

Hi Yasmin - sorry, I'd like to try to be more help but that picture has lost me a bit I'm afraid!

 

I think maybe you're thinking of an unconventional mapping of the image such that the middle of the image is the origin, and a point on the cylinder (z, w) where z is the distance from an end (normalized to 0,1 range) and w is the angle around the cylinder, will map directly to a point (r, a) in the image where r is the distance from the middle and a is the angle relative to, say, the +x axis.

 

While that is a valid mapping, it suffers one significant issue: the area of the cylinder surface that a given image pixel maps to is massively different depending on the value of z, the distance along the cylinder. In effect, for large z (i.e. at one end of the cylinder) you will get a high resolution texture *around* the cylinder, while at low z (the other end, mapping to the centre of the image) you will have a very low res texture. In the limit, the end of the cylinder at z=0 will have no angular resolution because all those points map to the same image pixel regardless of angle.

 

Anyway, sorry if I've completely misunderstood your image. In general, for consistent results across a model you should usually prefer texture mappings that are close to isotropic and constant resolution.


Visit http://www.mugsgames.com - Just released: Stroids, a retro style mini-game for Windows PC.

Mugs Games on Twitter: @MugsGames and Facebook: www.facebook.com/mugsgames

Me on Twitter @BarrySkellern

 





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS