Tue, 07/25/2023 - 06:00
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?
Attachments:
Tue, 07/25/2023 - 12:48
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.
Fri, 07/28/2023 - 09:47
Thank you! I set the version back to 7.6.0 and solved the problem.
Wed, 07/26/2023 - 13:29
Hello,
The author do not response - in this case I will ask to create a ticket to developer team.
Best regards, Dmitrii.
Wed, 07/26/2023 - 15:26
Hello,
A ticket was created. You can track it at the link: https://tracker.dev.opencascade.org/view.php?id=33434