# LOD-Switch example

This is the complete LOD-Switch example written in Python that utilized Maya's LOD-groups.

In the image below we can see the UI at the right. The first part is the settings-path to the Pipeline-file that will be used when creating the LODs. The "Show LOD chain"-checkbox will enable automatic LOD-switching once the LODs has been created. "Display LOD" will force a LOD-switch at the current camera distance. "LOD Aggressiveness" is more or less a distance-multiplier in case the computed distance needs to be adjusted in any direction. At last we have "Create LODs" which will start the process, and once completed will create LOD groups ready for switching. "Clear LODs" can be used to delete all newly created LODs / objects.

To the left we can see the generated LOD group, grey font means that the object is currently hidden, and white that is is visible.

IMPORTANT NOTE

The following code uses spScene's GetRadius method. spScene's GetRadius includes spSceneMesh, spSceneCamera & spSceneNode in its extent calculation. Which is then used in GetRadius calculation. However AssetDiameter/ or SceneRadius terms should refer only spSceneMeshes part of the processing set which could be a subset of spSceneMeshes in the spScene.

The following two uses cases will currently affect the radius of scene which will give you incorrect switch distances if you use spScene GetRadius.

  1. spSceneCamera is added to the scene.
  2. spSceneMesh is added to the scene that is used as clipping geometry or visibility sampler (using selection set)

If you have one of the above cases. Release after 9.1.39000.0 have global setting available that you can enable to exclude spSceneCamera from extent and radius calculations.

sg.SetGlobalBoolSetting( "IgnoreCameraInExtentsCalculation", true );

However for (2) you would need to do the book keeping on your end. Mainly the following

  1. Use spScene's SelectNodes to select spSceneMesh's. Remove any meshes that belong are part of the spSelectionSet's for clipping geometry or visibility sampling. This will give you a subset of processing set.

Now you can compute the bounding sphere radius of this subset and use it as AssetDiameter.

LOD-Switch UI