Search Unity

vertex world position

Discussion in 'Scripting' started by raoul, Dec 29, 2007.

  1. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    I can´t figure out how to get the world position of vertices returned by mesh.vertices? Anyone knows how to do this?

    Many thanks,
    Raoul
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Try adding the vertices position and the mesh's transform's position together. Possibly something like:

    Code (csharp):
    1. function Start ()
    2. {
    3.     var verticies : Vector3[] = GetComponent (MeshFilter).mesh.vertices;
    4.     var globalPos : Vector3 = verticies [0] + transform.position;
    5.     Debug.Log (globalPos.ToString ());
    6. }
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unfortunately that method doesn't account for rotation. What you want is MultiplyPoint...check out the MeshCombineUtility script in Standard Assets for an example of usage. Although normally you can use MultiplyPoint3x4 which does pretty much the same thing, but faster.

    --Eric
     
  4. raoul

    raoul

    Joined:
    Jul 14, 2007
    Posts:
    6,735
    Yes, I tried that Daniel but it fails as soon as you rotate the object (as Eric also posted). I will look at MultiplyPoint, thanks guys!