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 a general-purpose CSGConvexHull3D node #9933

Open
31 opened this issue Jun 9, 2024 · 5 comments
Open

Add a general-purpose CSGConvexHull3D node #9933

31 opened this issue Jun 9, 2024 · 5 comments
Labels

Comments

@31
Copy link

31 commented Jun 9, 2024

Describe the project you are working on

A game that includes a 3d modeling tool using CSG, where "fill all the space between this set of points" is a common operation, and the result must be displayed as a mesh.

Describe the problem or limitation you are having in your project

It's not trivial to create a triangle mesh from a 3d convex hull. It's hard to find a library that properly handles common edge cases (faces with more than 3 vertices, which occurs in something as simple as a common cube). Godot has some features available that use convex hulls (especially collision), but none do meshing.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

CSGConvexHull3D, a simple CSG node that has points and makes it into a convex hull mesh compatible with the rest of the CSG system.

  • There's no need for a nice editor GUI for setting up points in my case because I will be using this node programmatically.
  • For people who will use it in the editor, they may want to write their own Tool script that adds functionality on top, to make it easy to use for specific common shapes in their particular game. (However, an integrated points editor might be useful for very organic and one-off shapes.)

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

PR godotengine/godot#94321 integrates Manifold, which seems to have good convex hull meshing support. I wrote up a draft CSGConvexHull3D node implementation based on that PR here: godotengine/godot@25cc9b0.

I'm not familiar with https://github.com/godotengine/godot/blob/5833f597865c773fae3ee09fc4e31d4a243f812d/core/math/convex_hull.h and if it creates good meshes, but it's not usable from game code. If the API were exposed, it might be reasonable to use this to generate a mesh to pass into CSGMesh3D. I suspect that would be relatively slow.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No.

Is there a reason why this should be core and not an add-on in the asset library?

In theory I could create a 3d convex hull mesh by bringing in some other library or implementation and then pass the result into CSGMesh3D, but there are reasons I don't want to try:

  • Godot already has convex hull logic. Any additional library would be extra weight.
  • It wouldn't be able to benefit from any optimizations that can happen due to keeping the hull in a more "native" format.
  • It's (generally speaking) difficult to get this kind of code working in all exports as an asset/GDExtension rather than as a module/fork.

Related:

@Calinou
Copy link
Member

Calinou commented Jun 10, 2024

Does this have to be a CSG mesh? I'm concerned about adding more CSG meshes without an equivalent PrimitiveMesh, as this can encourage users to use slow CSG functionality when it's not needed. We have the same problem with CSGPolygon3D's Path mode, which lacks a PrimitiveMesh equivalent.

CSG meshes also don't support UV2 generation for lightmapping, while primitive meshes do.

@31
Copy link
Author

31 commented Jun 10, 2024

Does this have to be a CSG mesh?

No, it doesn't need to be a CSGPrimitive3D, but the cost is (potential) performance. That's what this is about from the proposal:

[Passing a convex hull mesh into the CSGMesh3D node] wouldn't be able to benefit from any optimizations that can happen due to keeping the hull in a more "native" format.

Internally, the CSG system could avoid creating a Godot mesh until it has applied all the CSG operations using Manifold, and avoid some pointless conversions back and forth. (Does it do this? Maybe not, but it seems like fairly obvious potential to me. 😄)

I'm concerned about adding more CSG meshes without an equivalent PrimitiveMesh, as this can encourage users to use slow CSG functionality when it's not needed. We have the same problem with CSGPolygon3D's Path mode, which lacks a PrimitiveMesh equivalent.

That's reasonable, I have nothing against also adding meshes for this, and for path-mode polygons as well.

Another factor: it was super easy to add the CSG node because all the functionality is right there for interop with Manifold. I'm not sure it would be so easy with meshes. For practical reasons I want to file a proposal with a ready implementation to try to get it done sooner rather than waiting for someone who knows how to implement it as a mesh--which might never happen. (It looks pretty overwhelming to me, personally.)

@fire
Copy link
Member

fire commented Jun 16, 2024

I support this proposal. Hulling and keeping the promise of manifold, is not trivial to do. I think manifold is the primary FOSS library that can do this.

@fire
Copy link
Member

fire commented Nov 12, 2024

It still needs to have a points editor by default.

Would you have any thoughts on using @celyk 's points editor plugin? I'll poke for more details.

@celyk
Copy link

celyk commented Nov 14, 2024

Hello! I recently made a plugin called VertexHandles that allows you to edit the vertices of a Mesh when placed under a MeshInstance3D. The code could be modified to generate a mesh based on the points instead. I hope this helps!

VertexHandles_demo.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants