private void UpdateShadowModel() { if (_planarShadowMeshCreator == null) { return; } // PlanarShadowMeshCreator generates a MeshGeometry3D that represents a shadow that is flattened to the plane. MeshGeometry3D shadowMesh; if (_currentShadowLight == _shadowDirectionalLight) { shadowMesh = _planarShadowMeshCreator.ApplyShadowMatrix(_shadowDirectionalLight.Direction); } else { shadowMesh = _planarShadowMeshCreator.ApplyShadowMatrix(_shadowPointLight.Position); } if (_shadowModel3D == null) { var shadowMaterial = (TransparentShadowCheckBox.IsChecked ?? false) ? _transparentShadowMaterial : _solidShadowMaterial; _shadowModel3D = new GeometryModel3D(shadowMesh, shadowMaterial); if (_shadowVisual3D != null) { MainViewport.Children.Remove(_shadowVisual3D); } _shadowVisual3D = _shadowModel3D.CreateModelVisual3D(); _shadowVisual3D.Transform = new TranslateTransform3D(0, 0.05, 0); // Lift the shadow 3D model slightly above the ground MainViewport.Children.Add(_shadowVisual3D); } else { _shadowModel3D.Geometry = shadowMesh; } }