Tag Archives: CSG

CAD: ScriptCAD.org Prototype (2019/12)

Around February 2019 I bootstrapped a scripted CAD environment named “ScriptCAD”, and resembles closely to OpenSCAD.org and OpenJSCAD.org (which I co-developed for a couple of years) with a new take, developed from scratch:

ScriptCAD.org: ScriptCAD Logo 2019/11
  • Scripting capability using JavaScript
  • Separate internal representation from display representation
    • Triangulation or Implicit representation
    • only triangulate at late stage at display or export
ScriptCAD.org Internal Stages
  • Intuitive Graphical User Interface (GUI)
    • Simple export various formats
    • Select top-level solids
    • Source <-> TreeView <-> 3D Model selection
Select Source <-> TreeView Item <-> 3D Model

The transparent Source vs Object Tree vs 3D Space has been in the back of my mind for a long time as I keep the connection of each stage intact and transparent.

  • Ease of use
    • hiding JS module complexity and notions
    • Browser use (either use built-in editor or drag-n-drop source with autoreload)
    • Command Line Interface (CLI) use

Screenshots & Examples

SpiritCAD.org Online as Preview

As of November 2019, ScriptCAD.org is reachable as an early preview (alpha stage), most examples work, some do not yet or display wrong output.

Note: there is only limited documentation yet (2019/11), and the API is subject of changes.

I still tune it to my use-cases and therefore API and overall design of the API might change, even drastically; once the API becomes more stable I will release the source code as well.

Some of use-cases (as seen in the gallery above):

  • coding low-level Gcode and use ScriptCAD to preview (render) Gcode including colors, scriptcad (CLI) outputs .gcode to actually print
    • testing single layer color mixed 3D Printing: forms, color mixing
  • ScriptCAD uses ThreeCSG/csg.js at its core to perform CSG operations, which can be very slow – hence, designing complex pieces can be slow as every change recomputes all again (I like to avoid this in future developments) yet as of 0.3.2 basic caching is implemented so only deltas are recomputed.

Introduction Video

The on-going development I document also. That’s it.

CAD: CSG Operation exclusive()

Historically Constructive Solid Geometry (CSG) covers three main boolean operations:

  • union
  • difference
  • intersection

like with Set Theory or more known when using Venn diagrams.

Brian Spilsbury started to look at 3D meshes for his JSxCAD library and how to process them: much closer to actual use cases of composing solids together and incorporate physical reality that two solids cannot occupy the same space at the same time while still unite or combine their shapes somehow.

He came up with the concept disjointed assembly of solids, which has the advantage of preserving the solids integrity in order to maintain individual information of material or colors per solid, and only change their shapes to align seamless to each other.

Disjointed Assembly or Exclusivity

The disjointed assembly or exclusive series of a, b and c like

a = sphere().color(red)
b = cube(1.5).color(green).translate([0.5,0.5,0.5])
c = cube(1).color(blue).translate([0.5,0,0])

may be written as

exclusive(a,b,c) = [ difference(a,b,c), difference(b,c), c  ]

The parts no longer intersect any space of each other, and seamlessly can be fused now together. The order of such exclusivity matters now: the first solid in line is changed by all succeeding solids, and each next solid in the disjointed assembly the same, whereas the last solid remains untouched, hence, exclusivity with ascending order, the last dominates most.

Alternatively, exclusivity with descending order:

exclusive(a,b,c) = [ a, difference(b,a), difference(c,b,a) ]

and then a remains untouched, and all succeeding parts are dominated by the preceding ones.

While union(), difference() and intersection() are base functions handling solids, exclusive() introduces a lightweight approach to handle grouping of multi-material CSG solids by having the parts accessible individually afterwards.

Support

Last update 2019/04/19:

  • OpenSCAD:  exclusive() may be written as a module:
module exclusive(order="asc",explode=[0,0,0]) {
   for (i = [0:1:$children-1]) 
      translate([explode[0]*i,explode[1]*i,explode[2]*i]) 
         if(order=="desc") 
            difference() {
               children(i);
               children([i-1:-1:0]);
            }
         else
            difference() {
               children(i);
               children([i+1:1:$children-1]);
            }
}

exclusive(explode=[3,0,0]) {
   color([1,0,0]) sphere($fn=32);
   color([0,1,0]) translate([0.5,0.5,0.5]) cube(1.5,center=true);
   color([0,0,1]) translate([0.5,0,0]) cube(1,center=true);
}

Screenshot from 2019-04-19 10-45-31

  • OpenJSCAD: not yet, you can easily write a function to handle an array of solids, and creates difference() operations to each other.
  • JSxCAD: assembly() with ascending order implied, means, the last object is most dominant.
  • Unreleased/Unnamed CAD (which I currently work on 2019/04): exclusive() available, with optional last argument options with order: either "asc" (default) or "desc" like:
    • exclusive(a,b,c);
    • exclusive(a,b,c,{order:"desc"});

Screenshot from 2019-04-10 08-48-11

That’s it.