Work in progress
The content of this page was not yet updated for Godot
and may be outdated. If you know how to improve this page or you can confirm
that it's up to date, feel free to open a pull request.
Prototyping levels with CSG¶
CSG stands for Constructive Solid Geometry, and is a tool to combine basic shapes or custom meshes to create more complex shapes. In 3D modeling software, CSG is mostly known as "Boolean Operators".
Level prototyping is one of the main uses of CSG in Godot. This technique allows users to create the most common shapes by combining primitives. Interior environments can be created by using inverted primitives.
The CSG nodes in Godot are mainly intended for prototyping. There is no built-in support for UV mapping or editing 3D polygons (though extruded 2D polygons can be used with the CSGPolygon3D node).
You can check how to use CSG nodes to build various shapes (such as stairs or roads) using the Constructive Solid Geometry demo project.
Introduction to CSG nodes¶
Like other features of Godot, CSG is supported in the form of nodes. These are the CSG nodes:
CSGCylinder3D (also supports cone)
CSG tools features¶
Every CSG node supports 3 kinds of boolean operations:
Union: Geometry of both primitives is merged, intersecting geometry is removed.
Intersection: Only intersecting geometry remains, the rest is removed.
Subtraction: The second shape is subtracted from the first, leaving a dent with its shape.
The CSGPolygon3D node extrude along a Polygon drawn in 2D (in X, Y coordinates) in the following ways:
Depth: Extruded back a given amount.
Spin: Extruded while spinning around its origin.
Path: Extruded along a Path node. This operation is commonly called lofting.
The Path mode must be provided with a Path3D node to work. In the Path node, draw the path and the polygon in CSGPolygon3D will extrude along the given path.
Any mesh can be used for CSGMesh3D; the mesh can be modelled in other software and imported into Godot. Multiple materials are supported. There are some restrictions for geometry:
it must be closed,
it must not self-intersect,
it must not contain internal faces,
every edge must connect to only two other faces.
The CSGCombiner3D node is an empty shape used for organization. It will only combine children nodes.
Every CSG node will first process its children nodes and their operations: union, intersection, or subtraction, in tree order, and apply them to itself one after the other.
In the interest of performance, make sure CSG geometry remains relatively simple, as complex meshes can take a while to process. If adding objects together (such as table and room objects), create them as separate CSG trees. Forcing too many objects in a single tree will eventually start affecting performance. Only use binary operations where you actually need them.
Prototyping a level¶
We will prototype a room to practice the use of CSG tools.
Working in Orthogonal projection gives a better view when combining the CSG shapes.
Our level will contain these objects:
Create a scene with a Node3D node as root node.
The default lighting of the environment doesn't provide clear shading at some angles. Change the display mode using Display Overdraw in the 3D viewport menu, or add a DirectionalLight node to help you see clearly.
Create a CSGBox3D and name it
room, enable Invert Faces and change the
dimensions of your room.
Next, create a CSGCombiner3D and name it
A desk has one surface and 4 legs:
Create 1 CSGBox3D children node in Union mode for the surface and adjust the dimensions.
Create 4 CSGBox3D children nodes in Union mode for the legs and adjust the dimensions.
Adjust their placement to resemble a desk.
CSG nodes inside a CSGCombiner3D will only process their operation within the combiner. Therefore, CSGCombiner3Ds are used to organize CSG nodes.
Create a CSGCombiner3D and name it
Our bed consists of 3 parts: the bed, the mattress and a pillow. Create a CSGBox3D and adjust its dimension for the bed. Create another CSGBox3D and adjust its dimension for the mattress.
We will create another CSGCombiner3D named
pillow as the child of
The scene tree should look like this:
We will combine 3 CSGSphere3D nodes in Union mode to form a pillow. Scale the Y axis of the spheres and enable Smooth Faces.
pillow node and switch the mode to Subtraction; the combined
spheres will cut a hole into the mattress.
Try to re-parent the
pillow node to the root
Node3D node; the hole will
This is to illustrate the effect of CSG processing order. Since the root node is not a CSG node, the CSGCombiner3D nodes are the end of the operations; this shows the use of CSGCombiner3D to organize the CSG scene.
Undo the re-parent after observing the effect. The bed you've built should look like this:
Create a CSGCombiner3D and name it
A lamp consists of 3 parts: the stand, the pole and the lampshade. Create a CSGCylinder3D, enable the Cone option and make it the stand. Create another CSGCylinder3D and adjust the dimensions to use it as a pole.
We will use a CSGPolygon3D for the lampshade. Use the Spin mode for the CSGPolygon3D and draw a trapezoid while in Front View (numeric keypad 1); this shape will extrude around the origin and form the lampshade.