0 votes

I'm trying to implement LOD culling with multimeshes but am struggling with being able to compare the distance between my camera and the multimesh. I currently am trying something like this:

aabb = multimesh.get_aabb()
    distance = get_viewport().get_camera().get_global_transform().origin.distance_to(aabb.position + 0.5 * aabb.size)

but it seems that the aabb is just at the origin? And I can't find any way to set an AABB, yet in the editor I see what looks like a bounding box around my multi mesh instances as shown in the screenshot below. Is it possible to access this or should I be using a different approach? I just want to be able to calculate the distance between my camera and a multimesh and then show or hide it depending on distance


in Engine by (103 points)

1 Answer

+1 vote
Best answer

Ah fixed it by refactoring how I was generating my multiMeshInstances. I had been creating my multiMeshInstances in a strange way by having a scene with a spatial which created a multiMeshInstance in code with its multimesh etc and instancing it in my main scene when generating forests. I must have got a bit mixed up because I refactored to be a multiMeshInstance with a script attached that I instance into my main scene and realised that I can call getaabb() on it and it does return correctly. Previously I think I had been trying to call getaabb() before my code had created multimesh and set all the bits and pieces. For anyone interested, this is my code now:

aabb = get_aabb()
distance = get_viewport().get_camera().get_global_transform().origin.distance_to(aabb.position + 0.5 * aabb.size)   
if distance > 350:
    visible = false
    visible = true
by (103 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.