Get_meshes() on CSGPolygon3D breaks unionization with sibling

Godot Version

4.2.1 Stable

Question

I have developed an editor plugin that allows you to run get_meshes() on a selected CSGShape3D and creates a new node whose mesh property is set to that of the CSGShape3D.

Of course, get_meshes() doesn’t return anything if the selected CSGShape3D is not the root shape, but I’ve worked around this by temporarily reparenting the shape to the editor tree’s root, running get_meshes while it is the root shape, then reparenting again to its previous parent, as if it has never left.

This works for the most part in isolation, but as soon as you have a tree that looks like this:

  • Node3D
    • CSGCombiner3D
      • CSGPolygon3D ← selected
        • ChildCSGPolygon3D
      • SiblingCSGPolygon3D

…and run my plugin against the selected node, it breaks or inverts some of the faces.

Here is footage of the issue:

Minimal reproduction suite: bm-csg-to-mesh-instance.zip - Google Drive

Select this CSGPolygon3D:
image

Then, ensure the “replace” checkbox is checked before clicking on “To CSGMesh3D”
image

Observe that the face on the red side suddenly closes up:

Other things I have tried:

  • Creating an ordinary MeshInstance3D node using my plugin, copying the ArrayMesh in the resultant MeshInstance3D in the inspector, pasting as the Mesh resource a brand-new CSGMesh3D node, then attempting to unionize this way.

I’m wondering if this is an issue with my plugin or an issue with CSG trimeshes in general.

Thanks for your help!