Beispiel #1
0
 public static string TransformLightType(LightType type)
 {
     if (mLightTypeTransform.ContainsKey(type.ToString()))
     {
         return(mLightTypeTransform[type.ToString()]);
     }
     return(type.ToString());
 }
        /// <summary>
        /// Constructor or added a new light to the scene
        /// </summary>
        /// <param name="type">the light type you wish to have or default of point</param>
        public LightClass(LightType type = LightType.Point)
        {
            if (type == LightType.Point)
            {
                light.Type = type;
                light.Diffuse = Color.White;
                light.Ambient = Color.White;
                light.Specular = Color.White;
                light.Position = Vector3.Zero;
                light.Range = 100.0f;

            }
            else if (type == LightType.Directional)
            {
                light.Type = type;
                light.Direction = Vector3.Zero;
                light.Ambient = Color.White;
                light.Diffuse = Color.White;
                light.Specular = Color.White;
                light.Range = 100.0f;
            }

            isLightEnabled = false;
            Type = type.ToString();
            Position = Vector3.Zero;
            Direction = Vector3.Zero;
            world = Matrix.Identity;
            mesh = Mesh.CreateSphere(DeviceManager.LocalDevice, .1f, 10, 10);

            material.Diffuse = Color.White;
            material.Ambient = Color.White;

            DeviceManager.LocalDevice.Material = material;
        }
        /// <summary>
        /// Constructor or added a new light to the scene
        /// </summary>
        /// <param name="type">the light type you wish to have or default of point</param>
        public LightClass(LightType type = LightType.Point)
        {
            if (type == LightType.Point)
            {
                light.Type     = type;
                light.Diffuse  = Color.White;
                light.Ambient  = Color.White;
                light.Specular = Color.White;
                light.Position = Vector3.Zero;
                light.Range    = 100.0f;
            }
            else if (type == LightType.Directional)
            {
                light.Type      = type;
                light.Direction = Vector3.Zero;
                light.Ambient   = Color.White;
                light.Diffuse   = Color.White;
                light.Specular  = Color.White;
                light.Range     = 100.0f;
            }

            isLightEnabled = false;
            Type           = type.ToString();
            Position       = Vector3.Zero;
            Direction      = Vector3.Zero;
            world          = Matrix.Identity;
            mesh           = Mesh.CreateSphere(DeviceManager.LocalDevice, .1f, 10, 10);

            material.Diffuse = Color.White;
            material.Ambient = Color.White;

            DeviceManager.LocalDevice.Material = material;
        }
Beispiel #4
0
        void OnWizardCreate()
        {
            GameObject go = new GameObject(lightType.ToString() + " Light"); //Create new light gameobject
            Light      lt = go.AddComponent <Light>();                       //Attach the light

            //Configure light
            lt.type  = lightType;
            lt.range = range;
            lt.color = color;
        }
Beispiel #5
0
        public void UpdateProperties()
        {
            lightComponent.type           = lightType;
            lightComponent.color          = color;
            lightComponent.intensity      = brightness;
            lightComponent.shadowStrength = shadowStrength;
            lightComponent.range          = range;
            lightComponent.spotAngle      = fov;

            if (transform.childCount > 1)
            {
                foreach (Transform t in transform)
                {
                    Destroy(t.gameObject);
                }
            }
            else if (transform.childCount > 0)
            {
                var    t       = transform.GetChild(0);
                string newName = lightType.ToString();
                if (t.name != newName)
                {
                    Destroy(t.gameObject);

                    var view = Instantiate(ObjectStorage.Instance.lightObjects[(int)lightType], transform);
                    view.localPosition = Vector3.zero;
                    view.localRotation = Quaternion.identity;
                    view.name          = newName;
                }
            }
            else
            {
                string newName = lightType.ToString();
                var    view    = Instantiate(ObjectStorage.Instance.lightObjects[(int)lightType], transform);
                view.localPosition = Vector3.zero;
                view.localRotation = Quaternion.identity;
                view.name          = newName;
            }
        }
