Mesh entity displayed as wireframe object

You can have a mesh entity displayed always in wireframe mode, regardless of the DisplayMode, by using the following class derived from Mesh:

 

Capture.PNG

 

class MyWireMesh : Mesh 
{ 
        public MyWireMesh(Mesh another) 
            : base(another) 
        { 
        } 

        protected override void Draw(DrawParams data) 
        { 
            Pre(); 

            gl.Color3fv(Utility.ColorToFloatArray(Color)); 

            base.Draw(data); 

            Post(); 
        } 

        protected override void SetShader(HqrData hqrData) 
        { 
            if (hqrData.ShaderParams != null) 
            { 
                bool prevLighting = hqrData.ShaderParams.Lighting; 

                hqrData.ShaderParams.Lighting = false; 

                base.SetShader(hqrData); 

                hqrData.ShaderParams.Lighting = prevLighting; 
            } 
        } 

        protected override void DrawForShadow() 
        { 
            Pre(); 

            base.DrawForShadow(); 

            Post(); 
        } 

        protected override void Render(RenderParams data) 
        { 
            Pre(); 

            gl.Color3fv(Utility.ColorToFloatArray(Color)); 

            base.Render(data); 

            Post(); 
        } 

        protected override void DrawSelected(DrawParams drawParams) 
        { 
            Pre(); 

            gl.Color3f(1, 1, 0); // Set the Selection color 

            base.DrawSelected(drawParams); 

            Post(); 
        } 

        protected override void DrawForSelection(DrawParams data) 
        { 
            Pre(); 

            base.DrawForSelection(data); 

            Post(); 
        } 

        private static void Post() 
        { 
            gl.PopAttrib(); 
            gl.PopAttrib(); 
            gl.PopAttrib(); 
        } 

        private void Pre() 
        { 
            gl.PushAttrib(gl.ENABLE_BIT); 
            gl.PushAttrib(gl.POLYGON_BIT); 
            gl.PushAttrib(gl.CURRENT_BIT); 

            gl.Disable(gl.LIGHTING); 
            gl.Disable(gl.CULL_FACE); 
            gl.PolygonMode(gl.FRONT_AND_BACK, gl.LINE); 
        } 
}
Have more questions? Submit a request

2 Comments

  • 0
    Avatar
    Damian Rafferty

    Is it possible to have a mesh entity display as another display mode besides wireframe, like Hidden Line?

  • 0
    Avatar
    Luca Cornazzani

    Sure.

    Use the following Pre() and Post() Methods: 

    private static void Post()
    {
    gl.PopAttrib();
    gl.PopAttrib();
    }

    private void Pre()
    {
    gl.PushAttrib(gl.ENABLE_BIT);
    gl.PushAttrib(gl.CURRENT_BIT);
    gl.Disable(gl.LIGHTING);
    }

      

    Override also these methods:

    protected override void DrawSilhouettes(projectionType projectionMode, double[] modelViewProj, int[] viewFrame, float screenToWorld, Dictionary<string, FontData> charDefs, Transformation transformation, Dictionary<string, Block> blocks)
    {
    Pre();
    gl.Color3f(0,0,0);
    base.DrawSilhouettes(projectionMode, modelViewProj, viewFrame, screenToWorld, charDefs, transformation, blocks);
    Post();
    }

    protected override void DrawEdges()
    {
    Pre();
    gl.Color3f(0, 0, 0);
    base.DrawEdges();
    Post();
    }

     

    And if you want the white color, replace the line

    gl.Color3fv(Utility.ColorToFloatArray(Color));

     

    in the Draw() and Render() methods with

     gl.Color3f(1, 1, 1);

     

Please sign in to leave a comment.