Ejemplo n.º 1
0
        /// <summary>
        /// Implementation of the Slice command.
        /// </summary>
        /// <param name="doc"></param>
        public static void Slice(vdDocument doc)
        {
            doc.Prompt("Select a vdPolyface Figure");
            vdFigure fig;
            gPoint   userpt;
            //This command waits until thew user clicks an entity.
            StatusCode code = doc.ActionUtility.getUserEntity(out fig, out userpt);

            doc.Prompt(null);
            if (code == StatusCode.Success)
            {
                vdPolyface face = fig as vdPolyface;
                if (face != null)
                {
                    doc.Prompt("Pick the Origin Point");
                    gPoint origin;
                    code = doc.ActionUtility.getUserPoint(out origin);
                    doc.Prompt(null);
                    if (code != StatusCode.Success)
                    {
                        return;
                    }
                    doc.Prompt("Give the Slice Direction Vector");
                    gPoint vector;
                    code = doc.ActionUtility.getUserPoint(out vector);
                    doc.Prompt(null);
                    if (code != StatusCode.Success)
                    {
                        return;
                    }
                    Vector v = new Vector(vector);
                    face.Invalidate();
                    face.Slice(origin, v);
                    face.Update();
                    face.Invalidate();
                }
            }
        }
Ejemplo n.º 2
0
        private vdPolyface AddMeshToEntities(vdEntities entities, MeshData mesh)
        {
            vdPolyface onepolyface = new vdPolyface();

            onepolyface.SetUnRegisterDocument(vDraw.ActiveDocument);
            onepolyface.setDocumentDefaults();

            // 顶点数组输入
            foreach (PointData point in mesh.Vertexes)
            {
                onepolyface.VertexList.Add(point.X * Tools.Ft2MmScale, point.Y * Tools.Ft2MmScale, point.Z * Tools.Ft2MmScale);
            }

            // 面片索引输入
            foreach (TriangleIndexData index in mesh.TriangleIndexes)
            {
                onepolyface.AddFaceItem(index.V1 + 1, index.V2 + 1, index.V3 + 1, index.V1 + 1, -1);
            }

            onepolyface.SmoothAngle = 45;
            onepolyface.Layer       = vDraw.ActiveDocument.Layers.FindName(mesh.MaterialName);
            entities.Add(onepolyface);

            if (ExportSetting.SystemSetting.IsExportTextureFile)
            {
                var material = Materials.Find(m => m.Name == mesh.MaterialName);
                if (material != null && !string.IsNullOrEmpty(material.GetValidMapFile()))
                {
                    var img = vDraw.ActiveDocument.Images.FindName(Path.GetFileNameWithoutExtension(material.GetValidMapFile()));
                    if (img != null)
                    {
                        onepolyface.PenColor.SystemColor   = Color.Gray;
                        onepolyface.PenColor.MaterialImage = img;

                        Matrix mtx = new Matrix();
                        mtx.IdentityMatrix();
                        mtx.ScaleMatrix(0.001, 0.001, 1);
                        onepolyface.PenColor.MaterialMatrix = mtx;
                    }
                }
            }

            onepolyface.Invalidate();
            onepolyface.Update();

            return(onepolyface);
        }
