feat: expand product exporters and FEM workflow

This commit is contained in:
NiJingzhe
2026-08-18 01:36:44 +08:00
parent 9d6703a786
commit ba1e06a489
49 changed files with 4363 additions and 382 deletions
+17
View File
@@ -0,0 +1,17 @@
# ProductMJCFExportReport
## Class Definition
```python
class ProductMJCFExportReport(output_path: Path, mapping_path: Path, mesh_directory: Path, root_definition_id: str, mesh_count: int, body_count: int, joint_count: int, equality_count: int, grounded_group_count: int, site_count: int, default_density_count: int, limitations: tuple[str, ...])
```
*Source: exporter/mjcf.py*
## Import Surface
- exporter namespace: `from simplecadapi import exporter` then `exporter.mjcf.ProductMJCFExportReport(...)`
## Description
Observed facts and compiler decisions from one MJCF export.
+17
View File
@@ -0,0 +1,17 @@
# ProductOBJExportReport
## Class Definition
```python
class ProductOBJExportReport(output_path: Path, root_definition_id: str, solid_count: int, definition_count: int, vertex_count: int, triangle_count: int, linear_deflection: float, angular_deflection_degrees: float, relative: bool, tessellation_backend: str = 'opencascade-brep-tessellation')
```
*Source: exporter/obj.py*
## Import Surface
- exporter namespace: `from simplecadapi import exporter` then `exporter.obj.ProductOBJExportReport(...)`
## Description
Evidence from direct BREP tessellation and triangle OBJ export.
+2 -2
View File
@@ -3,7 +3,7 @@
## Class Definition
```python
class ProductSTLExportReport(output_path: Path, root_definition_id: str, solid_count: int, definition_count: int, quadrilateral_count: int, residual_triangle_count: int, stl_triangle_count: int, quad_fraction: float, mesh_size: float, remesh_backend: str = 'gmsh-quad-dominant')
class ProductSTLExportReport(output_path: Path, root_definition_id: str, solid_count: int, definition_count: int, vertex_count: int, triangle_count: int, linear_deflection: float, angular_deflection_degrees: float, relative: bool, tessellation_backend: str = 'opencascade-brep-tessellation')
```
*Source: exporter/stl.py*
@@ -14,4 +14,4 @@ class ProductSTLExportReport(output_path: Path, root_definition_id: str, solid_c
## Description
Evidence from quad-dominant product-surface remeshing and STL export.
Evidence from direct BREP tessellation and binary STL export.
+4
View File
@@ -91,8 +91,12 @@ This index includes generated docs for the public SimpleCAD API surface, includi
## Export
- [ProductMJCFExportReport](ProductMJCFExportReport.md) *(from exporter/mjcf.py)* `exporter namespace`
- [ProductOBJExportReport](ProductOBJExportReport.md) *(from exporter/obj.py)* `exporter namespace`
- [ProductSTEPExportReport](ProductSTEPExportReport.md) *(from exporter/step.py)* `exporter namespace`
- [ProductSTLExportReport](ProductSTLExportReport.md) *(from exporter/stl.py)* `exporter namespace`
- [export_product_package_to_mjcf](export_product_package_to_mjcf.md) *(from exporter/mjcf.py)* `exporter namespace`
- [export_product_package_to_obj](export_product_package_to_obj.md) *(from exporter/obj.py)* `exporter namespace`
- [export_product_package_to_step](export_product_package_to_step.md) *(from exporter/step.py)* `exporter namespace`
- [export_product_package_to_stl](export_product_package_to_stl.md) *(from exporter/stl.py)* `exporter namespace`
@@ -0,0 +1,23 @@
# export_product_package_to_mjcf
## API Definition
```python
def export_product_package_to_mjcf(data: ProductPackageInput, output_path: str | Path, *, mesh_directory: str | Path | None = None, mapping_path: str | Path | None = None, linear_deflection: float = 0.15, default_density_kg_m3: float | None = None) -> ProductMJCFExportReport
```
*Source: exporter/mjcf.py*
## Import Surface
- exporter namespace: `from simplecadapi import exporter` then `exporter.mjcf.export_product_package_to_mjcf(...)`
## Description
Compile a validated `.scadpkg` assembly into an MJCF model.
Fixed constraints and attachments through forwarded nested-assembly
connectors create rigid groups. Revolute/prismatic edges form a
deterministic spanning tree. Gear, belt, and rack-pinion relations become
independent fixed-tendon equalities. Root assembly connectors and geometry
names in the ``interface.*`` namespace become MJCF sites.
+21
View File
@@ -0,0 +1,21 @@
# export_product_package_to_obj
## API Definition
```python
def export_product_package_to_obj(data: ProductPackageInput, output_path: str | Path, *, linear_deflection: float = 0.1, angular_deflection_degrees: float = 20.0, relative: bool = False) -> ProductOBJExportReport
```
*Source: exporter/obj.py*
## Import Surface
- exporter namespace: `from simplecadapi import exporter` then `exporter.obj.export_product_package_to_obj(...)`
## Description
Export one `.scadpkg` directly from evaluated BREP as triangle OBJ.
`linear_deflection` is the maximum chordal deviation in product units.
`angular_deflection_degrees` limits angular deviation on curved surfaces.
No remeshing or topology reconstruction is performed.
+5 -4
View File
@@ -3,7 +3,7 @@
## API Definition
```python
def export_product_package_to_stl(data: ProductPackageInput, output_path: str | Path, *, mesh_size: float = 1.0, recombination_angle_degrees: float = 45.0) -> ProductSTLExportReport
def export_product_package_to_stl(data: ProductPackageInput, output_path: str | Path, *, linear_deflection: float = 0.1, angular_deflection_degrees: float = 20.0, relative: bool = False) -> ProductSTLExportReport
```
*Source: exporter/stl.py*
@@ -14,7 +14,8 @@ def export_product_package_to_stl(data: ProductPackageInput, output_path: str |
## Description
Export one validated `.scadpkg` as a quad-dominant remeshed STL.
Export one `.scadpkg` directly from evaluated BREP as binary STL.
Gmsh recombines each CAD surface into quadrilaterals before its STL writer
splits every quad into two triangles, as required by the STL file format.
`linear_deflection` is the maximum chordal deviation in product units.
`angular_deflection_degrees` limits angular deviation on curved surfaces.
No remeshing or topology reconstruction is performed.
+22 -7
View File
@@ -150,6 +150,8 @@ downstream target from the consumer contract:
| `.scadpkg` | Rebuild, replay, cache, or further SimpleCAD editing is required | Complete durable definition closure, feature graphs, source snapshots, topology, connectors, constraints, and materials | SimpleCAD-specific archive |
| `.FCStd` | A FreeCAD user needs an editable native document | Definition-owned, dependency-first native feature graphs; final body links; repeated instances; nested assemblies; names; solved placements; materials; connectors; constraints; grounding; revision; and content hashes | Requires FreeCADCmd/FreeCAD |
| AP242 `.step` | Neutral CAD exchange or downstream OpenCASCADE tooling is required | Evaluated BREP, product hierarchy, shared definitions, occurrence names/placements, materials, colors, density, and named SimpleCAD property payloads | Canonical feature history is not reconstructed as AP242 features |
| Triangle `.obj` | Surface inspection or DCC exchange needs an indexed mesh | Direct OpenCASCADE tessellation of evaluated BREP with shared vertices and oriented triangles | Evaluated surface mesh only; no CAD hierarchy, feature semantics, quads, or materials |
| Binary `.stl` | Additive manufacturing or triangle-only consumers | The same direct OpenCASCADE BREP triangles | Facet soup only; no shared vertices, CAD hierarchy, feature semantics, or materials |
```python
package_path = assembly_package.artifact_paths["product"]
@@ -166,10 +168,21 @@ stl_report = scad.exporter.export_product_package_to_stl(
package_path,
"out/product.stl",
)
obj_report = scad.exporter.export_product_package_to_obj(
package_path,
"out/product.obj",
)
print(step_report.definition_ids, step_report.occurrence_count)
print(stl_report.solid_count, stl_report.stl_triangle_count)
print(stl_report.solid_count, stl_report.triangle_count)
print(obj_report.vertex_count, obj_report.triangle_count)
```
STL and OBJ use the same direct OpenCASCADE tessellation and parameters. Set
`linear_deflection` to the maximum chordal deviation in product units and
`angular_deflection_degrees` to the curved-surface angular limit. Both formats
contain oriented triangles; OBJ preserves shared vertex indices while binary STL
stores each facet independently. No remeshing or optional dependency is involved.
AP242 definition and occurrence metadata is stored in one standard
`PROPERTY_DEFINITION_REPRESENTATION`. Its named
`DESCRIPTIVE_REPRESENTATION_ITEM` records use
@@ -180,9 +193,11 @@ connectors, constraints, grounding, name, and solved placement.
`ProductSTEPExportReport` reports the schema, definition IDs, occurrence
count, material IDs, metadata item count, and explicit limitations.
For tetrahedral meshing, install `simplecadapi[gmsh]` and run
`examples/12_ap242_gmsh_volume_mesh.py`. The example exports one `.scadpkg`,
converts it to AP242 STEP, imports it with Gmsh's OpenCASCADE kernel, rejects
imports with no 3D volumes, generates a dimension-3 mesh, writes `.msh`, and
always finalizes Gmsh. Gmsh remains optional and is never imported by the core
SDK or the product exporters.
For tetrahedral meshing, run the split example directly in dependency order:
`model.py` captures `.scadpkg`, `export_step.py` exports AP242 STEP, and
`export_fem_mesh.py` imports that STEP with Gmsh's OpenCASCADE kernel. The FEM
stage rejects imports with no 3D volumes, generates a dimension-3 mesh, writes
`.msh`, and always finalizes Gmsh. Install and invoke the optional dependency
with `uv run --extra gmsh python
examples/12_ap242_gmsh_volume_mesh/export_fem_mesh.py`; Gmsh is never imported
by the core SDK or product exporters.
+12 -3
View File
@@ -81,9 +81,18 @@ definition/occurrence properties. The property descriptions contain canonical
sorted JSON for durable IDs and semantics. Feature history is not reconstructed
as AP242 features; `.scadpkg` remains the canonical replayable artifact.
The optional `gmsh` extra and `examples/12_ap242_gmsh_volume_mesh.py` demonstrate
`.scadpkg -> AP242 STEP -> tetrahedral .msh` without adding Gmsh to the core
runtime dependency set.
Product mesh export now shares one direct OpenCASCADE tessellation of evaluated
BREP solids. OBJ and binary STL contain the same oriented triangles; OBJ keeps
shared vertex indices while STL stores independent facets. The public accuracy
controls are `linear_deflection`, `angular_deflection_degrees`, and `relative`.
No remeshing dependency or Python 3.11 version gate is involved, so mesh export
works across the package's complete supported Python range.
The scripts in `examples/12_ap242_gmsh_volume_mesh/` build one `.scadpkg` and
demonstrate every package exporter and translator as independent downstream
commands: AP242 STEP, STL, OBJ, FCStd, FreeCAD, Fusion 360, and SolidWorks.
The optional Gmsh stage continues from AP242 STEP to a tetrahedral `.msh`
without adding Gmsh to the core runtime dependency set.
## 7. Native render crash isolation