VDF常見問題整理(四十七):如何在vdPolyface的特定面上應(yīng)用映射的圖像?
VectorDraw Developer Framework(VDF)是一個(gè)用于應(yīng)用程序可視化的圖形引擎庫。有了VDF提供的功能,您可以輕松地創(chuàng)建、編輯、管理、輸出、輸入和打印2D和3D圖形文件。
VectorDraw Developer Framework試用版下載
問:
如何在vdPolyface的特定面上應(yīng)用映射的圖像? 如果vdPolyface的面不在X / Y平面中,最后就會(huì)得到一些奇怪的結(jié)果。怎么才能解決這個(gè)問題?
答:
對于此代碼,可以使用以下圖像:
(點(diǎn)擊可下載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 +
結(jié)果顯示:
請注意:圖像將應(yīng)用于整個(gè)多面體,而不是應(yīng)用于特定的一個(gè)或多個(gè)面,因此,如果圖像投影中有面(如該三次多面體的底部),則圖像也將應(yīng)用于它們。
以上問答,如果您有任何的疑惑都可以在評論區(qū)留言,我們會(huì)及時(shí)回復(fù)。此系列的問答教程我們會(huì)持續(xù)更新,如果您感興趣,可以多多關(guān)注本教程。
熱門文章推薦:
=======================================================
如果您對想要購買正版授權(quán)VectorDraw Developer Framework(VDF),可以聯(lián)系咨詢相關(guān)問題。
關(guān)注慧聚IT微信公眾號 ???,了解產(chǎn)品的最新動(dòng)態(tài)及最新資訊。