コード例 #1
0
        public StandardXaml()
        {
            InitializeComponent();


            // Code snippets:

            // Force using WPF 3D rendering (useful for comparison of performance)
            //MainDXViewportView.GraphicsProfiles = new GraphicsProfile[] { GraphicsProfile.Wpf3D };


            // Force using Software rendering (for example for server side rendering)
            //MainDXViewportView.GraphicsProfiles = new GraphicsProfile[] { GraphicsProfile.NormalQualitySoftwareRendering };


            // Enable collecting rendering statistics (times required for each rendering phase). Statistics can be then read from MainDXViewportView.DXScene.Statistics object.
            //Ab3d.DirectX.DXDiagnostics.IsCollectingStatistics = true;


            // Enable logging (no info and trace level logging is compiled into relase build - only warnings and errors)
            //Ab3d.DirectX.DXDiagnostics.LogLevel = DXDiagnostics.LogLevels.Warn;
            //Ab3d.DirectX.DXDiagnostics.LogFileName = @"C:\temp\DXEngine.log";
            //Ab3d.DirectX.DXDiagnostics.IsWritingLogToOutput = true;


            // AfterFrameRendered event is triggered after each frame is rendered
            //MainDXViewportView.DXScene.AfterFrameRendered += delegate(object sender, EventArgs args) {  };


            // DXSceneDeviceCreated event is triggered after the DirectX device and DXScene objects were created (see help for more info).
            // This can be used to check the actually used GraphicsProfile and to set some specific graphics settings on DXScene.
            //MainDXViewportView.DXSceneDeviceCreated += delegate(object sender, EventArgs args)
            //{
            //    if (MainDXViewportView.UsedGraphicsProfile.DriverType != GraphicsProfile.DriverTypes.Wpf3D)
            //    {
            //        // Render polylines as simple diconnected lines with DirectX hardware acceleration (when using small line thickness the missing connection between the lines is not visible) - see help for more info
            //        MainDXViewportView.DXScene.RenderConnectedLinesAsDisconnected = true;
            //    }
            //};


            // DXSceneInitialized event is triggered after all the 3D objects have been initialized (see help for more info).
            // It can be used to get lower lever DXEngine's SceneNode objects that are created from WPF's objects.
            //MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs args)
            //{
            //    // Get the SceneNode that was created from the WPF's Box1Visual3D object
            //    var sceneNode = MainDXViewportView.GetSceneNodeForWpfObject(Box1Visual3D) as Ab3d.DirectX.Models.WpfModelVisual3DNode;
            //};



            // Sample specific code: add the sample title and button to copy xaml
            AddSampleTitle();

            this.Unloaded += (sender, args) => MainDXViewportView.Dispose();
        }
        public CustomFogShaderEffectSample()
        {
            InitializeComponent();

            _changedSceneNodes = new List <WpfGeometryModel3DNode>();

            MainDXViewportView.DXSceneDeviceCreated += delegate(object sender, EventArgs args)
            {
                var dxScene = MainDXViewportView.DXScene;

                if (dxScene == null) // Probably using WPF 3D rendering
                {
                    return;
                }

                // Create a new instance of FogEffect
                _fogEffect = new FogEffect();

                // Register effect with EffectsManager - this will also initialize the effect with calling OnInitializeResources method in the FogEffect class
                dxScene.DXDevice.EffectsManager.RegisterEffect(_fogEffect);

                // After the _logEffect has been initialized, we can set up the shaders.
                // First we load the compiled vertex and pixel shaders into byte arrays.
                // The compiled shaders are created with compiling the "FogShader.hlsl" file with executing the "CompileFogShader.bat" file (both in "Resources\Shaders\" folder).
                // To see how the hlsl shader file is created, see the "Ab3d.DirectX.ShaderFactory" project that has a step by step guide on how to create FogShader
                byte[] fogVertexShaderBytecode = System.IO.File.ReadAllBytes(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Shaders\\FogShader.vs"));
                byte[] fogPixelShaderBytecode  = System.IO.File.ReadAllBytes(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\Shaders\\FogShader.ps"));

                // When we have shader byte arrays we can send than to FogEffect
                _fogEffect.SetShaders(fogVertexShaderBytecode, fogPixelShaderBytecode);

                // Update fog distances and colors
                UpdateFogSettings();

                UpdateFogUsage();
            };

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                // Because _fogEffect was created here, we also need to dispose it here
                if (_fogEffect != null)
                {
                    _fogEffect.Dispose();
                    _fogEffect = null;
                }

                // We also need ot dispose the _defaultStandardEffect to reduce the reference count on it
                if (_defaultStandardEffect != null)
                {
                    _defaultStandardEffect.Dispose();
                    _defaultStandardEffect = null;
                }

                MainDXViewportView.Dispose();
            };
        }
コード例 #3
0
        public SphereVisual3DSample()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(SphereVisual3DSample_Loaded);

            // 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 += (sender, args) => MainDXViewportView.Dispose();
        }
