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

            var rnd = new Random();

            _randomIndexes = Enumerable.Range(0, 10).OrderBy(n => rnd.Next(100)).ToArray(); // randomize an array of 10 integers

            _wpfTestScene = new TestScene(WpfViewport3D, isInDXEngine: false);
            _wpfTestScene.CreatesTestScene(_randomIndexes);

            _dxTestScene = new TestScene(DXViewport3D, isInDXEngine: true);
            _dxTestScene.CreatesTestScene(_randomIndexes);

            var alphaClipThreshold = (AlphaClipCheckBox.IsChecked ?? false) ? UsedAlphaClipThreshold : 0f;

            _dxTestScene.SetDXEngineSettings(UseSolidColorEffectCheckBox.IsChecked ?? false, alphaClipThreshold);


            CopyWpfCamera(); // Copy settings from WpfCamera to DXCamera

            WpfCamera.StartRotation(20, 0);

            this.Unloaded += (sender, args) => MainDXViewportView.Dispose();
        }
コード例 #2
0
        private void OnSettingsChanged(object sender, RoutedEventArgs e)
        {
            if (!this.IsLoaded)
            {
                return;
            }

            if (_optimizedPointMeshes != null)
            {
                foreach (var optimizedPointMesh in _optimizedPointMeshes)
                {
                    optimizedPointMesh.OptimizePositions         = OptimizePositionsCheckBox.IsChecked ?? false;
                    optimizedPointMesh.RenderOnlyVisibleSegments = RenderOnlyVisibleSegmentsCheckBox.IsChecked ?? false;
                }
            }

            if (_shadedPointCloudEffect != null)
            {
                if (SpecularLightingCheckBox.IsChecked ?? false)
                {
                    _shadedPointCloudEffect.SpecularPower = 64;
                }
                else
                {
                    _shadedPointCloudEffect.SpecularPower = 0;
                }
            }

            MainDXViewportView.Refresh(); // Render the scene again
        }
コード例 #3
0
        public PixelRenderingSample()
        {
            InitializeComponent();

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

            _disposables = new DisposeList();

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

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

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

                MainDXViewportView.Dispose();
            };
        }
コード例 #4
0
        private SceneNode GetSceneNodeForWpfObject(object wpfObject)
        {
            if (wpfObject == null)
            {
                return(null);
            }

            SceneNode sceneNode = null;

            // Use _sceneNodesDictionary if possible
            if (_sceneNodesDictionary != null)
            {
                _sceneNodesDictionary.TryGetValue(wpfObject, out sceneNode);
            }


            // If SceneNode is not found, we an use the GetSceneNodeForWpfObject method.
            // Note that this method is very slow because it goes through each SceneNode in the scene
            // and for each SceneNode calls IsMyWpfObject method.
            if (sceneNode == null)
            {
                sceneNode = MainDXViewportView.GetSceneNodeForWpfObject(wpfObject);
            }

            return(sceneNode);
        }
コード例 #5
0
        public SolidColorInstanceRendering()
        {
            InitializeComponent();

            MainDXViewportView.DXSceneDeviceCreated += delegate(object sender, EventArgs args)
            {
                _currentRenderingType = GetCurrentRenderingType();

                CreateInstances();

                ChangeRenderingType();
            };

            // 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) =>
            {
                if (_solidColorEffectWithOutline != null)
                {
                    _solidColorEffectWithOutline.Dispose();
                    _solidColorEffectWithOutline = null;
                }

                MainDXViewportView.Dispose();
            };
        }
コード例 #6
0
        private void CreateObjectIdBitmapButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (_objectIdRenderingStep == null)
            {
                return;
            }

            _objectIdRenderingStep.IsEnabled = true;
            MainDXViewportView.DXScene.DefaultRenderObjectsRenderingStep.IsEnabled = false;

            try
            {
                var renderToBitmap = MainDXViewportView.RenderToBitmap(MainDXViewportView.DXScene.Width, MainDXViewportView.DXScene.Height, preferedMultisampling: 0);

                string fileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "ObjectIds.png");

                SaveBitmap(renderToBitmap, fileName);

                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(fileName)
                {
                    UseShellExecute = true
                });                                                                                                             // For .Net CORE projects we need to set UseShellExecute to true
            }
            finally
            {
                _objectIdRenderingStep.IsEnabled = false;
                MainDXViewportView.DXScene.DefaultRenderObjectsRenderingStep.IsEnabled = true;
            }
        }
