Pegmatite Pegmatite
Pegmatite Script

3D modeling for humans and AI agents

Build precise CAD models with a compact, PEG-based scripting language. Write your model, watch it take shape in a live preview, then export it as a print-ready 3MF or a STEP file for CAD. Everything runs locally — right in your browser or from the CLI.

No install needed Runs locally Agent-readable grammar
Crown rendered from the script above

Sample models

browse all →
Scraper rendered from Pegmatite Script

Scraper

An open handle and a wedge-shaped edge, built from two simple profiles.

def %base path "M 0 26 v -52 H 10 C 26 -26 10 -20 80 -19 H 127
  C 130 -19 132 -15 132 -4 V 4 C 132 16 130 19 127 19 H 80
  C 10 19 26 26 10 26 Z"

set $h 7
!color coral

plate: %base | extrude $h
[ -honeycomb 7 1.5 rim 5 in %base | extrude 7 ]
@left block 15 plate.depth $h | chamfer 15 $h at #top and #left
Screw & Nut rendered from Pegmatite Script

Screw & Nut

Helical threads and chamfered edges bring a pair of mechanical parts together.

/* Screw and nut - trapezoidal right hand thread */
set $pitch 3.81
set $height 24.3  /* head/nut height */

/* hex body, 46.8 across flats and so 54.04 across corners, its corners
   chamfered at 45 degrees from a circle just outside the flats */
def %hex {
  prism 6 across 46.8 $height | rotate 90 about z
  [-path "M23.53,0 H28 V4.47 Z" | revolve]
  @bottom -path "M28,0 V4.47 H23.53 Z" | revolve
}


part "screw"
set $minor 26.57   /* root diameter of the thread */
set $shaft 56.7
{
  head: %hex
  cylinder $minor $shaft

  /* ridge in section: 2.94 wide at the root, 0.65 at the crest, 2.02 tall.
     it runs a pitch past both ends, so its capped ends lie inside the head
     and above the tip, and the chamfer tapers the ridge to nothing */
  @center path "M-0.2,-1.47 L0,-1.47 L2.02,-0.325 L2.02,0.325 L0,1.47 L-0.2,1.47 Z"
  | helix $minor pitch $pitch height ($shaft + (2 * $pitch))

  /* trim the run-out and chamfer the tip - drawn top down, as SVG y grows down */
  on head &path "M0,0 H13.73 L15.5,1.6 V56.7 H28 V81 H0 Z" | revolve
}

part "nut"
set $bore 27.84    /* crest diameter of the internal thread */

@right 10 %hex
/* groove in section: 2.65 wide at the bore, 0.59 at the bottom, 1.8 deep */
@center -{
  cylinder $bore ($height + 2)
  @center path "M-0.2,-1.325 L0,-1.325 L1.8,-0.295 L1.8,0.295 L0,1.325 L-0.2,1.325 Z"
  | helix $bore pitch $pitch height ($height + (2 * $pitch))
}
Royal Orb rendered from Pegmatite Script

Royal Orb

A golden ornament made from spheres, sweeping bands and rows of pearls.

def %ring { sphere 70 | cut 30 40 }
def %pearls $start {
	circular 65 19 angle 154 start $start sphere 4
}

!color gold
orb:
{
	sphere 65
  [ z center:bottom %ring
    | rotate 90 about y
    | cut 50% 100 ]
  @center %ring
  [
    @top -1 %pearls 103
    @top -1 %pearls 283
    @bottom -1
      circular 65 42 sphere 4
  ]
} | cut 5 100%

z -2
cross:
{
 block 4 8 27 | fillet 2 at parallel x
 z top:top -8 block 4 24 8 | fillet 2 at parallel x
} | fillet 1 at #left or #right
Mug rendered from Pegmatite Script

Mug

A revolved body with a rounded rim and a handle swept along a single curve.

color wheat {
  /* body: one profile for the wall, the rounded rim and the floor */
  path "M0,90 H33 Q37,90 37.5,86 C42,76 47,62 46,48 C45,30 40,18 40,3
    Q40,0 38,0 Q36,0 36,3 C36,18 41,30 42,48 C43,62 39,74 33,82 Q30,84 26,84 H0 Z" | revolve

  /* handle: a D drawn with x up the mug and y out from it, stood up by about y;
     both ends sink into the wall */
  @right -6 z bottom 27 ellipse 7 14
  | sweep along path "M42,0 C46,-14 40,-31 26,-31 C12,-31 4,-20 0,-3" about y
} | rotate -45 about z
Duplo Brick rendered from Pegmatite Script

Duplo Brick

A 2×4 brick with hollow studs on top and anti-stud tubes, ribs and clutch stubs underneath.

set $pitch 16
set $length 63.8
set $width 31.8
set $height 19.15
set $wall 1.5
set $rib 1
set $rib_height 13.25
set $stub_depth 1.75

def %stud {
  tube 9.7 6.7 4.6 | chamfer 0.33 at nearest 5 0 4.6
}

