Ejemplo n.º 1
0
        public CommandAddKeyframes(GameObject obj) : base("Add Keyframes")
        {
            gObject = obj;
            Interpolation interpolation = GlobalState.Settings.interpolation;
            int           frame         = GlobalState.Animation.CurrentFrame;

            new CommandAddKeyframe(gObject, AnimatableProperty.PositionX, frame, gObject.transform.localPosition.x, interpolation).Submit();
            new CommandAddKeyframe(gObject, AnimatableProperty.PositionY, frame, gObject.transform.localPosition.y, interpolation).Submit();
            new CommandAddKeyframe(gObject, AnimatableProperty.PositionZ, frame, gObject.transform.localPosition.z, interpolation).Submit();

            // convert to ZYX euler
            Vector3 angles = gObject.transform.localEulerAngles;

            new CommandAddKeyframe(gObject, AnimatableProperty.RotationX, frame, angles.x, interpolation).Submit();
            new CommandAddKeyframe(gObject, AnimatableProperty.RotationY, frame, angles.y, interpolation).Submit();
            new CommandAddKeyframe(gObject, AnimatableProperty.RotationZ, frame, angles.z, interpolation).Submit();

            CameraController controller  = gObject.GetComponent <CameraController>();
            LightController  lcontroller = gObject.GetComponent <LightController>();

            if (null != controller)
            {
                new CommandAddKeyframe(gObject, AnimatableProperty.CameraFocal, frame, controller.focal, interpolation).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.CameraFocus, frame, controller.Focus, interpolation).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.CameraAperture, frame, controller.aperture, interpolation).Submit();
            }
            else if (null != lcontroller)
            {
                new CommandAddKeyframe(gObject, AnimatableProperty.Power, frame, lcontroller.Power, interpolation).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.ColorR, frame, lcontroller.Color.r, interpolation).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.ColorG, frame, lcontroller.Color.g, interpolation).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.ColorB, frame, lcontroller.Color.b, interpolation).Submit();
            }
            else
            {
                // Scale
                Vector3 scale = gObject.transform.localScale;
                new CommandAddKeyframe(gObject, AnimatableProperty.ScaleX, frame, scale.x, interpolation).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.ScaleY, frame, scale.y, interpolation).Submit();
                new CommandAddKeyframe(gObject, AnimatableProperty.ScaleZ, frame, scale.z, interpolation).Submit();
            }
        }
Ejemplo n.º 2
0
        private void OnBoolChangeParameter(string param, bool value)
        {
            foreach (GameObject gobject in Selection.SelectedObjects)
            {
                LightController lightingController = gobject.GetComponent <LightController>();
                if (null == lightingController)
                {
                    continue;
                }
                if (param == "CastShadows")
                {
                    lightingController.CastShadows = value;
                }

                if (param == "Enable")
                {
                    Light light = gobject.transform.GetComponentInChildren <Light>(true);
                    light.gameObject.SetActive(value);
                }

                SendLightParams(gobject);
            }
        }
Ejemplo n.º 3
0
        protected override void UpdateUI()
        {
            foreach (var gobject in Selection.SelectedObjects)
            {
                LightController lightController = gobject.GetComponent <LightController>();
                if (null == lightController)
                {
                    continue;
                }

                GlobalState.CurrentColor = lightController.Color;

                SetSliderValues(intensitySlider, lightController.Intensity, lightController.minIntensity, lightController.maxIntensity);
                SetSliderValues(rangeSlider, lightController.Range, lightController.minRange, lightController.maxRange);
                SetSliderValues(sharpnessSlider, lightController.Sharpness, 0f, 100f);
                SetSliderValues(outerAngleSlider, lightController.OuterAngle, 0f, 180f);

                SetCheckboxValue(castShadowsCheckbox, lightController.CastShadows);
                SetCheckboxValue(enableCheckbox, gobject.activeSelf);

                // Only the first light sets its parameters to the widgets
                break;
            }
        }
