-
-
Notifications
You must be signed in to change notification settings - Fork 78
Migrate Replicad to OCCT v8 bindings #263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
rifont
wants to merge
37
commits into
sgenoud:main
Choose a base branch
from
taucad:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
55cc60b
feat: OCCT V8 dual WASM build (single 18.96 MB + exceptions 22.22 MB)
rifont 7fd46ee
wip: replicad-ocjs-v8
rifont 12bd9cf
wip-suffix-overload-removal
rifont 36b3cca
feat: return by value and wasm-opt-O4
rifont c7daa97
chore: format
rifont 8fe0c9a
chore: add latest opencascadejs bindings
rifont 36bbf25
fix: specify O3 instead of invalid O4 wasm-opt flag
rifont eb0ad95
build(replicad-opencascadejs): add --traps-never-happen flag to wasm-…
rifont 9ddaf4c
chore: add latest simd max-perf builds
rifont e38aa56
refactor(shapeHelpers): replace deprecated TColgp array types with NC…
rifont 598cc0b
fix(shapes): remove redundant normal consistency enforcement in mesh …
rifont 4c9541c
fix(export): fix STEP export by calling correct Transfer method
rifont 959b405
refactor(build-config): consolidate OpenCascade build configs into si…
rifont a1e6a94
chore: regenerate wasm bindings
rifont 8bcd48e
chore: bump replicad-opencascadejs version
rifont 6d22951
chore: bump replicad version
rifont db21c69
fix(shapes): clear mesh cache before remeshing with coarser tolerance
rifont 7157137
chore(replicad): clean up obsolete tarball build artifacts
rifont 08a3937
refactor(lib2d): update OpenCascade 2D curve API to v8 naming
rifont 37ca844
feat(export): add material density and PBR support to assembly exporter
rifont 775b02c
fix(shapeHelpers): replace deprecated GCE2d_MakeSegment with GC_MakeS…
rifont f5dc773
refactor(shapes): replace face iteration mesh logic with native C++ e…
rifont 37e457e
chore: bump package versions
rifont fb01a8b
chore: rebuild replicad-opencascadejs
rifont b8359b2
fix: drop relaxed-simd for safari support
rifont 651594c
refactor(export): rename metallic to metalness in ShapeConfig type
rifont f7b86c7
chore(packages): add npm publish configuration and update descriptions
rifont 79c52f0
docs: clarify origin-relative positioning in solid creation APIs
rifont d868d4c
feat(ui): migrate to ESM sub-path exp
rifont 1e065b7
chore: rebuild latest ocjs builds
rifont a9a6abe
Merge upstream replicad v0.23.3 into taucad fork
rifont 8839e02
chore: regenerate wasm builds with gp_Pln included
rifont 6ba609c
refactor(api): simplify OpenCASCADE constructor calls with default pa…
rifont 38fa556
build(replicad): change moduleResolution from node to bundler
rifont 37f8368
chore: bump package verisons to beta
rifont 55535cd
fix: reconcile tau fork with replicad v0.23.3
rifont fe7a5b6
fix(example): build worker as ES module
rifont File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # OCCT V8 Migration — replicad Perspective | ||
|
|
||
| This document covers the replicad-specific changes for the OCCT V8 migration. | ||
|
|
||
| ## Summary | ||
|
|
||
| The OCCT V8 migration consolidates replicad's three WASM builds (`single`, `with_exceptions`, `multi`) into a **single unified build** using native WASM exceptions (`-fwasm-exceptions`). | ||
|
|
||
| | Build variant | V7.6 / V8 (before) | V8 (after) | | ||
| |---|---|---| | ||
| | `replicad_single` | No exception support | Full exception support via `-fwasm-exceptions` | | ||
| | `replicad_with_exceptions` | Separate build with `-fexceptions` | **Removed** — merged into single build | | ||
| | `replicad_multi` | pthread-based multi-threading | **Removed** — deferred (see below) | | ||
|
|
||
| ## Why a Single Build? | ||
|
|
||
| ### Native WASM Exceptions (`-fwasm-exceptions`) | ||
|
|
||
| The WebAssembly Exception Handling proposal (Phase 4) is now supported by 94.5%+ of browsers (Chrome 95+, Firefox 100+, Safari 15.2+). It provides: | ||
|
|
||
| - **Zero-cost happy path**: No `invoke_SIG` wrapper overhead on every function call | ||
| - **Proper stack traces**: `WebAssembly.Exception` objects preserve the call stack | ||
| - **Smaller binary**: ~10-15% smaller than JavaScript-based exception handling (`-fexceptions`) | ||
| - **No performance penalty**: Unlike `-fexceptions`, which added ~75% binary size and measurable runtime overhead, `-fwasm-exceptions` has negligible impact on non-throwing code paths | ||
|
|
||
| This eliminates the need for a separate "with_exceptions" build. The single build has full exception decoding support with `OCJS.getStandard_FailureData()`. | ||
|
|
||
| ### Multi-threading Deferred | ||
|
|
||
| Analysis revealed that OCCT's parallel algorithms were never actually activated in the replicad codebase: | ||
|
|
||
| - `BRepMesh_IncrementalMesh`: called with `isInParallel=false` (hardcoded in `shapes.ts`) | ||
| - `BOPAlgo_Options::SetRunParallel()`: defaults to `false` | ||
| - All benchmark operations showed **slower** performance with the multi-threaded build due to pthread infrastructure overhead (SharedArrayBuffer, mutex costs, pre-spawned workers) | ||
|
|
||
| Multi-threading will be revisited when explicit parallel algorithm activation is implemented upstream. | ||
|
|
||
| ## replicad Source Changes | ||
|
|
||
| The following replicad source files were modified for OCCT V8 compatibility: | ||
|
|
||
| - **`packages/replicad/src/Sketcher.ts`**: Updated for V8 API changes | ||
| - **`packages/replicad/src/shapes.ts`**: Updated mesh and shape operations | ||
| - **`packages/replicad/src/geom.ts`**: Geometry utility updates | ||
|
|
||
| ## Build Configuration | ||
|
|
||
| ### Single V8 YAML (`custom_build_single_v8.yml`) | ||
|
|
||
| Key changes from the V7.6 configuration: | ||
|
|
||
| ```yaml | ||
| emccFlags: | ||
| - -flto # Dead-code elimination at link | ||
| - -fwasm-exceptions # Native WASM exceptions | ||
| - -sEXPORT_EXCEPTION_HANDLING_HELPERS # JS helpers for exception decoding | ||
| - -sEXPORT_ES6=1 | ||
| - -sALLOW_MEMORY_GROWTH=1 | ||
| - -sINITIAL_MEMORY=100MB | ||
| - -sMAXIMUM_MEMORY=4GB | ||
| - --no-entry | ||
| - --emit-symbol-map | ||
| - -O3 | ||
| ``` | ||
|
|
||
| Bindings include `OCJS` and `Standard_Failure` for exception decoding (previously only in the `with_exceptions` build). | ||
|
|
||
| ## Performance | ||
|
|
||
| Benchmarks show V8 is significantly faster than V7.6, especially for boolean operations: | ||
|
|
||
| | Operation | V7.6.2 (ms) | V8 Single (ms) | Delta | | ||
| |---|---|---|---| | ||
| | fuse-two-boxes | 26.6 | 20.7 | -22% | | ||
| | n-body-fuse | 65.1 | 48.3 | -26% | | ||
| | deep-boolean-chain | 132.1 | 91.7 | -31% | | ||
| | bottle | 342.3 | 254.4 | -26% | | ||
| | birdhouse | 271.1 | 198.3 | -27% | | ||
| | vase | 226.4 | 162.8 | -28% | | ||
|
|
||
| ## Package Structure | ||
|
|
||
| ``` | ||
| dist/ | ||
| replicad-opencascadejs-0.21.0-v8.XX.tgz # WASM + JS glue | ||
| replicad-0.21.0-v8.XX.tgz # replicad library | ||
| ``` | ||
|
|
||
| Consumers reference these tarballs via GitHub raw URLs: | ||
|
|
||
| ```yaml | ||
| catalog: | ||
| replicad: "https://github.com/taucad/replicad/raw/main/dist/replicad-0.21.0-v8.XX.tgz" | ||
| replicad-opencascadejs: "https://github.com/taucad/replicad/raw/main/dist/replicad-opencascadejs-0.21.0-v8.XX.tgz" | ||
| ``` | ||
|
|
||
| ## Removed Files | ||
|
|
||
| - `build-config/custom_build_with_exceptions_v8.yml` — merged into `custom_build_single_v8.yml` | ||
| - `build-config/custom_build_multi_v8.yml` — multi-threading deferred | ||
| - `src/replicad_with_exceptions.*` — no longer needed | ||
| - `src/replicad_multi.*` — no longer needed | ||
|
|
||
| See `repos/opencascade.js/docs/occt-v8-migration.md` for build-level details. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| import opencascade from "replicad-opencascadejs/src/replicad_single.js"; | ||
| import opencascadeWasm from "replicad-opencascadejs/src/replicad_single.wasm?url"; | ||
| import { setOC } from "replicad"; | ||
| import { expose } from "comlink"; | ||
| import opencascade from 'replicad-opencascadejs'; | ||
| import opencascadeWasm from 'replicad-opencascadejs/wasm?url'; | ||
| import { setOC } from 'replicad'; | ||
| import { expose } from 'comlink'; | ||
|
|
||
| // We import our model as a simple function | ||
| import { drawBox } from "./cad"; | ||
| import { drawBox } from './cad'; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make sure you run prettier (with default config) to keep the same quotes than before.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do 👍 |
||
|
|
||
| // This is the logic to load the web assembly code into replicad | ||
| let loaded = false; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .npm-pack-all-tmp |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it does - I will add a task for this to the PR description so I don't forget to update, for now it's there whilst I publish the taucad scoped package to NPM for testing.