Skip to content

Implemented OpenSCAD support to models in STEP format. - #120

Open
codex826 wants to merge 4 commits into
opencax:masterfrom
codex826:alpha
Open

Implemented OpenSCAD support to models in STEP format. #120
codex826 wants to merge 4 commits into
opencax:masterfrom
codex826:alpha

Conversation

@codex826

Copy link
Copy Markdown

Pull Request: Add OpenSCAD Support for Exporting Models in STEP Format

Issue no: #111

🚀 Overview

This PR introduces the foundational groundwork for exporting OpenSCAD models to the STEP (ISO-10303-21 AP214) format. Unlike the traditional approach of exporting a single rendered mesh, this implementation provides a modular geometry engine and a faceted B-Rep writer capable of preserving individual solid structures within a single export file.

This work fulfills the GSoC 3D-CAD project objective to simplify workflows for CNC manufacturing and electronics design (e.g., KiCAD integration) by removing the need for external STL-to-STEP conversion tools.

🏗 Solution Implementation

1. Research & Analysis

  • Library Research: We investigated various libraries for STEP generation and chose a decoupled approach using openscad-parser for AST processing combined with a custom-built B-Rep generation engine. This avoids heavy external dependencies while ensuring full control over the STEP entity graph.
  • STEP Investigation: We researched STEP AP203/AP214 standards and identified FACETED_BREP as the optimal initial target for robust faceted geometry exchange between OpenSCAD and tools like KiCAD or FreeCAD.

2. Core Implementation (src/)

  • Geometry Engine (geometry.ts): Implements 3D math (Vectors, Matrix4) and mesh-level CSG operations.
    • Solid Primitives: cube, sphere, cylinder.
    • Booleans: union, difference, intersection.
    • Convex Hull: Standalone 3D incremental hull algorithm.
    • Extrusions: linear_extrude with twist and scale support.
  • STEP Exporter (step-exporter.ts): Converts internal Solid geometry into valid ISO-10303-21 STEP entities (CLOSED_SHELL, FACE_SURFACE, POLY_LOOP).
  • AST Evaluator (step-evaluator.ts): A tree-walking interpreter that translates OpenSCAD code (modules, functions, loops) into geometry primitives.

3. Integrated Tooling

  • Validator (step-validator.ts): Ensures generated files have no dangling references and follow the STEP structural specification.
  • CLI (cli.ts): A standalone tool for batch conversion and validation.

🛠 Tech Stack

  • Language: TypeScript (ESM)
  • Runtime: Node.js
  • Parser: openscad-parser
  • Math: Custom 3D Linear Algebra implementation.
  • Testing: Custom regression suite with Node.js assert.

🧪 Testing & Verification

We have implemented a comprehensive test suite in src/tests/ that verifies:

  • Geometric Accuracy: Math kernels and primitive generation.
  • CSG Correctness: Booleans and Hulls.
  • STEP Integrity: Structural validation of exported files.
  • Language Support: For-loops, nested modules, and variables.

🔮 Future Aspects & Advanced Models

The current focus was on building the "ground work" for detailed models:

  • B-Rep Advancement: The system is architected to support ADVANCED_BREP (smooth surfaces/NURBS) in the future by extending the Face definition to support analytic surfaces.
  • Assembly Support: We have prototyped the ability to export multiple separate solids in one STEP file, allowing individual parts of an OpenSCAD assembly to be selected in target CAD tools.
  • Build System Integration: The project is structured as a standard NPM package, ready to be integrated into CI/CD pipelines or desktop installers.

Created as part of the GSoC 3D-CAD initiative.

Pull Request: Add OpenSCAD Support for Exporting Models in STEP Format

🚀 Overview

This PR introduces the foundational groundwork for exporting OpenSCAD models to the STEP (ISO-10303-21 AP214) format. Unlike the traditional approach of exporting a single rendered mesh, this implementation provides a modular geometry engine and a faceted B-Rep writer capable of preserving individual solid structures within a single export file.

This work fulfills the GSoC 3D-CAD project objective to simplify workflows for CNC manufacturing and electronics design (e.g., KiCAD integration) by removing the need for external STL-to-STEP conversion tools.

🏗 Solution Implementation

1. Research & Analysis

  • Library Research: We investigated various libraries for STEP generation and chose a decoupled approach using openscad-parser for AST processing combined with a custom-built B-Rep generation engine. This avoids heavy external dependencies while ensuring full control over the STEP entity graph.
  • STEP Investigation: We researched STEP AP203/AP214 standards and identified FACETED_BREP as the optimal initial target for robust faceted geometry exchange between OpenSCAD and tools like KiCAD or FreeCAD.

2. Core Implementation (src/)

  • Geometry Engine (geometry.ts): Implements 3D math (Vectors, Matrix4) and mesh-level CSG operations.
    • Solid Primitives: cube, sphere, cylinder.
    • Booleans: union, difference, intersection.
    • Convex Hull: Standalone 3D incremental hull algorithm.
    • Extrusions: linear_extrude with twist and scale support.
  • STEP Exporter (step-exporter.ts): Converts internal Solid geometry into valid ISO-10303-21 STEP entities (CLOSED_SHELL, FACE_SURFACE, POLY_LOOP).
  • AST Evaluator (step-evaluator.ts): A tree-walking interpreter that translates OpenSCAD code (modules, functions, loops) into geometry primitives.

3. Integrated Tooling

  • Validator (step-validator.ts): Ensures generated files have no dangling references and follow the STEP structural specification.
  • CLI (cli.ts): A standalone tool for batch conversion and validation.

🛠 Tech Stack

  • Language: TypeScript (ESM)
  • Runtime: Node.js
  • Parser: openscad-parser
  • Math: Custom 3D Linear Algebra implementation.
  • Testing: Custom regression suite with Node.js assert.

🧪 Testing & Verification

I have implemented a comprehensive test suite in src/tests/ that verifies:

  • Geometric Accuracy: Math kernels and primitive generation.
  • CSG Correctness: Booleans and Hulls.
  • STEP Integrity: Structural validation of exported files.
  • Language Support: For-loops, nested modules, and variables.

🔮 Future Aspects & Advanced Models

The current focus was on building the "ground work" for detailed models:

  • B-Rep Advancement: The system is architected to support ADVANCED_BREP (smooth surfaces/NURBS) in the future by extending the Face definition to support analytic surfaces.
  • Assembly Support: We have prototyped the ability to export multiple separate solids in one STEP file, allowing individual parts of an OpenSCAD assembly to be selected in target CAD tools.
  • Build System Integration: The project is structured as a standard NPM package, ready to be integrated into CI/CD pipelines or desktop installers.

Created as part of the GSoC 3D-CAD initiative.

@t-paul

t-paul commented Mar 25, 2026

Copy link
Copy Markdown
Member

I'm not sure what this is targeting, it references issue #111 but does not match with the topic of that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants