============
Static Model
============

Using a static model can dramatically reduce rendering time, especially for large models. In this tutorial, we'll walk you through the basics of setting up your scene to work with a static model. For a top-level overview of the performance benefits of using a static model, please see the :ref:`Performance Considerations <prog_guide/0703_performance_considerations:Static model>` section of the Programming Guide.


6.1 Importing a Model File
==========================

We'll start off by importing an HSF file using an ``HPS::Stream::ImportOptionsKit``. (For more information on importing files, please see :doc:`this section </prog_guide/0901_importing_files>`.)

.. tabs::

	.. group-tab:: C++
	
		.. literalinclude:: ../../../internals/tests/docs/source/cpp/00700_static_model_update_info.cpp
		   :start-after: //! [import_file]
		   :end-before: //! [import_file]
		   
	.. group-tab:: C#

		.. literalinclude:: ../../../internals/tests/docs/source/cs/00700_static_model_update_info.cs
		   :start-after: //! [import_file]
		   :end-before: //! [import_file]
		   

6.2 Setting the Static Model
============================

Next we'll need to get references to our canvas and window objects. In this case our canvas is referenced by the ``_canvas`` variable and the window object is referenced by ``window``, but your application may define them differently. If you are using one of the Sandbox applications, you can get a reference to them using ``GetCanvas()`` and ``GetCanvas().GetWindowKey()``, respectively. 

Attach the newly imported model to the front view of our canvas. Then, we'll define the model segment as a static model:

.. tabs::

	.. group-tab:: C++
	
		.. literalinclude:: ../../../internals/tests/docs/source/cpp/00700_static_model_update_info.cpp
		   :start-after: //! [set_static_model]
		   :end-before: //! [set_static_model]
		   
	.. group-tab:: C#

		.. literalinclude:: ../../../internals/tests/docs/source/cs/00700_static_model_update_info.cs
		   :start-after: //! [set_static_model]
		   :end-before: //! [set_static_model]


6.3 Collecting Performance Diagnostics
======================================

In order to see diagnostic information about our static model, we'll use the ``HPS::WindowInfoControl`` to populate an ``HPS::UpdateInfo`` object:

.. tabs::

	.. group-tab:: C++
	
		.. literalinclude:: ../../../internals/tests/docs/source/cpp/00700_static_model_update_info.cpp
		   :start-after: //! [update_info_sample]
		   :end-before: //! [update_info_sample]
		   
	.. group-tab:: C#

		.. literalinclude:: ../../../internals/tests/docs/source/cs/00700_static_model_update_info.cs
		   :start-after: //! [update_info_sample]
		   :end-before: //! [update_info_sample]
		   

6.4 Using the Resource Monitor
==============================

A component of the ``HPS::DebuggingControl`` class, the Resource Monitor displays a variety of helpful statistics, including the number of static models generated in the most recent update. It's a useful tool for debugging and for testing which changes will trigger regeneration of the static model.

.. image:: images/06/ResourceMonitor.png

*The Resource Monitor*


Here's how to load it into the scene:

.. tabs::

	.. group-tab:: C++
	
		.. literalinclude:: ../../../internals/tests/docs/source/cpp/00700_static_model_update_info.cpp
		   :start-after: //! [set_resource_monitor]
		   :end-before: //! [set_resource_monitor]
		   
	.. group-tab:: C#

		.. literalinclude:: ../../../internals/tests/docs/source/cs/00700_static_model_update_info.cs
		   :start-after: //! [set_resource_monitor]
		   :end-before: //! [set_resource_monitor]
		   
		   
6.5 Update Types
================

For performance reasons, when a window is updated with the Default UpdateType, the static model is not regenerated during an update immediately following any changes that have been made to the scene that invalidated the static model subtree. Instead, the static model will be regenerated on the next update as long as no further changes have occurred that would have invalidated the static model subtree. In other words, HOOPS Visualize Desktop waits until it's reasonably sure that all of the invalidating changes have been made before performing an update to the static model. This is a performance optimization to avoid generating a static model unnecessarily. (To force a static model regeneration, however, you would simply use the ``HPS::Window::UpdateType::Exhaustive`` update type.) The first non-Exhaustive and non-CompileOnly update after a modification will *not* build a static model.

.. tabs::

	.. group-tab:: C++
	
		.. literalinclude:: ../../../internals/tests/docs/source/cpp/00700_static_model_update_info.cpp
		   :start-after: //! [first_update]
		   :end-before: //! [first_update]
		   
	.. group-tab:: C#

		.. literalinclude:: ../../../internals/tests/docs/source/cs/00700_static_model_update_info.cs
		   :start-after: //! [first_update]
		   :end-before: //! [first_update]
		   

The second non-Exhaustive and non-CompileOnly update after a modification *will* build a static model (assuming no additional static-breaking changes are made, which would delay the update).

.. tabs::

	.. group-tab:: C++
	
		.. literalinclude:: ../../../internals/tests/docs/source/cpp/00700_static_model_update_info.cpp
		   :start-after: //! [second_update]
		   :end-before: //! [second_update]
		   
	.. group-tab:: C#

		.. literalinclude:: ../../../internals/tests/docs/source/cs/00700_static_model_update_info.cs
		   :start-after: //! [second_update]
		   :end-before: //! [second_update]
		   

Appendix
========

Full source code:

.. tabs::

	.. group-tab:: C++
	
		.. literalinclude:: ../../../internals/tests/docs/source/cpp/00700_static_model_update_info.cpp
		   :start-after: //! [full_program_static_model_tutorial]
		   :end-before: //! [full_program_static_model_tutorial]
		   
	.. group-tab:: C#

		.. literalinclude:: ../../../internals/tests/docs/source/cs/00700_static_model_update_info.cs
		   :start-after: //! [full_program_static_model_tutorial]
		   :end-before: //! [full_program_static_model_tutorial]
		   
		   