Fail to Convert Geom_RectangularTrimmedSurface in Step Files to Gltf Files

Hi guys! I am trying to convert step files to gltf files. However, one Geom_RectangularTrimmedSurface which is a cylindrical surface in a step file is converted to a spherical surface in the gltf file. Quite confusing! Here is my code (from official sites):

int main(int argc, char* argv[]) {
    const char* stepFileName = "C:\\Programs\\step2gltf\\test\\Case2_GEAR.step";
    const char* gltfFileName = "C:\\Programs\\step2gltf\\gltf\\Case2_GEAR_Official.glb";

    // Create XDE document
    Handle(TDocStd_Document) doc;
    Handle(XCAFApp_Application) app = XCAFApp_Application::GetApplication();
    BinXCAFDrivers::DefineFormat(app);
    app->NewDocument("BinXCAF", doc);

    // Parse step file into XDE document
    STEPCAFControl_Reader reader;
    IFSelect_ReturnStatus readStat = reader.ReadFile(stepFileName);
    reader.Transfer(doc);

    Handle(XCAFDoc_ShapeTool) shapeTool = XCAFDoc_DocumentTool::ShapeTool(doc->Main());
    TDF_LabelSequence aRootLabels;
    shapeTool->GetFreeShapes(aRootLabels);

    TopoDS_Compound aCompound;
    BRep_Builder    aBuildTool;
    aBuildTool.MakeCompound(aCompound);
    for (TDF_LabelSequence::Iterator aRootIter(aRootLabels); aRootIter.More(); aRootIter.Next())
    {
        const TDF_Label& aRootLabel = aRootIter.Value();
        TopoDS_Shape aRootShape;
        if (XCAFDoc_ShapeTool::GetShape(aRootLabel, aRootShape))
        {
            aBuildTool.Add(aCompound, aRootShape);
        }
    }

    // perform meshing
    Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer(); // holds visualization defaults
    BRepMesh_IncrementalMesh anAlgo;
    anAlgo.ChangeParameters().Deflection = 0.1;
    anAlgo.ChangeParameters().Angle = 20.0 * M_PI / 180.0; // 20 degrees
    anAlgo.ChangeParameters().InParallel = true;
    anAlgo.SetShape(aCompound);
    anAlgo.Perform();

    // write or export the document
    TColStd_IndexedDataMapOfStringString aMetadata;
    RWGltf_CafWriter aGltfWriter(gltfFileName, true);

    // STEP reader translates into mm units by default
    aGltfWriter.ChangeCoordinateSystemConverter().SetInputLengthUnit(0.001);
    aGltfWriter.ChangeCoordinateSystemConverter().SetInputCoordinateSystem(RWMesh_CoordinateSystem_Zup);
    Message_ProgressRange optionalIndicator;
    if (!aGltfWriter.Perform(doc, aMetadata, optionalIndicator))
    {
        // export error
    }
}

Is there any way to fix this problem?

gkv311 n's picture

This is a regression since OCCT 7.7.0 (or a broken STEP file) - the model is read as expected by OCCT 7.6.0.

The best thing would be reporting a bug on Bugtracker.

pload XDE VISUALIZATION
testreadstep Case2_GEAR.step s
vinit View1
vdisplay s -dispMode 1
vfit
Rick Rich's picture

Thank you! I set the version back to 7.6.0 and solved the problem.

Dmitrii Pasukhin's picture

Hello,

The author do not response - in this case I will ask to create a ticket to developer team.

Best regards, Dmitrii.

Irina CHESNOKOVA's picture

Hello,

A ticket was created. You can track it at the link: https://tracker.dev.opencascade.org/view.php?id=33434