Class Mesh

Mesh class for initializing and storing mesh vertices.

Provides functionality for creating, manipulating, and rendering 3D mesh geometry with support for custom vertex formats and transformations.

Functions

mesh.generate_indices (count, template) Generate indices for quadrilateral primitives.
mesh.get_attribute_index (attribute, format) Gets the attribute index from the vertex format.
mesh.set_locations (vertexformat, used_locations) Assigns location indices to vertex format attributes.

Fields

mesh.lg_mesh Underlying LOVE Mesh object used for rendering.
mesh.vertexformat Vertex format specification used by this mesh.
mesh.material_index Material index.
mesh.bound Cached bounding box of the mesh geometry.
mesh.used_locations Location mapping table for vertex attributes.
mesh.vertex_attribute_index Index of the VertexPosition attribute in the vertex format.

Methods

mesh:init (primitive) The public constructor.
mesh:draw (material) Renders the mesh using the specified material.
mesh:get_bound () Gets the bounding box of the mesh.
mesh:get_vertex_count () Gets the total number of vertices in the mesh.
mesh:get_vertex_attribute (name, index[, out]) Gets a specific vertex attribute value by name and vertex index.
mesh:get_triangles_transform (matrix) Gets all triangles from the mesh with transformation applied.
mesh:get_triangles () Creates a cached array of triangles from the mesh vertices.
mesh:get_vertices ([start=1[, count]]) Gets an array of mesh vertices as an array.
mesh:get_vertices_transform (matrix[, start=1[, count]]) Gets transformed vertex positions as an array.
mesh:get_vertex_map () Gets the vertex index mapping of the mesh.
mesh:set_vertices (vertices, startvertex) Updates mesh vertices with new data.
mesh:apply_matrix (matrix) Applies a transformation matrix to all mesh vertex positions.


Functions

mesh.generate_indices (count, template)
Generate indices for quadrilateral primitives.

Parameters:

  • count number Count of vertices
  • template table Template list that is used to generate indices in a specific sequence
mesh.get_attribute_index (attribute, format)
Gets the attribute index from the vertex format. Searches for a specific vertex attribute by name in the vertex format table.

Parameters:

  • attribute string The attribute name to find (e.g., "VertexPosition", "VertexNormal")
  • format table Vertex format table containing attribute definitions

Returns:

    number or nil The index of the attribute, or nil if not found
mesh.set_locations (vertexformat, used_locations)
Assigns location indices to vertex format attributes. Ensures each vertex attribute has a unique location for shader binding.

Parameters:

  • vertexformat table Vertex format table to process
  • used_locations table Optional table of already used location indices

Returns:

    table,table Modified vertex format and updated used locations table

Fields

mesh.lg_mesh
Underlying LOVE Mesh object used for rendering.
  • lg_mesh love.Mesh
mesh.vertexformat
Vertex format specification used by this mesh.
mesh.material_index
Material index.
  • material_index number
mesh.bound
Cached bounding box of the mesh geometry.
mesh.used_locations
Location mapping table for vertex attributes.
mesh.vertex_attribute_index
Index of the VertexPosition attribute in the vertex format.
  • vertex_attribute_index number

Methods

mesh:init (primitive)
The public constructor. Initializes a mesh with vertices, optional indices, vertex format, etc.

Parameters:

  • primitive Table containing mesh data with following fields:
    • vertices table Array of vertex data
    • vertexformat table Vertex format specification (uses default if not provided) (optional)
    • indices table Index array for vertex mapping (optional)
    • mode string Drawing mode (default: "triangles") (optional)
    • count number Vertex count override (optional)
    • material_index number Material index (optional)
    • indices_tsize number Index data type size (optional)
mesh:draw (material)
Renders the mesh using the specified material.

Parameters:

  • material menori.Material The material to use when drawing the mesh
mesh:get_bound ()
Gets the bounding box of the mesh.

Returns:

    bound3 Axis-aligned bounding box
mesh:get_vertex_count ()
Gets the total number of vertices in the mesh.

Returns:

    number Vertex count
mesh:get_vertex_attribute (name, index[, out])
Gets a specific vertex attribute value by name and vertex index.

Parameters:

  • name string Attribute name (e.g., "VertexPosition", "VertexNormal")
  • index number Vertex index
  • out table Output table to store results (optional)

Returns:

    table Table containing the attribute values
mesh:get_triangles_transform (matrix)
Gets all triangles from the mesh with transformation applied.

Parameters:

  • matrix mat4 Transformation matrix to apply to vertices

Returns:

    table Array of triangles in format {{{x, y, z}, {x, y, z}, {x, y, z}}, ...}
mesh:get_triangles ()
Creates a cached array of triangles from the mesh vertices.

Returns:

    table Array of triangles in format {{{x, y, z}, {x, y, z}, {x, y, z}}, ...}
mesh:get_vertices ([start=1[, count]])
Gets an array of mesh vertices as an array.

Parameters:

  • start number Starting vertex index (default 1)
  • count number Number of vertices to retrieve (defaults to all remaining) (optional)

Returns:

    table Array of vertices, where each vertex is a table of attribute components
mesh:get_vertices_transform (matrix[, start=1[, count]])
Gets transformed vertex positions as an array.

Parameters:

  • matrix mat4 Transformation matrix to apply
  • start number Starting vertex index (default 1)
  • count number Number of vertices to retrieve (defaults to all remaining) (optional)

Returns:

    table Array of vertices, where each vertex is a table of attribute components
mesh:get_vertex_map ()
Gets the vertex index mapping of the mesh.

Returns:

    table or nil Index array if present, nil otherwise
mesh:set_vertices (vertices, startvertex)
Updates mesh vertices with new data.

Parameters:

  • vertices table Array of vertices, where each vertex is a table of attribute components
  • startvertex number The vertex index from which insertion will start
mesh:apply_matrix (matrix)
Applies a transformation matrix to all mesh vertex positions. Permanently modifies the mesh geometry by transforming all vertex positions.

Parameters:

  • matrix mat4 Transformation matrix to apply to vertex positions
generated by LDoc 1.5.0 Last updated 2025-08-18 00:01:40