You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
functions: inspect takes too long in getBounds #1612
Is your feature request related to a problem? Please describe.
In function inspect, it calls getBounds by default, which takes too long to run in some large models.
Describe the solution you'd like
Add an option to skip getBounds in inspect.
Describe alternatives you've considered
Get min/max from positions accessor, then apply transform, could be less accurate.
Additional context
Taking the glb file from another issue for example, it took ~24s in getBounds.
I think the underlying challenge in this example is that the scene reuses the same meshes on many nodes, and we end up recalculating the world AABB for the same mesh hundreds of times. Repeated AABB calculation can't fully be avoided — transforming a local AABB into world space does not yield an exact world AABB, it will be too large. But we could reduce the number of AABB calculations by:
for each mesh, compute local AABB
for each node with a mesh, compute conservative world AABB by transforming the local AABB
sort nodes by some heuristic (size of AABB? distance from approx AABB to approx scene AABB?)
for each node with a mesh, check if approx AABB is fully contained by 'in-progress' exact scene AABB. if so skip it, otherwise, compute the exact node AABB and use it to expand the exact scene AABB
return exact scene AABB
I expect we can reduce time for getBounds by 90% or so, for cases where meshes are reused/instanced.
An option to skip getBounds in inspect() wouldn't be out of the question... but I suspect most people won't find it, or won't know getBounds() is why inspect() is slow, which won't always be the cause.
Another option might be to expose individual functions like inspectNodes(nodes)? So then you can fetch only the information you need, and if you don't want the full inspectScenes(scenes) implementation, then you can easily create your own. Scene inspection is only 15 lines of code, so I'm hesitant to start adding options to that.
for each node with a mesh, compute conservative world AABB by transforming the local AABB
This could be less accurate than the current impl of min/max from each vertex in world space. See comments here. So this could lead to a breaking change, or an option which is off by default.
Another option might be to expose individual functions like inspectNodes(nodes)? So then you can fetch only the information you need, and if you don't want the full inspectScenes(scenes) implementation, then you can easily create your own. Scene inspection is only 15 lines of code, so I'm hesitant to start adding options to that.
Yes, it's good to have underlying functions like listTextures and listMeshes exported, in this case users choose what to inspect.
This could be less accurate than the current impl of min/max...
Wouldn't use the conservative AABB for the final result – just as a pre-pass. So we'd only compute an exact AABB for each node if its conservative AABB is not fully contained by the scene AABB yet. Final result will still be exact, just faster (hopefully).
But probably exporting the smaller functions could be good in any case!
Activity
donmccurdy commentedon Feb 13, 2025
I think the underlying challenge in this example is that the scene reuses the same meshes on many nodes, and we end up recalculating the world AABB for the same mesh hundreds of times. Repeated AABB calculation can't fully be avoided — transforming a local AABB into world space does not yield an exact world AABB, it will be too large. But we could reduce the number of AABB calculations by:
I expect we can reduce time for
getBoundsby 90% or so, for cases where meshes are reused/instanced.An option to skip
getBoundsininspect()wouldn't be out of the question... but I suspect most people won't find it, or won't knowgetBounds()is whyinspect()is slow, which won't always be the cause.Another option might be to expose individual functions like
inspectNodes(nodes)? So then you can fetch only the information you need, and if you don't want the fullinspectScenes(scenes)implementation, then you can easily create your own. Scene inspection is only 15 lines of code, so I'm hesitant to start adding options to that.kzhsw commentedon Feb 14, 2025
This could be less accurate than the current impl of min/max from each vertex in world space. See comments here. So this could lead to a breaking change, or an option which is off by default.
Yes, it's good to have underlying functions like
listTexturesandlistMeshesexported, in this case users choose what to inspect.donmccurdy commentedon Feb 14, 2025
Wouldn't use the conservative AABB for the final result – just as a pre-pass. So we'd only compute an exact AABB for each node if its conservative AABB is not fully contained by the scene AABB yet. Final result will still be exact, just faster (hopefully).
But probably exporting the smaller functions could be good in any case!