Ejemplo n.º 4
0
        void RecordFrame()
        {
            foreach (var selected in Selection.ActiveObjects)
            {
                if (!recordingObjects.TryGetValue(selected, out AnimationSet animationSet))
                {
                    oldAnimations.Add(selected, GetObjectAnimation(selected));

                    // Remove existing animation
                    animations.Remove(selected);
                    onRemoveAnimation.Invoke(selected);

                    // Create new one
                    animationSet = new AnimationSet(selected);
                    recordingObjects.Add(selected, animationSet);
                }

                foreach (Curve curve in animationSet.curves.Values)
                {
                    Vector3 position = selected.transform.localPosition;
                    Vector3 rotation = selected.transform.localEulerAngles;
                    Vector3 scale    = selected.transform.localScale;

                    float           power           = -1;
                    Color           color           = Color.white;
                    LightController lightController = selected.GetComponent <LightController>();
                    if (null != lightController)
                    {
                        power = lightController.Power;
                        color = lightController.Color;
                    }

                    float            cameraFocal      = -1;
                    float            cameraFocus      = -1;
                    float            cameraAperture   = -1;
                    CameraController cameraController = selected.GetComponent <CameraController>();
                    if (null != cameraController)
                    {
                        cameraFocal    = cameraController.focal;
                        cameraFocus    = cameraController.Focus;
                        cameraAperture = cameraController.aperture;
                    }

                    switch (curve.property)
                    {
                    case AnimatableProperty.PositionX: curve.AppendKey(new AnimationKey(currentFrame, position.x)); break;

                    case AnimatableProperty.PositionY: curve.AppendKey(new AnimationKey(currentFrame, position.y)); break;

                    case AnimatableProperty.PositionZ: curve.AppendKey(new AnimationKey(currentFrame, position.z)); break;

                    case AnimatableProperty.RotationX: AppendFilteredKey(curve, currentFrame, rotation.x); break;

                    case AnimatableProperty.RotationY: AppendFilteredKey(curve, currentFrame, rotation.y); break;

                    case AnimatableProperty.RotationZ: AppendFilteredKey(curve, currentFrame, rotation.z); break;

                    case AnimatableProperty.ScaleX: curve.AppendKey(new AnimationKey(currentFrame, scale.x)); break;

                    case AnimatableProperty.ScaleY: curve.AppendKey(new AnimationKey(currentFrame, scale.y)); break;

                    case AnimatableProperty.ScaleZ: curve.AppendKey(new AnimationKey(currentFrame, scale.z)); break;

                    case AnimatableProperty.Power: curve.AppendKey(new AnimationKey(currentFrame, power)); break;

                    case AnimatableProperty.ColorR: curve.AppendKey(new AnimationKey(currentFrame, color.r)); break;

                    case AnimatableProperty.ColorG: curve.AppendKey(new AnimationKey(currentFrame, color.g)); break;

                    case AnimatableProperty.ColorB: curve.AppendKey(new AnimationKey(currentFrame, color.b)); break;

                    case AnimatableProperty.CameraFocal: curve.AppendKey(new AnimationKey(currentFrame, cameraFocal)); break;

                    case AnimatableProperty.CameraFocus: curve.AppendKey(new AnimationKey(currentFrame, cameraFocus)); break;

                    case AnimatableProperty.CameraAperture: curve.AppendKey(new AnimationKey(currentFrame, cameraAperture)); break;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void EvaluateAnimations()
        {
            foreach (AnimationSet animationSet in animations.Values)
            {
                Transform trans    = animationSet.transform;
                Vector3   position = trans.localPosition;
                Vector3   rotation = trans.localEulerAngles;
                Vector3   scale    = trans.localScale;

                float power = -1;
                Color color = Color.white;

                float cameraFocal    = -1;
                float cameraFocus    = -1;
                float cameraAperture = -1;

                foreach (Curve curve in animationSet.curves.Values)
                {
                    if (!curve.Evaluate(currentFrame, out float value))
                    {
                        continue;
                    }
                    switch (curve.property)
                    {
                    case AnimatableProperty.PositionX: position.x = value; break;

                    case AnimatableProperty.PositionY: position.y = value; break;

                    case AnimatableProperty.PositionZ: position.z = value; break;

                    case AnimatableProperty.RotationX: rotation.x = value; break;

                    case AnimatableProperty.RotationY: rotation.y = value; break;

                    case AnimatableProperty.RotationZ: rotation.z = value; break;

                    case AnimatableProperty.ScaleX: scale.x = value; break;

                    case AnimatableProperty.ScaleY: scale.y = value; break;

                    case AnimatableProperty.ScaleZ: scale.z = value; break;

                    case AnimatableProperty.Power: power = value; break;

                    case AnimatableProperty.ColorR: color.r = value; break;

                    case AnimatableProperty.ColorG: color.g = value; break;

                    case AnimatableProperty.ColorB: color.b = value; break;

                    case AnimatableProperty.CameraFocal: cameraFocal = value; break;

                    case AnimatableProperty.CameraFocus: cameraFocus = value; break;

                    case AnimatableProperty.CameraAperture: cameraAperture = value; break;
                    }
                }

                trans.localPosition    = position;
                trans.localEulerAngles = rotation;
                trans.localScale       = scale;

                if (power != -1)
                {
                    LightController controller = trans.GetComponent <LightController>();
                    controller.Power = power;
                    controller.Color = color;
                }

                if (cameraFocal != -1 || cameraFocus != -1 || cameraAperture != -1)
                {
                    CameraController controller = trans.GetComponent <CameraController>();
                    if (cameraFocal != -1)
                    {
                        controller.focal = cameraFocal;
                    }
                    if (cameraFocus != -1)
                    {
                        controller.Focus = cameraFocus;
                    }
                    if (cameraAperture != -1)
                    {
                        controller.aperture = cameraAperture;
                    }
                }
            }
        }