DEV Community

cadprobs cadprobs
cadprobs cadprobs

Posted on

Reading a STEP file's volume and weight in the browser: what actually happens

STEP (ISO 10303) files don't contain triangles. They describe exact B-rep surfaces. So "how much does this part weigh?" is a geometry question before it's a math question.

1. Parse and tessellate. In the browser, the usual route is OpenCascade compiled to WebAssembly (e.g. occt-import-js). It reads the B-rep and triangulates each face. Finer tessellation means more accurate volume and more memory.

2. Integrate the volume. For a closed, consistently-oriented mesh, volume = Σ signed tetrahedra from the origin: V = Σ (v1 · (v2 × v3)) / 6. Open shells give garbage, so check watertightness first.

3. Multiply by density. Steel ≈ 7.85 g/cm³, aluminium ≈ 2.70, PLA ≈ 1.24. Watch units: most STEP files are mm, so mm³ → cm³ is /1000.

4. Gotchas. Assemblies with overlapping bodies double-count; surface-only IGES/STEP has no volume; unit headers are sometimes wrong (an inch file read as mm is off by 16.4³).

CADProps guest workflow showing a three-step Choose, Check, Finish panel for checking a file's units, scope and warnings

If you want to try it without writing code, FreeCAD (Shape.Volume) is the desktop reference. Disclosure: I work on CADProps, a free browser tool built this way: the STEP weight calculator and a plain STEP viewer.

Top comments (0)