Speckle Viewer: Load several version in the same scene

Hello,
I find the viewer super promising, and especially its integration into three, thank you!

I have two questions:

Last Friday I was able to reproduce the Basic Setup example, using this link:
https://app.speckle.systems/streams/fe42e4a84e/objects/7a9ee0c0038212875046ac85f9c2b463
I can’t remember where I copied it. When I open it online, I’m redirected to a new link that doesn’t work in my code. Which link should I officially take? From the project? From the version?

2nd related question:
How can I load several versions in the same scene, with a menu for switching from one to another, as in your viewer? Is there an automated component?

Many thanks

Hi @RaphaelVouilloz

Glad to hear again from you! :slight_smile:

I’m afraid I don’t quite understand the first question. I’ll gladly help, but I need more info regarding what you want to achieve. In any case, I’ve made this sandbox which explains how URL resources are loaded with a concrete example

Regarding you second question the same sandbox linked above shows how you can load multiple models/versions in the same scene. However, from what I’m aware there is no explicit per-defined component that you can use to switch between them, as that would be outside the viewer’s scope. If you need help with actually adding/removing or showing/hiding versions from a functional point of view let me know and I can make an example sandbox.

Cheers

1 Like

Hi Alex
Thanks, indeed the sandbox is super useful! I didnt’ get I should use the UrlHelper. The For loop is super nice. Have you actually an example with a menu to show/hide models loaded with this loop?
I have read the doc and the sandbox on Filtering, super useful. How can i get the id of each model from the WorldTree to pass it into filtering.hideObjects?
Best

Hi @RaphaelVouilloz

I’ve made this code sandbox based on the previous one which adds a button in a primitive UI that hides/shows each loaded model.

All models loaded in the viewer will contain a Model Root Node which id for speckle models will always be the speckle model complete URL. In the linked sandbox above I hooked up the viewer’s ViewerEvent.LoadComplete event which provides the loaded mode’s root node id. This is one way of getting hold of an id that can be used to apply filters or whatnot to an entire model.

Alternatively, you can get the model root node ids from the WorldTree’s root. All it’s direct children will be model root nodes. Here’s a quick example, which I’ve also included in the above sandbox but commented it out

  const modeRootNodes = viewer.getWorldTree().root.model.children;
  for (const node of modeRootNodes) {
    const modelRootNodeId = node.id;
    // Do something with the id
  }

If we are to enumerate other possible way of getting the model root nodes I guess we could also do a findAll on the WorldTree with the predicate (node) => isSubtreeRoot(node)

So there are multiple ways of getting the root node ids for the models, and choosing one of the approaches mostly depends on your use case.

Cheers

1 Like

Thanks Alex for the quick help, that works perfectly.
Best,

2 Likes