public override void Run(CommandArgs e)
        {
            var r = new Random();
            var mode = this.Scene.Mode;
            var isModelOrAccessoryOrEffect = mode == EditMode.ModelMode || mode == EditMode.AccessoryMode || mode == EditMode.EffectMode;
            var isCameraSelected = this.Scene.Cameras.SelectMany(_ => _.Layers).SelectMany(_ => _.SelectedFrames).Any();
            var isEnvironmentSelected = this.Scene.SelectedPropertyFrames.Any();

            if (!isModelOrAccessoryOrEffect && !isCameraSelected && !isEnvironmentSelected)
            {
                MessageBox.Show(this.ApplicationForm, Util.Bilingual
                (
                    this.Scene.Language,
                    "対象のモデル、カメラ、アクセサリ、またはエフェクトがありません。\r\n対象のキーフレームを選択してから実行してください。",
                    "No target selected.\r\nPlease select one or more keyframes to apply some noise."
                ), Util.Bilingual(this.Scene.Language, this.Text, this.EnglishText), MessageBoxButtons.OK, MessageBoxIcon.Information);

                e.Cancel = true;

                return;
            }

            using (var f = new ApplyNoiseForm
            {
                KeyFrameInterval = keyFrameInterval,
                KeyShiftWidth = keyShiftWidth,
                NoiseValueInterval = noiseValueInterval,
                NoiseValue = noiseValue,

                IsPositionEnabled = isModelOrAccessoryOrEffect || isCameraSelected,
                IsPositionLocalVisible = isModelOrAccessoryOrEffect,
                IsRotationEnabled = isModelOrAccessoryOrEffect || isCameraSelected,
                IsRotationLocalVisible = isModelOrAccessoryOrEffect,
                IsEnvironmentEnabled = isEnvironmentSelected,
                IsPositionLocal = isPositionLocal,
                IsRotationLocal = isRotationLocal,
            })
            {
                if (f.ShowDialog() != DialogResult.OK)
                {
                    e.Cancel = true;

                    return;
                }

                keyFrameInterval = f.KeyFrameInterval;
                noiseValueInterval = f.NoiseValueInterval;
                noiseValue = f.NoiseValue;
                keyShiftWidth = f.KeyShiftWidth;
                isPositionLocal = f.IsPositionLocal;
                isRotationLocal = f.IsRotationLocal;

                using (new UndoBlock(this.Scene))
                    switch (this.Scene.Mode)
                    {
                        case EditMode.AccessoryMode:
                            var acc = this.Scene.ActiveAccessory;

                            if (acc != null)
                                foreach (var layer in acc.Layers.Where(_ => _.SelectedFrames.Any()))
                                    ProcessLayer(r, layer.SelectedFrames.First().FrameNumber, layer.SelectedFrames.Last().FrameNumber, layer.Frames, isPositionLocal, isRotationLocal, null);

                            break;
                        case EditMode.CameraMode:
                            var camera = this.Scene.ActiveCamera;
                            var env = this.Scene.SelectedPropertyFrames;

                            if (camera != null)
                                foreach (var layer in camera.Layers.Where(_ => _.SelectedFrames.Any()))
                                    ProcessCameraLayer(r, layer.SelectedFrames.First().FrameNumber, layer.SelectedFrames.Last().FrameNumber, layer.Frames);

                            if (env.Any())
                                ProcessEnvironmentLayer(r, env.First().FrameNumber, env.Last().FrameNumber, this.Scene.PropertyFrames);

                            break;
                        case EditMode.EffectMode:
                            var eff = this.Scene.ActiveEffect;

                            if (eff != null)
                                ProcessLayer(r, eff.SelectedFrames.First().FrameNumber, eff.SelectedFrames.Last().FrameNumber, eff.Frames, isPositionLocal, isRotationLocal, null);

                            break;
                        case EditMode.ModelMode:
                            var model = this.Scene.ActiveModel;

                            if (model != null)
                                foreach (var bone in model.Bones)
                                    foreach (var layer in bone.Layers.Where(_ => _.SelectedFrames.Any()))
                                        ProcessLayer(r, layer.SelectedFrames.First().FrameNumber, layer.SelectedFrames.Last().FrameNumber, layer.Frames, isPositionLocal, isRotationLocal, bone);

                            break;
                    }
            }
        }
