123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- :github_url: hide
- .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
- .. DO NOT EDIT THIS FILE, but the MeshDataTool.xml source instead.
- .. The source is found in doc/classes or modules/<name>/doc_classes.
- .. _class_MeshDataTool:
- MeshDataTool
- ============
- **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
- Helper tool to access and edit :ref:`Mesh<class_Mesh>` data.
- Description
- -----------
- MeshDataTool provides access to individual vertices in a :ref:`Mesh<class_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<class_MeshDataTool_method_create_from_surface>`. When you are finished editing the data commit the data to a mesh with :ref:`commit_to_surface<class_MeshDataTool_method_commit_to_surface>`.
- Below is an example of how MeshDataTool may be used.
- ::
- var mesh = ArrayMesh.new()
- mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, CubeMesh.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.surface_remove(0)
- mdt.commit_to_surface(mesh)
- var mi = MeshInstance.new()
- mi.mesh = mesh
- add_child(mi)
- See also :ref:`ArrayMesh<class_ArrayMesh>`, :ref:`ImmediateGeometry<class_ImmediateGeometry>` and :ref:`SurfaceTool<class_SurfaceTool>` for procedural geometry generation.
- **Note:** Godot uses clockwise `winding order <https://learnopengl.com/Advanced-OpenGL/Face-culling>`__ for front faces of triangle primitive modes.
- Methods
- -------
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`clear<class_MeshDataTool_method_clear>` **(** **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`commit_to_surface<class_MeshDataTool_method_commit_to_surface>` **(** :ref:`ArrayMesh<class_ArrayMesh>` mesh **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`create_from_surface<class_MeshDataTool_method_create_from_surface>` **(** :ref:`ArrayMesh<class_ArrayMesh>` mesh, :ref:`int<class_int>` surface **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`get_edge_count<class_MeshDataTool_method_get_edge_count>` **(** **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`PoolIntArray<class_PoolIntArray>` | :ref:`get_edge_faces<class_MeshDataTool_method_get_edge_faces>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Variant<class_Variant>` | :ref:`get_edge_meta<class_MeshDataTool_method_get_edge_meta>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`get_edge_vertex<class_MeshDataTool_method_get_edge_vertex>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` vertex **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`get_face_count<class_MeshDataTool_method_get_face_count>` **(** **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`get_face_edge<class_MeshDataTool_method_get_face_edge>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` edge **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Variant<class_Variant>` | :ref:`get_face_meta<class_MeshDataTool_method_get_face_meta>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector3<class_Vector3>` | :ref:`get_face_normal<class_MeshDataTool_method_get_face_normal>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`get_face_vertex<class_MeshDataTool_method_get_face_vertex>` **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` vertex **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`get_format<class_MeshDataTool_method_get_format>` **(** **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Material<class_Material>` | :ref:`get_material<class_MeshDataTool_method_get_material>` **(** **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector3<class_Vector3>` | :ref:`get_vertex<class_MeshDataTool_method_get_vertex>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`PoolIntArray<class_PoolIntArray>` | :ref:`get_vertex_bones<class_MeshDataTool_method_get_vertex_bones>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Color<class_Color>` | :ref:`get_vertex_color<class_MeshDataTool_method_get_vertex_color>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`int<class_int>` | :ref:`get_vertex_count<class_MeshDataTool_method_get_vertex_count>` **(** **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`PoolIntArray<class_PoolIntArray>` | :ref:`get_vertex_edges<class_MeshDataTool_method_get_vertex_edges>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`PoolIntArray<class_PoolIntArray>` | :ref:`get_vertex_faces<class_MeshDataTool_method_get_vertex_faces>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Variant<class_Variant>` | :ref:`get_vertex_meta<class_MeshDataTool_method_get_vertex_meta>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector3<class_Vector3>` | :ref:`get_vertex_normal<class_MeshDataTool_method_get_vertex_normal>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Plane<class_Plane>` | :ref:`get_vertex_tangent<class_MeshDataTool_method_get_vertex_tangent>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`get_vertex_uv<class_MeshDataTool_method_get_vertex_uv>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`Vector2<class_Vector2>` | :ref:`get_vertex_uv2<class_MeshDataTool_method_get_vertex_uv2>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`PoolRealArray<class_PoolRealArray>` | :ref:`get_vertex_weights<class_MeshDataTool_method_get_vertex_weights>` **(** :ref:`int<class_int>` idx **)** |const| |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_edge_meta<class_MeshDataTool_method_set_edge_meta>` **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` meta **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_face_meta<class_MeshDataTool_method_set_face_meta>` **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` meta **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_material<class_MeshDataTool_method_set_material>` **(** :ref:`Material<class_Material>` material **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_vertex<class_MeshDataTool_method_set_vertex>` **(** :ref:`int<class_int>` idx, :ref:`Vector3<class_Vector3>` vertex **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_vertex_bones<class_MeshDataTool_method_set_vertex_bones>` **(** :ref:`int<class_int>` idx, :ref:`PoolIntArray<class_PoolIntArray>` bones **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_vertex_color<class_MeshDataTool_method_set_vertex_color>` **(** :ref:`int<class_int>` idx, :ref:`Color<class_Color>` color **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_vertex_meta<class_MeshDataTool_method_set_vertex_meta>` **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` meta **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_vertex_normal<class_MeshDataTool_method_set_vertex_normal>` **(** :ref:`int<class_int>` idx, :ref:`Vector3<class_Vector3>` normal **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_vertex_tangent<class_MeshDataTool_method_set_vertex_tangent>` **(** :ref:`int<class_int>` idx, :ref:`Plane<class_Plane>` tangent **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_vertex_uv<class_MeshDataTool_method_set_vertex_uv>` **(** :ref:`int<class_int>` idx, :ref:`Vector2<class_Vector2>` uv **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_vertex_uv2<class_MeshDataTool_method_set_vertex_uv2>` **(** :ref:`int<class_int>` idx, :ref:`Vector2<class_Vector2>` uv2 **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`set_vertex_weights<class_MeshDataTool_method_set_vertex_weights>` **(** :ref:`int<class_int>` idx, :ref:`PoolRealArray<class_PoolRealArray>` weights **)** |
- +-------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- Method Descriptions
- -------------------
- .. _class_MeshDataTool_method_clear:
- - void **clear** **(** **)**
- Clears all data currently in MeshDataTool.
- ----
- .. _class_MeshDataTool_method_commit_to_surface:
- - :ref:`Error<enum_@GlobalScope_Error>` **commit_to_surface** **(** :ref:`ArrayMesh<class_ArrayMesh>` mesh **)**
- Adds a new surface to specified :ref:`Mesh<class_Mesh>` with edited data.
- ----
- .. _class_MeshDataTool_method_create_from_surface:
- - :ref:`Error<enum_@GlobalScope_Error>` **create_from_surface** **(** :ref:`ArrayMesh<class_ArrayMesh>` mesh, :ref:`int<class_int>` surface **)**
- Uses specified surface of given :ref:`Mesh<class_Mesh>` to populate data for MeshDataTool.
- Requires :ref:`Mesh<class_Mesh>` with primitive type :ref:`Mesh.PRIMITIVE_TRIANGLES<class_Mesh_constant_PRIMITIVE_TRIANGLES>`.
- ----
- .. _class_MeshDataTool_method_get_edge_count:
- - :ref:`int<class_int>` **get_edge_count** **(** **)** |const|
- Returns the number of edges in this :ref:`Mesh<class_Mesh>`.
- ----
- .. _class_MeshDataTool_method_get_edge_faces:
- - :ref:`PoolIntArray<class_PoolIntArray>` **get_edge_faces** **(** :ref:`int<class_int>` idx **)** |const|
- Returns array of faces that touch given edge.
- ----
- .. _class_MeshDataTool_method_get_edge_meta:
- - :ref:`Variant<class_Variant>` **get_edge_meta** **(** :ref:`int<class_int>` idx **)** |const|
- Returns meta information assigned to given edge.
- ----
- .. _class_MeshDataTool_method_get_edge_vertex:
- - :ref:`int<class_int>` **get_edge_vertex** **(** :ref:`int<class_int>` idx, :ref:`int<class_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.
- ----
- .. _class_MeshDataTool_method_get_face_count:
- - :ref:`int<class_int>` **get_face_count** **(** **)** |const|
- Returns the number of faces in this :ref:`Mesh<class_Mesh>`.
- ----
- .. _class_MeshDataTool_method_get_face_edge:
- - :ref:`int<class_int>` **get_face_edge** **(** :ref:`int<class_int>` idx, :ref:`int<class_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.
- ----
- .. _class_MeshDataTool_method_get_face_meta:
- - :ref:`Variant<class_Variant>` **get_face_meta** **(** :ref:`int<class_int>` idx **)** |const|
- Returns the metadata associated with the given face.
- ----
- .. _class_MeshDataTool_method_get_face_normal:
- - :ref:`Vector3<class_Vector3>` **get_face_normal** **(** :ref:`int<class_int>` idx **)** |const|
- Calculates and returns the face normal of the given face.
- ----
- .. _class_MeshDataTool_method_get_face_vertex:
- - :ref:`int<class_int>` **get_face_vertex** **(** :ref:`int<class_int>` idx, :ref:`int<class_int>` vertex **)** |const|
- Returns the specified vertex of the given face.
- Vertex argument must be either 0, 1, or 2 because faces contain three vertices.
- ----
- .. _class_MeshDataTool_method_get_format:
- - :ref:`int<class_int>` **get_format** **(** **)** |const|
- Returns the :ref:`Mesh<class_Mesh>`'s format. Format is an integer made up of :ref:`Mesh<class_Mesh>` format flags combined together. For example, a mesh containing both vertices and normals would return a format of ``3`` because :ref:`ArrayMesh.ARRAY_FORMAT_VERTEX<class_ArrayMesh_constant_ARRAY_FORMAT_VERTEX>` is ``1`` and :ref:`ArrayMesh.ARRAY_FORMAT_NORMAL<class_ArrayMesh_constant_ARRAY_FORMAT_NORMAL>` is ``2``.
- See :ref:`ArrayFormat<enum_ArrayMesh_ArrayFormat>` for a list of format flags.
- ----
- .. _class_MeshDataTool_method_get_material:
- - :ref:`Material<class_Material>` **get_material** **(** **)** |const|
- Returns the material assigned to the :ref:`Mesh<class_Mesh>`.
- ----
- .. _class_MeshDataTool_method_get_vertex:
- - :ref:`Vector3<class_Vector3>` **get_vertex** **(** :ref:`int<class_int>` idx **)** |const|
- Returns the vertex at given index.
- ----
- .. _class_MeshDataTool_method_get_vertex_bones:
- - :ref:`PoolIntArray<class_PoolIntArray>` **get_vertex_bones** **(** :ref:`int<class_int>` idx **)** |const|
- Returns the bones of the given vertex.
- ----
- .. _class_MeshDataTool_method_get_vertex_color:
- - :ref:`Color<class_Color>` **get_vertex_color** **(** :ref:`int<class_int>` idx **)** |const|
- Returns the color of the given vertex.
- ----
- .. _class_MeshDataTool_method_get_vertex_count:
- - :ref:`int<class_int>` **get_vertex_count** **(** **)** |const|
- Returns the total number of vertices in :ref:`Mesh<class_Mesh>`.
- ----
- .. _class_MeshDataTool_method_get_vertex_edges:
- - :ref:`PoolIntArray<class_PoolIntArray>` **get_vertex_edges** **(** :ref:`int<class_int>` idx **)** |const|
- Returns an array of edges that share the given vertex.
- ----
- .. _class_MeshDataTool_method_get_vertex_faces:
- - :ref:`PoolIntArray<class_PoolIntArray>` **get_vertex_faces** **(** :ref:`int<class_int>` idx **)** |const|
- Returns an array of faces that share the given vertex.
- ----
- .. _class_MeshDataTool_method_get_vertex_meta:
- - :ref:`Variant<class_Variant>` **get_vertex_meta** **(** :ref:`int<class_int>` idx **)** |const|
- Returns the metadata associated with the given vertex.
- ----
- .. _class_MeshDataTool_method_get_vertex_normal:
- - :ref:`Vector3<class_Vector3>` **get_vertex_normal** **(** :ref:`int<class_int>` idx **)** |const|
- Returns the normal of the given vertex.
- ----
- .. _class_MeshDataTool_method_get_vertex_tangent:
- - :ref:`Plane<class_Plane>` **get_vertex_tangent** **(** :ref:`int<class_int>` idx **)** |const|
- Returns the tangent of the given vertex.
- ----
- .. _class_MeshDataTool_method_get_vertex_uv:
- - :ref:`Vector2<class_Vector2>` **get_vertex_uv** **(** :ref:`int<class_int>` idx **)** |const|
- Returns the UV of the given vertex.
- ----
- .. _class_MeshDataTool_method_get_vertex_uv2:
- - :ref:`Vector2<class_Vector2>` **get_vertex_uv2** **(** :ref:`int<class_int>` idx **)** |const|
- Returns the UV2 of the given vertex.
- ----
- .. _class_MeshDataTool_method_get_vertex_weights:
- - :ref:`PoolRealArray<class_PoolRealArray>` **get_vertex_weights** **(** :ref:`int<class_int>` idx **)** |const|
- Returns bone weights of the given vertex.
- ----
- .. _class_MeshDataTool_method_set_edge_meta:
- - void **set_edge_meta** **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` meta **)**
- Sets the metadata of the given edge.
- ----
- .. _class_MeshDataTool_method_set_face_meta:
- - void **set_face_meta** **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` meta **)**
- Sets the metadata of the given face.
- ----
- .. _class_MeshDataTool_method_set_material:
- - void **set_material** **(** :ref:`Material<class_Material>` material **)**
- Sets the material to be used by newly-constructed :ref:`Mesh<class_Mesh>`.
- ----
- .. _class_MeshDataTool_method_set_vertex:
- - void **set_vertex** **(** :ref:`int<class_int>` idx, :ref:`Vector3<class_Vector3>` vertex **)**
- Sets the position of the given vertex.
- ----
- .. _class_MeshDataTool_method_set_vertex_bones:
- - void **set_vertex_bones** **(** :ref:`int<class_int>` idx, :ref:`PoolIntArray<class_PoolIntArray>` bones **)**
- Sets the bones of the given vertex.
- ----
- .. _class_MeshDataTool_method_set_vertex_color:
- - void **set_vertex_color** **(** :ref:`int<class_int>` idx, :ref:`Color<class_Color>` color **)**
- Sets the color of the given vertex.
- ----
- .. _class_MeshDataTool_method_set_vertex_meta:
- - void **set_vertex_meta** **(** :ref:`int<class_int>` idx, :ref:`Variant<class_Variant>` meta **)**
- Sets the metadata associated with the given vertex.
- ----
- .. _class_MeshDataTool_method_set_vertex_normal:
- - void **set_vertex_normal** **(** :ref:`int<class_int>` idx, :ref:`Vector3<class_Vector3>` normal **)**
- Sets the normal of the given vertex.
- ----
- .. _class_MeshDataTool_method_set_vertex_tangent:
- - void **set_vertex_tangent** **(** :ref:`int<class_int>` idx, :ref:`Plane<class_Plane>` tangent **)**
- Sets the tangent of the given vertex.
- ----
- .. _class_MeshDataTool_method_set_vertex_uv:
- - void **set_vertex_uv** **(** :ref:`int<class_int>` idx, :ref:`Vector2<class_Vector2>` uv **)**
- Sets the UV of the given vertex.
- ----
- .. _class_MeshDataTool_method_set_vertex_uv2:
- - void **set_vertex_uv2** **(** :ref:`int<class_int>` idx, :ref:`Vector2<class_Vector2>` uv2 **)**
- Sets the UV2 of the given vertex.
- ----
- .. _class_MeshDataTool_method_set_vertex_weights:
- - void **set_vertex_weights** **(** :ref:`int<class_int>` idx, :ref:`PoolRealArray<class_PoolRealArray>` 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.)`
|