Esempio n. 1
0
        private void AddSkeleton(Viewport3D viewport, Node root, List<Point3D> uniquePoints)
        {
            int childCount = root.Children.Count;
            uniquePoints.Add(root.StartPointWorld);
            if (childCount == 0) { // if leaf node
                return;
            }

            for (int i = 0; i < childCount; i++) {
                Node child = root.Children[i];
                child.StartPointWorld.X = root.StartPointWorld.X + child.Offset.X;
                child.StartPointWorld.Y = root.StartPointWorld.Y + child.Offset.Y;
                child.StartPointWorld.Z = root.StartPointWorld.Z + child.Offset.Z;
                SolidColorBrush brush;
                if (child.Children.Count == 0) { // if end node
                    brush = new SolidColorBrush(Colors.Green);
                }
                else
            /*        if (root.Name == "RightKnee") {
                        brush = new SolidColorBrush(Colors.Blue);
                    }
                    else*/
                {
                    brush = new SolidColorBrush(Colors.Red);
                }

                viewport.AddChild(new LineVisual3D(root.StartPointWorld, child.StartPointWorld, brush));
                AddSkeleton(viewport, child, uniquePoints);
            }
        }
 public PerspectiveCamera(Point3D position,
                          Vector3D lookDirection,
                          Vector3D upDirection,
                          double fieldOfView, Viewport3D viewport)
 {
     this.Position = position;
     this.LookDirection = lookDirection;
     this.UpDirection = upDirection;
     this.FieldOfView = fieldOfView;
     this.Viewport = viewport;
 }
 public static IObservable <EventPattern <StylusSystemGestureEventArgs> > StylusSystemGestureObserver(this Viewport3D This)
 {
     return(Observable.FromEventPattern <StylusSystemGestureEventHandler, StylusSystemGestureEventArgs>(h => This.StylusSystemGesture += h, h => This.StylusSystemGesture -= h));
 }
 public static IObservable <EventPattern <DependencyPropertyChangedEventArgs> > DataContextChangedObserver(this Viewport3D This)
 {
     return(Observable.FromEventPattern <DependencyPropertyChangedEventHandler, DependencyPropertyChangedEventArgs>(h => This.DataContextChanged += h, h => This.DataContextChanged -= h));
 }
 public static IObservable <EventPattern <QueryCursorEventArgs> > QueryCursorObserver(this Viewport3D This)
 {
     return(Observable.FromEventPattern <QueryCursorEventHandler, QueryCursorEventArgs>(h => This.QueryCursor += h, h => This.QueryCursor -= h));
 }
 public static IObservable <EventPattern <MouseEventArgs> > GotMouseCaptureObserver(this Viewport3D This)
 {
     return(Observable.FromEventPattern <MouseEventHandler, MouseEventArgs>(h => This.GotMouseCapture += h, h => This.GotMouseCapture -= h));
 }
 public static IObservable <EventPattern <MouseWheelEventArgs> > PreviewMouseWheelObserver(this Viewport3D This)
 {
     return(Observable.FromEventPattern <MouseWheelEventHandler, MouseWheelEventArgs>(h => This.PreviewMouseWheel += h, h => This.PreviewMouseWheel -= h));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PointSelectionCommand" /> class.
 /// </summary>
 /// <param name="viewport">The viewport.</param>
 /// <param name="eventHandler">The selection event handler.</param>
 public PointSelectionCommand(Viewport3D viewport, EventHandler <ModelsSelectedEventArgs> eventHandler)
     : base(viewport, eventHandler)
 {
 }
Esempio n. 9
0
        private void LoadMotion(ref Motion motion, Viewport3D viewport, string data)
        {
            motion = new Motion();
            motion = Loader.LoadFromBvh(data);
            List<Point3D> uniquePoints = new List<Point3D>(200);

            motion.Skeleton.StartPointWorld.X = motion.Skeleton.Offset.X;
            motion.Skeleton.StartPointWorld.Y = motion.Skeleton.Offset.Y;
            motion.Skeleton.StartPointWorld.Z = motion.Skeleton.Offset.Z;
            AddSkeleton(viewport, motion.Skeleton, uniquePoints); // !!! TODO: use unique points avoid duplicate computations
            viewport.Render();
            _lastTimeRendered1 = DateTime.Now;
            _lastTimeRendered2 = DateTime.Now;
        }
Esempio n. 10
0
        private Model3D ConvertVisualToModel3D(Visual visual, ref double z)
        {
            Model3D    model    = null;
            Rect       bounds   = VisualTreeHelper.GetContentBounds(visual);
            Viewport3D viewport = visual as Viewport3D;

            if (viewport != null)
            {
                bounds = new Rect(viewport.RenderSize);
            }
            if (this.includeEmptyVisuals)
            {
                bounds.Union(VisualTreeHelper.GetDescendantBounds(visual));
            }
            if (!bounds.IsEmpty && bounds.Width > 0 && bounds.Height > 0)
            {
                MeshGeometry3D mesh = new MeshGeometry3D();
                mesh.Positions.Add(new Point3D(bounds.Left, bounds.Top, z));
                mesh.Positions.Add(new Point3D(bounds.Right, bounds.Top, z));
                mesh.Positions.Add(new Point3D(bounds.Right, bounds.Bottom, z));
                mesh.Positions.Add(new Point3D(bounds.Left, bounds.Bottom, z));
                mesh.TextureCoordinates.Add(new Point(0, 0));
                mesh.TextureCoordinates.Add(new Point(1, 0));
                mesh.TextureCoordinates.Add(new Point(1, 1));
                mesh.TextureCoordinates.Add(new Point(0, 1));
                mesh.Normals.Add(new Vector3D(0, 0, 1));
                mesh.Normals.Add(new Vector3D(0, 0, 1));
                mesh.Normals.Add(new Vector3D(0, 0, 1));
                mesh.Normals.Add(new Vector3D(0, 0, 1));
                mesh.TriangleIndices = new Int32Collection(new int[] { 0, 1, 2, 2, 3, 0 });
                mesh.Freeze();

                Brush           brush    = this.MakeBrushFromVisual(visual, bounds);
                DiffuseMaterial material = new DiffuseMaterial(brush);
                material.Freeze();

                model = new GeometryModel3D(mesh, material);
                ((GeometryModel3D)model).BackMaterial = material;

                z -= 1;
            }

            int childrenCount = VisualTreeHelper.GetChildrenCount(visual);

            if (childrenCount > 0)
            {
                Model3DGroup group = new Model3DGroup();
                if (model != null)
                {
                    group.Children.Add(model);
                }
                for (int i = 0; i < childrenCount; i++)
                {
                    Visual childVisual = CommonTreeHelper.GetChild(visual, i) as Visual;
                    if (childVisual != null)
                    {
                        Model3D childModel = this.ConvertVisualToModel3D(childVisual, ref z);
                        if (childModel != null)
                        {
                            group.Children.Add(childModel);
                        }
                    }
                }
                model = group;
            }

            if (model != null)
            {
                Transform transform = VisualTreeHelper.GetTransform(visual);
                Matrix    matrix    = (transform == null ? Matrix.Identity : transform.Value);
                Vector    offset    = VisualTreeHelper.GetOffset(visual);
                matrix.Translate(offset.X, offset.Y);
                if (!matrix.IsIdentity)
                {
                    Matrix3D    matrix3D    = new Matrix3D(matrix.M11, matrix.M12, 0, 0, matrix.M21, matrix.M22, 0, 0, 0, 0, 1, 0, matrix.OffsetX, matrix.OffsetY, 0, 1);
                    Transform3D transform3D = new MatrixTransform3D(matrix3D);
                    transform3D.Freeze();
                    model.Transform = transform3D;
                }
                model.Freeze();
            }

            return(model);
        }
Esempio n. 11
0
 // select
 public virtual void Select(ViewportRect rect, TransformMatrix matrix, Viewport3D viewport3d)
 {
 }
Esempio n. 12
0
        public void InitializeDice()
        {
            Viewport = new Viewport3D();      //Viewport3D class provides a rendering surface for 3-D visual content
            surface1 = new GeometryModel3D(); //GeometryModel3D class object provides generalized transformation support for 3-D objects
            surface2 = new GeometryModel3D();
            surface3 = new GeometryModel3D();
            surface4 = new GeometryModel3D();
            surface5 = new GeometryModel3D();
            surface6 = new GeometryModel3D();
            Camera   = new PerspectiveCamera();              //PerspectiveCamera class object represents a perspective projection camera

            myDLight = new DirectionalLight();               //DirectionalLight class object provides effect along a direction

            AmLight = new AmbientLight();                    //AmbientLight class objects provides Lights every surface uniformly a bright AmbientLight creates  because of lack of shading, but a low-intensity AmbientLight approximatesthe effect of light that has been scattered by reflecting between diffuse surfaces in the scene.

            MaterialGroup myMaterials = new MaterialGroup(); //MaterialGroup class objects applies multiple Materials to a model each Material is rendered in order, with the last Material in the group appearing on top.

            Transgroup = new Transform3DGroup();             //Transform3DGroup class contains a collection of Transform3Ds.
            Model3DGroup Modelgroup = new Model3DGroup();    //The Model3DGroup class is itself a Model3D and is often used to group multiple GeometryModel3Ds

            cube          = new Model3DGroup();
            surface1Plane = new MeshGeometry3D();// MeshGeometry3D class represents a set of 3D surfaces
            surface2Plane = new MeshGeometry3D();
            surface3Plane = new MeshGeometry3D();
            surface4Plane = new MeshGeometry3D();
            surface5Plane = new MeshGeometry3D();
            surface6Plane = new MeshGeometry3D();

            ModelVisual3D ModelVisualD = new ModelVisual3D();//ModelVisual3D class contains 3-D models

            //Camera.Position = new Point3D(-5, 2, 3);//setting the camera position in world coordinates
            //Camera.LookDirection = new Vector3D(5, -2, -3);//defininig the direction in which the camera looking in world coordinates
            Camera.Position      = new Point3D(0, 0, 2);   //setting the camera position in world coordinates
            Camera.LookDirection = new Vector3D(0, 0, -1); //defininig the direction in which the camera looking in world coordinates
            AmLight.Color        = Colors.White;           //setting the color of light

            //set Geometry property of MeshGeometry3D

            surface1.Geometry = surface1Plane;
            surface2.Geometry = surface2Plane;
            surface3.Geometry = surface3Plane;
            surface4.Geometry = surface4Plane;
            surface5.Geometry = surface5Plane;
            surface6.Geometry = surface6Plane;

            cube.Children.Add(surface1);
            cube.Children.Add(surface2);
            cube.Children.Add(surface3);
            cube.Children.Add(surface4);
            cube.Children.Add(surface5);
            cube.Children.Add(surface6);

            Modelgroup.Transform = Transgroup;

            Modelgroup.Children.Add(cube);

            Modelgroup.Children.Add(AmLight);
            Modelgroup.Children.Add(myDLight);

            Viewport.Camera = Camera;

            ModelVisualD.Content = Modelgroup;

            Viewport.Children.Add(ModelVisualD);

            //Defining surface position in world coordinates
            //-----------------------surface1------------------------


            surface1Plane.Positions.Add(new Point3D(-0.5, -0.5, -0.5));
            surface1Plane.Positions.Add(new Point3D(-0.5, 0.5, -0.5));
            surface1Plane.Positions.Add(new Point3D(0.5, 0.5, -0.5));
            surface1Plane.Positions.Add(new Point3D(0.5, 0.5, -0.5));
            surface1Plane.Positions.Add(new Point3D(0.5, -0.5, -0.5));
            surface1Plane.Positions.Add(new Point3D(-0.5, -0.5, -0.5));


            //TriangleIndices—Describes the connections between the vertices to form triangles if TriangleIndices is not specified, it is implied that the positions should beconnected in the order they appear: 0 1 2, then 3 4 5, and so on.

            surface1Plane.TriangleIndices.Add(0);
            surface1Plane.TriangleIndices.Add(1);
            surface1Plane.TriangleIndices.Add(2);
            surface1Plane.TriangleIndices.Add(3);
            surface1Plane.TriangleIndices.Add(4);
            surface1Plane.TriangleIndices.Add(5);

            surface1Plane.Normals.Add(new Vector3D(0, 0, -1));
            surface1Plane.Normals.Add(new Vector3D(0, 0, -1));
            surface1Plane.Normals.Add(new Vector3D(0, 0, -1));
            surface1Plane.Normals.Add(new Vector3D(0, 0, -1));
            surface1Plane.Normals.Add(new Vector3D(0, 0, -1));
            surface1Plane.Normals.Add(new Vector3D(0, 0, -1));

            surface1Plane.TextureCoordinates.Add(new Point(1, 0));
            surface1Plane.TextureCoordinates.Add(new Point(1, 1));
            surface1Plane.TextureCoordinates.Add(new Point(0, 1));
            surface1Plane.TextureCoordinates.Add(new Point(0, 1));
            surface1Plane.TextureCoordinates.Add(new Point(0, 0));
            surface1Plane.TextureCoordinates.Add(new Point(1, 0));

            //-----------------------surface2------------------------


            surface2Plane.Positions.Add(new Point3D(-0.5, -0.5, 0.5));
            surface2Plane.Positions.Add(new Point3D(0.5, -0.5, 0.5));
            surface2Plane.Positions.Add(new Point3D(0.5, 0.5, 0.5));
            surface2Plane.Positions.Add(new Point3D(0.5, 0.5, 0.5));
            surface2Plane.Positions.Add(new Point3D(-0.5, 0.5, 0.5));
            surface2Plane.Positions.Add(new Point3D(-0.5, -0.5, 0.5));

            surface2Plane.TriangleIndices.Add(0);
            surface2Plane.TriangleIndices.Add(1);
            surface2Plane.TriangleIndices.Add(2);
            surface2Plane.TriangleIndices.Add(3);
            surface2Plane.TriangleIndices.Add(4);
            surface2Plane.TriangleIndices.Add(5);

            surface2Plane.Normals.Add(new Vector3D(0, 0, 1));
            surface2Plane.Normals.Add(new Vector3D(0, 0, 1));
            surface2Plane.Normals.Add(new Vector3D(0, 0, 1));
            surface2Plane.Normals.Add(new Vector3D(0, 0, 1));
            surface2Plane.Normals.Add(new Vector3D(0, 0, 1));
            surface2Plane.Normals.Add(new Vector3D(0, 0, 1));

            surface2Plane.TextureCoordinates.Add(new Point(0, 0));
            surface2Plane.TextureCoordinates.Add(new Point(1, 0));
            surface2Plane.TextureCoordinates.Add(new Point(1, 1));
            surface2Plane.TextureCoordinates.Add(new Point(1, 1));
            surface2Plane.TextureCoordinates.Add(new Point(0, 1));
            surface2Plane.TextureCoordinates.Add(new Point(0, 0));

            //-----------------------surface3------------------------


            surface3Plane.Positions.Add(new Point3D(-0.5, -0.5, -0.5));
            surface3Plane.Positions.Add(new Point3D(0.5, -0.5, -0.5));
            surface3Plane.Positions.Add(new Point3D(0.5, -0.5, 0.5));
            surface3Plane.Positions.Add(new Point3D(0.5, -0.5, 0.5));
            surface3Plane.Positions.Add(new Point3D(-0.5, -0.5, 0.5));
            surface3Plane.Positions.Add(new Point3D(-0.5, -0.5, -0.5));

            surface3Plane.TriangleIndices.Add(0);
            surface3Plane.TriangleIndices.Add(1);
            surface3Plane.TriangleIndices.Add(2);
            surface3Plane.TriangleIndices.Add(3);
            surface3Plane.TriangleIndices.Add(4);
            surface3Plane.TriangleIndices.Add(5);

            surface3Plane.Normals.Add(new Vector3D(0, -1, 0));
            surface3Plane.Normals.Add(new Vector3D(0, -1, 0));
            surface3Plane.Normals.Add(new Vector3D(0, -1, 0));
            surface3Plane.Normals.Add(new Vector3D(0, -1, 0));
            surface3Plane.Normals.Add(new Vector3D(0, -1, 0));
            surface3Plane.Normals.Add(new Vector3D(0, -1, 0));

            surface3Plane.TextureCoordinates.Add(new Point(0, 0));
            surface3Plane.TextureCoordinates.Add(new Point(1, 0));
            surface3Plane.TextureCoordinates.Add(new Point(1, 1));
            surface3Plane.TextureCoordinates.Add(new Point(1, 1));
            surface3Plane.TextureCoordinates.Add(new Point(0, 1));
            surface3Plane.TextureCoordinates.Add(new Point(0, 0));

            //-----------------------surface4------------------------


            surface4Plane.Positions.Add(new Point3D(0.5, -0.5, -0.5));
            surface4Plane.Positions.Add(new Point3D(0.5, 0.5, -0.5));
            surface4Plane.Positions.Add(new Point3D(0.5, 0.5, 0.5));
            surface4Plane.Positions.Add(new Point3D(0.5, 0.5, 0.5));
            surface4Plane.Positions.Add(new Point3D(0.5, -0.5, 0.5));
            surface4Plane.Positions.Add(new Point3D(0.5, -0.5, -0.5));

            surface4Plane.TriangleIndices.Add(0);
            surface4Plane.TriangleIndices.Add(1);
            surface4Plane.TriangleIndices.Add(2);
            surface4Plane.TriangleIndices.Add(3);
            surface4Plane.TriangleIndices.Add(4);
            surface4Plane.TriangleIndices.Add(5);

            surface4Plane.Normals.Add(new Vector3D(1, 0, 0));
            surface4Plane.Normals.Add(new Vector3D(1, 0, 0));
            surface4Plane.Normals.Add(new Vector3D(1, 0, 0));
            surface4Plane.Normals.Add(new Vector3D(1, 0, 0));
            surface4Plane.Normals.Add(new Vector3D(1, 0, 0));
            surface4Plane.Normals.Add(new Vector3D(1, 0, 0));

            surface4Plane.TextureCoordinates.Add(new Point(1, 0));
            surface4Plane.TextureCoordinates.Add(new Point(1, 1));
            surface4Plane.TextureCoordinates.Add(new Point(0, 1));
            surface4Plane.TextureCoordinates.Add(new Point(0, 1));
            surface4Plane.TextureCoordinates.Add(new Point(0, 0));
            surface4Plane.TextureCoordinates.Add(new Point(1, 0));

            //-----------------------surface5------------------------


            surface5Plane.Positions.Add(new Point3D(0.5, 0.5, -0.5));
            surface5Plane.Positions.Add(new Point3D(-0.5, 0.5, -0.5));
            surface5Plane.Positions.Add(new Point3D(-0.5, 0.5, 0.5));
            surface5Plane.Positions.Add(new Point3D(-0.5, 0.5, 0.5));
            surface5Plane.Positions.Add(new Point3D(0.5, 0.5, 0.5));
            surface5Plane.Positions.Add(new Point3D(0.5, 0.5, -0.5));

            surface5Plane.TriangleIndices.Add(0);
            surface5Plane.TriangleIndices.Add(1);
            surface5Plane.TriangleIndices.Add(2);
            surface5Plane.TriangleIndices.Add(3);
            surface5Plane.TriangleIndices.Add(4);
            surface5Plane.TriangleIndices.Add(5);

            surface5Plane.Normals.Add(new Vector3D(0, 1, 0));
            surface5Plane.Normals.Add(new Vector3D(0, 1, 0));
            surface5Plane.Normals.Add(new Vector3D(0, 1, 0));
            surface5Plane.Normals.Add(new Vector3D(0, 1, 0));
            surface5Plane.Normals.Add(new Vector3D(0, 1, 0));
            surface5Plane.Normals.Add(new Vector3D(0, 1, 0));

            surface5Plane.TextureCoordinates.Add(new Point(1, 1));
            surface5Plane.TextureCoordinates.Add(new Point(0, 1));
            surface5Plane.TextureCoordinates.Add(new Point(0, 0));
            surface5Plane.TextureCoordinates.Add(new Point(0, 0));
            surface5Plane.TextureCoordinates.Add(new Point(1, 0));
            surface5Plane.TextureCoordinates.Add(new Point(1, 1));

            //-----------------------surface6------------------------


            surface6Plane.Positions.Add(new Point3D(-0.5, 0.5, -0.5));
            surface6Plane.Positions.Add(new Point3D(-0.5, -0.5, -0.5));
            surface6Plane.Positions.Add(new Point3D(-0.5, -0.5, 0.5));
            surface6Plane.Positions.Add(new Point3D(-0.5, -0.5, 0.5));
            surface6Plane.Positions.Add(new Point3D(-0.5, 0.5, 0.5));
            surface6Plane.Positions.Add(new Point3D(-0.5, 0.5, -0.5));

            surface6Plane.TriangleIndices.Add(0);
            surface6Plane.TriangleIndices.Add(1);
            surface6Plane.TriangleIndices.Add(2);
            surface6Plane.TriangleIndices.Add(3);
            surface6Plane.TriangleIndices.Add(4);
            surface6Plane.TriangleIndices.Add(5);

            surface6Plane.Normals.Add(new Vector3D(-1, 0, 0));
            surface6Plane.Normals.Add(new Vector3D(-1, 0, 0));
            surface6Plane.Normals.Add(new Vector3D(-1, 0, 0));
            surface6Plane.Normals.Add(new Vector3D(-1, 0, 0));
            surface6Plane.Normals.Add(new Vector3D(-1, 0, 0));
            surface6Plane.Normals.Add(new Vector3D(-1, 0, 0));

            surface6Plane.TextureCoordinates.Add(new Point(0, 1));
            surface6Plane.TextureCoordinates.Add(new Point(0, 0));
            surface6Plane.TextureCoordinates.Add(new Point(1, 0));
            surface6Plane.TextureCoordinates.Add(new Point(1, 0));
            surface6Plane.TextureCoordinates.Add(new Point(1, 1));
            surface6Plane.TextureCoordinates.Add(new Point(0, 1));

            //Accessing ImageBrush tags from App.xaml file with their keys name
            ImageBrush imgBrush1 = new ImageBrush((ImageSource)WPFBitmapConverter.Convert(Properties.Resources.One));
            ImageBrush imgBrush2 = new ImageBrush((ImageSource)WPFBitmapConverter.Convert(Properties.Resources.Six));
            ImageBrush imgBrush3 = new ImageBrush((ImageSource)WPFBitmapConverter.Convert(Properties.Resources.Four));
            ImageBrush imgBrush4 = new ImageBrush((ImageSource)WPFBitmapConverter.Convert(Properties.Resources.Five));
            ImageBrush imgBrush5 = new ImageBrush((ImageSource)WPFBitmapConverter.Convert(Properties.Resources.Three));
            ImageBrush imgBrush6 = new ImageBrush((ImageSource)WPFBitmapConverter.Convert(Properties.Resources.Two));

            surface1Material = new DiffuseMaterial((Brush)imgBrush1);
            surface2Material = new DiffuseMaterial((Brush)imgBrush2);
            surface3Material = new DiffuseMaterial((Brush)imgBrush3);
            surface4Material = new DiffuseMaterial((Brush)imgBrush4);
            surface5Material = new DiffuseMaterial((Brush)imgBrush5);
            surface6Material = new DiffuseMaterial((Brush)imgBrush6);

            surface1.Material = surface1Material;
            surface2.Material = surface2Material;
            surface3.Material = surface3Material;
            surface4.Material = surface4Material;
            surface5.Material = surface5Material;
            surface6.Material = surface6Material;
            this.Content      = Viewport;
        }
Esempio n. 13
0
        public void BeachBallSphere()
        {
            //Title = "Beachball Sphere";

            // Create Viewport3D as content of window.
            Viewport3D viewport = new Viewport3D();

            Content = viewport;

            // Get the MeshGeometry3D from the GenerateSphere method.
            MeshGeometry3D mesh =
                GenerateSphere(new Point3D(0, 0, 0), 1, 36, 18);

            mesh.Freeze();

            // Define a brush for the sphere.
            Brush[] brushes = new Brush[6] {
                Brushes.Red, Brushes.Blue,
                Brushes.Yellow, Brushes.Orange,
                Brushes.Green, Brushes.White
            };
            DrawingGroup drawgrp = new DrawingGroup();

            for (int i = 0; i < brushes.Length; i++)
            {
                RectangleGeometry rectgeo =
                    new RectangleGeometry(new Rect(10 * i, 0, 10, 60));

                GeometryDrawing geodraw =
                    new GeometryDrawing(brushes[i], null, rectgeo);

                drawgrp.Children.Add(geodraw);
            }
            DrawingBrush drawbrsh = new DrawingBrush(drawgrp);

            drawbrsh.Freeze();

            // Define the GeometryModel3D.
            GeometryModel3D geomod = new GeometryModel3D();

            geomod.Geometry = mesh;
            geomod.Material = new DiffuseMaterial(drawbrsh);

            // Create a ModelVisual3D for the GeometryModel3D.
            ModelVisual3D modvis = new ModelVisual3D();

            modvis.Content = geomod;
            viewport.Children.Add(modvis);

            // Create another ModelVisual3D for light.
            Model3DGroup modgrp = new Model3DGroup();

            modgrp.Children.Add(new AmbientLight(Color.FromRgb(128, 128, 128)));
            modgrp.Children.Add(
                new DirectionalLight(Color.FromRgb(128, 128, 128),
                                     new Vector3D(2, -3, -1)));

            modvis         = new ModelVisual3D();
            modvis.Content = modgrp;
            viewport.Children.Add(modvis);

            // Create the camera.
            PerspectiveCamera cam = new PerspectiveCamera(new Point3D(0, 0, 8),
                                                          new Vector3D(0, 0, -1), new Vector3D(0, 1, 0), 45);

            viewport.Camera = cam;

            // Create a transform for the GeometryModel3D.
            AxisAngleRotation3D axisangle =
                new AxisAngleRotation3D(new Vector3D(1, 1, 0), 0);
            RotateTransform3D rotate = new RotateTransform3D(axisangle);

            geomod.Transform = rotate;

            // Animate the RotateTransform3D.
            DoubleAnimation anima =
                new DoubleAnimation(360, new Duration(TimeSpan.FromSeconds(5)));

            anima.RepeatBehavior = RepeatBehavior.Forever;
            axisangle.BeginAnimation(AxisAngleRotation3D.AngleProperty, anima);
        }
Esempio n. 14
0
        public static PerspectiveCamera CreateFromBounds(AxisAlignedBox3D bounds, Viewport3D viewport,
			float fieldOfView, float yaw = 0.0f, float pitch = 0.0f, float zoom = 1.0f)
        {
            // Calculate initial guess at camera settings.
            Matrix3D transform = Matrix3D.CreateFromYawPitchRoll(yaw, pitch, 0);
            Vector3D cameraDirection = Vector3D.Normalize(transform.Transform(Vector3D.Forward));
            PerspectiveCamera initialGuess = new PerspectiveCamera
            {
                FieldOfView = fieldOfView,
                NearPlaneDistance = 1.0f,
                FarPlaneDistance = bounds.Size.Length() * 10,
                Position = bounds.Center - cameraDirection * bounds.Size.Length() * 2,
                LookDirection = cameraDirection,
                UpDirection = Vector3D.Up
            };

            Matrix3D projection = initialGuess.GetProjectionMatrix(viewport.AspectRatio);
            Matrix3D view = initialGuess.GetViewMatrix();

            // Project bounding box corners onto screen, and calculate screen bounds.
            float closestZ = float.MaxValue;
            Box2D? screenBounds = null;
            Point3D[] corners = bounds.GetCorners();
            foreach (Point3D corner in corners)
            {
                Point3D screenPoint = viewport.Project(corner,
                    projection, view, Matrix3D.Identity);

                if (screenPoint.Z < closestZ)
                    closestZ = screenPoint.Z;

                IntPoint2D intScreenPoint = new IntPoint2D((int) screenPoint.X, (int) screenPoint.Y);
                if (screenBounds == null)
                    screenBounds = new Box2D(intScreenPoint, intScreenPoint);
                else
                {
                    Box2D value = screenBounds.Value;
                    value.Expand(intScreenPoint);
                    screenBounds = value;
                }
            }

            // Now project back from screen bounds into scene, setting Z to the minimum bounding box Z value.
            IntPoint2D minScreen = screenBounds.Value.Min;
            IntPoint2D maxScreen = screenBounds.Value.Max;
            Point3D min = viewport.Unproject(new Point3D(minScreen.X, minScreen.Y, closestZ),
                projection, view, Matrix3D.Identity);
            Point3D max = viewport.Unproject(new Point3D(maxScreen.X, maxScreen.Y, closestZ),
                projection, view, Matrix3D.Identity);

            // Use these new values to calculate the distance the camera should be from the AABB centre.
            Vector3D size = Vector3D.Abs(max - min);
            float radius = size.Length();
            float dist = radius / (2 * MathUtility.Tan(fieldOfView * viewport.AspectRatio / 2));

            Point3D closestBoundsCenter = (min + (max - min) / 2);
            Point3D position = closestBoundsCenter - cameraDirection * dist * (1 / zoom);

            return new PerspectiveCamera
            {
                FieldOfView = fieldOfView,
                NearPlaneDistance = 1.0f,
                FarPlaneDistance = dist * 10,
                Position = position,
                LookDirection = cameraDirection,
                UpDirection = Vector3D.Up
            };
        }
 public static IObservable <EventPattern <RequestBringIntoViewEventArgs> > RequestBringIntoViewObserver(this Viewport3D This)
 {
     return(Observable.FromEventPattern <RequestBringIntoViewEventHandler, RequestBringIntoViewEventArgs>(h => This.RequestBringIntoView += h, h => This.RequestBringIntoView -= h));
 }
 public static IObservable <EventPattern <StylusButtonEventArgs> > PreviewStylusButtonDownObserver(this Viewport3D This)
 {
     return(Observable.FromEventPattern <StylusButtonEventHandler, StylusButtonEventArgs>(h => This.PreviewStylusButtonDown += h, h => This.PreviewStylusButtonDown -= h));
 }
Esempio n. 17
0
        /// <summary/>
        public void SaveSelectedSubSceneAsXaml(Point[] selectionPixels, string fileName)
        {
            // Add Those triangles which we selected
            Model3DGroup  mg           = new Model3DGroup();
            List <string> supportFiles = new List <string>();

            for (int i = 0; i < primitives.Length; i++)
            {
                if (primitives[i] is GeometryModel3D)
                {
                    GeometryModel3D gModel = (GeometryModel3D)primitives[i];

                    MeshGeometry3D saveMesh = null;
                    if (selectionPixels != null)
                    {
                        // Only save those meshes that actually had failed geometry
                        saveMesh = renderer.ExtractTrianglesAtPoints(
                            (MeshGeometry3D)gModel.Geometry,
                            gModel.Transform,
                            selectionPixels);
                    }
                    else
                    {
                        // Save the entire mesh
                        saveMesh = (MeshGeometry3D)gModel.Geometry;
                    }
                    if (saveMesh != null && saveMesh.Positions.Count > 0)
                    {
                        // Work around serialization problems with non URI based images
                        SerializeGeneratedWorkaround(gModel.Material, fileName, supportFiles);
                        SerializeGeneratedWorkaround(gModel.BackMaterial, fileName, supportFiles);
                        GeometryModel3D saveModel = new GeometryModel3D(saveMesh, gModel.Material);
                        saveModel.BackMaterial = gModel.BackMaterial;
                        saveModel.Transform    = gModel.Transform;
                        mg.Children.Add(saveModel);
                    }
                }
            }
            // Add all lights
            for (int i = 0; i < lights.Length; i++)
            {
                mg.Children.Add(lights[i]);
            }

            // Set the viewport
            Viewport3D    savedViewport = new Viewport3D();
            ModelVisual3D modelVisual   = new ModelVisual3D();

            modelVisual.Content = mg;
            savedViewport.Children.Add(modelVisual);
            savedViewport.Camera = camera;
            // Add the viewport to a panel with a Background
            DockPanel parent = new DockPanel();

            parent.Background = new SolidColorBrush(background);
            parent.Children.Add(savedViewport);

            using (TrustedStreamWriter sw = new TrustedStreamWriter(fileName))
            {
                string serialization = XamlWriter.Save(parent);
                // Make the thing readable ...
                serialization = serialization.Replace("xml:space=\"preserve\"", "");
                serialization = serialization.Replace("><", ">\n<");
                int    indentLevel    = -1;
                string indent         = "   ";
                bool   lastLineClosed = false;
                foreach (string line in serialization.Split('\n'))
                {
                    if (line.StartsWith("</"))
                    {
                        indentLevel--;
                        lastLineClosed = true;
                    }
                    else if (line.StartsWith("<"))
                    {
                        if (!lastLineClosed)
                        {
                            indentLevel++;
                        }
                        lastLineClosed = false;
                        if (line.Contains("/>"))
                        {
                            lastLineClosed = true;
                        }
                    }
                    for (int i = 0; i < indentLevel; i++)
                    {
                        sw.Write(indent);
                    }
                    sw.WriteLine(line);
                }

                // Add a list of support files added
                sw.WriteLine("<!--");
                sw.WriteLine("   Minimal XAML Repro brought to you by Avalon 3D test.");
                sw.WriteLine();
                sw.WriteLine("   Related support files needed:");
                foreach (string supportFile in supportFiles)
                {
                    sw.WriteLine("      " + supportFile);
                }
                sw.WriteLine("-->");
            }
        }
Esempio n. 18
0
 public void SetFusionRenderViewPort(Viewport3D graphicsViewPort)
 {
     this.CubeDrawer = new CubeDrawer(graphicsViewPort, FusionVolume);
 }
Esempio n. 19
0
 /// <summary/>
 public SceneRenderer(Size windowSize, Viewport3D viewport, Color background)
     : this(windowSize, viewport, background, DepthTestFunction.LessThanOrEqualTo)
 {
 }
 public static IObservable <EventPattern <MouseButtonEventArgs> > MouseRightButtonUpObserver(this Viewport3D This)
 {
     return(Observable.FromEventPattern <MouseButtonEventHandler, MouseButtonEventArgs>(h => This.MouseRightButtonUp += h, h => This.MouseRightButtonUp -= h));
 }
Esempio n. 21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StructureControl"/> class and sets up visual elements for rendering.
        /// </summary>
        /// <param name="pdbViewer">The PDB viewer.</param>
        internal StructureControl(PdbViewer pdbViewer)
        {
            this.pdbViewer = pdbViewer;

            NameScope.SetNameScope(this, new NameScope());

            this.viewport = new Viewport3D();
            this.viewport.ClipToBounds = true;
            this.Children.Add(this.viewport);

            this.camera          = new PerspectiveCamera();
            this.camera.Position = new Point3D(0, 0, cameraOffset);
            this.viewport.Camera = this.camera;

            ModelVisual3D lightingVisual = new ModelVisual3D();

            this.viewport.Children.Add(lightingVisual);

            Model3DGroup lightingModel = new Model3DGroup();

            lightingVisual.Content = lightingModel;

            PointLight pointLight = new PointLight(Colors.White, new Point3D(-4, 4, 8));

            lightingModel.Children.Add(pointLight);

            AmbientLight ambientLight = new AmbientLight(Color.FromRgb(32, 32, 32));

            lightingModel.Children.Add(ambientLight);

            this.moleculeVisual = new ModelVisual3D();
            viewport.Children.Add(this.moleculeVisual);

            Transform3DGroup transformGroup = new Transform3DGroup();

            this.moleculeVisual.Transform = transformGroup;

            this.translateTransform = new TranslateTransform3D();
            transformGroup.Children.Add(this.translateTransform);

            this.scaleTransform = new ScaleTransform3D();
            transformGroup.Children.Add(this.scaleTransform);

            this.rotateTransform          = new RotateTransform3D();
            this.rotateTransform.Rotation = new QuaternionRotation3D();
            transformGroup.Children.Add(this.rotateTransform);

            this.selectionRectangle            = new Rectangle();
            this.selectionRectangle.Stroke     = Brushes.White;
            this.selectionRectangle.Fill       = new SolidColorBrush(Color.FromArgb(32, 255, 255, 255));
            this.selectionRectangle.Visibility = Visibility.Hidden;
            this.Children.Add(this.selectionRectangle);

            this.testLabel                     = new Label();
            this.testLabel.Foreground          = Brushes.White;
            this.testLabel.FontSize            = 20;
            this.testLabel.HorizontalAlignment = HorizontalAlignment.Left;
            this.testLabel.VerticalAlignment   = VerticalAlignment.Center;
            this.Children.Add(this.testLabel);

            this.clip = 1;
            this.slab = 0;
            this.UpdateClipping();
        }
 public static IObservable <EventPattern <MouseEventArgs> > MouseEnterObserver(this Viewport3D This)
 {
     return(Observable.FromEventPattern <MouseEventHandler, MouseEventArgs>(h => This.MouseEnter += h, h => This.MouseEnter -= h));
 }
Esempio n. 23
0
        public void DrawCloud(int[] distancepixel)
        {
            DirectionalLight DirLight1 =
                new DirectionalLight();

            DirLight1.Color     = Colors.White;
            DirLight1.Direction =
                new Vector3D(1, 1, 1);
            PerspectiveCamera Camera1 =
                new PerspectiveCamera();

            Camera1.FarPlaneDistance  = 8000;
            Camera1.NearPlaneDistance = 100;
            Camera1.FieldOfView       = 10;
            Camera1.Position          =
                new Point3D(160, 120, -1000);
            Camera1.LookDirection =
                new Vector3D(0, 0, 1);
            Camera1.UpDirection =
                new Vector3D(0, -1, 0);


            Model3DGroup modelGroup = new Model3DGroup();

            int i = 0;

            for (int y = 0; y < 480; y += s)
            {
                for (int x = 0; x < 640; x += s)
                {
                    points[i]           = Triangle(x, y, s);
                    points[i].Transform =
                        new TranslateTransform3D(0, 0, 0);
                    modelGroup.Children.Add(points[i]);
                    i++;
                }
            }

            ModelVisual3D modelsVisual = new ModelVisual3D();

            modelsVisual.Content = modelGroup;
            Viewport3D myViewport = new Viewport3D();

            myViewport.IsHitTestVisible = false;
            myViewport.Camera           = Camera1;
            myViewport.Children.Add(modelsVisual);
            canvas1.Children.Add(myViewport);
            myViewport.Height = canvas1.Height;
            myViewport.Width  = canvas1.Width;
            Canvas.SetTop(myViewport, 0);
            Canvas.SetLeft(myViewport, 0);
            MainWindow mwin = new MainWindow();

            i = 0;
            for (int y = 0; y < 480; y += s)
            {
                for (int x = 0; x < 640; x += s)
                {
                    // if(mwin.depthframe != null)
                    ((TranslateTransform3D)
                     points[i].Transform).OffsetZ = distancepixel[i];
                    i++;
                }
            }
        }
 public static IObservable <EventPattern <DataTransferEventArgs> > SourceUpdatedObserver(this Viewport3D This)
 {
     return(Observable.FromEventPattern <EventHandler <DataTransferEventArgs>, DataTransferEventArgs>(h => This.SourceUpdated += h, h => This.SourceUpdated -= h));
 }
Esempio n. 25
0
 private void CreateViewport()
 {
     _viewport       = ResourceManager.Get <Viewport3D>("3DViewport_Interactive");
     _modelContainer = LocateModelContainer();
     _modelContainer.MouseLeftButtonDown += ModelContainer_MouseLeftButtonDown;
 }
 public static IObservable <EventPattern <StylusEventArgs> > PreviewStylusInAirMoveObserver(this Viewport3D This)
 {
     return(Observable.FromEventPattern <StylusEventHandler, StylusEventArgs>(h => This.PreviewStylusInAirMove += h, h => This.PreviewStylusInAirMove -= h));
 }
Esempio n. 27
0
        private FrameworkElement CreateVisualChild()
        {
            MeshGeometry3D meshGeometry3D = new MeshGeometry3D()
            {
                Positions          = new Point3DCollection(Planerator.Mesh),
                TextureCoordinates = new PointCollection(Planerator.TexCoords),
                TriangleIndices    = new Int32Collection(Planerator.Indices)
            };
            Material diffuseMaterial = new DiffuseMaterial(Brushes.White);

            diffuseMaterial.SetValue(Viewport2DVisual3D.IsVisualHostMaterialProperty, (object)true);
            VisualBrush visualBrush = new VisualBrush(this._logicalChild);

            this.SetCachingForObject(visualBrush);
            Material material = new DiffuseMaterial(visualBrush);

            this._rotationTransform.Rotation = this._quaternionRotation;
            Transform3DGroup transform3DGroup = new Transform3DGroup();

            transform3DGroup.Children.Add(this._scaleTransform);
            transform3DGroup.Children.Add(this._rotationTransform);
            Transform3DGroup transform3DGroup1 = transform3DGroup;
            GeometryModel3D  geometryModel3D   = new GeometryModel3D()
            {
                Geometry     = meshGeometry3D,
                Transform    = transform3DGroup1,
                BackMaterial = material
            };
            Model3DGroup model3DGroup = new Model3DGroup();

            model3DGroup.Children.Add(new DirectionalLight(Colors.White, new Vector3D(0, 0, -1)));
            model3DGroup.Children.Add(new DirectionalLight(Colors.White, new Vector3D(0.1, -0.1, 1)));
            model3DGroup.Children.Add(geometryModel3D);
            ModelVisual3D modelVisual3D = new ModelVisual3D()
            {
                Content = model3DGroup
            };

            if (this._frontModel != null)
            {
                this._frontModel.Visual = null;
            }
            this._frontModel = new Viewport2DVisual3D()
            {
                Geometry  = meshGeometry3D,
                Visual    = this._logicalChild,
                Material  = diffuseMaterial,
                Transform = transform3DGroup1
            };
            this.SetCachingForObject(this._frontModel);
            Viewport3D viewport3D = new Viewport3D()
            {
                ClipToBounds = false
            };

            viewport3D.Children.Add(modelVisual3D);
            viewport3D.Children.Add(this._frontModel);
            this._viewport3D = viewport3D;
            this.UpdateRotation();
            return(this._viewport3D);
        }
 public static IObservable <EventPattern <StylusEventArgs> > StylusOutOfRangeObserver(this Viewport3D This)
 {
     return(Observable.FromEventPattern <StylusEventHandler, StylusEventArgs>(h => This.StylusOutOfRange += h, h => This.StylusOutOfRange -= h));
 }
Esempio n. 29
0
 public override List <VMPoint> GetVerticesAtPoint(int x, int y, Viewport3D viewport)
 {
     return(MainTool.GetVerticesAtPoint(x, y, viewport));
 }
 public static IObservable <EventPattern <StylusEventArgs> > LostStylusCaptureObserver(this Viewport3D This)
 {
     return(Observable.FromEventPattern <StylusEventHandler, StylusEventArgs>(h => This.LostStylusCapture += h, h => This.LostStylusCapture -= h));
 }
Esempio n. 31
0
 public override void Render3D(Viewport3D viewport)
 {
 }
 public static IObservable <EventPattern <StylusButtonEventArgs> > StylusButtonUpObserver(this Viewport3D This)
 {
     return(Observable.FromEventPattern <StylusButtonEventHandler, StylusButtonEventArgs>(h => This.StylusButtonUp += h, h => This.StylusButtonUp -= h));
 }
 protected virtual void BeginTransition3D(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport)
 {
     EndTransition(transitionElement, oldContent, newContent);
 }
Esempio n. 34
0
		public override void Render(Viewport3D viewport, Matrix renderMatrix)
		{
			this.SetImageUrl();
			PrimitivesManager.Instance.AddPrimitive(this._image);
		}
Esempio n. 35
0
 public CubeDrawer(Viewport3D gvp, FusionVolume fv)
 {
     vol  = fv;
     _gvp = gvp;
     this.CreateCube3DGraphics(volumeCubeLineColor, LineThickness, new Vector3D(0, 0, 0));
 }