VectorDraw常见问题合集,让你从菜鸡到大神(十)

311 阅读4分钟

    VectorDraw Developer Framework(VDF)是一个用于应用程序可视化的图形引擎库。有了VDF提供的功能,您可以轻松地创建、编辑、管理、输出、输入和打印2D和3D图形文件。   

VectorDraw web library (javascript)不仅能打开CAD图纸,而且能显示任何支持HTML5标准平台上的通用矢量对象,如Windows,安卓,iOS和Linux。无需任何安装,VectorDraw web library (javascript)就可以运行在任何支持canvas标签和Javascript的主流浏览器(Chrome, Firefox, Safari, Opera, Dolphin, Boat等等)中。这意味着可以用DXF,DWG,DGN,SKP(Google的Sketchup),VDML等多种格式在任何台式、平板电脑,智能手机和便携式笔记本上展现出你的业务。

问:

如何才能创建一些3D对象?

答:

您可以使用一些基本功能和对象在VDF中创建的3D对象。

一、使用CommandAction方法,如:

 private void button1_Click(object sender, EventArgs e)
        {
            Doc = vdFramedControl1.BaseControl.ActiveDocument;
            
            gPoints pts = new gPoints(); pts.Add(new gPoint(-16, 0)); pts.Add(new gPoint(-14, 0)); pts.Add(new gPoint(-14, 3)); pts.Add(new gPoint(-16, 3));
            Doc.CommandAction.Cmd3dFace(pts); // create a 3D face from 4 points
            pts = new gPoints(); pts.Add(new gPoint(-12, 0, 0)); pts.Add(new gPoint(-10, 0, -1)); pts.Add(new gPoint(-8, 0, 0)); pts.Add(new gPoint(-5, 0, 0));
            pts.Add(new gPoint(-12, 3, 1)); pts.Add(new gPoint(-10.5, 2.7, -1)); pts.Add(new gPoint(-8, 3, 0)); pts.Add(new gPoint(-5, 3.2, 0));
            pts.Add(new gPoint(-12, 6, 0)); pts.Add(new gPoint(-10.5, 5.7, 4)); pts.Add(new gPoint(-8, 6, 1)); pts.Add(new gPoint(-5, 5.8, 1));
            pts.Add(new gPoint(-12.5, 9, -0.5)); pts.Add(new gPoint(-10.5, 9.2, 2)); pts.Add(new gPoint(-8, 9.1, 0)); pts.Add(new gPoint(-5, 8.8, 0));
            Doc.CommandAction.Cmd3DMesh(4, 4, pts); // create a vdPolyface MESH that is made by 16 points

            Doc.CommandAction.CmdSphere(new gPoint(0,0,0),3.0d,32,16); // create a sphere
            Doc.CommandAction.CmdCone(new gPoint(7, 0, 0), 3.0d, 1.0d, 10.0d, 30);// create a cone
            Doc.CommandAction.CmdBox3d(new gPoint(11, 0, 0), 4.0d, 2.0d, 3.0d, 0.0d); // create a orthogonal 6-side box
            Doc.CommandAction.CmdTorus(new gPoint(19, 0), 2.0D, 0.5D, 30, 20); // create a torus
        }

