/// <summary> /// Creates a mesh with a horizontal and vertical resolution indicated /// by the input parameters. It will generate /// (precisionU-1)*(precisionV-1) quads. /// </summary> public MeshGeometry3D CreateMesh(int precisionU, int precisionV) { lengthX = precisionU; lengthY = precisionV; du = (uMax - uMin) / (double)(precisionU - 1); dv = (vMax - vMin) / (double)(precisionV - 1); positions = new Point3D[lengthX, lengthY]; normals = new Vector3D[lengthX, lengthY]; textureCoords = new System.Windows.Point[lengthX, lengthY]; indices = new ArrayList(); double v = vMin; for (int y = 0; y < lengthY; y++) { double u = uMin; if (y == lengthY - 1) { v = vMax; } for (int x = 0; x < lengthX; x++) { if (x == lengthX - 1) { u = uMax; } VariableExpression.Define("u", u); VariableExpression.Define("v", v); positions[x, y] = Evaluate(); normals[x, y] = GetNormal(u, v); u += du; } v += dv; } VariableExpression.Undefine("u"); VariableExpression.Undefine("v"); SetTextureCoordinates(); SetIndices(); MeshGeometry3D mesh = new MeshGeometry3D(); for (int y = 0; y < lengthY; y++) { for (int x = 0; x < lengthX; x++) { mesh.Positions.Add(positions[x, y]); mesh.Normals.Add(normals[x, y]); mesh.TextureCoordinates.Add(textureCoords[x, y]); } } mesh.TriangleIndices = new Int32Collection(); foreach (int index in indices) { mesh.TriangleIndices.Add(index); } return(mesh); }
/// <summary> /// Creates a mesh with a horizontal and vertical resolution indicated /// by the input parameters. It will generate /// (precisionU-1)*(precisionV-1) quads. /// </summary> public Model3DGroup CreateWireframeModel(int precisionU, int precisionV) { lengthX = precisionU; lengthY = precisionV; du = (uMax - uMin) / (double)(precisionU - 1); dv = (vMax - vMin) / (double)(precisionV - 1); positions = new Point3D[lengthX, lengthY]; double v = vMin; for (int y = 0; y < lengthY; y++) { double u = uMin; if (y == lengthY - 1) { v = vMax; } for (int x = 0; x < lengthX; x++) { if (x == lengthX - 1) { u = uMax; } VariableExpression.Define("u", u); VariableExpression.Define("v", v); positions[x, y] = Evaluate(); u += du; } v += dv; } VariableExpression.Undefine("u"); VariableExpression.Undefine("v"); Model3DGroup group = new Model3DGroup(); // TODO: Remove //ScreenSpaceLines3D lines; /* * // Create Horizontal lines * for ( int y = 0; y < lengthY; y++ ) * { * lines = new ScreenSpaceLines3D(); * lines.Color = Colors.Black; * lines.Thickness = 1; * for ( int x = 0; x < lengthX; x++ ) * { * lines.Points.Add( positions[ x,y ] ); * } * group.Children.Add( lines ); * } * * // Create Vertical lines * for ( int x = 0; x < lengthX; x++ ) * { * lines = new ScreenSpaceLines3D(); * lines.Color = Colors.Black; * lines.Thickness = 1; * for ( int y = 0; y < lengthY; y++ ) * { * lines.Points.Add( positions[ x,y ] ); * } * group.Children.Add( lines ); * } */ return(group); }