Migrate export_step / export_stl / export_brep off FreeCAD, onto build123d + OCP — Phase 4: Rewrite export_stl to use OCP mesh + binary writer #44

Closed
opened 2026-06-24 03:24:33 +00:00 by Mark · 3 comments
Owner

Phase 4: Rewrite export_stl to use OCP mesh + binary writer

Goal: Replace pc2cad.py:5212 export_stl (FreeCAD + tessellate) with
an OCP BRepMesh_IncrementalMesh + binary writer pipeline. The
_write_stl_binary helper at pc2cad.py:5183 already accepts the
(vertices, triangles) shape; just feed it OCP data.

Approach:

  • Build the compound via the P3 path.
  • Mesh it: BRepMesh_IncrementalMesh(compound, tol).
  • For each face, read BRep_Tool.Triangulation(face, loc) to get
    Poly_Triangulation (nodes + triangles). Apply loc.Transformation() to
    node coordinates.
  • Flat-pack triangles (handle orientation) into vertices and triangles
    arrays; pass to _write_stl_binary.

Files: pc2cad.py:5212-5290 (rewrite export_stl),
pc2cad.py:5288-5289 (replace tessellate call).

Acceptance:

  • python pc2cad_cli.py samples/sample_plane_cyl.ply --out /tmp/p4.stl --out-format stl writes a binary STL.
  • python -c "from stl import mesh; m=mesh.Mesh.from_file('/tmp/p4.stl'); print(len(m.vectors))" reports a positive triangle count.
  • Triangle count is in the same order of magnitude as the pre-rewrite
    FreeCAD-tessellate output for the same sample (±20%).


Decomposed from pc2cad#23

## Phase 4: Rewrite `export_stl` to use OCP mesh + binary writer **Goal:** Replace `pc2cad.py:5212 export_stl` (FreeCAD + `tessellate`) with an OCP `BRepMesh_IncrementalMesh` + binary writer pipeline. The `_write_stl_binary` helper at `pc2cad.py:5183` already accepts the `(vertices, triangles)` shape; just feed it OCP data. **Approach:** - Build the compound via the P3 path. - Mesh it: `BRepMesh_IncrementalMesh(compound, tol)`. - For each face, read `BRep_Tool.Triangulation(face, loc)` to get `Poly_Triangulation` (nodes + triangles). Apply `loc.Transformation()` to node coordinates. - Flat-pack triangles (handle orientation) into `vertices` and `triangles` arrays; pass to `_write_stl_binary`. **Files:** `pc2cad.py:5212-5290` (rewrite `export_stl`), `pc2cad.py:5288-5289` (replace tessellate call). **Acceptance:** - `python pc2cad_cli.py samples/sample_plane_cyl.ply --out /tmp/p4.stl --out-format stl` writes a binary STL. - `python -c "from stl import mesh; m=mesh.Mesh.from_file('/tmp/p4.stl'); print(len(m.vectors))"` reports a positive triangle count. - Triangle count is in the same order of magnitude as the pre-rewrite FreeCAD-tessellate output for the same sample (±20%). --- --- _Decomposed from [pc2cad#23](https://forgejo.tail018ac4.ts.net/Mark/pc2cad/issues/23)_
Author
Owner

Auto-triage: needs decompose

Marked triage-approved + needs-decompose. decompose-executor will pick this up and break it into implementable sub-issues.

## Auto-triage: needs decompose Marked `triage-approved` + `needs-decompose`. decompose-executor will pick this up and break it into implementable sub-issues.
Author
Owner

Auto-triage: needs decompose

Marked triage-approved + needs-decompose. decompose-executor will pick this up and break it into implementable sub-issues.

## Auto-triage: needs decompose Marked `triage-approved` + `needs-decompose`. decompose-executor will pick this up and break it into implementable sub-issues.
Author
Owner

Auto-triage: needs decompose

Marked triage-approved + needs-decompose. decompose-executor will pick this up and break it into implementable sub-issues.

## Auto-triage: needs decompose Marked `triage-approved` + `needs-decompose`. decompose-executor will pick this up and break it into implementable sub-issues.
Mark 2026-07-08 10:05:45 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Mark/pc2cad#44
No description provided.