Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functions: inspect takes too long in getBounds #1612

Open
kzhsw opened this issue Feb 13, 2025 · 3 comments
Open

functions: inspect takes too long in getBounds #1612

kzhsw opened this issue Feb 13, 2025 · 3 comments
Labels

Comments

@kzhsw
Copy link
Contributor

kzhsw commented Feb 13, 2025

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.

Image

Image

@kzhsw kzhsw added the feature New enhancement or request label Feb 13, 2025
@donmccurdy donmccurdy added this to the 🗄️ Backlog milestone Feb 13, 2025
@donmccurdy
Copy link
Owner

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:

  1. for each mesh, compute local AABB
  2. for each node with a mesh, compute conservative world AABB by transforming the local AABB
  3. sort nodes by some heuristic (size of AABB? distance from approx AABB to approx scene AABB?)
  4. 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
  5. 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.

@kzhsw
Copy link
Contributor Author

kzhsw commented Feb 14, 2025

  1. 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.

@donmccurdy
Copy link
Owner

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants