Example #1
0
        void UpdateColor()
        {
            JSONObject fixtureDef = FixtureLibrary.Instance.GetFixtureDef(libraryPath);

            if (fixtureDef == null)
            {
                return;
            }

            Light fixtureLight = GetComponent <Light>();

            for (int i = 0; i < wheelNames.Count; i++)
            {
                string wheelName = wheelNames[i];
                Wheel  wheel     = wheelData[i];

                JSONArray  slots     = fixtureDef["wheels"][wheelName]["slots"] as JSONArray;
                int        numSlots  = slots.Count;
                int        slotIndex = (int)wheel.slot;
                float      t         = wheel.slot - slotIndex;
                JSONObject slotA     = slots[Mod(slotIndex - 1, numSlots)] as JSONObject;
                JSONObject slotB     = slots[Mod(slotIndex, numSlots)] as JSONObject;

                if (slotA["type"] == "Color")
                {
                    Color colorA = FixtureLibrary.ParseColorArray(slotA["colors"] as JSONArray);
                    Color colorB = FixtureLibrary.ParseColorArray(slotB["colors"] as JSONArray);
                    Color color  = (1 - t) * colorA + t * colorB;

                    _red   = color.r;
                    _green = color.g;
                    _blue  = color.b;

                    // TODO: color temperature
                }

                // wheel rotation
                if (Application.isPlaying)
                {
                    wheel.slot += wheel.speed * Time.deltaTime;
                    if (wheel.slot >= numSlots + 1)
                    {
                        wheel.slot -= numSlots;
                    }
                    if (wheel.slot < 1)
                    {
                        wheel.slot += numSlots;
                    }
                }
            }

            // color temperature mode
            if (_colorTemperature > 0)
            {
                fixtureLight.color            = Color.white;
                fixtureLight.colorTemperature = _colorTemperature;
            }
            else
            {
                if (isMatrix)
                {
                    Color          color  = Color.black;
                    MeshRenderer[] pixels = GetComponentsInChildren <MeshRenderer>();
                    foreach (MeshRenderer pixel in pixels)
                    {
                        // TODO: white channel
                        color += pixel.sharedMaterial.color;
                    }
                    fixtureLight.color = color / pixels.Length;
                }
                else
                {
                    fixtureLight.color = new Color(_red + _white, _green + _white, _blue + _white);
                }

                fixtureLight.colorTemperature = 6500;
            }
        }
