-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor bug fixes, jupyter-lab support
- Loading branch information
Showing
10 changed files
with
213 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,4 @@ project/build.properties | |
|
||
# others | ||
clean.sh | ||
doc/.ipynb_checkpoints/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "55600447-a1ea-4890-b717-cf415fbe85ec", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import coursierapi._\n", | ||
"interp.repositories() ++= Seq(MavenRepository.of(\"https://jitpack.io\"))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "47708706-19d0-4e4d-883f-14575a7199ce", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"//1. Local version: clone this repository, run `sbt publishLocal`\n", | ||
"//2. Remote version: nothing to do (but you depend on what versions are available)\n", | ||
"import $ivy.`com.github.dzufferey::scadla:0.1.1`" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "1517558d-4d31-448f-8345-4edd7ba192cc", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import scadla._\n", | ||
"import InlineOps._\n", | ||
"import EverythingIsIn.{millimeters, degrees}\n", | ||
"import scadla.backends.OpenSCAD // for rendering (getting a mesh)\n", | ||
"import scadla.backends.almond.Viewer // to show the mesh in jupyter/almond" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f8fd9997-7f2b-453c-9928-98f83b164fdc", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"// exmaple from the README\n", | ||
"val c = Cube(1, 1, 1)\n", | ||
"val s = Sphere(1.5)\n", | ||
"val obj = (c + c.move(-0.5, -0.5, 0)) * s\n", | ||
"val mesh = OpenSCAD(obj) // Solid -> Polyhedron\n", | ||
"Viewer(mesh)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "bd783282-7fa5-4777-94ef-5c002e9f547c", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"// a more complex example\n", | ||
"import squants.space.{Length, Angle}\n", | ||
"import scala.language.postfixOps\n", | ||
"import squants.space.LengthConversions._\n", | ||
"import scadla.utils.{RoundedCubeH, Trig, Trapezoid}\n", | ||
"\n", | ||
"// dimensions\n", | ||
"val baseWidth = 95 mm\n", | ||
"val baseLength = 150 mm\n", | ||
"val baseDepth = 5 mm\n", | ||
"\n", | ||
"val overallWidth = 200 mm\n", | ||
"val overallLength = baseLength\n", | ||
"val cornerRadius = 10 mm\n", | ||
"val wall = 2 mm\n", | ||
"val wallStraight = 40 mm\n", | ||
"val wallSlopped = 10 mm\n", | ||
"val wallAngle: Angle = 45\n", | ||
"\n", | ||
"val grooveWidth = 3 mm\n", | ||
"val grooveDepth = 2 mm\n", | ||
"val nbrGrooveH = 12\n", | ||
"val nbrGrooveV = 10\n", | ||
"\n", | ||
"def hat(x: Length, y: Length, z: Length, r: Length, a: Angle) = {\n", | ||
" val d = r*2\n", | ||
" val smaller = z * Trig.sin(a)\n", | ||
" Minkowski(\n", | ||
" Trapezoid((x-d-smaller,x-d,0),(y-d-smaller,y-d,0),z-1),\n", | ||
" Cylinder(r,1)\n", | ||
" ).move(r,r,0)\n", | ||
"}\n", | ||
"\n", | ||
"val base = Union(\n", | ||
" Cube(baseWidth, baseLength, baseDepth).move((overallWidth-baseWidth)/2,(overallLength-baseLength)/2,-baseDepth),\n", | ||
" RoundedCubeH(overallWidth, overallLength, wallStraight, cornerRadius),\n", | ||
" hat(overallWidth, overallLength, wallSlopped, cornerRadius, wallAngle).moveZ(wallStraight)\n", | ||
")\n", | ||
"val sampleGrooveH = Cube(grooveWidth, overallLength - 2*wall - 10, grooveDepth)\n", | ||
"val stepH = (overallWidth - 2*wall - 10) / nbrGrooveH\n", | ||
"val groovesH = for (i <- 1 until nbrGrooveH) yield sampleGrooveH.move(wall + 5 + i * stepH - grooveWidth/2, wall+5, wall)\n", | ||
"val sampleGrooveV = Cube(overallWidth - 2*wall - 10, grooveWidth, grooveDepth)\n", | ||
"val stepV = (overallLength - 2*wall - 10) / nbrGrooveV\n", | ||
"val groovesV = for (i <- 1 until nbrGrooveV) yield sampleGrooveV.move(wall + 5, wall + 5 + i * stepV - grooveWidth/2,wall)\n", | ||
"val shell = Difference(\n", | ||
" base,\n", | ||
" RoundedCubeH(overallWidth - 2*wall, overallLength - 2*wall, wallStraight-wall-grooveDepth, cornerRadius-wall).move(wall,wall,wall+grooveDepth),\n", | ||
" hat(overallWidth - 2*wall, overallLength - 2*wall, wallSlopped, cornerRadius-wall, wallAngle).move(wall,wall,wallStraight),\n", | ||
" Union(groovesH: _*),\n", | ||
" Union(groovesV: _*)\n", | ||
")\n", | ||
"val mesh = OpenSCAD(shell)\n", | ||
"Viewer(mesh)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "0b87f12e-127c-47a3-9bb1-17f082b7fdb1", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"// save the object as an STL file\n", | ||
"scadla.backends.stl.Printer.storeBinary(mesh, \"milling_basket.stl\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "174221c4-74f9-42d9-8613-75e972bd3b2f", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Scala", | ||
"language": "scala", | ||
"name": "scala" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": "text/x-scala", | ||
"file_extension": ".sc", | ||
"mimetype": "text/x-scala", | ||
"name": "scala", | ||
"nbconvert_exporter": "script", | ||
"version": "2.13.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package scadla.backends.almond | ||
|
||
import com.github.dzufferey.x3DomViewer.X3D | ||
import scalatags.Text.all._ | ||
import squants.space.{Millimeters, LengthUnit} | ||
|
||
class Config extends com.github.dzufferey.x3DomViewer.Config { | ||
|
||
var shapeAppearance = X3D.appearance(X3D.material(X3D.diffuseColor := "0.7 0.7 0.7")) | ||
val unit: LengthUnit = Millimeters | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package scadla.backends.almond | ||
|
||
import scadla._ | ||
import com.github.dzufferey.x3DomViewer.X3D._ | ||
import scalatags.Text.all._ | ||
|
||
object Viewer { // does not extend the normal Viewer class as it needs to return a value | ||
|
||
var conf = new Config | ||
|
||
def apply(obj: Polyhedron) = { | ||
val (points, faces) = obj.indexed | ||
val indices = faces.map{ case (a,b,c) => s"$a $b $c -1" }.mkString(" ") | ||
val coord = points.map( p => s"${p.x.to(conf.unit)} ${p.y.to(conf.unit)} ${p.z.to(conf.unit)}" ).mkString(" ") | ||
val ifaces = indexedFaceSet(coordIndex := indices.toString, coordinate( point := coord) ) | ||
val content = shape(conf.shapeAppearance, ifaces) | ||
com.github.dzufferey.x3DomViewer.Viewer.display(content, conf) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters