Hello,
I am loading STL files using ImportMesh (or ImportMeshAsync) in a canvas that is part of a SPA app. When navigating away from a specific page, the GL canvas is left in place, but I would need to cancel the request to load when navigating away. Is there a way to tell ImportMesh(Async) to cancel its request?
Thank you for your help.
Hey!
Unfortunately no. but you can use the callback to handle the case the user has already navigated away
1 Like
I was struggling with this as well, as we have a UI where a user can import a mesh. And this is a pain especially if the file is big and the user changes his mind and changes the file.
So waiting for a file to finish downloading, then cleaning it up, was not a great option.
I found a hacky way though, to abort a web request.
Import mesh returns a ISceneLoaderPlugin or ISceneLoaderPluginAsync.
const plugin = BABYLON.SceneLoader.ImportMesh();
Those plugins have an onDisposeObservable, and there is logic inside a SceneLoader that aborts a running request if onDisposeObservable fires an event.
So all I needed to do was notify observers.
(plugin as any)?.onDisposeObservable?.notifyObservers(plugin);
Would be great though if there was a public API for this.
2 Likes