public SpecialLineRendering()
        {
            InitializeComponent();


            // First create HiddenLineMaterial
            _hiddenLineMaterial = new HiddenLineMaterial()
            {
                LineColor     = Colors.Yellow.ToColor4(),
                LineThickness = 1f,
                LinePattern   = 0x1111,
            };

            // Also create a DXEngine's LineMaterial (it will be used by the ScreenSpaceLineNode and to render wireframe object)
            _dxLineMaterial = new LineMaterial()
            {
                LineThickness = 1,
                LineColor     = Colors.Yellow.ToColor4(),
                DepthBias     = 0.1f
                                // Set DepthBias to prevent rendering wireframe at the same depth as the 3D objects. This creates much nicer 3D lines because lines are rendered on top of 3D object and not in the same position as 3D object.
            };

            CreateTest3DObjects();

            MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs args)
            {
                if (MainDXViewportView.DXScene == null)
                {
                    return; // Probably WPF 3D rendering
                }
                CreateSceneNodesDictionary();

                // After the DXScene was initialized and the DXEngine's SceneNodes objects are created,
                // we can set advanced DXEngine properties
                ShowVisibleAndHiddenLines();
            };


            // IMPORTANT:
            // It is very important to call Dispose method on DXSceneView after the control is not used any more (see help file for more info)
            this.Unloaded += delegate
            {
                if (_hiddenLineMaterial != null)
                {
                    _hiddenLineMaterial.Dispose();
                    _hiddenLineMaterial = null;
                }

                if (_dxLineMaterial != null)
                {
                    _dxLineMaterial.Dispose();
                    _dxLineMaterial = null;
                }

                MainDXViewportView.Dispose();
            };
        }
        public SpecialLineRendering()
        {
            InitializeComponent();


            // First create HiddenLineMaterial
            _hiddenLineMaterial = new HiddenLineMaterial()
            {
                LineColor     = Colors.Yellow.ToColor4(),
                LineThickness = 1f, // Use very small line thickness (smaller than 1)
                LinePattern   = 0x1111,
            };

            CreateTest3DObjects();

            MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs args)
            {
                CreateSceneNodesDictionary();

                // After the DXScene was initialized and the DXEngine's SceneNodes objects are created,
                // we can set advanced DXEngine properties
                ShowVisibleAndHiddenLines();
            };


            // IMPORTANT:
            // It is very important to call Dispose method on DXSceneView after the control is not used any more (see help file for more info)
            this.Unloaded += delegate
            {
                if (_hiddenLineMaterial != null)
                {
                    _hiddenLineMaterial.Dispose();
                    _hiddenLineMaterial = null;
                }

                if (_dxLineMaterial != null)
                {
                    _dxLineMaterial.Dispose();
                    _dxLineMaterial = null;
                }

                MainDXViewportView.Dispose();
            };
        }
Exemple #3
0
        private void unloadGL()
        {
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);
            GL.BindVertexArray(0);
            GL.UseProgram(0);

            GL.DeleteFramebuffer(frameBufferObject);
            GL.DeleteBuffer(quadVertexObject);
            GL.DeleteVertexArray(quadArrayObject);
            GL.DeleteBuffer(vertexBufferObject);
            GL.DeleteBuffer(elementBufferObject);
            GL.DeleteVertexArray(vertexArrayObject);
            lineMat.Dispose();
            blitMat.Dispose();
            threshMat.Dispose();
            blurMat.Dispose();
        }
        public VertexColorRenderingSample()
        {
            InitializeComponent();

            CreateGradientColorsArray();

            // Use CameraControllerInfo to show that we can use left mouse button to set custom beam destination on the 3D model
            CameraControllerInfo.AddCustomInfoLine(0, MouseCameraController.MouseAndKeyboardConditions.LeftMouseButtonPressed, "SET BEAM DESTINATION");

            // When the ViewportBorder size is change the size of the overlay Canvas (drawn over the 3D scene)
            ViewportBorder.SizeChanged += delegate(object sender, SizeChangedEventArgs args)
            {
                UpdateOverlayCanvasSize();
            };


            // Process mouse events
            ViewportBorder.MouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e)
            {
                // Start user beam control
                _isUserBeamControl = true;

                ViewportBorder.CaptureMouse();

                var position = e.GetPosition(ViewportBorder);
                ProcessMouseHit(position);
            };

            ViewportBorder.MouseLeftButtonUp += delegate(object sender, MouseButtonEventArgs e)
            {
                // Stop user beam control
                _isUserBeamControl = false;
                ViewportBorder.ReleaseMouseCapture();

                ProcessMouseOutOfModel();
            };

            // Subscribe to MouseMove to allow user to specify the beam target
            ViewportBorder.MouseMove += delegate(object sender, MouseEventArgs e)
            {
                if (_isUserBeamControl)
                {
                    ProcessMouseHit(e.GetPosition(ViewportBorder));
                }
                else
                {
                    ProcessMouseOutOfModel();
                }
            };


            // Start animating the beam position
            CompositionTarget.Rendering += CompositionTargetOnRendering;


            // We add test models after the DXScene is initialized (this is required because specifal effects require DirectX device)
            MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs e)
            {
                if (MainDXViewportView.DXScene == null)
                {
                    return; // Probably WPF 3D rendering
                }
                // Get _vertexColorEffect that will be used to render model with vertex colors (note that this field must be disposed when it is not used any more - here in Unloaded event handler)

                AddTestModels();
            };

            // Cleanup
            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                CompositionTarget.Rendering -= CompositionTargetOnRendering;

                if (_vertexColorMaterial != null)
                {
                    _vertexColorMaterial.Dispose();
                    _vertexColorMaterial = null;
                }

                if (_lineMaterial != null)
                {
                    _lineMaterial.Dispose();
                    _lineMaterial = null;
                }

                MainDXViewportView.Dispose();
            };
        }