Design into 3D

Design into 3D is an effort to create a systematic set of project generators for CNC projects, documenting things well enough that one would be able to draw up traditional plans using pen and pencil and fabricate an instance of a project using hand tools.

It is simultaneously:


 * an opensource project which is a collection of projects for things such as boxes, furniture, and tools
 * a Kickstarter
 * a book (currently in early draft stages)
 * a paper submitted to the TeX User's Group 40th Anniversary 2019 conference https://www.tug.org/tug2019/program.html
 * Design into 3D is a system for modeling parametric projects for manufacture using CNC machines. It documents using OpenSCAD to allow a user to instantly see a 3D rendering of the result of adjusting a parameter in the Customizer interface, parameters are then saved as JSON files which are then read into a LuaLaTeX file which creates a PDF as a cut list/setup sheet/assembly instructions and METAPOST to create SVG files which may be loaded into a CAM tool. A further possibility is using a tool such as TPL (Tool Path Language) to make files which are ready to cut.
 * a website: https://designinto3d.com/
 * a design philosophy

The design philosophy touches on the idea that fundamentally there are only two types of furniture:


 * platforms
 * boxes

with more complicated pieces incorporating both structures.

Currently it uses OpenSCAD as a 3D modeling front-end using the customizer feature which is available in current versions. When the parameters for a suitable design are entered into the customizer they may be saved as a preset in a JSON file which is stored in the same directory as the OpenSCAD source file. These may then be loaded into a file which generates a design for cutting, or toolpaths. Prospects for this include Tool Path Language and METAPOST using the library embedded in LuaTeX and importing the JSON file using the Lua scripting language.

OpenSCAD
When launched, OpenSCAD will display a blank window with an Editor, Console, and Customizer:



Hide the Editor, Console, and disclose the areas of the Customizer and use the Preview area's interface controls (esp. the 3rd button from the left to View All) to display the project and the parameters which may be adjusted:



Clicking the + button in the preset area will allow one to name a preset and save the settings for the current design under that name. Presets will be saved as JSON files:

{   "parameterSets": { "export": { "$fn": "45", "Boxshape": "rounded", "Clearance": "0.01", "Height": "13.5", "Length": "66.675", "PARTNO": "0", "Thickness": "6.35", "Width": "209.55", "depth": "25.4", "diameter": "3.175", "dividers_lengthwise": "1", "dividers_thickness": "3.175", "dividers_widthwise": "2", "endmillshape": "ball", "largecompartment": "widthwise", "partspacing": "12.7" }   },    "fileFormatVersion": "1" }

which may then be used for further processing. In this case, the preset is named "export".

Geometry and Toolpaths
Once one has a saved preset in a JSON file from OpenSCAD, then it is a matter of generating the geometry and toolpaths which will be needed to cut out the project.

Variables
Loading files from JSON is well documented in most programming tools with free/opensource code readily available:


 * Lua: http://regex.info/blog/lua/json

Two are notable for being suited to making geometry and/or toolpaths:


 * Tool Path Language
 * METAPOST

For other options see: Programmatic G-Code Generators

One intersection of those is lualatex which includes a Lua interpreter for scripting, and a METAPOST library for vector graphics.

One can use Lua to read in the values from the JSON file and assign them to macros (in LaTeX) and variables (in Lua) which will allow one to make use of the values in METAPOST.

For example, in LaTeX, one defines a macro for each value which may then be redefined at need:

