J3D - How to use a UV mapping of an object to convert 2D coordinates to 3D ones

孤者浪人 提交于 2019-12-11 14:26:08

问题


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:

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).


回答1:


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.



来源:https://stackoverflow.com/questions/22688900/j3d-how-to-use-a-uv-mapping-of-an-object-to-convert-2d-coordinates-to-3d-ones

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!