我试图在AutoCAD中绘制一系列代表墙的多面体。墙的每个部分都是一个单独的多面体,它们最终将被组合在一起。我试图将它们绘制为PolygonMeshes,以便它们可以渲染为实体对象。这是我的DrawPolyhedron方法
public static ObjectId DrawPolyhedronMesh(Polyhedron polyhedronToDraw, string layerToInsertOn = "0")
{
using (Transaction acTrans = _database.TransactionManager.StartTransaction())
{
// Open the Block table record for read
BlockTable acBlkTbl = acTrans.GetObject(_database.BlockTableId, OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for write
BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
// Create a polygon mesh
PolygonMesh acPolyMesh = new PolygonMesh();
acPolyMesh.Layer = layerToInsertOn;
acPolyMesh.MSize = 4;
acPolyMesh.NSize = 4;
// Add the new object to the block table record and the transaction
acBlkTblRec.AppendEntity(acPolyMesh);
acTrans.AddNewlyCreatedDBObject(acPolyMesh, true);
// Before adding vertexes, the polyline must be in the drawing
Point3dCollection acPts3dPMesh = new Point3dCollection();
foreach(Point p in polyhedronToDraw.Vertices)
{
acPts3dPMesh.Add(GeometryAdapter.ClearspanPointToAcadPoint(p));
}
foreach (Point3d acPt3d in acPts3dPMesh)
{
PolygonMeshVertex acPMeshVer = new PolygonMeshVertex(acPt3d);
acPolyMesh.AppendVertex(acPMeshVer);
acTrans.AddNewlyCreatedDBObject(acPMeshVer, true);
}
// Open the active viewport
ViewportTableRecord acVportTblRec = acTrans.GetObject(_editor.ActiveViewportId, OpenMode.ForWrite) as ViewportTableRecord;
// Rotate the view direction of the current viewport
acVportTblRec.ViewDirection = new Vector3d(-1, -1, 1);
_editor.UpdateTiledViewportsFromDatabase();
// Save the new objects to the database
acTrans.Commit();
return acPolyMesh.Id;
}
}
结果如下:
它吸引我的墙,除了某些原因,每个单独的多面体在太空中投射出一条线。每个人都回到同一个点。我非常困惑为什么这是因为我在绘制网格之前和之后检查了顶点集合,并且没有任何看起来不合适的点。
编辑:结果奇怪的行将是原点(0,0,0)