/// <summary> /// 利用3个点得到两个pointLine /// </summary> /// <param name="verticals"></param> /// <returns></returns> public static void GetPointLines(PointLines pls, int id, /*Color32[] colors,*/ Vector3[] verticals) { List <PointLine> olds = pls.data.FindAll(x => x.id == id); if (olds != null && olds.Count > 0) { foreach (var item in olds) { item.ReFleshPos(/*colors,*/ verticals); } } else//第一次加载时,可预测 { for (int i = 0; i < verticals.Length; ++i) { for (int j = i + 1; j < verticals.Length; ++j) { Vector3 nor = Vector3.Normalize(verticals[i] - verticals[j]); if (ApproximateRights(nor, true) || ApproximateRights(nor, false))//轴向 { //去除重复的线 if (pls.data.Find(x => { return((x.startPoint == verticals[i] && x.endPoint == verticals[j]) || (x.startPoint == verticals[j] && x.endPoint == verticals[i])); }) == null) { PointLine pl = new PointLine(/*colors[i], */ verticals[i], verticals[j], id, i, j); pls.data.Add(pl); } } } } } }
/// <summary> /// 利用网格信息得到线集合 /// </summary> /// <param name="meshData"></param> /// <returns></returns> public static void UpdatePointLines(MeshStruct meshData, ref PointLines pointLine) { for (int i = 0; i < meshData.triangles.Length - 2; i += 3) { PointLine.GetPointLines(pointLine, i, new Vector3[] { meshData.vertices[meshData.triangles[i]], meshData.vertices[meshData.triangles[i + 1]], meshData.vertices[meshData.triangles[i + 2]] }); } }
/// <summary> /// 将网格点连接成线 /// </summary> /// <param name="points"></param> public static void DrawGridLines(PointLines pointLines, /*bool defut,*/ Color32 defultColor) { foreach (var item in pointLines.data) { /*if(defut)*/ GL.Color(defultColor); //else GL.Color(item.centercolor); GL.Vertex(item.startPoint); GL.Vertex(item.endPoint); } }