Hide and Isolate Objects simultaneously

  • Objective:

Hello,

I have a Revit model which I’m viewing with the speckle viewer embedded in my app.

The model contains rooms, which I want to always hide, as they get in the way.

My app also has functionality to select specific objects to be isolated.

  • Issue:

I’m observing that one cannot simultaneously hide some objects, while isolating some other objects.

They end up playing wack-a-mole with each other, with the last caller winning.

  • Example:

Here is the code I have written which mostly unblocks my issue, since the app is not always isolating objects. I let the isolation win out over the hiding:

  if (filtering) {
    // Hide first, since you can only hide or isolate, but not both. And we need isolation to win.
    const currentlyHidden = filtering.filteringState.hiddenObjects;
    const toHide = hideObjectIds.filter((id) => !currentlyHidden?.includes(id));
    const toShow = currentlyHidden?.filter((id) => !hideObjectIds.includes(id)) ?? [];
    if (toShow?.nonEmpty) filtering.showObjects(toShow);
    if (toHide.nonEmpty) filtering.hideObjects(toHide);

    const currentlyIsolated = filtering.filteringState.isolatedObjects;
    const toIsolate = isolateObjectIds.filter((id) => !currentlyIsolated?.includes(id));
    const toUnIsolate = currentlyIsolated?.filter((id) => !isolateObjectIds.includes(id)) ?? [];
    console.log({ currentlyIsolated, isolateObjectIds, toIsolate, toUnIsonlate: toUnIsolate });
    if (toUnIsolate.nonEmpty) filtering.unIsolateObjects(toUnIsolate);
    // Only isolate objects if specific ones are requested
    if (toIsolate.nonEmpty) filtering.isolateObjects(toIsolate);
  }

I say mostly, because seeing the ghosts of the rooms when isolating other features is still less than desirable

Rooms hidden when not isolating:
image

Room skeletons visible when isolating:

Thoughts appreciated

1 Like

Hi @Christopher_Fox

You are right, the filtering extension works on the same state when both isolating and hiding objects. We are aware of this limitation and we will eliminate it in a future iteration on filtering. Until that happens, there is a workaround you can easily use.

The filtering extension does not use any viewer core functionality that isn’t in it’s public API. This means that you can easily hide/isolate objects using the viewer-core directly. Specifically using setMaterial. I’ve made a live code example that combines the default filtering extension isolation method with a custom hiding approach using the viewer-core directly. Note however, that filtering states are not automatically updated because we’re applying materials directly, so you will have to keep track on your own which objects are hidden or not.

Let us know if you need further help

Cheers

On top of @alex’s reply, maybe if you need an always curated source for your embedded viewer that you set up an Automate script to prefilter these whenever new data gets published.

1 Like