public void OnPolymesh(PolymeshTopology polymesh) { IList <XYZ> pts = polymesh.GetPoints(); Transform t = CurrentTransform; pts = pts.Select(p => t.OfPoint(p)).ToList(); var normals = polymesh.GetNormals(); var uvs = polymesh.GetUVs(); int v1, v2, v3; int v4, v5, v6; int v7, v8, v9; int faceindex = 0; foreach (PolymeshFacet facet in polymesh.GetFacets()) { v1 = _vertices.AddVertex(new PointInt(pts[facet.V1], _switch_coordinates)); v2 = _vertices.AddVertex(new PointInt(pts[facet.V2], _switch_coordinates)); v3 = _vertices.AddVertex(new PointInt(pts[facet.V3], _switch_coordinates)); face.Add(v1); face.Add(v2); face.Add(v3); v4 = _uvs.AddVertex(new PointDouble(uvs[facet.V1])); v5 = _uvs.AddVertex(new PointDouble(uvs[facet.V2])); v6 = _uvs.AddVertex(new PointDouble(uvs[facet.V3])); face.Add(v4); face.Add(v5); face.Add(v6); if (polymesh.DistributionOfNormals == DistributionOfNormals.AtEachPoint) { v7 = _normals.AddVertex(new PointDouble(normals[facet.V1], _switch_coordinates)); v8 = _normals.AddVertex(new PointDouble(normals[facet.V2], _switch_coordinates)); v9 = _normals.AddVertex(new PointDouble(normals[facet.V3], _switch_coordinates)); } else if (polymesh.DistributionOfNormals == DistributionOfNormals.OnEachFacet) { v7 = _normals.AddVertex(new PointDouble(normals[faceindex], _switch_coordinates)); v8 = v7; v9 = v7; } else { v7 = _normals.AddVertex(new PointDouble(normals[0], _switch_coordinates)); v8 = v7; v9 = v7; } face.Add(v7); face.Add(v8); face.Add(v9); faceindex++; } }
/// <summary> /// 获取几何信息中每个三角面对应点的顶点坐标/法向坐标/UV坐标的索引 /// 并存入face列表中 /// </summary> /// <param name="polymesh"></param> /// <param name="pts"></param> /// <param name="normals"></param> /// <param name="uvs"></param> private void GetFaceIndex(PolymeshTopology polymesh, IList <XYZ> pts, IList <XYZ> normals, IList <UV> uvs) { int v1, v2, v3; int v4, v5, v6; int v7, v8, v9; int faceindex = 0; foreach (PolymeshFacet facet in polymesh.GetFacets()) { v1 = _vertices.AddVertex(new PointInt(pts[facet.V1], _switch_coordinates)); v2 = _vertices.AddVertex(new PointInt(pts[facet.V2], _switch_coordinates)); v3 = _vertices.AddVertex(new PointInt(pts[facet.V3], _switch_coordinates)); face.Add(v1); face.Add(v2); face.Add(v3); v4 = _uvs.AddVertex(new PointDouble(uvs[facet.V1])); v5 = _uvs.AddVertex(new PointDouble(uvs[facet.V2])); v6 = _uvs.AddVertex(new PointDouble(uvs[facet.V3])); face.Add(v4); face.Add(v5); face.Add(v6); if (polymesh.DistributionOfNormals == DistributionOfNormals.AtEachPoint) { v7 = _normals.AddVertex(new PointDouble(normals[facet.V1], _switch_coordinates)); v8 = _normals.AddVertex(new PointDouble(normals[facet.V2], _switch_coordinates)); v9 = _normals.AddVertex(new PointDouble(normals[facet.V3], _switch_coordinates)); } else if (polymesh.DistributionOfNormals == DistributionOfNormals.OnEachFacet) { v7 = _normals.AddVertex(new PointDouble(normals[faceindex], _switch_coordinates)); v8 = v7; v9 = v7; } else { v7 = _normals.AddVertex(new PointDouble(normals[0], _switch_coordinates)); v8 = v7; v9 = v7; } face.Add(v7); face.Add(v8); face.Add(v9); faceindex++; } }
/// <summary> /// Add the vertices of the given triangle to our /// vertex lookup dictionary and emit a triangle. /// </summary> void StoreTriangle(MeshTriangle triangle) { for (int i = 0; i < 3; ++i) { XYZ p = triangle.get_Vertex(i); PointInt q = new PointInt(p); _triangles.Add(_vertices.AddVertex(q)); } }