二、通过使用vdPolyface对象的代码:

 private void button2_Click(object sender, EventArgs e)
        {
            Doc = vdFramedControl1.BaseControl.ActiveDocument;
            int[] array_faces = {1, 2, 5, 4, 116,  // connect vertexes 1, 2, 5 and 4 to one face with color 116
                    7, 8, 3, 3, 116, 
                    7, 12, 3, 3, 116, 
                    8, 3, 6, 9, 116, 
                    3, 12, 11, 6, 116, 
                    6, 9, 10, 10, 116, 
                    6, 10, 11, 11, 116, 
                    7, 8, 14, 13, -1, 
                    14, 15, 25, 8, -1, 
                    15, 16, 9, 25, -1, 
                    9, 10, 17, 16, -1, 
                    17, 18, 11, 10, -1,
                    11, 26, 19, 18, -1, 
                    12, 26, 19, 20, -1, 
                    7, 12, 20, 13, -1, 
                    20, 19, 23, 24, -1, 
                    14, 15, 22, 21, -1, 
                    15, 19, 23, 22, -1, 
                    14, 20, 24, 21, -1, 
                    21, 22, 23, 24, -1, 
                    13, 14, 20, 20, 2, 
                    16, 17, 18, 18, 2, 
                    15, 16, 18, 19, 2};

            Int32Array faces = new Int32Array(array_faces);

            gPoints pts = new gPoints();
            pts.Add(2, 0, 0);
            pts.Add(3, 0, 0);
            pts.Add(1, 0, 1);
            pts.Add(2.2, 0, 1);
            pts.Add(3.8, 0, 1);
            pts.Add(5, 0, 1);
            pts.Add(0, 0, 2);
            pts.Add(1, 1, 2);
            pts.Add(5.5, 1, 2);
            pts.Add(7, 0, 2);
            pts.Add(5.5, -1, 2);
            pts.Add(1, -1, 2);
            pts.Add(-0.5, 0, 3);
            pts.Add(0.5, 1.5, 3);
            pts.Add(3.5, 1.7, 3);
            pts.Add(6, 1.5, 3);
            pts.Add(8, 0, 3);
            pts.Add(6, -1.5, 3);
            pts.Add(3.5, -1.7, 3);
            pts.Add(0.5, -1.5, 3);
            pts.Add(0.5, 1, 4);
            pts.Add(3, 1, 4);
            pts.Add(3, -1, 4);
            pts.Add(0.5, -1, 4);
            pts.Add(3.25, 1, 2);
            pts.Add(3.25, -1, 2);

            vdPolyface pFace = new vdPolyface(Doc, pts, faces); // create the vdPolyface and 
            Doc.Model.Entities.AddItem(pFace); // add it to the document
            Doc.CommandAction.View3D("VISW");
            Doc.CommandAction.View3D("SHADE");
        }

三、使用Generate3DPathSection:

 private void button3_Click(object sender, EventArgs e)
        {
            Doc = vdFramedControl1.BaseControl.ActiveDocument;
            //create an oval tube 

            vdEllipse ci = new vdEllipse(Doc, new gPoint(), 0.03, 0.02, 0, 0, 0); // Doesn't need to be in the document
            Vertexes verts = new Vertexes();
            verts.Add(0, 0, 0, 0); verts.Add(0, 1, 0, -0.5); verts.Add(1, 1, 0, 0.2); verts.Add(1, 2, 0, 0);
            vdPolyline pline = new vdPolyline(Doc, verts);// Doesn't need to be in the document
            //We will use a polyline  as path and an ellipse as section which ellipse is going to go round the polyline and create the polyface needed.
            vdPolyface pface = new vdPolyface();
            pface.SetUnRegisterDocument(Doc);
            pface.setDocumentDefaults();
            pface.setDocumentDefaults();
            pface.Generate3dPathSection(pline, ci, new gPoint(0, 0.0, 0.0), 0, 1);
             
            Doc.Model.Entities.AddItem(pface); // add the polyface to the document.
        }

四、使用GroundSurface:

检查AddEntities Sample和GroundSurface按钮,点击那里的代码。

五、通过切割(切片)现有的多面体:

 private void button4_Click(object sender, EventArgs e)
        {
            Doc = vdFramedControl1.BaseControl.ActiveDocument;
            Doc.New();

            if (Doc.CommandAction.CmdSphere(new gPoint(0, 0, 0), 3.0d, 32, 16))  // create a sphere
            {
                vdPolyface pface = Doc.Model.Entities[Doc.Model.Entities.Count - 1] as vdPolyface;
                if (pface != null)
                {
                    pface.PenColor.FromSystemColor(Color.PowderBlue);
                    pface.Slice(new gPoint(-0.5, 0, 0), new Vector(-1, 0, 0), true, true);
                    pface.Slice(new gPoint(0, -1, 0), new Vector(-1, -1, 0), false,true); // do not cover this slice
                    Doc.CommandAction.View3D("SHADE");
                }
            }
        }

