DiscussionsIssue archiveData Exchange and Application Framework

Archived discussion

Using new export GLTF edges functionality

Data Exchange and Application FrameworkTue, 05/06/2025 - 18:0212 replies

Browse this forum
QuestionAuthor

Hello,

I updated to the latest master branch, and am trying to save STEP files as GLTF, which would would include the edges (as was implemented here). The way I'm doing this is by opening the document, meshing with BRepMesh_IncrementalMesh, then saving with RWGltf_CafWriter::Perform.

I tried opening the resulting GLTF in the same online viewer linked in the issue, but I don't see any edges (see attached picture)

Is there some parameter that needs to be set for this to work? Is it on by default? Is there some constraint on when this can be used?

I'm attaching a binary, draco compressed file I produced with the latest master (7aa8558)

Discussion

12 archived replies

Posts are displayed in their archived order.

01Commenter-1

Hello, could you please share the original file? Do it have edges? Some topology structure can have issues, we need to check and fix them if they exist.

As for an option - writing edge is enabled by default.

Best regards, Commenter-1,

02Author

Here's the original step file attached.

Is there a sample of a Step file that should work, that I can test?

03Commenter-1

You model have no "free edges", edges which are not a part of face topology. You can check the result on the model, where the free edges or vertexes presented.

04Author

Would an approach like this work?

// 1) Read STEP into an XDE document
    Handle(TDocStd_Document) doc = new TDocStd_Document("XmlOcaf");
    STEPCAFControl_Reader reader;
    reader.SetDocument(doc);
    if (reader.ReadFile(stepFile)    != IFSelect_RetDone ||
        !reader.Transfer(doc)) {
        std::cerr << "ERROR: cannot load STEP file\n";
        return 1;
    }

    // 2) Get top-level shapes
    Handle(XCAFDoc_ShapeTool) shapeTool =
        XCAFDoc_DocumentTool::ShapeTool(doc->Main());
    TDF_LabelSequence rootShapes;
    shapeTool->GetFreeShapes(rootShapes);

    // 3) Mesh each shape (so triangles exist) and extract _all_ edges
    TopoDS_Compound edgeCompound;
    BRep_Builder builder;
    builder.MakeCompound(edgeCompound);

    for (Standard_Integer i = 1; i <= rootShapes.Length(); ++i) {
        TDF_Label lbl = rootShapes.Value(i);
        TopoDS_Shape shape = shapeTool->GetShape(lbl);

        // ensure triangulation
        BRepMesh_IncrementalMesh mesh(shape, 1e-2);

        // iterate _every_ edge and add to compound
        for (TopExp_Explorer exp(shape, TopAbs_EDGE); exp.More(); exp.Next()) {
            TopoDS_Edge edge = TopoDS::Edge(exp.Current());
            builder.Add(edgeCompound, edge);
        }
    }

    // 4) Add that compound as a new “free” shape
    TDF_Label edgesLabel = shapeTool->NewShape();
    shapeTool->SetShape(edgesLabel, edgeCompound);
    rootShapes.Append(edgesLabel);

    // 5) Export original shapes + our edge compound
    RWGltf_CafWriter writer(gltfFile, false);
    writer.Perform(
      doc,
      rootShapes,      // labels to export
      nullptr,         // no label-filter
      TColStd_IndexedDataMapOfStringString(), 
      Message_ProgressRange()
    );
05Commenter-1

Yes, looks like that it will work. You can simply adding shape to doc, by just AddShape method.

Best regards, Commenter-1.

06Author

Thanks, and if you can explain one more thing. What would the correct way be, to check if the Step file already contains these free edges or not?

07Commenter-1

Check can be done by checking edge which are not a part of wire or wires not part of face:
Free edge - edge which is not a part of Face(through Wire).

  TopExp_Explorer anExpEdge(shape, TopAbs_EDGE, TopAbs_WIRE);
  TopExp_Explorer anExpWire(shape, TopAbs_WIRE, TopAbs_FACE);
  if (!anExpEdge.More() && !anExpWire.More())
  {
    // no free edges or wires
  }

Best regards, Commenter-1.

08Author

Ok, I was able to do this. At the beginning it wasn't working, it turns out it doesn't work with gltfWriter.SetMergeFaces(true). After turning it off the edges are added to the gltf. Seems like a bug to me, I can look into this a bit.

I also found that the exported edges look dashed. I opened an issue for this here, and I have a fix for that that I will submit now.

09Commenter-1

Yes, it looks like as a bug. Thank you.

Best regards, Commenter-1.

10Author

Hi Dmitrii,
Found a fix for the merged faces: https://github.com/Open-Cascade-SAS/OCCT/pull/554
Note that this reverts the fix with the linestrip I previously submitted. Details in the PR.

11Author

Is it possible to create these free edges from the original model, so that they are displayed in the gltf file?

12Commenter-2

Hey !
Did you find the solution ?