:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/4.2/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/MeshDataTool.xml. .. _class_MeshDataTool: MeshDataTool ============ **Inherits:** :ref:`RefCounted` **<** :ref:`Object` Helper tool to access and edit :ref:`Mesh` data. .. rst-class:: classref-introduction-group Description ----------- MeshDataTool provides access to individual vertices in a :ref:`Mesh`. It allows users to read and edit vertex data of meshes. It also creates an array of faces and edges. To use MeshDataTool, load a mesh with :ref:`create_from_surface`. When you are finished editing the data commit the data to a mesh with :ref:`commit_to_surface`. Below is an example of how MeshDataTool may be used. .. tabs:: .. code-tab:: gdscript var mesh = ArrayMesh.new() mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, BoxMesh.new().get_mesh_arrays()) var mdt = MeshDataTool.new() mdt.create_from_surface(mesh, 0) for i in range(mdt.get_vertex_count()): var vertex = mdt.get_vertex(i) # In this example we extend the mesh by one unit, which results in separated faces as it is flat shaded. vertex += mdt.get_vertex_normal(i) # Save your change. mdt.set_vertex(i, vertex) mesh.clear_surfaces() mdt.commit_to_surface(mesh) var mi = MeshInstance.new() mi.mesh = mesh add_child(mi) .. code-tab:: csharp var mesh = new ArrayMesh(); mesh.AddSurfaceFromArrays(Mesh.PrimitiveType.Triangles, new BoxMesh().GetMeshArrays()); var mdt = new MeshDataTool(); mdt.CreateFromSurface(mesh, 0); for (var i = 0; i < mdt.GetVertexCount(); i++) { Vector3 vertex = mdt.GetVertex(i); // In this example we extend the mesh by one unit, which results in separated faces as it is flat shaded. vertex += mdt.GetVertexNormal(i); // Save your change. mdt.SetVertex(i, vertex); } mesh.ClearSurfaces(); mdt.CommitToSurface(mesh); var mi = new MeshInstance(); mi.Mesh = mesh; AddChild(mi); See also :ref:`ArrayMesh`, :ref:`ImmediateMesh` and :ref:`SurfaceTool` for procedural geometry generation. \ **Note:** Godot uses clockwise `winding order `__ for front faces of triangle primitive modes. .. rst-class:: classref-introduction-group Tutorials --------- - :doc:`Using the MeshDataTool <../tutorials/3d/procedural_geometry/meshdatatool>` .. rst-class:: classref-reftable-group Methods ------- .. table:: :widths: auto +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`clear` **(** **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`commit_to_surface` **(** :ref:`ArrayMesh` mesh, :ref:`int` compression_flags=0 **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`create_from_surface` **(** :ref:`ArrayMesh` mesh, :ref:`int` surface **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_edge_count` **(** **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedInt32Array` | :ref:`get_edge_faces` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`get_edge_meta` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_edge_vertex` **(** :ref:`int` idx, :ref:`int` vertex **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_face_count` **(** **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_face_edge` **(** :ref:`int` idx, :ref:`int` edge **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`get_face_meta` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector3` | :ref:`get_face_normal` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_face_vertex` **(** :ref:`int` idx, :ref:`int` vertex **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_format` **(** **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Material` | :ref:`get_material` **(** **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector3` | :ref:`get_vertex` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedInt32Array` | :ref:`get_vertex_bones` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Color` | :ref:`get_vertex_color` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_vertex_count` **(** **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedInt32Array` | :ref:`get_vertex_edges` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedInt32Array` | :ref:`get_vertex_faces` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`get_vertex_meta` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector3` | :ref:`get_vertex_normal` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Plane` | :ref:`get_vertex_tangent` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_vertex_uv` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_vertex_uv2` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedFloat32Array` | :ref:`get_vertex_weights` **(** :ref:`int` idx **)** |const| | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_edge_meta` **(** :ref:`int` idx, :ref:`Variant` meta **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_face_meta` **(** :ref:`int` idx, :ref:`Variant` meta **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_material` **(** :ref:`Material` material **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_vertex` **(** :ref:`int` idx, :ref:`Vector3` vertex **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_vertex_bones` **(** :ref:`int` idx, :ref:`PackedInt32Array` bones **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_vertex_color` **(** :ref:`int` idx, :ref:`Color` color **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_vertex_meta` **(** :ref:`int` idx, :ref:`Variant` meta **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_vertex_normal` **(** :ref:`int` idx, :ref:`Vector3` normal **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_vertex_tangent` **(** :ref:`int` idx, :ref:`Plane` tangent **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_vertex_uv` **(** :ref:`int` idx, :ref:`Vector2` uv **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_vertex_uv2` **(** :ref:`int` idx, :ref:`Vector2` uv2 **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | void | :ref:`set_vertex_weights` **(** :ref:`int` idx, :ref:`PackedFloat32Array` weights **)** | +-----------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_MeshDataTool_method_clear: .. rst-class:: classref-method void **clear** **(** **)** Clears all data currently in MeshDataTool. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_commit_to_surface: .. rst-class:: classref-method :ref:`Error` **commit_to_surface** **(** :ref:`ArrayMesh` mesh, :ref:`int` compression_flags=0 **)** Adds a new surface to specified :ref:`Mesh` with edited data. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_create_from_surface: .. rst-class:: classref-method :ref:`Error` **create_from_surface** **(** :ref:`ArrayMesh` mesh, :ref:`int` surface **)** Uses specified surface of given :ref:`Mesh` to populate data for MeshDataTool. Requires :ref:`Mesh` with primitive type :ref:`Mesh.PRIMITIVE_TRIANGLES`. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_edge_count: .. rst-class:: classref-method :ref:`int` **get_edge_count** **(** **)** |const| Returns the number of edges in this :ref:`Mesh`. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_edge_faces: .. rst-class:: classref-method :ref:`PackedInt32Array` **get_edge_faces** **(** :ref:`int` idx **)** |const| Returns array of faces that touch given edge. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_edge_meta: .. rst-class:: classref-method :ref:`Variant` **get_edge_meta** **(** :ref:`int` idx **)** |const| Returns meta information assigned to given edge. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_edge_vertex: .. rst-class:: classref-method :ref:`int` **get_edge_vertex** **(** :ref:`int` idx, :ref:`int` vertex **)** |const| Returns index of specified vertex connected to given edge. Vertex argument can only be 0 or 1 because edges are comprised of two vertices. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_face_count: .. rst-class:: classref-method :ref:`int` **get_face_count** **(** **)** |const| Returns the number of faces in this :ref:`Mesh`. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_face_edge: .. rst-class:: classref-method :ref:`int` **get_face_edge** **(** :ref:`int` idx, :ref:`int` edge **)** |const| Returns specified edge associated with given face. Edge argument must be either 0, 1, or 2 because a face only has three edges. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_face_meta: .. rst-class:: classref-method :ref:`Variant` **get_face_meta** **(** :ref:`int` idx **)** |const| Returns the metadata associated with the given face. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_face_normal: .. rst-class:: classref-method :ref:`Vector3` **get_face_normal** **(** :ref:`int` idx **)** |const| Calculates and returns the face normal of the given face. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_face_vertex: .. rst-class:: classref-method :ref:`int` **get_face_vertex** **(** :ref:`int` idx, :ref:`int` vertex **)** |const| Returns the specified vertex index of the given face. Vertex argument must be either 0, 1, or 2 because faces contain three vertices. \ **Example:**\ .. tabs:: .. code-tab:: gdscript var index = mesh_data_tool.get_face_vertex(0, 1) # Gets the index of the second vertex of the first face. var position = mesh_data_tool.get_vertex(index) var normal = mesh_data_tool.get_vertex_normal(index) .. code-tab:: csharp int index = meshDataTool.GetFaceVertex(0, 1); // Gets the index of the second vertex of the first face. Vector3 position = meshDataTool.GetVertex(index); Vector3 normal = meshDataTool.GetVertexNormal(index); .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_format: .. rst-class:: classref-method :ref:`int` **get_format** **(** **)** |const| Returns the :ref:`Mesh`'s format. Format is an integer made up of :ref:`Mesh` format flags combined together. For example, a mesh containing both vertices and normals would return a format of ``3`` because :ref:`Mesh.ARRAY_FORMAT_VERTEX` is ``1`` and :ref:`Mesh.ARRAY_FORMAT_NORMAL` is ``2``. See :ref:`ArrayFormat` for a list of format flags. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_material: .. rst-class:: classref-method :ref:`Material` **get_material** **(** **)** |const| Returns the material assigned to the :ref:`Mesh`. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_vertex: .. rst-class:: classref-method :ref:`Vector3` **get_vertex** **(** :ref:`int` idx **)** |const| Returns the position of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_vertex_bones: .. rst-class:: classref-method :ref:`PackedInt32Array` **get_vertex_bones** **(** :ref:`int` idx **)** |const| Returns the bones of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_vertex_color: .. rst-class:: classref-method :ref:`Color` **get_vertex_color** **(** :ref:`int` idx **)** |const| Returns the color of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_vertex_count: .. rst-class:: classref-method :ref:`int` **get_vertex_count** **(** **)** |const| Returns the total number of vertices in :ref:`Mesh`. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_vertex_edges: .. rst-class:: classref-method :ref:`PackedInt32Array` **get_vertex_edges** **(** :ref:`int` idx **)** |const| Returns an array of edges that share the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_vertex_faces: .. rst-class:: classref-method :ref:`PackedInt32Array` **get_vertex_faces** **(** :ref:`int` idx **)** |const| Returns an array of faces that share the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_vertex_meta: .. rst-class:: classref-method :ref:`Variant` **get_vertex_meta** **(** :ref:`int` idx **)** |const| Returns the metadata associated with the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_vertex_normal: .. rst-class:: classref-method :ref:`Vector3` **get_vertex_normal** **(** :ref:`int` idx **)** |const| Returns the normal of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_vertex_tangent: .. rst-class:: classref-method :ref:`Plane` **get_vertex_tangent** **(** :ref:`int` idx **)** |const| Returns the tangent of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_vertex_uv: .. rst-class:: classref-method :ref:`Vector2` **get_vertex_uv** **(** :ref:`int` idx **)** |const| Returns the UV of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_vertex_uv2: .. rst-class:: classref-method :ref:`Vector2` **get_vertex_uv2** **(** :ref:`int` idx **)** |const| Returns the UV2 of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_vertex_weights: .. rst-class:: classref-method :ref:`PackedFloat32Array` **get_vertex_weights** **(** :ref:`int` idx **)** |const| Returns bone weights of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_set_edge_meta: .. rst-class:: classref-method void **set_edge_meta** **(** :ref:`int` idx, :ref:`Variant` meta **)** Sets the metadata of the given edge. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_set_face_meta: .. rst-class:: classref-method void **set_face_meta** **(** :ref:`int` idx, :ref:`Variant` meta **)** Sets the metadata of the given face. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_set_material: .. rst-class:: classref-method void **set_material** **(** :ref:`Material` material **)** Sets the material to be used by newly-constructed :ref:`Mesh`. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_set_vertex: .. rst-class:: classref-method void **set_vertex** **(** :ref:`int` idx, :ref:`Vector3` vertex **)** Sets the position of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_set_vertex_bones: .. rst-class:: classref-method void **set_vertex_bones** **(** :ref:`int` idx, :ref:`PackedInt32Array` bones **)** Sets the bones of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_set_vertex_color: .. rst-class:: classref-method void **set_vertex_color** **(** :ref:`int` idx, :ref:`Color` color **)** Sets the color of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_set_vertex_meta: .. rst-class:: classref-method void **set_vertex_meta** **(** :ref:`int` idx, :ref:`Variant` meta **)** Sets the metadata associated with the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_set_vertex_normal: .. rst-class:: classref-method void **set_vertex_normal** **(** :ref:`int` idx, :ref:`Vector3` normal **)** Sets the normal of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_set_vertex_tangent: .. rst-class:: classref-method void **set_vertex_tangent** **(** :ref:`int` idx, :ref:`Plane` tangent **)** Sets the tangent of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_set_vertex_uv: .. rst-class:: classref-method void **set_vertex_uv** **(** :ref:`int` idx, :ref:`Vector2` uv **)** Sets the UV of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_set_vertex_uv2: .. rst-class:: classref-method void **set_vertex_uv2** **(** :ref:`int` idx, :ref:`Vector2` uv2 **)** Sets the UV2 of the given vertex. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_set_vertex_weights: .. rst-class:: classref-method void **set_vertex_weights** **(** :ref:`int` idx, :ref:`PackedFloat32Array` weights **)** Sets the bone weights of the given vertex. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)` .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)` .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`