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

screenshot

in Engine by (97 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
else:
    visible = true
by (97 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 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 webmaster@godotengine.org with your username.