Dynamic Asset Loading / Disposing

Hello everyone,

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.

Thanks for your time!

Perhaps you are looking for octrees? You’d still need the bounding boxes loaded early and call the octree manually.

1 Like

Ahhh yes, this could be the solution I need. Thank you!

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

Discussion on this in old forum

Needs much improvement but may give you some ideas.

1 Like

This is great!

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.

@jerome did a lot of similar thinking with terrains, I bet he ll be happy to hop in

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.

@3D_Wave_Design could you be so kind to share the function? I am also searching this topic

1 Like

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

Hope this helps!