Axiom.Core.SceneManager.SetSkyBox C# (CSharp) Method

SetSkyBox() public method

Enables / disables a 'sky box' i.e. a 6-sided box at constant distance from the camera representing the sky.
You could create a sky box yourself using the standard mesh and entity methods, but this creates a plane which the camera can never get closer or further away from - it moves with the camera. (you could create this effect by creating a world box which was attached to the same SceneNode as the Camera too, but this would only apply to a single camera whereas this skybox applies to any camera using this scene manager).

The material you use for the skybox can either contain layers which are single textures, or they can be cubic textures, i.e. made up of 6 images, one for each plane of the cube. See the TextureLayer class for more information.

public SetSkyBox ( bool enable, string materialName, float distance, bool drawFirst, Quaternion orientation, string groupName ) : void
enable bool True to enable the skybox, false to disable it
materialName string The name of the material the box will use.
distance float Distance in world coordinates from the camera to each plane of the box.
drawFirst bool /// If true, the box is drawn before all other /// geometry in the scene, without updating the depth buffer. /// This is the safest rendering method since all other objects /// will always appear in front of the sky. However this is not /// the most efficient way if most of the sky is often occluded /// by other objects. If this is the case, you can set this /// parameter to false meaning it draws after all other /// geometry which can be an optimisation - however you must /// ensure that the distance value is large enough that no /// objects will 'poke through' the sky box when it is rendered. ///
orientation Quaternion /// Specifies the orientation of the box. By default the 'top' of the box is deemed to be /// in the +y direction, and the 'front' at the -z direction. /// You can use this parameter to rotate the sky if you want. ///
groupName string
return void
	    public void SetSkyBox( bool enable,
							   string materialName,
							   float distance,
							   bool drawFirst,
							   Quaternion orientation,
							   string groupName )
		{
			// enable the skybox?
			this.isSkyBoxEnabled = enable;

			if ( enable )
			{
				Material m = (Material)MaterialManager.Instance[ materialName ];

				if ( m == null )
				{
					this.isSkyBoxEnabled = false;
					throw new AxiomException( string.Format( "Could not find skybox material '{0}'", materialName ) );
				}
				// Make sure the material doesn't update the depth buffer
				m.DepthWrite = false;
				// Ensure loaded
				m.Load();

				// ensure texture clamping to reduce fuzzy edges when using filtering
                m.GetTechnique( 0 ).GetPass( 0 ).GetTextureUnitState( 0 ).SetTextureAddressingMode( TextureAddressing.Clamp );

				this.isSkyBoxDrawnFirst = drawFirst;

				if ( this.skyBoxNode == null )
				{
					this.skyBoxNode = this.CreateSceneNode( "SkyBoxNode" );
				}
				else
				{
					this.skyBoxNode.DetachAllObjects();
				}

				// need to create 6 plane entities for each side of the skybox
				for ( int i = 0; i < 6; i++ )
				{
					Mesh planeModel = this.CreateSkyboxPlane( (BoxPlane)i, distance, orientation, groupName );
					string entityName = "SkyBoxPlane" + i;

					if ( this.skyBoxEntities[ i ] != null )
					{
						this.RemoveEntity( this.skyBoxEntities[ i ] );
					}

					// create an entity for this plane
					this.skyBoxEntities[ i ] = CreateEntity( entityName, planeModel.Name );

					// skyboxes need not cast shadows
					this.skyBoxEntities[ i ].CastShadows = false;

					// Have to create 6 materials, one for each frame
					// Used to use combined material but now we're using queue we can't split to change frame
					// This doesn't use much memory because textures aren't duplicated
					Material boxMaterial = (Material)MaterialManager.Instance[ entityName ];

					if ( boxMaterial == null )
					{
						// Create new by clone
						boxMaterial = m.Clone( entityName );
						boxMaterial.Load();
					}
					else
					{
						// Copy over existing
						//must not copy over the name, otherwise the sky box entity will be set to use the origional m material instead of the copy for each entity which each uses a different frame
						m.CopyTo( boxMaterial, false );
						boxMaterial.Load();
					}

					// set the current frame
					boxMaterial.GetTechnique( 0 ).GetPass( 0 ).GetTextureUnitState( 0 ).CurrentFrame = i;

					this.skyBoxEntities[ i ].MaterialName = boxMaterial.Name;

					// Attach to node
					this.skyBoxNode.AttachObject( this.skyBoxEntities[ i ] );
				} // for each plane
			}
		}

Same methods

SceneManager::SetSkyBox ( bool enable, string materialName, float distance ) : void
SceneManager