Example #1
0
        public SpaceMouseWPFHandler()
        {
            IntPtr hwnd  = IntPtr.Zero;
            Window myWin = Application.Current.MainWindow;

            try
            {
                hwnd = new WindowInteropHelper(myWin).Handle;
            }
            catch (Exception ex)
            {
                Logger.Error("Setting up 3D-Mice failed:", ex);
            }

            //Get the Hwnd source
            var hwndSource = HwndSource.FromHwnd(hwnd);

            if (hwndSource == null)
            {
                return;
            }

            hwndSource.AddHook(Win32QueueSinkHandler);

            // Connect to Raw Input & find devices
            Active3DxMouse = new SpaceMouse(hwndSource.Handle);

            // Setup event handlers to be called when something happens
            //Active3DxMouse.MotionEvent += MotionEventHandler;
            //Active3DxMouse.ButtonEvent += ButtonEventHandler;

            InitDeviceList();
        }
Example #2
0
        private void App_Exit(object sender, EventArgs e)
        {
            CompositionTarget.Rendering  -= CompositionTarget_RenderingHandler;
            Model.GlobalTimeChangedEvent -= Model_GlobalTimeChangedHandler;

            AutoBackup.Dispose();
            SavePresets();

            OperatorPartContext.DefaultRenderer.Dispose();
            DefaultRenderer.DefaultEffect.Dispose();
            Model.Dispose();
            ResourceManager.DisposeAll();
            D3DDevice.Device.Dispose();
            D3DDevice.DX10_1Device.Dispose();
            D3DDevice.Direct2DFactory.Dispose();
            D3DDevice.DirectWriteFactory.Dispose();

            Logger.Info(SHUT_DOWN_IDENTIFIER);
            Logger.Dispose();

            if (D3DDevice.DebugDevice != null)
            {
                D3DDevice.DebugDevice.ReportLiveDeviceObjects(ReportingLevel.Detail);
                Utilities.DisposeObj(ref D3DDevice.DebugDevice);
            }
        }
Example #3
0
        /**
         *  Primary WPF-handler called before updateing the user interface
         */
        void CompositionTarget_RenderingHandler(object sender, EventArgs e)
        {
            UpdateTimeSinceLastFrame();

            if (CompositionTargertRenderingEvent != null)
            {
                CompositionTargertRenderingEvent(this, EventArgs.Empty);
            }

#if USE_SOCKETS
            try
            {
                UpdateRequiredAfterUserInteraction |= UndoRedoStack.ProcessReceivedCommands();
            }
            catch (Exception exception)
            {
                Logger.Warn("Error when excecuting a remote command:\n'{0}'", exception.Message);
            }
#endif

            if (UpdateRequiredAfterUserInteraction ||
                (MainWindow != null && Math.Abs(MainWindow.CompositionView.PlaySpeed) > 0.001))
            {
                UpdateGlobalTime();

                if (UpdateAfterUserInteractionEvent != null)
                {
                    UpdateAfterUserInteractionEvent(this, new EventArgs());
                }
                UpdateRequiredAfterUserInteraction = false;

                // Flush the dispatcher queue if too long (this is likely to result in frame drops but will ensure responsiveness of controls)
                if (_queueLength > 1)
                {
                    DoEvents();
                }
            }
        }
