In conjunction with OCADml, this library provides an OCaml front-end to the OpenSCAD solid modelling language. All SCAD primitives and transformation functions are made available.

Notable differences from the OpenSCAD language


open OCADml
open OSCADml

let () =
  let scad_logo =
    let rad = 5.
    and fn = 720 in
    let cyl = Scad.cylinder ~fn ~center:true ~height:(rad *. 2.3) (rad /. 2.) in
    let cross_cyl = Scad.rotate (v3 0. (Float.pi /. 2.) 0.) cyl in
      [ Scad.difference
          (Scad.sphere ~fn rad)
          [ cyl; cross_cyl; Scad.rotate (v3 0. 0. (Float.pi /. 2.)) cross_cyl ]
      ; Scad.color ~alpha:0.25 Color.Magenta cross_cyl
  Scad.to_file "scad_logo.scad" scad_logo

Generated .scad scripts can then be viewed with the OpenSCAD viewer as you normally would, or directly exporting Scad.t into other model formats or PNGs with Scad.export and Scad.snapshot respectively.


OSCADml -- top level library interface

Core DSL


OCADml documentation

The OCADml library features prominently in the following examples, infact they can largely be considered part of OCADml's extended documentation. Thus in working through them, as well as using OSCADml, the OCADml manual should serve as a helpful reference.


Paths and Sweeps

Rounded Extrusions

Skins and Morphs

Function Plotting

[@@deriving cad]

There is a companion ppx, [@@deriving cad] for generating transformation functions for user-defined records and abstract types made up of the Scad.t, along with their corresponding vector (V2.t or V3.t) types (and those composed of them) provided in by OCADml.

Generating models on write

For a more pleasant modelling experience, it is highly recommended to setup dune to automate writing your models to file whenever the source files are saved. To do so, add a dune rule that runs your projects executable after it is built. For example, in your_project/bin/dune:

 (public_name your_project)
 (name main)
 (libraries OCADml OSCADml))

 (alias model)
  (run your_project)))

Then start dune in watch mode with dune build -w @model.