예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        public MainViewModel()
        {
            // Create a model group
            var modelGroup = new Model3DGroup();

            // Create a mesh builder and add a box to it
            var meshBuilder = new MeshBuilder(false, false);

            meshBuilder.AddSphere(new Point3D(0, 0, 0), 0.5);

            // Create a mesh from the builder (and freeze it)
            var mesh = meshBuilder.ToMesh(true);


            var blueMaterial   = MaterialHelper.CreateMaterial(Colors.Blue);
            var insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow);
            var greyMaterial   = MaterialHelper.CreateMaterial(Colors.LightGray);

            List <TranslateTransform3D> transformations = GetAllSheres();


            transformations.ForEach(
                f =>
                modelGroup.Children.Add(new GeometryModel3D
            {
                Geometry     = mesh,
                Transform    = f,
                Material     = blueMaterial,
                BackMaterial = insideMaterial
            }));

            // Set the property, which will be bound to the Content property of the ModelVisual3D (see MainWindow.xaml)
            this.Model = modelGroup;

            Thread t = new Thread(Do);

            t.Start();

            //Do();
        }
예제 #2
0
        // Define the model.
        private void DefineModel(Model3DGroup group)
        {
            //// Verify the dodecahedron calculations.
            //MeshExtensions.VerifyDodecahedron();

            // Show the axes.
            MeshExtensions.AddAxes(group);

            const double scale = 1.25;

            // Make a solid insphere.
            MeshGeometry3D mesh1 = new MeshGeometry3D();

            mesh1.AddSphere(D3.Origin, G3.DodecahedronInradius(), 60, 30, true);
            mesh1.ApplyTransformation(new ScaleTransform3D(scale, scale, scale));
            group.Children.Add(mesh1.MakeModel(Brushes.Red));

            // Make a translucent dodecahedron.
            MeshGeometry3D mesh2 = new MeshGeometry3D();

            mesh2.AddDodecahedron();
            mesh2.ApplyTransformation(new ScaleTransform3D(scale, scale, scale));
            Brush         brush  = new SolidColorBrush(Color.FromArgb(128, 128, 255, 128));
            MaterialGroup group2 = D3.MakeMaterialGroup(
                new DiffuseMaterial(brush),
                new SpecularMaterial(Brushes.White, 100));

            group.Children.Add(mesh2.MakeModel(group2));

            // Make a translucent circumsphere.
            MeshGeometry3D mesh3 = new MeshGeometry3D();

            mesh3.AddSphere(D3.Origin, G3.DodecahedronCircumradius(), 60, 30, true);
            mesh3.ApplyTransformation(new ScaleTransform3D(scale, scale, scale));
            MaterialGroup group3 = D3.MakeMaterialGroup(
                new DiffuseMaterial(brush),
                new SpecularMaterial(Brushes.White, 100));

            group.Children.Add(mesh3.MakeModel(group3));
        }
예제 #3
0
        /// <summary>
        /// Helper method that creates and textures a quad fromt he given points.
        /// </summary>
        public static Model3DGroup CreateQuad(Point3D topLeft, Point3D topRight,
                                              Point3D botRight, Point3D botLeft, Material material)
        {
            MeshGeometry3D mesh = new MeshGeometry3D();

            mesh.Positions.Add(topLeft);
            mesh.Positions.Add(topRight);
            mesh.Positions.Add(botRight);
            mesh.Positions.Add(botLeft);

            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(1);
            mesh.TriangleIndices.Add(2);

            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(2);
            mesh.TriangleIndices.Add(3);

            //Set the texture to cover the quad.
            mesh.TextureCoordinates.Add(new Point(0, 1));
            mesh.TextureCoordinates.Add(new Point(1, 1));
            mesh.TextureCoordinates.Add(new Point(1, 0));
            mesh.TextureCoordinates.Add(new Point(0, 0));

            Vector3D normal = CalculateNormal(topLeft, topRight, botRight);

            mesh.Normals.Add(normal);
            mesh.Normals.Add(normal);
            mesh.Normals.Add(normal);
            mesh.Normals.Add(normal);
            mesh.Normals.Add(normal);
            mesh.Normals.Add(normal);

            GeometryModel3D model = new GeometryModel3D(
                mesh, material);
            Model3DGroup quad = new Model3DGroup();

            quad.Children.Add(model);
            return(quad);
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        public MainViewModel()
        {
            // Create a model group
            var modelGroup = new Model3DGroup();

            // Create a mesh builder and add a box to it
            var meshBuilder = new MeshBuilder(false, false);

            meshBuilder.AddBox(new Point3D(0, 0, 1), 1, 2, 0.5);
            meshBuilder.AddBox(new Rect3D(0, 0, 1.2, 0.5, 1, 0.4));



            // Create a mesh from the builder (and freeze it)
            var mesh = meshBuilder.ToMesh(true);

            var meshBuilder1 = new MeshBuilder(false, false);

            meshBuilder1.AddCylinder(new Point3D(-10, 20, 0), new Point3D(10, 10, 0), 0.05);

            var mesh1 = meshBuilder1.ToMesh(true);

            // Create some materials
            var greenMaterial  = MaterialHelper.CreateMaterial(Colors.Green);
            var redMaterial    = MaterialHelper.CreateMaterial(Colors.Red);
            var blueMaterial   = MaterialHelper.CreateMaterial(Colors.Blue);
            var insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow);

            // Add 3 models to the group (using the same mesh, that's why we had to freeze it)
            //modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Material = greenMaterial, BackMaterial = insideMaterial });
            //modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(-2, 0, 0), Material = redMaterial, BackMaterial = insideMaterial });
            //modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(2, 0, 0), Material = blueMaterial, BackMaterial = insideMaterial });

            modelGroup.Children.Add(new GeometryModel3D {
                Geometry = mesh1, Material = redMaterial, BackMaterial = insideMaterial
            });

            // Set the property, which will be bound to the Content property of the ModelVisual3D (see MainWindow.xaml)
            this.Model = modelGroup;
        }
예제 #5
0
        // Make an outwardly-oriented square with texture.
        private void MakeRectangle(Model3DGroup model_group, Material model_material,
                                   Point3D pt0, Point3D pt1, Point3D pt2, Point3D pt3,
                                   Point u0, Point u1, Point u2, Point u3)
        {
            // Define the new mesh geometry.
            MeshGeometry3D new_mesh = new MeshGeometry3D();

            // Define the corner points.
            Point3D [] pt3Ds =
            {
                new Point3D(pt0.X, pt0.Y, pt0.Z),
                new Point3D(pt1.X, pt1.Y, pt1.Z),
                new Point3D(pt2.X, pt2.Y, pt2.Z),
                new Point3D(pt3.X, pt3.Y, pt3.Z)
            };
            new_mesh.Positions = new Point3DCollection(pt3Ds);

            // Define which points make up the triangles.
            new_mesh.TriangleIndices = new Int32Collection();
            new_mesh.TriangleIndices.Add(0);
            new_mesh.TriangleIndices.Add(1);
            new_mesh.TriangleIndices.Add(2);

            new_mesh.TriangleIndices.Add(0);
            new_mesh.TriangleIndices.Add(2);
            new_mesh.TriangleIndices.Add(3);

            // Set the texture coordinates.
            new_mesh.TextureCoordinates = new PointCollection();
            new_mesh.TextureCoordinates.Add(u0);
            new_mesh.TextureCoordinates.Add(u1);
            new_mesh.TextureCoordinates.Add(u2);
            new_mesh.TextureCoordinates.Add(u3);

            // Set the model's material.
            GeometryModel3D new_model = new GeometryModel3D(new_mesh, model_material);

            // Add the new model to the model group.
            model_group.Children.Add(new_model);
        }
        // Add the model to the Model3DGroup.
        private void DefineModel(Model3DGroup modelGroup, int t)
        {
            // Define lights.
            DefineLights();
            // Make a mesh to hold the surface.
            var mesh = new MeshGeometry3D();

            for (int i = 0; i < x.Length - 1; ++i)
            {
                for (int j = 0; j < z.Length - 1; ++j)
                {
                    // Make points at the corners of the surface
                    // over (x, z) - (x + dx, z + dz).

                    var p00 = new Point3D(x[i], psi[i][j].Magnitude, z[j]);
                    var p10 = new Point3D(x[i + 1], psi[i + 1][j].Magnitude, z[j]);
                    var p01 = new Point3D(x[i], psi[i][j + 1].Magnitude, z[j + 1]);
                    var p11 = new Point3D(x[i + 1], psi[i + 1][j + 1].Magnitude, z[j + 1]);

                    // Add the triangles.
                    AddTriangle(mesh, p00, p01, p11);
                    AddTriangle(mesh, p00, p11, p10);
                }
            }

            Console.WriteLine(mesh.Positions.Count + " points");
            Console.WriteLine(mesh.TriangleIndices.Count / 3 + " triangles");

            // Make the surface's material using a solid orange brush.
            var surfaceMaterial = new DiffuseMaterial(Brushes.Orange);

            // Make the mesh's model. Make the surface visible from both sides.
            var surfaceModel = new GeometryModel3D(mesh, surfaceMaterial)
            {
                BackMaterial = surfaceMaterial
            };

            // Add the model to the model groups.
            modelGroup.Children.Add(surfaceModel);
        }
예제 #7
0
        public void Init()
        {
            // Create a model group
            modelGroup = new Model3DGroup();

            // Create a mesh builder and add a box to it
            MeshBuilder meshBuilder = new MeshBuilder(false, false);

            //meshBuilder.AddBox(new Point3D(0, 0, 1), 1, 2, 0.5);
            //meshBuilder.AddBox(new Rect3D(0, 0, 1.2, 0.5, 1, 0.4));
            meshBuilder.AddEllipsoid(new Point3D(1, 1, 1), 2, 2, 2);

            //meshBuilder.AddArrow(new Point3D(0,0,0),new Point3D(10,10,10),2  );

            // Create a mesh from the builder (and freeze it)
            var mesh = meshBuilder.ToMesh(true);

            // Create some materials
            greenMaterial  = MaterialHelper.CreateMaterial(Colors.Green);
            redMaterial    = MaterialHelper.CreateMaterial(Colors.Red);
            blueMaterial   = MaterialHelper.CreateMaterial(Colors.Blue);
            insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow);

            materialBuffer.Add(Colors.Green, greenMaterial);
            materialBuffer.Add(Colors.Red, redMaterial);
            materialBuffer.Add(Colors.Blue, blueMaterial);
            materialBuffer.Add(Colors.Yellow, insideMaterial);

            // Add 3 models to the group (using the same mesh, that's why we had to freeze it)
            modelGroup.Children.Add(new GeometryModel3D {
                Geometry = mesh, Material = greenMaterial, Transform = new TranslateTransform3D(0, 0, 0), BackMaterial = insideMaterial
            });
            //modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(-2, 0, 0), Material = redMaterial, BackMaterial = insideMaterial });
            //modelGroup.Children.Add(new GeometryModel3D { Geometry = mesh, Transform = new TranslateTransform3D(2, 0, 0), Material = blueMaterial, BackMaterial = insideMaterial });

            // Set the property, which will be bound to the Content property of the ModelVisual3D (see MainWindow.xaml)
            this.Model = modelGroup;

            defaultMaterial = blueMaterial;
        }
