コード例 #1
0
        public CadMesh Load(string fname, double scale)
        {
            TotalPointCount = 0;
            TotalFaceCount  = 0;

            CadMesh mesh = new CadMesh(10, 10);

            StreamReader reader = new StreamReader(fname);

            string L1;
            string L2;

            DxfState state  = DxfState.STATE_NONE;
            int      valCnt = 0;


            double[] val = new double[3];

            int code;

            VertexList pointList = new VertexList();

            while (!reader.EndOfStream)
            {
                L1 = reader.ReadLine();
                L2 = reader.ReadLine();

                code = Int32.Parse(L1);
                L2   = L2.Trim();


                if (code == 0)
                {
                    if (L2 == "3DFACE")
                    {
                        state  = DxfState.STATE_3DFACE;
                        valCnt = 0;
                    }

                    if (pointList.Count > 0)
                    {
                        AddFace(mesh, pointList);
                        TotalFaceCount++;

                        pointList.Clear();
                    }

                    if (valCnt != 0)
                    {
                        state = 0;
                    }
                }

                if (state == DxfState.STATE_3DFACE)
                {
                    if (code < 10)
                    {
                        continue;
                    }

                    val[valCnt] = Double.Parse(L2) * scale;
                    valCnt++;

                    if (valCnt >= 3)
                    {
                        pointList.Add(CadVertex.Create(val[2], val[1], val[0]));
                        valCnt = 0;

                        TotalPointCount++;
                    }

                    continue;
                }
            }

            return(mesh);
        }