How can I get the AABB from a Shape3D?

Godot Version

4.1.3-stable

Question

For context:

I am making a 3D game, for the levels, I’m using the TBLoader plugin to import geometry from the Trenchbroom level editor (.MAP files).
The plugin comes with configuration for Trenchbroom so it can detect textures from my Godot project, along with that, it adds the functionality of brushes (geometry) being flagged as Area3D. Causing them to be imported as Area3D instead of StaticBody3D.

The problem:

For my game, I have added a door system that uses body_entered-body_exited signals to detect the player so it can open and close accordingly. The problem arises in the fact TBLoader imports Area3D geometry as a ConcaveShape3D, this causes the Area3D to signal body_exited causing the door to close for some reason while I’m entering the Area3D, this does not happen with a BoxShape3D.
I have a premade door scene I can instantiate to evade this problem but sometimes I need to make a door of a different size or have it use a custom animation, for this I need to set the door up manually and part of this process is converting the ConcaveShape3D to a BoxShape3D so the door can function properly.

I’m working on a custom plugin specialized for my game to speed up level development by automating repetitive tasks like this. The way I thought of automating this task is getting the AABB of the ConcaveShape3D and using its size and position as the size and position of a BoxShape3D. Sound good in theory but there is no direct way of getting the AABB of an Area3D, CollisionShape3D, or a Shape3D resource.

Nothing I’ve tried works, can anyone help?

You could try creating the AABB like:

func _ready() -> void:
	var shape = $CollisionShape3D.shape as ConcavePolygonShape3D
	var aabb = AABB()
	for face in shape.get_faces():
		aabb = aabb.expand(face)
	print(aabb)
2 Likes

Works flawlessly!