public static Viewport3DElement GetEnclosingViewportForModelVisual3D(SceneViewModel sceneViewModel, ModelVisual3DElement modelVisual3D) { Viewport3DElement viewport3Delement = (Viewport3DElement)sceneViewModel.CreateSceneNode(PlatformTypes.Viewport3D); viewport3Delement.SetValueAsWpf(Viewport3DElement.ClipToBoundsProperty, (object)true); Camera perspectiveCamera = Helper3D.CreateEnclosingPerspectiveCamera(45.0, 4.0 / 3.0, modelVisual3D.DesignTimeBounds, 0.8); viewport3Delement.Camera = (CameraElement)sceneViewModel.CreateSceneNode((object)perspectiveCamera); ModelVisual3DElement modelVisual3Delement = (ModelVisual3DElement)sceneViewModel.CreateSceneNode(PlatformTypes.ModelVisual3D); modelVisual3Delement.Name = "World"; viewport3Delement.Children.Add((Visual3DElement)modelVisual3Delement); AmbientLightElement ambientLightElement = (AmbientLightElement)sceneViewModel.CreateSceneNode(PlatformTypes.AmbientLight); ambientLightElement.SetValueAsWpf(LightElement.ColorProperty, (object)Color.FromRgb((byte)127, (byte)127, (byte)127)); ambientLightElement.Name = "AmbientLight"; modelVisual3Delement.Children.Add((Visual3DElement)GeometryCreationHelper3D.CreateModelVisual3DContainer((Model3DElement)ambientLightElement, sceneViewModel)); DirectionalLightElement directionalLightElement = (DirectionalLightElement)sceneViewModel.CreateSceneNode(PlatformTypes.DirectionalLight); directionalLightElement.SetValueAsWpf(LightElement.ColorProperty, (object)Color.FromRgb((byte)63, (byte)63, (byte)63)); directionalLightElement.SetValueAsWpf(DirectionalLightElement.DirectionProperty, (object)new Vector3D(0.0, 0.0, -1.0)); directionalLightElement.SetValueAsWpf(Model3DElement.TransformProperty, (object)new TranslateTransform3D(0.0, 0.0, 3.0)); directionalLightElement.Name = "DirectionalLight"; modelVisual3Delement.Children.Add((Visual3DElement)GeometryCreationHelper3D.CreateModelVisual3DContainer((Model3DElement)directionalLightElement, sceneViewModel)); modelVisual3Delement.Children.Add((Visual3DElement)modelVisual3D); return(viewport3Delement); }
public static Matrix3D CameraRotationMatrix(Camera camera) { Matrix3D matrix3D = Helper3D.CameraRotationTranslationMatrix(camera); matrix3D.OffsetX = 0.0; matrix3D.OffsetY = 0.0; matrix3D.OffsetZ = 0.0; return(matrix3D); }
private static void UnitTestAddLights(ModelVisual3D world) { AmbientLight ambientLight = new AmbientLight(Color.FromRgb((byte)127, (byte)127, (byte)127)); world.Children.Add((Visual3D)Helper3D.UnitTestCreateModelVisual3DContainer((Model3D)ambientLight)); Vector3D direction = new Vector3D(0.0, 0.0, -1.0); direction.Normalize(); DirectionalLight directionalLight = new DirectionalLight(Color.FromRgb((byte)63, (byte)63, (byte)63), direction); directionalLight.Transform = (Transform3D) new TranslateTransform3D(new Vector3D(0.0, 0.0, 3.0)); world.Children.Add((Visual3D)Helper3D.UnitTestCreateModelVisual3DContainer((Model3D)directionalLight)); }
internal static Camera CreateEnclosingPerspectiveCamera(double horizontalFieldOfView, double aspectRatio, List <Model3D> models) { Rect3D empty = Rect3D.Empty; foreach (Model3D model3D in models) { if (model3D != null) { empty.Union(model3D.Bounds); } } return(Helper3D.CreateEnclosingPerspectiveCamera(horizontalFieldOfView, aspectRatio, empty, 0.8)); }
public static Viewport3D UnitTestCreateViewportContainingModel(Model3D model, Camera camera, double width, double height, bool clipToBounds) { Viewport3D viewport3D = Helper3D.UnitTestCreateViewport3D(width, height, clipToBounds); ModelVisual3D world = new ModelVisual3D(); Helper3D.UnitTestAddLights(world); if (model != null) { world.Content = model; } viewport3D.Children.Add((Visual3D)world); Helper3D.UnitTestAddCameraToViewport3D(camera, viewport3D, width, height, model); return(viewport3D); }
public static double UnitsPerPixel(Viewport3D viewport, Base3DElement targetModel) { Matrix3D matrix3D1 = Matrix3D.Identity; Base3DElement base3Delement = targetModel.Parent as Base3DElement; if (base3Delement != null) { matrix3D1 = base3Delement.GetComputedTransformFromViewport3DToElement(); } Point3D point3D = matrix3D1.Transform(new Point3D(0.0, 0.0, 0.0)); double num = (matrix3D1.Transform(new Point3D(0.1, 0.1, 0.1)) - point3D).Length / 0.1; Matrix3D matrix3D2 = targetModel.Transform.Value * matrix3D1; Point3D targetPoint = new Point3D(matrix3D2.OffsetX, matrix3D2.OffsetY, matrix3D2.OffsetZ); return(Helper3D.UnitsPerPixel(viewport, targetPoint) / num); }
private static void UnitTestAddCameraToViewport3D(Camera camera, Viewport3D viewport, double width, double height, Model3D model) { List <Model3D> models = new List <Model3D>(); models.Add(model); if (camera == null) { if (double.IsNaN(height) || double.IsNaN(width)) { viewport.Camera = Helper3D.CreateEnclosingPerspectiveCamera(45.0, 1.0, models); } else { viewport.Camera = Helper3D.CreateEnclosingPerspectiveCamera(45.0, height / width, models); } } else { viewport.Camera = camera; } }
protected void RecomputeTransform() { AdornerSet3DContainer adornerSet3Dcontainer = this.adornerSet3DContainer; Viewport3D viewport = (Viewport3D)this.Element.Viewport.ViewObject.PlatformSpecificObject; Matrix3D viewport3DtoElement = this.Element.GetComputedTransformFromViewport3DToElement(); Point3D point = new Point3D(); if (this.DoCenterOnSpecifiedCenter) { point = (CanonicalTransform3D)this.Element.Transform.Center; } Matrix3D source = viewport3DtoElement; source.TranslatePrepend((Vector3D)point); if (this.DoRemoveObjectScale) { Matrix3D rotation = new Matrix3D(); Vector3D scale = new Vector3D(); Matrix3DOperations.DecomposeIntoRotationAndScale(source, out rotation, out scale); rotation.OffsetX = source.OffsetX; rotation.OffsetY = source.OffsetY; rotation.OffsetZ = source.OffsetZ; source = rotation; } if (this.adornmentLayer == AdornerSet3D.Location.OrthographicLayer && adornerSet3Dcontainer.ShadowAdorningViewport3D.Camera is ProjectionCamera) { OrthographicCamera ortho = (OrthographicCamera)adornerSet3Dcontainer.OrthographicAdorningViewport3D.Camera; Point3D point3D = AdornedToolBehavior3D.ProjectionPoint3DTranslatedToMatchingOrthographicPosition(viewport, viewport3DtoElement, ortho, point); source.OffsetX = point3D.X; source.OffsetY = point3D.Y; source.OffsetZ = point3D.Z; } Point3D targetPoint = new Point3D(source.OffsetX, source.OffsetY, source.OffsetZ); if (this.DoScaleToScreen) { double num1 = this.adornmentLayer != AdornerSet3D.Location.OrthographicLayer || !(adornerSet3Dcontainer.ShadowAdorningViewport3D.Camera is ProjectionCamera) ? Helper3D.UnitsPerPixel(viewport, targetPoint) * AdornerSet3D.PixelsPerInch : 6.0 / (this.AdornerSet3DContainer.AdornedViewport.GetComputedTightBounds().Width / 96.0); Matrix rotation; Vector scale; Matrix3DOperations.DecomposeIntoRotationAndScale(ElementUtilities.GetComputedTransform((Visual)viewport, (Visual)(this.View.ViewModel.DefaultView.ViewRoot.PlatformSpecificObject as FrameworkElement)), out rotation, out scale); double x = scale.X; double zoom = this.View.Zoom; double num2 = num1 / zoom * x; double offsetX = -targetPoint.X * num2 + targetPoint.X; double offsetY = -targetPoint.Y * num2 + targetPoint.Y; double offsetZ = -targetPoint.Z * num2 + targetPoint.Z; Matrix3D matrix3D = new Matrix3D(num2, 0.0, 0.0, 0.0, 0.0, num2, 0.0, 0.0, 0.0, 0.0, num2, 0.0, offsetX, offsetY, offsetZ, 1.0); ((MatrixTransform3D)this.adornerSetVisual.Transform).Matrix = source * matrix3D; } else { ((MatrixTransform3D)this.adornerSetVisual.Transform).Matrix = source; } }
internal static Camera CreateEnclosingPerspectiveCamera(double horizontalFieldOfView, double aspectRatio, Model3D model) { return(Helper3D.CreateEnclosingPerspectiveCamera(horizontalFieldOfView, aspectRatio, model != null ? model.Bounds : Rect3D.Empty, 0.8)); }