예제 #8
0
        private async void DrawGraph(int[][] array)
        {
            Random rnd = new Random();

            NodeCord = new Point3D[array.Length];
            int numberOfNode = 0;

            for (int i = 0; i < array.Length; i++)
            {
                for (int j = i; j < array.Length; j++)
                {
                    if (array[i][j] == 1)
                    {
                        numberOfNode++;
                    }
                }
            }

            for (int i = 0; i < array.Length; i++)
            {
                NodeCord[i] = new Point3D(rnd.NextDouble(), rnd.NextDouble(), rnd.NextDouble());
            }

            //for (int i = 0; i < array.Length; i++)
            //    for (int j = i; j < array.Length; j++)
            //        if (array[i][j] == 1)
            //            GraphDrawCanvas.Children.Add(await Draw.DrawEdge(NodeCord[i], NodeCord[j]));

            for (int i = 0; i < array.Length; i++)
            {
                Model3DGroup model3DGroup = new Model3DGroup();
                DefineModel(model3DGroup, NodeCord[i]);
                ModelVisual3D modelVisual = new ModelVisual3D
                {
                    Content = model3DGroup
                };

                Viewport3D.Children.Add(modelVisual);
            }
        }
        // Define the model.
        private void DefineModel(Model3DGroup group)
        {
            // Axes.
            //MeshExtensions.AddAxes(group);

            // Make a line graph.
            double[,] values = LoadData();
            string[]     xlabels       = { "Jan", "Feb", "Mar", "Apr", "May" };
            string[]     ylabels       = { "0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100" };
            string[]     zlabels       = { "Prod 4", "Prod 3", "Prod 2", "Prod 1" };
            Brush[]      valuesBrushes = { Brushes.Red, Brushes.Green, Brushes.Blue, Brushes.Yellow };
            const double labelGap      = 0.25;
            const double labelWid      = 2;
            const double labelHgt      = 0.75;
            const double labelFontSize = 0.6;
            const double titleHgt      = 1.5;
            const double titleFontSize = 0.7;
            const double yoff          = 1;

            MakeLineGraph(group,
                          values, valuesBrushes,
                          new Point3D(-4, -4 + yoff, -2), 8, 8, 4,
                          0.05, 0.04, 0.1,
                          Brushes.Blue, Brushes.LightBlue, Brushes.Red,
                          labelWid, labelHgt, labelGap, labelFontSize, Brushes.DarkBlue,
                          titleHgt, titleFontSize, Brushes.Black,
                          0, 4, 1, 1, "Month", xlabels,
                          0, 100, 10, 10, "Units Sold", ylabels,
                          0, 3, 1, 1, "Product", zlabels);

            // Title.
            FontFamily ff       = new FontFamily("Franklin Gothic Demi");
            Point3D    ll       = new Point3D(-4, 4 + yoff, -2);
            double     fontSize = 1.1;

            MakeLabel("Monthly Sales", ll,
                      new Vector3D(8, 0, 0), D3.YVector(1.25),
                      Brushes.Transparent, Brushes.Black, fontSize, ff,
                      HorizontalAlignment.Center, VerticalAlignment.Center, group);
        }
예제 #10
0
        // Define the model.
        private void DefineModel(Model3DGroup group)
        {
            // Make the ground.
            MeshGeometry3D groundMesh = new MeshGeometry3D();
            const double   wid        = 10;

            groundMesh.Positions.Add(new Point3D(-wid, 0, -wid));
            groundMesh.Positions.Add(new Point3D(-wid, 0, +wid));
            groundMesh.Positions.Add(new Point3D(+wid, 0, +wid));
            groundMesh.Positions.Add(new Point3D(+wid, 0, -wid));
            groundMesh.TriangleIndices.Add(0);
            groundMesh.TriangleIndices.Add(1);
            groundMesh.TriangleIndices.Add(2);
            groundMesh.TriangleIndices.Add(0);
            groundMesh.TriangleIndices.Add(2);
            groundMesh.TriangleIndices.Add(3);
            DiffuseMaterial groundMaterial = new DiffuseMaterial(Brushes.DarkGray);
            GeometryModel3D groundModel    = new GeometryModel3D(groundMesh, groundMaterial);

            group.Children.Add(groundModel);

            // Make some cubes.
            for (int x = -2; x <= 2; x += 2)
            {
                for (int z = -2; z <= 2; z += 2)
                {
                    MeshGeometry3D mesh = MakeCubeMesh(x, 0.5, z, 1);

                    byte            r        = (byte)(128 + x * 50);
                    byte            g        = (byte)(128 + z * 50);
                    byte            b        = (byte)(128 + x * 50);
                    Color           color    = Color.FromArgb(255, r, g, b);
                    DiffuseMaterial material = new DiffuseMaterial(
                        new SolidColorBrush(color));

                    GeometryModel3D model = new GeometryModel3D(mesh, material);
                    group.Children.Add(model);
                }
            }
        }
예제 #11
0
        private Model3DGroup ConstructAnnotationArrow(Point3D origin, Vector3D direction, Model3DGroup parent)
        {
            Model3DGroup     wholearrow = ((Model3DGroup)FindResource("M3DG_ArrowAtOrigin")).Clone();
            Transform3DGroup t3dgr      = new Transform3DGroup();

            wholearrow.Transform = t3dgr;
            t3dgr.Children.Add((Transform3D)FindResource("TRANSFORM_Arrow"));

            // Step 1: use the Z component of the normal to rotate around Y axis
            //         to determine the vector location in the XZ plane.
            double angleFromZaxis = 90 - ((180.0 / Math.PI) * Math.Asin(direction.Z));

            t3dgr.Children.Add(
                new RotateTransform3D(
                    new AxisAngleRotation3D(new Vector3D(0, 1, 0), angleFromZaxis)));

            // Step 2: use the X and Y components to rotate around the Z axis.
            double adjustment = 0;

            if (direction.X == 0)
            {
                direction.X = 0.0000001;
            }
            if (direction.X < 0)
            {
                adjustment = 180;
            }

            double angle = adjustment + (Math.Atan(direction.Y / direction.X) * 180.0 / Math.PI);

            t3dgr.Children.Add(
                new RotateTransform3D(
                    new AxisAngleRotation3D(new Vector3D(0, 0, 1), angle)));

            t3dgr.Children.Add(new TranslateTransform3D(
                                   origin.X, origin.Y, origin.Z));
            parent.Children.Add(wholearrow);

            return(wholearrow);
        }
