godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.72k stars 21.12k forks source link

Polygon2D (with multiple parts) fails to mask with Clip Children when Inverted on #91068

Open grunthos-dev opened 6 months ago

grunthos-dev commented 6 months ago

Tested versions

Reproducible in: 4.3-dev5, 4.2.1-stable, 4.1.3-stable

System information

Godot v4.2.2.rc3 - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2070 SUPER (NVIDIA; 31.0.15.5152) - Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz (8 Threads)

Issue description

When using a Polygon2D of multiple parts (using the Polygons array to define them via their point indices), it will correctly mask its children when Clip Children is set to Clip Only. However if you Invert the polygon, the masking fails to give the expected 'opposite' result. It doesn't matter if the boxes are created clockwise or anticlockwise.

I hope this is a legal and valid method of doing this.. I'm using this video as a guide... https://www.youtube.com/watch?v=NvJuW7ruuN0

PolygonInvertedClippingBugA_annotated

PolygonInvertedClippingBugB_annotated

PolygonInvertedClippingBugC_annotated

Steps to reproduce

We need to make a Polygon2D whose points define two separate boxes and use the Polygons array to define them via their indexes 0-3 for one and 4-7 for the other.

  1. In a new scene, add a Polygon2D and create a box with 4 points.
  2. In the inspector for the polygon, manually add 4 more points with Add Element for a total of 8. Drag these new points to form a second box to the side (see picture).
  3. In the Inspector, under the Data/Polygons section, increase the array Size to 2.
  4. For each array, change the type from null to PackedInt32Array.
  5. Under the first PackedIn32Array, add 4 elements and insert values 0 to 3
  6. Under the second PackedIn32Array, add 4 elements and insert values 4 to 7
  7. Drag the gogot icon.svg into the viewport and overlap the edges of both boxes of the polygon.
  8. Make the icon a child of the Polygon2D and set the polygon's Clip Children to Clip Only.
  9. This shows the masking working correctly.
  10. If you now set the polygon's Invert flag to ON, it fails. It does not give the expected result of clipping out the opposite parts of the sprite.

Minimal reproduction project (MRP)

PolygonInvertedClippingBug.zip

ajreckof commented 6 months ago

It looks like the polygons property is outright ignored and it treats it as if it was one big polygon.

aXu-AP commented 6 months ago

I tested it a bit, and it seems that Clip Children has nothing to do with the bug, it occurs without it also: kuva kuva As mentioned above, it seems that as of yet there simply isn't implementation for combination of clip children and polygons.