Mesh:positions
methodMesh:positions() -> number[]Vertex positions as flat x,y,z triplets in node-local space.
handle6 methods, 2 fields
A primitive node's mutable mesh, returned by node:mesh(). Reads are snapshot copies as flat arrays; update writes one validated, atomic batch. scene:raycast follows edits; a physics body keeps the primitive's own shape, fixed when the body is added.
SceneNode:meshThe examples on this page start from:
local scene = datumhue.scene.new({ width = 320, height = 240 })
scene:mount({ width = 320, height = 240 })
scene:directional_light({ direction = datumhue.math.vec3(-1, -2, -1) })
local mesh = scene:plane({ subdivisions = 8 }):mesh()| Field | Type | Access | Description |
|---|---|---|---|
vertex_count | integer | read-only | Number of vertices in the mesh. |
index_count | integer | read-only | Number of triangle indices; 0 for a non-indexed mesh. |
Mesh:positions() -> number[]Vertex positions as flat x,y,z triplets in node-local space.
Mesh:normals() -> number[]Vertex normals as flat x,y,z triplets; empty when the mesh has none.
Mesh:uvs() -> number[]Texture coordinates as flat u,v pairs; empty when the mesh has none.
Mesh:colors() -> number[]Vertex colors as flat r,g,b,a quads; empty when the mesh has none.
Mesh:indices() -> integer[]1-based triangle indices; empty for a non-indexed mesh.
Mesh:update(opts: scene.MeshUpdateOptions)Apply one batch of attribute writes atomically: the whole batch is validated against the post-update state (one agreed vertex count, indices in range, budget respected) and nothing is written on any violation.
-- Flat x, y, z triplets in the node's own space: lift y along a wave.
local pos = mesh:positions()
for i = 1, #pos, 3 do
pos[i + 1] = 0.1 * math.sin(pos[i] * 10)
end
mesh:update({ positions = pos, recompute_normals = true })
print(#pos, mesh.vertex_count) --> 300 100opts scene.MeshUpdateOptions options 6 keys Omitted keys keep their current value.
| Key | Type | Description |
|---|---|---|
| positions | number[] | Flat x,y,z triplets in node-local space; sets the vertex count. |
| normals | number[] | Flat x,y,z triplets; one per vertex. |
| uvs | number[] | Flat u,v pairs; one per vertex. |
| colors | number[] | Flat r,g,b,a quads (0..1); one per vertex. |
| indices | integer[] | 1-based triangle indices, length divisible by 3. An empty array makes the mesh non-indexed (vertex-order triangles). |
| recompute_normals | boolean | Recompute vertex normals after the other fields apply (smooth when indexed, flat otherwise). Mutually exclusive with normals. |