// Define the model.
        private void DefineModel(Model3DGroup group)
        {
            // Define a polygon in the XZ plane.
            Point3D center = new Point3D(0, 0, 4.5);

            Point3D[] polygon = G3.MakePolygonPoints(6, center,
                                                     new Vector3D(1, 0, 0), new Vector3D(0, 0, -1));

            // Make a transform to move the polygon in the -Z direction.
            TranslateTransform3D translate = new TranslateTransform3D(0, 0, -3);

            // Make a right cone.
            MeshGeometry3D mesh1 = new MeshGeometry3D();

            mesh1.AddCone(center, polygon, new Vector3D(0, 3, 0));
            group.Children.Add(mesh1.MakeModel(Brushes.Pink));

            // Make a skewed cone.
            translate.Transform(polygon);
            center = translate.Transform(center);
            MeshGeometry3D mesh2 = new MeshGeometry3D();

            mesh2.AddCone(center, polygon, new Vector3D(0, 3, 2));
            group.Children.Add(mesh2.MakeModel(Brushes.LightBlue));

            // Make a conic frustum with cutting plane parallel to the base.
            translate.Transform(polygon);
            center = translate.Transform(center);
            MeshGeometry3D mesh3 = new MeshGeometry3D();

            mesh3.AddConeFrustum(center, polygon, new Vector3D(0, 4, 0), 2);
            group.Children.Add(mesh3.MakeModel(Brushes.LightGreen));

            // Make a conic frustum with cutting plane not parallel to the base.
            translate.Transform(polygon);
            center = translate.Transform(center);
            MeshGeometry3D mesh4   = new MeshGeometry3D();
            Point3D        planePt = center + new Vector3D(0, 2, 0);
            Vector3D       planeN  = new Vector3D(1, 1, 1);

            mesh4.AddConeFrustum(center, polygon, new Vector3D(0, 4, 0), planePt, planeN);
            group.Children.Add(mesh4.MakeModel(Brushes.Orange));

            // Show the axes.
            MeshExtensions.AddAxes(group);
        }
