How to get global transform of a vertex?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi. Silly question… Using the MeshDataTool I can get a vertex’s position (formerly: translation) via get_vertex().
How do I convert that position into a global transform??

:bust_in_silhouette: Reply From: Zylann

Global according to what?
When you get a vertex from a mesh with MeshDataTool, you get the vertex relative to the model. There is no other “coordinate space” to reason with because a model alone has no parent or anything, it’s just a model.

You can, however, transform it if you want the global position the vertex would have, if it was set on a MeshInstance3D for example (I assume this is what you meant?).
In which case, you can do mesh_instance_node.global_transform * vertex_position and it gives you the global position.

I’m having to assume because your question lacks details, but if you meant the global transform including the basis (orientation based on normals and tangents, not just the global position), then you’d have to obtain the normal and tangent too. In which case it would be mesh_instance.global_transform * Transform3D(Basis(tangent, normal, bitangent), vertex_position).