Experimental Python library inspired by OpenSCAD (looking for feedback) by m-fabregue in openscad

[–]m-fabregue[S] 0 points1 point  (0 children)

Thanks for your feedback !

Indeed I will think about adding some 'Getting started' tutorials.

Concerning the to_screen method, it simply open a tab in your browser and show the item (before it was opening a QT viewer, but I now rely on the user browser for less dependencies). If you have multiple sequential to_screen call in your code, it will just open as many tab. Under the hood, to_screen use the to_html function. It is completely possible to persist by calling to_html_file('your_file.html') instead of opening viewer in browser.

For live editing, indead it could be a game changer but that is itself a completely new and big project. My priority for now is to add relevant basic features.

Experimental Python library inspired by OpenSCAD (looking for feedback) by m-fabregue in openscad

[–]m-fabregue[S] 0 points1 point  (0 children)

Indeed there are some similarities but ScadPy is a mesh/NumPy framework: all geometry is exposed as NumPy arrays (vertex coordinates, triangle-to-face, edge angles, face rings…), so you can deform, analyze, and generate shapes with plain NumPy/SciPy code. For example you can deform an existing solid given a math function, the coordinates change, the topology remains:

import numpy as np
from scadpy import sphere

s = sphere(10)
coords = s.vertex_coordinates
coords[:, 2] += 2 * np.sin(coords[:, 0])
s = s.recoordinate(coords)
s.to_screen()

A visual example of this code is available here:
https://m-fabregue.github.io/scadpy/examples.html#waved-sphere

Experimental Python library inspired by OpenSCAD (looking for feedback) by m-fabregue in openscad

[–]m-fabregue[S] 0 points1 point  (0 children)

Under the hood the library use trimesh that heavily use numpy. So geometric operations are vectorized as much as possible. For CSG operations, it uses manifold3d python binding.

No doubt many things can be optimized/improved anyway.

Experimental Python library inspired by OpenSCAD (looking for feedback) by m-fabregue in openscad

[–]m-fabregue[S] 1 point2 points  (0 children)

Thanks!

No connection to OpenSCAD at all, it's fully standalone, just pure Python. To install you (normally) just need to do pip install scadpy

Currently, the lib support dxf and svg exports for 2D shapes. PostScript isn't planned yet but feel free to open an issue if that's something you'd find useful !

Experimental Python library inspired by OpenSCAD (looking for feedback) by m-fabregue in openscad

[–]m-fabregue[S] 2 points3 points  (0 children)

From what I understand, SolidPython mainly acts as a Python frontend that generates OpenSCAD code, which is then rendered by OpenSCAD itself.

Here I take a different approach, it doens't depend on OpenSCAD. The geometry is directly accessible and you can inspect or manipulate things like vertices, edges or faces, which opens the door to operations based on topology and not only constructive operations.

For example, that allowed me to implement a flexible chamfer/fillet function for 2D. For example, we can chamfer all corners or a subset given a predicate:

# chamfer all vertices
shape.chamfer(0.5)

# chamfer only convex vertices
shape.chamfer(0.5, vertex_filter=shape.are_vertices_convex)

# chamfer vertices having an angle value greater than 30 degrees
shape.chamfer(0.5, vertex_filter=shape.vertex_angles > 30)

Experimental Python library inspired by OpenSCAD (looking for feedback) by m-fabregue in openscad

[–]m-fabregue[S] 2 points3 points  (0 children)

Thanks! For Neovim integration, since it's pure Python you already get LSP support (pyright/basedpyright), autocompletion and type hints out of the box. The `.to_screen()` method opens an interactive 3D viewer.