##########
Visibility
##########

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.


Element visibility
==================

To change and query the visibility state for all faces or edges within a model, the following functions can be used:

.. raw:: none

	view.setFaceVisibility()
	view.getFaceVisibility()
	view.setLineVisibility()
	view.getLineVisibility()

For more information regarding the above functions, visit :doc:`this link </api_ref/viewing/classes/Communicator.View>`.

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.


Node visibility
===============

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 :ref:`setNodesVisibilities() <api_ref/viewing/classes/Communicator.Model:setnodesvisibilities>` and :ref:`setNodesVisibility() <api_ref/viewing/classes/Communicator.Model:setnodesvisibility>`.


.. raw:: none

	model.setNodesVisibilities()
	model.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:

.. literalinclude:: /../../applications/client/docs/PG_Viewing_visibility.ts
   :start-after: //! [webviewer_setNodesVisibilities]
   :end-before: //! [webviewer_setNodesVisibilities]

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.


Visibility propagation
======================

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.


Hidden nodes
============

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.

The optional :ref:`initiallyHiddenStayHidden <api_ref/viewing/classes/Communicator.Model:setnodesvisibility>` parameter to :ref:`setNodesVisibility() <api_ref/viewing/classes/Communicator.Model:setnodesvisibility>` determines if geometry initially marked as hidden will be affected by changing the visibility state of a node.


Querying node visibility
========================

The function :ref:`model.getNodeVisibility() <api_ref/viewing/classes/Communicator.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 :ref:`model.getBranchVisibility() <api_ref/viewing/classes/Communicator.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 :ref:`resetNodesVisibility() <api_ref/viewing/classes/Communicator.Model:resetnodesvisibility>` will reset only the visibility of all nodes in the model tree while :ref:`reset() <api_ref/viewing/classes/Communicator.Model:reset>` will reset other attributes as well.

.. raw:: none

	model.resetNodesVisibility()
	model.reset()
