test_stack.gd 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. extends Test
  2. @export_range(1, 100) var height = 10
  3. @export_range(1, 100) var width = 1
  4. @export_range(1, 100) var depth = 1
  5. @export var box_size = Vector3(1.0, 1.0, 1.0)
  6. @export var box_spacing = Vector3(0.0, 0.0, 0.0)
  7. func _ready():
  8. _create_stack()
  9. func _create_stack():
  10. var root_node = $Stack
  11. var template_body = create_rigidbody_box(box_size, true)
  12. var pos_y = 0.5 * box_size.y + box_spacing.y
  13. for level in height:
  14. var row_node = Node3D.new()
  15. row_node.transform.origin = Vector3(0.0, pos_y, 0.0)
  16. row_node.name = "Row%02d" % (level + 1)
  17. root_node.add_child(row_node)
  18. var pos_x = -0.5 * (width - 1) * (box_size.x + box_spacing.x)
  19. for box_index_x in width:
  20. var pos_z = -0.5 * (depth - 1) * (box_size.z + box_spacing.z)
  21. for box_index_z in depth:
  22. var box_index = box_index_x * box_index_z
  23. var box = template_body.duplicate()
  24. box.transform.origin = Vector3(pos_x, 0.0, pos_z)
  25. box.name = "Box%02d" % (box_index + 1)
  26. row_node.add_child(box)
  27. pos_z += box_size.z + box_spacing.z
  28. pos_x += box_size.x + box_spacing.x
  29. pos_y += box_size.y + box_spacing.y
  30. template_body.queue_free()