예제 #2
0
        public override void Run(CommandArgs e)
        {
            var r    = new Random();
            var mode = this.Scene.Mode;
            var isModelOrAccessoryOrEffect = mode == EditMode.ModelMode || mode == EditMode.AccessoryMode || mode == EditMode.EffectMode;
            var isCameraSelected           = this.Scene.Cameras.SelectMany(_ => _.Layers).SelectMany(_ => _.SelectedFrames).Any();
            var isEnvironmentSelected      = this.Scene.SelectedPropertyFrames.Any();

            if (!isModelOrAccessoryOrEffect && !isCameraSelected && !isEnvironmentSelected)
            {
                MessageBox.Show(this.ApplicationForm, Util.Bilingual
                                (
                                    this.Scene.Language,
                                    "対象のモデル、カメラ、アクセサリ、またはエフェクトがありません。\r\n対象のキーフレームを選択してから実行してください。",
                                    "No target selected.\r\nPlease select one or more keyframes to apply some noise."
                                ), Util.Bilingual(this.Scene.Language, this.Text, this.EnglishText), MessageBoxButtons.OK, MessageBoxIcon.Information);

                e.Cancel = true;

                return;
            }

            using (var f = new ApplyNoiseForm
            {
                KeyFrameInterval = keyFrameInterval,
                KeyShiftWidth = keyShiftWidth,
                NoiseValueInterval = noiseValueInterval,
                NoiseValue = noiseValue,

                IsPositionEnabled = isModelOrAccessoryOrEffect || isCameraSelected,
                IsPositionLocalVisible = isModelOrAccessoryOrEffect,
                IsRotationEnabled = isModelOrAccessoryOrEffect || isCameraSelected,
                IsRotationLocalVisible = isModelOrAccessoryOrEffect,
                IsEnvironmentEnabled = isEnvironmentSelected,
                IsPositionLocal = isPositionLocal,
                IsRotationLocal = isRotationLocal,
            })
            {
                if (f.ShowDialog() != DialogResult.OK)
                {
                    e.Cancel = true;

                    return;
                }

                keyFrameInterval   = f.KeyFrameInterval;
                noiseValueInterval = f.NoiseValueInterval;
                noiseValue         = f.NoiseValue;
                keyShiftWidth      = f.KeyShiftWidth;
                isPositionLocal    = f.IsPositionLocal;
                isRotationLocal    = f.IsRotationLocal;

                using (new UndoBlock(this.Scene))
                    switch (this.Scene.Mode)
                    {
                    case EditMode.AccessoryMode:
                        var acc = this.Scene.ActiveAccessory;

                        if (acc != null)
                        {
                            foreach (var layer in acc.Layers.Where(_ => _.SelectedFrames.Any()))
                            {
                                ProcessLayer(r, layer.SelectedFrames.First().FrameNumber, layer.SelectedFrames.Last().FrameNumber, layer.Frames, isPositionLocal, isRotationLocal, null);
                            }
                        }

                        break;

                    case EditMode.CameraMode:
                        var camera = this.Scene.ActiveCamera;
                        var env    = this.Scene.SelectedPropertyFrames;

                        if (camera != null)
                        {
                            foreach (var layer in camera.Layers.Where(_ => _.SelectedFrames.Any()))
                            {
                                ProcessCameraLayer(r, layer.SelectedFrames.First().FrameNumber, layer.SelectedFrames.Last().FrameNumber, layer.Frames);
                            }
                        }

                        if (env.Any())
                        {
                            ProcessEnvironmentLayer(r, env.First().FrameNumber, env.Last().FrameNumber, this.Scene.PropertyFrames);
                        }

                        break;

                    case EditMode.EffectMode:
                        var eff = this.Scene.ActiveEffect;

                        if (eff != null)
                        {
                            ProcessLayer(r, eff.SelectedFrames.First().FrameNumber, eff.SelectedFrames.Last().FrameNumber, eff.Frames, isPositionLocal, isRotationLocal, null);
                        }

                        break;

                    case EditMode.ModelMode:
                        var model = this.Scene.ActiveModel;

                        if (model != null)
                        {
                            foreach (var bone in model.Bones)
                            {
                                foreach (var layer in bone.Layers.Where(_ => _.SelectedFrames.Any()))
                                {
                                    ProcessLayer(r, layer.SelectedFrames.First().FrameNumber, layer.SelectedFrames.Last().FrameNumber, layer.Frames, isPositionLocal, isRotationLocal, bone);
                                }
                            }
                        }

                        break;
                    }
            }
        }