VDF常見問題整理(十):如何創(chuàng)建一些3D對(duì)象?
VectorDraw Developer Framework(VDF)是一個(gè)用于應(yīng)用程序可視化的圖形引擎庫(kù)。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。
VectorDraw Developer Framework試用版下載
問:
如何才能創(chuàng)建一些3D對(duì)象?
答:
您可以使用一些基本功能和對(duì)象在VDF中創(chuàng)建的3D對(duì)象。
一、使用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對(duì)象的代碼:
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按鈕,點(diǎn)擊那里的代碼。
五、通過切割(切片)現(xiàn)有的多面體:
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對(duì)象和ToMesh()函數(shù)將其轉(zhuǎn)換為vdPolyface對(duì)象,如:
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對(duì)象的cut命令。
param name =curve>用于剪切多面的vdCurve對(duì)象。您可以使用圓,矩形,橢圓,折線和切割多面體對(duì)象。