Scheme Cad

A programmable 3D CAD tool

Tetrahedron image

Scheme Cad is a programmable 3D CAD tool that currently supports wireframe models and features animation. Users can program Scheme Cad by writing extensions in Scheme (a dialect of LISP).

Examples and documentation are provided online and in the distribution. Scheme Cad includes a full-blown REPL interpreter which promotes incremental development: you can write small pieces of code and test them right away, without having to compile and restart.

Scheme Cad runs on Windows and Linux, is free to use and is only a small (under 1M) download away. Give it a try and let us know what you like about it and how we can make it even better.

Download

Download the Scheme Cad Windows binaries or Linux binaries. Both are zip files under 1M in size.

Running

Mesh image

Unzip the downloaded binary in some location, then run cad.bat (on Windows) or cad.sh (on Linux).

The program will display a graphics window containing a simple tetrahedron model and a prompt at the bottom. Click and drag the mouse to rotate the model.

Next, try to load a more interesting model: type (load "mesh-demo.scm") in the CAD window, then press ENTER.

Finally, activate animation by typing (load "anim-demo.scm"). The model will spin with random angular velocities. To stop, type stop-anim.

Basic commands

When you've had enough demos and want to create your own model, use the following commands:
new
Deletes the current model and creates an empty one
v
Adds a new wireframe vertex (prompts for coordinates)
e
Connects two vertices (prompts for vertex indices)

Programming

With Scheme Cad, you get the full power of Scheme to transform the model or create your own data-entry primitives.

(vert x y z [n])
Adds a new vertex with the specified coordinates (and optional index n, or an automatically generated index if not specified).
(del-vert n)
Deletes the vertex with index n.
(edge n1 n2)
Adds an edge between two vertices (specified by their indices).
(del-edge n1 n2)
Deletes an edge.
(connect-all '(n1 n2 ...))
Creates a complete graph on the specified vertex set.
(clear-edges), (clear-edges)
Clears either just the edges, or the entire model
(cad-read [prompt])
Lets the user input a value, then returns it.
(set! num-verts? #t/#f)
Shows or hides vertex indices on-screen.
(center-view)
Re-centers the view around the current model.
(save "example.scm")
Saves the model (as a Scheme program).
(load "example.scm")
Loads a Scheme program.

To define top-level commands, simply define a function with the c: prefix. For example, here's how the "e" built-in command is defined:

(define (c:e)
  (let* ((n1 (cad-read "First index:"))
         (n2 (cad-read "Second index:")))
    (edge n1 n2)))

Meshes

(load "mesh.scm")
(define (f x y) (+ x y))
(mesh '(-2 -1 0 1 2) '(-2 -1 0 1 2) f)

Animation

The global variables yaw and pitch control the viewing angle. To animate the model, you must modify the yaw and pitch from within the display hook callback (stored in global variable display-hook). Be sure to provide a way to stop the animation, by restoring the original display hook. For details, read anim-demo.scm.

Sample source code

Also read default.scm, mesh.scm, mesh-demo.scm and anim-demo.scm. You can modify default.scm to make a custom set of primitives available at start-up.