Example #2
0
        void UpdateChannel(int channelIndex)
        {
            if (!useLibrary)
            {
                return;
            }

            string     channelName     = channelNames[channelIndex];
            string     channelKey      = FixtureLibrary.ParseTemplateChannelKey(channelName);
            string     channelPixelKey = FixtureLibrary.ParseTemplatePixelKey(channelName);
            JSONObject channel         = GetChannelDef(channelKey, channelPixelKey);

            if (channel == null)
            {
                return;
            }

            JSONObject capability = channel["capability"] as JSONObject;

            if (capability == null)
            {
                JSONArray capabilities = channel["capabilities"] as JSONArray;
                for (int i = 0; i < capabilities.Count; i++)
                {
                    capability = capabilities[i] as JSONObject;
                    if (_values[channelIndex] <= capability["dmxRange"][1])
                    {
                        break;
                    }
                }
            }

            if (capability == null)
            {
                return;
            }

            string capabilityType = capability["type"];

            if (capabilityType == "Pan")
            {
                _panTarget = FixtureLibrary.GetFloatProperty(capability, "angle", FixtureLibrary.Entity.RotationAngle, _values[channelIndex]);

                UpdateTransform();
            }
            else if (capabilityType == "Tilt")
            {
                _tiltTarget = FixtureLibrary.GetFloatProperty(capability, "angle", FixtureLibrary.Entity.RotationAngle, _values[channelIndex]);

                UpdateTransform();
            }
            else if (capabilityType == "PanTiltSpeed")
            {
                _panSpeed = _tiltSpeed = FixtureLibrary.GetFloatProperty(capability, "speed", FixtureLibrary.Entity.Speed, _values[channelIndex]);
            }
            else if (capabilityType == "Intensity")
            {
                _intensity = FixtureLibrary.GetFloatProperty(capability, "brightness", FixtureLibrary.Entity.Brightness, _values[channelIndex]);

                UpdateIntensity();
            }
            else if (capabilityType == "ColorIntensity")
            {
                string colorKey  = capability["color"];
                float  intensity = FixtureLibrary.GetFloatProperty(capability, "brightness", FixtureLibrary.Entity.Brightness, _values[channelIndex]);

                // TODO: not just for color channels
                if (!string.IsNullOrEmpty(channelPixelKey))
                {
                    Transform pixel = transform.Find(channelPixelKey);
                    if (pixel == null)
                    {
                        foreach (JSONString p in fixtureDef["matrix"]["pixelGroups"][channelPixelKey] as JSONArray)
                        {
                            pixel = transform.Find(p);
                            SetPixelColor(pixel, colorKey, intensity);
                        }
                    }
                    else
                    {
                        SetPixelColor(pixel, colorKey, intensity);
                    }
                }
                else
                {
                    if (colorKey == "Red")
                    {
                        _red = intensity;
                    }
                    else if (colorKey == "Green")
                    {
                        _green = intensity;
                    }
                    else if (colorKey == "Blue")
                    {
                        _blue = intensity;
                    }
                    else if (colorKey == "White")
                    {
                        _white = intensity;
                    }
                }

                // TODO: more colors

                UpdateColor();
            }
            else if (capabilityType == "Zoom")
            {
                _beamAngle = FixtureLibrary.GetFloatProperty(capability, "angle", FixtureLibrary.Entity.BeamAngle, _values[channelIndex]);

                UpdateSpotAngle();
            }
            else if (capabilityType == "ShutterStrobe")
            {
                _shutterEffect = FixtureLibrary.ParseEffect(capability["shutterEffect"]);
                _shutterSpeed  = FixtureLibrary.GetFloatProperty(capability, "speed", FixtureLibrary.Entity.Speed, _values[channelIndex]);

                UpdateShutter();
            }
            else if (capabilityType == "ColorTemperature")
            {
                _colorTemperature = FixtureLibrary.GetFloatProperty(capability, "colorTemperature", FixtureLibrary.Entity.ColorTemperature, _values[channelIndex]);

                UpdateColor();
            }
            else if (capabilityType == "ColorPreset")
            {
                if (capability["colors"] != null)
                {
                    Color color = FixtureLibrary.ParseColorArray(capability["colors"] as JSONArray);

                    _red   = color.r;
                    _green = color.g;
                    _blue  = color.b;
                }

                if (capability["colorsTemperature"] != null)
                {
                    _colorTemperature = FixtureLibrary.GetFloatProperty(capability, "colorTemperature", FixtureLibrary.Entity.ColorTemperature, _values[channelIndex]);
                }

                UpdateColor();
            }
            else if (capabilityType == "WheelSlot")
            {
                string wheelName = channelKey;
                if (capability["wheel"] != null)
                {
                    wheelName = capability["wheel"];
                }

                Wheel wheel = GetWheel(wheelName);
                if (wheel != null)
                {
                    wheel.slot  = FixtureLibrary.GetFloatProperty(capability, "slotNumber", FixtureLibrary.Entity.SlotNumber, _values[channelIndex]);
                    wheel.speed = 0;
                }

                UpdateColor();
            }
            else if (capabilityType == "WheelRotation")
            {
                string wheelName = channelKey;
                if (capability["wheel"] != null)
                {
                    wheelName = capability["wheel"];
                }

                Wheel wheel = GetWheel(wheelName);
                if (wheel != null)
                {
                    wheel.speed = FixtureLibrary.GetFloatProperty(capability, "speed", FixtureLibrary.Entity.Speed, _values[channelIndex]);
                }
            }
            else if (capabilityType == "NoFunction")
            {
                // TODO this is a hack for some bad ficture defs
                if (channelKey == "Strobe")
                {
                    _shutterEffect = FixtureLibrary.ShutterEffect.Open;
                }

                UpdateShutter();
            }
        }