package OSCADml

  1. Overview
  2. Docs
OCaml DSL for 3D solid modelling in OpenSCAD

Install

Dune Dependency

Authors

Maintainers

Sources

OSCADml-0.2.3.tbz
sha256=61bc12919734a42004f9f54bb03aa5403eac9cdd645cad1fb97ddd2eba148583
sha512=9aca48afeb2c89ace6b07110b6aadedac7d877fb9b0d1990b0c0b622829ff45ced3841fdae30b5b869293dea1b3ae39f1b00fc767c8e3f69d7e78f6412801ffb

Description

OSCADml is an OCaml front-end to the OpenSCAD CAD programming language.

Tags

OCADml CAD OpenSCAD CSG

Published: 03 May 2023

README

OpenSCAD DSL for OCaml

Overview

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

  • Angles are represented in radians (and converted to degrees when compiling to OpenSCAD).

  • linear_extrude and rotate_extrude have been renamed to extrude and revolve

  • The dimensional system (2D or 3D) each shape inhabits is tracked by the type system. This is used to restrict the operations that can be legally applied (e.g. 2D shapes cannot be moved off of the xy plane, extrude can only be applied to 2D shapes) and enforcing non-mixing of 2D and 3D shapes during boolean operations.

Usage

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.union
      [ 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
      ]
  in
  Scad.to_file "scad_logo.scad" scad_logo

Generated scads can then be viewed with the OpenSCAD viewer as you normally would.

Documentation

Documentation for OSCADml is available online and offline via odig, covering the API as well as some walkthrough style examples. Referring to the manual for OCADml is also likely to be helpful.

Companion PPX

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 the OCADml library.

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:

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

(rule
 (alias model)
 (action
  (run your_project)))

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

Dependencies (5)

  1. OCADml >= "0.6.0"
  2. cairo2 >= "0.6.2"
  3. gg >= "1.0.0"
  4. ocaml >= "4.14.0"
  5. dune >= "3.6"

Dev Dependencies (1)

  1. odoc with-doc

Used by (1)

  1. ppx_deriving_cad >= "0.2.0"

Conflicts

None