六、通过使用具有厚度的vdPolyHatch对象和ToMesh()函数将其转换为vdPolyface对象,如:

   private void button5_Click(object sender, EventArgs e)
        {
            double dLength = 400; double dDInterior = 100; double dDExterior = 200; double dSpecial = 10;
            double dHelp = dDInterior - dSpecial;
            Doc = vdFramedControl1.BaseControl.ActiveDocument;
            Doc.New();

            vdPolyline oPLine = new vdPolyline(); oPLine.SetUnRegisterDocument(Doc); oPLine.setDocumentDefaults();
            oPLine.VertexList.Add(new Vertex(dDExterior / 2, 0, 0, 1));
            oPLine.VertexList.Add(new gPoint(-dDExterior / 2, 0, 0));
            oPLine.VertexList.Add(new Vertex(-dDExterior / 2, 0, 0, 1));
            oPLine.Flag = VectorDraw.Professional.Constants.VdConstPlineFlag.PlFlagCLOSE;

            vdPolyline oPLine2 = new vdPolyline(); oPLine2.SetUnRegisterDocument(Doc); oPLine2.setDocumentDefaults();
            oPLine2.VertexList.Add(new Vertex(dDInterior / 2, -dSpecial / 2, 0, -1));
            oPLine2.VertexList.Add(new gPoint(-dDInterior / 2, -dSpecial / 2, 0));
            oPLine2.Flag = VectorDraw.Professional.Constants.VdConstPlineFlag.PlFlagCLOSE;

            vdPolyline oPLine3 = new vdPolyline(); oPLine3.SetUnRegisterDocument(Doc); oPLine3.setDocumentDefaults();
            oPLine3.VertexList.Add(new Vertex(dDInterior / 2, dSpecial / 2, 0, 1));
            oPLine3.VertexList.Add(new gPoint(-dDInterior / 2, dSpecial / 2, 0));
            oPLine3.Flag = VectorDraw.Professional.Constants.VdConstPlineFlag.PlFlagCLOSE;

            VectorDraw.Professional.vdCollections.vdCurves curves_Outer = new VectorDraw.Professional.vdCollections.vdCurves();
            curves_Outer.AddItem(oPLine);

            VectorDraw.Professional.vdCollections.vdCurves curves_Inside = new VectorDraw.Professional.vdCollections.vdCurves();
            curves_Inside.AddItem(oPLine2);
            curves_Inside.AddItem(oPLine3);

            //'create polyhatch
            vdPolyhatch onehatch = new vdPolyhatch();
            onehatch.SetUnRegisterDocument(Doc);
            onehatch.setDocumentDefaults();
            onehatch.PolyCurves.AddItem(curves_Outer);
            onehatch.PolyCurves.AddItem(curves_Inside);
            onehatch.HatchProperties = new VectorDraw.Professional.vdObjects.vdHatchProperties(VectorDraw.Professional.Constants.VdConstFill.VdFillModeSolid);
            onehatch.Thickness = dLength;

            //'create polyhatch
            vdPolyface oPFace = onehatch.ToMesh(0);
            oPFace.PenColor.FromSystemColor(Color.Purple);
            Doc.Model.Entities.AddItem(oPFace);

            Doc.CommandAction.View3D("VISE");
            Doc.CommandAction.View3D("SHADE");

            Doc.Model.ZoomExtents();
        }

七、通过使用vdPolyface对象的cut命令。

param name =curve>用于剪切多面的vdCurve对象。您可以使用圆,矩形,椭圆,折线和切割多面体对象。