70002427 Draw aligned to view entities that are not overlaped by existing model entities

Article 70002427
Type HowTo
Product Engine
Version 10
Date Added 10/28/2023 12:00:00 AM
Fixed 10.1005.0.2 (10/28/2023 12:00:00 AM)
Submitted by bandiroli

Summary

How can I draw aligned to view entities that are not overlaped by existing model entities

Solution

In order to draw aligned to view entities that are not overlap by existing model entities,
You need to create a vdEntities collections containing the align entities and not add them to the active layout entities Instead draw them in the AfterDraw event of vdDocument by disabling Depth Buffering as follow: 1. Create a polyface box and add it to the model entities

                doc.New();
                vdPolyface pf = new vdPolyface(doc);
                pf.CreateBox(new gPoint(0, 0, 0), 5, 5, 5, 0);//create a box (5x5x5) size
                doc.Model.Entities.AddItem(pf);
                createAlignToViewEntities(); //fill the collections with the alignet to view texts
                doc.RenderMode = vdRender.Mode.Shade;
                doc.ZoomExtents();
                doc.Redraw(false);
2. Create a collection of vdTexts that are align to view in each vertex of the box
void createAlignToViewEntities()
        {
            if (drawafterentities.Count > 0) return;
            drawafterentities.SetUnRegisterDocument(doc);
            //create a vdText foreach vertex of a box (5x5x5)
            drawafterentities.AddItem(new vdText(doc, "VectorDraw", new gPoint(0, 0, 0), 1.0, VdConstHorJust.VdTextHorCenter, VdConstVerJust.VdTextVerCen, doc.TextStyles.Standard) { AlignToView = true, AlignToViewSize = 10 ,PenColor = new vdColor(Color.Red)});
            drawafterentities.AddItem(new vdText(doc, "VectorDraw", new gPoint(5, 0, 0), 1.0, VdConstHorJust.VdTextHorCenter, VdConstVerJust.VdTextVerCen, doc.TextStyles.Standard) { AlignToView = true, AlignToViewSize = 10, PenColor = new vdColor(Color.Red) });
            drawafterentities.AddItem(new vdText(doc, "VectorDraw", new gPoint(5, 5, 0), 1.0, VdConstHorJust.VdTextHorCenter, VdConstVerJust.VdTextVerCen, doc.TextStyles.Standard) { AlignToView = true, AlignToViewSize = 10, PenColor = new vdColor(Color.Red) });
            drawafterentities.AddItem(new vdText(doc, "VectorDraw", new gPoint(0, 5, 0), 1.0, VdConstHorJust.VdTextHorCenter, VdConstVerJust.VdTextVerCen, doc.TextStyles.Standard) { AlignToView = true, AlignToViewSize = 10, PenColor = new vdColor(Color.Red) });
 
            drawafterentities.AddItem(new vdText(doc, "VectorDraw", new gPoint(0, 0, 5), 1.0, VdConstHorJust.VdTextHorCenter, VdConstVerJust.VdTextVerCen, doc.TextStyles.Standard) { AlignToView = true, AlignToViewSize = 10, PenColor = new vdColor(Color.Red) });
            drawafterentities.AddItem(new vdText(doc, "VectorDraw", new gPoint(5, 0, 5), 1.0, VdConstHorJust.VdTextHorCenter, VdConstVerJust.VdTextVerCen, doc.TextStyles.Standard) { AlignToView = true, AlignToViewSize = 10, PenColor = new vdColor(Color.Red) });
            drawafterentities.AddItem(new vdText(doc, "VectorDraw", new gPoint(5, 5, 5), 1.0, VdConstHorJust.VdTextHorCenter, VdConstVerJust.VdTextVerCen, doc.TextStyles.Standard) { AlignToView = true, AlignToViewSize = 10, PenColor = new vdColor(Color.Red) });
            drawafterentities.AddItem(new vdText(doc, "VectorDraw", new gPoint(0, 5, 5), 1.0, VdConstHorJust.VdTextHorCenter, VdConstVerJust.VdTextVerCen, doc.TextStyles.Standard) { AlignToView = true, AlignToViewSize = 10, PenColor = new vdColor(Color.Red) });
        }
3. Override the OnDrawAfter event
vdDOcument doc;

....

    doc.OnDrawAfter += Doc_OnDrawAfter;
    vdEntities drawafterentities = new vdEntities(); // this the the collection of texts that will be rendered "on - top" of the model entities

private void Doc_OnDrawAfter( object sender, vdRender render)
        {
            IvdOpenGLRender glrender = render.OpenGLRender;
            if (glrender != null) glrender.Flush(-1);//finishing draw all existing primitives in the buffer in case of 3d rendering views
            bool oldenabledepth = render.EnableDepthBuffer(false);//disable depth buffer comparison
            bool oldenabledepthwrite = render.EnableDepthBufferWrite(false);//disable write to depth buffer
            foreach (vdFigure item in drawafterentities)
            {
                item.Draw(render);
            }
            //restore depth buffer values
            render.EnableDepthBuffer(oldenabledepth);
            render.EnableDepthBufferWrite(oldenabledepthwrite);
        }

Send comments on this topic.