pub struct MeshGradient { /* private fields */ }Expand description
A grid of colored control points blended smoothly across each cell.
Each cell blends its four corner colors in Oklab with smoothstep weights, so color is continuous across cells and flat at every control point. Cell geometry is the bilinear patch of its corner positions; moving control points warps the colors. Alpha interpolates linearly. Authored paints evaluate inverse-bilinear patches independently on CPU/GPU; explicit rasterization retains the tessellated image baking path for existing artwork.
use motion_core::{
Color, MeshGradient, PixelSize, RasterLimits, Rect,
};
let mesh = MeshGradient::grid(2, 2, &[
Color::from_hex(0xff0000), Color::from_hex(0x00ff00),
Color::from_hex(0x0000ff), Color::WHITE,
])?;
let pattern = mesh.pattern(
Rect::new(0.0, 0.0, 64.0, 64.0),
PixelSize::new(16, 16),
4,
RasterLimits::default(),
)?;
assert_eq!(pattern.image.width(), 16);Implementations§
Source§impl MeshGradient
impl MeshGradient
Sourcepub fn new(
columns: u32,
rows: u32,
vertices: Vec<MeshVertex>,
) -> Result<Self, ValidationError>
pub fn new( columns: u32, rows: u32, vertices: Vec<MeshVertex>, ) -> Result<Self, ValidationError>
Creates a mesh from row-major control points.
Requires at least two points per axis, at most MAX_MESH_POINTS_PER_AXIS, and
exactly columns * rows finite vertices.
Sourcepub fn grid(
columns: u32,
rows: u32,
colors: &[Color],
) -> Result<Self, ValidationError>
pub fn grid( columns: u32, rows: u32, colors: &[Color], ) -> Result<Self, ValidationError>
Creates a regular lattice covering the unit square from row-major colors.
Sourcepub fn vertices(&self) -> &[MeshVertex]
pub fn vertices(&self) -> &[MeshVertex]
Row-major control points.
Sourcepub fn patch(&self, column: u32, row: u32) -> Result<MeshPatch, ValidationError>
pub fn patch(&self, column: u32, row: u32) -> Result<MeshPatch, ValidationError>
Creates one admitted analytic patch without allocating an image or lattice.
Rejects out-of-range indices or coordinates/colors outside shared shader support.
Sourcepub fn rasterize(
&self,
size: PixelSize,
subdivisions: u32,
limits: RasterLimits,
) -> Result<MeshImage, ValidationError>
pub fn rasterize( &self, size: PixelSize, subdivisions: u32, limits: RasterLimits, ) -> Result<MeshImage, ValidationError>
Rasterizes the unit square into a size image, splitting every cell edge into
subdivisions pieces. Pixels outside the mesh stay transparent.
Admits pixels, storage and triangle work through limits before allocating.
Sourcepub fn pattern(
&self,
bounds: Rect,
size: PixelSize,
subdivisions: u32,
limits: RasterLimits,
) -> Result<ImagePattern, ValidationError>
pub fn pattern( &self, bounds: Rect, size: PixelSize, subdivisions: u32, limits: RasterLimits, ) -> Result<ImagePattern, ValidationError>
Rasterizes the mesh and maps it onto bounds as an extend-padded bilinear pattern.