コード例 #4
0
        public ContentVisual3DSample()
        {
            InitializeComponent();

            LoadFile(AppDomain.CurrentDomain.BaseDirectory + @"Resources\Models\ship_boat.obj");

            // 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 += (sender, args) => MainDXViewportView.Dispose();
        }
コード例 #5
0
        private void Dispose()
        {
            // Dispose all resources that were created here
            SharpDX.Utilities.Dispose(ref _constantBuffer);
            SharpDX.Utilities.Dispose(ref _vertices);
            SharpDX.Utilities.Dispose(ref _layout);
            SharpDX.Utilities.Dispose(ref _vertexShader);
            SharpDX.Utilities.Dispose(ref _pixelShader);

            MainDXViewportView.Dispose();
        }
コード例 #6
0
        public ColoredPointCloud()
        {
            InitializeComponent();

            _disposables = new DisposeList();

            // Wait until DXScene is initialized and then create the data
            MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs args)
            {
                Mouse.OverrideCursor = Cursors.Wait;

                try
                {
                    Vector3[] positions;
                    var       positionsBounds = new BoundingBox(new Vector3(-100, 0, -100), new Vector3(100, 20, 100));

                    GenerateSinusPointCloudData(xCount: 300, yCount: 300,
                                                bounds: positionsBounds,
                                                positions: out positions);


                    var linearGradientBrush = CreateDataGradientBrush();
                    var gradientColorsArray = CreateGradientColorsArray(linearGradientBrush);

                    // Setup offsets and factors so that each position will be converted
                    // into a value from 0 to 1 based on the y position.
                    // This value will be used to define the color from the gradientColorsArray.

                    float minValue = positionsBounds.Minimum.Y;
                    float maxValue = positionsBounds.Maximum.Y;

                    var      offsets        = new Vector3(0, -minValue, 0);
                    var      factors        = new Vector3(0, 1.0f / (maxValue - minValue), 0);
                    Color4[] positionColors = CreatePositionColorsArray(positions, offsets, factors, gradientColorsArray);



                    InitializePointCloud(positions, positionsBounds, positionColors, UseOptimizedPointMesh, DisableDepthRead, DisableDepthWrite);
                }
                finally
                {
                    Mouse.OverrideCursor = null;
                }
            };

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                _disposables.Dispose();
                MainDXViewportView.Dispose();
            };
        }
コード例 #7
0
        public NormalMappingSample()
        {
            InitializeComponent();

            _disposables = new DisposeList();

            MainDXViewportView.DXSceneDeviceCreated += OnDXSceneDeviceCreated;

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                _disposables.Dispose();
                MainDXViewportView.Dispose();
            };
        }
コード例 #8
0
        public PixelRenderingOptionsSample()
        {
            InitializeComponent();

            _disposables = new DisposeList();

            CreateScene();

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                _disposables.Dispose();
                MainDXViewportView.Dispose();
            };
        }
コード例 #9
0
        public ObjectSelectionWithSubMeshes()
        {
            InitializeComponent();

            _disposables = new DisposeList();
            CreateScene();

            SetupHitTesting();

            this.Unloaded += delegate(object sender, RoutedEventArgs e)
            {
                _disposables.Dispose();
                MainDXViewportView.Dispose();
            };
        }
