Skip to content

functions: inspect takes too long in getBounds #1612

Open

Description

@kzhsw

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

Activity

  1. added this to the 🗄️ Backlog milestone on Feb 13, 2025
  2. donmccurdy commented on Feb 13, 2025

    @donmccurdy
    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.

  3. kzhsw commented on Feb 14, 2025

    @kzhsw
    ContributorAuthor
    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.

  4. donmccurdy commented on Feb 14, 2025

    @donmccurdy
    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions