I’ve been using the Asset Manager for preloading files in our projects, but I’m wondering if there’s a solution for dynamically loading / disposing 3D files based on camera position, frustum culling and memory management in the browser. We’re working on a mapping application, and it’d be nice to only load 3D terrain as needed for larger areas.
I’m in the beginning stages of scripting something, but I thought I’d reach out in the off chance a solution already exists before I go down the rabbit hole.
Here is a very basic method that uses workers to load assets depending on camera position relative to mapped coordinates over a large map load blocks - move with keyboard arrow keys. code here
Do the meshes need to exist in memory in order for the octree to work? I see that it can help for rendering, but I’m not sure how it’d apply to loading / unloading. The demos in that page don’t seem to work anymore.
I never used octree for that. I’d populate the octree with bounding boxes and load them when they got intersected. I think you could run that on a webworker to avoid locking the GUI.
Thanks. Independently, I’ve coded a function that runs when the camera moves; proxy meshes in an array check if they’re in frustum and calculate the distance between themself and the camera, then decide to load assets if certain requirements are satisfied. I havent quite digested what was done in the forum post @JohnK shared.
@Dshah_H Hey! Sorry for the late response, I’ve been MIA for awhile on this forum. My function is very project specific, so it may not work as intended for you, but the secret sauce is using the camera onViewMatrixChangeObservable method, and calculating distance between the object and camera using Vector3.Distance(), followed by if statements: if (sceneCamera.isInFrustum(lod1) && camDistance < 1000 && isLoaded === false) { do thing }.