コード例 #10
0
        public SampleSceneUserControl()
        {
            InitializeComponent();

            //MainViewportView.GraphicsProfiles = DXEngineSettings.Current.GraphicsProfiles;
            //MainViewportView.PresentationType = DXEngineSettings.Current.PresentationType;

            DXDiagnostics.IsCollectingStatistics = true;

            CreateScene();

            this.Loaded += (sender, args) => _startTime = DateTime.Now;

            this.Unloaded += (sender, args) => MainDXViewportView.Dispose();
        }
        public SharpHorizontalAndVerticalLines()
        {
            InitializeComponent();

            _twoDimensionalCamera = new TwoDimensionalCamera(MainDXViewportView,
                                                             ViewportBorder,
                                                             useScreenPixelUnits: true,
                                                             coordinateSystemType: TwoDimensionalCamera.CoordinateSystemTypes.CenterOfViewOrigin)
            {
                MoveCameraConditions       = MouseCameraController.MouseAndKeyboardConditions.RightMouseButtonPressed,
                QuickZoomConditions        = MouseCameraController.MouseAndKeyboardConditions.LeftMouseButtonPressed | MouseCameraController.MouseAndKeyboardConditions.RightMouseButtonPressed,
                IsMouseAndTouchZoomEnabled = true,
                ShowCameraLight            = ShowCameraLightType.Always
            };

            MouseCameraControllerInfo1.MouseCameraController = _twoDimensionalCamera.UsedMouseCameraController;


            // Use Loaded on TwoDimensionalCamera to delay creating the scene
            // until the TwoDimensionalCamera is loaded - then the view's size and dpi scale are known.
            _twoDimensionalCamera.Loaded += delegate(object sender, EventArgs args)
            {
                CreateTestScene();
            };


            MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs args)
            {
                // Do we need to show warning - it is shown when using super-sampling
                if (MainDXViewportView.DXScene.SupersamplingCount > 1)
                {
                    SupersamplingWarningTextBlock.Visibility = Visibility.Visible;
                }

                // NOTE:
                // To render all lines without anti-aliasing and without geometry shader,
                // set UseGeometryShaderFor3DLines and RenderAntialiased3DLines to false:
                //
                //MainDXViewportView.DXScene.UseGeometryShaderFor3DLines = false;
                //MainDXViewportView.DXScene.RenderAntialiased3DLines    = false;
            };


            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                MainDXViewportView.Dispose();
            };
        }
        public ModelMoverInsideObjectSample()
        {
            InitializeComponent();

            _normalMaterial   = new DiffuseMaterial(Brushes.Silver);
            _selectedMaterial = new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(150, 192, 192, 192))); // semi-transparent Silver

            _eventManager = new Ab3d.Utilities.EventManager3D(MainViewport);
            _eventManager.CustomEventsSourceElement = ViewportBorder;

            CreateRandomScene();

            // 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 += (sender, args) => MainDXViewportView.Dispose();
        }
コード例 #13
0
        // NOTES related to rendering many lights in Ab3d.DXEngine
        //
        // Ab3d.DXEngine can render ambient light and 16 other lights (Directional, Point and Spot lights) in one rendering pass
        // (maximum number of lights is defined in the following constant Ab3d.DirectX.Shaders.SuperShader.MaxLights).
        // When more lights are defined in the scene, the lights are rendered with multiple rendering passes.
        // For example this sample is rendered with 4 rendering passes (8 * 8 = 64 lights; 64 / 16 = 4 passes).
        // This means that the scene is first rendered with ambient light and first 16 lights.
        // Then all the scene objects are rendered again with the next 16 lights.
        // The pixel colors that are rendered this time are added to the pixels that were rendered in the previous pass (this is additive blending).
        // Then the next pass is rendered until all lights are used.
        //
        // This works well for most of the cases.
        // But additive blending also have some limitations:
        // 1) When multiple lights overlap the colors can become overburned (too white).
        //    This can happen because each pass just adds the colors to the previous color.
        //    For example if one object has Diffuse color set to (255, 150, 0) and is fully illuminated by two lights in two different rendering passes,
        //    the final color will be (255 + 255, 150 + 150, 0 + 0) = (255, 250, 0) which will be too bright (green = 255 instead of 150).
        //
        //    One way to prevent that is to use only 16 lights (remove the lights that are far away or have minimal effect on the scene).
        //    You can also use the FilterLightsFunction property on RenderObjectsRenderingStep (you can get it from DXScene.RenderingSteps collection) -
        //    the FilterLightsFunction can dynamically remove the lights that are not valid for the current scene (this is more efficient than adding and removing the lights from the scene).
        //
        //    Another way to prevented this is with manually arranging the lights so that the lights that overlay (shine on the same area) are rendered in the same
        //    rendering step (remember that 16 lights are rendered in one step). To do this you might need to add some dummy lights (PointLight with almost black color and radius 1).
        //
        //    It is also possible to increase the number of lights rendered in one rendering pass.
        //    To do this you will need to purchase the source code for the effects and shaders. Then please contact me and I will instruct you on how to
        //    change and compile the shader to accept more then 16 lights and render them in one rendering pass.
        //
        //
        // 2) Semi-transparent objects may not be rendered correctly.
        //    The problem is that multipass rendering required additive blending where pixel colors from rendering passes are added to the previous pixel color.
        //    But rendering transparent pixels require alpha blending where the final pixel color is determined by the alpha value of the pixel.
        //    Those two modes cannot be used at the same time so in some cases the transparent objects are not rendered correctly.
        //
        //
        // It is also possible to disable multi-pass rendering with setting the AllowMultipassRendering property to false.
        // The property is defined on RenderObjectsRenderingStep (you can get it from DXScene.RenderingSteps collection).

        public ManyLightsTest()
        {
            InitializeComponent();

            CreateLights();

            _startTime = DateTime.Now;
            CompositionTarget.Rendering += CompositionTargetOnRendering;

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

                MainDXViewportView.Dispose();
            };
        }