예제 #12
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private Model3DGroup CreateFloor()
        {
            Model3DGroup modelGroup      = new Model3DGroup();
            List <int>   ignorepositions = new List <int>();

            Random rand = new Random();

            for (int k = 0; k < 150; k++)
            {
                //ignorepositions.Add( rand.Next()% (6 *6 * 6) );
            }

            int xfactor = 5;
            int yfactor = 0;
            int zfactor = 5;
            int counter = 0;
            int space   = 15;

            /// this.ViewPort3d.Children.Add(Circuit.CircuitBox(0 , 0 , 0 , 10));
            for (int i = -1 * xfactor; i <= 1 * xfactor; i++)
            {
                ///  for (int j = 0; j <= 0; j++)
                //for (int j = -1 * yfactor; j <= 1 * yfactor; j++)
                {
                    for (int k = -1 * zfactor; k <= 1 * zfactor + 1; k++)
                    {
                        if (!ignorepositions.Contains(counter++))
                        {
                            this.CreateTile(space * i, space * this.Level, space * k, 14, ref modelGroup);
                        }
                        //this.ViewPort3d.Children.Add(Circuit.CircuitBox(-20*i, 0, 0, 10));
                        //this.ViewPort3d.Children.Add(Circuit.CircuitBox(0*i, 0, 0, 10));
                        //this.ViewPort3d.Children.Add(Circuit.CircuitBox(20*i, 0, 0, 10));
                        //this.ViewPort3d.Children.Add(Circuit.CircuitBox(40*i, 0, 0, 10));
                    }
                }
            }

            return(modelGroup);
        }
예제 #13
0
        // Make a row of bars in the X direction.
        private void MakeBars(double xmin, double ymin,
                              double zmin, double dx, double gap,
                              double[] values, string[] frontLabels, string[] topLabels,
                              Brush[] barBrushes, Brush[] bgBrushes, Brush[] fgBrushes,
                              FontFamily ff, Model3DGroup group)
        {
            double x        = xmin;
            double fontSize = 0.4;

            for (int i = 0; i < values.Length; i++)
            {
                // Make the bar.
                MeshGeometry3D barMesh = new MeshGeometry3D();
                Point3D        corner  = new Point3D(x, ymin, zmin);
                barMesh.AddBox(corner,
                               D3.XVector(dx),
                               D3.YVector(YScale * values[i]),
                               D3.ZVector(dx));
                group.Children.Add(barMesh.MakeModel(barBrushes[i]));

                // Display the front label.
                const double textWid = 1.8;
                MakeLabel(frontLabels[i],
                          new Point3D(x + dx, ymin, textWid + zmin + dx + gap),
                          D3.ZVector(-textWid), D3.XVector(-dx),
                          bgBrushes[i], fgBrushes[i], fontSize, ff,
                          HorizontalAlignment.Left, VerticalAlignment.Center, group);

                // Display the top label.
                MakeLabel(topLabels[i],
                          new Point3D(x,
                                      ymin + YScale * values[i],
                                      zmin - 0.1),
                          D3.XVector(dx), D3.YVector(dx),
                          Brushes.Transparent, fgBrushes[i], fontSize, ff,
                          HorizontalAlignment.Center, VerticalAlignment.Bottom, group);

                x += dx + gap;
            }
        }
예제 #14
0
        private RotateTransform3D rotationTransform;     // Матрица вращения
        public MyModel3D(Model3DGroup models, double x, double y, double z, string path, Size size, float axis_x = 0, double angle = 0, float axis_y = 0, float axis_z = 1)
        {
            this.Size     = size;
            this.Position = new Vector3D(x, y, z);
            MeshGeometry3D mesh = new MeshGeometry3D();

            // Проставляем вершины квадрату
            mesh.Positions = new Point3DCollection(new List <Point3D>
            {
                new Point3D(-size.Width / 2, -size.Height / 2, 0),
                new Point3D(size.Width / 2, -size.Height / 2, 0),
                new Point3D(size.Width / 2, size.Height / 2, 0),
                new Point3D(-size.Width / 2, size.Height / 2, 0)
            });
            // Указываем индексы для квадрата
            mesh.TriangleIndices = new Int32Collection(new List <int> {
                0, 1, 2, 0, 2, 3
            });
            mesh.TextureCoordinates = new PointCollection();
            // Устанавливаем текстурные координаты чтоб потом могли натянуть текстуру
            mesh.TextureCoordinates.Add(new Point(0, 1));
            mesh.TextureCoordinates.Add(new Point(1, 1));
            mesh.TextureCoordinates.Add(new Point(1, 0));
            mesh.TextureCoordinates.Add(new Point(0, 0));

            // Натягиваем текстуру
            ImageBrush      brush         = new ImageBrush(new BitmapImage(new Uri(path)));
            Material        material      = new DiffuseMaterial(brush);
            GeometryModel3D geometryModel = new GeometryModel3D(mesh, material);

            models.Children.Add(geometryModel);
            translateTransform = new TranslateTransform3D(x, y, z);
            rotationTransform  = new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(axis_x, axis_y, axis_z), angle), 0.5, 0.5, 0.5);

            Transform3DGroup tgroup = new Transform3DGroup();

            tgroup.Children.Add(translateTransform);
            tgroup.Children.Add(rotationTransform);
            geometryModel.Transform = tgroup;
        }
