// Add the model to the Model3DGroup. private void DefineModel() { // Brushes. #if MONOCHROME SolidColorBrush pink_brush = new SolidColorBrush(Color.FromArgb(255, 224, 224, 224)); SolidColorBrush lightgreen_brush = new SolidColorBrush(Color.FromArgb(255, 150, 150, 150)); SolidColorBrush lightergreen_brush = new SolidColorBrush(Color.FromArgb(255, 200, 200, 200)); SolidColorBrush lightblue_brush = new SolidColorBrush(Color.FromArgb(255, 100, 100, 100)); SolidColorBrush red_brush = new SolidColorBrush(Color.FromArgb(255, 60, 60, 60)); SolidColorBrush green_brush = new SolidColorBrush(Color.FromArgb(255, 80, 80, 80)); SolidColorBrush blue_brush = new SolidColorBrush(Color.FromArgb(255, 160, 160, 160)); SolidColorBrush seg_brush = new SolidColorBrush(Color.FromArgb(255, 20, 20, 20)); #else SolidColorBrush pink_brush = Brushes.Pink; SolidColorBrush lightgreen_brush = Brushes.LightGreen; SolidColorBrush lightblue_brush = Brushes.LightBlue; SolidColorBrush red_brush = Brushes.Red; SolidColorBrush green_brush = Brushes.Green; SolidColorBrush blue_brush = Brushes.Blue; SolidColorBrush seg_brush = Brushes.Red; #endif MeshGeometry3D point_mesh = new MeshGeometry3D(); point_mesh.AddCube(2, null); DiffuseMaterial cube_material = new DiffuseMaterial(lightblue_brush); GeometryModel3D cube_model = new GeometryModel3D(point_mesh, cube_material); MainModel3Dgroup.Children.Add(cube_model); MeshGeometry3D wire_mesh = point_mesh.ToWireframe(0.05); DiffuseMaterial wire_material = new DiffuseMaterial(red_brush); GeometryModel3D wire_model = new GeometryModel3D(wire_mesh, wire_material); MainModel3Dgroup.Children.Add(wire_model); #if AXES // Axes. Point3D origin = new Point3D(); const double axis_thickness = 0.05; const double axis_length = 3; MeshGeometry3D xaxis_mesh = new MeshGeometry3D(); xaxis_mesh.AddSegment(origin, new Point3D(axis_length, 0, 0), axis_thickness, true); DiffuseMaterial xaxis_material = new DiffuseMaterial(red_brush); GeometryModel3D xaxis_model = new GeometryModel3D(xaxis_mesh, xaxis_material); MainModel3Dgroup.Children.Add(xaxis_model); MeshGeometry3D yaxis_mesh = new MeshGeometry3D(); yaxis_mesh.AddSegment(origin, new Point3D(0, axis_length, 0), axis_thickness, true); DiffuseMaterial yaxis_material = new DiffuseMaterial(green_brush); GeometryModel3D yaxis_model = new GeometryModel3D(yaxis_mesh, yaxis_material); MainModel3Dgroup.Children.Add(yaxis_model); MeshGeometry3D zaxis_mesh = new MeshGeometry3D(); zaxis_mesh.AddSegment(origin, new Point3D(0, 0, axis_length), axis_thickness, true); DiffuseMaterial zaxis_material = new DiffuseMaterial(blue_brush); GeometryModel3D zaxis_model = new GeometryModel3D(zaxis_mesh, zaxis_material); MainModel3Dgroup.Children.Add(zaxis_model); #endif }
// Define the model. private void DefineModel(Model3DGroup group) { // Show the axes. MeshExtensions.AddAxes(group); const double scale = 0.75; // Make a solid cube. MeshGeometry3D mesh1 = new MeshGeometry3D(); mesh1.AddCube(); mesh1.ApplyTransformation(new ScaleTransform3D(scale, scale, scale)); group.Children.Add(mesh1.MakeModel(Brushes.Red)); // Make a translucent octahedron. MeshGeometry3D mesh2 = new MeshGeometry3D(); mesh2.AddOctahedron(); double octScale = scale * G3.CubeCircumradius() / G3.OctahedronInradius(); mesh2.ApplyTransformation(new ScaleTransform3D(octScale, octScale, octScale)); 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 cube. MeshGeometry3D mesh3 = new MeshGeometry3D(); mesh3.AddCube(); double cubeScale = octScale * G3.OctahedronCircumradius() / G3.CubeInradius(); mesh3.ApplyTransformation(new ScaleTransform3D(cubeScale, cubeScale, cubeScale)); MaterialGroup group3 = D3.MakeMaterialGroup( new DiffuseMaterial(brush), new SpecularMaterial(Brushes.White, 100)); group.Children.Add(mesh3.MakeModel(group3)); }
// Define the model. private void DefineModel(Model3DGroup group) { // Verify the cube calculations. MeshExtensions.VerifyCube(); // Show the axes. MeshExtensions.AddAxes(group); const double scale = 2; // Make a solid insphere. MeshGeometry3D mesh1 = new MeshGeometry3D(); mesh1.AddSphere(D3.Origin, G3.CubeInradius(), 60, 30, true); mesh1.ApplyTransformation(new ScaleTransform3D(scale, scale, scale)); group.Children.Add(mesh1.MakeModel(Brushes.Red)); // Make a translucent cube. MeshGeometry3D mesh2 = new MeshGeometry3D(); mesh2.AddCube(); 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.CubeCircumradius(), 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)); }
// 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")); }