# How to update the vertices global position after rotation

Hi
I would like to get the global vertices position of a mesh after rotating the gizmo. Is it possible?.
It seems that I’m getting only the local position. And the values do not change after rotation

Here is the playground: Babylon.js Playground

Hi mathus1,

I’m not sure why you’d want to do this, but the way to get those world space positions is to take the vertex positions and multiply them by the world matrix, as shown on lines 39 through 48 of the following.

vertex | Babylon.js Playground (babylonjs.com)

If your goal is just to use those world-space positions for something, I’d definitely recommend using them without setting them on the mesh as that will cause all sorts of other weirdness. If you really do need to set them, though, then you’ll also need to transform the normals by the world matrix, then reset the position and rotation of the object. Definitely simpler to just use the world-space positions without setting them if you can get away with that for your scenario. Hope this helps, and best of luck!

Thank you. What I want to do is to get the global normal vector of only one specific face of the mesh so that every time the mesh is rotated, I can update the normal to apply in the drag behavior class.

I thought that if I have 3 vertices of a face, I can have the normal using the method in Getting normal of a plane - Questions & Answers - HTML5 Game Devs Forum

Is there a better way to update the normal of a mesh face?

If you know the normal in local space, I think you can do this without ever accessing the vertex data at all by just storing the starting normal and transforming it using the world matrix when you need it. The world matrix, to be clear, is something that takes vectors from local space to world space. So if you store the local space normal you’re interested in (which is the same as the world space normal when no rotation is applied to the mesh) in a variable `localSpaceNormal`, calling the following code

``````BABYLON.Vector3.TransformNormal(localSpaceNormal, mesh.getWorldMatrix());
``````

will get you the world space normal each frame you need it. Hope this helps, and best of luck!

2 Likes

Lets consider that I create clones of this mesh in the playground, they all initially have the same normal but when I rotate each one in different angles is it possible to store the new normal for each mesh? or the command mesh.getWorldMatrix() already computes this for me?
Do I have to create a variable “transformed normal” for each mesh?

The short answer is yes, but it might be worthwhile to dig into some more background on transformation matrices in general to understand why. This document was written for D3D 9, but the concepts it discusses apply to pretty much all game engines, including Babylon. (The “Tranforms” page it links to might also be worth a read.) At a high level, every mesh in the scene has a world matrix, and that world matrix pertains to the specific position and orientation of that mesh; but to understand more deeply why that is and what you can do with it, I think those documents might be helpful.

2 Likes