:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/master/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`\ (\ mesh\: :ref:`ArrayMesh`, compression_flags\: :ref:`int` = 0\ ) | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Error` | :ref:`create_from_surface`\ (\ mesh\: :ref:`ArrayMesh`, surface\: :ref:`int`\ ) | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_edge_count`\ (\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedInt32Array` | :ref:`get_edge_faces`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`get_edge_meta`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_edge_vertex`\ (\ idx\: :ref:`int`, vertex\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_face_count`\ (\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_face_edge`\ (\ idx\: :ref:`int`, edge\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`get_face_meta`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector3` | :ref:`get_face_normal`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_face_vertex`\ (\ idx\: :ref:`int`, vertex\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_format`\ (\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Material` | :ref:`get_material`\ (\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector3` | :ref:`get_vertex`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedInt32Array` | :ref:`get_vertex_bones`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Color` | :ref:`get_vertex_color`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_vertex_count`\ (\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedInt32Array` | :ref:`get_vertex_edges`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedInt32Array` | :ref:`get_vertex_faces`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`get_vertex_meta`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector3` | :ref:`get_vertex_normal`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Plane` | :ref:`get_vertex_tangent`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_vertex_uv`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Vector2` | :ref:`get_vertex_uv2`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`PackedFloat32Array` | :ref:`get_vertex_weights`\ (\ idx\: :ref:`int`\ ) |const| | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_edge_meta`\ (\ idx\: :ref:`int`, meta\: :ref:`Variant`\ ) | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_face_meta`\ (\ idx\: :ref:`int`, meta\: :ref:`Variant`\ ) | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_material`\ (\ material\: :ref:`Material`\ ) | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_vertex`\ (\ idx\: :ref:`int`, vertex\: :ref:`Vector3`\ ) | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_vertex_bones`\ (\ idx\: :ref:`int`, bones\: :ref:`PackedInt32Array`\ ) | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_vertex_color`\ (\ idx\: :ref:`int`, color\: :ref:`Color`\ ) | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_vertex_meta`\ (\ idx\: :ref:`int`, meta\: :ref:`Variant`\ ) | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_vertex_normal`\ (\ idx\: :ref:`int`, normal\: :ref:`Vector3`\ ) | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_vertex_tangent`\ (\ idx\: :ref:`int`, tangent\: :ref:`Plane`\ ) | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_vertex_uv`\ (\ idx\: :ref:`int`, uv\: :ref:`Vector2`\ ) | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_vertex_uv2`\ (\ idx\: :ref:`int`, uv2\: :ref:`Vector2`\ ) | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`set_vertex_weights`\ (\ idx\: :ref:`int`, weights\: :ref:`PackedFloat32Array`\ ) | +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ .. rst-class:: classref-section-separator ---- .. rst-class:: classref-descriptions-group Method Descriptions ------------------- .. _class_MeshDataTool_method_clear: .. rst-class:: classref-method |void| **clear**\ (\ ) :ref:`🔗` 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**\ (\ mesh\: :ref:`ArrayMesh`, compression_flags\: :ref:`int` = 0\ ) :ref:`🔗` 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**\ (\ mesh\: :ref:`ArrayMesh`, surface\: :ref:`int`\ ) :ref:`🔗` 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| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`, vertex\: :ref:`int`\ ) |const| :ref:`🔗` 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| :ref:`🔗` 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**\ (\ idx\: :ref:`int`, edge\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`, vertex\: :ref:`int`\ ) |const| :ref:`🔗` Returns the specified vertex index of the given face. \ ``vertex`` must be either ``0``, ``1``, or ``2`` because faces contain three vertices. .. 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| :ref:`🔗` Returns the :ref:`Mesh`'s format as a combination of the :ref:`ArrayFormat` flags. 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``. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_get_material: .. rst-class:: classref-method :ref:`Material` **get_material**\ (\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`\ ) |const| :ref:`🔗` 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**\ (\ idx\: :ref:`int`, meta\: :ref:`Variant`\ ) :ref:`🔗` 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**\ (\ idx\: :ref:`int`, meta\: :ref:`Variant`\ ) :ref:`🔗` Sets the metadata of the given face. .. rst-class:: classref-item-separator ---- .. _class_MeshDataTool_method_set_material: .. rst-class:: classref-method |void| **set_material**\ (\ material\: :ref:`Material`\ ) :ref:`🔗` 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**\ (\ idx\: :ref:`int`, vertex\: :ref:`Vector3`\ ) :ref:`🔗` 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**\ (\ idx\: :ref:`int`, bones\: :ref:`PackedInt32Array`\ ) :ref:`🔗` 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**\ (\ idx\: :ref:`int`, color\: :ref:`Color`\ ) :ref:`🔗` 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**\ (\ idx\: :ref:`int`, meta\: :ref:`Variant`\ ) :ref:`🔗` 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**\ (\ idx\: :ref:`int`, normal\: :ref:`Vector3`\ ) :ref:`🔗` 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**\ (\ idx\: :ref:`int`, tangent\: :ref:`Plane`\ ) :ref:`🔗` 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**\ (\ idx\: :ref:`int`, uv\: :ref:`Vector2`\ ) :ref:`🔗` 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**\ (\ idx\: :ref:`int`, uv2\: :ref:`Vector2`\ ) :ref:`🔗` 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**\ (\ idx\: :ref:`int`, weights\: :ref:`PackedFloat32Array`\ ) :ref:`🔗` 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.)` .. |void| replace:: :abbr:`void (No return value.)`