使用规则重定义使civil 3d标签与视图平行
昨天同事提出了这样一个需求,
要让曲面的点位高程标签与屏幕平行,
以便于查看,
如下图:
其实这个实现起来很简单:
不知道大家对这个教程是否熟悉,
如果熟悉的话,
问题就相当简单。
直接修改样例代码,
几行代码就搞定了。
public class LabelOverrule : DrawableOverrule
{
public override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.Drawable drawable, Autodesk.AutoCAD.GraphicsInterface.WorldDraw wd)
{
return false;
}
public override void ViewportDraw(Autodesk.AutoCAD.GraphicsInterface.Drawable drawable, Autodesk.AutoCAD.GraphicsInterface.ViewportDraw vd)
{
SurfaceElevationLabel label = (SurfaceElevationLabel)drawable;
Point3d org = label.LabelLocation;
Matrix3d m = Matrix3d.PlaneToWorld(new Plane(org, vd.Viewport.ViewDirection)) *
Matrix3d.WorldToPlane(new Plane(org, label.GetPlane().Normal)) * Matrix3d.Rotation(-label.RotationAngle, label.GetPlane().Normal, org);
vd.Geometry.PushModelTransform(m);
base.ViewportDraw(drawable, vd);
vd.Geometry.PopModelTransform();
}
public override int SetAttributes(Autodesk.AutoCAD.GraphicsInterface.Drawable drawable, Autodesk.AutoCAD.GraphicsInterface.DrawableTraits traits)
{
return (base.SetAttributes(drawable, traits)|2048);
}
}
这里需要注意的是,
标签样式中“方向引用”需要设置为“世界坐标系”,
否则标签有些时候显示会不符合需求。
如何调用上面的代码,
还可以参照这个链接中文章。