- Go 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
Bumps the github-actions group with 1 update: [actions/setup-go](https://github.com/actions/setup-go).
Updates `actions/setup-go` from 7.0.0 to 7.1.0
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](
|
||
| .github | ||
| docs | ||
| examples | ||
| internal/cmd/genimages | ||
| .gitignore | ||
| .golangci.yml | ||
| animation.go | ||
| animation_test.go | ||
| bounds.go | ||
| bounds_test.go | ||
| clip.go | ||
| clip_test.go | ||
| depth_of_field.go | ||
| depth_of_field_test.go | ||
| doc.go | ||
| edges.go | ||
| edges_test.go | ||
| gallery_test.go | ||
| gif.go | ||
| gif_palette.go | ||
| gif_test.go | ||
| go.mod | ||
| go.sum | ||
| import.go | ||
| import_benchmark_test.go | ||
| import_test.go | ||
| LICENSE | ||
| lines.go | ||
| lines_test.go | ||
| mesh.go | ||
| mesh_benchmark_test.go | ||
| mesh_render_cache.go | ||
| mesh_render_cache_test.go | ||
| orbit.go | ||
| orbit_test.go | ||
| pyramid_test.go | ||
| README.md | ||
| render.go | ||
| render_benchmark_test.go | ||
| render_test.go | ||
| scene.go | ||
| scene_test.go | ||
| section.go | ||
| section_annotate.go | ||
| section_paint.go | ||
| section_raster.go | ||
| section_test.go | ||
solidlens
solidlens is a pure-Go, headless raster renderer for triangle meshes. It
loads STL, 3MF, and OBJ files, accepts *decad.Mesh through TriangleSource,
and renders a configured scene to an image.RGBA or PNG stream.
The scene owns the camera, model materials, directional and point lights, and background. The renderer owns only output dimensions, so it is safe to call concurrently with independent scenes.
Install
go get github.com/lestrrat-3d/solidlens
API
Use ReadMesh when the filename selects the import format, or call
ReadSTL, Read3MF, or ReadOBJ directly. Read3MF uses
github.com/lestrrat-go/3mf, including build transforms, components, and
model units. ReadSTL uses github.com/lestrrat-go/stl.
Use MeshFrom for native geometry. *decad.Mesh satisfies TriangleSource
without an adapter because it provides Vertices() []r3.Vec and
Triangles() [][3]int.
Build a Scene with Camera, Model, Material, DirectionalLight,
PointLight, and Background, then call Render or RenderPNG. Mesh
coordinates are treated as millimetres.
Set Model.Edges to draw lines along a model's edges. Edges carries
Enabled, Color, and a Width in pixels, and it is off by default.
Outline fills in the usual values for a given color. An edge is drawn when
it borders the mesh, when the two faces meeting there differ by at least
CreaseAngle degrees, or when it lies on the model's silhouette, so a
tessellated curve keeps its outline without turning into a grid of facets. A
negative CreaseAngle draws every shared edge, which gives a full wireframe.
A facet narrower than half a pixel at the model's distance does not turn its
neighbours' shared edge into a crease, so the gaps and slivers a CAD kernel
leaves between smooth faces draw no line. A face built from many such facets,
such as a flat flank cut into long needles, is wider than half a pixel as a
whole, so it keeps its own creases. Set Edges.Tolerance to a length in
millimetres to change that width, or to solidlens.Exact to draw the mesh as it
is.
Edges are drawn after every model's surface, so they stay hidden behind nearer bodies.
Open meshes render with both sides lit. A decad sheet body, the result of
WithSurfaceResult, tessellates to such a mesh, and passing its *decad.Mesh
as Model.Mesh shows its inner walls as well as its outer ones. The front of
a triangle is the side its vertices wind counter-clockwise on, which for a
sheet is decad's positive side. Set Model.BackMaterial to shade the other
side in a different material and make the sheet's orientation visible. When
it is nil, both sides use Model.Material. Edge lines are drawn along a
sheet's free edges, because those edges border the mesh.
The examples package contains a tested end-to-end render.
Orbit views and turntables
NewOrbit takes a set of models and returns an Orbit, which frames them and
turns a view into a Scene. A view is a Yaw and Pitch in degrees plus a
Zoom, so a tool that lets the user drag to rotate only has to change those
and render again. The camera keeps Z up and the lights follow it, so the face
being looked at stays lit.
RenderTurntableGIF writes a looping GIF of one full turn around the models.
GitHub shows a GIF inline in a README, but it does not run scripts, so an
animation is the closest it gets to a 3D view. Set Turntable.Width, Height,
Frames, Delay, View, and Orbit to change the size, smoothness, speed,
starting angle, and field of view or background. All are optional.
var out bytes.Buffer
err := solidlens.RenderTurntableGIF(ctx, &out, models, solidlens.Turntable{Width: 640, Height: 480})
A GIF holds 256 colours, so the palette is chosen from a sample of the frames and shared by all of them. Flat-shaded models keep their look, and a smooth gradient may show bands.
Orbit views and turntables
These pieces are separate, so you can use one without the others.
BoundsOfreturns the box around anyTriangleSources, with itsCenterandRadius.FitOrbittakes bounds and returns anOrbit, a camera on a sphere around a target.Orbitis a plain value. A viewer that rotates on drag changes itsYawandPitch, one that zooms scalesDistance, andOrbit.Cameraturns it into theCamerafor aScene.CameraLightsreturns a key and a fill light placed relative to a camera, so the visible side stays lit as the camera moves. It works with any camera, not only anOrbit.SceneSourceis a numbered list of scenes, one per animation frame.Scenesplays a list you built, andTurntableturns anOrbitonce around a base scene, lighting it withCameraLightsunless the base scene has lights.RenderGIFrenders anySceneSourceas a GIF that loops forever. GitHub shows a GIF inline in a README, but it does not run scripts, so an animation is the closest a README gets to a 3D view.
bounds, _ := solidlens.BoundsOf(mesh)
turntable := solidlens.Turntable{
Base: solidlens.Scene{Models: models, Background: solidlens.RGB(0.02, 0.02, 0.03)},
Orbit: solidlens.FitOrbit(bounds, 0),
}
err := solidlens.RenderGIF(ctx, &out, turntable, solidlens.GIFOptions{Width: 640, Height: 480})
A GIF holds 256 colours, so the palette is chosen from a sample of the frames and shared by all of them. Flat-shaded models keep their look, and a smooth gradient may show bands.
Plane sections
RenderSection draws how two or more solids meet on a cutting plane. Give a
SectionView the plane (Origin, and orthonormal in-plane axes U and V,
so a point's plane coordinates are (p-Origin).U and (p-Origin).V) and one
SectionLayer per solid. A layer holds closed loops of 3D points that lie in
the plane, such as decad's Body.SectionOutline returns: outer loops run
counter-clockwise seen from the tip of U x V, and holes run clockwise.
img, report, err := solidlens.RenderSection(ctx, solidlens.SectionView{
Plane: solidlens.SectionPlane{U: solidlens.Vec{X: 1}, V: solidlens.Vec{Y: 1}},
Layers: []solidlens.SectionLayer{
{Name: "gear", Loops: gearLoops, Fill: solidlens.RGBA(0.05, 0.4, 0.95, 0.55), Outline: solidlens.RGB(0.02, 0.2, 0.7)},
{Name: "mate", Loops: mateLoops, Fill: solidlens.RGBA(0.95, 0.6, 0.05, 0.55), Outline: solidlens.RGB(0.7, 0.35, 0.02)},
},
})
Where two layers cover the same area the overlap color, red by default, paints
over both, and edges are anti-aliased by supersampling. The image gets a
millimetre grid with labels, a scale bar, a legend, and an optional Caption.
The window fits all layers unless Window is set. The returned
SectionReport has each layer's exact area, a raster estimate of it, and the
raster overlap area, along with the pixel and sample sizes that bound the
estimate's precision.
Cutaways
Set Model.Clip to a ClipPlane to cut a model open before it is drawn. The half-space the plane's Normal points
into is removed, so a camera on that side looks into the solid. A closed solid shows the inside of its own surface
through the cut, and Cap shades it: an unlit material draws it as one flat colour, which reads as the solid's cut
face. ClipMesh returns the clipped mesh directly.
model := solidlens.Model{
Mesh: mesh,
Material: solidlens.Matte(color),
Clip: &solidlens.ClipPlane{
Normal: solidlens.Vec{Y: -1},
Cap: &solidlens.Material{Color: color, Unlit: true},
},
}
Guide lines
Set Scene.Lines to draw world-space polylines over the render, such as the
guides in an exploded view. A Line carries its Points, a Color, a Width
in pixels (zero means one pixel) and a Dash pattern in pixels. Dash
alternates the length of a dash and of the gap after it, so {6, 4} draws
6 pixel dashes 4 pixels apart. It runs along the whole polyline and carries on
around corners. An empty Dash draws a solid line.
Lines are drawn on top of every model and its edges and are not depth tested, so a guide stays visible behind a surface. Width and dash lengths are screen pixels, so a line keeps its look at any distance.
Depth of field
Set Scene.DepthOfField to blur everything away from a focal plane. It takes
a FocusDistance from the camera and an Aperture diameter, both in scene
units, and a larger aperture blurs more. Each pixel spreads into a disc, or
into a regular polygon when Blades is between 3 and 16, which gives the
bokeh shape. MaxRadius caps the blur in pixels and defaults to 24. A nil
DepthOfField renders everything sharp.
| Sharp | FocusDistance: 16, Aperture: 0.7, Blades: 6 |
|---|---|
![]() |
![]() |
A small bright spot that is out of focus fades into its surroundings, because
the blur averages it with the dark pixels around it. Set Highlight to make
pixels brighter than HighlightThreshold (default 0.8) count for 1+Highlight
times as much in that average, so the spot stays visible as a disc or polygon.
A highlight that lies behind a nearer surface does not glow over it.
bokehLightsScene in internal/cmd/genimages/depth_of_field.go builds this
render with Highlight: 80.
The blur reads the finished depth buffer, so it cannot show surfaces hidden
behind a blurred foreground edge. Render time grows with the square of the
largest blur radius, so lower MaxRadius to speed up a heavily blurred
render.
Gallery
The gallery uses triangle meshes built in Go and rendered with RenderPNG.
It shows directional and point lighting, per-model materials, edge lines,
perspective camera placement, and a configured background. The faceted bodies
show their facet edges, while the sphere keeps only its silhouette, because
its neighbouring faces stay under the default crease angle.
| Mechanical forms | Primitive forms |
|---|---|
![]() |
![]() |
The committed STL and 3MF files in docs/models are the scene
sources. Run go run ./internal/cmd/genimages to regenerate the checked-in
images from those files and the section image from its in-code outlines. Run go run ./internal/cmd/genimages --models only
when intentionally rebuilding the model assets.
License
This project is source-available, and is licensed under the PolyForm Noncommercial License 1.0.0.
- Noncommercial use is free. Individuals, hobby and personal projects, research, education, nonprofits, and government may use, modify, and redistribute it at no cost, subject to the license terms.
- Commercial / business use requires a separate license. Any use by or for a business, or for commercial advantage, is not permitted under the noncommercial license. To obtain a commercial license, reach out on Bluesky at @lestrrat.bsky.social.
Contributions
This repository does not accept external pull requests.





