Speckle/viewer hiding/showing objects

Hello everyone!

I am currently working on a project that uses the speckle/viewer^2.11.4.
I need to implement a filter that shows or hides objects based on given objectIds.
For the implementation I’m using this very helpful documentation: Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.

I have the problem that the ghostmode on the hideObjects-function doesnt seem to work properly for my case. Maybe I’m doing it wrong but the objects are still somewhat visible and they are also selectable. At least they get detected by the:

this.viewer.on(ViewerEvent.ObjectClicked, async (selectionInfo: SelectionEvent) => { ... }
SelectionEvent.

I need to completely hide the objects and have the selectionEvent ignore them. Or at least get an Indicator, when a Hit is in ghostMode.
Just for reference. This is a really simple piece of code that I use to hide Objects:

    applyObjectsFilter = async (objectIds: string[]) => {
        await this.viewer.hideObjects(objectIds, ' ', true, true)
    }

Here is how the WIP viewer looks like. The door is selected, eventhou its hidden.

Any ideas on how to archieve that?

(btw I have noticed that the code example in the documentation for showObjects and hideObjects seem to have wrong parameters, because the showObjects example has the ghoseMode-parameter and the hideObjects doesnt.)

Thank you :slight_smile:

Hi @mgerhardt

I see that you are calling hideObjects with the ghost parameter (last parameter) set to true. That’s the reason upon hiding the hidden objects remain ghosted and intractable. Try either setting it to false, either not setting it at all, since it’s optional and it defaults to false.

Cheers

1 Like

thanks for the quick reply!

Setting ghost to false helps with the transperency problem. I guess I missunderstood the ghost-parameter.
Object is still selectable though.
This is my select-function:

 await this.viewer.selectObjects([selectionInfo.hits[0].object.id])

I use this to select the object the user has clicked. Any way to have this ignore hidden objects?

@dimitrie can correct me if I’m wrong, but you need to ignore hidden objects yourself by using the return value of hideObjects. All filtering calls return a FilteringState which you can use to keep track of various states of the objects in the scene at any time.
Basically you’d need to go through the hits array inside the SelectionEvent in order, and find the first hit which is not hidden by looking if it’s id is in the hiddenObjects array inside the FilteringState object returned by hideObjects

1 Like