Make 3D models in Snail with lib/sculpt, from code - solids joined, cut and blended, placed by anchors on each other, checked for floating or buried parts, and looked at as review sheets (PNG) or in a live window (game/workshop). Use when a Snail project mounts sculpt, uses game/workshop, or a 3D model, character, prop or shape is asked for in Snail. Read the snail skill first for the language.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Snail Sculpt?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/codeadopter-snail-sculpt)
---
name: snail-sculpt
description: Make 3D models in Snail with lib/sculpt, from code - solids joined, cut and blended, placed by anchors on each other, checked for floating or buried parts, and looked at as review sheets (PNG) or in a live window (game/workshop). Use when a Snail project mounts sculpt, uses game/workshop, or a 3D model, character, prop or shape is asked for in Snail. Read the snail skill first for the language.
---
# 3D models in Snail
`lib/sculpt` builds a model from basic solids and tells you, in text and pictures, what you built.
You do not see the model while you write it, so work in a loop: build, read the report, look at
the sheet, change the code. The language is in `snailc guide`; the full reference is
`docs/sculpt.md`, and `snailc api sculpt solid` and `snailc api sculpt anchor` list the calls with
their comments. Helper functions of a model are global names: declare them `private fn`.
```toml
main = "main.snail"
libs = ["sculpt"]
```
## A model, its report and its sheet
```snail
use sculpt
fn lamp(s: *Sculpt, shade_lift: f32) -> Solid
let brass = rgb(200, 160, 70)
let foot = s.cylinder(0.3, 0.06, 0.02).grounded().part("foot", brass)
let stem_top = Vec3(0.0, 1.0, 0.0) # a point: a capsule runs from one point to another
let stem = s.capsule(foot.top().sink(0.02), stem_top, 0.03).part("stem", brass)
let shade = s.cone(0.35, 0.3, 0.15)
.shell(0.02)
.on(stem.tip(), lift: shade_lift)
.part("shade", rgb(240, 230, 200))
return foot + stem + shade
fn main()
var s: Sculpt
var broken = lamp(&s, 0.1).check()
print("{broken.pieces} pieces")
for ref finding in broken.findings: print(str(finding.text))
var s2: Sculpt
let model = lamp(&s2, -0.15)
var report = model.check()
print("{report.pieces} piece, {report.findings.len} problems, lowest part '{report.lowest}'")
var sheet = model.sheet()
sheet.save("lamp.png")
```
```text
2 pieces
'shade' floats: it is 0.100 from 'stem'; moving it by (0.000, -0.100, 0.000) closes the gap
1 piece, 0 problems, lowest part 'foot'
```
- `report.print_all("lamp")` prints the size of the model, a line for each part with the box of
what shows of it, and every problem at the line of your program that made the solid. Read the
parts' lines: a check finds what floats, is buried or cuts nothing, but not a leg twice too
thin or two legs melted into one.
- The sheet is a PNG, 1536 by 1024: look at it with your image tool after every change. It has
two views in depth and the front, side, top and back flat over rulers. `model.sheet(focus:
"shade")` closes in on one part when it is too small to judge, and `copy: 1` on one copy of a
mirrored or repeated part.
- One `Sculpt` holds one model. Build a second model, or a variant to compare, in a second one.
## Traps: where a guess fails
- **A flat thing is a `ribbon`, not a squashed solid.** `stretch` with a small factor gives
distances that fall short by that factor, so checks and the workshop's drawing go wrong and
slow. `s.ribbon(points, width, end_width, thickness)` is a blade, a leaf or a strap with an
exact distance, however thin, and `s.ellipsoid(size)` an egg, a lens or a flattened ball.
- **Sizes are from side to side, and origins are middles.** `box(size)`, `ellipsoid(size)`, a
cylinder's and cone's `height` and a torus's `thickness` are full extents; only `radius` is a
radius. A sphere, box, cylinder, cone and torus are made with their middle at the origin: a
cone of height 1 spans y -0.5 to 0.5. `s.capsule(from, to, r)` and `s.tube(points, r)` are the
exceptions: their origin is their first point.
- **`on` stands a solid on an anchor by its base**, its y axis along the way the surface faces.
`.on(anchor, sink: 0.05)` sets it into the surface, `lift:` raises it, `roll: 30.0` turns it
about the surface's direction and `lean: 12.0` tips it forward about the point it stands on (a
hat). A limb that should grow out of a body starts inside it: `s.capsule(hip.sink(0.05), foot,
0.1)`. To put a solid's middle on a point without turning it, use `.at(anchor.position)`.
- **`on` turns a solid the shortest way**, so a flat one (a slab leaf, a ribbon) keeps facing
as near as it can to how it was made: add `roll:` to face it where it should, and check the
side view of the sheet.
- **`sink` and `lift` give a point, `sunk` and `lifted` an anchor.** `anchor.sink(0.05)` is a
`Vec3` for a capsule's end; `anchor.sunk(0.05)` is the anchor moved in, to stand something on.
- **A spot, a badge or a panel on a curved surface is a `patch`**, not a flat solid pressed
against it: `skin.patch(anchor, width, height)` is the skin itself there, raised a little. Take
it of the skin alone (the body, before the rest is joined), name it, and join it.
- **Left is `+x`.** The model faces `+z`, so its own left is on the right of the front view.
Build one side and `.mirror()` it.
- **A mouth or a seam is a `stroke`**: `head.stroke(left_corner, right_corner, 0.02)` is a line
along the surface between two anchors; subtract it for a groove, join it for a ridge.
- **A check finds what floats; `gap` finds what was meant.** `model.gap("hat", "head")` is how far
apart two parts are, 0 where they touch, minus how deep they overlap. `sheet(hide: ["hat"])` shows what a part covers,
and `check(hide: ["leaves"])` checks the rest without it.
- **`top()`, `front()` and the other sides are the furthest points that way.** For a point
elsewhere use `anchor.shift(right, up)` (slid along the surface: the way to spread things over
a long body), `top_at(x, z)` and `bottom_at(x, z)` (above a ground point), `cast(from, toward)`
(where a ray meets the solid), `surface(direction)` (from the solid's middle, which on a long
solid crowds toward its middle), or on a limb `side(share, toward)` and `tip()`.
- **Solids given the same name are one part.** Name each thing once, or give copies the same
name on purpose.
- **A blend swells the surface** by up to a quarter of its distance. Call `.grounded()` on the
finished model, not on its pieces, when it must stand on y = 0.
- **A `Solid` is a value.** Every call returns a new solid; `body.move(up)` alone changes
nothing. A `var all: Solid` is nothing, and `all = all + piece` in a loop builds on it.
- **Directions are the workspace's**, whatever the solid was turned by: `turn(Vec3.up(), 30.0)`
turns about the solid's own origin around the world's y axis, in degrees.
- **A problem in a helper function is reported at the helper's line.** Parts give it a name.
## The calls
```snail
use sculpt
fn main()
var s: Sculpt
# Basic solids.
let ball = s.sphere(0.5)
let crate = s.box(Vec3(1.0, 0.5, 0.8), 0.05) # size, then how round its edges are
let egg = s.ellipsoid(Vec3(0.6, 0.9, 0.6))
let can = s.cylinder(0.3, 1.0, 0.02) # radius, height, round
let horn = s.cone(0.2, 0.6) # radius, height; a third value is the top's radius
let ring = s.torus(0.5, 0.1) # around y: radius, thickness of the tube
let limb = s.capsule(Vec3(0.0, 0.0, 0.0), Vec3(0.0, 1.0, 0.0), 0.1, 0.06)
let tail = s.tube([Vec3(0.0, 0.0, 0.0), Vec3(0.0, 0.3, -0.4), Vec3(0.0, 0.8, -0.5)], 0.08, 0.02)
let blade = s.ribbon([Vec3(0.0, 0.0, 0.0), Vec3(0.0, 0.3, 0.05), Vec3(0.0, 0.5, 0.2)], 0.04, 0.005, 0.003)
# Joining and cutting. `blend` melts the two together over that distance.
let joined = ball.union(crate, blend: 0.1) + horn.move(Vec3(0.0, 0.8, 0.0))
let cut = joined - can.turn(Vec3(1.0, 0.0, 0.0), 90.0)
let shared = ball & crate
let hollow = egg.shell(0.03).cut_below(0.0)
let puffed = crate.grow(0.03) # the surface moved out by 0.03, edges rounded
let lid = crate.pivot(crate.back().position).turn(Vec3(1.0, 0.0, 0.0), -30.0) # turned about its back edge
# Anchors: a point of the surface and the way it faces.
let chest = crate.front().shift(0.2, 0.1) # slid 0.2 right and 0.1 up on the front face
let badge = s.cylinder(0.05, 0.02).on(chest) # stands on the face by its base
let dial = crate.drill(crate.top(), 0.1, 0.05) # a round hole 0.05 deep
let knob = s.sphere(0.04).on(crate.top().sunk(0.05)) # on the floor of that hole
let elbow = limb.side(0.5, Vec3(1.0, 0.0, 0.0)) # half way up the limb, on its +x side
let hand = s.sphere(0.08).at(limb.end()) # middle on the limb's far end
let leaf = s.sphere(0.1).on(tail.tip(), sink: 0.05)
let spot = egg.patch(egg.front().shift(0.1, 0.2), 0.15, 0.1).part("spots", rgb(120, 70, 30))
let hat = s.cylinder(0.1, 0.15).on(ball.top(), lean: 15.0) # tipped forward about where it sits
let spike = horn.aim(Vec3(0.0, 0.0, 1.0)) # turned so its y axis points to +z
# Copies.
let pair = hand.mirror() # with its image across x = 0
let legs = can.scale(0.2).move(Vec3(0.3, 0.0, 0.3)).mirror().mirror(Vec3(0.0, 0.0, 1.0))
let spokes = limb.ring(6, Vec3(0.0, 0.0, 1.0)) # six, turned around z
let slots = s.box(Vec3(0.02, 0.1, 0.05)).row(5, Vec3(0.05, 0.0, 0.0))
var bumps: Solid
for i in 0..4: bumps = bumps + s.sphere(0.1).move(Vec3(i as f32 * 0.3, 0.0, 0.0))
# Measures.
let size = joined.size() # 1.05 wide: the blend swells the 1.0 crate
let middle = joined.center()
print("{size.x:.2} wide, middle at y {middle.y:.2}, limb ends at y {limb.end().y:.1}")
let all = s.all([cut, shared, hollow, puffed, lid, badge, dial, knob, hand, leaf, spot, hat, spike, pair, legs,
spokes, slots, bumps, blade])
print("{s.nodes.len > 0} {not all.is_nothing()} {elbow.normal.x:.1} {ring.size().y:.1}")
```
```text
1.05 wide, middle at y 0.30, limb ends at y 1.0
true true 1.0 0.1
```
## A model in a window, live
`game/workshop` (Windows only for now) draws the model in a window straight from its field on the
GPU, and builds it again whenever the program's code changes, so under `snailc run --hot` each save
of the model's code shows a moment later. See `snailc guide hot` for running a hot session.
```snail
use game/workshop
fn pawn(s: *Sculpt) -> Solid
let base = s.cylinder(0.3, 0.1, 0.03).grounded().part("base", rgb(230, 225, 210))
let body = s.cone(0.22, 0.5, 0.08).on(base.top(), sink: 0.02).part("body", rgb(230, 225, 210))
let head = s.sphere(0.14).on(body.top(), sink: 0.04).part("head", rgb(230, 225, 210))
return base.union(body, blend: 0.03).union(head, blend: 0.02)
fn main()
var shop = workshop("pawn")
while shop.frame()
shop.show(pawn)
```
- Keep the three lines of `main` as they are: the frame loop must be in `main` for hot changes.
`show` takes the function that builds the model; it calls it only when the code changes.
- A part's look goes with its name: `.part("shell", rgb(40, 120, 60), look: spots(rgb(20, 30,
20), 0.08).shine(0.15))`; `metal()`, `glow(1.5)`, `stripes(color, width)`, `speckles(color,
size)` and the rest are in `docs/sculpt.md`. Sheets show the patterns, so you can review them
without a window. A pattern goes with what is done to the solid after `.part(...)`: stripes run
across the part's y, so name a plank standing on its edge, then turn it flat, for grain.
`snailc hot send "style clay"` (or `toon`, `parts`, `lit`) changes how the window draws the
whole model; `style mesh` shows it as a game will draw it, as meshes, with their triangles.
- Many copies (a meadow, a forest, a wall) are one `s.scatter([tuft, stone], Vec3(0.3, 1.0,
0.3), [40, 1, 40], jitter: 0.1)`, not a loop of unions: a point runs only the copies near it, so
1,600 tufts cost about what a few do. Each copy must stay inside its cell; the call says by how
much one would not.
- A model moves by joints: `limb.joint("elbow", elbow_point)` makes a rigid piece, and
`shop.play(model, move)` with `fn move(pose: *Pose, t: f32)` calling `pose.turn("elbow",
axis, degrees)` animates it; `snailc hot send "time 0.5"` shows a moment, paused. Join joints
with `+`, not by cutting. `docs/sculpt.md` has the rest.
- `snailc hot send "report"` answers with the model's measures and problems, `"sheet pawn.png"`
saves its review sheet and `"sheet head.png head"` a close-up of a part, `"view front"` (or
`back`, `left`, `right`, `top`, `corner`) turns the view for `snailc hot shot`.
- Someone watching can click the model and type a note. `snailc hot send "notes"` gives them to
you with the part and the line of your program each is about: `'head', made at main.snail:6:20,
at (0.02, 0.61, 0.11): a bit bigger`. Act on them, then `snailc hot send "notes clear"`.