Esempio n. 2
0
        // Define the model.
        private void DefineModel(Model3DGroup group)
        {
            // Axes.
            MeshExtensions.AddAxes(group);

            MeshGeometry3D mesh1 = new MeshGeometry3D();
            MeshGeometry3D mesh2 = new MeshGeometry3D();
            MeshGeometry3D mesh3 = new MeshGeometry3D();
            MeshGeometry3D mesh4 = new MeshGeometry3D();

            double  x0     = -5;
            Point3D center = new Point3D(x0, 0, 4.5);

            // Box.
            mesh1.AddBox(center + new Vector3D(-0.5, 0, -1),
                         D3.XVector(1), D3.YVector(3), D3.ZVector(2));
            center.X += 2;

            // Box wrapped.
            mesh2.AddBoxWrapped(center + new Vector3D(-0.5, 0, -1),
                                D3.XVector(1), D3.YVector(3), D3.ZVector(2));
            center.X += 2;

            // Cone.
            Point3D[] circle = G3.MakePolygonPoints(20, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddCone(center, circle, D3.YVector(4));
            center.X += 2;

            // Cone frustum.
            circle = G3.MakePolygonPoints(20, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddConeFrustum(center, circle, D3.YVector(4), 3);
            center.X += 2;

            // Cone frustum w/cutting plane.
            circle = G3.MakePolygonPoints(20, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddConeFrustum(center, circle, D3.YVector(4),
                                 center + new Vector3D(0, 2, 0), new Vector3D(0, 1, 1));
            center.X += 2;

            // Start a new row.
            center.X  = x0;
            center.Z -= 3;

            // Cube.
            MeshGeometry3D cubeMesh = new MeshGeometry3D();

            cubeMesh.AddCube();
            cubeMesh.ApplyTransformation(new ScaleTransform3D(1, 1.5, 0.5));
            cubeMesh.ApplyTransformation(
                new TranslateTransform3D(center.X, center.Y + 1.5, 0));
            mesh3.Merge(cubeMesh);
            center.X += 2;

            // Cylinder.
            Point3D[] polygon = G3.MakePolygonPoints(7, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddCylinder(polygon, new Vector3D(0, 2, -1));
            center.X += 2;

            // Cylinder.
            circle = G3.MakePolygonPoints(20, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddCylinder(circle, new Vector3D(0, 2, -1), true);
            center.X += 2;

            // Cylinder w/cutting planes.
            polygon = G3.MakePolygonPoints(7, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddCylinder(polygon, new Vector3D(0, 1, 0),
                              center + new Vector3D(0, 2, 0), new Vector3D(0, 2, 1),
                              center + new Vector3D(0, -2, 0), new Vector3D(0, 2, -1));
            center.X += 2;

            // Cylinder w/cutting planes.
            polygon = G3.MakePolygonPoints(7, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddCylinder(polygon, new Vector3D(0, 1, 0),
                              center + new Vector3D(0, 2, 0), new Vector3D(0, 2, 1),
                              center + new Vector3D(0, -2, 0), new Vector3D(0, 2, -1), true);
            center.X += 2;

            // Start a new row.
            center.X  = x0;
            center.Z -= 3;

            // Dodecahedron.
            MeshGeometry3D dodMesh = new MeshGeometry3D();

            dodMesh.AddDodecahedron();
            double dodScale = 1 / G3.DodecahedronCircumradius();

            dodMesh.ApplyTransformation(new ScaleTransform3D(dodScale, dodScale, dodScale));
            dodMesh.ApplyTransformation(
                new TranslateTransform3D(center.X, center.Y + 0.5, center.Z));
            mesh3.Merge(dodMesh);
            center.X += 2;

            // Frustum.
            polygon = G3.MakePolygonPoints(5, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddFrustum(center, polygon, D3.YVector(4), 2);
            center.X += 2;

            // Icosahedron.
            MeshGeometry3D icoMesh = new MeshGeometry3D();

            icoMesh.AddIcosahedron();
            double icoScale = 1 / G3.IcosahedronCircumradius();

            icoMesh.ApplyTransformation(new ScaleTransform3D(icoScale, icoScale, icoScale));
            icoMesh.ApplyTransformation(
                new TranslateTransform3D(center.X, center.Y + 0.5, center.Z));
            mesh3.Merge(icoMesh);
            center.X += 2;

            // Octahedron.
            MeshGeometry3D octMesh = new MeshGeometry3D();

            octMesh.AddOctahedron();
            double octScale = 1 / G3.OctahedronCircumradius();

            octMesh.ApplyTransformation(new ScaleTransform3D(octScale, octScale, octScale));
            octMesh.ApplyTransformation(
                new TranslateTransform3D(center.X, center.Y + 0.5, center.Z));
            mesh3.Merge(octMesh);
            center.X += 2;

            // Pyramid.
            polygon = G3.MakePolygonPoints(6, center, D3.XVector(1), D3.ZVector(-1));
            mesh1.AddPyramid(center, polygon, D3.YVector(3));
            center.X += 2;

            // Start a new row.
            center.X  = x0;
            center.Z -= 3;

            // Sphere.
            mesh1.AddSphere(center + new Vector3D(0, 1, 0), 1, 20, 10);
            center.X += 2;

            // Tetrahedron.
            MeshGeometry3D tetMesh = new MeshGeometry3D();

            tetMesh.AddTetrahedron();
            double tetScale = 1 / G3.TetrahedronCircumradius();

            tetMesh.ApplyTransformation(new ScaleTransform3D(tetScale, tetScale, tetScale));
            tetMesh.ApplyTransformation(
                new TranslateTransform3D(center.X, center.Y + 0.5, center.Z));
            mesh3.Merge(tetMesh);
            center.X += 2;

            // Textured sphere.
            mesh4.Positions.Add(new Point3D());
            mesh4.TextureCoordinates.Add(new Point(1.01, 1.01));
            mesh4.AddTexturedSphere(center + new Vector3D(0, 1, 0), 1, 20, 10);
            center.X += 2;

            // Textured torus.
            mesh4.AddTexturedTorus(center + new Vector3D(0, 1, 0), 0.6, 0.4, 30, 15);
            center.X += 2;

            // Torus.
            mesh1.AddTorus(center + new Vector3D(0, 1, 0), 0.6, 0.4, 30, 15);
            center.X += 2;

            // Start a new row.
            center.X  = x0;
            center.Z -= 3;

            group.Children.Add(mesh1.MakeModel(Brushes.LightGreen));
            group.Children.Add(mesh2.MakeModel("wrapper.png"));
            group.Children.Add(mesh3.MakeModel(Brushes.LightBlue));
            group.Children.Add(mesh4.MakeModel("world.jpg"));
        }
Esempio n. 3
0
        // Add the model to the Model3DGroup.
        private void DefineModel(Model3DGroup model_group)
        {
            // Make the normal and selected materials.
            NormalMaterial   = new DiffuseMaterial(Brushes.LightGreen);
            SelectedMaterial = new DiffuseMaterial(Brushes.Red);

            // Create some cubes.
            for (int x = -5; x <= 3; x += 4)
            {
                for (int y = -5; y <= 3; y += 4)
                {
                    for (int z = -5; z <= 3; z += 4)
                    {
                        // Make a cube with lower left corner (x, y, z).
                        MeshGeometry3D mesh = new MeshGeometry3D();
                        mesh.AddBox(x, y, z, 2, 2, 2);
                        GeometryModel3D model = new GeometryModel3D(mesh, NormalMaterial);
                        model_group.Children.Add(model);

                        // Remember that this model is selectable.
                        SelectableModels.Add(model);
                    }
                }
            }

            // test cage adding
            MeshGeometry3D cagemesh = new MeshGeometry3D();

            cagemesh.AddCage(5, 5, 5, 2, 2, 2, 0.05);
            var cagemodel = new GeometryModel3D(cagemesh, NormalMaterial);

            model_group.Children.Add(cagemodel);
            SelectableModels.Add(cagemodel);

            // test cylinder adding
            MeshGeometry3D cylindermesh = new MeshGeometry3D();

            cylindermesh.AddSmoothCylinder(new Point3D(7, 7, 7), new Vector3D(1, 1, 1), 0.5, 20);
            var cylindermodel = new GeometryModel3D(cylindermesh, NormalMaterial);

            model_group.Children.Add(cylindermodel);
            SelectableModels.Add(cylindermodel);

            // test sphere adding
            MeshGeometry3D spheremesh = new MeshGeometry3D();

            spheremesh.AddSmoothSphere(new Point3D(8.5, 8.5, 8.5), Math.Sqrt(3 * 0.5 + 0.5 * 0.5), 20, 40);
            var spheremodel = new GeometryModel3D(spheremesh, NormalMaterial);

            model_group.Children.Add(spheremodel);
            SelectableModels.Add(spheremodel);

            // add cone
            MeshGeometry3D conemesh = new MeshGeometry3D();

            conemesh.AddCone(new Point3D(9, 9, 9), new Vector3D(1, 1, 1), 0.5, -0.2, 20);
            var conemodel = new GeometryModel3D(conemesh, NormalMaterial);

            model_group.Children.Add(conemodel);
            SelectableModels.Add(conemodel);

            // X axis.
            MeshGeometry3D mesh_x = MeshExtensions.XAxisArrow(1, 7);

            model_group.Children.Add(mesh_x.SetMaterial(Brushes.Red, false));
            var forwardmodel = "前方".To3DLabel(new Point3D(8.5, 0.5, 0), new Vector3D(0, 0, 1), new Vector3D(0, 1, 0), Brushes.Red, 0.5);

            model_group.Children.Add(forwardmodel);

            // Y axis.
            MeshGeometry3D mesh_y = MeshExtensions.YAxisArrow(1, 7);

            model_group.Children.Add(mesh_y.SetMaterial(Brushes.Green, false));
            var upmodel = "上方".To3DLabel(new Point3D(0, 8.5, 0), new Vector3D(0, 0, 1), new Vector3D(0, 1, 0), Brushes.Green, 0.5);

            model_group.Children.Add(upmodel);

            // Z axis.
            MeshGeometry3D mesh_z = MeshExtensions.ZAxisArrow(1, 7);

            model_group.Children.Add(mesh_z.SetMaterial(Brushes.Blue, false));
            var rightmodel = "右方".To3DLabel(new Point3D(0, 0, 9), new Vector3D(0, 0, 1), new Vector3D(0, 1, 0), Brushes.Blue, 0.5);

            model_group.Children.Add(rightmodel);
        }