0 votes

I'm creating a city procedurally, for that I'm using CSG nodes in code to generate the houses, but right after I added the houses to the city, the game took forever to load.

I wanna know witch are the methods available to optimize the performance on my case.

Also, I heard that CSG nodes are just for prototyping because of the performance weight related to it, is that true?

Godot version 3.3.2
in Engine by (61 points)
edited by

hi,
why are you using CSG nodes? Why dont you use simple mesh instances?
You know, CSG nodes are for boolean operations on meshes!?

Hi, I first tried with MeshInstances, but I had problems with faces sharing the same space, now I'm using CSG nodes with union and subtract operations, witch makes a lot easier to program

CSGs being a boolean operator means that every single frame they are updated (i.e, moved or in your case added to the scene), they all have to perform a calculation on how to intersect their geometry. The more you have, the worse it gets until your game won't run anymore. In general, you can estimate their performance hit by updating them in the editor (because they lag the editor too).

But CSGs are more intended to be fully modelled (and calculated) in the editor — for now at least, there's no way to fix that terrible performance aspect at runtime, as they weren't designed with that use in mind.

You could maybe create them as a scene and instance the scene...? I'm not sure if that would still have a performance hit or not. And in using MeshInstance, maybe you could model with quads in places where you have geometry overlaps (so, more work but then you won't have overlaps).

Make sure to use separate node trees for CSG operations. Don't cram all CSG nodes under a single CSG node; only use boolean operations where you actually need them

1 Answer

+3 votes

So, basically : with CSGs —

CSGs At Work
This is their expected behaviour.

CSGs unique feature is to add or subtract together and it's why they are known as boolean operators. A CSG Combiner takes a group of CSG meshes and tries to make a singular mesh out of all of them.

Boolean Operations

It potentially has attractive video memory benefits, but if every single mesh within it has to be (re)calculated together in a single frame, your game will slow tremendously.

"Is this mesh in that mesh? If yes, then make a mesh-sized hole right there — in all 100 or so meshes." (now try and figure out how many vertexes it should have).

CSG meshes ≠ Bad

I should be clear that the issue with CSGs is predominately with the way they typically degrade performance. The meshes themselves aren't baddies:

Speedy CSG
In this case they're acting no different to MeshInstances and they're as fast or faster when spawning them from code. But it's just not the same story if you opt to utilise their design feature. So the question is do you really need them in your project?

Summarising

– Do you really need boolean operations? (to make chamfers, cutouts, holes, etc.)

Lots of Boolean Operations
– Do you need to group all your meshes under one CSG Combiner? (use multiple)

Separate Combiners don't affect each other
– It is super necessary for your project to script individual meshes at runtime?
(perhaps you could instances scenes of procedurally-ready house sections)

Instancing Scenes through Code
– Finally, could you achieve the same using a premade 3D model (Blender)?

SketchUp
Blender can be easy——ish...

I hope that it helps in some way!
Good luck!

by (992 points)
edited by

Thanks! I will think this trough, I'm considering to use pre-made chunks and add then to a GridMap

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.