OpenCascade.js (Node.js) — TransferRoots() Very Slow (Need Optimized Way to Get Bounding Box, Faces & Vertices)

I’m using OpenCascade.js in a Node.js project to read a single-part STEP file and extract its bounding box, faces, and vertices.
The issue I’m facing is that the STEP file reading — particularly the TransferRoots() call — is taking a very long time.

Here is my code

const fileStats = fs.statSync(stepFilePath);
const stepFileSizeMB = fileStats.size / (1024 * 1024);

// ------------------------
// OpenCascade Initialization
// ------------------------
const oc = await initOpenCascade();

// ------------------------
// Read STEP into virtual FS
// ------------------------
const stepFileBuffer = new Uint8Array(fs.readFileSync(stepFilePath));
oc.FS.writeFile("/model.step", stepFileBuffer);

// ------------------------
// STEP File Reading
// ------------------------
const reader = new oc.STEPControl_Reader_1();
const status = reader.ReadFile("/model.step");
if (status !== oc.IFSelect_ReturnStatus.IFSelect_RetDone) {
throw new Error("Failed to read STEP file");
}

// ------------------------
// Transfer Roots
// ------------------------
reader.TransferRoots(new oc.Message_ProgressRange_1());
const nbShapes = reader.NbShapes();
if (nbShapes === 0) throw new Error("No shapes found in STEP file");

So, even though the STEP file is just a single part, the total processing time to read it and compute the bounding box is around 70 seconds, which is too slow for my use case. Transfer Roots alone is taking 55sec.

Could anyone please advise on:
1. How to optimize reader.ReadFile() and especially reader.TransferRoots() for better performance in OpenCascade.js?
2. Or if there’s a faster alternative to get bounding box, faces, and vertices without transferring all shapes?

If anyone can share a code snippet or example showing the most optimized approach to read large STEP files and quickly extract bounding box, faces, and vertices, it would be greatly appreciated.

Dmitrii Pasukhin's picture

Hello, There is not another way to parse file. The setting and speed can be only setup on level of building WASM module. For OCJ it is a challenge.

OpenCascade.js is old version and have not so much modern optimisation of builds. I'm working on personal project for JS build with flexible approach. Some breaf details: https://dpasukhi.github.io/OCCT-Light/

Best regards, Dmitrii.

vis god's picture

Hi Dmitrii,

Thank you for your reply and for clarifying the current limitations of OpenCascade.js. I appreciate the work you’re doing on OCCT-Light.

I wanted to ask if you are planning to release this light version publicly, and if so, when we might expect it. Also, are there any leads or workarounds I could use for now to get my job done? If not, do you know of any open source JavaScript wrapper or library that could efficiently extract bounding boxes, faces, and vertices from STEP files in Node.js or python?

Best regards,

gkv311 n's picture

The problem description is too brief to make particular suggestions.

So, even though the STEP file is just a single part, the total processing time to read it and compute the bounding box is around 70 seconds, which is too slow for my use case. Transfer Roots alone is taking 55sec.

Consider sharing some test STEP model which you expect to be loaded much faster. Compare loading time with native OCCT tools like DRAW Harness or CAD Assistant to see if performance is considerably affected by Opencascade.js or it is bad in any case.

WebAssembly technology used in Opencascade.js implies many limitations, so that even though it is quite performant, normally it is slower than a native application to some degree. Sometimes it might be considerably slower, if code hits a particular limitation badly (like an overhead for emulated C++ exceptions).

If not, do you know of any open source JavaScript wrapper or library that could efficiently extract bounding boxes, faces, and vertices from STEP files in Node.js or python?

I would expect that Python wrapper like pythonOCC should provide better performance in most cases, but if this is important or not depends on your context.