Search Unity

Get position of vertices in Unity from 2D texture.

Discussion in 'Scripting' started by sorawit2000y2k, May 22, 2023.

  1. sorawit2000y2k

    sorawit2000y2k

    Joined:
    May 22, 2023
    Posts:
    1
    Hey guy,

    I have 3D (.obj) file and texture file (.png).
    .obj file have
    v (vertices), vn (vertices normalize), vt (vertices texture), f (face/triangles)
    .png is image texture of that 3D file.

    I import both of them into Unity using Meshfilter for .obj and Mesh Renderer for texture file .png.

    Then I create annotation on .png file, output look like {[(x,y), (x,y), (x,y), (x,y), (x,y),], text = "a"}
    Is it possible to know the 3D position of annotations inside Unity?

    What I'm trying so far.
    1. I match the position of texture file to 3D file according to face, ex (x,y) = (0.3, 0.6) -> (-1.5, 0.8, -2.8).
    I try using this 3D position inside Unity but the position do not connect to surface of mesh file, mean the 3D position isn't correct.
    2. I try using only index and access the vertices index inside Unity, the position from vertices connect to surface of mesh file but do not close to character a on the mesh file. This mean my vertices index is incorrect.

    To sum up,
    I want to create function to translate vec2d position in texture file to vec3d position in unity.

    If anyone have other idea please tell me.
     
  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,105
    I don't see you mentioning UV coordinates. You do know how textures work in 3D right?
     
    Bunny83 likes this.
  3. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,990
    This had been asked several times in the past. This one was about 10 years ago. So there's not necessarily a 1-to-1 mapping beween UV / texture coordinates and worldspace coordinates. It depends on the actual mesh and how it's mapped in texture space.