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

Allow multiple CSG meshes to be merged into one #182

Open
golddotasksquestions opened this issue Oct 24, 2019 · 10 comments
Open

Allow multiple CSG meshes to be merged into one #182

golddotasksquestions opened this issue Oct 24, 2019 · 10 comments

Comments

@golddotasksquestions
Copy link

golddotasksquestions commented Oct 24, 2019

Describe the project you are working on:
Prototype for level design.

(Currently on hiatus. salvagable.)

Describe the problem or limitation you are having in your project:
The scene tree becomes increasingly chaotic the more CSG meshes are in the scene. Besides being chaotic, performance get's worse the bigger the tree and the number of Booolean operations. There is even an explicit warning about it in the docs.
Overview in the viewport becomes worse and worse with every CSG mesh. Even as few as 3 CSG boxes make it hard to tell the wireframe of the mesh apart from all the bounding boxes!
Boolean operations are usually an intermediate step to get the part to a reusable unit. Not being able to merge CSG meshes together makes reuse ability hard and prototyping harder to manage.

csg_01
This is just 3 boxes. Can't make a level with 3 boxes.

"Make the sure the objects children are not selectable" is helping with visibility, and is great for when you want CSGs to stay open and editable, but not with performance and I still would like to have to option to commit to this shape by merging it together, freeing up all overhead that a huge open CSG mesh tree would undoubtedly entail.

Describe how this feature / enhancement will help you overcome this problem or limitation:
The true power and potential of CSG meshes unfolds when infinite reusability, recombination and remerging of CSG meshes is possible. For this to happen we need the ability to

  1. merge any CSG Meshes and CSG Primitives and
  2. change MeshesInstances into custom CSG meshes and vice versa with a simple mouse click.

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:
Viewport RMB click -> "merge CSG mesh and it's children",
Scene panel RMB click -> "merge CSG mesh and it's children",
Menu bar: RMB click -> "merge CSG mesh and it's children" ->
csg_02

Describe implementation detail for your proposal (in code), if possible:
I can't pronounce "C" with classes.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
It would be used often by Level designers, people who quickly want to block out prototypes, gamejams games that require just very basic geometry. It would also integrate brilliantly with the upcoming Gltf2 export https://github.com/godotengine/godot/issues/14752

Is there a reason why this should be core and not an add-on in the asset library?:
It would be a imho necessary improvement to an existing feature to make is more usable for production work.

@fire
Copy link
Member

fire commented Oct 24, 2019

I need to work on this, but this is usable for meshes, csg and gridmaps. godotengine/godot#32218

Future work is animated characters and materials.

@Jummit
Copy link

Jummit commented Oct 27, 2019

Does this have to be limited to CSG, or is this a tool used for all 3d meshes? It could be put in the "Mesh" dropdown.
EDIT: Just read @fire s comment and I think he has the same point.

@jabcross
Copy link

jabcross commented Feb 5, 2020

Note: by code, you can call get_meshes() on the root object to generate an ArrayMesh, which you can put in a separate MeshInstance later. Adding a button in the resource's dropdown would be pretty easy.

@SuperDIMMaX
Copy link

CSG not merge, this is limitation, but you can merge as single mesh get_meshes() or exist addon CSGExport (generate obj file).
But probality more usefull use blender or another editor for this, Godot now make non optimal CSG (generate a lot of vertex), this good only if you have procedual mesh, if you have this - get_meshes(), make mesh instance and del CSG. CSG needed if you morph mesh as boolean operation (hole in the any type wall) - i examle use for breaking glass

@Calinou
Copy link
Member

Calinou commented Sep 29, 2021

Note that for this to be done in a non-destructive way, it should create a new MeshInstance node as a sibling and hide the CSG nodes instead of removing the CSG nodes entirely after conversion. If you are certain that you won't need to edit the mesh anymore, then you can remove the CSG nodes after conveting them to a MeshInstance. (Hidden CSG nodes don't use much CPU time compared to visible CSG nodes, so you can leave them as-is in most cases.)

To make the BakedLightmap + CSG workflow quicker, we can enable UV2 and lightmap generation if a dedicated property is enabled on the selected CSG node. (The property in question needs to be added too, as use_in_baked_light will most likely be hidden from CSG nodes soon to avoid confusion.)

As for the implementation itself, there should probably be two options offered in a node context menu when a CSG node is selected:

  • Create MeshInstance Sibling
    • Use this when you want to minimize loading times and allow for lightmap baking. Does not allow for further CSG operations to be performed on the whole mesh.
  • Create CSGMesh Sibling
    • Use this when you want to merge the CSG nodes together for performance reasons. Allows for further CSG operations to be performed on the whole mesh. Does not allow for lightmap baking, and more demanding on the CPU during scene loading compared to a MeshInstance.

If needed, we can add a Shift modifier for destructive operation (indicated in a tooltip for each option). This would remove the original CSG node automatically after the operation is complete.

@gaudecker
Copy link

Note that for this to be done in a non-destructive way, it should create a new MeshInstance node as a sibling and hide the CSG nodes instead of removing the CSG nodes entirely after conversion.

This would pair nicely with the proposed editor-only nodes. You would mark the the CSG tree as editor-only, then build the MeshInstances either manually or automatically on run.

@Calinou
Copy link
Member

Calinou commented Mar 18, 2022

This would pair nicely with the proposed editor-only nodes. You would mark the the CSG tree as editor-only, then build the MeshInstances either manually or automatically on run.

If you don't intend to change CSG nodes during gameplay, there isn't much of a point to merge several CSG nodes into one, as the mesh is only built once on load. Merging meshes might improve load times a bit, but probably not by a significant margin in most scenes (especially when you factor in things like texture loading).

Merging several CSG nodes into one is useful if you intend to change CSG nodes during gameplay, or if you have a complex enough CSG tree that editing becomes very slow. However, in this case, it's usually a better idea to use less deep CSG trees with fewer nodes.

@fire
Copy link
Member

fire commented Jun 16, 2022

Working with CSG elalish/manifold#91 so I have interest in improving this.

@PiCode9560
Copy link

From what I understand, baking CSG will not be available @fire improve it. But, I don't know when It's going to be finished. For temporary solution, why can't they just allow get_meshes() to work at runtime?

@atirut-w
Copy link

atirut-w commented Sep 3, 2023

allow get_meshes() to work at runtime

As in, exposing it as a button in the editor?

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

9 participants