コード例 #1
0
ファイル: MeshLayer.cs プロジェクト: ViRGIS-Team/ViRGiS_v2
        protected override Task _save()
        {
            RecordSet layer = _layer as RecordSet;

            layer.Position           = transform.position.ToPoint();
            layer.Transform.Position = Vector3.zero;
            layer.Transform.Rotate   = transform.rotation;
            layer.Transform.Scale    = transform.localScale;
            EditableMesh[] meshes = GetComponentsInChildren <EditableMesh>();
            string         ex     = Path.GetExtension(layer.Source).ToLower();

            features = new List <DMesh3>();
            foreach (EditableMesh mesh in meshes)
            {
                features.Add(mesh.GetMesh());
            }
            if (ex == ".obj")
            {
                List <WriteMesh> wmeshes = new List <WriteMesh>();
                foreach (DMesh3 dmesh in features)
                {
                    DMesh3 mesh = new DMesh3(dmesh);
                    foreach (int idx in mesh.VertexIndices())
                    {
                        Vector3d vtx = mesh.GetVertex(idx);
                        mesh.SetVertex(idx, new Vector3d(vtx.x, vtx.z, vtx.y));
                    }
                    wmeshes.Add(new WriteMesh(mesh, ""));
                }
                saveObj(layer.Source, wmeshes);
            }
            if (ex == ".dxf")
            {
                DXF.DxfDocument          doc       = new DXF.DxfDocument();
                CoordinateTransformation transform = null;
                if (GetCrs() != null)
                {
                    transform = new CoordinateTransformation(AppState.instance.mapProj, GetCrs());
                }
                foreach (DMesh3 dmesh in features)
                {
                    foreach (Index3i tri in dmesh.Triangles())
                    {
                        DXF.Vector3 v1 = dmesh.GetVertex(tri.a).ToDxfVector3(transform);
                        DXF.Vector3 v2 = dmesh.GetVertex(tri.b).ToDxfVector3(transform);
                        DXF.Vector3 v3 = dmesh.GetVertex(tri.c).ToDxfVector3(transform);
                        doc.AddEntity(new Face3d(v1, v2, v3));
                    }
                }
                using (Stream stream = File.Open(layer.Source, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite)) {
                    doc.Save(stream);
                    stream.Close();
                }
            }
            return(Task.CompletedTask);
        }
コード例 #2
0
 /// <summary>
 /// Convert a netDXF Vector3 in z-up coordinate frame to a Vectir3D in Y-up coordinate frame
 /// using the optional Coordinate Transform to reproject the point if present
 /// </summary>
 /// <param name="v">DXF.Vector3</param>
 /// <param name="ct">Coordinate transform</param>
 /// <returns>Vector3d</returns>
 public static Vector3d ToVector3d(this DXF.Vector3 v, CoordinateTransformation ct = null)
 {
     double[] vlocal = new double[3] {
         v.X, v.Y, v.Z
     };
     if (ct != null)
     {
         ct.TransformPoint(vlocal);
     }
     return(new Vector3d((float)vlocal[0], (float)vlocal[2], (float)vlocal[1]));
 }
コード例 #3
0
    public void AddTriangles(List <Vector3RD> triangleVertices, string layerName)
    {
        Block block = new Block(layerName);

        for (int i = 0; i < triangleVertices.Count; i += 3)
        {
            netDxf.Vector3 vertex1 = new netDxf.Vector3(triangleVertices[i].x, triangleVertices[i].y, triangleVertices[i].z);
            netDxf.Vector3 vertex2 = new netDxf.Vector3(triangleVertices[i + 1].x, triangleVertices[i + 1].y, triangleVertices[i + 1].z);
            netDxf.Vector3 vertex3 = new netDxf.Vector3(triangleVertices[i + 2].x, triangleVertices[i + 2].y, triangleVertices[i + 2].z);
            Face3d         face    = new Face3d(vertex1, vertex3, vertex2);
            block.Entities.Add(face);
            //doc.AddEntity(face);
            //face.Layer = Laag;
        }
        Insert blokInsert = new Insert(block);

        blokInsert.Layer = dxfLayer;
        dxfDocument.AddEntity(blokInsert);
    }