CSGShape3D

Inherits:GeometryInstance3D<VisualInstance3D<Node3D<Node<Object

Inherited By:CSGCombiner3D,CSGPrimitive3D

The CSG base class.

Description

This is the CSG base class that provides CSG operation support to the various CSG nodes in Godot.

Performance: CSG nodes are only intended for prototyping as they have a significant CPU performance cost.

Consider baking final CSG operation results into static geometry that replaces the CSG nodes.

Individual CSG root node results can be baked to nodes with static resources with the editor menu that appears when a CSG root node is selected.

Individual CSG root nodes can also be baked to static resources with scripts by callingbake_static_mesh() for the visual mesh orbake_collision_shape() for the physics collision.

Entire scenes of CSG nodes can be baked to static geometry and exported with the editor gltf scene exporter.

Tutorials

Properties

bool

calculate_tangents

true

int

collision_layer

1

int

collision_mask

1

float

collision_priority

1.0

Operation

operation

0

float

snap

bool

use_collision

false

Methods

ConcavePolygonShape3D

bake_collision_shape()

ArrayMesh

bake_static_mesh()

bool

get_collision_layer_value(layer_number:int)const

bool

get_collision_mask_value(layer_number:int)const

Array

get_meshes()const

bool

is_root_shape()const

void

set_collision_layer_value(layer_number:int, value:bool)

void

set_collision_mask_value(layer_number:int, value:bool)


Enumerations

enumOperation:🔗

OperationOPERATION_UNION =0

Geometry of both primitives is merged, intersecting geometry is removed.

OperationOPERATION_INTERSECTION =1

Only intersecting geometry remains, the rest is removed.

OperationOPERATION_SUBTRACTION =2

The second shape is subtracted from the first, leaving a dent with its shape.


Property Descriptions

boolcalculate_tangents =true🔗

Calculate tangents for the CSG shape which allows the use of normal maps. This is only applied on the root shape, this setting is ignored on any child.


intcollision_layer =1🔗

The physics layers this area is in.

Collidable objects can exist in any of 32 different layers. These layers work like a tagging system, and are not visual. A collidable can use these layers to select with which objects it can collide, using the collision_mask property.

A contact is detected if object A is in any of the layers that object B scans, or object B is in any layer scanned by object A. SeeCollision layers and masks in the documentation for more information.


intcollision_mask =1🔗

The physics layers this CSG shape scans for collisions. Only effective ifuse_collision istrue. SeeCollision layers and masks in the documentation for more information.


floatcollision_priority =1.0🔗

The priority used to solve colliding when occurring penetration. Only effective ifuse_collision istrue. The higher the priority is, the lower the penetration into the object will be. This can for example be used to prevent the player from breaking through the boundaries of a level.


Operationoperation =0🔗

The operation that is performed on this shape. This is ignored for the first CSG child node as the operation is between this node and the previous child of this nodes parent.


floatsnap🔗

Deprecated: The CSG library no longer uses snapping.

This property does nothing.


booluse_collision =false🔗

Adds a collision shape to the physics engine for our CSG shape. This will always act like a static body. Note that the collision shape is still active even if the CSG shape itself is hidden. See alsocollision_mask andcollision_priority.


Method Descriptions

ConcavePolygonShape3Dbake_collision_shape()🔗

Returns a baked physicsConcavePolygonShape3D of this node's CSG operation result. Returns an empty shape if the node is not a CSG root node or has no valid geometry.

Performance: If the CSG operation results in a very detailed geometry with many faces physics performance will be very slow. Concave shapes should in general only be used for static level geometry and not with dynamic objects that are moving.


ArrayMeshbake_static_mesh()🔗

Returns a baked staticArrayMesh of this node's CSG operation result. Materials from involved CSG nodes are added as extra mesh surfaces. Returns an empty mesh if the node is not a CSG root node or has no valid geometry.


boolget_collision_layer_value(layer_number:int)const🔗

Returns whether or not the specified layer of thecollision_layer is enabled, given alayer_number between 1 and 32.


boolget_collision_mask_value(layer_number:int)const🔗

Returns whether or not the specified layer of thecollision_mask is enabled, given alayer_number between 1 and 32.


Arrayget_meshes()const🔗

Returns anArray with two elements, the first is theTransform3D of this node and the second is the rootMesh of this node. Only works when this node is the root shape.


boolis_root_shape()const🔗

Returnstrue if this is a root shape and is thus the object that is rendered.


voidset_collision_layer_value(layer_number:int, value:bool)🔗

Based onvalue, enables or disables the specified layer in thecollision_layer, given alayer_number between 1 and 32.


voidset_collision_mask_value(layer_number:int, value:bool)🔗

Based onvalue, enables or disables the specified layer in thecollision_mask, given alayer_number between 1 and 32.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.