Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

I am trying to get vertex positions in an imported mesh, but the results are way off.

Discussion in 'Scripting' started by DevMerlin, Aug 29, 2016.

  1. DevMerlin

    DevMerlin

    Joined:
    Dec 21, 2011
    Posts:
    96
    When I try to collect the array from the mesh, they're off by a huge amount. A vertex located at the start of the object is 0,-0,-0.01 and a vertex located at the end of the object is.. 1, 0, 0.1. This doesn't seem to make any sense.

    These are also -after- the coordinates are transformed into world space.

    For a mesh that is 16 meters long and comprised of 70 points, I would expect vertex 65 to be at 3,0,16.

    This is the code I am using to collect the information.

    Code (CSharp):
    1. CurrentObject=Instantiate(TerrainObjects[0])asTransform;
    2. meshFilter =CurrentObject.GetComponent<MeshFilter>();
    3. vertices = meshFilter.mesh.vertices;CurrentObject.transform.parent = gameObject.transform;//Vector3 EndVectorLocation = transform.InverseTransformDirection(vertices[10]);Debug.Log(transform.TransformPoint(vertices[10]));
    Have I missed something in getting the correct transform positions?
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Vertex order is arbitrary and not necessarily the same between the application the mesh was modeled in and Unity post-import.

    What is it you're trying to achieve?