Mesh
Description
Section titled “Description”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.
Example
Section titled “Example”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]);
import { Mesh, Vertex } from "fragmentcolor";
const mesh = new Mesh();mesh.addVertex([0.0, 0.5, 0.0]);mesh.addVertex([-0.5, -0.5, 0.0]);mesh.addVertex([0.5, -0.5, 0.0]);
from fragmentcolor import Mesh, Vertex
mesh = Mesh()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])
// Swift placeholder: bindings WIP
// Kotlin placeholder: bindings WIP
Methods
Section titled “Methods”Mesh::new
Section titled “Mesh::new”Create an empty mesh.
Example
Section titled “Example”use fragmentcolor::mesh::Mesh;let m = Mesh::new();1 collapsed line
_ = m;
import { Mesh } from "fragmentcolor";const m = new Mesh();
from fragmentcolor import Meshm = Mesh()
// Swift placeholder: bindings WIP
// Kotlin placeholder: bindings WIP
Mesh::from_vertices
Section titled “Mesh::from_vertices”Create a mesh from an iterator of Vertex values.
Example
Section titled “Example”use fragmentcolor::Mesh;
let mesh = Mesh::from_vertices([ [0.0, 0.0], [1.0, 0.0], [0.0, 1.0],]);
import { Mesh } from "fragmentcolor";
const mesh = Mesh.fromVertices([ [0.0, 0.0], [1.0, 0.0], [0.0, 1.0],]);
from fragmentcolor import Mesh
mesh = Mesh.from_vertices([ [0.0, 0.0], [1.0, 0.0], [0.0, 1.0],])
// Swift placeholder: bindings WIP
// Kotlin placeholder: bindings WIP
Mesh::add_vertex
Section titled “Mesh::add_vertex”Add a single vertex to the mesh.
Example
Section titled “Example”use fragmentcolor::mesh::{Mesh};let mut m = Mesh::new();m.add_vertex([0.0, 0.0]);
import { Mesh } from "fragmentcolor";const m = new Mesh();m.addVertex([0.0, 0.0]);
from fragmentcolor import Meshm = Mesh()m.add_vertex([0.0, 0.0])
// Swift placeholder: bindings WIP
// Kotlin placeholder: bindings WIP
Mesh::add_vertices
Section titled “Mesh::add_vertices”Add many vertices to the mesh.
Example
Section titled “Example”use fragmentcolor::mesh::Mesh;let mut m = Mesh::new();m.add_vertices([[0.0, 0.0],[1.0, 0.0],]);
import { Mesh } from "fragmentcolor";const m = new Mesh();m.addVertices([[0.0, 0.0],[1.0, 0.0],]);
from fragmentcolor import Meshm = Mesh()m.add_vertices([[0.0, 0.0],[1.0, 0.0],])
// Swift placeholder: bindings WIP
// Kotlin placeholder: bindings WIP
Mesh::add_instance
Section titled “Mesh::add_instance”Add a single instance (any Vertex can be converted into an instance).
Example
Section titled “Example”use fragmentcolor::mesh::{Mesh, Vertex};let mut m = Mesh::new();let v = Vertex::new([0.0, 0.0]);m.add_instance(v);
import { Mesh, Vertex } from "fragmentcolor";const m = new Mesh();const v = new Vertex([0.0, 0.0]);m.addInstance(v);
from fragmentcolor import Mesh, Vertexm = Mesh()v = Vertex([0.0, 0.0])m.add_instance(v)
// Swift placeholder: bindings WIP
// Kotlin placeholder: bindings WIP
Mesh::add_instances
Section titled “Mesh::add_instances”Add many instances to the mesh.
Example
Section titled “Example”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]),]);
import { Mesh, Vertex } from "fragmentcolor";const m = new Mesh();m.addInstances([Vertex.new([0.0, 0.0]),Vertex.new([1.0, 1.0]),]);
from fragmentcolor import Mesh, Vertexm = Mesh()m.add_instances([Vertex([0.0, 0.0]),Vertex([1.0, 1.0]),])
// Swift placeholder: bindings WIP
// Kotlin placeholder: bindings WIP
Mesh::clear_instances
Section titled “Mesh::clear_instances”Remove all instances from a mesh (render defaults to 1 instance).
Example
Section titled “Example”use fragmentcolor::mesh::Mesh;let mut m = Mesh::new();m.clear_instances();
import { Mesh } from "fragmentcolor";const m = new Mesh();m.clearInstances();
from fragmentcolor import Meshm = Mesh()m.clear_instances()
// Swift placeholder: bindings WIP
// Kotlin placeholder: bindings WIP
Mesh::set_instance_count
Section titled “Mesh::set_instance_count”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).
Example
Section titled “Example”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 instancesm.set_instance_count(1_000_000);
import { Mesh } from "fragmentcolor";const m = new Mesh();m.addVertices([ [-0.01, -0.01], [ 0.01, -0.01], [ 0.00, 0.01],]);// draw one million instancesm.setInstanceCount(1_000_000);
from fragmentcolor import Meshm = Mesh()m.add_vertices([ [-0.01, -0.01], [ 0.01, -0.01], [ 0.00, 0.01],])# draw one million instancesm.set_instance_count(1_000_000)
// Swift placeholder: bindings WIP
// Kotlin placeholder: bindings WIP
Mesh::clear_instance_count
Section titled “Mesh::clear_instance_count”Remove all instances from a mesh (render defaults to 1 instance).
Example
Section titled “Example”use fragmentcolor::mesh::Mesh;let mut m = Mesh::new();m.clear_instance_count();
import { Mesh } from "fragmentcolor";const m = new Mesh();m.clearInstanceCount();
from fragmentcolor import Meshm = Mesh()m.clear_instance_count()
// Swift placeholder: bindings WIP
// Kotlin placeholder: bindings WIP