Ejemplo n.º 3
0
        bool Merge3DFace(vdPolyface vdp)
        {
            int                   II       = int.MaxValue;
            Int32Array            i32      = vdp.FaceList;
            Dictionary <int, int> deleteID = new Dictionary <int, int>();

            Dictionary <int, int> kk1 = new Dictionary <int, int>();
            Dictionary <int, int> kk2 = new Dictionary <int, int>();

            //合并三角形
            #region 合并三角形
            for (int i = 0; i < i32.Count; i = i + 5)
            {
                if (i32[i + 4] != II && i32[i] == i32[i + 3]) //一定是没有被合并过的,说明是三角形
                {
                    int i1 = i32[i];
                    int i2 = i32[i + 1];
                    int i3 = i32[i + 2];
                    kk1.Clear();
                    kk1.Add(i1, i1);
                    kk1.Add(i2, i2);
                    kk1.Add(i3, i3);

                    for (int j = i + 5; j < i32.Count; j = j + 5)
                    {
                        if (i32[j + 4] != II && i32[j] == i32[j + 3])   //剔除已经处理过的
                        {
                            int j1 = i32[j];
                            int j2 = i32[j + 1];
                            int j3 = i32[j + 2];

                            //kk2.Clear();
                            //kk2.Add(j1, j1);
                            //kk2.Add(j2, j2);
                            //kk2.Add(j3, j3);


                            int k1 = 0;
                            int k2 = 0;
                            int k3 = 0;
                            int k4 = 0;

                            //找到公共边
                            if ((i1 == j1 || i1 == j2 || i1 == j3) && (i2 == j1 || i2 == j2 || i2 == j3))
                            {
                                k1 = i3;
                                k2 = i1;
                                k4 = i2;
                            }
                            else if ((i2 == j1 || i2 == j2 || i2 == j3) && (i3 == j1 || i3 == j2 || i3 == j3))
                            {
                                k1 = i1;
                                k2 = i2;
                                k4 = i3;
                            }
                            else if ((i1 == j1 || i1 == j2 || i1 == j3) && (i3 == j1 || i3 == j2 || i3 == j3))
                            {
                                k1 = i2;
                                k2 = i3;
                                k4 = i1;
                            }
                            else
                            {
                                continue;
                            }

                            if (!kk1.ContainsKey(j1))
                            {
                                k3 = j1;
                            }

                            if (!kk1.ContainsKey(j2))
                            {
                                k3 = j2;
                            }

                            if (!kk1.ContainsKey(j3))
                            {
                                k3 = j3;
                            }

                            //检查是否共面

                            gPoints gps3 = new gPoints();
                            //gps3.Add(vdp.VertexList[i1 - 1]);
                            //gps3.Add(vdp.VertexList[i2 - 1]);
                            //gps3.Add(vdp.VertexList[i3 - 1]);

                            gps3.Add(vdp.VertexList[k1 - 1]);
                            gps3.Add(vdp.VertexList[k2 - 1]);
                            gps3.Add(vdp.VertexList[k4 - 1]);


                            Vector vec = gps3.GetNormal();

                            // 导出时,下面计算dist的方法有异常OutOfRange异常抛出,特加以下判断
                            if (k3 > vdp.VertexList.Count || k1 > vdp.VertexList.Count || k3 <= 0 || k1 <= 0)
                            {
                                continue;
                            }

                            double dist = Globals.DistancePointToPlane(vdp.VertexList[k3 - 1], vec,
                                                                       vdp.VertexList[k1 - 1]);
                            if (Math.Abs(dist) > Globals.VD_ZERO6)
                            {
                                continue;
                            }

                            //判断是否是凹多边形   凹多边形有显示问题

                            ////判断是否构成了三角形
                            gps3.InsertAt(3, vdp.VertexList[k3 - 1]);

                            //gPoints gps4=gps3.Clone() as gPoints;
                            //gps3.makeClosed();
                            //gps4.makeClosed();
                            //gps4.RemoveInLinePoints();

                            //if (gps3.Count != gps4.Count) continue;


                            double area1 = GetArea3D(gps3[0], gps3[1], gps3[2]);
                            double area2 = GetArea3D(gps3[3], gps3[1], gps3[2]);
                            double area3 = GetArea3D(gps3[0], gps3[1], gps3[3]);
                            double area4 = GetArea3D(gps3[0], gps3[2], gps3[3]);

                            double area = Math.Max(area3, area4);
                            if (area1 + area2 <= area)  //凹多边形
                            {
                                continue;
                            }


                            i32[i]     = k4;
                            i32[i + 1] = k1;
                            i32[i + 2] = k2;
                            i32[i + 3] = k3;//这里放到第3个点经常出现问题


                            i32[j + 4] = II;
                            break;
                        }
                    }
                }
            }
            #endregion
            #region 生成新的polyface
            Int32Array iii32 = new Int32Array();
            for (int i = 0; i < vdp.FaceList.Count; i = i + 5)
            {
                if (vdp.FaceList[i + 4] != II)
                {
                    iii32.Add(i32[i]);
                    iii32.Add(i32[i + 1]);
                    iii32.Add(i32[i + 2]);
                    iii32.Add(i32[i + 3]);
                    iii32.Add(i32[i + 4]);
                }
            }
            vdp.FaceList = iii32;
            vdp.Invalidate();
            #endregion
            return(true);
        }