コード例 #14
0
        public PerformanceTest()
        {
            InitializeComponent();

            // To use RenderAsManyFramesAsPossible we need DirectXOverlay presentation type
            MainDXViewportView.PresentationType = DXView.PresentationTypes.DirectXOverlay;

            InfoTextBlock.Text = string.Format(InfoTextBlock.Text, HeadingIncreaseOnEachFrame);

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

                string testName = string.Format("PerformanceTest with '{0}' ({1})",
                                                System.IO.Path.GetFileName(StartupFileName),
                                                OptimizeReadModel ? "optimized" : "not optimized");

                _performanceAnalyzer = new PerformanceAnalyzer(MainDXViewportView, testName, initialCapacity: 10000);
                _performanceAnalyzer.StartCollectingStatistics();
            };


            this.Loaded += OnLoaded;


            //this.Focusable = true; // by default Page is not focusable and therefore does not receive keyDown event
            //this.PreviewKeyDown += OnPreviewKeyDown;


            // FPS will be displayed in Window Title - save the title so we can restore it later
            _savedWindowTitle = Application.Current.MainWindow.Title;

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                StopTest(showResults: false);

                MainDXViewportView.Dispose();

                if (_parentWindow != null)
                {
                    _parentWindow.PreviewKeyDown -= OnPreviewKeyDown;
                }
            };
        }
コード例 #15
0
        public ReflectionMapSample()
        {
            InitializeComponent();

            //Ab3d.DirectX.DXDiagnostics.CreateDebugDirectXDevice = true;

            MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs args)
            {
                if (MainDXViewportView.UsedGraphicsProfile.DriverType != GraphicsProfile.DriverTypes.Wpf3D)
                {
                    // We create the CubeMap from 6 bitmap images
                    string packUriPrefix = string.Format("pack://application:,,,/{0};component/Resources/SkyboxTextures/", this.GetType().Assembly.GetName().Name);

                    // Create DXCubeMap with specifying 6 bitmaps for all sides of the cube
                    _dxCubeMap = new DXCubeMap(packUriPrefix,
                                               "CloudyLightRaysRight512.png",
                                               "CloudyLightRaysLeft512.png",
                                               "CloudyLightRaysUp512.png",
                                               "CloudyLightRaysDown512.png",
                                               "CloudyLightRaysFront512.png",
                                               "CloudyLightRaysBack512.png");

                    // To show the environment map correctly for our bitmaps we need to flip bottom bitmap horizontally and vertically
                    _dxCubeMap.FlipBitmaps(flipRightBitmapType: DXCubeMap.FlipBitmapType.None,
                                           flipLeftBitmapType: DXCubeMap.FlipBitmapType.None,
                                           flipUpBitmapType: DXCubeMap.FlipBitmapType.None,
                                           flipDownBitmapType: DXCubeMap.FlipBitmapType.FlipXY,
                                           flipFrontBitmapType: DXCubeMap.FlipBitmapType.None,
                                           flipBackBitmapType: DXCubeMap.FlipBitmapType.None);

                    SetupCubeMapMaterial();
                }
            };

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                // We need to dispose all the DirectX resources created here:
                if (_dxCubeMap != null)
                {
                    _dxCubeMap.Dispose();
                    _dxCubeMap = null;
                }

                // Then dispose the MainDXViewportView
                MainDXViewportView.Dispose();
            };
        }
