1. 程式人生 > 實用技巧 >使用規則重定義使civil 3d標籤與檢視平行

使用規則重定義使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);
        }
    }

這裡需要注意的是,

標籤樣式中“方向引用”需要設定為“世界座標系”,

否則標籤有些時候顯示會不符合需求。