/// <summary> /// constructs a mesh from the passed array of 3d points /// points must be in column-major format /// </summary> /// <param name="verts">a grid of 3d points to mesh</param> /// <param name="rows">the number of rows in the grid</param> /// <returns>a ColorPlain mesh object colored by layer</returns> public static Mesh GetMesh(Point3D[] verts, int rows) { int cols = verts.Length / rows; Mesh mesh = new Mesh(meshNatureType.ColorSmooth); mesh.Vertices = verts; mesh.Triangles = new SmoothTriangle[(rows - 1) * (cols - 1) * 2]; int count = 0; for (int j = 0; j < (rows - 1); j++) { for (int i = 0; i < (cols - 1); i++) { mesh.Triangles[count++] = new SmoothTriangle(i + j * cols, i + j * cols + 1, i + (j + 1) * cols + 1); mesh.Triangles[count++] = new SmoothTriangle(i + j * cols, i + (j + 1) * cols + 1, i + (j + 1) * cols); } } mesh.RegenMode = regenType.RegenAndCompile; mesh.ComputeEdges(); //mesh.ComputeNormals(); mesh.NormalAveragingMode = meshNormalAveragingType.AveragedByAngle; return mesh; }
public static void UpdateMesh(Mesh target, Mesh source) { target.Vertices = source.Vertices; target.Triangles = source.Triangles.ToArray(); //int count = 0; //for (int j = 0; j < (rows - 1); j++) //{ // for (int i = 0; i < (cols - 1); i++) // { // mesh.Triangles[count++] = new IndexTriangle(i + j * cols, // i + j * cols + 1, // i + (j + 1) * cols + 1); // mesh.Triangles[count++] = new IndexTriangle(i + j * cols, // i + (j + 1) * cols + 1, // i + (j + 1) * cols); // } //} target.RegenMode = regenType.RegenAndCompile; target.ComputeEdges(); //mesh.ComputeNormals(); target.NormalAveragingMode = meshNormalAveragingType.AveragedByAngle; }
//static public Point3D[] GetMeshGaussianPoints(ISurface s, int ROWS, int COLS, out double[] gauss) //{ // Vect2 uv = new Vect2(); // Vect3 xyz = new Vect3(); // gauss = new double[ROWS * COLS]; // Point3D[] d = new Point3D[ROWS * COLS]; // int i = 0; // for (int iU = 0; iU < ROWS; iU++) // { // uv[0] = (double)iU / (double)(ROWS - 1); // for (int iV = 0; iV < COLS; iV++, i++) // { // uv[1] = (double)iV / (double)(COLS - 1); // s.xRad(uv, ref xyz, ref gauss[i]); // Utilities.Vect3ToPoint3D(ref d[i], xyz); // } // } // return d; //} /// <summary> /// constructs a mesh representation of a surface using MESHROWS and MESHCOLS for resoultion /// </summary> /// <param name="s">the surface to mesh</param> /// <param name="uvLims">(optional)the uv limits to mesh, uvLim[0,x] = uLim, uvLim[1,x] = vLim</param> /// <param name="bGauss">true for gaussian colormap, false for by-layer coloring</param> /// <returns>a mesh of either MulticolorPlain or ColorPlain type</returns> public static Mesh GetMesh(ISurface s, double[,] uvLims, bool bGauss) { int rows = MESHU, cols = MESHV; //Mesh mesh = new Mesh(meshNatureType.RichPlain); meshNatureType meshtype = bGauss ? meshNatureType.MulticolorSmooth : meshNatureType.ColorSmooth; Mesh mesh = new Mesh(meshtype); mesh.ColorMethod = bGauss ? colorMethodType.byEntity : colorMethodType.byLayer; mesh.Vertices = bGauss ? SurfaceTools.GetMeshGaussianPoints(s, rows, cols, uvLims) : SurfaceTools.GetExtensionPoints(s, rows, cols, uvLims); mesh.RegenMode = regenType.RegenAndCompile; mesh.Triangles = new SmoothTriangle[(rows - 1) * (cols - 1) * 2]; int count = 0; for (int j = 0; j < (rows - 1); j++) { for (int i = 0; i < (cols - 1); i++) { mesh.Triangles[count++] = new SmoothTriangle(i + j * cols, i + j * cols + 1, i + (j + 1) * cols + 1); mesh.Triangles[count++] = new SmoothTriangle(i + j * cols, i + (j + 1) * cols + 1, i + (j + 1) * cols); } } mesh.ComputeEdges(); //mesh.ComputeNormals(); mesh.NormalAveragingMode = meshNormalAveragingType.AveragedByAngle; mesh.EntityData = s; mesh.Selectable = false; return mesh; }