Skip to content

Mesh

A Mesh holds vertex data and draw state. Create with Graphics.newMesh or Mesh.new(vertices, drawMode).

Parameters:

  • vertices (List) — List of vertices (e.g. each vertex [x, y, z, r, g, b, a]).
  • drawMode (String) — "triangles", "trianglestrip", "lines", "linestrip", "lineloop", or "points".

Creates a new mesh. Prefer Graphics.newMesh(...) so you can pass a shader.

Parameters:

  • vertices (List) — Full list of vertices. Replaces all existing vertex data.

Replace all vertices in the mesh.

Parameters:

  • vertices (List) — Source list.
  • start (Num) — Start index (0-based).
  • count (Num) — Number of vertices to upload.

Replace a range of vertices from a slice of vertices.

Returns: Num — Number of vertices in the mesh.

var n = _mesh.getVertexCount()
_mesh.setDrawRange(0, n - (n % 3)) // multiple of 3 for triangles

getVertex(index) / setVertex(index, vertex)

Section titled “getVertex(index) / setVertex(index, vertex)”

Returns: (getter) A vertex value (e.g. list of numbers).

Parameters:

  • index (Num) — Vertex index (0-based).
  • vertex (e.g. List) — Vertex data (e.g. [x, y, z, r, g, b, a]).

Get or set a single vertex by index.

getVertexAttribute(index, attribute) / setVertexAttribute(index, attribute, value)

Section titled “getVertexAttribute(index, attribute) / setVertexAttribute(index, attribute, value)”

Returns: (getter) The attribute value (e.g. Num).

Parameters:

  • index (Num) — Vertex index.
  • attribute (String) — Attribute name (e.g. "px", "py", "pz", "r", "g", "b", "a").
  • value (Num) — Value to set.

Get or set a specific vertex attribute. Useful for animating positions or colors without replacing the whole vertex list. Call flush after updates so the GPU sees changes.

_mesh.setVertexAttribute(0, "px", -0.5 + Math.sin(time) * 0.3)
_mesh.setVertexAttribute(0, "r", 0.5 + 0.5 * Math.sin(time))
_mesh.flush()

Returns: (getter) List of indices, or the current vertex map.

Parameters:

  • indices (List) — List of vertex indices (0-based) for indexed drawing.

Get or set the index buffer for indexed drawing (e.g. share vertices across triangles).

_mesh.setVertexMap([0, 1, 2, 0, 2, 3]) // two triangles sharing vertices

Upload any pending vertex or attribute changes to the GPU. Call after setVertexAttribute or setVertices when you want the mesh to reflect updates on the next draw.

for (i in 0...count) {
_mesh.setVertexAttribute(i, "r", r)
}
_mesh.flush()
Graphics.drawMesh(_mesh)

Equivalent to Graphics.drawMesh(this). Draws the mesh with the current vertex range and draw mode.

Returns: (getter) String — Current draw mode.

Parameters:

  • mode (String) — One of "triangles", "trianglestrip", "lines", "linestrip", "lineloop", "points".

getDrawRange() / setDrawRange(start, count) / clearDrawRange()

Section titled “getDrawRange() / setDrawRange(start, count) / clearDrawRange()”

Returns: (getter) Current draw range or null if not set.

Parameters:

  • start (Num) — First vertex index to draw.
  • count (Num) — Number of vertices to draw.

Limit drawing to a subrange of vertices. clearDrawRange() resets to draw all vertices. Useful for revealing geometry over time or drawing a subset.

_mesh.setDrawRange(0, 9) // draw first 10 vertices (e.g. 3 triangles)
_mesh.clearDrawRange() // draw entire mesh