コード例 #16
0
        public OptimizedPointCloud()
        {
            InitializeComponent();

            PixelSizeComboBox.ItemsSource   = new float[] { 0.1f, 0.5f, 1, 2, 4, 8 };
            PixelSizeComboBox.SelectedIndex = 3;

            SceneTypeComboBox.ItemsSource = new string[]
            {
                "100,000 pixels (100 x 1,000)",
                "1 million pixels (100 x 10,000)",
                "10 million pixels (100 x 100,000)",
                "25 million pixels (1000 x 25,000)",
                "100 million pixels (1000 x 100,000)",
                "150 million pixels (1000 x 150,000)"
                // Bigger values would exceed max .Net array size in CreatePositionsArray method
            };
            SceneTypeComboBox.SelectedIndex = 1;

            _modelDisposables = new DisposeList();


            DXDiagnostics.IsCollectingStatistics = true; // Collect rendering statistics

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

            MainDXViewportView.SceneRendered += delegate(object sender, EventArgs args)
            {
                UpdateStatistics();
            };

            // Setup keyboard support
            this.Focusable       = true;             // by default Page is not focusable and therefore does not receive keyDown event
            this.PreviewKeyDown += OnPreviewKeyDown; // Use PreviewKeyDown to get arrow keys also (KeyDown event does not get them)
            this.Focus();

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                _modelDisposables.Dispose();
                MainDXViewportView.Dispose();
            };
        }
コード例 #17
0
        private void Dispose()
        {
            DisposePointDataObjects();

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

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

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

            // You may also try to use HighSpeedNormalQualityHardwareRendering graphics profile (with uncommenting the following line)
            // This will use a per-vertex lighting calculations (lighting colors are calculated for each vertex and then interpolated to the pixels; in per-pixel rendering the calculations are done for each pixel)
            // and still preserve the 4-times antialiasing and anisotropic texture sampling.
            // This might give improved performance especially on slower GPUs.
            // Even faster rendering would be with using LowQualityHardwareRendering.
            //
            // MainDXViewportView.GraphicsProfiles = new GraphicsProfile[] { GraphicsProfile.HighSpeedNormalQualityHardwareRendering };

            CreateModelGroupInstances();

            // 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 += (sender, args) => MainDXViewportView.Dispose();
        }
コード例 #19
0
        public DeviceRemovedHandlerSample()
        {
            InitializeComponent();


            List <SphereInfo> usedSphereData;

            // If we have stored data, then use then
            if (_savedSphereData != null)
            {
                usedSphereData = _savedSphereData;

                Camera1.Heading        = _savedCameraHeading;
                Camera1.Attitude       = _savedCameraAttitude;
                Camera1.Distance       = _savedCameraDistance;
                Camera1.TargetPosition = _savedCameraTargetPosition;

                _savedSphereData = null;

                SampleReloadedIntoTextBlock.Visibility = Visibility.Visible;
            }
            else
            {
                // ... else generate new data
                usedSphereData = CreateRandomSphereData(20);
            }

            ShowSpheres(usedSphereData);


            // To subscribe to DeviceRemoved we need to wait until DXScene is created
            MainDXViewportView.DXSceneDeviceCreated += delegate(object sender, EventArgs args)
            {
                if (MainDXViewportView.DXScene != null)
                {
                    MainDXViewportView.DXScene.DeviceRemoved += DXSceneOnDeviceRemoved;
                }
            };

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                MainDXViewportView.Dispose();
            };
        }
コード例 #20
0
        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();
            };
        }
