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 }
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(); } }
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); }
private void OnIsSolidColorMaterialCheckBoxCheckedChanged(object sender, RoutedEventArgs e) { if (!this.IsLoaded) { return; } _instancedMeshGeometryVisual3D.IsSolidColorMaterial = IsSolidColorMaterialCheckBox.IsChecked ?? false; MainDXViewportView.Refresh(); }
private void OnSolidModelColorComboBoxChanged(object sender, SelectionChangedEventArgs e) { if (!this.IsLoaded) { return; } ChangeRenderingType(); MainDXViewportView.Refresh(); }
private void OnRenderingTypeRadioButtonCheckedChanged(object sender, RoutedEventArgs e) { if (!this.IsLoaded) { return; } ChangeRenderingType(); MainDXViewportView.Refresh(); }
private void EdgeThresholdComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (!this.IsLoaded) { return; } _edgeDetectionPostProcess.EdgeThreshold = (float)EdgeThresholdComboBox.SelectedItem; MainDXViewportView.Refresh(); // Render the scene again }
private void OnOutlineSettingsChanged(object sender, RoutedEventArgs e) { if (!this.IsLoaded) { return; } UpdateBlackOutlineEffectForOutlineThickness(); MainDXViewportView.Refresh(); }
private void GammaCorrectionComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (!this.IsLoaded || _gammaCorrectionPostProcess == null) { return; } _gammaCorrectionPostProcess.Gamma = GetSelectedComboBoxFloatValue(GammaCorrectionComboBox); MainDXViewportView.Refresh(); // Render the scene again }
private void FilterSizeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (!this.IsLoaded) { return; } UpdateGaussianBlurParameters(); MainDXViewportView.Refresh(); // Render the scene again }
private void OnOutlineTypeChanged(object sender, RoutedEventArgs e) { if (!this.IsLoaded) { return; } UpdateUsedOutlineTechnique(); MainDXViewportView.Refresh(); // Render the scene again }
private void EdgeThresholdComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (!this.IsLoaded) { return; } UpdateEdgeDetectionParameters(); MainDXViewportView.Refresh(); // Render the scene again }
private void ExpansionWidthSlider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (!this.IsLoaded) { return; } UpdateExpandParameters(); MainDXViewportView.Refresh(); // Render the scene again }
private void StandardDeviationSlider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (!this.IsLoaded) { return; } UpdateGaussianBlurParameters(); MainDXViewportView.Refresh(); // Render the scene again }
private void OutlineSizeSlider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (!this.IsLoaded) { return; } _horizontalExpandPostProcess.ExpansionWidth = (int)OutlineSizeSlider.Value; _verticalExpandPostProcess.ExpansionWidth = (int)OutlineSizeSlider.Value; MainDXViewportView.Refresh(); // Render scene again }
private void OnFogUsageChanged(object sender, RoutedEventArgs e) { if (!this.IsLoaded) { return; } UpdateFogUsage(); // Render the scene again MainDXViewportView.Refresh(); }
private void OnFogSettingsChanged(object sender, RoutedEventArgs e) { if (!this.IsLoaded) { return; } UpdateFogSettings(); // After we change the effect data, we need to manually re-render the scene MainDXViewportView.Refresh(); }
private void OnShowSolidObjectCheckBoxCheckedChanged(object sender, RoutedEventArgs e) { if (!this.IsLoaded || MainDXViewportView.DXScene == null) { return; } // Enable / disable standard rendering of 3D objects MainDXViewportView.DXScene.DefaultRenderObjectsRenderingStep.IsEnabled = ShowSolidObjectCheckBox.IsChecked ?? false; MainDXViewportView.Refresh(); }
private void OnIsCheckingIsCastingShadowCheckBoxChanged(object sender, RoutedEventArgs e) { if (_planarShadowRenderingProvider != null) { // See comments in LoadModel for more info about the following commented lines: //var teapotSceneNode = MainDXViewportView.GetSceneNodeForWpfObject(_teapotGeometryModel3D) as WpfGeometryModel3DNode; // we can get the teapotSceneNode in MainDXViewportView.DXSceneInitialized //if (teapotSceneNode != null) // teapotSceneNode.IsCastingShadow = IsCheckingIsCastingShadowCheckBox.IsChecked ?? false; _planarShadowRenderingProvider.IsCheckingIsCastingShadow = IsCheckingIsCastingShadowCheckBox.IsChecked ?? false; MainDXViewportView.Refresh(); } }
private void OutlineWidthComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (!this.IsLoaded || _horizontalExpandPostProcess == null) { return; } int outlineWidth = (int)OutlineWidthComboBox.SelectedItem; _horizontalExpandPostProcess.ExpansionWidth = outlineWidth; _verticalExpandPostProcess.ExpansionWidth = outlineWidth; MainDXViewportView.Refresh(); // Render the scene again }
private void PointSizeComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (!this.IsLoaded) { return; } //RecreatePointCloud(); var selectedValue = (float)PointSizeComboBox.SelectedItem; _shadedPointCloudEffect.PointSize = selectedValue; MainDXViewportView.Refresh(); // Render the scene again }
private void CreateObjectsUIButton_OnClick(object sender, RoutedEventArgs e) { RootModelVisual3D.Children.Clear(); StartStopwatch(); var model3DGroup = CreateManyObjects(); // Create ModelVisual3D from modelVisual3D and add it to the scene RootModelVisual3D.Children.Add(model3DGroup.CreateModelVisual3D()); MainDXViewportView.Refresh(); // Manually render next frame StopStopwatch(UIThreadTime1TextBlock); }
private void OnIsCameraDistanceSortingEnabledCheckBoxCheckedChanged(object sender, RoutedEventArgs e) { if (MainDXViewportView.DXScene == null) { return; } bool isSortingEnabled = IsCameraDistanceSortingEnabledCheckBox.IsChecked ?? false; MainDXViewportView.DXScene.IsTransparencySortingEnabled = isSortingEnabled; if (!isSortingEnabled) { MainDXViewportView.Refresh(); // If we check the sorting CheckBox then render the scene again to sort the objects } }
private void OnCustomShadowLightCheckBoxCheckedChanged(object sender, RoutedEventArgs e) { if (!this.IsLoaded) { return; } if (CustomShadowLightCheckBox.IsChecked ?? false) { _planarShadowRenderingProvider.CustomShadowLight = new Ab3d.DirectX.Lights.DirectionalLight(new Vector3(0, -1, 0)); //_planarShadowRenderingProvider.CustomShadowLight = new Ab3d.DirectX.Lights.PointLight(new Vector3(0, 500, 0), 300); } else { _planarShadowRenderingProvider.CustomShadowLight = null; } MainDXViewportView.Refresh(); }
private void UpdateShadowSettings() { if (MainDXViewportView.DXScene == null) // Probably using WPF 3D rendering { return; } // When the ShadowMapSize or ShadowDepthBluringSize is changed, // we need to dispose the current VarianceShadowRenderingProvider and create a new one if (_varianceShadowRenderingProvider != null && (_varianceShadowRenderingProvider.ShadowMapSize != _shadowMapSize || _varianceShadowRenderingProvider.ShadowDepthBluringSize != _shadowDepthBluringSize)) { MainDXViewportView.DXScene.InitializeShadowRendering(null); _varianceShadowRenderingProvider.Dispose(); _varianceShadowRenderingProvider = null; } if (_varianceShadowRenderingProvider == null) { _varianceShadowRenderingProvider = new VarianceShadowRenderingProvider() { ShadowMapSize = _shadowMapSize, ShadowDepthBluringSize = _shadowDepthBluringSize, ShadowThreshold = _shadowThreshold, ShadowDepthBias = _shadowDepthBias }; MainDXViewportView.DXScene.InitializeShadowRendering(_varianceShadowRenderingProvider); } else { // ShadowThreshold can be changed without reinitializing the shadow rendering _varianceShadowRenderingProvider.ShadowThreshold = _shadowThreshold; _varianceShadowRenderingProvider.ShadowDepthBias = _shadowDepthBias; } UpdateCastingShadowLight(); MainDXViewportView.Refresh(); // Render the scene again }
private void OnPixelSizeChanged(object sender, RoutedEventArgs e) { if (!this.IsLoaded || DesignerProperties.GetIsInDesignMode(this) || _isInternalChange || _pixelEffect == null) { return; } _isPixelSizeChanged = true; var newPixelSize = (float)PixelSizeComboBox.SelectedItem; if (_isUsingPixelsVisual3D) { foreach (var pixelsVisual3D in MainViewport.Children.OfType <PixelsVisual3D>()) { pixelsVisual3D.PixelSize = newPixelSize; } } else { foreach (var sceneNodeVisual3D in MainViewport.Children.OfType <SceneNodeVisual3D>()) { var meshObjectNode = sceneNodeVisual3D.SceneNode as MeshObjectNode; if (meshObjectNode != null) { var pixelMaterial = meshObjectNode.Materials[0] as PixelMaterial; if (pixelMaterial != null) { pixelMaterial.PixelSize = newPixelSize; meshObjectNode.NotifySceneNodeChange(SceneNode.SceneNodeDirtyFlags.MaterialChanged); } } } } _pixelEffect.PixelSize = newPixelSize; // Re-render the scene // Manually calling Refresh is needed in case ShowGeometryModel3D method was used to show pixels. // In this case we have only changed the _pixelEffect.PixelSize and this will not trigger automatic scene re-render. MainDXViewportView.Refresh(); }
private void LoadObjFileUIButton_OnClick(object sender, RoutedEventArgs e) { RootModelVisual3D.Children.Clear(); StartStopwatch(); // 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(); // Create ModelVisual3D from readModel3D and add it to the scene RootModelVisual3D.Children.Add(readModel3D.CreateModelVisual3D()); MainDXViewportView.Refresh(); // Manually render next frame StopStopwatch(UIThreadTime1TextBlock); }
private void OnModelCheckBoxCheckedChanged(object sender, RoutedEventArgs e) { var checkBox = sender as CheckBox; var modelVisual3D = checkBox.Tag as ModelVisual3D; if (modelVisual3D != null) { var modelName = modelVisual3D.GetName(); if (checkBox.IsChecked ?? false) { _selectedObjectNames.Add(modelName); } else { _selectedObjectNames.Remove(modelName); } } MainDXViewportView.Refresh(); // Render scene again }
private void AlphaClipThresholdSlider_OnValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (_instancedTextNode == null) { return; } var newValue = (float)AlphaClipThresholdSlider.Value; if (MathUtils.IsZero(newValue)) { AlphaClipThresholdValueTextBlock.Text = "disabled"; } else { AlphaClipThresholdValueTextBlock.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:0.00}", newValue); } _instancedTextNode.AlphaClipThreshold = newValue; MainDXViewportView.Refresh(); }