godot icon indicating copy to clipboard operation
godot copied to clipboard

Subtracting two CSG box nodes from a box can generate a floating triangle

Open 31 opened this issue 1 year ago • 9 comments
trafficstars

Tested versions

  • 4.2.1
  • 4.3-dev1

System information

Godot v4.3.dev1 - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2080 Ti (NVIDIA; 31.0.15.4584) - Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz (16 Threads)

Issue description

Subtracting two CSGBox nodes from one larger CSGBox gave me a floating triangle:

image

I normally hit this in more complicated level prototyping situations, but it's pretty easy (at least with my luck 😄) to reproduce with simple subtractions like this, too.

Wiggling one of the boxes a little can get a good mesh, but this only works after noticing the issue. When making level geometry prototypes, I often end up with missing/extra triangles that I didn't notice on the first pass. Wiggling a node that is already involved in the level (e.g. it has things placed on top of it) also causes more work to get everything placed right again.

Steps to reproduce

The MRP contains a camera pointed at the triangle and lighting to make it easier to see when running the scene. It should look like the screenshot.

Minimal reproduction project (MRP)

CSGSubtractRepro.zip

More at https://github.com/31/godot-csg-mesh-repro

31 avatar Dec 27 '23 22:12 31

There hasn't been much work in the CSG code and I've been busy, so poke me if you want to investigate. I can give you a tour of where the code is on discord.

https://github.com/godotengine/godot/blob/master/modules/csg/csg.cpp#L283-L463

fire avatar Dec 28 '23 00:12 fire

Thanks for the offer, but after reading this earlier issue I found:

  • https://github.com/godotengine/godot/issues/58637

I'm not sure working on this rather than trying to find an alternative would actually be the best for my project. I do also use coplanar faces quite frequently, and don't need good performance. Based on that issue, it seems that good performance is considered a core requirement of Godot's CSG for compatibility reasons and making Godot's fast CSG handle all cases might not be feasible.

Maybe I could figure out how to add a slow layer on top of Godot's CSG that e.g. detects that the mesh isn't manifold and "shakes" nearby nodes. 😄 However, if I'm using subtraction to e.g. make a tunnel (involving coplanar faces), random shaking could lead to the tunnel being totally blocked rather than open, so it is probably not so simple.

Even just detecting non-manifold CSG output would at least help with level design by letting me know the CSG nodes need some manual shaking before I put things on the floor. It would also make it easier to catch bad cases and report them.

For now, I've added a few more examples at https://github.com/31/godot-csg-mesh-repro: one uses coplanar faces, and one uses near-coplanar faces and ends up with a missing triangle.

31 avatar Dec 28 '23 01:12 31

I think a way to detect non-manifold as a ui element would help.

Even just detecting non-manifold CSG output would at least help with level design by letting me know the CSG nodes need some manual shaking before I put things on the floor. It would also make it easier to catch bad cases and report them.

fire avatar Dec 28 '23 05:12 fire

I confirm this has been an issue even in 3.5. In a project we have, CSG subtraction was required during random generation, causing these to happen at complete random. I'm unsure on what the workaround is. "Shaking the CSG nodes" is not good enough in a random situation.

Mickeon avatar Jan 06 '24 17:01 Mickeon

Changing the snap to 0.0001 from 0.001 causes this test case to pass.

image

fire avatar Apr 20 '24 14:04 fire

Any thoughts on setting snap to

  1. 0.000001 meters is equal to 0.001 millimeters. A typical bacterium measures between 1 and 10 microns.
  2. 0.00001 meters is equal to 0.01 millimeters. Small scale models (e.g., mechanical parts, jewelry).

from:

ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "snap", PROPERTY_HINT_RANGE, "0.000001,1,0.000001,suffix:m"), "set_snap", "get_snap");

fire avatar Apr 20 '24 15:04 fire

editor_screenshot_2024-05-08T204422

Testing some csg bug cases on a bugfix pr.

fire avatar May 09 '24 03:05 fire

@fire What is the PR in question?

Mickeon avatar Jul 05 '24 20:07 Mickeon

https://github.com/godotengine/godot/pull/91748

fire avatar Jul 05 '24 21:07 fire

Fixed by: https://github.com/godotengine/godot/pull/94321

fire avatar Nov 30 '24 01:11 fire