Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules/
**/node_modules/
dist/
**/dist/
*.js
*.js.map
*.d.ts
*.d.ts.map
**/*.js
**/*.js.map
**/*.d.ts
**/*.d.ts.map
88 changes: 88 additions & 0 deletions openscad-step-export/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# OpenSCAD STEP Export

This project implements a robust STEP file exporter for OpenSCAD, developed as part of the GSoC 3D-CAD initiative. It allows exporting OpenSCAD models directly to the industry-standard STEP format (ISO-10303-21 AP214) as faceted BREP geometry.

## Features

- **Standard Primitives**: Full support for `cube`, `sphere`, and `cylinder`.
- **Transformations**: `translate`, `rotate`, `scale`, `mirror`, and `multmatrix`.
- **CSG Operations**: Robust (faceted) implementations of `union`, `difference`, `intersection`, and `hull`.
- **Extrusions**: Support for `linear_extrude` including `twist` and `scale`.
- **OpenSCAD Language**: Evaluation of modules, functions, for-loops, if/else, and all standard expression types.
- **STEP Validation**: Integrated validator ensuring high-integrity output with no dangling entity references.
- **Standalone CLI**: Simple command-line interface for batch processing or integration into other tools.

## Installation

```bash
# Clone the repository and navigate to the project folder
cd openscad-step-export

# Install dependencies
npm install

# Build the project
npm run build
```

## Usage

### Command Line Interface (CLI)

Use the CLI to convert any `.scad` file to `.step`:

```bash
# Basic export
node dist/cli.js -i my_model.scad -o my_model.step

# Export with structural validation
node dist/cli.js -i my_model.scad --validate

# Customizing $fn resolution
node dist/cli.js -i my_model.scad --fn 32
```

### Scripting API

You can also use the library programmatically in your own TypeScript/Node.js projects:

```typescript
import { OpenScadStepEvaluator, exportSolidsToStep } from './dist/index.js';
import { Parser, Lexer, CodeFile, ErrorCollector } from 'openscad-parser';

// 1. Parse your SCAD code
const code = 'cube(10);';
const file = new CodeFile('test.scad', code);
// ... parse to AST using openscad-parser ...

// 2. Evaluate to Solid geometry
const evaluator = new OpenScadStepEvaluator();
const solids = evaluator.evaluate(ast);

// 3. Export to STEP string
const stepString = exportSolidsToStep(solids, {
author: "Your Name",
modelName: "My Part"
});
```

## Development and Testing

The project includes a comprehensive suite of over 30 tests covering geometry math, AST evaluation, and the STEP exporter itself.

```bash
npm test
```

## Project Structure

- `src/geometry.ts`: Core 3D math and CSG mesh engine.
- `src/step-evaluator.ts`: OpenSCAD AST interpreter (evaluation logic).
- `src/step-exporter.ts`: ISO-10303-21 (STEP) file formatter.
- `src/step-validator.ts`: Structural integrity checker for STEP output.
- `src/cli.ts`: Command-line interface logic.
- `src/tests/`: Comprehensive regression test suite.

## License

MIT - See the `package.json` for details.
40 changes: 40 additions & 0 deletions openscad-step-export/fixtures/complex-model.scad
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Complex model exercising CSG, modules, functions, and loops
x = 20;

function edge(v) = v * 2;

module my_part(size) {
translate([size, 0, 0]) cube(size);
}

// Loop generating translated spheres
for (i = [0:5:20]) {
translate([i, 0, i]) sphere(r=2, $fn=8);
}

// Boolean difference
difference() {
cube(size=10, center=true);
sphere(r=7, $fn=12);
}

// Boolean intersection
intersection() {
cube(size=10, center=true);
sphere(r=7, $fn=12);
}

// Hull of two cubes
hull() {
cube(2);
translate([8, 0, 0]) cube(2);
}

// Union + cone
union() {
cylinder(h=6, r1=2, r2=1, center=true, $fn=8);
translate([0, 0, -5]) cube(3, center=true);
}

// Custom module call
my_part(5);
2 changes: 2 additions & 0 deletions openscad-step-export/fixtures/simple-cube.scad
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Simple cube – smoke test
cube(10);
234 changes: 234 additions & 0 deletions openscad-step-export/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading