Wed, 03/25/2026 - 11:41
I imported a simple STEP (KUKA Robot) using OCCT7.9.0, but it takes at least ten minutes each time, and sometimes the memory exceeds ten gigabytes. According to research, OCCT can fix the iteration problem caused by shape, but I use
DE_ShapeFixParameters fixParams = DESTEP_Parameters::GetDefaultShapeFixParameters();
fixParams.FixShellOrientationMode = DE_ShapeFixParameters::FixMode::NotFix;
reader.SetShapeFixParameters(fixParams);
It's useless either. I'm sorry, I really can't find any other solution. Can you give me an answer
The following is the complete code for testing, and I tried to upload the file (only 8MB), but it still shows that the file is too large
#include <STEPCAFControl_Reader.hxx>
#include <STEPControl_Reader.hxx>
#include <XtCAFControl_Reader.hxx>
#include <STEPControl_Controller.hxx>
#include <STEPCAFControl_Controller.hxx>
#include <TCollection_AsciiString.hxx>
#include <TDocStd_Document.hxx>
#include <XCAFApp_Application.hxx>
#include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ShapeTool.hxx>
#include <BinXCAFDrivers.hxx>
#include <BinMXCAFDoc.hxx>
#include <Poly_Triangulation.hxx>
#include <BRepTools.hxx>
#include <BRep_Tool.hxx>
#include <XmlXCAFDrivers.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Compound.hxx>
#include <Message_ProgressIndicator.hxx>
#include <Message_ProgressRange.hxx>
#include <Message.hxx>
#include <TDataStd_Name.hxx>
#include <TDataStd_NamedData.hxx>
#include <Interface_Static.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
const double XCAFLenUnit_General = 1;
// init STEPreader
void ApplySTEPReader(STEPCAFControl_Reader& reader, DESTEP_Parameters& params)
{
STEPControl_Controller::Init();
STEPCAFControl_Controller::Init();
Interface_Static::SetIVal("read.step.caf.content", 1);
// not load resource
Interface_Static::SetCVal("read.step.resource.name", "");
// close fix
Interface_Static::SetIVal("read.step.shape.fix_orientation", 0);
// 1) 7.9.0 config
params.ReadColor = Standard_True;
params.ReadName = Standard_True;
params.ReadLayer = Standard_True;
// FixShellOrientationMode NotFix
DE_ShapeFixParameters fixParams = DESTEP_Parameters::GetDefaultShapeFixParameters();
fixParams.FixShellOrientationMode = DE_ShapeFixParameters::FixMode::NotFix;
reader.SetShapeFixParameters(fixParams);
reader.SetColorMode(Standard_True);
reader.SetNameMode(Standard_True);
reader.SetLayerMode(Standard_True);
reader.SetPropsMode(Standard_True);
reader.SetMatMode(Standard_True);
reader.SetSHUOMode(Standard_True);
}
// Generate XCAF document (BinXCAF) and register the format
bool CreateBinXCADocument(Handle(TDocStd_Document)& outDoc) {
Handle(XCAFApp_Application) app = XCAFApp_Application::GetApplication();
if (app.IsNull()) {
std::cerr << "not create frame\n";
return false;
}
BinXCAFDrivers::DefineFormat(app);
//XmlXCAFDrivers::DefineFormat(app);
app->NewDocument("BinXCAF", outDoc);
if (!XCAFDoc_DocumentTool::IsXCAFDocument(outDoc)) {
std::cerr << "XCAF create fail\n";
return false;
}
return true;
}
/**
* @brief auto-check if the shape has triangulation, if not, generate it with the given linear deflection (precision).
* @param theShape need to check and triangulate if missing
* @param theLinDeflection precision for triangulation, typically set to meshParam.Deflection (e.g., 0.1 mm -> 0.0001 m)
*/
void EnsureTriangulation(const TopoDS_Shape& theShape, Standard_Real theLinDeflection) {
if (theShape.IsNull()) return;
Standard_Boolean hasMissingMesh = Standard_False;
// Quick scan: As long as there is a surface without a grid, it is marked as requiring processing
TopExp_Explorer anExp(theShape, TopAbs_FACE);
for (; anExp.More(); anExp.Next()) {
const TopoDS_Face& aFace = TopoDS::Face(anExp.Current());
TopLoc_Location aLoc;
// Check if the surface already has a triangular mesh
Handle(Poly_Triangulation) aTri = BRep_Tool::Triangulation(aFace, aLoc);
if (aTri.IsNull()) {
hasMissingMesh = Standard_True;
break;
}
}
// If missing grids are found, perform gridding
if (hasMissingMesh) {
//For the BRep model (STEP/XT), this step is necessary
//For the glTF model, if there is already a grid, it is usually not executed here
BRepMesh_IncrementalMesh aMesher(theShape, theLinDeflection, Standard_False, 0.5, Standard_True);
}
}
bool STEP2XCAF(Handle(TDocStd_Document)& outDoc, const std::string& stepPathUtf8) {
CreateBinXCADocument(outDoc);
if (outDoc.IsNull()) { std::cerr << "STEP2XCAF: create doc failed\n"; return false; }
STEPCAFControl_Reader reader;
DESTEP_Parameters params;
ApplySTEPReader(reader, params);
XCAFDoc_DocumentTool::SetLengthUnit(outDoc, XCAFLenUnit_General); // mm -> meters 改动
IFSelect_ReturnStatus status = reader.ReadFile(stepPathUtf8.c_str(), params);
if (status != IFSelect_RetDone) {
std::cerr << "STEP2XCAF: ReadFile failed for " << stepPathUtf8 << "\n";
return false;
}
if (!reader.Transfer(outDoc)) {
std::cerr << "STEP2XCAF: Transfer failed\n";
return false;
}
// === general mesh ===
Handle(XCAFDoc_ShapeTool) shapeTool = XCAFDoc_DocumentTool::ShapeTool(outDoc->Main());
TDF_LabelSequence freeShapes;
shapeTool->GetFreeShapes(freeShapes);
for (Standard_Integer i = 1; i <= freeShapes.Length(); i++) {
TDF_Label L = freeShapes.Value(i);
TopoDS_Shape aShape;
if (shapeTool->GetShape(L, aShape) && !aShape.IsNull()) {
EnsureTriangulation(aShape, (double)XCAFLenUnit_General / 1000);
}
}
return true;
}
int main() {
system("chcp 65001"); // UTF-8
std::string stp_path = "D:/myscripy/myQT/ModelSimConvey/FLK-KR120R27002-48LA.stp";
Handle(TDocStd_Document) Doc;
std::cout << "in STEP..." << std::endl;
STEP2XCAF(Doc, stp_path);
std::cout << "end!" << std::endl;
system("pause");
return 0;
}
Wed, 03/25/2026 - 12:28
Hello, the issue is probably fixed on latest master or 8.0.0rc3+.
If it is not about the thousands of faces - then please share you file and we will analyze. Better report issue and attache file in GitHub: https://github.com/Open-Cascade-SAS/OCCT/issues/new/choose
Best regards, Dmitrii.