예제 #15
0
        private Model3DGroup groupDrawCover(Point3D orgin, Size3D size, Uri col)
        {
            //duł klosza
            Point3D A1 = new Point3D((orgin.X) * 4, (orgin.Y + size.Y / 5), (orgin.Z - size.Z / 2) * 4);              //A
            Point3D B1 = new Point3D((orgin.X + size.X / 2) * 4, (orgin.Y + size.Y / 5), (orgin.Z - size.Z / 4) * 4); //B
            Point3D C1 = new Point3D((orgin.X + size.X / 2) * 4, (orgin.Y + size.Y / 5), (orgin.Z + size.Z / 4) * 4); //C
            Point3D D1 = new Point3D((orgin.X) * 4, (orgin.Y + size.Y / 5), (orgin.Z + size.Z / 2) * 4);              //D
            Point3D E1 = new Point3D((orgin.X - size.X / 2) * 4, (orgin.Y + size.Y / 5), (orgin.Z + size.Z / 4) * 4); //E
            Point3D F1 = new Point3D((orgin.X - size.X / 2) * 4, (orgin.Y + size.Y / 5), (orgin.Z - size.Z / 4) * 4); //F

            //góra klosza
            Point3D A2 = new Point3D((orgin.X) * 2, (orgin.Y + size.Y / 2), (orgin.Z - size.Z / 2) * 2);              //A'
            Point3D B2 = new Point3D((orgin.X + size.X / 2) * 2, (orgin.Y + size.Y / 2), (orgin.Z - size.Z / 4) * 2); //B'
            Point3D C2 = new Point3D((orgin.X + size.X / 2) * 2, (orgin.Y + size.Y / 2), (orgin.Z + size.Z / 4) * 2); //C'
            Point3D D2 = new Point3D((orgin.X) * 2, (orgin.Y + size.Y / 2), (orgin.Z + size.Z / 2) * 2);              //D'
            Point3D E2 = new Point3D((orgin.X - size.X / 2) * 2, (orgin.Y + size.Y / 2), (orgin.Z + size.Z / 4) * 2); //E'
            Point3D F2 = new Point3D((orgin.X - size.X / 2) * 2, (orgin.Y + size.Y / 2), (orgin.Z - size.Z / 4) * 2); //F'


            //GeometryModel3D model1 = meth.rectangleModel(A1, B1, B2, A2, col);
            GeometryModel3D model1 = meth.rectangleModel(A2, B2, B1, A1, col);
            GeometryModel3D model2 = meth.rectangleModel(B2, C2, C1, B1, col);
            GeometryModel3D model3 = meth.rectangleModel(C2, D2, D1, C1, col);
            GeometryModel3D model4 = meth.rectangleModel(D2, E2, E1, D1, col);
            GeometryModel3D model5 = meth.rectangleModel(E2, F2, F1, E1, col);
            GeometryModel3D model6 = meth.rectangleModel(F2, A2, A1, F1, col);


            Model3DGroup group = new Model3DGroup();

            group.Children.Add(model1); //prawy tył
            group.Children.Add(model2); //prawa
            group.Children.Add(model3); //prawy przód
            group.Children.Add(model4); //lewy przód
            group.Children.Add(model5); //lewa
            group.Children.Add(model6); //lewa tył

            return(group);
        }
예제 #16
0
        private void cubeButtonClick(object sender, RoutedEventArgs e)
        {
            ClearViewport();
            SetCamera();

            Model3DGroup cube = new Model3DGroup();
            Point3D      p0   = new Point3D(0, 0, 0);
            Point3D      p1   = new Point3D(5, 0, 0);
            Point3D      p2   = new Point3D(5, 0, 5);
            Point3D      p3   = new Point3D(0, 0, 5);
            Point3D      p4   = new Point3D(0, 5, 0);
            Point3D      p5   = new Point3D(5, 5, 0);
            Point3D      p6   = new Point3D(5, 5, 5);
            Point3D      p7   = new Point3D(0, 5, 5);

            //front side triangles
            cube.Children.Add(CreateTriangleModel(p3, p2, p6));
            cube.Children.Add(CreateTriangleModel(p3, p6, p7));
            //right side triangles
            cube.Children.Add(CreateTriangleModel(p2, p1, p5));
            cube.Children.Add(CreateTriangleModel(p2, p5, p6));
            //back side triangles
            cube.Children.Add(CreateTriangleModel(p1, p0, p4));
            cube.Children.Add(CreateTriangleModel(p1, p4, p5));
            //left side triangles
            cube.Children.Add(CreateTriangleModel(p0, p3, p7));
            cube.Children.Add(CreateTriangleModel(p0, p7, p4));
            //top side triangles
            cube.Children.Add(CreateTriangleModel(p7, p6, p5));
            cube.Children.Add(CreateTriangleModel(p7, p5, p4));
            //bottom side triangles
            cube.Children.Add(CreateTriangleModel(p2, p3, p0));
            cube.Children.Add(CreateTriangleModel(p2, p0, p1));

            ModelVisual3D model = new ModelVisual3D();

            model.Content = cube;
            this.mainViewport.Children.Add(model);
        }
        private void SetupBooksReadByCountryModel()
        {
            Model3DGroup modelGroup = new Model3DGroup();

            // get the range of colours for the for the countries
            int range = _mainModel.AuthorCountries.Count > 0 ?
                        _mainModel.AuthorCountries.Select(s => s.TotalBooksReadFromCountry).Max() : 5;
            OxyPalette      faintPalette;
            List <OxyColor> colors;

            OxyPlotUtilities.SetupFaintPaletteForRange(range, out colors, out faintPalette, 128);

            List <OxyColor> stdColors      = OxyPlotUtilities.SetupStandardColourSet();
            int             geographyIndex = 0;

            foreach (var authorCountry in _mainModel.AuthorCountries.OrderByDescending(x => x.TotalBooksReadFromCountry))
            {
                var name    = authorCountry.Country;
                var country = _mainModel.WorldCountries.Where(w => w.Country == name).FirstOrDefault();
                if (country != null)
                {
                    AddCountryBooksEllipsoid(modelGroup, colors, authorCountry, name, country);
                }

                if (_mainModel.CountryGeographies != null && _mainModel.CountryGeographies.Count > 0)
                {
                    geographyIndex = AddCountryGeographyPlane(modelGroup, stdColors, geographyIndex, name);
                }
            }

            AddGeographiesForCountriesWithoutBooksRead(modelGroup);

            double       maxHeight = Math.Log(range);
            TubeVisual3D path      = GetPathForMeanReadingLocation(maxHeight);

            modelGroup.Children.Add(path.Content);

            BooksReadByCountryModel = modelGroup;
        }
