Using the MeshDataTool

    The MeshDataTool is not as fast as altering arrays directly using ArrayMesh. However, it provides more information and tools to work with meshes than the ArrayMesh does. When the MeshDataTool is used, it calculates mesh data that is not available in ArrayMeshes such as faces and edges, which are necessary for certain mesh algorithms. If you do not need this extra information then it may be better to use an ArrayMesh.

    Note

    MeshDataTool can only be used on Meshes that use the PrimitiveType .

    As an example, let’s walk through the process of deforming the mesh generated in the .

    Assume the mesh is stored in an ArrayMesh named mesh. We then initialize the MeshDataTool from mesh by calling . If there is already data initialized in the MeshDataTool calling create_from_surface() will clear it for you. Alternatively, you can call clear() yourself before re-using the MeshDataTool

    uses the vertex arrays from the ArrayMesh to calculate two additional arrays, one for edges and one for faces.

    An edge is a connection between any two vertices. Each edge in the edge array contains a reference to the two vertices it is composed of, and up to two faces that it is contained within.

    A face is a triangle made up of three vertices and three corresponding edges. Each face in the face array contains a reference to the three triangles and three edges it is composed of.

    The vertex array contains edges, faces, normals, color, tangent, uv, uv2, bones, and weight information connected with each vertex.

    To access information from these arrays you use a function of the form get_****():

    What you choose to do with these functions is up to you. A common use case is to iterate over all vertices and transform them in some way:

    GDScript

    Finally, commit_to_surface() adds a new surface to the ArrayMesh. So if you are dynamically updating an existing ArrayMesh, first delete the existing surface before adding a new one.

    GDScript

    Below is a complete example that creates a pulsing blob complete with new normals and vertex colors.