Files
MovementTests/tools/generate_collisions.gd
Minimata d15542e4ed
Some checks failed
Create tag and build when new code gets to main / BumpTag (push) Successful in 7s
Create tag and build when new code gets to main / Export (push) Has been cancelled
ported to Godot 5 and fixed collisions on tooling script
2025-09-16 09:40:20 +02:00

41 lines
1.3 KiB
GDScript

@tool
extends Node3D
@export_tool_button("Generate collisions", "Callable") var generate_col_action = generate_collisions
@export_group("Layers and masks")
@export_flags_3d_physics var collision_layer
@export_flags_3d_physics var collision_mask
func get_all_children_of_type(node, type) -> Array:
var nodes : Array = []
for child in node.get_children():
if is_instance_of(child, type):
nodes.append(child)
if child.get_child_count() > 0:
nodes.append_array(get_all_children_of_type(child, type))
return nodes
func clear_collisions_on_meshes(meshes: Array):
for mesh_instance: MeshInstance3D in meshes:
for child in mesh_instance.get_children():
child.queue_free()
func generate_collisions_on_meshes(meshes: Array):
for mesh_instance: MeshInstance3D in meshes:
mesh_instance.create_trimesh_collision()
func set_collision_mask_on_bodies(bodies: Array):
for staticbody: StaticBody3D in bodies:
staticbody.collision_layer = collision_layer
staticbody.collision_mask = collision_mask
func generate_collisions():
var mesh_instances = get_all_children_of_type(self, MeshInstance3D)
clear_collisions_on_meshes(mesh_instances)
generate_collisions_on_meshes(mesh_instances)
var staticbody_instances = get_all_children_of_type(self, StaticBody3D)
set_collision_mask_on_bodies(staticbody_instances)