/// <summary> /// 导出扁平的贴花或者叫纹理(DecalFlat)adj. (flat) 光滑均匀的;(陆地)平坦的;(水面)平静的;无坡度的;扁的; /// </summary> /// <param name="element"></param> private void ExportDecalFlat(Element element) { ModelGeometry exportedGeometry = new ModelGeometry(); exportedGeometry.Transform = transformationStack.Peek(); GeometryElement arg_2F_0 = element.get_Geometry(Geometry_Options); exportedGeometry.Points = new List <XYZ>(4); using (IEnumerator <GeometryObject> enumerator = arg_2F_0.GetEnumerator()) { while (enumerator.MoveNext()) { Line line = (Line)enumerator.Current; if (!(line == null)) { exportedGeometry.Points.Add(line.Origin); if (exportedGeometry.Points.Count >= 4) { break; } } } } if (exportedGeometry.Points.Count != 4) { return; } exportedGeometry.Indices = new List <int>(6); exportedGeometry.Indices.Add(0); exportedGeometry.Indices.Add(2); exportedGeometry.Indices.Add(1); exportedGeometry.Indices.Add(0); exportedGeometry.Indices.Add(3); exportedGeometry.Indices.Add(2); exportedGeometry.Uvs = new List <UV>(4); exportedGeometry.Uvs.Add(new UV(0.0, 1.0)); exportedGeometry.Uvs.Add(new UV(1.0, 1.0)); exportedGeometry.Uvs.Add(new UV(1.0, 0.0)); exportedGeometry.Uvs.Add(new UV(0.0, 0.0)); exportedGeometry.CalculateNormals(false); exportedGeometry.MakeDoubleSided(); int num = this.currentDecalMaterialId; currentDecalMaterialId = num + 1; ElementId elementId = new ElementId(num); decalMaterialIdToDecal.Add(elementId, element); Tuple <Document, ElementId> tuple = new Tuple <Document, ElementId>(documentStack.Peek(), elementId); ChangeCurrentMaterial(tuple); documentAndMaterialIdToGeometries[tuple].Add(exportedGeometry); }
/// <summary> /// 导出有弧度弯曲的贴花DecalCurved /// </summary> /// <param name="element"></param> private void ExportDecalCurved(Element element) { ModelGeometry exportedGeometry = new ModelGeometry(); exportedGeometry.Transform = transformationStack.Peek(); GeometryElement expr_23 = element.get_Geometry(Geometry_Options); Arc arc = expr_23.ToArray()[1] as Arc; Curve arg_49_0 = expr_23.ToArray()[3] as Arc; XYZ[] array = arc.Tessellate().ToArray <XYZ>(); XYZ[] array2 = arg_49_0.Tessellate().ToArray(); exportedGeometry.Points = new List <XYZ>(array.Length + array2.Length); exportedGeometry.Uvs = new List <UV>(array.Length + array2.Length); for (int i = 0; i < array.Length; i++) { exportedGeometry.Points.Add(array[i]); exportedGeometry.Uvs.Add(new UV(1f - i * (1f / (array.Length - 1)), 1.0)); } for (int j = 0; j < array2.Length; j++) { exportedGeometry.Points.Add(array2[j]); exportedGeometry.Uvs.Add(new UV(j * (1f / (array.Length - 1)), 0.0)); } exportedGeometry.Indices = new List <int>((array.Length - 1) * 6); for (int k = 0; k < array.Length - 1; k++) { exportedGeometry.Indices.Add(k); exportedGeometry.Indices.Add(k + 1); exportedGeometry.Indices.Add(array.Length * 2 - k - 1); exportedGeometry.Indices.Add(k + 1); exportedGeometry.Indices.Add(array.Length * 2 - k - 2); exportedGeometry.Indices.Add(array.Length * 2 - k - 1); } exportedGeometry.CalculateNormals(false); exportedGeometry.MakeDoubleSided(); int num = this.currentDecalMaterialId; currentDecalMaterialId = num + 1; ElementId elementId = new ElementId(num); decalMaterialIdToDecal.Add(elementId, element); Tuple <Document, ElementId> tuple = new Tuple <Document, ElementId>(documentStack.Peek(), elementId); ChangeCurrentMaterial(tuple); documentAndMaterialIdToGeometries[tuple].Add(exportedGeometry); }
/// <summary> /// 当输出3d面的镶嵌多边形时,将调用此方法。 /// </summary> /// <param name="polymesh">表示多边形网格拓扑的节点</param> void IExportContext.OnPolymesh(PolymeshTopology polymesh) { ModelGeometry exportedGeometry = new ModelGeometry { Points = polymesh.GetPoints(), Normals = polymesh.GetNormals(), Uvs = polymesh.GetUVs(), Transform = transformationStack.Peek(), DistributionOfNormals = polymesh.DistributionOfNormals, Indices = new List <int>(polymesh.GetFacets().Count * 3) }; if (exportedGeometry.Transform.IsConformal && exportedGeometry.Transform.HasReflection) { using (IEnumerator <PolymeshFacet> enumerator = polymesh.GetFacets().GetEnumerator()) { while (enumerator.MoveNext()) { PolymeshFacet current = enumerator.Current; exportedGeometry.Indices.Add(current.V1); exportedGeometry.Indices.Add(current.V3); exportedGeometry.Indices.Add(current.V2); } goto Fine; } } foreach (PolymeshFacet current2 in polymesh.GetFacets()) { exportedGeometry.Indices.Add(current2.V1); exportedGeometry.Indices.Add(current2.V2); exportedGeometry.Indices.Add(current2.V3); } Fine: if (isElementDoubleSided) { exportedGeometry.MakeDoubleSided(); } documentAndMaterialIdToGeometries[currentDocumentAndMaterialId].Add(exportedGeometry); }
private void ExportSolid2(Solid solid) { foreach (Face face in solid.Faces) { if (!(face.Equals(null))) { Mesh mesh = face.Triangulate(userSetting.LevelOfDetail / 15.0); if (!(mesh.Equals(null)) && !mesh.Visibility.Equals(Visibility.Invisible)) { ModelGeometry exportedGeometry = new ModelGeometry(); // 设置坐标系 exportedGeometry.Transform = transformationStack.Peek(); exportedGeometry.Points = new List <XYZ>(mesh.Vertices); exportedGeometry.Indices = new List <int>(mesh.NumTriangles * 3); //指示此转换是否为保形的布尔值。指示此转换是否产生反射的布尔值。反射变换会更改坐标系的惯用性。 if (exportedGeometry.Transform.IsConformal && exportedGeometry.Transform.HasReflection) { for (int i = 0; i < mesh.NumTriangles; i++) { MeshTriangle meshTriangle = mesh.get_Triangle(i); exportedGeometry.Indices.Add((int)meshTriangle.get_Index(0)); exportedGeometry.Indices.Add((int)meshTriangle.get_Index(2)); exportedGeometry.Indices.Add((int)meshTriangle.get_Index(1)); } } else { for (int j = 0; j < mesh.NumTriangles; j++) { MeshTriangle meshTriangle2 = mesh.get_Triangle(j); exportedGeometry.Indices.Add((int)meshTriangle2.get_Index(0)); exportedGeometry.Indices.Add((int)meshTriangle2.get_Index(1)); exportedGeometry.Indices.Add((int)meshTriangle2.get_Index(2)); } } ModelGeometry TGeometry = exportedGeometry; //计算模型法线 TGeometry.CalculateNormals(TGeometry.Transform.IsConformal && exportedGeometry.Transform.HasReflection); exportedGeometry.CalculateUVs(true, false); //判断是不是反正双面实体 if (face.IsTwoSided) { exportedGeometry.MakeDoubleSided(); } //将当前元素面的材质ID放入元组中(文档,元素材质ID) ElementId materialElementId = face.MaterialElementId; Tuple <Document, ElementId> tuple = new Tuple <Document, ElementId>(documentStack.Peek(), materialElementId); //加入元组索引 ChangeCurrentMaterial(tuple); //用元组索引将模型加入到模型数据池 documentAndMaterialIdToGeometries[tuple].Add(exportedGeometry); } } } }