tpaviot/pythonocc-core

Location not updated by `BRep_Tool.Triangulation`?

Opened this issue · 2 comments

I am reimplementing the logic in the upstream STL writer in pythonocc-core in order to obtain a surface mesh without having to resort to File I/O, and it seems that calling BRep_Tool.Triangulation should update the TopLoc_Location it is passed, but, at least according to its DumpJSON method, this is not happening. Here's the core of my traversal loop:

    exp = TopExp_Explorer(shape, TopAbs_FACE)
    while exp.More():
        face = exp.Current()
        if face.Orientation() == TopAbs_REVERSED:
            print("FIXME Reversed face")

        loc = TopLoc_Location()
        tri = BRep_Tool.Triangulation(face, loc)
        if tri:
            trsf = loc.Transformation()
            for i in range(tri.NbNodes()):
                p = tri.Node(1+i)
                p.Transform(trsf)
                nodes.append([p.X(), p.Y(), p.Z()])

A full self-contained example is also available.

In the full example, I am trying to mesh a box. STL export (ostensibly using the OCCT C++ code above) works fine, but with my reimplementation, I get a mesh that looks like this:

Image

I.e. all faces of the box seem to coincide in one plane, seemingly consistent with lack of transformation information.

Not sure the problem comes from the point coordinates, maybe the face definition is wrong.

Thanks for following up!

maybe the face definition is wrong.

I'm sorry, I don't understand what that means. Could you explain?