TriangleMesh

class TriangleMesh(val maxVertices: Int = 4096, val maxIndices: Int = maxVertices * 6)

A batch of triangles with a colour at every corner, drawn in a single call.

Compose draws paths, and a tunnel drawn as paths reads as a wire frame because it is one. This fills the space between the lines instead. Each corner carries its own colour and the graphics card blends between them across the face, so lighting worked out once per corner comes out smooth over the whole surface. A few thousand triangles cost one call, where the same number of filled paths would cost a few thousand.

Build it once and reuse it: clear at the start of every frame, add corners with vertex, join them with triangle or quad, then hand it to drawMesh. Nothing is allocated after the first frame unless the number of triangles grows to a size the mesh has not drawn before.

Constructors

Link copied to clipboard
constructor(maxVertices: Int = 4096, maxIndices: Int = maxVertices * 6)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun clear()
Link copied to clipboard
fun TriangleMesh.glow(x: Float, y: Float, radius: Float, argb: Int, sides: Int = 6)

Adds a soft round spot: a fan of triangles in full colour at the middle and clear at the rim.

Link copied to clipboard
fun TriangleMesh.glyph(kind: Int, x: Float, y: Float, size: Float, turn: Float, argb: Int)

One of four small marks, turned by turn: 0 a cross, 1 a diamond, 2 a chevron, 3 a dash.

Link copied to clipboard
fun TriangleMesh.polygon(x: Float, y: Float, radius: Float, sides: Int, turn: Float, argb: Int, rim: Int = argb)

A filled regular polygon turned by turn radians: argb in the middle, rim at the corners.

Link copied to clipboard
fun quad(a: Int, b: Int, c: Int, d: Int)

Two triangles covering four corners given in order round the edge.

Link copied to clipboard
fun TriangleMesh.ring(x: Float, y: Float, radius: Float, thickness: Float, argb: Int, sides: Int = 24)

A ring thickness wide, in one colour, as a band of sides quads.

Link copied to clipboard
fun TriangleMesh.shard(x: Float, y: Float, length: Float, turn: Float, argb: Int)

A thin sliver like a shard of glass, length long, turned by turn.

Link copied to clipboard
fun TriangleMesh.spark(x: Float, y: Float, length: Float, width: Float, argb: Int)

A four pointed spark: two narrow diamonds crossed, bright in the middle and clear at the tips.

Link copied to clipboard
fun TriangleMesh.streak(tailX: Float, tailY: Float, headX: Float, headY: Float, width: Float, argb: Int)

A streak from a clear tail to a bright head, width wide at the head.

Link copied to clipboard
fun TriangleMesh.strip(xs: FloatArray, ys: FloatArray, count: Int, width: Float, argb: Int)

A wide line through the first count points of xs and ys.

Link copied to clipboard
fun triangle(a: Int, b: Int, c: Int)

Joins three corners. Quietly skipped when any of them does not exist or the mesh is full.

Link copied to clipboard
fun vertex(x: Float, y: Float, argb: Int): Int

Adds a corner and answers its number, or -1 when the mesh is full. argb is packed colour.