xyz Im sorry for not being able to make my problem clear. As i thought that my first post was clearly defined. I want to get a certain point (furthest extent in one axis) in global coordinates no matter how mesh/node is rotated.
Following your advice on using aabb ive concluded that it gives me wrong values, no matter which of your suggestion i implement.
So far i have not found a solution based on official documentation and your suggestions.
I reorganized the code and nodes so it would be easier to track.
extends Node3D
@onready var red_plane: Node3D = $Red_plane
@onready var meshy_node: Node3D = $MeshyNode
var global_aabb:AABB
var arr_y = []
func _ready() -> void:
var mesh_array = meshy_node.get_children()
for mesh in mesh_array:
var mesh_aabb = mesh.get_aabb()
var mesh_glob_trans = mesh.global_transform
var glob_mesh_aabb = mesh_aabb * mesh_glob_trans
global_aabb = global_aabb.merge(glob_mesh_aabb)
var arr = []
for i in range(8):
var pt = global_aabb.get_endpoint(i)
arr.append(pt)
for p in arr:
arr_y.append(p.y)
print("pos1: ",global_aabb.position)
print("siz1: ",global_aabb.size)
print("end1: ",global_aabb.end)
print("arr: ",arr)
print("arr_y: ",arr_y)
print("arr_y max: ",arr_y.max())
func _process(delta: float) -> void:
red_plane.global_position.y = lerp(red_plane.global_position.y,arr_y.max(),0.8*delta)
pass
Result
pos1: (-0.200719, -4.347878, -3.79828)
siz1: (2.579584, 6.751319, 7.38325)
end1: (2.378866, 2.403441, 3.58497)
arr: [(-0.200719, -4.347878, -3.79828), (-0.200719, -4.347878, 3.58497), (-0.200719, 2.403441, -3.79828), (-0.200719, 2.403441, 3.58497), (2.378866, -4.347878, -3.79828), (2.378866, -4.347878, 3.58497), (2.378866, 2.403441, -3.79828), (2.378866, 2.403441, 3.58497)]
arr_y: [-4.34787845611572, -4.34787845611572, 2.40344095230103, 2.40344095230103, -4.34787845611572, -4.34787845611572, 2.40344095230103, 2.40344095230103]
arr_y max: 2.40344095230103
Where you can see that red plane is where the highest aabb point is for sure but its not the correct value for some reason. Becasue if i manually in editor transform the red plane into the furthest Y towards UP direction position then i get approximate value of Y=4.40
Imo the merging of aabb makes the results somehow wrong, i dont understand how it merges, The documentation does not explains it.