Compare commits

...

3 Commits

Author SHA1 Message Date
e9340617ee Add more examples 2023-03-06 21:50:15 +13:00
b20fe5738d Ignore scad and stl files 2023-03-05 22:35:42 +13:00
78c25b740d Add stuff 2023-03-05 22:33:47 +13:00
4 changed files with 280 additions and 68 deletions

2
.gitignore vendored
View File

@@ -1,2 +1,4 @@
.venv .venv
.ipynb_checkpoints .ipynb_checkpoints
*.stl
*.scad

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "SolidPython"]
path = SolidPython
url = https://github.com/SolidCode/SolidPython.git

1
SolidPython Submodule

Submodule SolidPython added at a6822d5188

View File

@@ -12,7 +12,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 3,
"id": "a75c573b", "id": "a75c573b",
"metadata": { "metadata": {
"tags": [] "tags": []
@@ -34,15 +34,43 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 4,
"id": "25a01e9c", "id": "25a01e9c",
"metadata": { "metadata": {
"tags": [] "tags": []
}, },
"outputs": [], "outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Geometries in cache: 1\n",
"Geometry cache size in bytes: 3032\n",
"CGAL Polyhedrons in cache: 0\n",
"CGAL cache size in bytes: 0\n",
"Total rendering time: 0:00:00.000\n",
" Top level object is a 3D object:\n",
" Facets: 22\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2fb4234896484f178a27830ab615f08b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HTML(value=''), Renderer(background='#cccc88', background_opacity=0.0, camera=PerspectiveCamera…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [ "source": [
"c = cylinder(r=7, h=2)\n", "cyl = cylinder(r=7, h=2)\n",
"r.render(c)" "r.render(cyl)"
] ]
}, },
{ {
@@ -57,12 +85,40 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 5,
"id": "ecdfd420-ebef-49b1-8d90-c35b1e5ac571", "id": "ecdfd420-ebef-49b1-8d90-c35b1e5ac571",
"metadata": { "metadata": {
"tags": [] "tags": []
}, },
"outputs": [], "outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Geometries in cache: 1\n",
"Geometry cache size in bytes: 728\n",
"CGAL Polyhedrons in cache: 0\n",
"CGAL cache size in bytes: 0\n",
"Total rendering time: 0:00:00.000\n",
" Top level object is a 3D object:\n",
" Facets: 6\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f3131bd71d4b44ffa01e86efeb64a525",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HTML(value=''), Renderer(background='#cccc88', background_opacity=0.0, camera=PerspectiveCamera…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [ "source": [
"c = cube((10,4,6)) #pass a tuple x, y, z\n", "c = cube((10,4,6)) #pass a tuple x, y, z\n",
"r.render(c)" "r.render(c)"
@@ -78,7 +134,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 33, "execution_count": null,
"id": "2ae63616-4044-4c6a-bf11-9ebf83f8f22a", "id": "2ae63616-4044-4c6a-bf11-9ebf83f8f22a",
"metadata": { "metadata": {
"tags": [] "tags": []
@@ -90,7 +146,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 34, "execution_count": null,
"id": "77e99d01-1aa4-43ce-93bf-c71c6f1325c8", "id": "77e99d01-1aa4-43ce-93bf-c71c6f1325c8",
"metadata": { "metadata": {
"tags": [] "tags": []
@@ -106,7 +162,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 35, "execution_count": null,
"id": "bb5ad126-5476-43a8-9c8f-75aebce0c47e", "id": "bb5ad126-5476-43a8-9c8f-75aebce0c47e",
"metadata": { "metadata": {
"tags": [] "tags": []
@@ -133,7 +189,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 43, "execution_count": null,
"id": "86cb4b1a-03cf-449c-bc08-2ea81512c34a", "id": "86cb4b1a-03cf-449c-bc08-2ea81512c34a",
"metadata": { "metadata": {
"tags": [] "tags": []
@@ -157,7 +213,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": null,
"id": "a5769eb4-13d4-425a-a22b-8e14123f8908", "id": "a5769eb4-13d4-425a-a22b-8e14123f8908",
"metadata": { "metadata": {
"tags": [] "tags": []
@@ -177,7 +233,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 48, "execution_count": null,
"id": "6107bce9-ff24-4f94-974b-637445c707f5", "id": "6107bce9-ff24-4f94-974b-637445c707f5",
"metadata": { "metadata": {
"tags": [] "tags": []
@@ -205,7 +261,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 19, "execution_count": null,
"id": "c425603f-8c79-4e7b-b204-3c128768b6ab", "id": "c425603f-8c79-4e7b-b204-3c128768b6ab",
"metadata": { "metadata": {
"tags": [] "tags": []
@@ -225,46 +281,12 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": null,
"id": "9062af4f-d729-4208-abbf-1750b682b482", "id": "9062af4f-d729-4208-abbf-1750b682b482",
"metadata": { "metadata": {
"tags": [] "tags": []
}, },
"outputs": [ "outputs": [],
{
"name": "stderr",
"output_type": "stream",
"text": [
"Geometries in cache: 4\n",
"Geometry cache size in bytes: 9824\n",
"CGAL Polyhedrons in cache: 1\n",
"CGAL cache size in bytes: 65232\n",
"Total rendering time: 0:00:00.068\n",
" Top level object is a 3D object:\n",
" Simple: yes\n",
" Vertices: 48\n",
" Halfedges: 144\n",
" Edges: 72\n",
" Halffacets: 52\n",
" Facets: 26\n",
" Volumes: 2\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "11a120f2cd4641279ef0d1f1af319eac",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HTML(value=''), Renderer(background='#cccc88', background_opacity=0.0, camera=PerspectiveCamera…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [ "source": [
"base = cube((5,5,2))\n", "base = cube((5,5,2))\n",
"inner = cylinder(r=0.5, h=5)\n", "inner = cylinder(r=0.5, h=5)\n",
@@ -288,36 +310,220 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": null,
"id": "1810ff24-c0f8-4c80-adc2-6985cd52d7dc", "id": "1810ff24-c0f8-4c80-adc2-6985cd52d7dc",
"metadata": { "metadata": {
"tags": [] "tags": []
}, },
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"'/home/jimmy/projects/Solid-Python-Demo/part.scad'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"scad_render_to_file(part, \"part.scad\")" "scad_render_to_file(part, \"part.scad\")"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "51cdff0e", "id": "98302da6-a3ac-4386-9398-2afa67b2856c",
"metadata": {}, "metadata": {},
"source": [ "source": [
"https://github.com/nickc92/ViewSCAD\n", "## Convert to stl"
"https://solidpython.readthedocs.io/en/latest/\n",
"https://openscad.org/"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"id": "44f345ad-417a-4783-b721-847351a13f4b",
"metadata": {},
"outputs": [],
"source": [
"! openscad -o part.stl part.scad"
]
},
{
"cell_type": "markdown",
"id": "c0c11a99-e3f6-4479-81d6-28715f84199f",
"metadata": {},
"source": [
"## Polyhedron"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "9866b676-247c-4a9b-a67d-0122d2932819",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Geometries in cache: 1\n",
"Geometry cache size in bytes: 584\n",
"CGAL Polyhedrons in cache: 0\n",
"CGAL cache size in bytes: 0\n",
"Total rendering time: 0:00:00.000\n",
" Top level object is a 3D object:\n",
" Facets: 6\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "95a13583cb54495f85e760a9be96547c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HTML(value=''), Renderer(background='#cccc88', background_opacity=0.0, camera=PerspectiveCamera…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"'/home/jimmy/projects/Solid-Python-Demo/polyhedron.scad'"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"p = polyhedron(points = [\n",
" [2, 2, 2],\n",
" [2, 1, 2],\n",
" [2, 2 ,1],\n",
" [1, 2, 1],\n",
" [1, 3, 2]\n",
" ], \n",
" faces = [\n",
" [0 ,1, 2],\n",
" [0, 1, 3],\n",
" [1, 2, 3],\n",
" [2, 3, 4],\n",
" [0, 3, 4],\n",
" [0, 2, 4]\n",
" ]\n",
")\n",
"r.render(p)\n",
"scad_render_to_file(p, \"polyhedron.scad\")"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "cf0508f0-cd53-4161-aa5d-47ebd3a5af52",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Geometries in cache: 27\n",
"Geometry cache size in bytes: 79560\n",
"CGAL Polyhedrons in cache: 1\n",
"CGAL cache size in bytes: 1358544\n",
"Total rendering time: 0:00:03.888\n",
" Top level object is a 3D object:\n",
" Simple: yes\n",
" Vertices: 1008\n",
" Halfedges: 3024\n",
" Edges: 1512\n",
" Halffacets: 1012\n",
" Facets: 506\n",
" Volumes: 2\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ea6ccc6896874bb4a4c3ba5ce93ea251",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HTML(value=''), Renderer(background='#cccc88', background_opacity=0.0, camera=PerspectiveCamera…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"base = cube((10, 10, 1))\n",
"for y in range(5):\n",
" for x in range(5):\n",
" base -= translate([x*2+1, y*2+1, 0])(cylinder(r=0.5, h=1))\n",
"r.render(base)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "ddd5c9a6-61e9-48d6-9755-354d48628ac0",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Geometries in cache: 111\n",
"Geometry cache size in bytes: 80808\n",
"CGAL Polyhedrons in cache: 1\n",
"CGAL cache size in bytes: 482320\n",
"Total rendering time: 0:00:01.601\n",
" Top level object is a 3D object:\n",
" Simple: no\n",
" Vertices: 324\n",
" Halfedges: 1050\n",
" Edges: 525\n",
" Halffacets: 406\n",
" Facets: 203\n",
" Volumes: 2\n",
"WARNING: Object may not be a valid 2-manifold and may need repair!\n",
"EXPORT-WARNING: Exported object may not be a valid 2-manifold and may need repair\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "cd1ce9b432e2425d989cf116cd0d61b8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HTML(value=''), Renderer(background='#cccc88', background_opacity=0.0, camera=PerspectiveCamera…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from random import randint\n",
"base = cube((10, 10, 1))\n",
"for y in range(10):\n",
" for x in range(10):\n",
" base += translate([x, y, 0])(cube((1,1,randint(1,10))))\n",
"r.render(base)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "173c5f9c-e99e-461d-a421-cb68a1ad6783",
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {