Skip to content
fill_mesh_shaded

fill_mesh_shaded

Mojo function 🡭

fill_mesh_shaded

fn def fill_mesh_shaded(mut canvas: Canvas, points: List[FPoint], faces: List[Int], vertex_colors: List[Color])

fill_mesh with a color per vertex, interpolated across each face: a smoothly shaded surface rather than a faceted one (#426). Everything else is fill_mesh’s – seam-free shared edges, painter’s order, the transform, recording as one op – and a face whose three corners share a color draws exactly as fill_mesh draws it.

Interpolation is barycentric, in the canvas’s color space: SRGB mixes the stored bytes, LINEAR mixes linear light and encodes back, the same rule source-over follows, so a smooth face agrees with the same face drawn as many flat faces at intermediate colors. A different name rather than an overload, because a color per vertex and a color per face are the same type and only their counts differ, and a call whose meaning depends on a count is a call that changes meaning when the mesh does.

Args:

  • canvas (Canvas): Canvas to draw on.
  • points (List[FPoint]): The vertices, in the canvas’s coordinates.
  • faces (List[Int]): Index triples into points, one triangle each, in draw order.
  • vertex_colors (List[Color]): One color per vertex, same count as points.

Raises:

Error: faces is not whole triples, an index is out of range, or vertex_colors is not one per vertex.