########################
Displaying Indoor Models
########################


This tutorial showcases another approach compared to the :doc:`/tutorials/workflows/wf_advancedrealtime/wf_importing_geometries` tutorial. Indeed, loading a complete landscape may be a burden, and this is a costly operation in terms of performances since REDart has to render the complete environment, including the landscape, vegetation, clouds and all decorative geometries.

As an alternative to using a full outdoor environment, we'll use a HDR texture map generated from the outdoor environment:

.. figure:: wd_displaying_indoor_models_environment.png 
  :align: center
  
  **The generated HDR environment map.**

The :doc:`/book/subjects/bk_art/bk_art_asset_editor` can be used to produce environment maps: It'll generate both a LDR, HDR and a suitable ART environment .red file that can be loaded as we'll see below.


**************************
Loading an Environment Map
**************************

The loader is the ``ART::IAssetManager``, and similarly to the loading of complete atlas, we load environment files instead:

.. code:: cpp 

    // Load our environment:
    RED::Object* environment;
    RED::Matrix envaxis, planetaxissun;
    RC_TEST( iassetmgr->LoadEnvironment( environment, envaxis, planetaxissun, "../Resources/atlas_Environment.red" ) );

    // Setup the environment before starting the world:
    RC_TEST( iearth->SetEnvironment( environment, 1.0, envaxis, 1000.0 ) );

    // Start the world:
    RC_TEST( iworld->Start( window, REDartProgressCB, NULL ) );

We see that the ``ART::IAssetManager::LoadEnvironment`` method returns two matrices:

    * The first matrix is the tangent space matrix containing the position and axis system of the environment used during its creation. It's expressed in Planetary Coordinate System (PCS).
    * The second matrix is the World Coordinate System (WCS) matrix of the sun position used for the environment creation. It can be used to reposition the sun properly so that the lighting of the geometry matches the lighting of the surrounding environment. Therefore, it can be used "as is" for ``ART::IPlanet::OverrideAxisSystem``.

Then, we call ``ART::IPlanet::SetEnvironment``, instead of ``ART::IPlanet::SetAtlas`` that was used in the previous tutorial. Setting up an environment will remove an atlas and vice-versa. Note that the SetEnvironment method requires an altitude to be supplied. This is the maximal height of all geometries that are intended to be seen within the environment. This parameter is required noticeably for a proper setup of sun shadows.


*****************
Navigating Indoor
*****************

The navigation remains unchanged, except that now we don't have any environment anymore. Consequently, rendering performances are higher but the environment lighting is static since it's enclosed in an image. Here are a few images of the rendered scene:

.. figure:: wf_displaying_indoor_models_inside_view.png 
  :align: center
  
  **A view from the inside with the surrounding environment**

.. note:: 
    
    Since we use a HDR environment map which is a faithful capture of the landscape environment, we get the same lighting intensities as we would have got with the real landscape.

.. figure:: wf_displaying_indoor_models_outside_view.png 
  :align: center
  
  **A view from the outside that reveals the environment map**

Of course, using an environment don't produce good results for an outside view. In addition we loose the lighting of external lights applied to the landscape as we could notice in the :doc:`/tutorials/workflows/wf_advancedrealtime/wf_importing_geometries` example.

