Archived discussion

Convert from GLTF to STEP

pythonOCCMon, 08/19/2024 - 15:063 replies

Browse this forum
QuestionAuthor

Hi,

I am trying to make simple converter from GTLF (GLB) to STEP format. I am using a simple box as my test input (see attached .zip).

Reading of the GTLF file seems to work fine using:

# Create an handle to a document
doc = TDocStd_Document("gltf-convert-doc")
# Create GLTF reader
gltf_reader = RWGltf_CafReader()
gltf_reader.SetDocument(doc)
read_status = gltf_reader.Perform(input_filename, Message_ProgressRange())
if read_status != IFSelect_RetDone:
  raise AssertionError("Could not load GLTF file")
# Get as single shape
shape = gltf_reader.SingleShape()

I get a single compound top level shape with 6 faces.

If i display it with:

# Display GLTF shape
display, start_display, add_menu, add_function_to_menu = init_display()
display.DisplayShape(shape, update=True)
start_display()

Everything looks fine and box appears.

For converting and writing to STEP I am doing the following:

# Create STEP writer
step_writer = STEPControl_Writer()
Interface_Static.SetCVal("write.step.schema", "ap203")
# transfer shapes and write file
step_writer.Transfer(shape, STEPControl_AsIs)
write_status = step_writer.Write(output_filename)
if write_status != IFSelect_RetDone:
    raise AssertionError("Could not write STEP file.")

Which seems to be working. It produces a .stp file with content. But when I open the file with a CAD program (such a CAD Assistant) it shows nothing (see attached screenshot).

Any insight would be much appreciated.

Discussion

3 archived replies

Posts are displayed in their archived order.

01Commenter-1

Hello, you trying to export mesh format into BRep format. In that case there are a few limitations.

1. CAD Assistent based on old OCCT and do not support STP with mesh

2. STP format support mesh only on AP214 and AP242. But I really recommend to use ONLY AP242

3. OCCT older then 7.7 do not support import or export STP files with mesh.

Best regards, Commenter-1

02Author

Thank you for the response.

I and using OCCT 7.8.1 and I have tried switching to AP242 with:

Interface_Static.SetCVal("write.step.schema", "AP242DIS")

I tried opening the converted .stp file in FreeCAD this time. However the result is the same, just an empty document.

I have also attempted to convert the shape into BRep format (probably naively so) using:

# Create builder and shell
builder = BRep_Builder()
shell = TopoDS_Shell()
builder.MakeShell(shell)
# Iterate over faces and add to shell
it = TopoDS_Iterator(shape)
while it.More():
  face = it.Value()
  builder.Add(shell, it.Value())
  it.Next()

# Create solid and add shell
solid = TopoDS_Solid()
builder.MakeSolid(solid)
builder.Add(solid, shell)

print("Solid topology")
dump_topology_to_string(solid)

With the topology dump output:

Solid topology
<class 'TopoDS_Solid'>
..<class 'TopoDS_Shell'>
....<class 'TopoDS_Face'>
....<class 'TopoDS_Face'>
....<class 'TopoDS_Face'>
....<class 'TopoDS_Face'>
....<class 'TopoDS_Face'>
....<class 'TopoDS_Face'>

But also no luck, is displays fine using DisplayShape(...), but the step file seems blank when opening, even though the file itself is not empty.

Is there another approach I could take for this type of conversion or what am I missing?

03Commenter-1

FreeCAD based on OCCT, Im not sure about their version.

Could you check the file content and check that file contains some faces inside as a a lot of doubles and so one.

Or could you share result file?

Related topics:

Error when build triangle meshes - Forum Open Cascade Technology

STL to STEP - Forum Open Cascade Technology

Best regards, Commenter-1.