%           "PARTNO": "0", \newcommand{\PARTNO}{\relax} \newcommand{\definePARTNO}[1]{\renewcommand{\PARTNO}{#1}}

Note that it will be necessary to rename variables so as to avoid LaTeX special characters (such as underscores) or LaTeX command structures (such as \end...).

One then reads in each variable from the selected preset (assigned to the LaTeX macro \boxspecification):

PARTNO = (table['parameterSets']['\boxspecification']['PARTNO'])

and defines the contents of the matching TeX macro:

\definePARTNO{\directlua{tex.print(PARTNO)}}

Modeling
The challenge here is the differences in how the modeling is done in each tool:


 * OpenSCAD defines volumes and the removing of material from an area using Boolean operations for difference and intersection
 * Tool Path Language defines a toolpath for a tool resulting in the removal of material based on that tool diameter/shape moving through the material
 * METAPOST defines geometric regions without an offset

Defining a series of macros and functions which allow each tool to work in a similar fashion would simplify these calculations tremendously.

Possible approaches:


 * import SVG into OpenSCAD
 * work up OpenSCAD macro which allows the use of METAPOST syntax

Geometry
First though, one must define the geometry of the design. This is done using classic geometric constructs, and possibly some curves defined by fancy math (but usually drawn up in a CAD or Bézier curve drawing program.

Points
The most basic construct is a point in coordinate space --- some CAM tools allow one to assign a drilling operation at a point.

Lines
Straight lines are the fundamental building blocks of vector drawing and are of course defined as the shortest distance between two points. Some CAM tools will allow one to assign various toolpaths to lines, and if not directly on the line, the offset will be determined by which point is the origin and which is the final point.

Arcs
Many CAD programs will allow the definition of arcs which are easily drawn and may be specified in several ways --- an origin point, end point, and a point of rotation are typical.

Curves
Curves are omitted from some tools, and when present may be defined in several ways.

Bézier Curves
The most common is Bézier curves which are defined by an on-curve point (the origin), a matching off-curve point, and an additional off-curve point paired with the ending on-curve point.

Paths
Paths are made up of multiple points, and/or lines/arcs/curves and are differentiated by being open or closed.

Open Paths
As noted above, toolpaths may be assigned to open paths, and the directionality will determine any offset. Open paths are necessarily limited in the toolpaths which may be assigned, and it will typically not be possible to assign any but the most basic of operations to them.

Closed Paths
Closed paths meet back at the point of origin and open up additional operations in CAM tools. They may be made up of lines, arcs, curves, or some combination.

Often tools will have especial support for regular polygons, allowing their creation or definition quickly and efficiently.

Third Dimensional Shapes
Extending all of these into 3 dimensions becomes more complex with each additional element, each of which complicates the mathematics.

Up through arcs and regular curves, these are usually manageable, as is expressed in constructive solid geometry (CSG), and OpenSCAD is essentially a scripting front-end for this.

Extending arbitrary curves into 3 dimensional space involves complex geometric calculations which are the domain of 3 dimensional modeling tools such as Blender and various commercial programs.

Fortunately, the regular polygons and extruded shapes of CSG afford one a very wide array of design options.

Joinery
Once one has multiple three dimensional shapes, one must consider their interactions and connections.

Toolpaths
Creating toolpaths is just that, modeling the motion of the rotary tool through 3 dimensional space.

These toolpaths necessarily partake of the roundness of the tool, and are limited by that in terms of 3D space, so circles are easy, while sharp-cornered triangles and squares are not possible. One possible strategy here is to model the possible 2-dimensional shapes which one might have occasion to cut out:


 * circles
 * ovals
 * arcs of circles
 * triangles with rounded corners
 * square/rectangles with rounded corners

Geometric shapes
With a library of such geometry, one should be able to cut out the majority of designs which are typically done using 2.5D CAM.

One possible organization method would be to characterize them by number of points and whether or no they can be determined by only arcs/straight lines:


 * 0
 * circle
 * ellipse (requires some sort of non-arc curve)
 * egg-shaped (oval) (requires some sort of non-arc curve)
 * annulus (one circle within another forming a ring)
 * superellipse (see astroid below)
 * 1
 * cone with rounded end (arc) --- also see "sector" under 3 below
 * 2
 * semicircle/circular/half-circle segment (arc and a straight line) see also sector below
 * arch --- curve possibly smoothly joining a pair of straight lines with a flat bottom
 * lens/vesica piscis (two convex curves)
 * lune/crescent (one convex, one concave curve)
 * heart (two curves)
 * tomoe (comma shape) --- requires non arc curves
 * 3
 * triangle
 * equilateral
 * isosceles
 * right triangle
 * scalene
 * (circular) sector (two straight edges, one convex arc)
 * quadrant (90°)
 * sextants (60°)
 * octants (45°)
 * Deltoid curve (three concave arcs)
 * Reuleaux triangle (three convex arcs)
 * Arbelos (one convex, two concave arcs)
 * two straight edges, one concave arc --- "dart" was suggested by Dr. Donald Knuth at the TUG2019 conference.
 * "hyperbolic sector"
 * two convex, one concave arc --- with the above named, "arrowhead" is freed up to use for this.
 * 4
 * rectangle
 * square
 * parallelogram
 * rhombus
 * trapezoid/trapezium
 * kite
 * ring/annulus segment (straight line, concave arc, straight line, convex arc)
 * asteroid (four concave arcs)
 * salinon (four semicircles)
 * three straight lines and one concave arc

Resources and Research
There are a number of other parametric tools for CNC using a variety of technologies. Each is a reflection of the capabilities and limitations of the tools used. They may be roughly divided into three categories:

Parametric CAD tools
Unfortunately, the complexities of parametric design make these tools rather difficult to use for the typical user:


 * Commercial
 * Autodesk Fusion 360\slash Inventor
 * CATIA V5
 * NX
 * Onshape
 * Pro Engineer
 * Rhino 3D (when using the Grasshopper plug-in)
 * Solid Edge
 * SolidWorks
 * Opensource (graphical)
 * FreeCAD
 * NaroCAD
 * OpenVSP (Vehicle Sketch Pad from NASA)
 * SolveSpace
 * Varkon

This is by no means an exhaustive list, see CAD and Commercial Software for further examples.

General purpose parametric design/programming tools
Here, we concern ourselves only with tools which are explicitly intended to create designs in CAD formats, or projects ready for CNC production:


 * Maker.js --- a Microsoft Garage project, this is a JavaScript library for creating and sharing modular line drawings. Has an interactive interface, and a facility for customizing it --- preview is in 2D, getting a 3D preview requires that one export an STL or openjscad code
 * atfab --- published as a book: Make: Design for CNC Furniture Projects and Fabrication Technique and written up in the article “CNC Maker Bench” project in MAKE Volume 38. This system uses a Processing app and in its current configuration requires directly editing the parameters in the code: https://github.com/akaziuna/cnc-standing-height-workbench
 * Antimony/Kokopelli --- The complexity of this has resulted in a number of projects having multiple iterations such as Matt Keeter's http://www.mattkeeter.com/projects/kokopelli/ which as been succeeded by https://github.com/mkeeter/antimony which as I understand it uses the https://libfive.com/ library --- An early stage of this work was written up in: http://mattkeeter.com/research/thesis.pdf
 * OpenJSCAD has a nascent gallery at: https://danmarshall.github.io/jscad-gallery/

Special purpose parametric design tools
Unsurprisingly, There are a number of parametric design tools for specific usages:


 * Gears --- there are a number of these, see: https://wiki.shapeoko.com/index.php/CAD#Gears and most notably: https://geargenerator.com/#200,200,100,6,1,0,0,4,1,8,2,4,27,-90,0,0,16,4,4,27,-60,1,1,12,1,12,20,-60,2,0,60,5,12,20,0,0,0,2,-563
 * Boxes --- https://wiki.shapeoko.com/index.php/Online_resources#Boxes
 * Clocks --- https://clocktickgenerator.makertoolmaker.com/ and Clockit
 * Furniture --- https://o-lap.org/
 * Houses --- https://wikihouse.cc/
 * Bowlerstudio --- http://commonwealthrobotics.com/
 * Organizer --- https://gen.haxit.org/organizer/ --- uses https://github.com/bit101/quicksettings for the interface https://www.reddit.com/r/openscad/comments/bt83ox/can_openscad_do_this_generate_parametric_objects/

A number of projects have been begun, and then vanished, for instance "Mattermachine", or been begun and then abandoned such as https://www.floodeditor.com/ the developer of which is working at: https://higharc.com/

Future
Potential projects which may be worked up:


 * Box (1)
 * Rabbeted --- https://www.thingiverse.com/thing:3575705 http://chaunax.github.io/projects/twhl-box/twhl.html see: https://www.shapeoko.com/wiki/index.php/Carbide_Create:_A_Simple_CNC_Box
 * fitted --- the simplest box, requiring a minimum of parameters, and invariant of endmill diameter for round or oval boxes (or boxes with sufficiently rounded corners)
 * mitered --- a simple box design requiring only a 90 degree V endmill
 * drawer dividers
 * finger joint: https://community.carbide3d.com/t/cnc-finger-joint-box/8880 with an OpenSCAD file posted to https://community.carbide3d.com/uploads/default/original/2X/7/7b38d865b39af4c06b29020c62a2130a57a02255.zip (one version at: https://cutrocket.com/p/5cb536396c281/ ) --- note that this and dovetail joinery require a fixture for holding the board vertically: https://cutrocket.com/p/5cb25f3380844/
 * magazine storage https://community.carbide3d.com/t/design-into-3d-boxes-magazine-storage/16238
 * dovetails: https://community.carbide3d.com/t/sharing-carbide-create-dovetail-files/9371/21
 * Tools
 * Japanese hand brace
 * locking register calipers: http://www.shapeoko.com/wiki/index.php/File:Tool_calipers_locking.svg https://community.carbide3d.com/t/locking-register-calipers-after-h-o-studley/658
 * bevel gauge: https://cutrocket.com/p/5c199e292863a/ https://community.carbide3d.com/t/adding-geometry-to-cut-as-a-pocket-with-a-finishing-pass/9993
 * hex bit organizer: https://www.reddit.com/r/functionalprint/comments/4yt295/hex_bit_storage/ --- OpenSCAD code
 * Birdhouses (2)
 * Games
 * Cribbage Boards (3) --- https://commons.wikimedia.org/wiki/File:Cribbage_Board.svg (done in METAPOST)
 * Chinese checkers (4) --- note that this began as https://en.wikipedia.org/wiki/Halma --- may make sense to offer variations beyond size. https://commons.wikimedia.org/wiki/File:Chinese_checkers_start.svg https://community.carbide3d.com/t/design-into-3d-games-chinese-checkers/16056/ and https://www.thingiverse.com/thing:3853757 --- allows one to export a DXF from OpenSCAD which may be imported into Carbide Create or any other CAM tool
 * Organizers
 * Spice racks (5)
 * Desk Organizers (6)
 * serving tray (7)
 * collectible card sorting tray (8)
 * Endmills (9)
 * parametric design in Alibre Atom 3D: https://community.carbide3d.com/t/parametric-design-using-alibre-atom3d/17409
 * Spoons / utensils
 * phone / iPad / tablet / laptop holder --- the parameter would be the tablet size/model
 * Flags --- import an SVG from Wikimedia, adjust for waviness https://community.carbide3d.com/t/carbide-create-pro-wavy-flag/16974/13
 * picture frames (10) --- parameters would include size of picture, width and thickness of stock, frame width, and options for ornamentation and possibly labeling

Programming Notes
Use translation to make OpenSCAD coordinates match those of TPL.

Spot all four corners with rapid movements in OpenSCAD.

Work up identical macros for all programs in question starting with OpenSCAD, TPL, and METAPOST.