Liking cljdoc? Tell your friends :D

Clojars Project

clj-manifold3d

This library provides a Clojure(Script) wrapper over Emmett Lalish's incredible Manifold 3D geometry library. The CLJ implementation is based on JNI bindings to c++ produced via. javacpp: see https://github.com/SovereignShop/manifold. The CLJS implementation is based on emscripten build of Manifold for wasm.

It currently only includes Linux builds of Manifold. I intend to support other environments soon.

It implements most of the library functionality, plus extends it to support native convex hulls (2D and 3D), partial revolutions, polyhedrons, and n-section lofts. It provides a full superset of OpenSCAD functionality, making migration as easy as possible.

Manifold represents a dramatic advance in the state-of-the-art of open-source programmatic CAD. It has been adopted by most major CAD kernels.

The library aspires to achieve code compatibility between Clojure and ClojureScript so that models build in the more friendly Java environment can be shared and distributed in the javascript environment. However, there are challenges in the way the Manifold js library is provided as a promise. To (mostly) support this, this library elects to accept promises at the API level. Working with promises can be pretty annoying, especially without a type system that supports them well. For this reason, the CLJS API generally also works on non-promise objects.

Install

The Manifold .so libs are included in the bindings jar. To export meshes you'll need to have libassimp installed on your system:

sudo apt install libassimp-dev

The ClojureScript lib is not yet well supported or available via. Maven. You'll have to clone the repo and move public/manifold.wasm into public/js/. Run npm install to install the gltf (for rendering meshes) then connect via. shadow. There's a half-baked function called createGLTF in manifold_viewer.js that will take a manifold and throw it onto the model-viewer element defined in the index.html.

Status

Alpha, core API is unlikely to change much but test coverage is not complete. There likely are bugs. The CLJS implementation especially is likely to change.

Documentation

See the core namespace for some documentation. Refer to the original library for more complete documentation.

Examples

Examples should look very familiar if you've ever used OpenSCAD. Bellow are demonstrations of some of the operations that are currently unavailable in Manifold.

2D hulls:

(require '[clj-manifold3d.core :refer [circle square translate extrude get-mesh export-mesh hull
                                       cross-section revolve difference cylinder sphere offset
                                       polyhedron loft frame]])

(-> (hull (circle 5)
          (-> (square 10 10 true)
              (translate [30 0])))
    (extrude 80 70 180 [0.7 0.7])
    (get-mesh)
    (export-mesh "hull2D.stl"))

2D hull

3D hulls:

(-> (hull (cylinder 2 12 12 120)
          (-> (sphere 4 120)
              (translate [0 0 20])))
    (get-mesh)
    (export-mesh "hull3D.stl"))

3D hull

Partial revolutions:

(let [m (-> (cross-section [[-10 0] [10 0] [0 10]])
            (translate [30 0]))]
  (-> (difference m (offset m -1))
      (revolve 50 135)
      (get-mesh)
      (export-mesh "revolve.stl")))

Partial revolve

Polyhedron:

(-> (polyhedron [[0 0 0]
                 [5 0 0]
                 [5 5 0]
                 [0 5 0]
                 [0 0 5]
                 [5 0 5]
                 [5 5 5]
                 [0 5 5]]
                [[0 3 2 1]
                 [4 5 6 7]
                 [0 1 5 4]
                 [1 2 6 5]
                 [2 3 7 6]
                 [3 0 4 7]])
    (get-mesh)
    (export-mesh "polyhedron-cube.stl"))

Partial revolve

Loft:

(-> (let [c (difference (square 10 10 true) (square 8 8 true))]
      (loft [c (scale c [1.5 1.5]) c]
            [(frame 1)
             (-> (frame 1) (translate [0 0 15]))
             (-> (frame 1) (translate [0 0 30]))]))
    (get-mesh)
    (export-mesh "loft.stl"))

Partial revolve

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close