- Home /
Transform vertex to word space
how i can transform mesh vertex to world space and then draw it ?
Mesh m = GetComponent<MeshFilter>().mesh;
Vector3 []vertices = m.vertices; Vector3 []normals = m.normals;
// Draw first 10 vertices with normals in world space
for(int i = 0;i < 10;i++) { Debug.DrawRay(transform.TransformPoint(vertices[i]), transform.TransformDirection(normals[i]) * 5); }
meaning how can I display the selected vertices in the model ?
Answer by Peter G · Feb 21, 2011 at 01:01 PM
Just add the vertex to the object position.
Vector3 realPos = vertexPos + transform.position;
That won't work if you rotate the object... that's why there is the function transform.TransformPoint() it converts from local to worldspace.
I know. His code should have already done that so I don't know why he needed help. If he really wants to do it manually though, he can just multiply each point by transform.rotation before adding in the object position.
Answer by Bunny83 · Feb 21, 2011 at 03:03 PM
I really don't get your question... your code already does this...
Vector3 wPos = transform.TransformPoint(vertices[i]);
TransformPoint transformes a point from local coordinates to world coordinates wit respect to the transforms position/rotation/scale.
Your answer
![](https://koobas.hobune.stream/wayback/20220613105459im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is there a way to make a script do something every time a new level loads? 1 Answer
Simple LOD script problem (switching mesh at runtime) 1 Answer
Importing animations and objects from Blender to Unity. 2 Answers
Trying to rotate a tower after instantiate 2 Answers
getting dx9 error. happened overnight 0 Answers