Axiom.Core.LightFactory._createInstance C# (CSharp) Method

_createInstance() protected method

protected _createInstance ( string name, NamedParameterList param ) : Axiom.Core.MovableObject
name string
param NamedParameterList
return Axiom.Core.MovableObject
		protected override MovableObject _createInstance( string name, NamedParameterList param )
		{
			Light light = new Light( name );

			if ( param != null )
			{
				// Setting the light type first before any property specific to a certain light type
				if ( param.ContainsKey( "type" ) )
				{
					switch ( param[ "type" ].ToString() )
					{
						case "point":
							light.Type = LightType.Point;
							break;
						case "directional":
							light.Type = LightType.Directional;
							break;
						case "spot":
						case "spotlight":
							light.Type = LightType.Spotlight;
							break;
						default:
							throw new AxiomException( "Invalid light type '" + param[ "type" ] + "'." );
					}
				}

				// Common properties
				if ( param.ContainsKey( "position" ) )
				{
					light.Position = Vector3.Parse( param[ "position" ].ToString() );
				}

				if ( param.ContainsKey( "direction" ) )
				{
					light.Direction = Vector3.Parse( param[ "direction" ].ToString() );
				}

				if ( param.ContainsKey( "diffuseColour" ) )
				{
					light.Diffuse = ColorEx.Parse_0_255_String( param[ "diffuseColour" ].ToString() );
				}

				if ( param.ContainsKey( "specularColour" ) )
				{
					light.Specular = ColorEx.Parse_0_255_String( param[ "specularColour" ].ToString() );
				}

				if ( param.ContainsKey( "attenuation" ) )
				{
					Vector4 attenuation = Vector4.Parse( param[ "attenuation" ].ToString() );
					light.SetAttenuation( attenuation.x, attenuation.y, attenuation.z, attenuation.w );
				}

				if ( param.ContainsKey( "castShadows" ) )
				{
					light.CastShadows = Convert.ToBoolean( param[ "castShadows" ].ToString() );
				}

				if ( param.ContainsKey( "visible" ) )
				{
					light.CastShadows = Convert.ToBoolean( param[ "visible" ].ToString() );
				}
				// TODO: Add PowerScale Property to Light
				if ( param.ContainsKey( "powerScale" ) )
				{
					light.PowerScale = (float)Convert.ToDouble( param[ "powerScale" ].ToString() );
				}
				// TODO: Add ShadowFarDistance to Light
				if ( param.ContainsKey( "shadowFarDistance" ) )
				{
					light.ShadowFarDistance = (float)Convert.ToDouble( param[ "shadowFarDistance" ].ToString() );
				}

				// Spotlight properties
				if ( param.ContainsKey( "spotlightInner" ) )
				{
					light.SpotlightInnerAngle = (float)Convert.ToDouble( param[ "spotlightInner" ].ToString() );
				}

				if ( param.ContainsKey( "spotlightOuter" ) )
				{
					light.SpotlightOuterAngle = (float)Convert.ToDouble( param[ "spotlightOuter" ].ToString() );
				}

				if ( param.ContainsKey( "spotlightFalloff" ) )
				{
					light.SpotlightFalloff = (float)Convert.ToDouble( param[ "spotlightFalloff" ].ToString() );
				}
			}

			return light;
		}