VDF常見問題整理(四十七):如何在vdPolyface的特定面上應用映射的圖像?
VectorDraw Developer Framework(VDF)是一個用于應用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。
VectorDraw Developer Framework試用版下載
問:
如何在vdPolyface的特定面上應用映射的圖像? 如果vdPolyface的面不在X / Y平面中,最后就會得到一些奇怪的結果。怎么才能解決這個問題?
答:
對于此代碼,可以使用以下圖像:
(點擊可下載VectorDraw File Converter)
請參見下面的代碼和注釋:
vdDocument doc = framed.BaseControl.ActiveDocument; doc.New(); // create a new dowcument and add a "box" polyface bool res = doc.CommandAction.CmdBox3d(new gPoint(10, 10, 3), (double)3.0d, (double)3.0d, (double)3.0d, VectorDraw.Geometry.Globals.DegreesToRadians((double)23.5d)); if (!res) return; vdPolyface pface = doc.ActiveLayOut.Entities.Last as vdPolyface; // this the polyface just created by CmdBox3d if (pface == null) return; doc.CommandAction.CmdRotate3d("Y", pface, new gPoint(), (double)62.1d); // rotate it a bit doc.CommandAction.View3D("VINW"); doc.CommandAction.View3D("SHADEON"); // set the view vdImageDef imgdef = doc.Images.Add(@"converter_200x200.png"); //add the image definition to be applied if (imgdef == null) return; int choosenface = 3; // 0,1,2,..,7 8 faces in total In this face we will apply the material // get the position of the points that make the specific face int[] face = new int[] { pface.FaceList[choosenface * 5 ], pface.FaceList[choosenface * 5 + 1], pface.FaceList[choosenface * 5 + 3] }; gPoint origin = new gPoint(pface.VertexList[face[0]]); // set which point will be the origin of the image gPoint xDir = new gPoint(pface.VertexList[face[1]]); // set which point will be the x direction of the image gPoint yDir = new gPoint(pface.VertexList[face[2]]); // set which point will be the y direction of the image Matrix mat = new Matrix(); // need to create the Matrix to be applied Vector xver = new Vector(origin, xDir); // based on the origin Vector yver = new Vector(origin, yDir); //xdir and ydir mat.SetFrom(origin, xver, yver); gPoint originTrans = mat.Transform(origin); // get the transformed origin gPoint xDirTrans = mat.Transform(xDir);// get the transformed x direction //create the mapped image double border = originTrans.Distance3D(xDirTrans) / 100.0d; // give a bit of a border arround vdMappedImage mappedimg = new vdMappedImage(imgdef, new gPoint(originTrans.x +
結果顯示:
請注意:圖像將應用于整個多面體,而不是應用于特定的一個或多個面,因此,如果圖像投影中有面(如該三次多面體的底部),則圖像也將應用于它們。
以上問答,如果您有任何的疑惑都可以在評論區(qū)留言,我們會及時回復。此系列的問答教程我們會持續(xù)更新,如果您感興趣,可以多多關注本教程。
熱門文章推薦:
=======================================================
如果您對想要購買正版授權VectorDraw Developer Framework(VDF),可以聯(lián)系在線客服>>咨詢相關問題。
關注慧聚IT微信公眾號 ???,了解產品的最新動態(tài)及最新資訊。