I want to calculate the corresponding position in 3d space(world space), for a position from uv space.
EDIT:
I want to find the world space position corresponding to a point in uv space( not screen space ) for an arbitrary geometry. I’m considering the simplest case, when there’s only one point corresponding to a point in uvspace(ie no overlapping uvs).
For example:
I have a texture that’s entirely black except for a single pixel that’s white. I apply this texture on a geometry i created in a 3d modeling package(Maya, 3ds max etc ), that has the UVs unfolded with no tiling and no overlaping. How can i calculate the coordinates in 3d space for the point on the geometry, where the white pixel is displayed ?
There’s no built-in function for this, because in the general case (not the specific example you’re giving):
Any one UV coordinate could be mapped to multiple polygons on a single mesh. (So there could be multiple object-space coordinates for a single UV coordinate)
There could be multiple models using that mesh in the scene. (So there could be multiple world-space coordinates for a single object-space coordinate)
I think the only way you can get this information is to use the Mesh class. You would need to iterate over every triangle in the mesh (or just the submesh(es) you need), and check whether the triangle formed by its vertices’ UV coordinates contains the UV point in which you’re interested.
Once you find a triangle that contains the point, you can find its position in object space by interpolating the vertices’ spatial coordinates, using the barycentric position of the UV coordinate within the UV triangle.
Then you’d transform it using the GameObject’s Transform to finally get it into world space.
Note that this doesn’t take animation into account.
I'm sorry i didn't make myself clear enough. I am aware of the Camera.ScreenToWorldPoint method, but what i want is different. I did search the forums and Unityanswers but didn't find anything. I want to find the world space position corresponding to a point in uv space( not screen space ) for an arbitrary geometry. This point might have a position in uvspace outside of the 0-1 interval that the screenspace allows( ex. [2.3 ; 1.4] ). I'm considering the simplest case, when there's only one point corresponding to a point in uvspace(ie no overlapping uvs).
I edited my first post with a simplified case of what i'm trying to calculate. I'm trying to use this concept for a gameplay mechanic that's way more complex and harder to explain , but the essence is there.
The question makes perfect sense. He wants to get the 3D world space coordinate of a texel on the surface of a polygon. I actually have a use for this myself. I was thinking especially in your case you could use a custom shader--since you know the color you are looking for.
I'm sorry i didn't make myself clear enough. I am aware of the Camera.ScreenToWorldPoint method, but what i want is different. I did search the forums and Unityanswers but didn't find anything. I want to find the world space position corresponding to a point in uv space( not screen space ) for an arbitrary geometry. This point might have a position in uvspace outside of the 0-1 interval that the screenspace allows( ex. [2.3 ; 1.4] ). I'm considering the simplest case, when there's only one point corresponding to a point in uvspace(ie no overlapping uvs).
– nikudyI edited my first post with a simplified case of what i'm trying to calculate. I'm trying to use this concept for a gameplay mechanic that's way more complex and harder to explain , but the essence is there.
– nikudyThe question makes perfect sense. He wants to get the 3D world space coordinate of a texel on the surface of a polygon. I actually have a use for this myself. I was thinking especially in your case you could use a custom shader--since you know the color you are looking for.
– quitebutterythe question is clear enough, what's your problem to direct to the documentation?
– RendergonPolygons