예제 #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        public MainViewModel()
        {
            // Create a model group
            Model3DGroup modelGroup = new Model3DGroup();

            // Create a mesh builder and add a box to it
            MeshBuilder meshBuilder = new MeshBuilder(false, false);

            CreateSimpleTriangulatedMesh(meshBuilder);

            // Create a mesh from the builder (and freeze it)
            MeshGeometry3D mesh = meshBuilder.ToMesh(true);

            // Create some materials
            Material blueMaterial   = MaterialHelper.CreateMaterial(Colors.Blue);
            Material insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow);

            modelGroup.Children.Add(new GeometryModel3D {
                Geometry = mesh, Material = blueMaterial, BackMaterial = insideMaterial
            });
            Model = modelGroup;
        }
예제 #19
0
        private Model3DGroup create3dmodel(List <Point3D> list)
        {
            var         modelGroup = new Model3DGroup();
            MeshBuilder msh        = new MeshBuilder();

            for (int k = 0; k < list.Count; k++)
            {
                msh.AddBox(list[k], 0.1, 0.1, 0.1);
            }
            var gm             = new GeometryModel3D();
            var mesh           = msh.ToMesh(true);
            var greenMaterial  = MaterialHelper.CreateMaterial(Colors.Green);
            var insideMaterial = MaterialHelper.CreateMaterial(Colors.Yellow);

            modelGroup.Children.Add(new GeometryModel3D
            {
                Geometry     = mesh,
                Material     = greenMaterial,
                BackMaterial = insideMaterial
            });
            return(modelGroup);
        }
        /// <summary>
        /// Create a visible model of the STL file
        /// </summary>
        /// <param name="filename">The STL file with full extension</param>
        public void ViewNewStl(string filename)
        {
            // WTF!! No file
            if (!File.Exists(filename))
            {
                return;
            }

            // Check the file extension to be STL
            FileInfo fileInfo = new FileInfo(filename);

            if (fileInfo.Extension.ToLower() != ".stl")
            {
                return;
            }

            ModelColor = configuration.STLcolor;

            Filename = filename;

            // Create a model of the STL file



            ModelImporter modellImporter = new ModelImporter();

            modellImporter.DefaultMaterial =
                new DiffuseMaterial(
                    new SolidColorBrush((Color)ColorConverter.ConvertFromString(modellColor)));
            Model3DGroup model3DGroup = modellImporter.Load(filename);



            StlModel.Content = model3DGroup;


            myViewPort3D.CameraController.ResetCamera();
            myViewPort3D.CameraController.ZoomExtents(0);
        }
예제 #21
0
        // create the base line net on X-Z plane
        private void createLineNet(Model3DGroup model_group)
        {
            // resolution: 50mm
            // x: 0 -> 2000
            // z: -800 -> 800

            int    net_resolution = 50;
            double y_plane        = ConfigParameters.SENSOR_TO_GROUND_DISTANCE;
            double line_thickness = 1;

            double start_x = 0,
                   end_x   = 2000,
                   start_z = -800,
                   end_z   = 800;

            for (int i = (int)(start_x / net_resolution); i < end_x / net_resolution; i++)
            {
                // add label for x
                if (i % 2 == 0)
                {
                    model_group.Children.Add(createTextLabel3D((i * net_resolution).ToString(),
                                                               new SolidColorBrush(Colors.Yellow),
                                                               true,
                                                               20,
                                                               new Point3D(i * net_resolution, y_plane, end_z + 50),
                                                               new Vector3D(0, 0, 1),
                                                               new Vector3D(1, 0, 0))
                                             );
                }

                // add net
                model_group.Children.Add(getLine(new Point3D(i * net_resolution, y_plane, start_z), new Point3D(i * net_resolution, y_plane, end_z), line_thickness));
            }

            for (int i = (int)(start_z / net_resolution); i < end_z / net_resolution + 1; i++)
            {
                model_group.Children.Add(getLine(new Point3D(start_x, y_plane, i * net_resolution), new Point3D(end_x, y_plane, i * net_resolution), line_thickness));
            }
        }
예제 #22
0
        public MainWindow()
        {
            InitializeComponent();

            Model = new Model3DGroup();

            DataContext = this;

            UserData.RegisterAssembly();
            UserData.RegisterType <Material>();

            script = new Script();
            script.Globals["SceneFactory"]    = new SceneFactory(Model);
            script.Globals["MaterialFactory"] = new MaterialFactory(script);

            var text = @"red = MaterialFactory.CreateSimple('red');
                         pink = MaterialFactory.CreateSimple('pink');
                         SceneFactory.CreatePlane('ground', 10, 10, pink);
                         SceneFactory.CreateSphere('ball', 0, 0, 1, red);";

            script.DoString(text);
        }
