Curv: A Language for making Art using Mathematics

twistor shreks_donut

What is Curv?

Curv is an open source† 3D solid modelling language, for 3D printing and procedurally generated art.

It's easy to use for beginners. It's incredibly powerful for experts. And it's fast: all rendering is performed by the GPU.

Curv is also an expressive file format for the exchange of 2D and 3D procedurally generated graphics.

† github.com/doug-moen/curv -- BSD licence

How Curv Achieves these Design Goals

Ease of use:
For ease of use, the best choice is Constructive Solid Geometry (CSG) embedded in a simple, pure functional language.
Rendering Speed:
To quickly render a wide range of CSG primitives, the best choice is to render on a GPU, and to represent shapes using Signed Distance Fields (SDF) and Function Representation (F-Rep).
Expressive Power:
SDF/F-Rep is the best choice for CSG: A wide range of CSG primitives are available in Open Source. New CSG primitives can be defined directly in Curv.

OpenSCAD is Amazing

The OpenSCAD Language is Weak

The language is weak and complicated:

OpenSCAD vs Curved and Coloured Shapes

Curved surfaces & organic shapes are hard to achieve:

Very limited support for colour.

I Get Involved with the OpenSCAD Project

The Curv Project

Curv project on github: first commit May 2016

Language Goals

Language Characteristics

The 7 Data Types

Function Call Syntax

Function call is a binary operation: f x

Pipeline Syntax

dodecahedron
 >> colour red
 `union` icosahedron
dodeca-icosa

Blocks

An expression is a block with local variables:

let
diam = 1;
len = 4;

in
union(candy, stick)

where
candy = sphere diam >> colour red;
stick = cylinder {h: len, d: diam/8} >> move(0,0,-len/2);

Libraries

Contents of "lollipop.curv":

{
lollipop(diam, len) =
    union (
        sphere(diam) >> colour red,
        cylinder{h:len, d:diam/8} >> move(0,0,-len/2)
    );
}

To use the library elsewhere:

lollipop(1,4)
where
include file "lollipop.curv";

The Shape Library

Primitive Shapes

2D:

3D:

Transformations

Additive/Subtractive Operations

Colour

Shape Representations

Explicit Modelling Implicit Modelling
Directly generate boundary points Answer questions about particular points

parametric equation (unit circle):

(x,y) = (cos t, sin t)

implicit equation (unit circle):

x^2 + y^2 - 1 = 0
Boundary Representations Volumetric Representations
parametric splines simple vs Signed Distance Fields
triangle mesh discrete (voxels) vs continuous (Function Representation)

Benefits of SDF/F-Rep

Curv 0.0 uses Signed Distance Fields with Function Representation.

How SDF/F-Rep Works

A signed distance field maps each point in space onto the minimum distance from that point to the boundary of the shape.

An SDF is zero for points on the boundary of the shape, negative for points inside the shape, and positive for points outside of the shape.

The circle primitive is defined like this:

circle r = make_shape {
  dist(x,y,z,t) = sqrt(x^2 + y^2) - r;
  bbox = [[-r,-r,0], [r,r,0]];  // axis aligned bounding box
  is_2d = true;
};

Future Work

Live Demo