/// Make the ground mesh. void MakeGround(double groundY) { MeshGeometry3D groundMesh = new MeshGeometry3D(); const double dx = 15; const double dy = 1; const double dz = dx; Point3D corner = new Point3D(-dx / 2, groundY - dy, -dz / 2); groundMesh.AddBoxWrapped(corner, D3.XVector(dx), D3.YVector(dy), D3.ZVector(dz)); Point[] topCoords = { new Point(0.1, 0.1), new Point(0.1, 0.9), new Point(0.9, 0.9), new Point(0.9, 0.1), }; Point[] frontCoords = { new Point(0.0, 0.1), new Point(0.0, 0.9), new Point(0.1, 0.9), new Point(0.1, 0.1), }; Point[] leftCoords = { new Point(0.9, 0.0), new Point(0.1, 0.0), new Point(0.1, 0.1), new Point(0.9, 0.1), }; Point[] rightCoords = { new Point(0.1, 1.0), new Point(0.9, 1.0), new Point(0.9, 0.9), new Point(0.1, 0.9), }; Point[] backCoords = { new Point(1.0, 0.9), new Point(1.0, 0.1), new Point(0.9, 0.1), new Point(0.9, 0.9), }; Point[] bottomCoords = { new Point(0.9, 0.1), new Point(0.9, 0.9), new Point(0.1, 0.9), new Point(0.1, 0.1), }; groundMesh.AddBox(corner, D3.XVector(dx), D3.YVector(dy), D3.ZVector(dz), frontCoords, leftCoords, rightCoords, backCoords, topCoords, bottomCoords); _group.Children.Add(groundMesh.MakeModel(System.IO.Path.Combine(_resDir, @"rock.jpg"))); }
// Define the model. private void DefineModel(Model3DGroup group) { // Make a box. MeshGeometry3D mesh1 = new MeshGeometry3D(); mesh1.AddBox(new Point3D(1, -1, 0), D3.XVector(2), D3.YVector(2), D3.ZVector(2), D3.UnitTextures); group.Children.Add(mesh1.MakeModel("wood.jpg")); // Make a cube with every face different. MeshGeometry3D mesh2 = new MeshGeometry3D(); Point[][] textureCoords = D3.SectionTextureCoords(2, 3); mesh2.AddBox(new Point3D(0, 1, -2), D3.XVector(2), D3.YVector(2), D3.ZVector(2), textureCoords[0], textureCoords[1], textureCoords[2], textureCoords[3], textureCoords[4], textureCoords[5]); group.Children.Add(mesh2.MakeModel("all.jpg")); // Make a green parallelepiped. MeshGeometry3D mesh3 = new MeshGeometry3D(); mesh3.AddBox(new Point3D(-4, -1, -3), new Vector3D(2, 0.5, -0.5), new Vector3D(0, 2, -0.5), new Vector3D(-0.5, 0, 2)); group.Children.Add(mesh3.MakeModel(Brushes.LightGreen)); // Make a wrapped box. MeshGeometry3D mesh4 = new MeshGeometry3D(); mesh4.AddBoxWrapped(new Point3D(-3, -1, 0), D3.XVector(2), D3.YVector(2), D3.ZVector(2)); group.Children.Add(mesh4.MakeModel("wrapper.png")); // Show the axes. MeshExtensions.AddAxes(group); }
// 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")); }