Beispiel #6
0
 public override void GetObjectProperties(NameValuePairList retList)
 {
     retList.Clear();
     retList["Name"]        = Name;
     retList["LightType"]   = LightType.ToString();
     retList["Position"]    = StringConverter.ToString(Position);
     retList["Direction"]   = StringConverter.ToString(Direction);
     retList["Diffuse"]     = StringConverter.ToString(Diffuse);
     retList["Specular"]    = StringConverter.ToString(Specular);
     retList["LightRange"]  = StringConverter.ToString(Range);
     retList["Attenuation"] = StringConverter.ToString(Attenuation);
     retList["CastShadows"] = StringConverter.ToString(CastShadows);
     retList["Power"]       = StringConverter.ToString(Power);
 }
Beispiel #7
0
        public override void Render(StringBuilder sb)
        {
            //<PointLight DEF='point' on='TRUE' intensity='0.9000' color='0.64 0.65 0.5' location='-1.4 0.47 0.75' radius='5.0000' >  </PointLight>

            TagName = LightType.ToString();
            AddProperty("direction", Vector3.ToString(Direction));
            AddProperty("location", Vector3.ToString(Location));
            AddProperty("intensity", Intensity.ToSlamString());
            AddProperty("shadowIntensity", ShadowIntensity.ToSlamString());
            AddProperty("color", Vector3.ToString(Color));
            AddProperty("radius", Radius.ToSlamString());
            AddProperty("range", Range.ToSlamString());

            base.Render(sb);
        }
        override public void Serialize(JsonWriter writer)
        {
            writer.WriteStartObject();

            writer.WritePropertyName(PNAME_TYPE);
            writer.WriteValue(Type.ToString());


            if (Color != COLOR_DEFAULT)
            {
                writer.WritePropertyName(PNAME_COLOR);
                writer.WriteStartArray();
                writer.WriteValue(Color.R);
                writer.WriteValue(Color.G);
                writer.WriteValue(Color.B);
                writer.WriteEndArray();
            }

            if (Intensity != INTENSITY_DEFAULT)
            {
                writer.WritePropertyName(PNAME_INTENSITY);
                writer.WriteValue(Intensity);
            }

            if (Range != RANGE_DEFAULT)
            {
                writer.WritePropertyName(PNAME_RANGE);
                writer.WriteValue(Range);
            }

            if (Type == LightType.spot)
            {
                writer.WritePropertyName(PNAME_SPOT);
                Spot.Serialize(writer);
            }


            base.Serialize(writer);

            writer.WriteEndObject();
        }
Beispiel #9
0
        public virtual XmlElement Save(XmlDocument xmlDoc)
        {
            XmlElement xmlNode = xmlDoc.CreateElement(TypeDescriptor.GetClassName(this));

            xmlNode.SetAttribute("LightType", lightType.ToString());
            xmlNode.SetAttribute("Enabled", enabled.ToString());
            xmlNode.SetAttribute("Diffuse", diffuse.ToString());
            xmlNode.SetAttribute("Specular", specular.ToString());

            if (lightType == LightType.Point)
            {
                xmlNode.SetAttribute("Position", position.ToString());
                xmlNode.SetAttribute("Attenuation0", attenuation0.ToString());
                xmlNode.SetAttribute("Attenuation1", attenuation1.ToString());
                xmlNode.SetAttribute("Attenuation2", attenuation2.ToString());
                xmlNode.SetAttribute("Range", range.ToString());
            }
            else if (lightType == LightType.Directional)
            {
                xmlNode.SetAttribute("Direction", direction.ToString());
            }
            else
            {
                xmlNode.SetAttribute("Position", position.ToString());
                xmlNode.SetAttribute("Direction", direction.ToString());
                xmlNode.SetAttribute("Attenuation0", attenuation0.ToString());
                xmlNode.SetAttribute("Attenuation1", attenuation1.ToString());
                xmlNode.SetAttribute("Attenuation2", attenuation2.ToString());
                xmlNode.SetAttribute("Range", range.ToString());
                xmlNode.SetAttribute("Falloff", falloff.ToString());
                xmlNode.SetAttribute("InnerConeAngle", innerConeAngle.ToString());
                xmlNode.SetAttribute("OuterConeAngle", outerConeAngle.ToString());
            }

            return(xmlNode);
        }
 public static string TransformLightType( LightType type )
 {
     if( mLightTypeTransform.ContainsKey( type.ToString())) {
         return mLightTypeTransform[ type.ToString() ];
     }
     return type.ToString();
 }