Properly handle loading multiple models

Hi developers, I’m building a web app and need your advice.

I tried to follow the same idea of injecting the viewer into Nuxt components as it’s done in the main speckle-server solution. Everything worked fine when I was only loading one model at startup. At that point, a SpeckleLoader instance was created to load the model.

However, the requirements changed. Now I need to load additional models after the first one is opened. As a temporary solution, I created a separate component that uses the same viewer instance but creates a new SpeckleLoader to load these additional models.

Here’s my question: is it better to reuse the original SpeckleLoader, or is creating a new one for each batch of models a valid approach?

I’ve started noticing strange issues—like the section box resetting unexpectedly and inconsistent model loading. I’m beginning to suspect that creating multiple loaders might be conflicting with the viewer’s state.

Thanks!

Hi @Nikita_Sneg

By design, each load operations requires it’s own loader instance. Reusing instances of SpeckleLoader is not recommended and might not even be possible, as the underlying object-loader objects gets disposed after the load is complete. So each speckle model gets it’s own loader. The viewer then will automatically manage and release loader resources during it’s lifetime

If you can better describe the circumstances these strange issues are happening, along with more detail about your implementation we might be able to help.

Cheers

Thanks, I will try this out.

1 Like