kovacsv / occt-import-js

The emscripten interface for OpenCascade import functionalities.
GNU Lesser General Public License v2.1
141 stars 23 forks source link

STP model size 200M, slow speed how to solve? #8

Closed varlxw closed 1 year ago

kovacsv commented 2 years ago

Probably it's the triangulation. Adding parameters to define the quality of the result mesh (#5) should solve this.

trusktr commented 1 year ago

Can you point us to the part of the code where it interfaces with the native module to pass such options?

kovacsv commented 1 year ago

Check out this file: https://github.com/kovacsv/occt-import-js/blob/main/occt-import-js/src/importer.cpp. Triangulation quality is defined by linear and angular deflection (see this page for details). Now there is a kind of heuristics for these values based on the model size, but I think these two parameters should be available on the JavaScript interface.

static bool TriangulateShape (TopoDS_Shape& shape)
{
    Bnd_Box boundingBox;
    BRepBndLib::Add (shape, boundingBox, false);
    if (boundingBox.IsVoid ()) {
        return false;
    }

    Standard_Real xMin, yMin, zMin, xMax, yMax, zMax;
    boundingBox.Get (xMin, yMin, zMin, xMax, yMax, zMax);
    Standard_Real avgSize = ((xMax - xMin) + (yMax - yMin) + (zMax - zMin)) / 3.0;
    Standard_Real linDeflection = avgSize / 1000.0;
    Standard_Real angDeflection = 0.5;
    BRepMesh_IncrementalMesh mesh (shape, linDeflection, Standard_False, angDeflection);
    return true;
}
kovacsv commented 1 year ago

Triangulation parameters are available in version 0.0.14.