Mesh

fun FilamentSceneScope.Mesh(material: MaterialInstance?, positions: FloatArray, normals: FloatArray, uvs: FloatArray, indices: IntArray, position: Position = Position(0f), rotation: Rotation = Rotation.Identity, scale: Scale = Scale(1f), pivot: Position = Position(0f), boundingBox: Box? = null, visible: Boolean = true, castShadows: Boolean = true, receiveShadows: Boolean = true, onCreate: EntityScope.() -> Unit = {})

Renders a custom triangle mesh from raw vertex data — the escape hatch for geometry the built-in primitives (Cube, Sphere, Plane, Cylinder) don't cover (procedural terrain, generated meshes, imported non-glTF geometry).

Vertices are non-interleaved: positions (xyz triples), normals (xyz triples), and uvs (uv pairs) are parallel arrays addressed by indices (a flat list of triangle corner indices, 3 per triangle). The tangent frame Filament's LIT shaders need is derived automatically from the normals, UVs, and topology — supply correct normals and UVs.

Geometry arrays are compared by content: re-creating identical arrays on recomposition is safe (no GPU re-upload); changing any element re-uploads the buffers and rebuilds the renderable. Still prefer remember-ing large arrays to skip the comparison cost.

Mesh(
material = myMaterial,
positions = floatArrayOf(/* x,y,z, … */),
normals = floatArrayOf(/* x,y,z, … */),
uvs = floatArrayOf(/* u,v, … */),
indices = intArrayOf(0, 1, 2, /* … */),
)

Parameters

material

Material applied to the whole mesh, or null while it is still loading.

positions

Vertex positions as xyz triples. Length must be a multiple of 3.

normals

Per-vertex normals as xyz triples. Must match positions in length.

uvs

Per-vertex UVs as uv pairs. Length must be 2 * vertexCount.

indices

Triangle indices (32-bit). Length must be a multiple of 3.

position

World-space position of the pivot point.

rotation

World-space rotation. Build one with Rotation.axisAngle/Rotation.euler.

scale

Per-axis scale.

pivot

Mesh-space point that rotation/scale revolve around and that ends up at position. Defaults to the mesh origin.

boundingBox

AABB used for frustum culling. Defaults to one computed from positions. Provide an explicit box if you skip culling or animate vertices beyond the static bounds.

visible

Whether this renderable is in the scene. False removes it from the scene (cheaply, keeping the entity alive) — a show/hide toggle without losing state.

castShadows

Whether the mesh casts shadows onto other renderables. On by default.

receiveShadows

Whether the mesh receives shadows cast by others. On by default.

onCreate

Runs once when the mesh enters the scene, with the renderable entity and engine in scope (EntityScope) — use it to register the mesh with view.pick callbacks or other entity-keyed maps.