Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        private void ExportSolid(Solid solid)
        {
            SolidOrShellTessellationControls solidOrShellTessellationControls = new SolidOrShellTessellationControls
            {
                LevelOfDetail      = userSetting.LevelOfDetail / 30.0,
                Accuracy           = 0.1,
                MinAngleInTriangle = 0.0001,
                MinExternalAngleBetweenTriangles = 1.0
            };

            try
            {
                TriangulatedSolidOrShell triangulatedSolidOrShell = SolidUtils.TessellateSolidOrShell(solid, solidOrShellTessellationControls);
                int shellComponentCount = triangulatedSolidOrShell.ShellComponentCount;
                for (int i = 0; i < shellComponentCount; i++)
                {
                    TriangulatedShellComponent shellComponent = triangulatedSolidOrShell.GetShellComponent(i);
                    ModelGeometry exportedGeometry            = new ModelGeometry
                    {
                        Transform = transformationStack.Peek(),
                        Points    = new List <XYZ>(shellComponent.VertexCount)
                    };
                    for (int num = 0; num != shellComponent.VertexCount; num++)
                    {
                        exportedGeometry.Points.Add(shellComponent.GetVertex(num));
                    }
                    exportedGeometry.Indices = new List <int>(shellComponent.TriangleCount * 3);
                    for (int j = 0; j < shellComponent.TriangleCount; j++)
                    {
                        TriangleInShellComponent triangle = shellComponent.GetTriangle(j);
                        exportedGeometry.Indices.Add(triangle.VertexIndex0);
                        exportedGeometry.Indices.Add(triangle.VertexIndex1);
                        exportedGeometry.Indices.Add(triangle.VertexIndex2);
                    }
                    exportedGeometry.CalculateNormals(false);
                    exportedGeometry.CalculateUVs(true, false);
                    ElementId materialElementId       = solid.Faces.get_Item(0).MaterialElementId;
                    Tuple <Document, ElementId> tuple = new Tuple <Document, ElementId>(documentStack.Peek(), materialElementId);
                    ChangeCurrentMaterial(tuple);
                    documentAndMaterialIdToGeometries[tuple].Add(exportedGeometry);
                }
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 4
0
        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);
                    }
                }
            }
        }