コード例 #21
0
        public Lines3DSample()
        {
            InitializeComponent();

            ArrowLengthInfoImage.ToolTip =
                @"Specifies the maximum arrow length set as fraction of the line length.
For example: 0.2 means that the maximum arrow length will be 1 / 5 (=0.2) of the line length.
If the line is short so that the arrow length exceeds the amount defined by MaxLineArrowLength,
the arrow is shortened (the arrow angle is increased).";


            SetUpMultiPolyLineVisual3D();

            MainDXViewportView.GraphicsProfiles = DirectX.Client.Settings.DXEngineSettings.Current.GraphicsProfiles;

            // 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 += (sender, args) => MainDXViewportView.Dispose();
        }
コード例 #22
0
        public SubMeshesSample()
        {
            InitializeComponent();

            _disposables = new DisposeList();

            CreateScene();

            StartAnimation();


            this.Unloaded += delegate(object sender, RoutedEventArgs e)
            {
                CompositionRenderingHelper.Instance.Unsubscribe(this);

                _disposables.Dispose();

                MainDXViewportView.Dispose();
            };
        }
コード例 #23
0
        public OptimizedMeshMorphing()
        {
            InitializeComponent();

            _meshMorphTimes      = new List <double>();
            _meshUpdateTimes     = new List <double>();
            _dxEngineUpdateTimes = new List <double>();

            DXDiagnostics.IsCollectingStatistics = true;

            CreateScene();
            CreateMorphedMesh();

            MainDXViewportView.SceneRendered += delegate
            {
                if (_dxEngineUpdateTimes == null)
                {
                    _dxEngineUpdateTimes = new List <double>();
                }

                if (MainDXViewportView.DXScene != null && MainDXViewportView.DXScene.Statistics != null)
                {
                    _dxEngineUpdateTimes.Add(MainDXViewportView.DXScene.Statistics.UpdateTimeMs);
                }
            };

            CompositionTarget.Rendering += CompositionTargetOnRendering;

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

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

                MainDXViewportView.Dispose();
            };
        }
コード例 #24
0
        public TwoDimensionalCameraSample()
        {
            InitializeComponent();

            // NOTE: TwoDimensionalCamera class is available with full source in this samples project in the Common folder.

            // Create an instance of TwoDimensionalCamera.
            // TwoDimensionalCamera will internally create a TargetPositionCamera and MouseCameraController (when mouseEventsSourceElement is not null).
            // They will be used to show the 2D scene.
            _twoDimensionalCamera = new TwoDimensionalCamera(MainDXViewportView,
                                                             mouseEventsSourceElement: ViewportBorder,   // if mouseEventsSourceElement is null, then MouseCameraController will not be created by TwoDimensionalCamera
                                                             useScreenPixelUnits: false,                 // when false, then the size in device independent units is used (as size of DXViewportView); when true size in screen pixels is used (see SharpHorizontalAndVerticalLines sample)
                                                             coordinateSystemType: TwoDimensionalCamera.CoordinateSystemTypes.CenterOfViewOrigin)
            {
                MoveCameraConditions       = MouseCameraController.MouseAndKeyboardConditions.RightMouseButtonPressed,
                QuickZoomConditions        = MouseCameraController.MouseAndKeyboardConditions.LeftMouseButtonPressed | MouseCameraController.MouseAndKeyboardConditions.RightMouseButtonPressed,
                IsMouseAndTouchZoomEnabled = true,
                ShowCameraLight            = ShowCameraLightType.Always
            };

            _twoDimensionalCamera.CameraChanged += delegate(object sender, EventArgs args)
            {
                UpdateSceneInfo();
            };


            // You can access the create TargetPositionCamera with UsedCamera property
            // and MouseCameraController with UsedMouseCameraController property.
            CameraAxisPanel1.TargetCamera = _twoDimensionalCamera.UsedCamera;
            MouseCameraControllerInfo1.MouseCameraController = _twoDimensionalCamera.UsedMouseCameraController;



            CreateShapesSample();
            //LoadSampleLinesData(lineThickness: 0.8, new Rect(-400, -300, 800, 600));

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                MainDXViewportView.Dispose();
            };
        }
コード例 #25
0
        public HitTestingSample()
        {
            InitializeComponent();

            _disposables = new DisposeList();

            _hitLinesModelVisual3D = new ModelVisual3D();
            MainViewport3D.Children.Add(_hitLinesModelVisual3D);


            CreateTestModels();

            MainDXViewportView.SceneRendered += MainDXViewportViewOnSceneRendered;

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                _disposables.Dispose();

                MainDXViewportView.Dispose();
            };
        }
