Exemplo n.º 1
0
        private void FaceToDirection(CadFigure fig, Vector3d org, Vector3d dir)
        {
            if (fig.Type != CadFigure.Types.POLY_LINES)
            {
                return;
            }

            Vector3d faceNormal = CadUtil.TypicalNormal(fig.PointList);

            if (faceNormal.EqualsThreshold(dir) || (-faceNormal).EqualsThreshold(dir))
            {
                // Face is already target direction
                return;
            }

            //   | 回転軸 rv
            //   |
            //   |
            //   | --------->向けたい方向 dir
            //   /
            //  /
            // 面の法線 faceNormal
            Vector3d rv = CadMath.Normal(faceNormal, dir);

            double t = CadMath.AngleOfVector(faceNormal, dir);

            CadUtil.RotateFigure(fig, org, rv, t);
        }
Exemplo n.º 2
0
        public static CadMesh CreateExtruded(VertexList src, Vector3d dv, int div = 0)
        {
            if (src.Count < 3)
            {
                return(null);
            }

            div += 1;

            VertexList vl;

            Vector3d n = CadUtil.TypicalNormal(src);


            if (CadMath.InnerProduct(n, dv) <= 0)
            {
                vl = new VertexList(src);
                vl.Reverse();
            }
            else
            {
                vl = src;
            }

            int vlCnt = vl.Count;

            CadMesh mesh = new CadMesh(vl.Count * 2, vl.Count);

            CadFace f;

            Vector3d dt = dv / div;

            Vector3d sv = Vector3d.Zero;

            // 頂点リスト作成
            for (int i = 0; i < div + 1; i++)
            {
                for (int j = 0; j < vlCnt; j++)
                {
                    mesh.VertexStore.Add(vl[j] + sv);
                }

                sv += dt;
            }


            // 表面
            f = new CadFace();

            for (int i = 0; i < vlCnt; i++)
            {
                f.VList.Add(i);
            }

            mesh.FaceStore.Add(f);


            // 裏面
            f = new CadFace();

            int si = (div + 1) * vlCnt - 1;
            int ei = si - (vlCnt - 1);

            for (int i = si; i >= ei; i--)
            {
                f.VList.Add(i);
            }

            mesh.FaceStore.Add(f);

            // 側面
            for (int k = 0; k < div; k++)
            {
                int ti = vlCnt * k;

                for (int i = 0; i < vlCnt; i++)
                {
                    int j = (i + 1) % vlCnt;

                    f = new CadFace();

                    f.VList.Add(i + ti);
                    f.VList.Add(i + ti + vlCnt);
                    f.VList.Add(j + ti + vlCnt);
                    f.VList.Add(j + ti);

                    mesh.FaceStore.Add(f);
                }
            }

            MeshUtil.SplitAllFace(mesh);

            return(mesh);
        }
Exemplo n.º 3
0
        // option:
        // e.g.
        // a100q30 max area = 100, min degree = 30
        // a100q max area = 100, min degree = default (20)
        // min degree < 34
        // Other options see
        // https://www.cs.cmu.edu/~quake/triangle.switch.html
        //
        public void Triangulate(uint figID, string option)
        {
            CadFigure tfig = Controller.DB.GetFigure(figID);

            if (tfig == null || tfig.Type != Types.POLY_LINES)
            {
                return;
            }

            if (tfig.PointCount < 3)
            {
                return;
            }

            CadFigure cfig = FigUtil.Clone(tfig);

            Vector3d org = cfig.PointList[0].vector;
            Vector3d dir = Vector3d.UnitZ;

            Vector3d faceNormal = CadUtil.TypicalNormal(cfig.PointList);

            Vector3d rotateV = default;

            double t = 0;

            if (!faceNormal.EqualsThreshold(dir) && !(-faceNormal).EqualsThreshold(dir))
            {
                rotateV = CadMath.Normal(faceNormal, dir);
                t       = -CadMath.AngleOfVector(faceNormal, dir);
                CadUtil.RotateFigure(cfig, org, rotateV, t);
            }

            //Controller.CurrentLayer.AddFigure(cfig);

            VertexList vl = cfig.GetPoints(12);

            CadMesh m = IglW.Triangulate(vl, option);

            HeModel hem = HeModelConverter.ToHeModel(m);

            CadFigureMesh fig = (CadFigureMesh)Controller.DB.NewFigure(CadFigure.Types.MESH);

            fig.SetMesh(hem);

            for (int i = 0; i < fig.PointCount; i++)
            {
                CadVertex v = fig.PointList[i];
                v.Z = org.Z;
                fig.PointList[i] = v;
            }

            if (t != 0)
            {
                CadUtil.RotateFigure(fig, org, rotateV, -t);
            }

            CadOpeList root = new CadOpeList();
            CadOpe     ope;

            ope = new CadOpeAddFigure(Controller.CurrentLayer.ID, fig.ID);
            Session.AddOpe(ope);

            Controller.CurrentLayer.AddFigure(fig);


            ope = new CadOpeRemoveFigure(Controller.CurrentLayer, figID);
            Session.AddOpe(ope);

            Controller.CurrentLayer.RemoveFigureByID(figID);
            Controller.CurrentFigure = null;

            Session.PostRemakeObjectTree();
        }