Skip to content

Mesh

High-level geometry container. A Mesh owns a list of vertices and optional instances. Internally it deduplicates vertices and always draws indexed and instanced (instance_count defaults to 1 when none are provided).

Vertex layouts are managed by the Shader. At render time, inputs declared in your shader’s vertex function (annotated with @location(N)) are derived from the source and matched by name and type to Mesh properties across both streams (instance first, then vertex).

Mapping is driven by shader reflection; there are no special-case names or reserved locations. The renderer matches attributes by explicit location if provided (instance first, then vertex), and otherwise by name.

If a required input cannot be found or its type does not match, rendering returns an error indicating the missing attribute or mismatch.

use fragmentcolor::mesh::{Mesh, Vertex, VertexValue};
let mut mesh = Mesh::new();
mesh.add_vertex([0.0, 0.5, 0.0]);
mesh.add_vertex([-0.5, -0.5, 0.0]);
mesh.add_vertex([0.5, -0.5, 0.0]);

Create an empty mesh.

use fragmentcolor::mesh::Mesh;
let m = Mesh::new();
1 collapsed line
_ = m;

Create a mesh from an iterator of Vertex values.

use fragmentcolor::Mesh;
let mesh = Mesh::from_vertices([
[0.0, 0.0],
[1.0, 0.0],
[0.0, 1.0],
]);

Add a single vertex to the mesh.

use fragmentcolor::mesh::{Mesh};
let mut m = Mesh::new();
m.add_vertex([0.0, 0.0]);

Add many vertices to the mesh.

use fragmentcolor::mesh::Mesh;
let mut m = Mesh::new();
m.add_vertices([
[0.0, 0.0],
[1.0, 0.0],
]);

Add a single instance (any Vertex can be converted into an instance).

use fragmentcolor::mesh::{Mesh, Vertex};
let mut m = Mesh::new();
let v = Vertex::new([0.0, 0.0]);
m.add_instance(v);

Add many instances to the mesh.

use fragmentcolor::mesh::{Mesh, Vertex};
let mut m = Mesh::new();
m.add_instances([
Vertex::new([0.0, 0.0]),
Vertex::new([1.0, 1.0]),
]);

Remove all instances from a mesh (render defaults to 1 instance).

use fragmentcolor::mesh::Mesh;
let mut m = Mesh::new();
m.clear_instances();

Override how many instances to draw without providing per-instance attributes.

Use this when driving instance data from a storage buffer and indexing via @builtin(instance_index).

use fragmentcolor::mesh::Mesh;
let mut m = Mesh::new();
m.add_vertices([
[-0.01, -0.01],
[ 0.01, -0.01],
[ 0.00, 0.01],
]);
// draw one million instances
m.set_instance_count(1_000_000);

Remove all instances from a mesh (render defaults to 1 instance).

use fragmentcolor::mesh::Mesh;
let mut m = Mesh::new();
m.clear_instance_count();