コード例 #26
0
        public AdvancedInstanceRendering()
        {
            InitializeComponent();

            _disposables = new DisposeList();

            // Wait until DXScene and DirectX device are initialized.
            // Then we can create the instance buffers in the InstancedMeshGeometry3DNode object.
            MainDXViewportView.DXSceneDeviceCreated += MainDXViewportViewOnDXSceneDeviceCreated;

            // Start animating...
            CompositionTarget.Rendering += CompositionTargetOnRendering;

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

                _disposables.Dispose();
                MainDXViewportView.Dispose();
            };
        }
コード例 #27
0
        public LinesSelector()
        {
            InitializeComponent();
            WColor.SetColor(new Color4(0, 0, 1, 1),
                            new Color4(1, 0, 0, 1), new Color4(1, 1, 0, 1));

            _lineSelectorData = new List <LineSelectorData>();

            for (int i = 0; i < 10; i++)
            {
                CreateColoredPolyLine(20000, i);
            }

            _isCameraChanged       = true; // When true, the CalculateScreenSpacePositions method is called before calculating line distances
            Camera1.CameraChanged += delegate(object sender, CameraChangedRoutedEventArgs e)
            {
                _isCameraChanged = true;
                UpdateClosestLine();
            };

            this.MouseMove += delegate(object sender, MouseEventArgs e)
            {
                _lastMousePosition = e.GetPosition(MainBorder);
                UpdateClosestLine();
            };

            // Cleanup
            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                //if (lineMaterial != null)
                //{
                //    lineMaterial.Dispose();
                //    lineMaterial = null;
                //}

                MainDXViewportView.Dispose();
            };

            startStatusBarTimer();
        }
コード例 #28
0
        public LandscapeGeneratorSample()
        {
            InitializeComponent();


            // Setup RadioBoxes and Comboboxes
            FillPossibleLandscapeSizes();

            // Create linear gradient that will be used for Legent and for coloring vertexes
            var linearGradientBrush = CreateDataGradientBrush();

            _gradientColor4Array = CreateGradientColorsArray(linearGradientBrush);

            AddLegendControl(linearGradientBrush);


            // Adjust the CameraAxis control to show a coordinate system with Z up (more standard when showing height map).
            // Note: WPF uses right handed coordinate system with Y up.
            CameraAxisPanel1.CustomizeAxes(new Vector3D(1, 0, 0), "X", Colors.Red,
                                           new Vector3D(0, 1, 0), "Z", Colors.Green,
                                           new Vector3D(0, 0, -1), "Y", Colors.Blue);


            Camera1.StartRotation(10, 0);

            this.Loaded += delegate(object sender, RoutedEventArgs args)
            {
                GoToNextRandomSeed(); // Set new random seed - after seed text will be changed, the CreateLandscape will be called
            };

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                if (_vertexColorMaterial != null)
                {
                    _vertexColorMaterial.Dispose();
                }

                MainDXViewportView.Dispose();
            };
        }
コード例 #29
0
        public VertexColorRenderingSample()
        {
            InitializeComponent();

            AddTestModel();

            Camera1.StartRotation(45, 0);


            // Cleanup
            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                // We need to dispose all DXEngine objects that are created here - in this case _vertexColorMaterial
                if (_vertexColorMaterial != null)
                {
                    _vertexColorMaterial.Dispose();
                    _vertexColorMaterial = null;
                }

                MainDXViewportView.Dispose();
            };
        }
コード例 #30
0
        public OctTreeSample()
        {
            InitializeComponent();

            _octTreeLinesModelVisual3D = new ModelVisual3D();
            MainViewport3D.Children.Add(_octTreeLinesModelVisual3D);

            _hitLinesModelVisual3D = new ModelVisual3D();
            MainViewport3D.Children.Add(_hitLinesModelVisual3D);

            CreateScene();

            this.Unloaded += delegate(object sender, RoutedEventArgs args)
            {
                if (_dxMesh != null)
                {
                    _dxMesh.Dispose();
                    _dxMesh = null;
                }

                MainDXViewportView.Dispose();
            };
        }