color #C91A09
{
  body: block $length $width $height
  [ grid 4 2 ($pitch - 9.7) %stud ]

  cavity: @bottom -block ($length - 2 * $wall) ($width - 2 * $wall) ($height - $wall)
  [
  	!@center
    /* stiffening ribs hang from the roof */
    z top block cavity.width $rib $rib_height
    z top linear $pitch 3 block $rib cavity.depth $rib_height
    /* anti-stud tubes, bored clear of the ribs */
    z bottom linear $pitch 3 tube 13.6 11.6 cavity.height | chamfer 0.33 at nearest 7 0 0
    z bottom linear $pitch 3 -cylinder 11.6 cavity.height
    /* clutch stubs on the inside of the walls */
    y front z bottom linear $pitch 4 block $rib $stub_depth cavity.height
    y back z bottom linear $pitch 4 block $rib $stub_depth cavity.height
    x left z bottom mirror y ($pitch - $rib) block $stub_depth $rib cavity.height
    x right z bottom mirror y ($pitch - $rib) block $stub_depth $rib cavity.height
  ]
}
| chamfer 0.2 at z == 0 and (x < (0.1 - $length / 2) or x > ($length / 2 - 0.1) or y < (0.1 - $width / 2) or y > ($width / 2 - 0.1))

Twisted Vase rendered from Pegmatite Script

Twisted Vase

A star profile that widens along a curved outline and twists a quarter turn as it rises into a thin-walled vase.

set $vase "M0 0H28.248C31.085-2.357 46.44-13.48 46.51-39.95s-32.8-57.52-33.35-83.79 5.82-34.22 7.61-40.25H0"
set $h height(path $vase)
color mediumpurple
% $t star 11 2 1.8  | scale width(path $vase, $t * $h) | rotate (90 * $t) | extrude $h | shell 1.5
Flower Pot rendered from Pegmatite Script

Flower Pot

A revolved profile shapes the walls, rim and base of this everyday pot.

color peru
path "M0 0H49L54-5V-96h-1Q49-96 49-92V-7L47-5H0Z" | revolve
[ circular 113 20 -block 8 8 100 | fillet 1 at parallel z ]
@bottom -cylinder 15 20
Jewelry Box rendered from Pegmatite Script

Jewelry Box

A chamfered hexagonal box studded with rows of pyramids, topped by a lid that fits its inner wall.

set $side 42
set $height 40

def %decoration {
	grid (floor($side/8) - 1) (floor($height/8) - 1) pyramid 4 edge 8 1.5
}

part "box"
box: prism 6 edge $side $height | chamfer 2 at (parallel z or #bottom)
inner: -prism 6 edge ($side-3) ($height-3)
block (($side - 3) * 2) 3 ($height-6)
on box [#f2 #f3 #f4 #f5 #f6 #f7] y 1 -%decoration | flip z

part "lid"
!color steelblue
/* set reference face to box#top then extrude #top shape there */
on box#top #top | extrude 3
on #bottom inner#top |  offset -0.2 | round 2 | extrude 3
Six Seven rendered from Pegmatite Script

Six Seven

Raised numbers in a Google font on a rounded plate, framed by a rim that follows its outline.

set $gap 12
set $text "67"

/* references  Google Fonts, try eg. !font "Fontdiner Swanky" 400 */
!font "Lobster" 400
!font-size 16
!color black

title: text $text | extrude 1
@bottom color gold block (title.width + $gap) (title.depth + $gap) 2
  | fillet 2 at parallel z
#top | extrude 1 wall 2 inside
SIM Adapters rendered from Pegmatite Script

SIM Adapters

Three flat plates that step a SIM card up a size, each with a chamfered pocket cut to fit the smaller card.

set $thick 0.76   /* SIM card thickness */
set $fit 0        /* extra clearance around the inserted card */
!@front 5       /* spacing between the printed plates */

/* pocket position, measured in from the outer card's right and back edges */
set $microRight 1.9
set $microBack 1.2
set $nanoRight 1.15
set $nanoBack 0.54

/* card outline with the orientation chamfer on the front-left corner */
def %card $w $d $c polygon points [$c 0] [$w 0] [$w $d] [0 $d] [0 $c] | round 0.1

def %mini %card 25 15 3
def %micro %card 15 11.8 2.5
def %nano %card 12.3 8.8 1.75

!color black

part "Micro to Mini"
%mini | extrude $thick [
  on #top x right -$microRight y back -$microBack -%micro | offset $fit | extrude $thick
]

part "Nano to Micro"
%micro | extrude $thick [
  on #top x right -$nanoRight y back -$nanoBack -%nano | offset $fit | extrude $thick
]

part "Nano to Mini"
%mini | extrude $thick [
  on #top x right (-$microRight - $nanoRight) y back (-$microBack - $nanoBack) -%nano | offset $fit | extrude $thick
]
Voronoi Vase rendered from Pegmatite Script

Voronoi Vase

A tapered, hollow vase whose walls are cut into a random lattice of Voronoi cells.

rect 50 50 | extrude 120 apex [0 0 -370] | shell 3 [
  on #f2 -voronoi 2 cells 60 seed 6 rim 3 in #f2 | extrude 3
  on #f3 -voronoi 2 cells 60 seed 2 rim 3 in #f3 | extrude 3
  on #f4 -voronoi 2 cells 60 seed 3 rim 3 in #f4 | extrude 3
  on #f5 -voronoi 2 cells 60 seed 7 rim 3 in #f5 | extrude 3
]

A grammar both sides can read

Start a model yourself or pick up a script from an AI agent. The same concise language keeps your design easy to read, change and build on. And when you write by hand, the editor helps you along.

The Pegmatite editor

Write by hand.
Help as you go.

Try the editor
The command browser shows illustrated extrude, revolve, helix and sweep operations beside a 3D sign.
Explore the command palette while your model stays in view.