protected void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (_loaded)
            {
                return;
            }

            _graphicsDeviceService = new GraphicsDeviceService();
            _renderWindow          = new RenderWindow((int)ActualWidth, (int)ActualHeight, _graphicsDeviceService.Device);
            _backBufferPointer     = _renderWindow.GetBackBufferComPointer();

            _trackball.TransformUpdated += OnTrackballTransformUpdated;
            _trackball.EventSource       = this;

            _renderer = new Renderer(_graphicsDeviceService.Device, GetModel(),
                                     _graphicsDeviceService.Device.Viewport.Width, _graphicsDeviceService.Device.Viewport.Height,
                                     _trackball.Transform);

            ModelEditorViewModel vm = (ModelEditorViewModel)DataContext;

            vm.RenderParametersChanged += (sender2, e2) => Refresh();

            Refresh();

            _loaded = true;
        }
 private Model GetModel()
 {
     if (_model == null)
     {
         ModelEditorViewModel vm = (ModelEditorViewModel)DataContext;
         _model = ModelConverter.FromScene(vm.Scene.Scene, _graphicsDeviceService.Device);
     }
     return(_model);
 }
Beispiel #3
0
        private void Refresh()
        {
            if (_backBufferPointer == IntPtr.Zero)
            {
                return;
            }

            D3DImageSource.Lock();

            // Calling SetBackBuffer repeatedly with the same IntPtr is a no-op, so there's no
            // performance penalty.
            D3DImageSource.SetBackBuffer(D3DResourceType.IDirect3DSurface9, _backBufferPointer, true);

            ModelEditorViewModel vm = (ModelEditorViewModel)DataContext;

            _renderer.Render(vm.RenderParameters);

            D3DImageSource.AddDirtyRect(new Int32Rect(0, 0, (int)ActualWidth, (int)ActualHeight));
            D3DImageSource.Unlock();
        }
        private void Render()
        {
            ModelEditorViewModel vm = (ModelEditorViewModel)DataContext;

            _renderer.Render(vm.RenderParameters);
        }