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.