3d-base 0.3.3__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {3d_base-0.3.3/src/3d_base.egg-info → 3d_base-0.4.0}/PKG-INFO +3 -1
- {3d_base-0.3.3 → 3d_base-0.4.0}/pyproject.toml +2 -2
- {3d_base-0.3.3 → 3d_base-0.4.0/src/3d_base.egg-info}/PKG-INFO +3 -1
- {3d_base-0.3.3 → 3d_base-0.4.0}/src/3d_base.egg-info/requires.txt +2 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/src/base3d/mesh.py +41 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/src/base3d/skill/SKILL.md +3 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/tests/test_mesh.py +26 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/LICENSE +0 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/README.md +0 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/setup.cfg +0 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/src/3d_base.egg-info/SOURCES.txt +0 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/src/3d_base.egg-info/dependency_links.txt +0 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/src/3d_base.egg-info/entry_points.txt +0 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/src/3d_base.egg-info/top_level.txt +0 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/src/base3d/__init__.py +0 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/src/base3d/cli.py +0 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/src/base3d/show.py +0 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/src/base3d/thickness.py +0 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/tests/test_show.py +0 -0
- {3d_base-0.3.3 → 3d_base-0.4.0}/tests/test_thickness.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: 3d-base
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Headless pictures of 3D meshes with correct occlusion and smooth shading, and a health check for exported STL files
|
|
5
5
|
Author: Konstantinos Georgiou
|
|
6
6
|
License-Expression: MIT
|
|
@@ -15,6 +15,8 @@ Requires-Dist: numpy>=1.22
|
|
|
15
15
|
Requires-Dist: trimesh>=3.20
|
|
16
16
|
Requires-Dist: scipy>=1.8
|
|
17
17
|
Requires-Dist: rtree>=1.0
|
|
18
|
+
Requires-Dist: fast-simplification>=0.1
|
|
19
|
+
Requires-Dist: scikit-image>=0.21
|
|
18
20
|
Provides-Extra: captions
|
|
19
21
|
Requires-Dist: pillow>=10.1; extra == "captions"
|
|
20
22
|
Provides-Extra: sections
|
|
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "3d-base"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.0"
|
|
8
8
|
description = "Headless pictures of 3D meshes with correct occlusion and smooth shading, and a health check for exported STL files"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
11
11
|
license = "MIT"
|
|
12
12
|
authors = [{ name = "Konstantinos Georgiou" }]
|
|
13
|
-
dependencies = ["numpy>=1.22", "trimesh>=3.20", "scipy>=1.8", "rtree>=1.0"]
|
|
13
|
+
dependencies = ["numpy>=1.22", "trimesh>=3.20", "scipy>=1.8", "rtree>=1.0", "fast-simplification>=0.1", "scikit-image>=0.21"]
|
|
14
14
|
keywords = ["3d", "mesh", "stl", "render", "headless", "trimesh", "3d-printing", "cad"]
|
|
15
15
|
classifiers = ["Programming Language :: Python :: 3", "Topic :: Multimedia :: Graphics :: 3D Rendering"]
|
|
16
16
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: 3d-base
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Headless pictures of 3D meshes with correct occlusion and smooth shading, and a health check for exported STL files
|
|
5
5
|
Author: Konstantinos Georgiou
|
|
6
6
|
License-Expression: MIT
|
|
@@ -15,6 +15,8 @@ Requires-Dist: numpy>=1.22
|
|
|
15
15
|
Requires-Dist: trimesh>=3.20
|
|
16
16
|
Requires-Dist: scipy>=1.8
|
|
17
17
|
Requires-Dist: rtree>=1.0
|
|
18
|
+
Requires-Dist: fast-simplification>=0.1
|
|
19
|
+
Requires-Dist: scikit-image>=0.21
|
|
18
20
|
Provides-Extra: captions
|
|
19
21
|
Requires-Dist: pillow>=10.1; extra == "captions"
|
|
20
22
|
Provides-Extra: sections
|
|
@@ -270,6 +270,47 @@ def solid_from_skin(mesh: trimesh.Trimesh, centre, lean: float = 0.3, keep=None,
|
|
|
270
270
|
return solid
|
|
271
271
|
|
|
272
272
|
|
|
273
|
+
def remanifold(mesh: trimesh.Trimesh, pitch: float = 0.3, close: int = 1, smooth: int = 25,
|
|
274
|
+
decimate_to: int = 25000) -> trimesh.Trimesh:
|
|
275
|
+
"""A mesh rebuilt as one simple solid on a voxel grid.
|
|
276
|
+
|
|
277
|
+
A boolean operation can leave a mesh that is watertight but not a simple solid: a tunnel through a
|
|
278
|
+
seam where two parts join (a handle, so the Euler number is not 2), or a near-coincident sheet
|
|
279
|
+
where two surfaces meet at a grazing angle, which a thickness measure reads as a wall thinner than
|
|
280
|
+
any line and a slicer cannot print. This turns the mesh into filled voxels of side `pitch`, which
|
|
281
|
+
cannot carry a tunnel or a gap thinner than `pitch`; `close` passes of a morphological closing
|
|
282
|
+
fill the sub-pitch tunnels and the thin grooves a surface would otherwise read as handles; the
|
|
283
|
+
surface is taken from the voxels and, because it comes out stepped, smoothed with `smooth` Taubin
|
|
284
|
+
iterations, which keep the volume and the topology. The mesh is decimated to about `decimate_to`
|
|
285
|
+
faces first, because voxelising a high-resolution mesh is the memory cost and the grid resamples
|
|
286
|
+
the surface anyway. The result is one watertight simple solid; a crisp cut such as a bore or a
|
|
287
|
+
slot is re-cut by the caller afterwards, since the grid fills a gap thinner than its pitch.
|
|
288
|
+
|
|
289
|
+
A hole wider than `pitch` is kept, so a part that is meant to have a hole stays as it is; only the
|
|
290
|
+
tunnels and gaps narrower than the grid go. Needs `scipy`, `scikit-image` and `fast-simplification`.
|
|
291
|
+
"""
|
|
292
|
+
from trimesh.voxel import ops as _vops
|
|
293
|
+
from scipy import ndimage as _nd
|
|
294
|
+
if decimate_to and len(mesh.faces) > decimate_to:
|
|
295
|
+
try:
|
|
296
|
+
mesh = mesh.simplify_quadric_decimation(percent=float(decimate_to) / len(mesh.faces))
|
|
297
|
+
except Exception:
|
|
298
|
+
pass
|
|
299
|
+
vg = mesh.voxelized(float(pitch)).fill()
|
|
300
|
+
mat = np.asarray(vg.matrix)
|
|
301
|
+
if close:
|
|
302
|
+
pad = int(close) + 1
|
|
303
|
+
mat = _nd.binary_closing(np.pad(mat, pad), iterations=int(close))[pad:-pad, pad:-pad, pad:-pad]
|
|
304
|
+
out = _vops.matrix_to_marching_cubes(mat)
|
|
305
|
+
out.apply_transform(vg.transform)
|
|
306
|
+
out.merge_vertices()
|
|
307
|
+
out = max(out.split(only_watertight=False), key=lambda b: abs(b.volume))
|
|
308
|
+
out.fix_normals()
|
|
309
|
+
if smooth:
|
|
310
|
+
trimesh.smoothing.filter_taubin(out, iterations=int(smooth))
|
|
311
|
+
return out
|
|
312
|
+
|
|
313
|
+
|
|
273
314
|
def _seen_from(mesh: trimesh.Trimesh, centre, which, cells: int = 64, batch: int = 4_000_000, skin: float = 0.0):
|
|
274
315
|
"""Which of the faces `which` a ray from `centre` to their middles meets first, or within `skin`
|
|
275
316
|
of first: a face less than that nearer the centre is a fold or a second copy of the surface.
|
|
@@ -343,6 +343,9 @@ fixed each.
|
|
|
343
343
|
|
|
344
344
|
## trimesh calls that cost a build each to learn
|
|
345
345
|
|
|
346
|
+
- `mesh.remanifold(mesh)` rebuilds a mesh as one simple solid on a voxel grid, to shed the seam
|
|
347
|
+
tunnels and near-coincident-sheet slivers a boolean leaves (a handle, or a wall thinner than any
|
|
348
|
+
line where two surfaces graze). A hole wider than the pitch is kept; re-cut a bore or a slot after.
|
|
346
349
|
- A cut half is `trimesh.intersections.slice_mesh_plane(mesh, plane_normal, plane_origin, cap=True)`
|
|
347
350
|
(there is no `slice_plane`), and capping needs shapely and mapbox-earcut. A cut outline is
|
|
348
351
|
`mesh.section(plane_origin=, plane_normal=)`, then `.to_planar()` for 2D polygons.
|
|
@@ -285,3 +285,29 @@ def test_a_sliver_just_inside_the_inner_surface_neither_hides_it_nor_stays():
|
|
|
285
285
|
assert solid.is_watertight and solid.is_winding_consistent and solid.euler_number == 2
|
|
286
286
|
assert solid.contains([[0.0, 0.0, 8.9], [0.0, 0.0, 5.0]]).all() # the top is solid through
|
|
287
287
|
assert abs(solid.volume - 2.0 / 3.0 * np.pi * 1000) < 0.03 * 2094
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def _block_with_hole(side, hole, height=4.0):
|
|
291
|
+
# a square block with a square hole through it, built from a polygon with a hole (no boolean
|
|
292
|
+
# backend needed), so it is a genus-1 solid: watertight with a handle
|
|
293
|
+
from shapely.geometry import Polygon
|
|
294
|
+
h, s = hole / 2.0, side / 2.0
|
|
295
|
+
shell = [(-s, -s), (s, -s), (s, s), (-s, s)]
|
|
296
|
+
inner = [(-h, -h), (h, -h), (h, h), (-h, h)]
|
|
297
|
+
return trimesh.creation.extrude_polygon(Polygon(shell, [inner]), height=height)
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def test_remanifold_closes_a_sub_pitch_tunnel_to_a_simple_solid():
|
|
301
|
+
from base3d.mesh import remanifold
|
|
302
|
+
holed = _block_with_hole(10.0, 0.3) # a 0.3 mm tunnel through a 10 mm block
|
|
303
|
+
assert holed.euler_number == 0 # genus 1: a handle, not a simple solid
|
|
304
|
+
fixed = remanifold(holed, pitch=0.6, close=1, smooth=0)
|
|
305
|
+
assert fixed.is_watertight and fixed.euler_number == 2 # the sub-pitch tunnel is gone
|
|
306
|
+
assert 400.0 < fixed.volume < 800.0 # voxelising inflates the surface; it never shrinks the solid
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def test_remanifold_keeps_a_hole_wider_than_the_pitch():
|
|
310
|
+
from base3d.mesh import remanifold
|
|
311
|
+
frame = _block_with_hole(12.0, 3.0) # a 3 mm hole, far wider than the pitch
|
|
312
|
+
kept = remanifold(frame, pitch=0.6, close=1, smooth=0)
|
|
313
|
+
assert kept.is_watertight and kept.euler_number == 0 # the real hole is still a hole
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|