Beispiel #1
0
 private void SetColorAndIntensityOfAllLights(Sansar.Color c, float intensity)
 {
     foreach (var light in LightComponents)
     {
         light.SetColorAndIntensity(c, intensity);
     }
 }
Beispiel #2
0
        private void SetColorAndIntensity(LightComponent light, Sansar.Color targetColor, float targetIntensity)
        {
            if (ModeFadeTime <= 0.1f)
            {
                light.SetColorAndIntensity(targetColor, targetIntensity);
            }
            else
            {
                int steps = (int)(ModeFadeTime / 0.1f);
                Sansar.Color currentColor = light.GetNormalizedColor();
                Sansar.Color colorDelta = (targetColor - currentColor) / steps;

                float currentIntensity = light.GetRelativeIntensity();
                float intensityDelta = (targetIntensity - currentIntensity) / steps;
                for(int i=0; i< steps; ++i)
                {
                    currentColor += colorDelta;
                    currentIntensity += intensityDelta;

                    light.SetColorAndIntensity(currentColor, currentIntensity);

                    Wait(TimeSpan.FromSeconds(0.1));
                    if (AbortColorChange) return;
                }

                // Ensure we reach the target:
                light.SetColorAndIntensity(targetColor, targetIntensity);
            }
        }
Beispiel #3
0
    private void PlayLightProgram(int LightProgram, ScriptEventData data)
    {
        fltEffectTime     = float.Parse(EffectTime[LightProgram]);
        fltLightIntensity = float.Parse(LightIntensity[LightProgram]);
        fltLightAngle     = float.Parse(LightAngle[LightProgram]);
        fltLightFallOff   = float.Parse(LightFallOff[LightProgram]);

        spotActive  = false;
        blinkActive = false;
        fadeActive  = false;
        pulseActive = false;
        light.SetAngle(fltLightAngle);
        light.SetAngularFalloff(fltLightFallOff);
        if (RandomColor[LightProgram])
        {
            targetColor.R = (float)random.NextDouble();
            targetColor.G = (float)random.NextDouble();
            targetColor.B = (float)random.NextDouble();
            targetColor.A = LightColor[LightProgram].A;
        }
        else
        {
            targetColor = LightColor[LightProgram];
        }

        if (Effect[LightProgram] == "fade")
        {
            //Log.Write("Fade LightProgram:" + LightProgram);
            //Log.Write("Color: " + LightColor[LightProgram]);
            fltBaseLightIntensity = float.Parse(BaseLightIntensity[LightProgram]);
            //Log.Write("deltaTime: " + EffectParm[LightProgram]);
            deltaTime = float.Parse(EffectParm[LightProgram]);
            //Log.Write("deltaTime: " + deltaTime);
            FadeIn(fltEffectTime, deltaTime);
        }
        if (Effect[LightProgram] == "pulse")
        {
            Log.Write("Pulse1");
            fltBaseLightIntensity = float.Parse(BaseLightIntensity[LightProgram]);
            Log.Write("Pulse2");
            Pulse(fltEffectTime, deltaTime, RandomColor[LightProgram]);
        }
        if (Effect[LightProgram] == "blink")
        {
            Blink(fltEffectTime, RandomColor[LightProgram]);
        }
        if (Effect[LightProgram] == "spot")
        {
            Spot(fltEffectTime, RandomColor[LightProgram]);
        }
    }
Beispiel #4
0
        private void StartInterpolation()
        {
            if ((interpolationCoroutine == null) && HasFadeTime())
            {
                targetColor     = previousColor = LightComponents[0].GetNormalizedColor();
                targetIntensity = previousIntensity = LightComponents[0].GetRelativeIntensity();

                interpolationDuration = 0.0f;
                interpolationTime     = 0.0f;
                interpolationActive   = false;

                interpolationCoroutine = StartCoroutine(InterpolateLightColor);
            }
        }
Beispiel #5
0
        private void InterpolateLightColor()
        {
            const float deltaTime = 0.1f;
            TimeSpan    ts        = TimeSpan.FromSeconds(deltaTime);

            while (true)
            {
                Wait(ts);

                if (interpolationActive)
                {
                    interpolationTime = Math.Max(interpolationTime - deltaTime, 0.0f);

                    float t = interpolationTime / interpolationDuration;

                    Sansar.Color color     = previousColor * t + targetColor * (1.0f - t);
                    float        intensity = previousIntensity * t + targetIntensity * (1.0f - t);

                    SetColorAndIntensityOfAllLights(color, intensity);

                    interpolationActive = (interpolationTime > 0.0f);
                }
            }
        }
Beispiel #6
0
        private void Subscribe(ScriptEventData sed)
        {
            if (subscriptions == null)
            {
                subscriptions = SubscribeToAll(ModeAEvent, (data) =>
                {
                    if (ModeAFadeTime > 0.0f)
                    {
                        previousColor         = LightComponents[0].GetNormalizedColor();
                        previousIntensity     = LightComponents[0].GetRelativeIntensity();
                        targetColor           = ModeAColor;
                        targetIntensity       = ModeAIntensity;
                        interpolationDuration = ModeAFadeTime;
                        interpolationTime     = ModeAFadeTime;
                        interpolationActive   = true;
                    }
                    else
                    {
                        interpolationActive = false;
                        SetColorAndIntensityOfAllLights(ModeAColor, ModeAIntensity);
                    }
                });

                subscriptions += SubscribeToAll(ModeBEvent, (data) =>
                {
                    if (ModeBFadeTime > 0.0f)
                    {
                        previousColor         = LightComponents[0].GetNormalizedColor();
                        previousIntensity     = LightComponents[0].GetRelativeIntensity();
                        targetColor           = ModeBColor;
                        targetIntensity       = ModeBIntensity;
                        interpolationDuration = ModeBFadeTime;
                        interpolationTime     = ModeBFadeTime;
                        interpolationActive   = true;
                    }
                    else
                    {
                        interpolationActive = false;
                        SetColorAndIntensityOfAllLights(ModeBColor, ModeBIntensity);
                    }
                });

                subscriptions += SubscribeToAll(ModeCEvent, (data) =>
                {
                    if (ModeCFadeTime > 0.0f)
                    {
                        previousColor         = LightComponents[0].GetNormalizedColor();
                        previousIntensity     = LightComponents[0].GetRelativeIntensity();
                        targetColor           = ModeCColor;
                        targetIntensity       = ModeCIntensity;
                        interpolationDuration = ModeCFadeTime;
                        interpolationTime     = ModeCFadeTime;
                        interpolationActive   = true;
                    }
                    else
                    {
                        interpolationActive = false;
                        SetColorAndIntensityOfAllLights(ModeCColor, ModeCIntensity);
                    }
                });
            }

            if (HasFadeTime())
            {
                StartInterpolation();
            }
        }