ScalaCad is a Constructive Solid Geometry library/DSL for Scala with support for creating, visualizing, and exporting 3D models. Models created with ScalaCad can be exported to the STL file format for 3D printing.
To use ScalaCad, add the following to your build:
resolvers += Resolver.bintrayRepo("joewing", "maven")
libraryDependencies += "net.joewing" %% "scalacad" % "<version>"A simple embedded domain-specific language (DSL) for creating models
is available in the net.joewing.scalacad.primitives package.
The following 3D objects are available:
CubeCylinderSphere
2D objects can be extruded to create 3-dimensional objects using the
extrude function. This permits one to perform rotations, etc., which
enables one to create objects such as screw threads.
The following 3D objects are available:
CirclePolygonRasterRectangleTriangle
Both 2D and 3D objects can be transformed via the following transformations:
RotateScaleTranslate
Both 2D and 3D objects can be combined using the following operations:
DifferenceIntersectionUnion
Models can be visualized using AwtRenderer.show from thenet.joewing.scalacad.io package. This will open a window to display the object.
Models can be saved to STL files using the StlFileWriter.write method
from the net.joewing.scalacad.io package.
Models can be loaded from STL files using the StlFileReader.read method
from the net.joewing.scalacad.io package.
Here's a simple example that can run from the command line as a script.
See the SBT Documentation
for instructions on installing the scalas script required to run this.
Once scalas is available in your path, simply save this file as
Hole.scala, make it executable (chmod +x Hole.scala), and run it
(./Hole.scala).
#!/usr/bin/env scalas
// A simple ScalaCad example as a Scala script.
// See https://www.scala-sbt.org/1.0/docs/Scripts.html
/***
resolvers += Resolver.bintrayRepo("joewing", "maven")
libraryDependencies += "net.joewing" %% "scalacad" % "0.4"
*/
import net.joewing.scalacad._
import net.joewing.scalacad.primitives._
val obj = cube(10, 10, 10).centered - cylinder(10, 3, 3, 16).centered
io.StlFileWriter.write(obj, "hole.stl")