Question about selectionManager.selectLayer function

I am using Hoops Communicator 2024.03. In the Model Browser Layers Tab of the demo application, when I use setSelectionFilter, toggle the layer item has different event number in the selectionArray callback event.

// when bodyInstance node is select, I force it to select PartInstance
this._viewer.selectionManager.setSelectionFilter((nodeId) => {
  if (this._viewer.model.getNodeType(nodeId) === NodeType.BodyInstance) {
    return this._viewer.model.getNodeParent(nodeId);
  }
    return nodeId
})
// LayersTree.js
// By passing the same layerName with SelectionMode.Toggle, if selectionFilter is used
// For adding nodes of the layer, the SelectionArray callback event will have size more than thousand
// For remove nodes of the layer, the SelectionArray callback event will have size less than thousand

// But if the selectionFilter is commented, the event will have the same size for both add and remove situation
    _selectLayer(layerId, selectionMode) {
        const layerName = TreeGetLayerName(layerId);
        if (layerName !== null) {
            this._viewer.selectionManager.selectLayer(layerName, selectionMode);
        }
    }

So I would like to know if this is expected behavior? Thank you.

Hello @nick.wong,

I’m not quite sure what you mean when you say “event number” as in:

The selectionArray callback returns a NodeSelectionEvent object. Are you referring to the node id?

Hi tino,

For the event number I mean the size of selectionArray callback argument.

// for example, the size of events
selectionArray: (events) => { ... }

So what I encountered is the size of events is different when calling selectLayer with SelectionMode.Toggle and selectionFilter. In other word, the nodes are selected and the nodes are removed by the selectLayer function is different when selectionFilter is used.

Thank you.

In my tests on HC 2024.3.0, I’m not able to reproduce the issue based on my understanding of your description and code snippets.

I modified your selectionFilter code to count the number of times a node is returned:

let viewer = hwv;
let selectionFilterNodeCount = 0;

viewer.selectionManager.setSelectionFilter((nodeId) => {
  if (viewer.model.getNodeType(nodeId) === Communicator.NodeType.BodyInstance) {
    let nodeParent = viewer.model.getNodeParent(nodeId);

    selectionFilterNodeCount++;

    return nodeParent;
  }

  selectionFilterNodeCount++;
  return nodeId;
});

For the selectionArray callback, I simply show the length of the returned selections array:

selectionArray: function (selections) {
  if (selections.length > 0) {
    console.log("selectionArray count: " + selections.length);
  }
}

I’m using the arboleda model (which is part of the Communicator package). I make the following call to select the first layer in the model browser:

hwv.selectionManager.selectLayer("Ceiling", Communicator.SelectionMode.Toggle);

The selectionArray callback returns 99 and the variable selectionFilterNodeCount also has a value of 99. Below is a screenshot:

Can you confirm if my steps are consistent with yours?

Thank you for your reply.

The issue I encountered is when I select nodes of the layer (Add ) it has 1857 nodes selected. When I deselect the nodes of the layer (using Toggle mode), it has 440 nodes from the callback.

As a result, when I click the selected layer item in the layer mode browser, there are some layerParts are still being highlighted.

So for the two calls you described Add and Toggle, would they be something like?:

hwv.selectionManager.selectLayer("name_of_layer", Communicator.SelectionMode.Add);

hwv.selectionManager.selectLayer("name_of_layer", Communicator.SelectionMode.Toggle);
this._viewer.selectionManager.selectLayer(layerName, selectionMode);

This is the API I used. Given that when the layerName is not selected, SelectionMode.Set is used. If the layerName is selected, SelectionMode.Toggle is used.

For the selectionArray screenshot, the layerName are the same for both Set and Toggle case.

Nick,

Please see my direct message to you about possibly getting more information in order for me to reproduce the issue.

Thanks,
Tino