예제 #23
0
        private void SetGeometry(string model)
        {
            Model3DGroup device = null;

            try
            {
                //Import 3D model file
                ModelImporter import = new ModelImporter();
                System.Windows.Media.Media3D.Material mat = MaterialHelper.CreateMaterial(
                    //new SolidColorBrush(Colors.SaddleBrown));
                    new SolidColorBrush(Colors.Pink));
                import.DefaultMaterial = mat;
                //Load the 3D model file
                device = import.Load(model);
            }
            catch (Exception e)
            {
                // Handle exception in case can not file 3D model
                MessageBox.Show("Exception Error : " + e.StackTrace);
            }
            Visual3DModel = device;
        }
        public void Draw(ComputedStructure structure)
        {
            var modelGroup             = new Model3DGroup();
            var meshBuilderTension     = new MeshBuilder(false, false);
            var meshBuilderCompression = new MeshBuilder(false, false);

            foreach (ComputedMember m in structure.Members)
            {
                if (m.MaxAxialForce < 0)
                {
                    meshBuilderCompression.AddCylinder(NodeToHelixPoint(m.NodeI), NodeToHelixPoint(m.NodeJ), m.ReqDim, 20); // resolution hard-coded, section parameter = radius
                }

                else
                {
                    meshBuilderTension.AddCylinder(NodeToHelixPoint(m.NodeI), NodeToHelixPoint(m.NodeJ), m.ReqDim, 20);
                }
            }


            // Create meshes from the builder (and freeze it)
            var meshTension     = meshBuilderTension.ToMesh(true);
            var meshCompression = meshBuilderCompression.ToMesh(true);

            // Create materials
            var CMaterialCompression = MaterialHelper.CreateMaterial(Colors.Red);
            var CMaterialTension     = MaterialHelper.CreateMaterial(Colors.Blue);

            // Add to modelGroup
            modelGroup.Children.Add(new GeometryModel3D {
                Geometry = meshTension, Material = CMaterialTension, BackMaterial = CMaterialTension
            });
            modelGroup.Children.Add(new GeometryModel3D {
                Geometry = meshCompression, Material = CMaterialCompression, BackMaterial = CMaterialCompression
            });

            // Assign modelGroup to Model to draw
            this.Model = modelGroup;
        }
예제 #25
0
        public static Model3DGroup createRectangleModel(Point3D[] p, Material m, bool up = true)
        {
            if (p.Length != 4)
            {
                return(null);
            }

            Model3DGroup rect = new Model3DGroup();

            if (up)
            {
                rect.Children.Add(createTriangleModel(p[0], p[1], p[2], m));
                rect.Children.Add(createTriangleModel(p[0], p[2], p[3], m));
            }
            else
            {
                rect.Children.Add(createTriangleModel(p[0], p[2], p[1], m));
                rect.Children.Add(createTriangleModel(p[0], p[3], p[2], m));
            }

            return(rect);
        }
예제 #26
0
        private Model3DGroup ThrowUpRainbow(Model3DGroup sadFloors)
        {
            ColourGenerator colourGenerator = new ColourGenerator(((Model3DGroup)sadFloors.Children[0]).Children.Count);

            for (int i = 0; i < sadFloors.Children.Count; i++)
            {
                Model3DGroup packages = new Model3DGroup();
                packages = (Model3DGroup)sadFloors.Children[i];
                for (int j = 0; j < packages.Children.Count; j++)
                {
                    Model3DGroup onePackage = new Model3DGroup();
                    onePackage = (Model3DGroup)packages.Children[j];
                    GeometryModel3D model = new GeometryModel3D();
                    model = (GeometryModel3D)onePackage.Children[0];
                    DiffuseMaterial material = new DiffuseMaterial();
                    material       = (DiffuseMaterial)model.Material;
                    material.Brush = new SolidColorBrush(colourGenerator.GetColor());
                }
            }

            return(sadFloors);
        }
예제 #27
0
        static private Model3DGroup CreateTriangleModel(Material material, Point3D p0, Point3D p1, Point3D p2)
        {
            MeshGeometry3D mesh = new MeshGeometry3D();

            mesh.Positions.Add(p0);
            mesh.Positions.Add(p1);
            mesh.Positions.Add(p2);
            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(1);
            mesh.TriangleIndices.Add(2);
            Vector3D normal = CalculateNormal(p0, p1, p2);

            mesh.Normals.Add(normal);
            mesh.Normals.Add(normal);
            mesh.Normals.Add(normal);
            GeometryModel3D model = new GeometryModel3D(
                mesh, material);
            Model3DGroup group = new Model3DGroup();

            group.Children.Add(model);
            return(group);
        }
예제 #28
0
        public void AddDots(IEnumerable <Tuple <Point3D, Color> > dots, double radius = .05, bool isShiny = true, bool isHiRes = false)
        {
            Model3DGroup geometries = new Model3DGroup();

            foreach (Tuple <Point3D, Color> dot in dots)
            {
                Material material = GetMaterial(isShiny, dot.Item2);

                GeometryModel3D geometry = new GeometryModel3D();
                geometry.Material     = material;
                geometry.BackMaterial = material;
                geometry.Geometry     = UtilityWPF.GetSphere_Ico(radius, isHiRes ? 3 : 1, true);
                geometry.Transform    = new TranslateTransform3D(dot.Item1.ToVector());

                geometries.Children.Add(geometry);
            }

            ModelVisual3D visual = new ModelVisual3D();

            visual.Content = geometries;
            _viewport.Children.Insert(_viewportOffset_Init, visual);        // put this between the lights and the labels
        }
