Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd triangle holes will appear in CSG subtraction #22988

Closed
fire opened this issue Oct 13, 2018 · 13 comments
Closed

Odd triangle holes will appear in CSG subtraction #22988

fire opened this issue Oct 13, 2018 · 13 comments

Comments

@fire
Copy link
Member

fire commented Oct 13, 2018

Similiar Issues:

#18476

Godot version:
43c2868

OS/device including version:
Nvidia GTX 1080 on Windows 10

Issue description:

godot windows opt tools 64_2018-10-13_08-51-52

Steps to reproduce:

Create CSG nodes consisting of a plane of sufficient size and then use a cylinder to subtract. Odd triangle holes will appear.

Minimal reproduction project:

epoch_packet_hidden_node.zip

@Toshiwoz
Copy link
Contributor

Toshiwoz commented Oct 17, 2018

I have a very similar issue but with cubes.
csg_portal_issue

As you can see from the gif, I used 3 cubes:

  • external walls
    • internal walls (subtracts)
    • entrance (subtracts)

Depending on the position of the door it shows or not the artifacts.
Does it have to do with the snap property value?
Possibly related to #21125?

@akien-mga akien-mga added this to the 3.1 milestone Oct 18, 2018
@dbenoy
Copy link

dbenoy commented Dec 5, 2018

I get a lot of artifacts when I try to subtract one aggregate union from another in this project:

image

image

Edit: Oops. Messed up archiving the project. Recreated one with similar problems.
sandbox.zip

(Using 89f8b84)

@akien-mga akien-mga modified the milestones: 3.1, 3.2 Jan 24, 2019
@Francesco149
Copy link

Francesco149 commented Apr 3, 2019

same here, running 3.1-stable on linux x86_64 on a r9 270x with the amdgpu drivers

happens on both the es2 and es3 renderers

@ShyRed
Copy link
Contributor

ShyRed commented Apr 3, 2019

Here are the results of a debugging session using the sandbox project 😅

In the sandbox project I see 3 holes and get exactly 3 failed polygon triangulations.

One example:

0.000000000,0.000000000
0.549831629,0.725973845
0.588947773,0.687405705
0.549831629,0.725973845
0.000000000,0.000000000
0.549831629,0.725973845
0.000000000,0.000000000
0.633987665,0.642996907
1.40420127,1.42415524
1.07861471,1.42415524
0.549831629,0.725973845
0.549831629,0.725973845
0.000000000,0.000000000
0.633987665,0.642996907
0.549831629,0.725973845

which looks like
image

When putting the values into some online delaunay triangulation demo, I get a working triangulation.

Just use javascript console and put in the following:

demo.addAt(0.000000000*100,0.000000000*100);
demo.addAt(0.549831629*100,0.725973845*100);
demo.addAt(0.588947773*100,0.687405705*100);
demo.addAt(0.549831629*100,0.725973845*100);
demo.addAt(0.000000000*100,0.000000000*100);
demo.addAt(0.549831629*100,0.725973845*100);
demo.addAt(0.000000000*100,0.000000000*100);
demo.addAt(0.633987665*100,0.642996907*100);
demo.addAt(1.40420127*100,1.42415524*100);
demo.addAt(1.07861471*100,1.42415524*100);
demo.addAt(0.549831629*100,0.725973845*100);
demo.addAt(0.549831629*100,0.725973845*100);
demo.addAt(0.000000000*100,0.000000000*100);
demo.addAt(0.633987665*100,0.642996907*100);
demo.addAt(0.549831629*100,0.725973845*100);

which should result in the following:

image

So my current assumption is that either our triangulation is faulty or not tolerant enough since other implementation seem to be able to triangulate the polygon just fine?

@ShyRed
Copy link
Contributor

ShyRed commented Apr 5, 2019

After some more debugging and tinkering with the source code: The failed polygons do not seem to be the ones belonging to the holes / missing triangles :( I added delaunay triangulation to CSG in case polygon triangulation fails and the resulting triangles seem to belong to the shape(s) that are being subtracted with:

image

So I suspect it really is the CSG algorithm itself that is having trouble finding and closing all holes. Polygon triangulation seems fine and the invalid polygons should indeed not be triangulated.

@bojidar-bg
Copy link
Contributor

Just a wild guess, but.. could it be that some vertices/edges/faces are assigned wrongly, thus creating the bad polygons and holes at once?

@b-sharman
Copy link

b-sharman commented May 5, 2019

I'm seeing a similar issue, but with CSG union.

Screenshot from 2019-05-04 23-11-06

Edit: Moving the ramp very slightly away from the box so that their edges don't intersect at the same point (e.g. x=0.001) fixes the issue. Towards the box works also, just as long as they don't meet exactly.

@duckinator
Copy link

Encountered this with 3.1.1.stable.official. Similar to what @nonoesimposible said, fudging values by ±0.1 seems to fix things.

Screenshot_20190608_231113

@ptrojahn
Copy link
Contributor

I found a way to fix the holes in the example by @fire. Please retest your csg shapes. If you can please upload small example projects. Screenshots are pretty hard to debug.

@fire
Copy link
Member Author

fire commented Aug 16, 2019

@ptrojahn There's a new approximate equal function that scales epsilon. It may be useful.

@fire
Copy link
Member Author

fire commented Aug 16, 2019

static _ALWAYS_INLINE_ bool is_equal_approx_ratio(real_t a, real_t b, real_t epsilon = CMP_EPSILON, real_t min_epsilon = CMP_EPSILON) {

@Toshiwoz
Copy link
Contributor

I found a way to fix the holes in the example by @fire. Please retest your csg shapes. If you can please upload small example projects. Screenshots are pretty hard to debug.

The issue opener seems to have done that:
#22988 (comment)

If you want more I can provide mine.

ptrojahn added a commit to ptrojahn/godot that referenced this issue Aug 19, 2019
Related to godotengine#22988 (Fixes the holes in the shape of
the first comment)
@fire
Copy link
Member Author

fire commented Sep 5, 2019

My original test case is solved. Please open a new issue if you have other test cases.

@fire fire closed this as completed Sep 5, 2019
pchasco pushed a commit to pchasco/godot that referenced this issue Oct 23, 2019
Related to godotengine#22988 (Fixes the holes in the shape of
the first comment)
@fire fire mentioned this issue Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests