0

I am currently working on trying to convert 2D coordinates to 3D ones. Basically, I have the texture in 2D and I would like to be able to show on a 3D object, having the same texture applied to it, where I am pointing at.

Let's say I have the 2D texture of the world. I would like to be able to know, given U,V coordinates on the texture, to get the X,Y,Z coordinates on a sphere having the same texture applied to it.

I am using J3D and now I am working with blender and figure out what is the best way to tackle this problem.

Any idea?

EDIT:

Here is a graphical idea of what I am trying to achieve: enter image description here

You get (X,Y) coordinates of a point on a 2D texture and, thanks to some function, get and visualize where it would be if it was placed on a 3D object (I define both the mapping and the object itself).

N3sh
  • 881
  • 8
  • 37

1 Answers1

0

I'm not a J3D user not I've used it ever before, I've used these in Blender and OpenGL, so I think I can attempt this question.

I think you are having some trouble understanding texturing in 3D. You will not generate the vertices from the UV coordinates, you will use the UV coordinates (which I call texCoords for clarity) on the vertices to apply the textures to them. If you don't know how to do UV mapping in blender, you can watch my video here.

Then you have some steps as specified in this tutorial.

First, you need to create a polygon. Hoping that you know it already, skipping it here. Then set the texture coordinates onto that polygon like this.

polygon1.setTextureCoordinate (0, new Point2f(u1, v1));
polygon1.setTextureCoordinate (1, new Point2f(u2, v2)); 
polygon1.setTextureCoordinate (2, new Point2f(u3, v3));
polygon1.setTextureCoordinate (3, new Point2f(u4, v4));

Assuming that the coordinates are in UV (Some also call them ST).

Then you load the texture image using the TextureLoader class.

Texture texImage = new TextureLoader("brick.jpg", this).getTexture();

Then set it on the appearance using it's setTexture() method. And that's it.

Hope this helps.

Sri Harsha Chilakapati
  • 11,744
  • 6
  • 50
  • 91
  • I will try to follow your suggestions, thanks. But, just to clarify, I need to be able to send X,Y coordinates to a function (coordinates related to a 2D image) and it returns X,Y,Z coordinates, which represent the location of that point on the texture when applied to the object. Basically, I am looking for a way to create a 2D matrix returning 3D coordinates. Let's say I click on the city of London (in the 2D image), I should be able to have a small pointer in the 3D object, where London is located on that object. – N3sh Mar 27 '14 at 13:45
  • @N3sh Could you clarify a bit more? Do you want to be able to select an object in the 3d space by clicking on its texture or what? – Sri Harsha Chilakapati Mar 27 '14 at 14:48