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

Add boolean operator nodes in 2D (CSG) #39

Merged
merged 66 commits into from
Dec 9, 2020
Merged

Add boolean operator nodes in 2D (CSG) #39

merged 66 commits into from
Dec 9, 2020

Conversation

Xrayez
Copy link
Contributor

@Xrayez Xrayez commented Nov 22, 2020

goost_csg_2d

goost_csg_2d_decomp

Closes godotengine/godot-proposals#200, helps goostengine/goost-examples#1.

This implements CSG-like behavior as seen in Godot's CSG system: https://docs.godotengine.org/en/stable/tutorials/3d/csg_tools.html

  1. The core behavior is provided by PolyNode2D class which does have boolean operators (including XOR, which Godot doesn't have). The node can also be used for representing polygons with hierarchical structure, with inner and outer relationships between them.

  2. PolyNode2D does not provide methods/properties to use it as a collision object. Instead, a new PolyCollisionShape2D is added (inherits new PolyShape2D which just builds convex/concave geometry), and which acts analogously to CollisionPolygon2D, except that it uses PolyNode2D as children to build collision shapes from. This makes it quite flexible to use, and not necessarily restricted to static bodies, but also things like defining area/navigation/light occluders which also may reuse those.

  3. Primitives are implemented as geometry generators. For now that's PolyCircle2D and PolyRectangle2D. Again, unlike in Godot, those are not named as PolyCircleShape2D, because "Shape" terminology is reserved to lean closer to collision shapes or other similar functionality.

  4. PolyNode2D may be set as open (polylines) or closed (polygons). Clipping lines with polygons is also possible, but the support for such operations is not priority to make perfect.

Geometry can be edited just like CollisionPolygon2D when you select PolyNode2D. Textures (with normalmap) and color for drawing can also be set.

goost_poly_node_2d

I believe this feature is the most powerful behind Goost out of all at this point. 🙂

To-do

There are quite a bunch of things which has to be ironed out, but current implementation is more or less usable so I'd appreciate any feedback at this point.

  • Write documentation.
  • Write unit tests.
  • Add editor icons for new classes.

@Xrayez Xrayez added enhancement Improvement of existing features discussion Further information is requested breaks compat Compatibility breakage feature 💡 New feature proposal labels Nov 22, 2020
This is only done in C++, the binding code still constructs a new node.
Fixes drawing with final transform, introduces color property per each node.

Added a bunch of other methods to collect polygons and polylines.
Greatly simplifies boolean operations, `is_hole` renamed to `is_inner`
to denote hierarchical representation of nodes, and not necessarily
geometrical meaning.
Some of these may still make sense, but can be reimplemented later.
Drawing is per node now, but mostly parent is responsible.
Outlines from operations such as difference can be implemented
in canvas editor plugin instead.
Allows to edit points.
The warning suggests that such nodes should be converted to `PolyNode2D` instead, this will be implemented.

One issue still persists: I haven't found a way to move `PolyCircle2D` in the editor unless you use the move tool explicitly.
@Xrayez Xrayez removed the discussion Further information is requested label Nov 29, 2020
@Xrayez
Copy link
Contributor Author

Xrayez commented Dec 3, 2020

Here's what editor icons look like (also an example of how these nodes can be used):

image

@Xrayez
Copy link
Contributor Author

Xrayez commented Dec 9, 2020

I think I'm done feature-wise, there are certainly things which can be improved and even added, especially documentation, but that's good enough to use, I encourage anyone to test those classes out.

If those are not intuitive to use, then perhaps the usage could be documented at https://goost.readthedocs.io/en/gd3/components/geometry.html.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaks compat Compatibility breakage component:geometry 📐 enhancement Improvement of existing features feature 💡 New feature proposal topic:core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add boolean operations to 2D collision objects
1 participant