コード例 #7
0
        public BackgroundAndOverlayRendering()
        {
            InitializeComponent();

            _disposables = new DisposeList();

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

                PrepareAlwaysOnTopRendering();
                AddCustomRenderedObjects();

                AddCustomRenderedLines();
            };


            // 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 (_disposables != null)
                {
                    _disposables.Dispose();
                    _disposables = null;
                }

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

            // Setting GraphicsProfiles tells DXEngine which graphics device it should use (and what devices are fallback devices if the first device cannot be initialized)
            // ApplicationContext.Current.GraphicsProfiles is changed by changing the "Graphics settings" with clicking on its button in upper left part of application.
            MainDXViewportView.GraphicsProfiles = DirectX.Client.Settings.DXEngineSettings.Current.GraphicsProfiles;

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }


            // Create instance MeshGeometry3D
            _instanceMeshGeometry3D = new Ab3d.Meshes.SphereMesh3D(centerPosition: new Point3D(0, 0, 0), radius: 5, segments: 20, generateTextureCoordinates: false).Geometry;

            // Prepare data for 8000 instances (each InstanceData represents one instance's Color and its World matrix that specifies its position, scale and rotation)
            _instancedData = CreateInstancesData(new Point3D(0, 200, 0), new Size3D(400, 400, 400), 20, 20, 20);


            MainDXViewportView.SceneRendered += MainDXViewportViewOnSceneRendered;


            // 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();
        }
コード例 #9
0
        private void OnDXSceneViewInitialized()
        {
            if (MainDXViewportView.UsedGraphicsProfile.DriverType == GraphicsProfile.DriverTypes.Wpf3D)
            {
                HouseWithThreesWireframeVisual.RemoveDuplicateLines = true; // This is recommended setting for WPF because it reduces the number of lines
                PersonWireframeVisual.RemoveDuplicateLines          = true;
                return;
            }

            HouseWithThreesWireframeVisual.RemoveDuplicateLines = false; // Rendering lines in DXEngine is very cheap so we can skip the process of finding and removing duplicates
            PersonWireframeVisual.RemoveDuplicateLines          = false;

            // Get the SceneNodes (WpfWireframeVisual3DNode) used by DXScene
            // This way we can access some properties that are specific to DirectX and are not used in WPF WireframeVisual3D (like depth bias properties)
            _wpfHouseWithThreesWireframeVisualNode = MainDXViewportView.GetSceneNodeForWpfObject(HouseWithThreesWireframeVisual) as WpfWireframeVisual3DNode;

            if (_wpfHouseWithThreesWireframeVisualNode != null)
            {
                _wpfHouseWithThreesWireframeVisualNode.Name = "HouseWithThreesWireframeVisualNode";
            }


            _wpfPersonWireframeVisualNode = MainDXViewportView.GetSceneNodeForWpfObject(PersonWireframeVisual) as WpfWireframeVisual3DNode;

            if (_wpfPersonWireframeVisualNode != null)
            {
                _wpfPersonWireframeVisualNode.Name = "PersonWireframeVisualNode";
            }

            UpdateDepthBias();
        }
