Zoom-independent curve pattern

Eyeshot's Entity.LineTypePattern is zoom dependent, which means that the size of the dashes gets bigger or smaller depending on the zoom level:

Capture.PNG Capture2.PNG Capture.PNG

If you want the size of the dashes to remain the same regardless of the zoom level, similar to what AutoCAD® does for selected entities, you can inherit from the relevant Entity class and override the Entity.Draw() method to enable the line stipple feature, like this:

class MyCircle : Circle
{
    public ushort Stipple = 0xF0F0; // See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glLineStipple.xml 

    public MyCircle(double x, double y, double z, double radius)
        : base(x, y, z, radius)
    {
    }

    protected override void Draw(DrawParams data)
    {
        data.RenderContext.EndDrawBufferedLines();

        data.RenderContext.SetLineStipple(1, Stipple, data.Viewport.Camera);
        data.RenderContext.EnableLineStipple(true);

        base.Draw(data);
        data.RenderContext.EndDrawBufferedLines();
        data.RenderContext.EnableLineStipple(false);
    }
}

 

This will be the result:

Capture.PNG Capture2.PNG Capture.PNG

  

If you want to obtain the same result for the Region entity, you need to override the Region.DrawEdge() as shown in the below code snippet:

class MyRegion : Region
{
    public ushort Stipple = 0xF0F0; // See https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glLineStipple.xml

    public MyRegion(Region another) : base(another) { }

    private double _myTol;
    public override void Regen(RegenParams data)
    {
        base.Regen(data);

        _myTol = data.Deviation; //I want to use the same tolerance for drawing the edges.
    }

    public override void DrawEdges(DrawParams data)
    {
        data.RenderContext.EndDrawBufferedLines();

        float currentLineWidth = data.RenderContext.CurrentLineWidth;
        if (this.LineWeightMethod == colorMethodType.byEntity)
        {
            data.RenderContext.SetLineSize(this.LineWeight, true);
        }

        if (this.LineTypeMethod == colorMethodType.byEntity)
        {
            data.RenderContext.SetLineStipple(3, Stipple, data.Viewport.Camera);
            data.RenderContext.EnableLineStipple(true);

        }

        // Draw edges
        foreach (var curve in ContourList)
        {
            Entity ent = (Entity) curve;
            if (ent.Vertices == null)            
                ent.Regen(_myTol);                
            
            data.RenderContext.DrawLineStrip(ent.Vertices);
        }      
        data.RenderContext.EndDrawBufferedLines();
        data.RenderContext.EnableLineStipple(false); 
        data.RenderContext.SetLineSize(currentLineWidth, true); 
    }
}
Region star = devDept.Eyeshot.Entities.Region.CreatePolygon(new[]
{
    new Point2D(0, -10),
    new Point2D(15, -20),
    new Point2D(7.5, -2.5),
    new Point2D(20, 7.5),
    new Point2D(5, 7.5),
    new Point2D(0, 20),
    new Point2D(-5, 7.5),
    new Point2D(-20, 7.5),
    new Point2D(-7.5, -2.5),
    new Point2D(-15, -20)
});

MyRegion r = new MyRegion(star);
r.LineWeightMethod = r.LineTypeMethod = colorMethodType.byEntity;
r.LineWeight = 3; 
design1.Entities.Add(r, 0, Color.Gold);

 

This will be the result:

starRegion1.PNG  starRegion2.PNG

 

Note: This trick requires OpenGL renderer or Direct3D renderer with feature level greater than 9.3. (it can be seen in design.RendererVersion).

Previous versions of this article: Eyeshot 5

Was this article helpful?
1 out of 1 found this helpful

Comments

1 comment
Date Votes
  • How can I create a Zoom Independent Text entity?

    /Kasper

    1

Please sign in to leave a comment.

Articles in this section

See more