Expand description
A software rasterizer for 3D model thumbnails, as Eagle makes them at import: the model is drawn in the viewer’s home view on a 1080 square with a transparent background, the empty border is cropped away and 40 transparent pixels are added on every side.
The view is the viewer’s: Y up, the eye in direction (-1.5, 2, 3) from the
centre of the bounding sphere, 45 degrees of vertical field of view, at
the distance where the sphere fills the view. Lighting is
geom::shade with the light at the eye.
Triangles are filled with fixed-point edge functions (a consistent tie-break rule, so shared edges leave neither cracks nor double hits) into a 2x supersampled z-buffer, which is then box-filtered down with premultiplied alpha so the silhouette is antialiased.
Textured meshes sample their picture per pixel (texture::Texture::sample,
bilinear in linear light) at perspective-correct coordinates; pixels
below a texture’s alpha cutoff are left out. Normal, bump and emissive
maps are read at the same coordinates (geom::normal_mapped,
geom::bumped).
See-through meshes are drawn after the rest, farthest first, each one’s back faces and then its front faces, and write depth as they go: what Eagle’s viewer (three.js) and the app’s shader do.
Triangles with any vertex nearer than the near plane are skipped rather
than clipped: the fitted camera keeps the whole bounding sphere in front
of the eye (the near plane is at most d - 2r), so nothing is lost.
Constants§
- CANVAS
- Side of the square Eagle renders models on.
- PADDING
- Transparent border added around the cropped render.
Functions§
- render
- Draws
modelon a transparentsizexsizeimage. - render_
view - Draws
meshesas the viewer shows them: awxhpicture through the camera matrixvp(projection times view, clip depth 0..1), lit fromto_eye(unit, towards the camera), meshes without a colour indefault_color, on a transparent background. The viewer’s snapshot.render_view_linesadds the viewer’s lines. - render_
view_ lines render_viewwith line segments drawn over the faces, each in its colour, about a pixel wide and hidden where a face is in front of them (the edges, grid and axes the viewer shows).- thumbnail
- Eagle’s import thumbnail of the 3D file at
path: the render on aCANVASsquare, trimmed and padded byPADDING.Nonewhen the file can’t be read as a model or shows nothing. - trim_
and_ pad - Crops
imgto the bounding box of its pixels with alpha above 0 and addspadtransparent pixels on every side;Nonewhen nothing is visible.