예제 #29
0
        private Model3DGroup BuildNormals(Point3D p0, Point3D p1, Point3D p2, Vector3D normal)
        {
            Model3DGroup       normalGroup = new Model3DGroup();
            Point3D            p;
            ScreenSpaceLines3D normal0Wire = new ScreenSpaceLines3D();
            ScreenSpaceLines3D normal1Wire = new ScreenSpaceLines3D();
            ScreenSpaceLines3D normal2Wire = new ScreenSpaceLines3D();
            Color c     = Colors.Blue;
            int   width = 3;

            normal0Wire.Thickness = width;
            normal0Wire.Color     = c;
            normal1Wire.Thickness = width;
            normal1Wire.Color     = c;
            normal2Wire.Thickness = width;
            normal2Wire.Color     = c;
            double num    = 1;
            double mult   = .01;
            double denom  = mult * 3.0;// Convert.ToDouble(normalSizeTextBox.Text);
            double factor = num / denom;

            p = Vector3D.Add(Vector3D.Divide(normal, factor), p0);
            normal0Wire.Points.Add(p0);
            normal0Wire.Points.Add(p);
            p = Vector3D.Add(Vector3D.Divide(normal, factor), p1);
            normal1Wire.Points.Add(p1);
            normal1Wire.Points.Add(p);
            p = Vector3D.Add(Vector3D.Divide(normal, factor), p2);
            normal2Wire.Points.Add(p2);
            normal2Wire.Points.Add(p);

            //Normal wires are not models, so we can't
            //add them to the normal group.  Just add them
            //to the viewport for now...
            this.show_viewport3D.Children.Add(normal0Wire);
            this.show_viewport3D.Children.Add(normal1Wire);
            this.show_viewport3D.Children.Add(normal2Wire);
            return(normalGroup);
        }
예제 #30
0
        public TriangleUpdater(Rectangle3D rectangle3D, Model3DGroup model3DGroup, List <object> generalFiguresList)
        {
            Rectangle rectangle = new Rectangle(model3DGroup, 3, generalFiguresList);

            rectangle.Show();

            rectangle.ColorPicker.SelectedColor = rectangle3D.color;

            rectangle.X1.Text = rectangle3D.pointLU.X.ToString();
            rectangle.Y1.Text = rectangle3D.pointLU.Y.ToString();
            rectangle.Z1.Text = rectangle3D.pointLU.Z.ToString();

            rectangle.X2.Text = rectangle3D.pointLD.X.ToString();
            rectangle.Y2.Text = rectangle3D.pointLD.Y.ToString();
            rectangle.Z2.Text = rectangle3D.pointLD.Z.ToString();

            rectangle.X3.Text = rectangle3D.pointRD.X.ToString();
            rectangle.Y3.Text = rectangle3D.pointRD.Y.ToString();
            rectangle.Z3.Text = rectangle3D.pointRD.Z.ToString();

            rectangle.elementName.Text = rectangle3D.name.Substring(0, rectangle3D.name.Length - 6);
        }
예제 #31
0
        /// <summary>
        /// Generates triangle from 3 points.
        /// </summary>
        /// <param name="p0">A Kit3D.Windows.Media.Media3D.Point3D that specifies
        /// 3D point for visualization component.</param>
        /// <param name="p1">A Kit3D.Windows.Media.Media3D.Point3D that specifies
        /// 3D point for visualization component.</param>
        /// <param name="p2">A Kit3D.Windows.Media.Media3D.Point3D that specifies
        /// 3D point for visualization component.</param>
        /// <returns>A Kit3D.Windows.Media.Media3D.Model3DGroup that specifies
        /// trianle of triangle.</returns>
        private Model3DGroup CreateTriangleModel(Point3D p0, Point3D p1, Point3D p2)
        {
            MeshGeometry3D mesh = new MeshGeometry3D();
            mesh.Positions.Add(p0);
            mesh.Positions.Add(p1);
            mesh.Positions.Add(p2);
            mesh.TriangleIndices.Add(0);
            mesh.TriangleIndices.Add(1);
            mesh.TriangleIndices.Add(2);
            mesh.TextureCoordinates.Add(new Point(1, 1));
            mesh.TextureCoordinates.Add(new Point(1, 0));
            mesh.TextureCoordinates.Add(new Point(0, 1));
            Material material = new DiffuseMaterial(new Kit3DBrush(
                new SolidColorBrush(CalculateColor(CalculateNormal(p0, p1, p2)))));
            GeometryModel3D model = new GeometryModel3D(
                mesh, material);
            Model3DGroup group = new Model3DGroup();
            group.Children.Add(model);

            return group;
        }
예제 #32
0
        /// <summary>
        /// Shows the sample of surface.
        /// </summary>
        /// <param name="model3D">A WebMech.Web.Model3DData that specifies
        /// data object of 3D model with basic statistic data and list of 3D points.</param>
        public void ShowSample(Model3DData model3D)
        {
            Clear();
            ClearCamera();

            Model3DGroup surface = new Model3DGroup();
            Point3D[] points = GetSurfacePoints(model3D);
            for (int y = 0; y < (surfaceSize * (surfaceSize - 1)); y += surfaceSize)
            {
                for (int x = 0; x < (surfaceSize - 1); x++)
                {
                    surface.Children.Add(
                        CreateTriangleModel(
                                points[x + y + surfaceSize],
                                points[x + y],
                                points[x + y + 1])
                    );
                    surface.Children.Add(
                        CreateTriangleModel(
                                points[x + y + surfaceSize],
                                points[x + y + 1],
                                points[x + y + surfaceSize + 1])
                    );
                }
            }
            ModelVisual3D model = new ModelVisual3D();
            model.Content = surface;
            mainViewport.Children.Add(model);
        }