打开级联写入 glTF Writer

Open Cascade Write glTF Writer

Open Cascade 在他们当前的开发分支中有 glTF 编写器 - RWGltf_CafWriter

我正在尝试使用它来将 STP 转换为 glTF,并从这个问题开始 - Any Open source Libraries to Convert STEP files to glTF file format?

看起来可行,但我是 Open Cascade 技术的新手,几乎没有问题

谢谢

While calculating triangulation for shapes using BRepMesh_IncrementalMesh, it needs line deflection and angle deflection, what are these and what should be its values?

Deflection parameters 定义网格质量。在特定领域/算法中,您可能应该提前知道几何形状的适用偏差(例如不超过 1 毫米)。然而,在可视化和任意 CAD 模型的上下文中,线性偏转通常是相对于文档的边界框定义的。

RWGltf_CafWriter requires TDocStd_Document and TDF_LabelSequence, how do we get these from Shapes?

TDocStd_Document 是一个 XDE document 被各种文件格式转换器支持——包括 STEP 和 glTF。如果那时你有一个来自 STEP 文件的 TopoDS_Shape,那么你可能使用了一个简化的 STEP 转换器 STEPControl_Reader。为了保留原文档的结构,最好使用STEPCAFControl_Reader填充一个XDE文档。

在 XDE 文档中,形状(不仅是形状)存储为标签,因此 TDF_LabelSequence 集合用于传递信息,如一系列根形状(文档中的模型树根) ,称为自由形状:

// read / create / fill in the document
Handle(TDocStd_Document) theXdeDoc; // created in advance

STEPCAFControl_Reader aStepReader;
if (!aStepReader.ReadFile ("myStep.stp") != IFSelect_RetDone) { // parse error }
if (!aStepReader.Transfer (theXdeDoc)) { // translation error }
...
// collect document roots into temporary compound
Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool (myXdeDoc->Main());

TDF_LabelSequence aRootLabels;
aShapeTool->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 = Prs3d::GetDeflection (aCompound, aDrawer);
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 ("exported.glb", true);
// STEP reader translates into mm units by default
aGltfWriter.ChangeCoordinateSystemConverter().SetInputLengthUnit (0.001);
aGltfWriter.ChangeCoordinateSystemConverter().SetInputCoordinateSystem (RWMesh_CoordinateSystem_Zup);
if (!aGltfWriter.Perform (theXdeDoc, aMetadata, Handle(Message_ProgressIndicator)())) { // export error }

在 Draw Harness 中,转换可能如下所示(命令的源代码可用作使用相关 OCCT 算法的工作代码的有用参考):

pload XDE OCAF VISUALIZATION MODELING
# read STEP file into XDE document
ReadStep D myStep.stp
# display the document in 3D viewer (will also compute default triangulation)
vinit
XDisplay -dispMode 1 D
vfit
# export XDE document into glTF file
WriteGltf D myGltf.glb