Example #4
0
        private void SetupApplication()
        {
            //count to length of the Dispatcher-queue to later prevent frozen UI and slaggy performance
            Dispatcher.Hooks.OperationPosted  += (o, e) => Interlocked.Increment(ref _queueLength);
            Dispatcher.Hooks.OperationStarted += (o, e) => Interlocked.Decrement(ref _queueLength);
            Dispatcher.Hooks.OperationAborted += (o, e) => Interlocked.Decrement(ref _queueLength);



            Logger.Initialize(Current.Dispatcher);

            Console.SetOut(new StreamToLogEntryWriter(LogEntry.EntryLevel.INF));
            Console.SetError(new StreamToLogEntryWriter(LogEntry.EntryLevel.ERR));

            ConsoleViewWriter = new Components.Console.ConsoleViewWriter();
            Logger.AddWriter(ConsoleViewWriter);

            if (File.Exists(@"../.dropbox"))
            {
                throw new ArgumentException(String.Format("Tooll may not be started within this dropbox directory.\nPlease make a local copy to your hard drive, e.g. To your desktop."));
            }



            // Load Configu
            if (!Directory.Exists("Config"))
            {
                Logger.Debug("Creating missing directory 'Config'...");
                Directory.CreateDirectory("Config");
            }

            ProjectSettings = new Settings("Config/ProjectSettings.json");
            UserSettings    = new Settings("Config/UserSettings.json");

            if (UserSettings.GetOrSetDefault("Tooll.AutoBackupEnabled", true))
            {
                TryToRecoverFromBackupAfterCrash();
            }

            // Start Logging
            Directory.CreateDirectory(@"Log");
            var logWriter = new FileWriter(String.Format(@"Log/{0}.log", DateTime.Now.ToString("yyyy_MM_dd-HH_mm_ss_fff")))
            {
                Filter = LogEntry.EntryLevel.ALL
            };

            Logger.AddWriter(logWriter);
            Logger.Info(STARTUP_IDENTIFIER_PRECEDING_TIMESTAMP + DateTime.Now);
            Logger.Info("Version: {0}", Core.Utilities.GetCompleteVersionString());


            SetupOperatorGitRepository();
            D3DDevice.Device = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport);

            if (D3DDevice.Device.CreationFlags.HasFlag(DeviceCreationFlags.Debug))
            {
                D3DDevice.DebugDevice = new DeviceDebug(D3DDevice.Device);
            }
            var featureLevel = D3DDevice.Device.FeatureLevel;

            Logger.Info("Found DirectX Device with feature level {0}", featureLevel);

            Logger.Info(".net version {0}", System.Environment.Version);

            using (var dxgiDevice = D3DDevice.Device.QueryInterface <SharpDX.DXGI.Device1>())
            {
                var adapter = dxgiDevice.Adapter;
                D3DDevice.DX10_1Device = new SharpDX.Direct3D10.Device1(adapter, SharpDX.Direct3D10.DeviceCreationFlags.BgraSupport,
                                                                        SharpDX.Direct3D10.FeatureLevel.Level_10_1);
            }
            D3DDevice.Direct2DFactory    = new SharpDX.Direct2D1.Factory();
            D3DDevice.DirectWriteFactory = new SharpDX.DirectWrite.Factory();

            SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericKeyboard, SharpDX.RawInput.DeviceFlags.None, IntPtr.Zero);
            SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericMouse, SharpDX.RawInput.DeviceFlags.None, IntPtr.Zero);
            SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericJoystick, SharpDX.RawInput.DeviceFlags.None, IntPtr.Zero);
            ComponentDispatcher.ThreadFilterMessage += ComponentDispatcher_ThreadFilterMessage;

            ShutdownMode = ShutdownMode.OnExplicitShutdown;
            var progressDialog = new LoadOperatorDefinitionsProgressDialog();

            progressDialog.ShowDialog();
            ShutdownMode = ShutdownMode.OnMainWindowClose;


            Model = new Model();

            var isSender = String.Compare(ProjectSettings.GetOrSetDefault("Tooll.IsHost", "true"), "true", StringComparison.OrdinalIgnoreCase) == 0;

            UndoRedoStack = new UndoRedoStack(isSender);

            if (!UserSettings.Contains("View.WorkspaceMatrices"))
            {
                UserSettings["View.WorkspaceMatrices"] = new Dictionary <Guid, Matrix>();
            }
            else
            {
                var matrices = (JObject)UserSettings["View.WorkspaceMatrices"];
                UserSettings["View.WorkspaceMatrices"] = JsonConvert.DeserializeObject <Dictionary <Guid, Matrix> >(matrices.ToString());
            }

            MetaManager.OPERATOR_TEST_REFERENCE_PATH = ProjectSettings.GetOrSetDefault("Tooll.OperatorTestReferencePath", "assets-ff/test-references/");

            OperatorPresetManager = new OperatorPresetManager();

            AutoBackup = new AutoBackup();
            AutoBackup.SecondsBetweenSaves = (int)UserSettings.GetOrSetDefault("Tooll.AutoBackupPeriodInSeconds", 60 * 5);
            AutoBackup.Enabled             = UserSettings.GetOrSetDefault("Tooll.AutoBackupEnabled", true);

            if (AutoBackup.Enabled)
            {
                AutoBackup.ReduceNumberOfBackups();
            }


            TimeLogger.Enabled = ProjectSettings.GetOrSetDefault("Tooll.ProfilingEnabled", false);

            UpdateRequiredAfterUserInteraction = false;

            CompositionTarget.Rendering  += CompositionTarget_RenderingHandler;
            Model.GlobalTimeChangedEvent += Model_GlobalTimeChangedHandler;
            Exit += App_Exit;

            // Load demo soundtrack and setup bass sound system
            SetupSoundSystemWithSoundtrack();
        }
        public override void PasteKeyframes()
        {
            var addedNewCurves = false;

            List <ICommand> pasteKeyframeCommands   = new List <ICommand>();
            var             curvesWithSelectedTimes = getSelectedOrAllVDefinitions();

            var parameterNamesWithKeys = new Dictionary <String, List <Keyframe> >();

            try
            {
                parameterNamesWithKeys =
                    JsonConvert.DeserializeObject <Dictionary <String, List <Keyframe> > >(
                        Clipboard.GetText());
            }
            catch (Exception e)
            {
                Logger.Warn("Inserting keyframes failed: {0}", e.Message);
                return;
            }

            _updatingCurveEnabled = false;  // prevent update triggered by Curve.Move

            // Compute start and end times
            var minTime = double.PositiveInfinity;
            var maxTime = double.NegativeInfinity;

            foreach (var keyframe in parameterNamesWithKeys.Select(inputNameAndKeys => inputNameAndKeys.Value)
                     .SelectMany(keyframes => keyframes))
            {
                minTime = Math.Min(minTime, keyframe.Time);
                maxTime = Math.Max(maxTime, keyframe.Time);
            }

            // Collect matching curves
            var curvesWithMatchingInputs = new List <ICurve>();

            foreach (var inputNameAndKeys in parameterNamesWithKeys)
            {
                var inputName = inputNameAndKeys.Key;
                var keys      = inputNameAndKeys.Value;

                foreach (var input in curveInputs)
                {
                    if (input.Name != inputName)
                    {
                        continue;
                    }

                    var curve = curvesByInput[input];
                    curvesWithMatchingInputs.Add(curve);
                }
            }

            var curveMapping = new  List <Tuple <ICurve, List <Tuple <double, VDefinition> > > >();

            if (curvesWithMatchingInputs.Count == 0)
            {
                // Check if non-animated inputs exists.
                var parametersToAnimate = parameterNamesWithKeys.Keys.ToList();

                foreach (var se in m_ObservedOperatorWidgets)
                {
                    var opWidget = se as OperatorWidget;
                    if (opWidget == null)
                    {
                        continue;
                    }

                    foreach (var input in opWidget.Operator.Inputs)
                    {
                        if (parametersToAnimate.IndexOf(input.Name) == -1)
                        {
                            continue;
                        }

                        // Skip if already connected
                        if (input.Connections.Count > 0)
                        {
                            continue;
                        }

                        // Animate parameter
                        var addAnimiationCommand = new SetupAnimationCommand(input, App.Current.Model.GlobalTime);
                        App.Current.UndoRedoStack.AddAndExecute(addAnimiationCommand);

                        // Add to list of curves
                        var animationOpPart = Animation.GetRegardingAnimationOpPart(input);
                        var animationCurve  = animationOpPart.Func as ICurve;
                        curvesByInput[input] = animationCurve;
                        curveInputs.Add(input);
                        parametersToAnimate.Remove(input.Name);
                        addedNewCurves = true;
                    }
                }
            }

            // Insert gap to all animated parameters
            foreach (var curve in curvesByInput.Values)
            {
                var points = curve.GetPoints();
                points.Sort((a, b) => a.Key > b.Key ? -1:1);        // If moving unsorted, later keyframes could be overwritten.

                foreach (var timeWithKey in points)
                {
                    var time = timeWithKey.Key;
                    if (time > App.Current.Model.GlobalTime)
                    {
                        var c = new MoveKeyframeCommand(time, time + maxTime - minTime, curve);
                        pasteKeyframeCommands.Add(c);
                    }
                }
            }

            foreach (var inputNameAndKeys in parameterNamesWithKeys)
            {
                var inputName = inputNameAndKeys.Key;
                var keyframes = inputNameAndKeys.Value;

                foreach (var input in curveInputs)
                {
                    if (input.Name != inputName)
                    {
                        continue;
                    }

                    var curve = curvesByInput[input];

                    foreach (var keyframe in keyframes)
                    {
                        pasteKeyframeCommands.Add(new AddOrUpdateKeyframeCommand(keyframe.Time - minTime + App.Current.Model.GlobalTime, keyframe.VDefinition, curve));
                    }
                }
            }

            var macroCommand = new MacroCommand("Paste Keyframes", pasteKeyframeCommands);

            App.Current.UndoRedoStack.AddAndExecute(macroCommand);
            _updatingCurveEnabled = true;
            if (addedNewCurves)
            {
                ShowCurvesForSelectedOperators();
            }
            else
            {
                RebuildCurrentCurves();
            }
        }