There are two different types of visibility states in the HOOPS Web Viewer component. One of them is element visibility, which refers to the visibility of faces, lines and points within a model, and the other is node visibility, which refers to the visibility state of individual model tree nodes and their descendants.
To change and query the visibility state for all faces or edges within a model, the following functions can be used:
The functions above set or query the global visibility state of faces or edges for all mesh geometry within the scene. There is currently no way to change the visibility state of only faces or edges for individual nodes in the scene.
You can set the visibility state for nodes within the model tree with the functions below. This will affect the visibility of all mesh geometry at the specified nodes and their descendants. Click on the following links for more information regarding setNodesVisibilities() and setNodesVisibility()
These functions take either a map from nodeId to visibility state or a list of node IDs and allow you to quickly set the visibility state of multiple nodes:
In the above case, we use a map to set the visibility of node 1 (which, in the case of the microengine sample model, is the top-level node) to false and then set the visibility of node 16 (which, in this case, is one of the subassemblies) to true. The result is that only node 16 will be shown.
Changes to the visibility state of a node are not only applied to the node itself but also applied to all of its descendants. However, the state of a node parent is not inherited after it has been initially set. In other words, the parent node visibility can be false but geometry inside of descendant nodes might still be visible if the visibility state of these descendant nodes is set to true after the parent node's visibility was initially set.
Nodes can be marked as "hidden" during the authoring or import stage meaning that they should initially not be shown for various reasons. This could be because they represent construction or other temporary geometry or because they are not part of the active CAD view. Often it is not desirable for those nodes to be affected by "normal" visibility changes.
Querying Node Visibility
The function model.getNodeVisibility() allows you to query the visibility state of an individual node. As mentioned above this is not a reliable way to determine if any geometry is visible that is a descendant of the queried node. To retrieve that information you can use the function model.getBranchVisibility(). This function will look at all descendants of the specified node and determine if they are any of the following:
- All Visible
- All Invisible
- Partially Visible
This information can be useful, for example, to set the state of UI elements in your application.
Resetting Node Visibility
Every node in the model tree has a default visibility state. To restore the visibility state of all nodes in the model tree you can use the functions below. The function resetNodesVisibility() will reset only the visibility of all nodes in the model tree while reset() will reset other attributes as well.