示例#1
0
        private void Dispose()
        {
            DisposePointDataObjects();

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

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

            MainDXViewportView.Dispose();
        }
示例#2
0
        public ShadedPointCloudSample()
        {
            InitializeComponent();

            // First create an instance of AssemblyShaderBytecodeProvider.
            // This will allow using EffectsManager to cache and get the shaders from the assembly's EmbeddedResources.
            // See ShadedPointCloudEffect.EnsureShaders method for more info.
            var resourceAssembly = this.GetType().Assembly;
            var assemblyShaderBytecodeProvider = new AssemblyShaderBytecodeProvider(resourceAssembly, resourceAssembly.GetName().Name + ".Resources.Shaders.");

            EffectsManager.RegisterShaderResourceStatic(assemblyShaderBytecodeProvider);

            MainDXViewportView.PresentationType = DXView.PresentationTypes.DirectXImage;

            //MainDXViewportView.GraphicsProfiles = new GraphicsProfile[] { GraphicsProfile.LowQualityHardwareRendering };

            //Ab3d.DirectX.Controls.D3DHost.RenderAsManyFramesAsPossible = true;



            // Subscribe to DXSceneDeviceCreated event - there the DirectX 11 device was already created
            MainDXViewportView.DXSceneInitialized += delegate(object sender, EventArgs args)
            {
                var dxScene = MainDXViewportView.DXScene;

                if (dxScene == null) // When null, then we are probably using WPF 3D rendering
                {
                    return;
                }

                // Create a new instance of ShadedPointCloudEffect
                _shadedPointCloudEffect = new ShadedPointCloudEffect();

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


                // Set global effect settings
                _shadedPointCloudEffect.DiffuseColor  = Colors.Orange.ToColor4();
                _shadedPointCloudEffect.SpecularColor = Color3.White;
                _shadedPointCloudEffect.SpecularPower = 64;
                _shadedPointCloudEffect.PointSize     = (float)PointSizeComboBox.SelectedItem;


                // Create new material from the effect
                _effectMaterial = new EffectMaterial(_shadedPointCloudEffect);
                //_disposables.Add(_effectMaterial); // is not added to disposables because it is disposed separately and can be disposed after the number of positions is changed in the DropDown


                // Create the demo data and show them
                RecreatePointCloud();
            };



            ModelsCountComboBox.ItemsSource   = new int[] { 1, 2, 3, 4, 5, 10, 20, 50, 60, 100, 200, 500 };
            ModelsCountComboBox.SelectedIndex = 2;

            PointsCountComboBox.ItemsSource   = new int[] { 100000, 500000, 1000000, 2000000, 5000000, 10000000, 20000000, 30000000, 40000000, 50000000, 60000000 };
            PointsCountComboBox.SelectedIndex = 2;

            PointSizeComboBox.ItemsSource   = new float[] { 0.001f, 0.005f, 0.01f, 0.02f, 0.05f, 0.1f, 0.2f, 0.5f, 1.0f, 2.0f, 5.0f, 10.0f };
            PointSizeComboBox.SelectedIndex = 8;


            if (SampleDataFile != null)
            {
                PointsCountTextBlock.Visibility = Visibility.Collapsed;
                PointsCountComboBox.Visibility  = Visibility.Collapsed;
            }


            Camera1.StartRotation(45, 0);
            StartStopCameraButton.Content = "Stop camera rotation";

            Camera1.CameraChanged += delegate(object sender, CameraChangedRoutedEventArgs args)
            {
                if (MainDXViewportView.DXScene == null)
                {
                    return;
                }

                MainDXViewportView.DXScene.Camera.Update();
                double pixelSize = OptimizedPointMesh <PositionNormal> .GetPixel3DSize(MainDXViewportView.DXScene.Camera, MainDXViewportView.DXScene.Width, new Vector3(0, 0, 0));

                if (Camera1.CameraType == BaseCamera.CameraTypes.OrthographicCamera)
                {
                    InfoTextBlock.Text = $"CameraWidth:  {Camera1.CameraWidth:F0}; Pixel size: {pixelSize:F2}";
                }
                else
                {
                    InfoTextBlock.Text = $"Camera Distance:  {Camera1.Distance:F0}; Pixel size: {pixelSize:F2}";
                }
            };

            this.Unloaded += (sender, args) => Dispose();
        }