コード例 #10
0
        public ObjectIdRendering()
        {
            InitializeComponent();

            var boxMesh      = new Ab3d.Meshes.BoxMesh3D(new Point3D(0, 0, 0), new Size3D(1, 1, 1), 1, 1, 1).Geometry;
            int modelsXCount = 20;
            int modelsYCount = 1;
            int modelsZCount = 20;

            var model3DGroup = CreateModel3DGroup(boxMesh, new Point3D(0, 5, 0), new Size3D(500, modelsYCount * 10, 500), 10, modelsXCount, modelsYCount, modelsZCount);

            MainViewport.Children.Add(model3DGroup.CreateModelVisual3D());


            _disposables = new DisposeList();

            MainDXViewportView.DXSceneDeviceCreated += MainDxViewportViewOnDxSceneDeviceCreated;

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

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

            _selectedMaterial   = new DiffuseMaterial(Brushes.Red);
            _unSelectedMaterial = new DiffuseMaterial(Brushes.Blue);

            LowerBoxVisual3D.SetName("LowerBoxVisual3D");
            PassageBoxVisual3D.SetName("PassageBoxVisual3D");
            UpperBoxVisual3D.SetName("UpperBoxVisual3D");
            MovableVisualParent.SetName("MovableVisualParent");
            MovableBoxVisual3D.SetName("MovableBoxVisual3D");
            ArrowLineVisual3D.SetName("ArrowLineVisual3D");
            Cylinder1.SetName("Cylinder1");
            Cylinder2.SetName("Cylinder2");
            Cylinder3.SetName("Cylinder3");
            TransparentPlaneVisual3D.SetName("TransparentPlaneVisual3D");


            this.Loaded += new RoutedEventHandler(DXEventManager3DWrapperSample_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();
        }
コード例 #12
0
        public AllVisualsSample()
        {
            InitializeComponent();

            // 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();



            //// Code to add test button:
            //var testButton = new Button()
            //{
            //    Content = "TEST",
            //    HorizontalAlignment = HorizontalAlignment.Right,
            //    VerticalAlignment = VerticalAlignment.Bottom,
            //};

            //testButton.Click += delegate (object sender, RoutedEventArgs args)
            //{
            //    // Place to put test code
            //};

            //MainGrid.Children.Add(testButton);
        }
コード例 #13
0
        public InstancedMeshGeometry3DTest()
        {
            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.LowQualityHardwareRendering };

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }


            CreateInstances();


            // 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();
        }
コード例 #14
0
        public InstancedTextNodeSample()
        {
            InitializeComponent();


            AlphaClipThresholdInfoControl.InfoText =
                @"AlphaClipThreshold is used to correctly render the textures with rendered characters and transparent background. It specifies at which alpha value the pixels will be clipped (skipped from rendering and their depth will not be written to the depth buffer).

When set to 0, then alpha-clipping is disabled and in this case the characters may not be rendered correctly.
Default value is 0.15.

See 'Improved visuals / Alpha clipping' sample and comments in its code for more info.";

            CreateSimpleDemoScene();

            var coloredAxisVisual3D = new ColoredAxisVisual3D();

            MainViewport.Children.Add(coloredAxisVisual3D);

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

                MainDXViewportView.Dispose();
            };
        }
コード例 #15
0
        private void LineTypesRadioButtonChanged(object sender, RoutedEventArgs e)
        {
            if (!this.IsLoaded)
            {
                return;
            }

            // First recreate all 3D objects to reset their attributes and settings
            CreateTest3DObjects();
            MainDXViewportView.Update();

            if (StandardLinesRadioButton.IsChecked ?? false)
            {
                // Nothing to do - just show standard lines
            }
            else if (OnlyHiddenLinesRadioButton.IsChecked ?? false)
            {
                ShowOnlyHiddenLines();
            }
            else if (StandardAndHiddenLinesRadioButton.IsChecked ?? false)
            {
                ShowVisibleAndHiddenLines();
            }
            else if (AlwaysVisibleLines1RadioButton.IsChecked ?? false)
            {
                ShowAlwaysVisibleLinesWithDXAttribute();
            }
            else if (AlwaysVisibleLines2RadioButton.IsChecked ?? false)
            {
                ShowAlwaysVisibleLinesAdvanced();
            }
        }
コード例 #16
0
        public AllVisualsSample()
        {
            InitializeComponent();

            // 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();
        }
 private void ShadowTransparencySlider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
 {
     if (_planarShadowRenderingProvider != null)
     {
         _planarShadowRenderingProvider.ShadowTransparency = (float)ShadowTransparencySlider.Value / 100.0f;
         MainDXViewportView.Refresh();
     }
 }
 private void OnClipToBoundsCheckBoxChanged(object sender, RoutedEventArgs e)
 {
     if (_planarShadowRenderingProvider != null)
     {
         _planarShadowRenderingProvider.CutShadowToPlaneBounds = (ClipToBoundsCheckBox.IsChecked ?? false);
         MainDXViewportView.Refresh();
     }
 }
        public MouseControllerForPointCloud()
        {
            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);


                    // Set DXScene and OptimizedPointMesh to PointCloudMouseCameraController1
                    PointCloudMouseCameraController1.DXScene            = MainDXViewportView.DXScene;
                    PointCloudMouseCameraController1.OptimizedPointMesh = _optimizedPointMesh;

                    PointCloudMouseCameraController1.MaxDistanceToAnyPosition = 1.0f;
                }
                finally
                {
                    Mouse.OverrideCursor = null;
                }
            };

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


            _xSize = 2000;
            _ySize = 2000;

            _arrowsLength = 30;

            _sphereStartPosition = new Vector3(0, 200, 0);

            Camera1.TargetPosition = new Point3D(0, _sphereStartPosition.Y * 0.3, 0); // target y = 1/3 of the sphere start height


            // Min and max distance will be used to get the color from the current arrow distance
            _minDistance = _sphereStartPosition.Y;

            double dx = Math.Abs(_sphereStartPosition.X) + (_xSize / 2);
            double dz = Math.Abs(_sphereStartPosition.Z) + (_ySize / 2);

            _maxDistance = Math.Sqrt(dx * dx + _sphereStartPosition.Y * _sphereStartPosition.Y + dz * dz);


            _gradientColors = CreateDistanceColors();


            DXDiagnostics.IsCollectingStatistics = true; // Collect rendering time and other statistics

            MainDXViewportView.SceneRendered += delegate(object sender, EventArgs args)
            {
                _totalRenderingTime = MainDXViewportView.DXScene.Statistics.TotalRenderTimeMs;
                _renderingTimeSamplesCount++;
            };


            this.Loaded += delegate(object o, RoutedEventArgs args)
            {
                CreateArrows();

                _startTime = DateTime.Now;

                // Use CompositionRenderingHelper to subscribe to CompositionTarget.Rendering event
                // This is much safer because in case we forget to unsubscribe from Rendering, the CompositionRenderingHelper will unsubscribe us automatically
                // This allows to collect this class will Grabage collector and prevents infinite calling of Rendering handler.
                // After subscribing the ICompositionRenderingSubscriber.OnRendering method will be called on each CompositionTarget.Rendering event
                CompositionRenderingHelper.Instance.Subscribe(this);
            };

            // 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
            {
                CompositionRenderingHelper.Instance.Unsubscribe(this);
                MainDXViewportView.Dispose();
            };
        }
コード例 #22
0
        private void LoadObjFileBackgroundButton_OnClick(object sender, RoutedEventArgs e)
        {
            RootModelVisual3D.Children.Clear();
            GC.Collect();

            if (MainDXViewportView.DXScene == null)
            {
                MessageBox.Show("This sample cannot run with WPF 3D rendering");
                return;
            }

            var dxScene = MainDXViewportView.DXScene;

            Task.Factory.StartNew(() =>
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                // Load model from obj file
                var readerObj   = new Ab3d.ReaderObj();
                var readModel3D = readerObj.ReadModel3D(_objFileName);

                // Scale and position the read model so that its bottom center is at (0,-100,0) and it can fit into 200 x 200 x 200 Rect3D
                Ab3d.Utilities.ModelUtils.PositionAndScaleModel3D(readModel3D, new Point3D(0, -100, 0), PositionTypes.Bottom, new Size3D(200, 200, 200));
                readModel3D.Freeze();

                var createdSceneNode = Ab3d.DirectX.Models.SceneNodeFactory.CreateFromModel3D(readModel3D, null, dxScene);

                // Call InitializeResources to create all required DirectX resources from the background thread
                createdSceneNode.InitializeResources(dxScene);

                stopwatch.Stop();
                _backgroundThreadTime = (float)stopwatch.Elapsed.TotalMilliseconds;

                // Now go to UI thread and create the Visual3D objects and update the scene there.
                // There are two reasons to do that:
                // 1) We cannot create objects that are derived from Visual3D on the background thread (we also cannot freeze them with calling Freeze method - this is possible on MeshGeometry, Model3D and Material objects).
                // 2) We should not update the scene from the backgrond thread because we do not know when the UI thread is reading the scene.
                Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
                {
                    StartStopwatch();

                    // Create SceneNodeVisual3D that will show the created SceneNode
                    var sceneNodeVisual3D = new SceneNodeVisual3D(createdSceneNode);
                    RootModelVisual3D.Children.Add(sceneNodeVisual3D);

                    MainDXViewportView.Refresh(); // Manually render next frame

                    StopStopwatch(UIThreadTime2TextBlock);
                    BackgroundThreadTimeTextBlock.Text = string.Format("Background Thread time: {0:#,##0.00}ms", _backgroundThreadTime);
                }));
            });


            StartStopwatch();
            StopStopwatch(UIThreadTime2TextBlock);
        }
コード例 #23
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();
        }
コード例 #24
0
        public ModelRotatorSample()
        {
            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;

            // IMPORTANT !!!
            // When ModelMoverVisual3D is used with EventManager3D
            // we need to call SubscribeWithEventManager3D to use EventManager3D for mouse events processing
            SelectedModelRotator.SubscribeWithEventManager3D(_eventManager);

            // Setup events on ModelRotatorVisual3D
            SelectedModelRotator.ModelRotateStarted += delegate(object sender, ModelRotatedEventArgs args)
            {
                if (_selectedBoxModel == null)
                {
                    return;
                }

                // When a new rotation is started, we create a new AxisAngleRotation3D with the used Axis or rotation
                // During the rotation we will adjust the angle (inside ModelRotated event handler)
                _axisAngleRotation3D = new AxisAngleRotation3D(args.RotationAxis, 0);

                // Insert the new rotate transform before the last translate transform that positions the box
                var rotateTransform3D = new RotateTransform3D(_axisAngleRotation3D);

                AddRotateTransform(_selectedBoxModel, rotateTransform3D);
            };

            SelectedModelRotator.ModelRotated += delegate(object sender, ModelRotatedEventArgs args)
            {
                if (_selectedBoxModel == null)
                {
                    return;
                }

                _axisAngleRotation3D.Angle = args.RotationAngle;
            };

            SelectedModelRotator.ModelRotateEnded += delegate(object sender, ModelRotatedEventArgs args)
            {
                // Nothing to do here in this sample
                // The event handler is here only for description purposes
            };


            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();
        }
        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();
            };
        }
コード例 #26
0
        private void OnRenderingTypeRadioButtonCheckedChanged(object sender, RoutedEventArgs e)
        {
            if (!this.IsLoaded)
            {
                return;
            }

            ChangeRenderingType();
            MainDXViewportView.Refresh();
        }
コード例 #27
0
        private void OnIsSolidColorMaterialCheckBoxCheckedChanged(object sender, RoutedEventArgs e)
        {
            if (!this.IsLoaded)
            {
                return;
            }

            _instancedMeshGeometryVisual3D.IsSolidColorMaterial = IsSolidColorMaterialCheckBox.IsChecked ?? false;
            MainDXViewportView.Refresh();
        }
コード例 #28
0
        private void OnSolidModelColorComboBoxChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!this.IsLoaded)
            {
                return;
            }

            ChangeRenderingType();
            MainDXViewportView.Refresh();
        }
コード例 #29
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();
        }
コード例 #30
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();
        }