Meshes and file writers¶
satprint.mesh
¶
Heightmap -> watertight, 3D-printable solid (binary STL), plus a textured glTF binary (GLB) for viewing and a multi-part 3MF for multi-material printers.
The model is a rectangular block: a terrain surface on top, four vertical walls and a flat bottom. Every edge is shared by exactly two triangles with consistent outward-facing winding, so slicers accept it without repair.
Coordinate system (millimeters): X west -> east (0 .. width_mm) Y south -> north (0 .. depth_mm) Z up (0 at bottom of base)
BuildingMesh(vertices, roof_faces, wall_faces, count)
dataclass
¶
Building solids sharing one vertex array (mm, same axes as Mesh).
as_mesh()
¶
Roofs and walls as one :class:Mesh.
Source code in satprint/mesh.py
88 89 90 | |
empty()
classmethod
¶
A mesh with no solids.
Source code in satprint/mesh.py
78 79 80 81 82 83 84 85 86 | |
Mesh(vertices, faces)
dataclass
¶
A triangle mesh in millimeters, x east, y north, z up.
triangle_count
property
¶
Number of triangles.
bounds()
¶
(min corner, max corner) of the vertices.
Source code in satprint/mesh.py
52 53 54 | |
surface_area_mm2()
¶
Total triangle area.
Source code in satprint/mesh.py
62 63 64 65 66 | |
volume_mm3()
¶
Signed volume via the divergence theorem (positive when outward-wound).
Source code in satprint/mesh.py
56 57 58 59 60 | |
check_watertight(mesh)
¶
Edge-manifold diagnostics: every directed edge should appear exactly once and every undirected edge exactly twice.
Source code in satprint/mesh.py
838 839 840 841 842 843 844 845 846 847 848 849 850 851 | |
frame_mesh(width_mm, depth_mm, frame_mm, height_mm)
¶
A closed rectangular ring around the width_mm x depth_mm block.
The ring's inner walls lie on the block's walls, so the two touch without
overlapping. It stands from z=0 to height_mm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width_mm
|
float
|
block width (X). |
required |
depth_mm
|
float
|
block depth (Y). |
required |
frame_mm
|
float
|
ring width, outward from the block. |
required |
height_mm
|
float
|
ring height. |
required |
Returns:
| Type | Description |
|---|---|
Mesh
|
the ring as one closed, outward-wound solid. |
Source code in satprint/mesh.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
heightmap_split_solids(relief_mm, width_mm, depth_mm, base_mm, cell_mask, skin_mm=None)
¶
Split the :func:heightmap_to_mesh block into two closed solids.
Each grid cell is a column from the floor to the terrain; the cells where
cell_mask is True form the first solid and the rest the second. The
two meet in vertical walls along the mask boundary, so together they fill
the same block. cell_mask must have no 2x2 checkerboards (see
water._fix_diagonals), or the solids touch along a single edge.
With skin_mm, the masked solid is only a skin that thick under the
terrain, and the unmasked solid fills the block beneath it, so the lower
layers print in one filament. Where the terrain is thinner than twice the
skin, the skin is half the terrain height.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
relief_mm
|
ndarray
|
(rows, cols) heights above the base top, row 0 north. |
required |
width_mm
|
float
|
block width. |
required |
depth_mm
|
float
|
block depth. |
required |
base_mm
|
float
|
base thickness under the lowest terrain point. |
required |
cell_mask
|
ndarray
|
(rows-1, cols-1) booleans, one per grid cell. |
required |
skin_mm
|
float | None
|
thickness of the masked solid; None for full columns. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Mesh, Mesh]
|
(masked solid, unmasked solid); either may have no faces. |
Source code in satprint/mesh.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |
heightmap_to_mesh(relief_mm, width_mm, depth_mm, base_mm)
¶
Build a solid block whose top surface follows relief_mm.
Parameters¶
relief_mm : (rows, cols) array of heights above the base top, in mm. Row 0 is the northern edge, column 0 the western edge. width_mm, depth_mm : physical X/Y extent of the block. base_mm : thickness of the solid base under the lowest terrain point.
Source code in satprint/mesh.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
merge_building_meshes(*meshes)
¶
Concatenate building meshes into one vertex array, solids kept apart.
Source code in satprint/mesh.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
merge_meshes(*meshes)
¶
Concatenate meshes into one vertex and face array.
Source code in satprint/mesh.py
93 94 95 96 97 98 99 100 101 | |
plate_center(plate)
¶
The (x, y) center in mm of the plate named in :data:PLATES.
Source code in satprint/mesh.py
34 35 36 37 | |
read_binary_stl(data)
¶
Parse binary STL bytes into an (n, 3, 3) float32 triangle array.
Source code in satprint/mesh.py
829 830 831 832 833 834 835 | |
read_glb(data)
¶
Split GLB bytes into its JSON document and binary chunk.
Source code in satprint/mesh.py
813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
write_3mf(parts, name='satprint', attribution=None, plate_center=PLATE_CENTER_MM)
¶
Serialize parts as one 3MF object made of named, colored parts.
Slicers (Bambu Studio, OrcaSlicer, PrusaSlicer) open it as one object
with one part per entry. A Bambu-style Metadata/model_settings.config
names the parts and gives each distinct color its own filament, numbered
in order of first use, so parts of one color share a filament. Bambu
Studio reads it; other slicers ignore it. The colors are display hints
only. The build item moves the model so its footprint is centered on
plate_center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parts
|
list[tuple[str, Mesh, str]]
|
(part name, mesh in mm, |
required |
name
|
str
|
object name. |
'satprint'
|
attribution
|
str | None
|
data credits, stored as the 3MF |
None
|
plate_center
|
tuple[float, float]
|
(x, y) plate center in mm. |
PLATE_CENTER_MM
|
Returns:
| Type | Description |
|---|---|
bytes
|
the 3MF file contents. |
Source code in satprint/mesh.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
write_binary_stl(mesh, target=None, name='satprint')
¶
write_binary_stl(mesh: Mesh, target: None = None, name: str = 'satprint') -> bytes
write_binary_stl(mesh: Mesh, target: str | io.IOBase, name: str = 'satprint') -> None
Serialize mesh as binary STL. Returns bytes when target is None.
Source code in satprint/mesh.py
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | |
write_glb(mesh, rows, cols, texture, mime_type='image/jpeg', name='satprint', copyright=None, buildings=None)
¶
Serialize a :func:heightmap_to_mesh block as GLB with texture
draped over the top surface.
The top surface is the first rows * cols vertices and the first
2 * (rows-1) * (cols-1) faces, as heightmap_to_mesh builds them.
Grid node (r, c) gets texture coordinates (c / (cols-1), r / (rows-1)),
so the image must cover the same area with row 0 at the north edge. The
walls and base are a second primitive in a plain material. Output is in
meters, Y up, as glTF requires.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Mesh
|
block from :func: |
required |
rows
|
int
|
heightmap rows used to build |
required |
cols
|
int
|
heightmap columns used to build |
required |
texture
|
bytes
|
encoded image bytes (JPEG or PNG). |
required |
mime_type
|
str
|
|
'image/jpeg'
|
name
|
str
|
mesh and node name. |
'satprint'
|
copyright
|
str | None
|
data attribution, stored in |
None
|
buildings
|
BuildingMesh | None
|
optional building solids. Their roofs take the same texture, mapped by plan position; walls and floors are plain gray. |
None
|
Returns:
| Type | Description |
|---|---|
bytes
|
the GLB file contents. |
Source code in satprint/mesh.py
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 | |