DistortionMesh class

Polynomial radial distortion for VR lens correction. Based on Google Cardboard SDK distortion algorithm.

Uses a pre-computed mesh grid to warp the rendered image to counteract the lens barrel distortion of VR headsets.

Constructors

DistortionMesh({List<double> coefficients = const [0.441, 0.156], int resolution = 40, double screenToLensDistance = 0.042, double interLensDistance = 0.06})
DistortionMesh.cardboardV1()
Google Cardboard V1 preset.
factory
DistortionMesh.cardboardV2()
Google Cardboard V2 preset.
factory
DistortionMesh.none()
No distortion (flat).
factory

Properties

coefficients List<double>
Distortion coefficients (K1, K2, ...).
final
distortedPoints List<Offset>
Pre-computed distorted UV coordinates.
latefinal
hashCode int
The hash code for this object.
no setterinherited
indices List<int>
latefinal
interLensDistance double
Inter-lens distance in meters.
final
originalPoints List<Offset>
latefinal
resolution int
Grid resolution (default 40x40 like Cardboard SDK).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
screenToLensDistance double
Screen-to-lens distance in meters.
final

Methods

applyToCanvas(Canvas canvas, Size viewportSize, {bool isLeftEye = true}) → void
Draws the distortion mesh on a canvas as a wireframe grid (for debug).
distort(double nx, double ny) Offset
Applies polynomial radial distortion.
distortionFactor(double rSquared) double
drawDistortedImage(Canvas canvas, Image image, Size viewportSize, {Matrix4? atwTransform, bool enableChromaticAberration = false}) → void
Warps a rendered offline Image onto the target canvas using the pre-computed distortion mesh. Supports atwTransform matrix for Asynchronous Time Warp and enableChromaticAberration for correcting lens chromatic dispersion via multi-pass RGB blend.
inverseDistort(double radius) double
Computes inverse distortion using Secant method. Given a distorted radius, finds the undistorted radius.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited